function delete($entry, $directory) { $target = $directory . '/' . basename($entry); if (is_writeable($target)) { osc_remove($target); return true; } return false; }
function save($id = null, $data) { global $osC_Database, $osC_Language, $osC_Image, $osC_Session; $error = false; $osC_Database->startTransaction(); //products if (is_numeric($id)) { $Qproduct = $osC_Database->query('update :table_products set products_type = :products_type, products_sku = :products_sku, products_model = :products_model, products_price = :products_price, products_quantity = :products_quantity, products_moq = :products_moq, products_max_order_quantity = :products_max_order_quantity, order_increment = :order_increment, quantity_unit_class = :quantity_unit_class, products_date_available = :products_date_available, products_weight = :products_weight, products_weight_class = :products_weight_class, products_status = :products_status, products_tax_class_id = :products_tax_class_id, manufacturers_id = :manufacturers_id, quantity_discount_groups_id = :quantity_discount_groups_id, products_last_modified = now(), products_attributes_groups_id = :products_attributes_groups_id where products_id = :products_id'); $Qproduct->bindInt(':products_id', $id); } else { $Qproduct = $osC_Database->query('insert into :table_products (products_type, products_sku, products_model, products_price, products_quantity, products_moq, products_max_order_quantity, order_increment, quantity_unit_class, products_date_available, products_weight, products_weight_class, products_status, products_tax_class_id, manufacturers_id, products_date_added, quantity_discount_groups_id, products_attributes_groups_id) values (:products_type, :products_sku, :products_model, :products_price, :products_quantity, :products_moq, :products_max_order_quantity, :order_increment, :quantity_unit_class, :products_date_available, :products_weight, :products_weight_class, :products_status, :products_tax_class_id, :manufacturers_id, :products_date_added, :quantity_discount_groups_id, :products_attributes_groups_id)'); $Qproduct->bindRaw(':products_date_added', 'now()'); } $Qproduct->bindTable(':table_products', TABLE_PRODUCTS); $Qproduct->bindInt(':products_type', $data['products_type']); $Qproduct->bindValue(':products_sku', $data['products_sku']); $Qproduct->bindValue(':products_model', $data['products_model']); $Qproduct->bindValue(':products_price', $data['price']); $Qproduct->bindInt(':products_quantity', $data['quantity']); $Qproduct->bindInt(':products_moq', $data['products_moq']); $Qproduct->bindInt(':products_max_order_quantity', $data['products_max_order_quantity']); $Qproduct->bindInt(':order_increment', $data['order_increment']); $Qproduct->bindInt(':quantity_unit_class', $data['quantity_unit_class']); if (date('Y-m-d') < $data['date_available']) { $Qproduct->bindValue(':products_date_available', $data['date_available']); } else { $Qproduct->bindRaw(':products_date_available', 'null'); } $Qproduct->bindValue(':products_weight', $data['weight']); $Qproduct->bindInt(':products_weight_class', $data['weight_class']); $Qproduct->bindInt(':products_status', $data['status']); $Qproduct->bindInt(':products_tax_class_id', $data['tax_class_id']); $Qproduct->bindInt(':manufacturers_id', $data['manufacturers_id']); $Qproduct->bindInt(':quantity_discount_groups_id', $data['quantity_discount_groups_id']); if (empty($data['products_attributes_groups_id'])) { $Qproduct->bindRaw(':products_attributes_groups_id', 'null'); } else { $Qproduct->bindInt(':products_attributes_groups_id', $data['products_attributes_groups_id']); } $Qproduct->setLogging($_SESSION['module'], $id); $Qproduct->execute(); if ($osC_Database->isError()) { $error = true; } else { if (is_numeric($id)) { $products_id = $id; } else { $products_id = $osC_Database->nextID(); } //products_to_categories $Qcategories = $osC_Database->query('delete from :table_products_to_categories where products_id = :products_id'); $Qcategories->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES); $Qcategories->bindInt(':products_id', $products_id); $Qcategories->setLogging($_SESSION['module'], $products_id); $Qcategories->execute(); if ($osC_Database->isError()) { $error = true; } else { if (isset($data['categories']) && !empty($data['categories'])) { foreach ($data['categories'] as $category_id) { $Qp2c = $osC_Database->query('insert into :table_products_to_categories (products_id, categories_id) values (:products_id, :categories_id)'); $Qp2c->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES); $Qp2c->bindInt(':products_id', $products_id); $Qp2c->bindInt(':categories_id', $category_id); $Qp2c->setLogging($_SESSION['module'], $products_id); $Qp2c->execute(); if ($osC_Database->isError()) { $error = true; break; } } } } } if ($error === false && is_numeric($id)) { $Qdelete = $osC_Database->query('delete from :table_products_attachments_to_products where products_id = :products_id'); $Qdelete->bindTable(':table_products_attachments_to_products', TABLE_PRODUCTS_ATTACHMENTS_TO_PRODUCTS); $Qdelete->bindInt(':products_id', $products_id); $Qdelete->setLogging($_SESSION['module'], $products_id); $Qdelete->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false && sizeof($data['attachments']) > 0) { foreach ($data['attachments'] as $attachments_id) { $Qp2a = $osC_Database->query('insert into :table_products_attachments_to_products (products_id, attachments_id) values (:products_id, :attachments_id)'); $Qp2a->bindTable(':table_products_attachments_to_products', TABLE_PRODUCTS_ATTACHMENTS_TO_PRODUCTS); $Qp2a->bindInt(':products_id', $products_id); $Qp2a->bindInt(':attachments_id', $attachments_id); $Qp2a->setLogging($_SESSION['module'], $products_id); $Qp2a->execute(); if ($osC_Database->isError()) { $error = true; break; } } } //accessories if ($error === false) { if (is_numeric($id)) { $Qdelete = $osC_Database->query('delete from :table_products_accessories where products_id = :products_id'); $Qdelete->bindTable(':table_products_accessories', TABLE_PRODUCTS_ACCESSORIES); $Qdelete->bindInt(':products_id', $products_id); $Qdelete->setLogging($_SESSION['module'], $products_id); $Qdelete->execute(); if ($osC_Database->isError()) { $error = true; } } if (sizeof($data['accessories_ids']) > 0) { foreach ($data['accessories_ids'] as $accessories_id) { $Qinsert = $osC_Database->query('insert into :table_products_accessories (products_id, accessories_id) values (:products_id, :accessories_id)'); $Qinsert->bindTable(':table_products_accessories', TABLE_PRODUCTS_ACCESSORIES); $Qinsert->bindInt(':products_id', $products_id); $Qinsert->bindInt(':accessories_id', $accessories_id); $Qinsert->setLogging($_SESSION['module'], $products_id); $Qinsert->execute(); if ($osC_Database->isError()) { $error = true; break; } } } } //downloadable products & gift certificates if ($data['products_type'] == PRODUCT_TYPE_DOWNLOADABLE) { if (is_numeric($id)) { $Qdownloadables = $osC_Database->query('update :table_products_downloadables set number_of_downloads = :number_of_downloads, number_of_accessible_days = :number_of_accessible_days where products_id = :products_id'); } else { $Qdownloadables = $osC_Database->query('insert into :table_products_downloadables (products_id, number_of_downloads, number_of_accessible_days) values (:products_id, :number_of_downloads, :number_of_accessible_days)'); } $Qdownloadables->bindTable(':table_products_downloadables', TABLE_PRODUCTS_DOWNLOADABLES); $Qdownloadables->bindInt(':products_id', $products_id); $Qdownloadables->bindInt(':number_of_downloads', $data['number_of_downloads']); $Qdownloadables->bindInt(':number_of_accessible_days', $data['number_of_accessible_days']); $Qdownloadables->setLogging($_SESSION['module'], $products_id); $Qdownloadables->execute(); if ($osC_Database->isError()) { $error = true; } else { $filename = null; $cache_filename = null; $file = new upload('downloadable_file'); if ($file->exists()) { $file->set_destination(realpath('../download')); if ($file->parse() && $file->save()) { $filename = $file->filename; $cache_filename = md5($filename . time()); rename(DIR_FS_DOWNLOAD . $filename, DIR_FS_DOWNLOAD . $cache_filename); } } if (!is_null($filename)) { if (is_numeric($id)) { $Qfile = $osC_Database->query('select cache_filename from :table_products_downloadables where products_id = :products_id'); $Qfile->bindTable(':table_products_downloadables', TABLE_PRODUCTS_DOWNLOADABLES); $Qfile->bindInt(':products_id', $products_id); $Qfile->execute(); if ($Qfile->numberOfRows() > 0) { $file = $Qfile->value('cache_filename'); unlink(DIR_FS_DOWNLOAD . $file); } } $Qupdate = $osC_Database->query('update :table_products_downloadables set filename = :filename, cache_filename = :cache_filename where products_id = :products_id'); $Qupdate->bindTable(':table_products_downloadables', TABLE_PRODUCTS_DOWNLOADABLES); $Qupdate->bindInt(':products_id', $products_id); $Qupdate->bindValue(':filename', $filename); $Qupdate->bindValue(':cache_filename', $cache_filename); $Qupdate->setLogging($_SESSION['module'], $products_id); $Qupdate->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $sample_filename = null; $cache_sample_filename = null; $sample_file = new upload('sample_downloadable_file'); if ($sample_file->exists()) { $sample_file->set_destination(realpath('../download')); if ($sample_file->parse() && $sample_file->save()) { $sample_filename = $sample_file->filename; $cache_sample_filename = md5($sample_filename . time()); @rename(DIR_FS_DOWNLOAD . $sample_filename, DIR_FS_DOWNLOAD . $cache_sample_filename); } } if (!is_null($sample_filename) && $error === false) { if (is_numeric($id)) { $Qfile = $osC_Database->query('select cache_sample_filename from :table_products_downloadables where products_id = :products_id'); $Qfile->bindTable(':table_products_downloadables', TABLE_PRODUCTS_DOWNLOADABLES); $Qfile->bindInt(':products_id', $products_id); $Qfile->execute(); if ($Qfile->numberOfRows() > 0) { $file = $Qfile->value('cache_sample_filename'); unlink(DIR_FS_DOWNLOAD . $file); } } $Qfiles = $osC_Database->query('update :table_products_downloadables set sample_filename = :sample_filename, cache_sample_filename = :cache_sample_filename where products_id = :products_id'); $Qfiles->bindTable(':table_products_downloadables', TABLE_PRODUCTS_DOWNLOADABLES); $Qfiles->bindInt(':products_id', $products_id); $Qfiles->bindValue(':sample_filename', $sample_filename); $Qfiles->bindValue(':cache_sample_filename', $cache_sample_filename); $Qfiles->setLogging($_SESSION['module'], $products_id); $Qfiles->execute(); if ($osC_Database->isError()) { $error = true; } } } } } else { if ($data['products_type'] == PRODUCT_TYPE_GIFT_CERTIFICATE) { if (is_numeric($id)) { $Qcertificates = $osC_Database->query('update :table_products_gift_certificates set gift_certificates_type = :gift_certificates_type, gift_certificates_amount_type = :gift_certificates_amount_type, open_amount_max_value = :open_amount_max_value, open_amount_min_value = :open_amount_min_value where products_id = :products_id'); } else { $Qcertificates = $osC_Database->query('insert into :table_products_gift_certificates (products_id, gift_certificates_type, gift_certificates_amount_type, open_amount_max_value, open_amount_min_value) values (:products_id, :gift_certificates_type, :gift_certificates_amount_type, :open_amount_max_value, :open_amount_min_value)'); } $Qcertificates->bindTable(':table_products_gift_certificates', TABLE_PRODUCTS_GIFT_CERTIFICATES); $Qcertificates->bindInt(':products_id', $products_id); $Qcertificates->bindInt(':gift_certificates_type', $data['gift_certificates_type']); $Qcertificates->bindInt(':gift_certificates_amount_type', $data['gift_certificates_amount_type']); $Qcertificates->bindValue(':open_amount_max_value', $data['open_amount_max_value']); $Qcertificates->bindValue(':open_amount_min_value', $data['open_amount_min_value']); $Qcertificates->setLogging($_SESSION['module'], $products_id); $Qcertificates->execute(); if ($osC_Database->isError()) { $error = true; } } } //products_description if ($error === false) { foreach ($osC_Language->getAll() as $l) { if (is_numeric($id)) { $Qpd = $osC_Database->query('update :table_products_description set products_name = :products_name, products_short_description = :products_short_description, products_description = :products_description, products_tags = :products_tags, products_url = :products_url, products_friendly_url = :products_friendly_url, products_page_title = :products_page_title, products_meta_keywords = :products_meta_keywords, products_meta_description = :products_meta_description where products_id = :products_id and language_id = :language_id'); } else { $Qpd = $osC_Database->query('insert into :table_products_description (products_id, language_id, products_name, products_short_description, products_description, products_tags, products_url, products_friendly_url, products_page_title, products_meta_keywords, products_meta_description) values (:products_id, :language_id, :products_name, :products_short_description, :products_description, :products_tags, :products_url, :products_friendly_url, :products_page_title, :products_meta_keywords, :products_meta_description)'); } $Qpd->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION); $Qpd->bindInt(':products_id', $products_id); $Qpd->bindInt(':language_id', $l['id']); $Qpd->bindValue(':products_name', $data['products_name'][$l['id']]); $Qpd->bindValue(':products_short_description', $data['products_short_description'][$l['id']]); $Qpd->bindValue(':products_description', $data['products_description'][$l['id']]); $Qpd->bindValue(':products_tags', $data['products_tags'][$l['id']]); $Qpd->bindValue(':products_url', $data['products_url'][$l['id']]); $Qpd->bindValue(':products_friendly_url', $data['products_friendly_url'][$l['id']]); $Qpd->bindValue(':products_page_title', $data['products_page_title'][$l['id']]); $Qpd->bindValue(':products_meta_keywords', $data['products_meta_keywords'][$l['id']]); $Qpd->bindValue(':products_meta_description', $data['products_meta_description'][$l['id']]); $Qpd->setLogging($_SESSION['module'], $products_id); $Qpd->execute(); if ($osC_Database->isError()) { $error = true; break; } } } //BEGIN: products images if ($error === false) { $images = array(); $image_path = '../images/products/_upload/' . $osC_Session->getID() . '/'; $osC_DirectoryListing = new osC_DirectoryListing($image_path, true); $osC_DirectoryListing->setIncludeDirectories(false); foreach ($osC_DirectoryListing->getFiles() as $file) { @copy($image_path . $file['name'], '../images/products/originals/' . $file['name']); @unlink($image_path . $file['name']); $images[$file['name']] = -1; } osc_remove($image_path); $default_flag = 1; foreach (array_keys($images) as $image) { $Qimage = $osC_Database->query('insert into :table_products_images (products_id, default_flag, sort_order, date_added) values (:products_id, :default_flag, :sort_order, :date_added)'); $Qimage->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES); $Qimage->bindInt(':products_id', $products_id); $Qimage->bindInt(':default_flag', $default_flag); $Qimage->bindInt(':sort_order', 0); $Qimage->bindRaw(':date_added', 'now()'); $Qimage->execute(); if ($osC_Database->isError()) { $error = true; } else { $image_id = $osC_Database->nextID(); $images[$image] = $image_id; $new_image_name = $products_id . '_' . $image_id . '_' . $image; @rename('../images/products/originals/' . $image, '../images/products/originals/' . $new_image_name); $Qupdate = $osC_Database->query('update :table_products_images set image = :image where id = :id'); $Qupdate->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES); $Qupdate->bindValue(':image', $new_image_name); $Qupdate->bindInt(':id', $image_id); $Qupdate->setLogging($_SESSION['module'], $products_id); $Qupdate->execute(); foreach ($osC_Image->getGroups() as $group) { if ($group['id'] != '1') { $osC_Image->resize($new_image_name, $group['id'], 'products'); } } } $default_flag = 0; } } //END: products images //BEGIN: products variants if ($error === false) { //if edit product, delete variant first if (is_numeric($id)) { $Qvariants = $osC_Database->query('select * from :table_products_variants where products_id = :products_id order by products_variants_id'); $Qvariants->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS); $Qvariants->bindInt(':products_id', $_REQUEST['products_id']); $Qvariants->execute(); $records = array(); while ($Qvariants->next()) { $Qentries = $osC_Database->query('select products_variants_id, products_variants_groups_id, products_variants_values_id from :table_products_variants_entries where products_variants_id = :products_variants_id order by products_variants_groups_id, products_variants_values_id'); $Qentries->bindTable(':table_products_variants_entries', TABLE_PRODUCTS_VARIANTS_ENTRIES); $Qentries->bindInt(':products_variants_id', $Qvariants->valueInt('products_variants_id')); $Qentries->execute(); $variants_values = array(); while ($Qentries->next()) { $variants_values[] = $Qentries->valueInt('products_variants_groups_id') . '_' . $Qentries->valueInt('products_variants_values_id'); } $variant = implode('-', $variants_values); if (!isset($data['products_variants_id'][$variant])) { //remove cache file $cache_filename = $Qvariants->value('cache_filename'); if (!empty($cache_filename) && file_exists(DIR_FS_DOWNLOAD . $cache_filename)) { osc_remove(DIR_FS_DOWNLOAD . $cache_filename); } //delete variants $Qdelete = $osC_Database->query('delete from :table_products_variants where products_variants_id = :products_variants_id'); $Qdelete->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS); $Qdelete->bindInt(':products_variants_id', $Qvariants->valueInt('products_variants_id')); $Qdelete->execute(); if ($osC_Database->isError()) { $error = true; break; } //delete variants entries if ($error === false) { $Qdelete = $osC_Database->query('delete from :table_products_variants_entries where products_variants_id = :products_variants_id'); $Qdelete->bindTable(':table_products_variants_entries', TABLE_PRODUCTS_VARIANTS_ENTRIES); $Qdelete->bindInt(':products_variants_id', $Qvariants->valueInt('products_variants_id')); $Qdelete->execute(); if ($osC_Database->isError()) { $error = true; break; } } } } } $products_quantity = 0; //insert or update variant if (isset($data['products_variants_id']) && is_array($data['products_variants_id'])) { foreach ($data['products_variants_id'] as $key => $variants_id) { if ($variants_id > 0) { $Qpv = $osC_Database->query('update :table_products_variants set products_price = :products_price, products_sku = :products_sku, products_model = :products_model, products_quantity = :products_quantity, products_weight = :products_weight, products_status = :products_status, products_images_id = :products_images_id, is_default = :is_default where products_variants_id = :products_variants_id'); $Qpv->bindInt(':products_variants_id', $variants_id); } else { $Qpv = $osC_Database->query('insert into :table_products_variants (products_id, products_price, products_sku, products_model, products_quantity, products_weight, products_status, is_default, products_images_id) values (:products_id, :products_price, :products_sku, :products_model, :products_quantity, :products_weight, :products_status, :is_default, :products_images_id)'); $Qpv->bindInt(':products_id', $products_id); } $Qpv->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS); $Qpv->bindInt(':is_default', $data['variants_default'][$key]); $Qpv->bindValue(':products_price', $data['variants_price'][$key]); $Qpv->bindValue(':products_sku', $data['variants_sku'][$key]); $Qpv->bindValue(':products_model', $data['variants_model'][$key]); $Qpv->bindValue(':products_quantity', $data['variants_quantity'][$key]); $Qpv->bindValue(':products_weight', $data['variants_weight'][$key]); $Qpv->bindValue(':products_status', $data['variants_status'][$key]); $products_images_id = is_numeric($data['variants_image'][$key]) ? $data['variants_image'][$key] : $images[$data['variants_image'][$key]]; $Qpv->bindInt(':products_images_id', $products_images_id); $Qpv->execute(); if ($osC_Database->isError()) { $error = true; break; } else { if (is_numeric($variants_id) && $variants_id > 0) { $products_variants_id = $variants_id; } else { $products_variants_id = $osC_Database->nextID(); } //downloadable file if ($data['products_type'] == PRODUCT_TYPE_DOWNLOADABLE) { $variants_file = new upload('products_variants_download_' . $key); if ($variants_file->exists()) { //remove old file if (is_numeric($variants_id) && $variants_id > 0) { $Qfile = $osC_Database->query('select cache_filename from :table_products_variants where products_variants_id = :products_variants_id'); $Qfile->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS); $Qfile->bindInt(':products_variants_id', $variants_id); $Qfile->execute(); $cache_filename = $Qfile->value('cache_filename'); if (!empty($cache_filename)) { osc_remove(DIR_FS_DOWNLOAD . $cache_filename); } } $variants_file->set_destination(realpath('../download')); if ($variants_file->parse() && $variants_file->save()) { $variants_filename = $variants_file->filename; $cache_variants_filename = md5($variants_filename . time()); @rename(DIR_FS_DOWNLOAD . $variants_filename, DIR_FS_DOWNLOAD . $cache_variants_filename); $Qupdate = $osC_Database->query('update :table_products_variants set filename = :filename, cache_filename = :cache_filename where products_variants_id = :products_variants_id'); $Qupdate->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS); $Qupdate->bindInt(':products_variants_id', $products_variants_id); $Qupdate->bindValue(':filename', $variants_filename); $Qupdate->bindValue(':cache_filename', $cache_variants_filename); $Qupdate->execute(); if ($osC_Database->isError()) { $error = true; break; } } } } $products_quantity += $data['variants_quantity'][$key]; } //variant entries if ($error === false && $variants_id == '-1') { $assigned_variants = explode('-', $key); for ($i = 0; $i < sizeof($assigned_variants); $i++) { $assigned_variant = explode('_', $assigned_variants[$i]); $Qpve = $osC_Database->query('insert into :table_products_variants_entries (products_variants_id, products_variants_groups_id, products_variants_values_id) values (:products_variants_id, :products_variants_groups_id, :products_variants_values_id)'); $Qpve->bindTable(':table_products_variants_entries', TABLE_PRODUCTS_VARIANTS_ENTRIES); $Qpve->bindInt(':products_variants_id', $products_variants_id); $Qpve->bindInt(':products_variants_groups_id', $assigned_variant[0]); $Qpve->bindInt(':products_variants_values_id', $assigned_variant[1]); $Qpve->setLogging($_SESSION['module'], $products_id); $Qpve->execute(); if ($osC_Database->isError()) { $error = true; break; } } } } if ($error === false) { $osC_Database->simpleQuery('update ' . TABLE_PRODUCTS . ' set products_quantity = ' . $products_quantity . ' where products_id =' . $products_id); if ($osC_Database->isError()) { $error = true; } } } } //END: products variants //BEGIN: xsell products if ($error === false) { if (is_numeric($id)) { $Qdelete = $osC_Database->query('delete from :table_products_xsell where products_id = :products_id'); $Qdelete->bindTable(':table_products_xsell', TABLE_PRODUCTS_XSELL); $Qdelete->bindInt(':products_id', $id); $Qdelete->setLogging($_SESSION['module'], $id); $Qdelete->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { if (isset($data['xsell_id_array']) && !empty($data['xsell_id_array'])) { foreach ($data['xsell_id_array'] as $xsell_products_id) { $Qxsell = $osC_Database->query('insert into :table_products_xsell (products_id, xsell_products_id) values (:products_id , :xsell_products_id )'); $Qxsell->bindTable(':table_products_xsell', TABLE_PRODUCTS_XSELL); $Qxsell->bindInt(':products_id', $products_id); $Qxsell->bindInt(':xsell_products_id', $xsell_products_id); $Qxsell->setLogging($_SESSION['module'], $products_id); $Qxsell->execute(); if ($osC_Database->isError()) { $error = true; break; } } } } } //END: xsell products //BEGIN: products attributes if ($error === false) { if (is_numeric($id)) { $Qdelete = $osC_Database->query('delete from :table_products_attributes where products_id = :products_id '); $Qdelete->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES); $Qdelete->bindInt(':products_id', $id); $Qdelete->setLogging($_SESSION['module'], $id); $Qdelete->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { if (!empty($data['products_attributes'])) { foreach ($data['products_attributes'] as $attribute) { $Qef = $osC_Database->query('insert into :table_products_attributes (products_id, products_attributes_values_id, language_id, value) values (:products_id , :products_attributes_values_id, :language_id, :value)'); $Qef->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES); $Qef->bindInt(':products_id', $products_id); $Qef->bindInt(':products_attributes_values_id', $attribute['id']); $Qef->bindInt(':language_id', $attribute['language_id']); $Qef->bindValue(':value', $attribute['value']); $Qef->execute(); if ($osC_Database->isError()) { $error = true; break; } } } } } //END: products attributes //BEGIN: customization fields if ($error === false) { if (is_numeric($id) && isset($data['customization_fields'])) { $ids = array(); foreach ($data['customization_fields'] as $customization) { if ($customization['customizations_fields_id'] > 0) { $ids[] = $customization['customizations_fields_id']; } } $Qcheck = $osC_Database->query('select customization_fields_id from :table_customization_fields where products_id = :products_id'); $Qcheck->bindTable(':table_customization_fields', TABLE_CUSTOMIZATION_FIELDS); $Qcheck->bindInt(':products_id', $products_id); if (sizeof($ids) > 0) { $Qcheck->appendQuery('and customization_fields_id not in (:customization_fields_id)'); $Qcheck->bindRaw(':customization_fields_id', implode(', ', $ids)); } $Qcheck->execute(); //delete customization fields if ($Qcheck->numberOfRows() > 0) { $batch = array(); while ($Qcheck->next()) { $batch[] = $Qcheck->valueInt('customization_fields_id'); } $Qdelete = $osC_Database->query('delete from :table_customization_fields where customization_fields_id in (:customization_fields_id)'); $Qdelete->bindTable(':table_customization_fields', TABLE_CUSTOMIZATION_FIELDS); $Qdelete->bindRaw(':customization_fields_id', implode(', ', $batch)); $Qdelete->setLogging($_SESSION['module'], $products_id); $Qdelete->execute(); if ($osC_Database->isError()) { $error = true; break; } if ($error === false) { $Qdelete = $osC_Database->query('delete from :table_customization_fields_description where customization_fields_id in (:customization_fields_id)'); $Qdelete->bindTable(':table_customization_fields_description', TABLE_CUSTOMIZATION_FIELDS_DESCRIPTION); $Qdelete->bindRaw(':customization_fields_id', implode(', ', $batch)); $Qdelete->setLogging($_SESSION['module'], $products_id); $Qdelete->execute(); if ($osC_Database->isError()) { $error = true; break; } } } } } if ($error === false) { if (isset($data['customization_fields']) && !empty($data['customization_fields'])) { foreach ($data['customization_fields'] as $field) { if ($field['customizations_fields_id'] > 0) { $Qfield = $osC_Database->query('update :table_customization_fields set type = :type, is_required = :is_required where customization_fields_id = :customization_fields_id'); $Qfield->bindInt(':customization_fields_id', $field['customizations_fields_id']); } else { $Qfield = $osC_Database->query('insert into :table_customization_fields (products_id, type, is_required) values (:products_id, :type, :is_required)'); } $Qfield->bindTable(':table_customization_fields', TABLE_CUSTOMIZATION_FIELDS); $Qfield->bindInt(':products_id', $products_id); $Qfield->bindInt(':type', $field['customizations_type']); $Qfield->bindInt(':is_required', $field['customizations_is_required']); $Qfield->execute(); if ($osC_Database->isError()) { $error = true; break; } else { $fields_id = $field['customizations_fields_id'] > 0 ? $field['customizations_fields_id'] : $osC_Database->nextID(); $lan = get_object_vars($field['customizations_name_data']); foreach ($osC_Language->getAll() as $l) { if ($field['customizations_fields_id'] > 0) { $Qdescription = $osC_Database->query('update :table_customization_fields_description set name = :name where customization_fields_id = :customization_fields_id and languages_id = :languages_id'); } else { $Qdescription = $osC_Database->query('insert into :table_customization_fields_description (customization_fields_id, languages_id, name) values (:customization_fields_id, :languages_id, :name)'); } $Qdescription->bindTable(':table_customization_fields_description', TABLE_CUSTOMIZATION_FIELDS_DESCRIPTION); $Qdescription->bindInt(':customization_fields_id', $fields_id); $Qdescription->bindInt(':languages_id', $l['id']); $Qdescription->bindValue(':name', $lan['name' . $l['id']]); $Qdescription->setLogging($_SESSION['module'], $products_id); $Qdescription->execute(); if ($osC_Database->isError()) { $error = true; break; } } } } } } //END: customization fields if ($error === false) { $osC_Database->commitTransaction(); osC_Cache::clear('categories'); osC_Cache::clear('category_tree'); osC_Cache::clear('also_purchased'); osC_Cache::clear('sefu-products'); osC_Cache::clear('new_products'); osC_Cache::clear('feature_products'); return $products_id; } $osC_Database->rollbackTransaction(); return false; }
function uploadLanguage() { global $toC_Json, $osC_Language, $osC_Currencies; $osC_Currencies = new osC_Currencies(); $error = false; $feedback = array(); $language = $_FILES['upload_file']; $tmp_path = DIR_FS_CACHE . 'languages/' . time(); if (!is_dir(DIR_FS_CACHE . 'languages')) { if (!mkdir(DIR_FS_CACHE . 'languages', 0777)) { $error = true; } } if ($error === false && mkdir($tmp_path, 0777)) { $temp_file = new upload($language, $tmp_path); if ($temp_file->exists() && $temp_file->parse() && $temp_file->save()) { require_once '../ext/zip/pclzip.lib.php'; $archive = new PclZip($tmp_path . '/' . $temp_file->filename); if ($archive->extract(PCLZIP_OPT_PATH, $tmp_path) == 0) { $error = true; $feedback[] = $osC_Language->get('ms_error_wrong_zip_file_format'); } } else { $error = true; $feedback[] = $osC_Language->get('ms_error_save_file_failed'); } } else { $error = true; $feedback[] = sprintf($osC_Language->get('ms_error_creating_directory_failed'), DIR_FS_CACHE); } if ($error === false) { $osC_DirectoryListing = new osC_DirectoryListing($tmp_path); $osC_DirectoryListing->setIncludeDirectories(true); $osC_DirectoryListing->setIncludeFiles(false); $files = $osC_DirectoryListing->getFiles(); $code = null; foreach ($files as $file) { if (is_dir($tmp_path . '/' . $file['name'] . '/includes') && is_dir($tmp_path . '/' . $file['name'] . '/' . DIR_FS_ADMIN) && is_dir($tmp_path . '/' . $file['name'] . '/install')) { $code = $file['name']; break; } } if ($code != null) { toc_dircopy($tmp_path . '/' . $code . "/includes/languages", DIR_FS_CATALOG . 'includes/languages'); toc_dircopy($tmp_path . '/' . $code . "/" . DIR_FS_ADMIN . "includes/languages", DIR_FS_CATALOG . DIR_FS_ADMIN . 'includes/languages'); toc_dircopy($tmp_path . '/' . $code . "/install/includes/languages", DIR_FS_CATALOG . 'install/includes/languages'); toc_dircopy($tmp_path . '/' . $code . "/install/templates", DIR_FS_CATALOG . 'install/templates'); osc_remove($tmp_path); } else { $error = true; $feedback[] = $osC_Language->get('ms_error_wrong_language_package'); } } if ($error === false) { if (osC_Language_Admin::import($code, 'replace')) { $response = array('success' => true, 'feedback' => $osC_Language->get('ms_success_action_performed')); } else { $response = array('success' => false, 'feedback' => $osC_Language->get('ms_error_action_not_performed')); } } else { $response = array('success' => false, 'feedback' => $osC_Language->get('ms_error_action_not_performed') . '<br />' . implode('<br />', $feedback)); } header('Content-Type: text/html'); echo $toC_Json->encode($response); }
function deleteImage() { global $toC_Json, $osC_Language, $osC_Session; $error = false; if (is_numeric($_REQUEST['image'])) { $osC_Image = new osC_Image_Admin(); if (!$osC_Image->delete($_REQUEST['image'])) { $error = true; } } else { $image_path = '../images/products/_upload/' . $osC_Session->getID() . '/'; if (!osc_remove($image_path . $_REQUEST['image'])) { $error = true; } } if ($error === false) { $response = array('success' => true, 'feedback' => $osC_Language->get('ms_success_action_performed')); } else { $response = array('success' => false, 'feedback' => $osC_Language->get('ms_error_action_not_performed')); } echo $toC_Json->encode($response); }
function _upload_new_template(&$result) { global $osC_Language, $osC_Database; $template_file = new upload('template_file', realpath('../templates'), '777', 'zip'); if ($template_file->exists()) { if ($template_file->parse() && $template_file->save()) { $module_name = substr($template_file->filename, 0, strpos($template_file->filename, '.')); $directory = realpath('../templates') . '/' . $module_name; if (is_dir($directory)) { $result[] = $osC_Language->get('ms_error_template_directory_exist'); osc_remove(realpath('../templates') . '/' . $template_file->filename); return false; } require_once '../ext/zip/pclzip.lib.php'; $archive = new PclZip(realpath('../templates') . '/' . $template_file->filename); if ($archive->extract(PCLZIP_OPT_PATH, realpath('../templates')) == 0) { return false; } osc_remove(realpath('../templates') . '/' . $template_file->filename); if (file_exists('../templates/' . $module_name . '/template.php')) { include '../templates/' . $module_name . '/template.php'; $class = 'osC_Template_' . $module_name; if (!class_exists($class)) { $result[] = $osC_Language->get('ms_error_template_class_not_exist'); osc_remove(realpath('../templates') . '/' . $module_name); return false; } $module = new $class(); $Qtemplate = $osC_Database->query('select id from :table_templates where code = :code'); $Qtemplate->bindTable(':table_templates', TABLE_TEMPLATES); $Qtemplate->bindvalue(':code', $module->_code); $Qtemplate->execute(); if ($Qtemplate->numberOfRows() > 0) { $result[] = $osC_Language->get('ms_error_template_code_exist'); osc_remove(realpath('../templates') . '/' . $module_name); return false; } return true; } else { $result[] = $osC_Language->get('ms_error_template_file_not_exist'); osc_remove(realpath('../templates') . '/' . $module_name); return false; } } else { $result[] = $osC_Language->get('ms_error_wrong_zip_file'); osc_remove(realpath('../templates') . '/' . $template_file->filename); } } return false; }
function remove($id, $del_files = false) { global $osC_Database, $osC_Language; $Qcheck = $osC_Database->query('select code from :table_languages where languages_id = :languages_id'); $Qcheck->bindTable(':table_languages', TABLE_LANGUAGES); $Qcheck->bindInt(':languages_id', $id); $Qcheck->execute(); if ($Qcheck->value('code') != DEFAULT_LANGUAGE) { $error = false; $osC_Database->startTransaction(); $Qcategories = $osC_Database->query('delete from :table_categories_description where language_id = :language_id'); $Qcategories->bindTable(':table_categories_description', TABLE_CATEGORIES_DESCRIPTION); $Qcategories->bindInt(':language_id', $id); $Qcategories->execute(); if ($osC_Database->isError()) { $error = true; } if ($error === false) { $Qcustomization = $osC_Database->query('delete from :table_customization_fields_description where languages_id = :languages_id'); $Qcustomization->bindTable(':table_customization_fields_description', TABLE_CUSTOMIZATION_FIELDS_DESCRIPTION); $Qcustomization->bindInt(':languages_id', $id); $Qcustomization->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qproducts = $osC_Database->query('delete from :table_products_description where language_id = :language_id'); $Qproducts->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION); $Qproducts->bindInt(':language_id', $id); $Qproducts->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $QcustomizationFields = $osC_Database->query('delete from :table_customization_fields_description where languages_id = :languages_id'); $QcustomizationFields->bindTable(':table_customization_fields_description', TABLE_CUSTOMIZATION_FIELDS_DESCRIPTION); $QcustomizationFields->bindInt(':languages_id', $id); $QcustomizationFields->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qproducts = $osC_Database->query('delete from :table_products_variants_groups where language_id = :language_id'); $Qproducts->bindTable(':table_products_variants_groups', TABLE_PRODUCTS_VARIANTS_GROUPS); $Qproducts->bindInt(':language_id', $id); $Qproducts->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qproducts = $osC_Database->query('delete from :table_products_variants_values where language_id = :language_id'); $Qproducts->bindTable(':table_products_variants_values', TABLE_PRODUCTS_VARIANTS_VALUES); $Qproducts->bindInt(':language_id', $id); $Qproducts->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qmanufacturers = $osC_Database->query('delete from :table_manufacturers_info where languages_id = :languages_id'); $Qmanufacturers->bindTable(':table_manufacturers_info', TABLE_MANUFACTURERS_INFO); $Qmanufacturers->bindInt(':languages_id', $id); $Qmanufacturers->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qstatus = $osC_Database->query('delete from :table_orders_status where language_id = :language_id'); $Qstatus->bindTable(':table_orders_status', TABLE_ORDERS_STATUS); $Qstatus->bindInt(':language_id', $id); $Qstatus->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qreturns = $osC_Database->query('delete from :table_orders_returns_status where languages_id = :language_id'); $Qreturns->bindTable(':table_orders_returns_status', TABLE_ORDERS_RETURNS_STATUS); $Qreturns->bindInt(':language_id', $id); $Qreturns->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qreturns = $osC_Database->query('delete from :table_orders_transactions_status where language_id = :language_id'); $Qreturns->bindTable(':table_orders_transactions_status', TABLE_ORDERS_TRANSACTIONS_STATUS); $Qreturns->bindInt(':language_id', $id); $Qreturns->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qgroup = $osC_Database->query('delete from :table_products_images_groups where language_id = :language_id'); $Qgroup->bindTable(':table_products_images_groups', TABLE_PRODUCTS_IMAGES_GROUPS); $Qgroup->bindInt(':language_id', $id); $Qgroup->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qclasses = $osC_Database->query('delete from :table_quantity_unit_classes where language_id = :language_id'); $Qclasses->bindTable(':table_quantity_unit_classes', TABLE_QUANTITY_UNIT_CLASSES); $Qclasses->bindInt(':language_id', $id); $Qclasses->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qclasses = $osC_Database->query('delete from :table_weight_classes where language_id = :language_id'); $Qclasses->bindTable(':table_weight_classes', TABLE_WEIGHT_CLASS); $Qclasses->bindInt(':language_id', $id); $Qclasses->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qarticles = $osC_Database->query('delete from :table_articles_description where language_id = :language_id'); $Qarticles->bindTable(':table_articles_description', TABLE_ARTICLES_DESCRIPTION); $Qarticles->bindInt(':language_id', $id); $Qarticles->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qcategories = $osC_Database->query('delete from :table_articles_categories_description where language_id = :language_id'); $Qcategories->bindTable(':table_articles_categories_description', TABLE_ARTICLES_CATEGORIES_DESCRIPTION); $Qcategories->bindInt(':language_id', $id); $Qcategories->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qcoupons = $osC_Database->query('delete from :table_coupons_description where language_id = :language_id'); $Qcoupons->bindTable(':table_coupons_description', TABLE_COUPONS_DESCRIPTION); $Qcoupons->bindInt(':language_id', $id); $Qcoupons->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qgroups = $osC_Database->query('delete from :table_customers_groups_description where language_id = :language_id'); $Qgroups->bindTable(':table_customers_groups_description', TABLE_CUSTOMERS_GROUPS_DESCRIPTION); $Qgroups->bindInt(':language_id', $id); $Qgroups->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qtemplates = $osC_Database->query('delete from :table_email_templates_description where language_id = :language_id'); $Qtemplates->bindTable(':table_email_templates_description', TABLE_EMAIL_TEMPLATES_DESCRIPTION); $Qtemplates->bindInt(':language_id', $id); $Qtemplates->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qfaqs = $osC_Database->query('delete from :table_faqs_description where language_id = :language_id'); $Qfaqs->bindTable(':table_faqs_description', TABLE_FAQS_DESCRIPTION); $Qfaqs->bindInt(':language_id', $id); $Qfaqs->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qattributes = $osC_Database->query('delete from :table_products_attributes_values where language_id = :language_id'); $Qattributes->bindTable(':table_products_attributes_values', TABLE_PRODUCTS_ATTRIBUTES_VALUES); $Qattributes->bindInt(':language_id', $id); $Qattributes->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qattributes = $osC_Database->query('delete from :table_products_attributes where language_id = :language_id'); $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES); $Qattributes->bindInt(':language_id', $id); $Qattributes->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qimages = $osC_Database->query('delete from :table_slide_images where language_id = :language_id'); $Qimages->bindTable(':table_slide_images', TABLE_SLIDE_IMAGES); $Qimages->bindInt(':language_id', $id); $Qimages->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qlanguages = $osC_Database->query('delete from :table_languages where languages_id = :language_id'); $Qlanguages->bindTable(':table_languages', TABLE_LANGUAGES); $Qlanguages->bindInt(':language_id', $id); $Qlanguages->setLogging($_SESSION['module'], $id); $Qlanguages->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qdefinitions = $osC_Database->query('delete from :table_languages_definitions where languages_id = :languages_id'); $Qdefinitions->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS); $Qdefinitions->bindInt(':languages_id', $id); $Qdefinitions->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qratings = $osC_Database->query('delete from :table_ratings_description where languages_id = :languages_id'); $Qratings->bindTable(':table_ratings_description', TABLE_RATINGS_DESCRIPTION); $Qratings->bindInt(':languages_id', $id); $Qratings->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qpolls = $osC_Database->query('delete from :table_polls_description where languages_id = :languages_id'); $Qpolls->bindTable(':table_polls_description', TABLE_POLLS_DESCRIPTION); $Qpolls->bindInt(':languages_id', $id); $Qpolls->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qanswers = $osC_Database->query('delete from :table_polls_answers_description where languages_id = :languages_id'); $Qanswers->bindTable(':table_polls_answers_description', TABLE_POLLS_ANSWERS_DESCRIPTION); $Qanswers->bindInt(':languages_id', $id); $Qanswers->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qattachments = $osC_Database->query('delete from :table_products_attachments_description where languages_id = :languages_id'); $Qattachments->bindTable(':table_products_attachments_description', TABLE_PRODUCTS_ATTACHMENTS_DESCRIPTION); $Qattachments->bindInt(':languages_id', $id); $Qattachments->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qdepartment = $osC_Database->query('delete from :table_departments_description where languages_id = :languages_id'); $Qdepartment->bindTable(':table_departments_description', TABLE_DEPARTMENTS_DESCRIPTION); $Qdepartment->bindInt(':languages_id', $id); $Qdepartment->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $osC_Database->commitTransaction(); osC_Cache::clear('languages'); //delete language files too if ($del_files === true) { $lang_admin_path = DIR_FS_CATALOG . DIR_FS_ADMIN . 'includes/languages/'; $lang_front_path = DIR_FS_CATALOG . 'includes/languages/'; $lang_install_path = DIR_FS_CATALOG . 'install/includes/languages/'; $lang_code = $Qcheck->value('code'); if (file_exists($lang_admin_path . $lang_code . '.php')) { @unlink($lang_admin_path . $lang_code . '.php'); } if (is_dir($lang_admin_path . $lang_code)) { osc_remove($lang_admin_path . $lang_code); } if (file_exists($lang_front_path . $lang_code . '.xml')) { @unlink($lang_front_path . $lang_code . '.xml'); } if (is_dir($lang_front_path . $lang_code)) { osc_remove($lang_front_path . $lang_code); } if (file_exists($lang_install_path . $lang_code . '.php')) { @unlink($lang_install_path . $lang_code . '.php'); } if (is_dir($lang_install_path . $lang_code)) { osc_remove($lang_install_path . $lang_code); } } return true; } else { $osC_Database->rollbackTransaction(); } } return false; }
function osc_remove($source) { global $osC_Language, $osC_MessageStack; if (is_dir($source)) { $dir = dir($source); while ($file = $dir->read()) { if ($file != '.' && $file != '..') { if (is_writeable($source . '/' . $file)) { osc_remove($source . '/' . $file); } else { $osC_MessageStack->add('header', sprintf($osC_Language->get('ms_error_file_not_removable'), $source . '/' . $file), 'error'); } } } $dir->close(); if (is_writeable($source)) { return rmdir($source); } else { $osC_MessageStack->add('header', sprintf($osC_Language->get('ms_error_directory_not_removable'), $source), 'error'); } } else { if (is_writeable($source)) { return unlink($source); } else { $osC_MessageStack->add('header', sprintf($osC_Language->get('ms_error_file_not_removable'), $source), 'error'); } } }