function execute()
 {
     global $osC_Session, $osC_Product, $toC_Customization_Fields, $osC_Language, $messageStack;
     if (!isset($osC_Product)) {
         $id = false;
         foreach ($_GET as $key => $value) {
             if ((ereg('^[0-9]+(#?([0-9]+:?[0-9]+)+(;?([0-9]+:?[0-9]+)+)*)*$', $key) || ereg('^[a-zA-Z0-9 -_]*$', $key)) && $key != $osC_Session->getName()) {
                 $id = $key;
             }
             break;
         }
         if ($id !== false && osC_Product::checkEntry($id)) {
             $osC_Product = new osC_Product($id);
         }
     }
     if (isset($osC_Product)) {
         $errors = array();
         $data = array();
         $customizations = $osC_Product->getCustomizations();
         foreach ($customizations as $field) {
             $fields_id = $field['customization_fields_id'];
             if ($field['type'] == CUSTOMIZATION_FIELD_TYPE_INPUT_TEXT) {
                 $value = isset($_POST['customizations'][$fields_id]) ? $_POST['customizations'][$fields_id] : null;
                 if ($field['is_required'] && $value == null) {
                     $messageStack->add_session('products_customizations', sprintf($osC_Language->get('error_customization_field_must_be_specified'), $field['name']), 'error');
                 } else {
                     if ($value != null) {
                         $data[$fields_id] = array('customization_fields_id' => $field['customization_fields_id'], 'customization_fields_name' => $field['name'], 'customization_type' => CUSTOMIZATION_FIELD_TYPE_INPUT_TEXT, 'customization_value' => $value);
                     }
                 }
             } else {
                 $file = new upload('customizations_' . $fields_id, DIR_FS_CACHE . '/products_customizations/');
                 if ($field['is_required'] && !$file->exists() && !$toC_Customization_Fields->hasCustomizationField($osC_Product->getID(), $fields_id)) {
                     $messageStack->add_session('products', sprintf($osC_Language->get('error_customization_field_must_be_specified'), $field['name']), 'error');
                 } else {
                     if ($file->exists()) {
                         if ($file->parse() && $file->save()) {
                             $filename = $file->filename;
                             $cache_filename = md5($filename . time());
                             rename(DIR_FS_CACHE . '/products_customizations/' . $filename, DIR_FS_CACHE . '/products_customizations/' . $cache_filename);
                             $data[$fields_id] = array('customization_fields_id' => $field['customization_fields_id'], 'customization_fields_name' => $field['name'], 'customization_type' => CUSTOMIZATION_FIELD_TYPE_INPUT_FILE, 'customization_value' => $filename, 'cache_filename' => $cache_filename);
                         } else {
                             $messageStack->add_session('products_customizations', $file->getLastError(), 'error');
                         }
                     }
                 }
             }
         }
         //var_dump($data);exit;
         if ($messageStack->size('products_customizations') === 0) {
             $toC_Customization_Fields->set($osC_Product->getID(), $data);
         }
     }
     osc_redirect(osc_href_link(FILENAME_PRODUCTS, $osC_Product->getID()));
 }
 function save($id = null, $data)
 {
     global $osC_Database, $osC_Language, $osC_Image;
     if (is_numeric($id)) {
         foreach ($osC_Language->getAll() as $l) {
             $image_upload = new upload('image' . $l['id'], DIR_FS_CATALOG . 'images/');
             if ($image_upload->exists() && $image_upload->parse() && $image_upload->save()) {
                 $Qdelete = $osC_Database->query('select image from :table_slide_images where image_id = :image_id and language_id=:language_id');
                 $Qdelete->bindTable(':table_slide_images', TABLE_SLIDE_IMAGES);
                 $Qdelete->bindInt(':image_id', $id);
                 $Qdelete->bindValue(':language_id', $l['id']);
                 $Qdelete->execute();
                 if ($Qdelete->numberOfRows() > 0) {
                     @unlink(DIR_FS_CATALOG . 'images/' . $Qdelete->value('image'));
                 }
                 $Qimage = $osC_Database->query('update :table_slide_images set image = :image, description = :description, image_url = :image_url, sort_order = :sort_order, status = :status where image_id = :image_id and language_id=:language_id');
                 $Qimage->bindValue(':image', $image_upload->filename);
             } else {
                 $Qimage = $osC_Database->query('update :table_slide_images set description = :description, image_url = :image_url, sort_order = :sort_order, status = :status where image_id = :image_id and language_id=:language_id');
             }
             $Qimage->bindTable(':table_slide_images', TABLE_SLIDE_IMAGES);
             $Qimage->bindValue(':description', $data['description'][$l['id']]);
             $Qimage->bindValue(':image_url', $data['image_url'][$l['id']]);
             $Qimage->bindValue(':sort_order', $data['sort_order']);
             $Qimage->bindValue(':status', $data['status']);
             $Qimage->bindInt(':image_id', $id);
             $Qimage->bindValue(':language_id', $l['id']);
             $Qimage->execute();
         }
     } else {
         $Qmaximage = $osC_Database->query('select max(image_id) as image_id from :table_slide_images');
         $Qmaximage->bindTable(':table_slide_images', TABLE_SLIDE_IMAGES);
         $Qmaximage->execute();
         $image_id = $Qmaximage->valueInt('image_id') + 1;
         foreach ($osC_Language->getAll() as $l) {
             $products_image = new upload('image' . $l['id'], DIR_FS_CATALOG . 'images/');
             if ($products_image->exists() && $products_image->parse() && $products_image->save()) {
                 $Qimage = $osC_Database->query('insert into :table_slide_images (image_id,language_id ,description,image ,image_url ,sort_order,status) values (:image_id,:language_id,:description ,:image,:image_url ,:sort_order,:status)');
                 $Qimage->bindTable(':table_slide_images', TABLE_SLIDE_IMAGES);
                 $Qimage->bindValue(':image_id', $image_id);
                 $Qimage->bindValue(':language_id', $l['id']);
                 $Qimage->bindValue(':description', $data['description'][$l['id']]);
                 $Qimage->bindValue(':image', $products_image->filename);
                 $Qimage->bindValue(':image_url', $data['image_url'][$l['id']]);
                 $Qimage->bindValue(':sort_order', $data['sort_order']);
                 $Qimage->bindValue(':status', $data['status']);
                 $Qimage->execute();
             }
         }
     }
     if ($osC_Database->isError()) {
         return false;
     } else {
         osC_Cache::clear('slide-images');
         return true;
     }
 }
 function storeFileUpload($file, $directory)
 {
     if (is_writeable($directory)) {
         $upload = new upload($file, $directory);
         if ($upload->exists() && $upload->parse() && $upload->save()) {
             return true;
         }
     }
     return false;
 }
 public static function save($id = null, $data)
 {
     global $osC_Database;
     $error = false;
     if (empty($data['html_text']) && empty($data['image_local']) && !empty($data['image'])) {
         $image = new upload($data['image'], realpath('../images/' . $data['image_target']));
         if (!$image->exists() || !$image->parse() || !$image->save()) {
             $error = true;
         }
     }
     if ($error === false) {
         $image_location = !empty($data['image_local']) ? $data['image_local'] : (isset($image) ? $data['image_target'] . $image->filename : null);
         if (is_numeric($id)) {
             $Qbanner = $osC_Database->query('update :table_banners set banners_title = :banners_title, banners_url = :banners_url, banners_image = :banners_image, banners_group = :banners_group, banners_html_text = :banners_html_text, expires_date = :expires_date, expires_impressions = :expires_impressions, date_scheduled = :date_scheduled, status = :status where banners_id = :banners_id');
             $Qbanner->bindInt(':banners_id', $id);
         } else {
             $Qbanner = $osC_Database->query('insert into :table_banners (banners_title, banners_url, banners_image, banners_group, banners_html_text, expires_date, expires_impressions, date_scheduled, status, date_added) values (:banners_title, :banners_url, :banners_image, :banners_group, :banners_html_text, :expires_date, :expires_impressions, :date_scheduled, :status, now())');
         }
         $Qbanner->bindTable(':table_banners', TABLE_BANNERS);
         $Qbanner->bindValue(':banners_title', $data['title']);
         $Qbanner->bindValue(':banners_url', $data['url']);
         $Qbanner->bindValue(':banners_image', $image_location);
         $Qbanner->bindValue(':banners_group', !empty($data['group_new']) ? $data['group_new'] : $data['group']);
         $Qbanner->bindValue(':banners_html_text', $data['html_text']);
         if (empty($data['date_expires'])) {
             $Qbanner->bindRaw(':expires_date', 'null');
             $Qbanner->bindInt(':expires_impressions', $data['expires_impressions']);
         } else {
             $Qbanner->bindValue(':expires_date', $data['date_expires']);
             $Qbanner->bindInt(':expires_impressions', 0);
         }
         if (empty($data['date_scheduled'])) {
             $Qbanner->bindRaw(':date_scheduled', 'null');
             $Qbanner->bindInt(':status', $data['status'] === true ? 1 : 0);
         } else {
             $Qbanner->bindValue(':date_scheduled', $data['date_scheduled']);
             $Qbanner->bindInt(':status', $data['date_scheduled'] > date('Y-m-d') ? 0 : ($data['status'] === true ? 1 : 0));
         }
         $Qbanner->setLogging($_SESSION['module'], $id);
         $Qbanner->execute();
         if (!$osC_Database->isError()) {
             return true;
         }
     }
     return false;
 }
Exemple #5
0
 function upload()
 {
     $logo_image = new upload('logo_image');
     if ($logo_image->exists()) {
         self::deleteLogo('originals');
         $img_type = substr($_FILES['logo_image']['name'], strrpos($_FILES['logo_image']['name'], '.') + 1);
         $original = DIR_FS_CATALOG . DIR_WS_IMAGES . 'logo_originals.' . $img_type;
         $logo_image->set_destination(realpath(DIR_FS_CATALOG . 'images/'));
         if ($logo_image->parse() && $logo_image->save()) {
             copy(DIR_FS_CATALOG . 'images/' . $logo_image->filename, $original);
             @unlink(DIR_FS_CATALOG . 'images/' . $logo_image->filename);
             $osC_DirectoryListing = new osC_DirectoryListing('../templates');
             $osC_DirectoryListing->setIncludeDirectories(true);
             $osC_DirectoryListing->setIncludeFiles(false);
             $osC_DirectoryListing->setExcludeEntries('system');
             $templates = $osC_DirectoryListing->getFiles();
             foreach ($templates as $template) {
                 $code = $template['name'];
                 if (file_exists('../templates/' . $code . '/template.php')) {
                     include '../templates/' . $code . '/template.php';
                     $class = 'osC_Template_' . $code;
                     self::deleteLogo($code);
                     if (class_exists($class)) {
                         $module = new $class();
                         $logo_height = $module->getLogoHeight();
                         $logo_width = $module->getLogoWidth();
                         $dest_image = DIR_FS_CATALOG . DIR_WS_IMAGES . 'logo_' . $code . '.' . $img_type;
                         osc_gd_resize($original, $dest_image, $logo_width, $logo_height);
                     }
                 }
             }
             return true;
         }
     }
     return false;
 }
Exemple #6
0
 function save($id = null, $data)
 {
     global $osC_Database, $osC_Language;
     $category_id = '';
     $error = false;
     $osC_Database->startTransaction();
     if (is_numeric($id)) {
         $Qcat = $osC_Database->query('update :table_categories set categories_status = :categories_status, sort_order = :sort_order, last_modified = now() where categories_id = :categories_id');
         $Qcat->bindInt(':categories_id', $id);
     } else {
         $Qcat = $osC_Database->query('insert into :table_categories (parent_id, categories_status, sort_order, date_added) values (:parent_id, :categories_status, :sort_order, now())');
         $Qcat->bindInt(':parent_id', $data['parent_id']);
     }
     $Qcat->bindTable(':table_categories', TABLE_CATEGORIES);
     $Qcat->bindInt(':sort_order', $data['sort_order']);
     $Qcat->bindInt(':categories_status', $data['categories_status']);
     $Qcat->setLogging($_SESSION['module'], $id);
     $Qcat->execute();
     if (!$osC_Database->isError()) {
         $category_id = is_numeric($id) ? $id : $osC_Database->nextID();
         if (is_numeric($id)) {
             if ($data['categories_status']) {
                 $Qpstatus = $osC_Database->query('update :table_products set products_status = 1 where products_id in (select products_id from :table_products_to_categories where categories_id = :categories_id)');
                 $Qpstatus->bindTable(':table_products', TABLE_PRODUCTS);
                 $Qpstatus->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES);
                 $Qpstatus->bindInt(":categories_id", $id);
                 $Qpstatus->execute();
             } else {
                 if ($data['flag']) {
                     $Qpstatus = $osC_Database->query('update :table_products set products_status = 0 where products_id in (select products_id from :table_products_to_categories where categories_id = :categories_id)');
                     $Qpstatus->bindTable(':table_products', TABLE_PRODUCTS);
                     $Qpstatus->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES);
                     $Qpstatus->bindInt(":categories_id", $id);
                     $Qpstatus->execute();
                 }
             }
         }
         if ($osC_Database->isError()) {
             $error = true;
         }
         foreach ($osC_Language->getAll() as $l) {
             if (is_numeric($id)) {
                 $Qcd = $osC_Database->query('update :table_categories_description set categories_name = :categories_name, categories_url = :categories_url, categories_page_title = :categories_page_title, categories_meta_keywords = :categories_meta_keywords, categories_meta_description = :categories_meta_description where categories_id = :categories_id and language_id = :language_id');
             } else {
                 $Qcd = $osC_Database->query('insert into :table_categories_description (categories_id, language_id, categories_name, categories_url, categories_page_title, categories_meta_keywords, categories_meta_description) values (:categories_id, :language_id, :categories_name, :categories_url, :categories_page_title, :categories_meta_keywords, :categories_meta_description)');
             }
             $Qcd->bindTable(':table_categories_description', TABLE_CATEGORIES_DESCRIPTION);
             $Qcd->bindInt(':categories_id', $category_id);
             $Qcd->bindInt(':language_id', $l['id']);
             $Qcd->bindValue(':categories_name', $data['name'][$l['id']]);
             $Qcd->bindValue(':categories_url', $data['url'][$l['id']] == '' ? $data['name'][$l['id']] : $data['url'][$l['id']]);
             $Qcd->bindValue(':categories_page_title', $data['page_title'][$l['id']]);
             $Qcd->bindValue(':categories_meta_keywords', $data['meta_keywords'][$l['id']]);
             $Qcd->bindValue(':categories_meta_description', $data['meta_description'][$l['id']]);
             $Qcd->setLogging($_SESSION['module'], $category_id);
             $Qcd->execute();
             if ($osC_Database->isError()) {
                 $error = true;
                 break;
             }
         }
         $Qdelete = $osC_Database->query('delete from :toc_categories_ratings where categories_id = :categories_id');
         $Qdelete->bindTable(':toc_categories_ratings', TABLE_CATEGORIES_RATINGS);
         $Qdelete->bindInt(':categories_id', $category_id);
         $Qdelete->execute();
         if (!empty($data['ratings'])) {
             $ratings = explode(',', $data['ratings']);
             foreach ($ratings as $ratings_id) {
                 $Qinsert = $osC_Database->query('insert into :toc_categories_ratings (categories_id, ratings_id) values (:categories_id, :ratings_id)');
                 $Qinsert->bindTable(':toc_categories_ratings', TABLE_CATEGORIES_RATINGS);
                 $Qinsert->bindInt(':categories_id', $category_id);
                 $Qinsert->bindInt(':ratings_id', $ratings_id);
                 $Qinsert->execute();
                 if ($osC_Database->isError()) {
                     $error = true;
                     break;
                 }
             }
         }
         if ($error === false) {
             $categories_image = new upload($data['image'], realpath('../' . DIR_WS_IMAGES . 'categories'));
             if ($categories_image->exists() && $categories_image->parse() && $categories_image->save()) {
                 $Qimage = $osC_Database->query('select categories_image from :table_categories where categories_id = :categories_id');
                 $Qimage->bindTable(':table_categories', TABLE_CATEGORIES);
                 $Qimage->bindInt(':categories_id', $category_id);
                 $Qimage->execute();
                 $old_image = $Qimage->value('categories_image');
                 if (!empty($old_image)) {
                     $Qcheck = $osC_Database->query('select count(*) as image_count from :table_categories where categories_image = :categories_image');
                     $Qcheck->bindTable(':table_categories', TABLE_CATEGORIES);
                     $Qcheck->bindValue(':categories_image', $old_image);
                     $Qcheck->execute();
                     if ($Qcheck->valueInt('image_count') == 1) {
                         $path = realpath('../' . DIR_WS_IMAGES . 'categories') . '/' . $old_image;
                         unlink($path);
                     }
                 }
                 $Qcf = $osC_Database->query('update :table_categories set categories_image = :categories_image where categories_id = :categories_id');
                 $Qcf->bindTable(':table_categories', TABLE_CATEGORIES);
                 $Qcf->bindValue(':categories_image', $categories_image->filename);
                 $Qcf->bindInt(':categories_id', $category_id);
                 $Qcf->setLogging($_SESSION['module'], $category_id);
                 $Qcf->execute();
                 if ($osC_Database->isError()) {
                     $error = true;
                 }
             }
         }
     }
     if ($error === false) {
         $osC_Database->commitTransaction();
         osC_Cache::clear('categories');
         osC_Cache::clear('category_tree');
         osC_Cache::clear('also_purchased');
         return true;
     }
     $osC_Database->rollbackTransaction();
     return false;
 }
Exemple #7
0
 function uploadAttachment()
 {
     global $toC_Json, $osC_Language, $osC_Session;
     $error = false;
     $path = DIR_FS_CACHE_ADMIN . 'emails/attachments/' . $osC_Session->getID();
     if (!file_exists($path)) {
         if (!mkdir($path, 0777)) {
             $error = true;
         }
     }
     if ($error === false) {
         $attachment = new upload('file_upload', $path);
         if (!($attachment->exists() && $attachment->parse() && $attachment->save())) {
             $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'));
     }
     header('Content-type:text/html');
     echo $toC_Json->encode($response);
 }
Exemple #8
0
 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;
 }
Exemple #9
0
 public static function save($id = null, $data)
 {
     global $osC_Database, $osC_Language, $osC_Image;
     $error = false;
     $osC_Database->startTransaction();
     if (is_numeric($id)) {
         $Qproduct = $osC_Database->query('update :table_products set products_quantity = :products_quantity, products_price = :products_price, products_model = :products_model, products_weight = :products_weight, products_weight_class = :products_weight_class, products_status = :products_status, products_tax_class_id = :products_tax_class_id, products_last_modified = now() where products_id = :products_id');
         $Qproduct->bindInt(':products_id', $id);
     } else {
         $Qproduct = $osC_Database->query('insert into :table_products (products_quantity, products_price, products_model, products_weight, products_weight_class, products_status, products_tax_class_id, products_date_added) values (:products_quantity, :products_price, :products_model, :products_weight, :products_weight_class, :products_status, :products_tax_class_id, :products_date_added)');
         $Qproduct->bindRaw(':products_date_added', 'now()');
     }
     $Qproduct->bindTable(':table_products', TABLE_PRODUCTS);
     $Qproduct->bindInt(':products_quantity', $data['quantity']);
     $Qproduct->bindFloat(':products_price', $data['price']);
     $Qproduct->bindValue(':products_model', $data['model']);
     $Qproduct->bindFloat(':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->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();
         }
         $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) {
         $images = array();
         $products_image = new upload('products_image');
         $products_image->set_extensions(array('gif', 'jpg', 'jpeg', 'png'));
         if ($products_image->exists()) {
             $products_image->set_destination(realpath('../images/products/originals'));
             if ($products_image->parse() && $products_image->save()) {
                 $images[] = $products_image->filename;
             }
         }
         if (isset($data['localimages'])) {
             foreach ($data['localimages'] as $image) {
                 $image = basename($image);
                 if (file_exists('../images/products/_upload/' . $image)) {
                     copy('../images/products/_upload/' . $image, '../images/products/originals/' . $image);
                     @unlink('../images/products/_upload/' . $image);
                     $images[] = $image;
                 }
             }
         }
         $default_flag = 1;
         foreach ($images as $image) {
             $Qimage = $osC_Database->query('insert into :table_products_images (products_id, image, default_flag, sort_order, date_added) values (:products_id, :image, :default_flag, :sort_order, :date_added)');
             $Qimage->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
             $Qimage->bindInt(':products_id', $products_id);
             $Qimage->bindValue(':image', $image);
             $Qimage->bindInt(':default_flag', $default_flag);
             $Qimage->bindInt(':sort_order', 0);
             $Qimage->bindRaw(':date_added', 'now()');
             //          $Qimage->setLogging($_SESSION['module'], $products_id);
             $Qimage->execute();
             if ($osC_Database->isError()) {
                 $error = true;
             } else {
                 foreach ($osC_Image->getGroups() as $group) {
                     if ($group['id'] != '1') {
                         $osC_Image->resize($image, $group['id']);
                     }
                 }
             }
             $default_flag = 0;
         }
     }
     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_description = :products_description, products_keyword = :products_keyword, products_tags = :products_tags, products_url = :products_url 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_description, products_keyword, products_tags, products_url) values (:products_id, :language_id, :products_name, :products_description, :products_keyword, :products_tags, :products_url)');
             }
             $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_description', $data['products_description'][$l['id']]);
             $Qpd->bindValue(':products_keyword', $data['products_keyword'][$l['id']]);
             $Qpd->bindValue(':products_tags', $data['products_tags'][$l['id']]);
             $Qpd->bindValue(':products_url', $data['products_url'][$l['id']]);
             //          $Qpd->setLogging($_SESSION['module'], $products_id);
             $Qpd->execute();
             if ($osC_Database->isError()) {
                 $error = true;
                 break;
             }
         }
     }
     if ($error === false) {
         if (isset($data['attributes']) && !empty($data['attributes'])) {
             foreach ($data['attributes'] as $attributes_id => $value) {
                 if (is_array($value)) {
                 } elseif (!empty($value)) {
                     $Qcheck = $osC_Database->query('select id from :table_product_attributes where products_id = :products_id and id = :id limit 1');
                     $Qcheck->bindTable(':table_product_attributes', TABLE_PRODUCT_ATTRIBUTES);
                     $Qcheck->bindInt(':products_id', $products_id);
                     $Qcheck->bindInt(':id', $attributes_id);
                     $Qcheck->execute();
                     if ($Qcheck->numberOfRows() === 1) {
                         $Qattribute = $osC_Database->query('update :table_product_attributes set value = :value where products_id = :products_id and id = :id');
                     } else {
                         $Qattribute = $osC_Database->query('insert into :table_product_attributes (id, products_id, languages_id, value) values (:id, :products_id, :languages_id, :value)');
                         $Qattribute->bindInt(':languages_id', 0);
                     }
                     $Qattribute->bindTable(':table_product_attributes', TABLE_PRODUCT_ATTRIBUTES);
                     $Qattribute->bindValue(':value', $value);
                     $Qattribute->bindInt(':products_id', $products_id);
                     $Qattribute->bindInt(':id', $attributes_id);
                     $Qattribute->execute();
                     if ($osC_Database->isError()) {
                         $error = true;
                         break;
                     }
                 }
             }
         }
     }
     if ($error === false) {
         $variants_array = array();
         $default_variant_combo = null;
         if (isset($data['variants_combo']) && !empty($data['variants_combo'])) {
             foreach ($data['variants_combo'] as $key => $combos) {
                 if (isset($data['variants_combo_db'][$key])) {
                     $Qsubproduct = $osC_Database->query('update :table_products set products_quantity = :products_quantity, products_price = :products_price, products_model = :products_model, products_weight = :products_weight, products_weight_class = :products_weight_class, products_status = :products_status, products_tax_class_id = :products_tax_class_id where products_id = :products_id');
                     $Qsubproduct->bindInt(':products_id', $data['variants_combo_db'][$key]);
                 } else {
                     $Qsubproduct = $osC_Database->query('insert into :table_products (parent_id, products_quantity, products_price, products_model, products_weight, products_weight_class, products_status, products_tax_class_id, products_date_added) values (:parent_id, :products_quantity, :products_price, :products_model, :products_weight, :products_weight_class, :products_status, :products_tax_class_id, :products_date_added)');
                     $Qsubproduct->bindInt(':parent_id', $products_id);
                     $Qsubproduct->bindRaw(':products_date_added', 'now()');
                 }
                 $Qsubproduct->bindTable(':table_products', TABLE_PRODUCTS);
                 $Qsubproduct->bindInt(':products_quantity', $data['variants_quantity'][$key]);
                 $Qsubproduct->bindFloat(':products_price', $data['variants_price'][$key]);
                 $Qsubproduct->bindValue(':products_model', $data['variants_model'][$key]);
                 $Qsubproduct->bindFloat(':products_weight', $data['variants_weight'][$key]);
                 $Qsubproduct->bindInt(':products_weight_class', $data['variants_weight_class'][$key]);
                 $Qsubproduct->bindInt(':products_status', $data['variants_status'][$key]);
                 $Qsubproduct->bindInt(':products_tax_class_id', $data['variants_tax_class_id'][$key]);
                 //            $Qsubproduct->setLogging($_SESSION['module'], $id);
                 $Qsubproduct->execute();
                 if (isset($data['variants_combo_db'][$key])) {
                     $subproduct_id = $data['variants_combo_db'][$key];
                 } else {
                     $subproduct_id = $osC_Database->nextID();
                 }
                 if ($data['variants_default_combo'] == $key) {
                     $default_variant_combo = $subproduct_id;
                 }
                 /*
                             if ( $osC_Database->isError() ) {
                               $error = true;
                               break;
                             }
                 */
                 $combos_array = explode(';', $combos);
                 foreach ($combos_array as $combo) {
                     list($vgroup, $vvalue) = explode('_', $combo);
                     $variants_array[$subproduct_id][] = $vvalue;
                     $check_combos_array[] = $vvalue;
                     $Qcheck = $osC_Database->query('select products_id from :table_products_variants where products_id = :products_id and products_variants_values_id = :products_variants_values_id');
                     $Qcheck->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
                     $Qcheck->bindInt(':products_id', $subproduct_id);
                     $Qcheck->bindInt(':products_variants_values_id', $vvalue);
                     $Qcheck->execute();
                     if ($Qcheck->numberOfRows() < 1) {
                         $Qvcombo = $osC_Database->query('insert into :table_products_variants (products_id, products_variants_values_id) values (:products_id, :products_variants_values_id)');
                         $Qvcombo->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
                         $Qvcombo->bindInt(':products_id', $subproduct_id);
                         $Qvcombo->bindInt(':products_variants_values_id', $vvalue);
                         //                $Qvcombo->setLogging($_SESSION['module'], $products_id);
                         $Qvcombo->execute();
                         if ($osC_Database->isError()) {
                             $error = true;
                             break 2;
                         }
                     }
                 }
             }
         }
         if ($error === false) {
             if (empty($variants_array)) {
                 $Qcheck = $osC_Database->query('select pv.* from :table_products p, :table_products_variants pv where p.parent_id = :parent_id and p.products_id = pv.products_id');
                 $Qcheck->bindTable(':table_products', TABLE_PRODUCTS);
                 $Qcheck->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
                 $Qcheck->bindInt(':parent_id', $products_id);
                 $Qcheck->execute();
                 while ($Qcheck->next()) {
                     $Qdel = $osC_Database->query('delete from :table_products_variants where products_id = :products_id');
                     $Qdel->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
                     $Qdel->bindInt(':products_id', $Qcheck->valueInt('products_id'));
                     $Qdel->execute();
                     $Qdel = $osC_Database->query('delete from :table_products where products_id = :products_id');
                     $Qdel->bindTable(':table_products', TABLE_PRODUCTS);
                     $Qdel->bindInt(':products_id', $Qcheck->valueInt('products_id'));
                     $Qdel->execute();
                 }
             } else {
                 $Qcheck = $osC_Database->query('select pv.* from :table_products p, :table_products_variants pv where p.parent_id = :parent_id and p.products_id = pv.products_id and pv.products_id not in (":products_id")');
                 $Qcheck->bindTable(':table_products', TABLE_PRODUCTS);
                 $Qcheck->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
                 $Qcheck->bindInt(':parent_id', $products_id);
                 $Qcheck->bindRaw(':products_id', implode('", "', array_keys($variants_array)));
                 $Qcheck->execute();
                 while ($Qcheck->next()) {
                     $Qdel = $osC_Database->query('delete from :table_products_variants where products_id = :products_id and products_variants_values_id = :products_variants_values_id');
                     $Qdel->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
                     $Qdel->bindInt(':products_id', $Qcheck->valueInt('products_id'));
                     $Qdel->bindInt(':products_variants_values_id', $Qcheck->valueInt('products_variants_values_id'));
                     $Qdel->execute();
                     $Qdel = $osC_Database->query('delete from :table_products where products_id = :products_id');
                     $Qdel->bindTable(':table_products', TABLE_PRODUCTS);
                     $Qdel->bindInt(':products_id', $Qcheck->valueInt('products_id'));
                     $Qdel->execute();
                 }
                 foreach ($variants_array as $key => $values) {
                     $Qdel = $osC_Database->query('delete from :table_products_variants where products_id = :products_id and products_variants_values_id not in (":products_variants_values_id")');
                     $Qdel->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
                     $Qdel->bindInt(':products_id', $key);
                     $Qdel->bindRaw(':products_variants_values_id', implode('", "', $values));
                     $Qdel->execute();
                 }
             }
         }
         $Qupdate = $osC_Database->query('update :table_products set has_children = :has_children where products_id = :products_id');
         $Qupdate->bindTable(':table_products', TABLE_PRODUCTS);
         $Qupdate->bindInt(':has_children', empty($variants_array) ? 0 : 1);
         $Qupdate->bindInt(':products_id', $products_id);
         $Qupdate->execute();
     }
     if ($error === false) {
         $Qupdate = $osC_Database->query('update :table_products_variants set default_combo = :default_combo where products_id in (":products_id")');
         $Qupdate->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
         $Qupdate->bindInt(':default_combo', 0);
         $Qupdate->bindRaw(':products_id', implode('", "', array_keys($variants_array)));
         $Qupdate->execute();
         if (is_numeric($default_variant_combo)) {
             $Qupdate = $osC_Database->query('update :table_products_variants set default_combo = :default_combo where products_id = :products_id');
             $Qupdate->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
             $Qupdate->bindInt(':default_combo', 1);
             $Qupdate->bindInt(':products_id', $default_variant_combo);
             $Qupdate->execute();
         }
     }
     if ($error === false) {
         $osC_Database->commitTransaction();
         osC_Cache::clear('categories');
         osC_Cache::clear('category_tree');
         osC_Cache::clear('also_purchased');
         return true;
     }
     $osC_Database->rollbackTransaction();
     return false;
 }
 function osC_Products_Importer($parameters)
 {
     parent::toC_Importer($parameters);
     if (!empty($parameters['image_file'])) {
         $this->_image_file = $parameters['image_file'];
         $temp_file = new upload($this->_image_file, DIR_FS_CACHE);
         if ($temp_file->exists() && $temp_file->parse() && $temp_file->save()) {
             require_once '../ext/zip/pclzip.lib.php';
             $archive = new PclZip($temp_file->destination . $temp_file->filename);
             $path = realpath($temp_file->destination . $temp_file->filename);
             if ($archive->extract(PCLZIP_OPT_PATH, realpath(DIR_FS_CATALOG . DIR_WS_IMAGES . 'products/_upload/')) == 0) {
                 return false;
             } else {
                 @unlink($path);
             }
         }
     }
 }
Exemple #11
0
 function save($id = null, $data)
 {
     global $osC_Database, $osC_Language, $osC_Image;
     $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;
                     }
                 }
             }
         }
     }
     //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_images
     if ($error === false) {
         $images = array();
         for ($i = 0; $i < sizeof($_FILES['products_image']['name']); $i++) {
             $_FILES['products_image' . $i] = array('name' => $_FILES['products_image']['name'][$i], 'type' => $_FILES['products_image']['type'][$i], 'size' => $_FILES['products_image']['size'][$i], 'tmp_name' => $_FILES['products_image']['tmp_name'][$i]);
             $products_image = new upload('products_image' . $i);
             if ($products_image->exists()) {
                 $products_image->set_destination(realpath('../images/products/originals'));
                 if ($products_image->parse() && $products_image->save()) {
                     $images[] = $products_image->filename;
                 }
             }
         }
         if (isset($data['localimages'])) {
             foreach ($data['localimages'] as $image) {
                 $image = basename($image);
                 if (file_exists('../images/products/_upload/' . $image)) {
                     copy('../images/products/_upload/' . $image, '../images/products/originals/' . $image);
                     @unlink('../images/products/_upload/' . $image);
                     $images[] = $image;
                 }
             }
         }
         $default_flag = 1;
         foreach ($images as $image) {
             $Qimage = $osC_Database->query('insert into :table_products_images (products_id, image, default_flag, sort_order, date_added) values (:products_id, :image, :default_flag, :sort_order, :date_added)');
             $Qimage->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
             $Qimage->bindInt(':products_id', $products_id);
             $Qimage->bindValue(':image', $image);
             $Qimage->bindInt(':default_flag', $default_flag);
             $Qimage->bindInt(':sort_order', 0);
             $Qimage->bindRaw(':date_added', 'now()');
             $Qimage->setLogging($_SESSION['module'], $products_id);
             $Qimage->execute();
             if ($osC_Database->isError()) {
                 $error = true;
             } else {
                 foreach ($osC_Image->getGroups() as $group) {
                     if ($group['id'] != '1') {
                         $osC_Image->resize($image, $group['id'], 'products');
                     }
                 }
             }
             $default_flag = 0;
         }
     }
     //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_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_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_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_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;
             }
         }
     }
     //check table products_attributes_details and details value
     $is_variants_changed = true;
     if (is_numeric($id)) {
         $Qvariants = $osC_Database->query('select products_variants_id from :table_products_variants where products_id = :products_id');
         $Qvariants->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
         $Qvariants->bindInt(':products_id', $products_id);
         $Qvariants->execute();
         if ($Qvariants->numberOfRows() === sizeof($data['variants_price'])) {
             $old_variants = array();
             $new_variants = array();
             $old_values = array();
             $new_values = array();
             while ($Qvariants->next()) {
                 $Qcheck = $osC_Database->query('select products_variants_groups_id, products_variants_values_id from :table_products_variants_entries where products_variants_id = :products_variants_id');
                 $Qcheck->bindTable(':table_products_variants_entries', TABLE_PRODUCTS_VARIANTS_ENTRIES);
                 $Qcheck->bindInt(':products_variants_id', $Qvariants->valueInt('products_variants_id'));
                 $Qcheck->execute();
                 $variants = array();
                 while ($Qcheck->next()) {
                     $variants[] = $Qcheck->valueInt('products_variants_groups_id') . '_' . $Qcheck->valueInt('products_variants_values_id');
                     $old_values[] = $Qcheck->valueInt('products_variants_groups_id') . '_' . $Qcheck->valueInt('products_variants_values_id');
                 }
                 $old_variants[$Qvariants->valueInt('products_variants_id')] = $variants;
             }
             if (!empty($data['variants_price'])) {
                 foreach ($data['variants_price'] as $key => $vaule) {
                     $new_variants = explode('-', $key);
                     foreach ($new_variants as $tmp) {
                         $new_values[] = $tmp;
                     }
                 }
             }
             $result = array_diff(array_unique($old_values), array_unique($new_values));
             if (empty($result)) {
                 $is_variants_changed = false;
             }
         }
         if ($is_variants_changed === true) {
             $Qdpve = $osC_Database->query('delete from :table_products_variants_entries where products_variants_id in ( select products_variants_id from :table_products_variants where products_id = :products_id )');
             $Qdpve->bindTable(':table_products_variants_entries', TABLE_PRODUCTS_VARIANTS_ENTRIES);
             $Qdpve->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
             $Qdpve->bindInt(':products_id', $products_id);
             $Qdpve->setLogging($_SESSION['module'], $products_id);
             $Qdpve->execute();
             if ($osC_Database->isError()) {
                 $error = true;
             }
             if ($error === false) {
                 $Qdpv = $osC_Database->query('delete from :table_products_variants where products_id = :products_id');
                 $Qdpv->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
                 $Qdpv->bindInt(':products_id', $products_id);
                 $Qdpv->setLogging($_SESSION['module'], $products_id);
                 $Qdpv->execute();
                 if ($osC_Database->isError()) {
                     $error = true;
                 }
             }
         }
     }
     //  insert or update products_attributes_details and detials value
     if ($error === false) {
         if (isset($data['variants_price'])) {
             if ($is_variants_changed === true) {
                 $products_quantity = 0;
                 foreach ($data['variants_price'] as $key => $vaule) {
                     $Qpv = $osC_Database->query('insert into :table_products_variants (products_id, products_price, products_sku, products_model, products_quantity, products_weight, products_status) values (:products_id, :products_price, :products_sku, :products_model, :products_quantity, :products_weight, :products_status)');
                     $Qpv->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
                     $Qpv->bindInt(':products_id', $products_id);
                     $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]);
                     $Qpv->execute();
                     if ($osC_Database->isError()) {
                         $error = true;
                         break;
                     } else {
                         $products_variants_id = $osC_Database->nextID();
                         if ($data['variants_status'][$key] == '1') {
                             $products_quantity += $data['variants_quantity'][$key];
                         }
                     }
                     if ($error === false) {
                         $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;
                             }
                         }
                     }
                 }
             } else {
                 $products_quantity = 0;
                 foreach ($data['variants_price'] as $key => $vaule) {
                     $assigned_variants = explode('-', $key);
                     foreach ($old_variants as $products_variants_id => $variants) {
                         $result = array_diff($variants, $assigned_variants);
                         if (empty($result)) {
                             $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 where products_variants_id = :products_variants_id');
                             $Qpv->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
                             $Qpv->bindInt(':products_variants_id', $products_variants_id);
                             $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]);
                             $Qpv->setLogging($_SESSION['module'], $products_id);
                             $Qpv->execute();
                             //break variants search loop
                             if ($osC_Database->isError()) {
                                 $error = true;
                                 break;
                             }
                         }
                     }
                     //break variants update loop
                     if ($error === true) {
                         break;
                     }
                     if ($data['variants_status'][$key] == '1') {
                         $products_quantity += $data['variants_quantity'][$key];
                     }
                 }
             }
             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;
                 }
             }
         }
     }
     //  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;
                     }
                 }
             }
         }
     }
     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;
                     }
                 }
             }
         }
     }
     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 true;
     }
     $osC_Database->rollbackTransaction();
     return false;
 }
Exemple #12
0
 function save($id = null, $data)
 {
     global $osC_Database, $osC_Language;
     $error = false;
     $osC_Database->startTransaction();
     if (is_numeric($id)) {
         $Qmanufacturer = $osC_Database->query('update :table_manufacturers set manufacturers_name = :manufacturers_name, last_modified = now() where manufacturers_id = :manufacturers_id');
         $Qmanufacturer->bindInt(':manufacturers_id', $id);
     } else {
         $Qmanufacturer = $osC_Database->query('insert into :table_manufacturers (manufacturers_name, date_added) values (:manufacturers_name, now())');
     }
     $Qmanufacturer->bindTable(':table_manufacturers', TABLE_MANUFACTURERS);
     $Qmanufacturer->bindValue(':manufacturers_name', $data['name']);
     $Qmanufacturer->setLogging($_SESSION['module'], $id);
     $Qmanufacturer->execute();
     if (!$osC_Database->isError()) {
         if (is_numeric($id)) {
             $manufacturers_id = $id;
         } else {
             $manufacturers_id = $osC_Database->nextID();
         }
         $image = new upload('manufacturers_image', realpath('../' . DIR_WS_IMAGES . 'manufacturers'));
         if ($image->exists()) {
             if ($image->parse() && $image->save()) {
                 $Qimage = $osC_Database->query('update :table_manufacturers set manufacturers_image = :manufacturers_image where manufacturers_id = :manufacturers_id');
                 $Qimage->bindTable(':table_manufacturers', TABLE_MANUFACTURERS);
                 $Qimage->bindValue(':manufacturers_image', $image->filename);
                 $Qimage->bindInt(':manufacturers_id', $manufacturers_id);
                 $Qimage->setLogging($_SESSION['module'], $manufacturers_id);
                 $Qimage->execute();
                 if ($osC_Database->isError()) {
                     $error = true;
                 }
             }
         }
     } else {
         $error = true;
     }
     if ($error === false) {
         foreach ($osC_Language->getAll() as $l) {
             if (is_numeric($id)) {
                 $Qurl = $osC_Database->query('update :table_manufacturers_info set manufacturers_url = :manufacturers_url where manufacturers_id = :manufacturers_id and languages_id = :languages_id');
             } else {
                 $Qurl = $osC_Database->query('insert into :table_manufacturers_info (manufacturers_id, languages_id, manufacturers_url) values (:manufacturers_id, :languages_id, :manufacturers_url)');
             }
             $Qurl->bindTable(':table_manufacturers_info', TABLE_MANUFACTURERS_INFO);
             $Qurl->bindInt(':manufacturers_id', $manufacturers_id);
             $Qurl->bindInt(':languages_id', $l['id']);
             $Qurl->bindValue(':manufacturers_url', $data['url'][$l['id']]);
             $Qurl->setLogging($_SESSION['module'], $manufacturers_id);
             $Qurl->execute();
             if ($osC_Database->isError()) {
                 $error = true;
                 break;
             }
         }
     }
     if ($error === false) {
         $osC_Database->commitTransaction();
         osC_Cache::clear('manufacturers');
         osC_Cache::clear('sefu-manufacturers');
         return true;
     }
     $osC_Database->rollbackTransaction();
     return false;
 }
 public function add($product_id, $quantity = null)
 {
     global $lC_Database, $lC_Services, $lC_Language, $lC_Customer, $lC_Product;
     if (!is_numeric($product_id)) {
         return false;
     }
     $Qproduct = $lC_Database->query('select p.*, i.image from :table_products p left join :table_products_images i on (p.products_id = i.products_id and i.default_flag = :default_flag) where p.products_id = :products_id');
     $Qproduct->bindTable(':table_products', TABLE_PRODUCTS);
     $Qproduct->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
     $Qproduct->bindInt(':default_flag', 1);
     $Qproduct->bindInt(':products_id', $product_id);
     $Qproduct->execute();
     if ($Qproduct->value('image') == null) {
         // check for parent image
         $Qimage = $lC_Database->query('select image from :table_products_images where products_id = :parent_id');
         $Qimage->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
         $Qimage->bindInt(':default_flag', 1);
         $Qimage->bindInt(':parent_id', $Qproduct->valueInt('parent_id'));
         $Qimage->execute();
         $image = $Qimage->value('image');
     } else {
         $image = $Qproduct->value('image');
     }
     if ($Qproduct->valueInt('products_status') === 1) {
         if ($this->exists($product_id)) {
             $item_id = $this->getBasketID($product_id);
             if (is_numeric($quantity)) {
                 $quantity = $this->getQuantity($item_id) + 1;
             }
             $this->_contents[$item_id]['quantity'] = $quantity;
             if ($lC_Customer->isLoggedOn()) {
                 $Qupdate = $lC_Database->query('update :table_shopping_carts set quantity = :quantity where customers_id = :customers_id and item_id = :item_id');
                 $Qupdate->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS);
                 $Qupdate->bindInt(':quantity', $quantity);
                 $Qupdate->bindInt(':customers_id', $lC_Customer->getID());
                 $Qupdate->bindInt(':item_id', $item_id);
                 $Qupdate->execute();
             }
         } else {
             if (!is_numeric($quantity)) {
                 $quantity = 1;
             }
             $Qdescription = $lC_Database->query('select products_name, products_keyword, products_description, products_tags, products_url from :table_products_description where products_id = :products_id and language_id = :language_id');
             $Qdescription->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
             $Qdescription->bindInt(':products_id', $product_id);
             $Qdescription->bindInt(':language_id', $lC_Language->getID());
             $Qdescription->execute();
             $desc = $Qdescription->toArray();
             if ($Qproduct->valueInt('parent_id') > 0) {
                 $Qmaster = $lC_Database->query('select products_name as parent_name, products_description as description, products_keyword as keyword, products_tags as tags, products_url as url from :table_products_description where products_id = :products_id and language_id = :language_id limit 1');
                 $Qmaster->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
                 $Qmaster->bindInt(':products_id', $Qproduct->valueInt('parent_id'));
                 $Qmaster->bindInt(':language_id', $lC_Language->getID());
                 $Qmaster->execute();
                 if ($Qproduct->valueInt('is_subproduct') > 0) {
                     $desc['products_name'] = $Qmaster->value('parent_name') . ' - ' . $desc['products_name'];
                 } else {
                     $desc['products_name'] = $Qmaster->value('parent_name');
                 }
                 $desc['products_description'] = $Qmaster->value('description');
                 $desc['products_keyword'] = $Qmaster->value('keyword');
                 $desc['products_tags'] = $Qmaster->value('tags');
                 $desc['products_url'] = $Qmaster->value('url');
             }
             // we get the product price from the product class - price already includes options, etc.
             if (!isset($lC_Product)) {
                 $lC_Product = new lC_Product($product_id);
             }
             $price = $lC_Product->getPrice($product_id, $lC_Customer->getCustomerGroup(), $_POST);
             if ($lC_Customer->isLoggedOn()) {
                 $Qid = $lC_Database->query('select max(item_id) as item_id from :table_shopping_carts where customers_id = :customers_id');
                 $Qid->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS);
                 $Qid->bindInt(':customers_id', $lC_Customer->getID());
                 $Qid->execute();
                 $item_id = $Qid->valueInt('item_id') + 1;
             } else {
                 if (empty($this->_contents)) {
                     $item_id = 1;
                 } else {
                     $item_id = max(array_keys($this->_contents)) + 1;
                 }
             }
             $this->_contents[$item_id] = array('item_id' => $item_id, 'id' => $product_id, 'parent_id' => $Qproduct->valueInt('parent_id'), 'name' => $desc['products_name'], 'model' => $Qproduct->value('products_model'), 'sku' => $Qproduct->value('products_sku'), 'keyword' => $desc['products_keyword'], 'tags' => $desc['products_tags'], 'url' => $desc['products_url'], 'description' => $desc['products_description'], 'image' => $image, 'price' => $price, 'quantity' => $quantity, 'weight' => $Qproduct->value('products_weight'), 'tax_class_id' => $Qproduct->valueInt('products_tax_class_id'), 'date_added' => lC_DateTime::getShort(lC_DateTime::getNow()), 'weight_class_id' => $Qproduct->valueInt('products_weight_class'));
             // simple options
             if (isset($_POST['simple_options']) && empty($_POST['simple_options']) === false) {
                 foreach ($_POST['simple_options'] as $options_id => $values_id) {
                     if (is_array($values_id)) {
                         $text_value = current($values_id);
                         // for text fields
                         $values_id = key($values_id);
                     }
                     $QsimpleOptionsValues = $lC_Database->query('select price_modifier from :table_products_simple_options_values where options_id = :options_id and values_id = :values_id and customers_group_id = :customers_group_id');
                     $QsimpleOptionsValues->bindTable(':table_products_simple_options_values', TABLE_PRODUCTS_SIMPLE_OPTIONS_VALUES);
                     $QsimpleOptionsValues->bindInt(':options_id', $options_id);
                     $QsimpleOptionsValues->bindInt(':values_id', $values_id);
                     $QsimpleOptionsValues->bindInt(':customers_group_id', '1');
                     $QsimpleOptionsValues->execute();
                     $Qvariants = $lC_Database->query('select pvg.title as group_title, pvg.module, pvv.title as value_title from :table_products_variants_groups pvg, :table_products_variants_values pvv where pvg.id = :options_id and pvv.id = :values_id and pvv.languages_id = :languages_id and pvv.products_variants_groups_id = pvg.id and pvg.languages_id = :languages_id limit 1');
                     $Qvariants->bindTable(':table_products_variants_groups', TABLE_PRODUCTS_VARIANTS_GROUPS);
                     $Qvariants->bindTable(':table_products_variants_values', TABLE_PRODUCTS_VARIANTS_VALUES);
                     $Qvariants->bindInt(':options_id', $options_id);
                     $Qvariants->bindInt(':values_id', $values_id);
                     $Qvariants->bindInt(':languages_id', $lC_Language->getID());
                     $Qvariants->bindInt(':languages_id', $lC_Language->getID());
                     $Qvariants->execute();
                     if (strstr($Qvariants->value('module'), 'file_upload')) {
                         $group_title = is_array($_FILES['simple_options_upload']['name']) && count($_FILES['simple_options_upload']['name']) > 2 ? $lC_Language->get('text_label_files') : $lC_Language->get('text_label_file');
                         $value_title = is_array($_FILES['simple_options_upload']['name']) ? implode(', ', $_FILES['simple_options_upload']['name']) : $_FILES['simple_options_upload']['name'];
                         if (substr($value_title, -2) == ', ') {
                             $value_title = substr($value_title, 0, -2);
                         }
                         $value_title = str_replace(', ,', ', ', $value_title);
                         if ($value_title == '') {
                             $group_title = '';
                         }
                         if (is_array($_FILES['simple_options_upload']['name'])) {
                             $filesArr = $_FILES;
                             $_SESSION['file_upload'] = $_FILES['simple_options_upload'];
                             foreach ($filesArr['simple_options_upload']['name'] as $key => $file) {
                                 $_FILES = array('simple_options_upload' => array('name' => $file, 'type' => $filesArr['simple_options_upload']['type'][$key], 'tmp_name' => $filesArr['simple_options_upload']['tmp_name'][$key], 'error' => $filesArr['simple_options_upload']['error'][$key], 'size' => $filesArr['simple_options_upload']['size'][$key]));
                                 // upload the file
                                 $image = new upload('simple_options_upload', realpath('pub'));
                                 if ($image->exists()) {
                                     if ($image->parse() && $image->save()) {
                                         // success
                                     }
                                 }
                             }
                         }
                     } else {
                         if ($Qvariants->value('module') == 'text_field') {
                             $group_title = $Qvariants->value('group_title');
                             $value_title = $text_value;
                         } else {
                             $group_title = $Qvariants->value('group_title');
                             $value_title = $Qvariants->value('value_title');
                         }
                     }
                     $this->_contents[$item_id]['simple_options'][] = array('value_id' => $values_id, 'group_id' => $options_id, 'group_title' => $group_title, 'value_title' => $value_title, 'price_modifier' => $QsimpleOptionsValues->valueDecimal('price_modifier'));
                     $QsimpleOptionsValues->freeResult();
                     $Qvariants->freeResult();
                 }
             }
             if ($lC_Customer->isLoggedOn()) {
                 $Qnew = $lC_Database->query('insert into :table_shopping_carts (customers_id, item_id, products_id, quantity, meta_data, date_added) values (:customers_id, :item_id, :products_id, :quantity, :meta_data, :date_added)');
                 $Qnew->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS);
                 $Qnew->bindInt(':customers_id', $lC_Customer->getID());
                 $Qnew->bindInt(':item_id', $item_id);
                 $Qnew->bindInt(':products_id', $product_id);
                 $Qnew->bindInt(':quantity', $quantity);
                 $Qnew->bindValue(':meta_data', serialize($this->_contents[$item_id]['simple_options']));
                 $Qnew->bindRaw(':date_added', 'now()');
                 $Qnew->execute();
             }
             if ($Qproduct->valueInt('parent_id') > 0) {
                 $Qvariant = $lC_Database->query('select pvg.id as group_id, pvg.title as group_title, pvg.module, pvv.id as value_id, pvv.title as value_title from :table_products_variants pv, :table_products_variants_values pvv, :table_products_variants_groups pvg where pv.products_id = :products_id and pv.products_variants_values_id = pvv.id and pvv.languages_id = :languages_id and pvv.products_variants_groups_id = pvg.id and pvg.languages_id = :languages_id');
                 $Qvariant->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
                 $Qvariant->bindTable(':table_products_variants_values', TABLE_PRODUCTS_VARIANTS_VALUES);
                 $Qvariant->bindTable(':table_products_variants_groups', TABLE_PRODUCTS_VARIANTS_GROUPS);
                 $Qvariant->bindInt(':products_id', $product_id);
                 $Qvariant->bindInt(':languages_id', $lC_Language->getID());
                 $Qvariant->bindInt(':languages_id', $lC_Language->getID());
                 $Qvariant->execute();
                 while ($Qvariant->next()) {
                     $group_title = lC_Variants::getGroupTitle($Qvariant->value('module'), $Qvariant->toArray());
                     $value_title = lC_Variants::getValueTitle($Qvariant->value('module'), $Qvariant->toArray());
                     $has_custom_value = lC_Variants::hasCustomValue($Qvariant->value('module'));
                     if (strstr($Qvariant->value('module'), 'file_upload')) {
                         $group_title = is_array($_FILES['variants_upload']['name']) && count($_FILES['variants_upload']['name']) > 2 ? $lC_Language->get('text_label_files') : $lC_Language->get('text_label_file');
                         $value_title = is_array($_FILES['variants_upload']['name']) ? implode(', ', $_FILES['variants_upload']['name']) : $_FILES['variants_upload']['name'];
                         if (substr($value_title, -2) == ', ') {
                             $value_title = substr($value_title, 0, -2);
                         }
                         if (is_array($_FILES['variants_upload']['name'])) {
                             $filesArr = $_FILES;
                             $_SESSION['file_upload'] = $_FILES['variants_upload'];
                             foreach ($filesArr['variants_upload']['name'] as $key => $file) {
                                 $_FILES = array('variants_upload' => array('name' => $file, 'type' => $filesArr['variants_upload']['type'][$key], 'tmp_name' => $filesArr['variants_upload']['tmp_name'][$key], 'error' => $filesArr['variants_upload']['error'][$key], 'size' => $filesArr['variants_upload']['size'][$key]));
                                 // upload the file
                                 $image = new upload('variants_upload', realpath('pub'));
                                 if ($image->exists()) {
                                     if ($image->parse() && $image->save()) {
                                         // success
                                     }
                                 }
                             }
                         }
                     } else {
                         if ($Qvariant->value('module') == 'text_field') {
                             $group_title = $Qvariant->value('group_title');
                         } else {
                             $group_title = $Qvariant->value('group_title');
                             $value_title = $Qvariant->value('value_title');
                         }
                     }
                     $this->_contents[$item_id]['variants'][] = array('group_id' => $Qvariant->valueInt('group_id'), 'value_id' => $Qvariant->valueInt('value_id'), 'group_title' => $group_title, 'value_title' => $value_title, 'has_custom_value' => $has_custom_value);
                     if ($lC_Customer->isLoggedOn() && $has_custom_value === true) {
                         $Qnew = $lC_Database->query('insert into :table_shopping_carts_custom_variants_values (shopping_carts_item_id, customers_id, products_id, products_variants_values_id, products_variants_values_text) values (:shopping_carts_item_id, :customers_id, :products_id, :products_variants_values_id, :products_variants_values_text)');
                         $Qnew->bindTable(':table_shopping_carts_custom_variants_values', TABLE_SHOPPING_CARTS_CUSTOM_VARIANTS_VALUES);
                         $Qnew->bindInt(':shopping_carts_item_id', $item_id);
                         $Qnew->bindInt(':customers_id', $lC_Customer->getID());
                         $Qnew->bindInt(':products_id', $product_id);
                         $Qnew->bindInt(':products_variants_values_id', $Qvariant->valueInt('value_id'));
                         $Qnew->bindValue(':products_variants_values_text', $value_title);
                         $Qnew->execute();
                     }
                 }
             }
         }
         $this->_cleanUp();
         $this->_calculate();
     }
 }
Exemple #14
0
 public static function save($id = null, $data)
 {
     global $osC_Database, $osC_Language;
     $category_id = '';
     $error = false;
     $osC_Database->startTransaction();
     if (is_numeric($id)) {
         $Qcat = $osC_Database->query('update :table_categories set sort_order = :sort_order, last_modified = now() where categories_id = :categories_id');
         $Qcat->bindInt(':categories_id', $id);
     } else {
         $Qcat = $osC_Database->query('insert into :table_categories (parent_id, sort_order, date_added) values (:parent_id, :sort_order, now())');
         $Qcat->bindInt(':parent_id', $data['parent_id']);
     }
     $Qcat->bindTable(':table_categories', TABLE_CATEGORIES);
     $Qcat->bindInt(':sort_order', $data['sort_order']);
     $Qcat->setLogging($_SESSION['module'], $id);
     $Qcat->execute();
     if (!$osC_Database->isError()) {
         $category_id = is_numeric($id) ? $id : $osC_Database->nextID();
         foreach ($osC_Language->getAll() as $l) {
             if (is_numeric($id)) {
                 $Qcd = $osC_Database->query('update :table_categories_description set categories_name = :categories_name where categories_id = :categories_id and language_id = :language_id');
             } else {
                 $Qcd = $osC_Database->query('insert into :table_categories_description (categories_id, language_id, categories_name) values (:categories_id, :language_id, :categories_name)');
             }
             $Qcd->bindTable(':table_categories_description', TABLE_CATEGORIES_DESCRIPTION);
             $Qcd->bindInt(':categories_id', $category_id);
             $Qcd->bindInt(':language_id', $l['id']);
             $Qcd->bindValue(':categories_name', $data['name'][$l['id']]);
             $Qcd->setLogging($_SESSION['module'], $category_id);
             $Qcd->execute();
             if ($osC_Database->isError()) {
                 $error = true;
                 break;
             }
         }
         if ($error === false) {
             $categories_image = new upload($data['image'], realpath('../' . DIR_WS_IMAGES . 'categories'));
             if ($categories_image->exists() && $categories_image->parse() && $categories_image->save()) {
                 $Qcf = $osC_Database->query('update :table_categories set categories_image = :categories_image where categories_id = :categories_id');
                 $Qcf->bindTable(':table_categories', TABLE_CATEGORIES);
                 $Qcf->bindValue(':categories_image', $categories_image->filename);
                 $Qcf->bindInt(':categories_id', $category_id);
                 $Qcf->setLogging($_SESSION['module'], $category_id);
                 $Qcf->execute();
                 if ($osC_Database->isError()) {
                     $error = true;
                 }
             }
         }
     }
     if ($error === false) {
         $osC_Database->commitTransaction();
         osC_Cache::clear('categories');
         osC_Cache::clear('category_tree');
         osC_Cache::clear('also_purchased');
         return true;
     }
     $osC_Database->rollbackTransaction();
     return false;
 }
Exemple #15
0
 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;
 }
Exemple #16
0
 public static function save($id = null, $data)
 {
     global $lC_Database, $lC_Language, $lC_Image, $lC_CategoryTree;
     $error = false;
     $lC_Database->startTransaction();
     if (is_numeric($id)) {
         $Qproduct = $lC_Database->query('update :table_products set parent_id = :parent_id, products_quantity = :products_quantity, products_cost = :products_cost, products_price = :products_price, products_msrp = :products_msrp, products_model = :products_model, products_sku = :products_sku, products_weight = :products_weight, products_weight_class = :products_weight_class, products_status = :products_status, groups_pricing_enable = :groups_pricing_enable, qpb_pricing_enable = :qpb_pricing_enable, specials_pricing_enable = :specials_pricing_enable, products_tax_class_id = :products_tax_class_id, products_last_modified = now(), products_sort_order = :products_sort_order where products_id = :products_id');
         $Qproduct->bindInt(':products_id', $id);
     } else {
         $Qproduct = $lC_Database->query('insert into :table_products (parent_id, products_quantity, products_cost, products_price, products_msrp, products_model, products_sku, products_weight, products_weight_class, products_status, products_tax_class_id, products_ordered, products_date_added, groups_pricing_enable, qpb_pricing_enable, specials_pricing_enable, products_sort_order) values (:parent_id, :products_quantity, :products_cost, :products_price, :products_msrp, :products_model, :products_sku, :products_weight, :products_weight_class, :products_status, :products_tax_class_id, :products_ordered, :products_date_added, :groups_pricing_enable, :qpb_pricing_enable, :specials_pricing_enable, :products_sort_order)');
         $Qproduct->bindRaw(':products_date_added', 'now()');
         $Qproduct->bindInt(':products_ordered', $data['products_ordered']);
     }
     // set parent status
     if (isset($_POST['products_status']) && $_POST['products_status'] == 'active') {
         $data['status'] = 1;
     }
     if (isset($_POST['products_status']) && $_POST['products_status'] == 'inactive') {
         $data['status'] = -1;
     }
     if (isset($_POST['products_status']) && $_POST['products_status'] == 'recurring') {
         $data['status'] = 0;
     }
     $Qproduct->bindTable(':table_products', TABLE_PRODUCTS);
     $Qproduct->bindInt(':parent_id', $data['parent_id']);
     $Qproduct->bindInt(':products_quantity', $data['quantity']);
     $Qproduct->bindFloat(':products_cost', $data['cost']);
     $Qproduct->bindFloat(':products_price', $data['price']);
     $Qproduct->bindFloat(':products_msrp', $data['msrp']);
     $Qproduct->bindValue(':products_model', $data['model']);
     $Qproduct->bindValue(':products_sku', $data['sku']);
     $Qproduct->bindFloat(':products_weight', $data['weight']);
     $Qproduct->bindInt(':products_weight_class', $data['weight_class']);
     $Qproduct->bindInt(':products_tax_class_id', $data['tax_class_id']);
     $Qproduct->bindInt(':products_status', $data['status']);
     $Qproduct->bindInt(':groups_pricing_enable', $data['groups_pricing_switch']);
     $Qproduct->bindInt(':qpb_pricing_enable', $data['qpb_pricing_switch']);
     $Qproduct->bindInt(':specials_pricing_enable', $data['specials_pricing_switch']);
     $Qproduct->bindInt(':products_sort_order', $data['products_sort_order']);
     $Qproduct->setLogging($_SESSION['module'], $id);
     $Qproduct->execute();
     if (is_numeric($id)) {
         $products_id = $id;
     } else {
         $products_id = $lC_Database->nextID();
     }
     // products to categories
     if ($lC_Database->isError()) {
         $error = true;
     } else {
         $Qcategories = $lC_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 ($lC_Database->isError()) {
             $error = true;
         } else {
             if (isset($data['categories']) && !empty($data['categories'])) {
                 foreach ($data['categories'] as $category_id) {
                     $Qp2c = $lC_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 ($lC_Database->isError()) {
                         $error = true;
                         break;
                     }
                 }
             }
         }
     }
     // product images
     if ($error === false) {
         $images = array();
         $products_image = new upload('products_image');
         $products_image->set_extensions(array('gif', 'jpg', 'jpeg', 'png'));
         if ($products_image->exists()) {
             $products_image->set_destination(realpath('../images/products/originals'));
             if ($products_image->parse() && $products_image->save()) {
                 $images[] = $products_image->filename;
             }
         }
         if (isset($data['localimages'])) {
             foreach ($data['localimages'] as $image) {
                 $image = basename($image);
                 if (@file_exists('../images/products/_upload/' . $image)) {
                     copy('../images/products/_upload/' . $image, '../images/products/originals/' . $image);
                     @unlink('../images/products/_upload/' . $image);
                     $images[] = $image;
                 }
             }
         }
         $default_flag = 1;
         foreach ($images as $image) {
             $Qimage = $lC_Database->query('insert into :table_products_images (products_id, image, default_flag, sort_order, date_added) values (:products_id, :image, :default_flag, :sort_order, :date_added)');
             $Qimage->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
             $Qimage->bindInt(':products_id', $products_id);
             $Qimage->bindValue(':image', $image);
             $Qimage->bindInt(':default_flag', $default_flag);
             $Qimage->bindInt(':sort_order', 0);
             $Qimage->bindRaw(':date_added', 'now()');
             $Qimage->setLogging($_SESSION['module'], $products_id);
             $Qimage->execute();
             if ($lC_Database->isError()) {
                 $error = true;
             } else {
                 foreach ($lC_Image->getGroups() as $group) {
                     if ($group['id'] != '1') {
                         $lC_Image->resize($image, $group['id']);
                     }
                 }
             }
             $default_flag = 0;
         }
     }
     // product description
     if ($error === false) {
         if (isset($data['categories']) && !empty($data['categories'])) {
             $cPath = $lC_CategoryTree->getcPath($data['categories'][0]);
         } else {
             $cPath = $category_id != '' ? $lC_CategoryTree->getcPath($category_id) : 0;
         }
         foreach ($lC_Language->getAll() as $l) {
             // this code will be revisited
             // if (self::validatePermalink($data['products_keyword'][$l['id']], $id, 2, $l['id']) != 1) {
             //   $data['products_keyword'][$l['id']] = $data['products_keyword'][$l['id']] . '-link';
             // }
             // check to see if the DB entry exists for the selected language
             $Qchk1 = $lC_Database->query('select products_description from :table_products_description where products_id = :products_id and language_id = :language_id limit 1');
             $Qchk1->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
             $Qchk1->bindInt(':products_id', $products_id);
             $Qchk1->bindInt(':language_id', $l['id']);
             $Qchk1->execute();
             if (is_numeric($id) && $Qchk1->numberOfRows() == 1) {
                 $Qpd = $lC_Database->query('update :table_products_description set products_name = :products_name, products_blurb = :products_blurb, products_description = :products_description, products_keyword = :products_keyword, products_tags = :products_tags, products_url = :products_url where products_id = :products_id and language_id = :language_id');
             } else {
                 $Qpd = $lC_Database->query('insert into :table_products_description (products_id, language_id, products_name, products_blurb, products_description, products_keyword, products_tags, products_url) values (:products_id, :language_id, :products_name, :products_blurb, :products_description, :products_keyword, :products_tags, :products_url)');
             }
             $Qchk1->freeResult();
             $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_blurb', $data['products_blurb'][$l['id']]);
             $Qpd->bindValue(':products_description', $data['products_description'][$l['id']]);
             $Qpd->bindValue(':products_keyword', $data['products_keyword'][$l['id']]);
             $Qpd->bindValue(':products_tags', $data['products_tags'][$l['id']]);
             $Qpd->bindValue(':products_url', $data['products_url'][$l['id']]);
             $Qpd->setLogging($_SESSION['module'], $products_id);
             $Qpd->execute();
             if ($lC_Database->isError()) {
                 $error = true;
                 break;
             }
             // check to see if the DB entry exists for the selected language
             $Qchk2 = $lC_Database->query('select products_description from :table_permalinks where item_id = :item_id and language_id = :language_id limit 1');
             $Qchk2->bindTable(':table_permalinks', TABLE_PERMALINKS);
             $Qchk2->bindInt(':item_id', $products_id);
             $Qchk2->bindInt(':language_id', $l['id']);
             $Qchk2->execute();
             // added for permalink
             if (is_numeric($id) && $Qchk2->numberOfRows() == 1) {
                 $Qpl = $lC_Database->query('update :table_permalinks set permalink = :permalink, query = :query where item_id = :item_id and type = :type and language_id = :language_id');
             } else {
                 $Qpl = $lC_Database->query('insert into :table_permalinks (item_id, language_id, type, query, permalink) values (:item_id, :language_id, :type, :query, :permalink)');
             }
             $Qchk2->freeResult();
             $Qpl->bindTable(':table_permalinks', TABLE_PERMALINKS);
             $Qpl->bindInt(':item_id', $products_id);
             $Qpl->bindInt(':language_id', $l['id']);
             $Qpl->bindInt(':type', 2);
             $Qpl->bindValue(':query', 'cPath=' . $cPath);
             $Qpl->bindValue(':permalink', $data['products_keyword'][$l['id']]);
             $Qpl->setLogging($_SESSION['module'], $products_id);
             $Qpl->execute();
             if ($lC_Database->isError()) {
                 $error = true;
                 break;
             }
         }
     }
     // product attributes
     if ($error === false) {
         if (isset($data['attributes']) && !empty($data['attributes'])) {
             foreach ($data['attributes'] as $attributes_id => $value) {
                 if (is_array($value)) {
                 } elseif (!empty($value) && $value != 'NULL') {
                     $Qcheck = $lC_Database->query('select id from :table_product_attributes where products_id = :products_id and id = :id limit 1');
                     $Qcheck->bindTable(':table_product_attributes', TABLE_PRODUCT_ATTRIBUTES);
                     $Qcheck->bindInt(':products_id', $products_id);
                     $Qcheck->bindInt(':id', $attributes_id);
                     $Qcheck->execute();
                     if ($Qcheck->numberOfRows() === 1) {
                         $Qattribute = $lC_Database->query('update :table_product_attributes set value = :value, value2 = :value2 where products_id = :products_id and id = :id');
                     } else {
                         $Qattribute = $lC_Database->query('insert into :table_product_attributes (id, products_id, languages_id, value, value2) values (:id, :products_id, :languages_id, :value, :value2)');
                         $Qattribute->bindInt(':languages_id', $lC_Language->getID());
                     }
                     // support for 2nd value such as end date
                     $value2 = isset($data['attributes2'][$attributes_id]) && $data['attributes2'][$attributes_id] != null ? $data['attributes2'][$attributes_id] : '';
                     $Qattribute->bindTable(':table_product_attributes', TABLE_PRODUCT_ATTRIBUTES);
                     $Qattribute->bindValue(':value', $value);
                     $Qattribute->bindValue(':value2', $value2);
                     $Qattribute->bindInt(':products_id', $products_id);
                     $Qattribute->bindInt(':id', $attributes_id);
                     $Qattribute->execute();
                     if ($lC_Database->isError()) {
                         $error = true;
                         break;
                     }
                 }
             }
         }
     }
     // simple options
     if ($error === false) {
         // delete the simple options
         $Qdel = $lC_Database->query('delete from :table_products_simple_options where products_id = :products_id');
         $Qdel->bindTable(':table_products_simple_options', TABLE_PRODUCTS_SIMPLE_OPTIONS);
         $Qdel->bindInt(':products_id', $products_id);
         $Qdel->setLogging($_SESSION['module'], $products_id);
         $Qdel->execute();
         // delete the simple options values
         $Qdel = $lC_Database->query('delete from :table_products_simple_options_values where products_id = :products_id');
         $Qdel->bindTable(':table_products_simple_options_values', TABLE_PRODUCTS_SIMPLE_OPTIONS_VALUES);
         $Qdel->bindInt(':products_id', $products_id);
         $Qdel->setLogging($_SESSION['module'], $products_id);
         $Qdel->execute();
         // if values are set, save them
         if (isset($data['simple_options_group_name']) && !empty($data['simple_options_group_name'])) {
             foreach ($data['simple_options_group_name'] as $group_id => $value) {
                 // add the new option
                 $Qoptions = $lC_Database->query('insert into :table_products_simple_options (options_id, products_id, sort_order, status) values (:options_id, :products_id, :sort_order, :status)');
                 $Qoptions->bindTable(':table_products_simple_options', TABLE_PRODUCTS_SIMPLE_OPTIONS);
                 $Qoptions->bindInt(':options_id', $group_id);
                 $Qoptions->bindInt(':products_id', $products_id);
                 $Qoptions->bindInt(':sort_order', $data['simple_options_group_sort_order'][$group_id]);
                 $Qoptions->bindInt(':status', $data['simple_options_group_status'][$group_id]);
                 $Qoptions->setLogging($_SESSION['module'], $products_id);
                 $Qoptions->execute();
                 if ($lC_Database->isError()) {
                     $error = true;
                     break;
                 }
                 // add the new option values
                 if (is_array($data['simple_options_entry_price_modifier'])) {
                     foreach ($data['simple_options_entry_price_modifier'] as $customers_group_id => $options) {
                         foreach ($options as $options_id => $option_value) {
                             if ($options_id == $group_id) {
                                 foreach ($option_value as $values_id => $price_modifier) {
                                     // Added for simple options values sort order
                                     // based for now on variants values sort order globally across all products
                                     $Qsortorder = $lC_Database->query('select sort_order FROM :table_products_variants_values where id = :id');
                                     $Qsortorder->bindTable(':table_products_variants_values', TABLE_PRODUCTS_VARIANTS_VALUES);
                                     $Qsortorder->bindInt(':id', $values_id);
                                     $Qsortorder->execute();
                                     $Qoptval = $lC_Database->query('insert into :table_products_simple_options_values (products_id, values_id, options_id, customers_group_id, price_modifier, sort_order) values (:products_id, :values_id, :options_id, :customers_group_id, :price_modifier, :sort_order)');
                                     $Qoptval->bindTable(':table_products_simple_options_values', TABLE_PRODUCTS_SIMPLE_OPTIONS_VALUES);
                                     $Qoptval->bindInt(':products_id', $products_id);
                                     $Qoptval->bindInt(':values_id', $values_id);
                                     $Qoptval->bindInt(':options_id', $options_id);
                                     $Qoptval->bindInt(':customers_group_id', $customers_group_id);
                                     $Qoptval->bindInt(':sort_order', $Qsortorder->valueInt('sort_order'));
                                     $Qoptval->bindFloat(':price_modifier', (double) $price_modifier);
                                     $Qoptval->setLogging($_SESSION['module'], $products_id);
                                     $Qoptval->execute();
                                     if ($lC_Database->isError()) {
                                         $error = true;
                                         break 4;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // specials pricing
     if ($error === false) {
         if ($data['specials_pricing_switch'] == 1) {
             $specials_id = self::hasSpecial($products_id);
             $specials_data = array('specials_id' => (int) $specials_id, 'products_id' => (int) $products_id, 'specials_price' => $data['products_special_price1'], 'specials_start_date' => $data['products_special_start_date1'], 'specials_expires_date' => $data['products_special_expires_date1'], 'specials_status' => $data['products_special_pricing_enable1'] != '' ? 1 : 0);
             lC_Specials_Admin::save((int) $specials_id, $specials_data);
         }
     }
     if ($error === false) {
         $lC_Database->commitTransaction();
         lC_Cache::clear('categories');
         lC_Cache::clear('category_tree');
         lC_Cache::clear('also_purchased');
         return $products_id;
         // Return the products id for use with the save_close buttons
     }
     $lC_Database->rollbackTransaction();
     return false;
 }
Exemple #17
0
 function uploadImage()
 {
     global $toC_Json, $osC_Database, $osC_Session;
     $osC_Image = new osC_Image_Admin();
     if (is_array($_FILES)) {
         $products_image = array_keys($_FILES);
         $products_image = $products_image[0];
     }
     $products_image = new upload($products_image);
     if (isset($_REQUEST['products_id']) && $_REQUEST['products_id'] > 0) {
         if ($products_image->exists()) {
             $image_path = '../images/products/originals/';
             $products_image->set_destination($image_path);
             if ($products_image->parse() && $products_image->save()) {
                 $default_flag = 1;
                 $Qcheck = $osC_Database->query('select id from :table_products_images where products_id = :products_id and default_flag = :default_flag limit 1');
                 $Qcheck->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
                 $Qcheck->bindInt(':products_id', $_REQUEST['products_id']);
                 $Qcheck->bindInt(':default_flag', 1);
                 $Qcheck->execute();
                 if ($Qcheck->numberOfRows() === 1) {
                     $default_flag = 0;
                 }
                 $Qimage = $osC_Database->query('insert into :table_products_images (products_id, image, default_flag, sort_order, date_added) values (:products_id, :image, :default_flag, :sort_order, :date_added)');
                 $Qimage->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
                 $Qimage->bindInt(':products_id', $_REQUEST['products_id']);
                 $Qimage->bindValue(':image', $products_image->filename);
                 $Qimage->bindInt(':default_flag', $default_flag);
                 $Qimage->bindInt(':sort_order', 0);
                 $Qimage->bindRaw(':date_added', 'now()');
                 $Qimage->execute();
                 if (!$osC_Database->isError()) {
                     $image_id = $osC_Database->nextID();
                     $new_image_name = $_REQUEST['products_id'] . '_' . $image_id . '_' . $products_image->filename;
                     @rename($image_path . $products_image->filename, $image_path . $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->execute();
                 }
                 foreach ($osC_Image->getGroups() as $group) {
                     if ($group['id'] != '1') {
                         $osC_Image->resize($new_image_name, $group['id']);
                     }
                 }
             }
         }
     } else {
         $image_path = '../images/products/_upload/' . $osC_Session->getID() . '/';
         toc_mkdir($image_path);
         if ($products_image->exists()) {
             $products_image->set_destination($image_path);
             $products_image->parse();
             $products_image->save();
         }
     }
     header('Content-Type: text/html');
     $response['success'] = true;
     $response['feedback'] = $osC_Language->get('ms_success_action_performed');
     echo $toC_Json->encode($response);
 }
Exemple #18
0
 function uploadImage()
 {
     global $toC_Json, $osC_Database;
     $osC_Image = new osC_Image_Admin();
     if (is_array($_FILES)) {
         $products_image = array_keys($_FILES);
         $products_image = $products_image[0];
     }
     if (isset($_REQUEST['products_id'])) {
         $products_image = new upload($products_image);
         if ($products_image->exists()) {
             $products_image->set_destination(realpath('../images/products/originals'));
             if ($products_image->parse() && $products_image->save()) {
                 $default_flag = 1;
                 $Qcheck = $osC_Database->query('select id from :table_products_images where products_id = :products_id and default_flag = :default_flag limit 1');
                 $Qcheck->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
                 $Qcheck->bindInt(':products_id', $_REQUEST['products_id']);
                 $Qcheck->bindInt(':default_flag', 1);
                 $Qcheck->execute();
                 if ($Qcheck->numberOfRows() === 1) {
                     $default_flag = 0;
                 }
                 $Qimage = $osC_Database->query('insert into :table_products_images (products_id, image, default_flag, sort_order, date_added) values (:products_id, :image, :default_flag, :sort_order, :date_added)');
                 $Qimage->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
                 $Qimage->bindInt(':products_id', $_REQUEST['products_id']);
                 $Qimage->bindValue(':image', $products_image->filename);
                 $Qimage->bindInt(':default_flag', $default_flag);
                 $Qimage->bindInt(':sort_order', 0);
                 $Qimage->bindRaw(':date_added', 'now()');
                 $Qimage->setLogging($_SESSION['module'], $_REQUEST['products_id']);
                 $Qimage->execute();
                 foreach ($osC_Image->getGroups() as $group) {
                     if ($group['id'] != '1') {
                         $osC_Image->resize($products_image->filename, $group['id']);
                     }
                 }
             }
         }
     }
     header('Content-Type: text/html');
     $response['success'] = true;
     $response['feedback'] = $osC_Language->get('ms_success_action_performed');
     echo $toC_Json->encode($response);
 }
Exemple #19
0
 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);
 }
Exemple #20
0
 function save($image_name)
 {
     global $osC_Database;
     $image = new upload($image_name, realpath('../' . DIR_WS_IMAGES));
     if ($image->exists() && $image->parse()) {
         if ($image->save()) {
             if (defined('WATERMARK_FILE_NAME')) {
                 @unlink('../' . DIR_WS_IMAGES . WATERMARK_FILE_NAME);
                 $Qupdate = $osC_Database->query('update :table_configuration set configuration_value = :configuration_value, last_modified = now() where configuration_key = \'WATERMARK_FILE_NAME\'');
                 $Qupdate->bindTable(':table_configuration', TABLE_CONFIGURATION);
                 $Qupdate->bindValue(':configuration_value', $image->filename);
                 $Qupdate->execute();
             } else {
                 $Qinsert = $osC_Database->query("insert into :table_configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('watermark file name', 'WATERMARK_FILE_NAME', :configuration_value, 'The name of the watermark file', 6, 0, now());");
                 $Qinsert->bindTable(':table_configuration', TABLE_CONFIGURATION);
                 $Qinsert->bindValue(':configuration_value', $image->filename);
                 $Qinsert->execute();
             }
             if (!$osC_Database->isError()) {
                 $response = array('success' => true, 'image' => '../' . DIR_WS_IMAGES . $_FILES['watermark_image']['name']);
                 osC_Cache::clear('configuration');
             } else {
                 $response = array('success' => false, 'feedback' => $osC_Language->get('ms_error_action_not_performed'));
             }
             return $response;
         }
     }
 }
 function save($id, $data)
 {
     global $osC_Database, $osC_Language;
     $error = false;
     if ($data['attachments_file']) {
         $file = new upload($data['attachments_file']);
         if ($file->exists()) {
             //remove old attachment file
             if (is_numeric($id)) {
                 $Qfile = $osC_Database->query('select cache_filename from :table_products_attachments where attachments_id = :id');
                 $Qfile->bindTable(':table_products_attachments', TABLE_PRODUCTS_ATTACHMENTS);
                 $Qfile->bindInt(':id', $id);
                 $Qfile->execute();
                 if ($Qfile->numberOfRows() == 1) {
                     @unlink(DIR_FS_CACHE . '/products_attachments/' . $Qfile->value('cache_filename'));
                 }
             }
             $file->set_destination(realpath(DIR_FS_CACHE . '/products_attachments'));
             if ($file->parse() && $file->save()) {
                 $filename = $file->filename;
                 $cache_filename = md5($filename . time());
                 @rename(DIR_FS_CACHE . 'products_attachments/' . $file->filename, DIR_FS_CACHE . '/products_attachments/' . $cache_filename);
                 if (is_numeric($id)) {
                     $Qattachment = $osC_Database->query('update :table_products_attachments set filename  = :filename , cache_filename = :cache_filename where attachments_id = :id');
                     $Qattachment->bindTable(':table_products_attachments', TABLE_PRODUCTS_ATTACHMENTS);
                     $Qattachment->bindInt(':id', $id);
                 } else {
                     $Qattachment = $osC_Database->query('insert into :table_products_attachments (filename, cache_filename) values (:filename, :cache_filename)');
                     $Qattachment->bindTable(':table_products_attachments', TABLE_PRODUCTS_ATTACHMENTS);
                 }
                 $Qattachment->bindValue(':filename', $filename);
                 $Qattachment->bindValue(':cache_filename', $cache_filename);
                 $Qattachment->setLogging($_SESSION['module'], $id);
                 $Qattachment->execute();
                 if ($osC_Database->isError()) {
                     $error = true;
                 }
             }
         }
     }
     if ($error === false) {
         $attachments_id = is_numeric($id) ? $id : $osC_Database->nextID();
         foreach ($osC_Language->getAll() as $l) {
             if (is_numeric($id)) {
                 $Qad = $osC_Database->query('update :table_products_attachments_description set attachments_name = :attachments_name, attachments_description  = :attachments_description where attachments_id = :id and languages_id = :language_id');
             } else {
                 $Qad = $osC_Database->query('insert into :table_products_attachments_description (attachments_id, languages_id, attachments_name, attachments_description) values (:id, :language_id, :attachments_name, :attachments_description)');
             }
             $Qad->bindTable(':table_products_attachments_description', TABLE_PRODUCTS_ATTACHMENTS_DESCRIPTION);
             $Qad->bindInt(':id', $attachments_id);
             $Qad->bindInt(':language_id', $l['id']);
             $Qad->bindValue(':attachments_name', $data['attachments_name'][$l['id']]);
             $Qad->bindValue(':attachments_description', $data['attachments_description'][$l['id']]);
             $Qad->setLogging($_SESSION['module'], $attachments_id);
             $Qad->execute();
             if ($osC_Database->isError()) {
                 $error = true;
                 break;
             }
         }
     } else {
         $error = true;
     }
     if ($error === false) {
         $osC_Database->commitTransaction();
         return true;
     }
     $osC_Database->rollbackTransaction();
     return false;
 }
Exemple #22
0
 function save($id = null, $data)
 {
     global $osC_Database, $osC_Language, $osC_Image;
     $error = false;
     $osC_Database->startTransaction();
     if (is_numeric($id)) {
         $Qarticle = $osC_Database->query('update :table_articles set articles_status = :articles_status, articles_order = :articles_order,articles_categories_id = :articles_categories_id,articles_last_modified = now() where articles_id = :articles_id');
         $Qarticle->bindInt(':articles_id', $id);
     } else {
         $Qarticle = $osC_Database->query('insert into :table_articles (articles_status,articles_order,articles_categories_id,articles_date_added) values (:articles_status,:articles_order,:articles_categories_id ,:articles_date_added)');
         $Qarticle->bindRaw(':articles_date_added', 'now()');
     }
     $Qarticle->bindTable(':table_articles', TABLE_ARTICLES);
     $Qarticle->bindValue(':articles_status', $data['articles_status']);
     $Qarticle->bindValue(':articles_order', $data['articles_order']);
     $Qarticle->bindValue(':articles_categories_id', $data['articles_categories']);
     $Qarticle->setLogging($_SESSION['module'], $id);
     $Qarticle->execute();
     if ($osC_Database->isError()) {
         $error = true;
     } else {
         if (is_numeric($id)) {
             $articles_id = $id;
         } else {
             $articles_id = $osC_Database->nextID();
         }
     }
     //articles images
     if ($data['delimage'] == 1) {
         $osC_Image->deleteArticlesImage($articles_id);
         $Qdelete = $osC_Database->query('update :table_articles set articles_image = NULL where articles_id = :articles_id');
         $Qdelete->bindTable(':table_articles', TABLE_ARTICLES);
         $Qdelete->bindInt(':articles_id', $id);
         $Qdelete->setLogging($_SESSION['module'], $id);
         $Qdelete->execute();
         if ($osC_Database->isError()) {
             $error = true;
         }
     }
     if ($error === false) {
         $articles_image = new upload('articles_image', realpath('../' . DIR_WS_IMAGES . '/articles/originals'));
         if ($articles_image->exists() && $articles_image->parse() && $articles_image->save()) {
             $Qarticle = $osC_Database->query('update :table_articles set articles_image = :articles_image where articles_id = :articles_id');
             $Qarticle->bindTable(':table_articles', TABLE_ARTICLES);
             $Qarticle->bindValue(':articles_image', $articles_image->filename);
             $Qarticle->bindInt(':articles_id', $articles_id);
             $Qarticle->setLogging($_SESSION['module'], $articles_id);
             $Qarticle->execute();
             if ($osC_Database->isError()) {
                 $error = true;
             } else {
                 foreach ($osC_Image->getGroups() as $group) {
                     if ($group['id'] != '1') {
                         $osC_Image->resize($articles_image->filename, $group['id'], 'articles');
                     }
                 }
             }
         }
     }
     //Process Languages
     //
     if ($error === false) {
         foreach ($osC_Language->getAll() as $l) {
             if (is_numeric($id)) {
                 $Qad = $osC_Database->query('update :table_articles_description set articles_name = :articles_name, articles_url = :articles_url, articles_description = :articles_description, articles_page_title = :articles_page_title, articles_meta_keywords = :articles_meta_keywords, articles_meta_description = :articles_meta_description where articles_id = :articles_id and language_id = :language_id');
             } else {
                 $Qad = $osC_Database->query('insert into :table_articles_description (articles_id, language_id, articles_name, articles_url, articles_description, articles_page_title, articles_meta_keywords, articles_meta_description) values (:articles_id, :language_id, :articles_name, :articles_url, :articles_description, :articles_page_title, :articles_meta_keywords, :articles_meta_description)');
             }
             $Qad->bindTable(':table_articles_description', TABLE_ARTICLES_DESCRIPTION);
             $Qad->bindInt(':articles_id', $articles_id);
             $Qad->bindInt(':language_id', $l['id']);
             $Qad->bindValue(':articles_name', $data['articles_name'][$l['id']]);
             $Qad->bindValue(':articles_url', $data['articles_url'][$l['id']] == '' ? $data['articles_name'][$l['id']] : $data['articles_url'][$l['id']]);
             $Qad->bindValue(':articles_description', $data['articles_description'][$l['id']]);
             $Qad->bindValue(':articles_page_title', $data['page_title'][$l['id']]);
             $Qad->bindValue(':articles_meta_keywords', $data['meta_keywords'][$l['id']]);
             $Qad->bindValue(':articles_meta_description', $data['meta_description'][$l['id']]);
             $Qad->setLogging($_SESSION['module'], $articles_id);
             $Qad->execute();
             if ($osC_Database->isError()) {
                 $error = true;
                 break;
             }
         }
     }
     if ($error === false) {
         $osC_Database->commitTransaction();
         osC_Cache::clear('sefu-articles');
         return true;
     }
     $osC_Database->rollbackTransaction();
     return false;
 }
 function save($id = null, $data)
 {
     global $osC_Database;
     $error = false;
     $image_location = '';
     if ($data['banner_type'] == 'image') {
         $image = null;
         $old_image = null;
         $new_image = false;
         if (is_numeric($id)) {
             $Qimage = $osC_Database->query('select banners_image from :table_banners where banners_id = :banners_id');
             $Qimage->bindTable(':table_banners', TABLE_BANNERS);
             $Qimage->bindInt(':banners_id', $id);
             $Qimage->execute();
             $old_image = $Qimage->value('banners_image');
         }
         if (!empty($data['image'])) {
             $image = new upload($data['image'], realpath('../images/'));
             if ($image->exists() && $image->parse() && $image->save()) {
                 $new_image = true;
             }
         }
         if ($new_image === true) {
             $image_location = $image->filename;
             if (!empty($old_image) && is_file('../images/' . $old_image) && is_writeable('../images/' . $old_image)) {
                 @unlink('../images/' . $old_image);
             }
         } else {
             if ($new_image === false && !empty($old_image)) {
                 $image_location = $old_image;
             } else {
                 $error = true;
             }
         }
     }
     if (is_numeric($id)) {
         if ($new_image == true && !empty($old_image) || $data['banner_type'] == 'text' && !empty($old_image)) {
             $Qimage = $osC_Database->query('select count(*) as image_count from :table_banners where banners_image = :banners_image and banners_id <> :banners_id');
             $Qimage->bindTable(':table_banners', TABLE_BANNERS);
             $Qimage->bindInt(':banners_id', $id);
             $Qimage->bindValue(':banners_image', $old_image);
             $Qimage->execute();
             if ($Qimage->value('image_count') == 0) {
                 if (!empty($old_image) && is_file('../images/' . $old_image) && is_writeable('../images/' . $old_image)) {
                     @unlink('../images/' . $old_image);
                 }
             }
         }
     }
     if ($error === false) {
         if (is_numeric($id)) {
             $Qbanner = $osC_Database->query('update :table_banners set banners_title = :banners_title, banners_url = :banners_url, banners_image = :banners_image, banners_group = :banners_group, banners_html_text = :banners_html_text, expires_date = :expires_date, expires_impressions = :expires_impressions, date_scheduled = :date_scheduled, status = :status where banners_id = :banners_id');
             $Qbanner->bindInt(':banners_id', $id);
         } else {
             $Qbanner = $osC_Database->query('insert into :table_banners (banners_title, banners_url, banners_image, banners_group, banners_html_text, expires_date, expires_impressions, date_scheduled, status, date_added) values (:banners_title, :banners_url, :banners_image, :banners_group, :banners_html_text, :expires_date, :expires_impressions, :date_scheduled, :status, now())');
         }
         $Qbanner->bindTable(':table_banners', TABLE_BANNERS);
         $Qbanner->bindValue(':banners_title', $data['title']);
         $Qbanner->bindValue(':banners_url', $data['url']);
         $Qbanner->bindValue(':banners_image', $image_location);
         $Qbanner->bindValue(':banners_group', !empty($data['group_new']) ? $data['group_new'] : $data['group']);
         $Qbanner->bindValue(':banners_html_text', $data['html_text']);
         if (empty($data['date_expires'])) {
             $Qbanner->bindRaw(':expires_date', 'null');
             $Qbanner->bindInt(':expires_impressions', $data['expires_impressions']);
         } else {
             $Qbanner->bindValue(':expires_date', $data['date_expires']);
             $Qbanner->bindInt(':expires_impressions', 0);
         }
         if (empty($data['date_scheduled'])) {
             $Qbanner->bindRaw(':date_scheduled', 'null');
             $Qbanner->bindInt(':status', $data['status'] === true ? 1 : 0);
         } else {
             $Qbanner->bindValue(':date_scheduled', $data['date_scheduled']);
             $Qbanner->bindInt(':status', $data['date_scheduled'] > date('Y-m-d') ? 0 : ($data['status'] === true ? 1 : 0));
         }
         $Qbanner->setLogging($_SESSION['module'], $id);
         $Qbanner->execute();
         if (!$osC_Database->isError()) {
             return true;
         }
     }
     return false;
 }
Exemple #24
0
 public static function fileUpload()
 {
     global $osC_Database, $_module;
     $osC_Image = new osC_Image_Admin();
     if (is_numeric($_GET[$_module])) {
         $products_image = new upload('products_image');
         $products_image->set_extensions(array('gif', 'jpg', 'jpeg', 'png'));
         if ($products_image->exists()) {
             $products_image->set_destination(realpath('../images/products/originals'));
             if ($products_image->parse() && $products_image->save()) {
                 $default_flag = 1;
                 $Qcheck = $osC_Database->query('select id from :table_products_images where products_id = :products_id and default_flag = :default_flag limit 1');
                 $Qcheck->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
                 $Qcheck->bindInt(':products_id', $_GET[$_module]);
                 $Qcheck->bindInt(':default_flag', 1);
                 $Qcheck->execute();
                 if ($Qcheck->numberOfRows() === 1) {
                     $default_flag = 0;
                 }
                 $Qimage = $osC_Database->query('insert into :table_products_images (products_id, image, default_flag, sort_order, date_added) values (:products_id, :image, :default_flag, :sort_order, :date_added)');
                 $Qimage->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
                 $Qimage->bindInt(':products_id', $_GET[$_module]);
                 $Qimage->bindValue(':image', $products_image->filename);
                 $Qimage->bindInt(':default_flag', $default_flag);
                 $Qimage->bindInt(':sort_order', 0);
                 $Qimage->bindRaw(':date_added', 'now()');
                 $Qimage->setLogging($_SESSION['module'], $_GET[$_module]);
                 $Qimage->execute();
                 foreach ($osC_Image->getGroups() as $group) {
                     if ($group['id'] != '1') {
                         $osC_Image->resize($products_image->filename, $group['id']);
                     }
                 }
             }
         }
     }
     $result = array('result' => 1, 'rpcStatus' => RPC_STATUS_SUCCESS);
     echo json_encode($result);
 }