ZenCart_Documentation  1.5.0
http://www.collinsharper.com
C:/xampp/htdocs/zen-cart/admin/includes/modules/update_product.php
Go to the documentation of this file.
00001 <?php
00009   if (!defined('IS_ADMIN_FLAG')) {
00010     die('Illegal Access');
00011   }
00012   if (isset($_GET['pID'])) $products_id = zen_db_prepare_input($_GET['pID']);
00013   if (isset($_POST['edit_x']) || isset($_POST['edit_y'])) {
00014     $action = 'new_product';
00015   } elseif ($_POST['products_model'] . $_POST['products_url'] . $_POST['products_name'] . $_POST['products_description'] != '') {
00016     $products_date_available = zen_db_prepare_input($_POST['products_date_available']);
00017 
00018     $products_date_available = (date('Y-m-d') < $products_date_available) ? $products_date_available : 'null';
00019 
00020     // Data-cleaning to prevent MySQL5 data-type mismatch errors:
00021     $tmp_value = zen_db_prepare_input($_POST['products_quantity']);
00022     $products_quantity = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
00023     $tmp_value = zen_db_prepare_input($_POST['products_price']);
00024     $products_price = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
00025     $tmp_value = zen_db_prepare_input($_POST['products_weight']);
00026     $products_weight = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
00027     $tmp_value = zen_db_prepare_input($_POST['manufacturers_id']);
00028     $manufacturers_id = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
00029 
00030     $sql_data_array = array('products_quantity' => $products_quantity,
00031                             'products_type' => zen_db_prepare_input($_GET['product_type']),
00032                             'products_model' => zen_db_prepare_input($_POST['products_model']),
00033                             'products_price' => $products_price,
00034                             'products_date_available' => $products_date_available,
00035                             'products_weight' => $products_weight,
00036                             'products_status' => zen_db_prepare_input((int)$_POST['products_status']),
00037                             'products_virtual' => zen_db_prepare_input((int)$_POST['products_virtual']),
00038                             'products_tax_class_id' => zen_db_prepare_input((int)$_POST['products_tax_class_id']),
00039                             'manufacturers_id' => $manufacturers_id,
00040                             'products_quantity_order_min' => zen_db_prepare_input($_POST['products_quantity_order_min']),
00041                             'products_quantity_order_units' => zen_db_prepare_input($_POST['products_quantity_order_units']),
00042                             'products_priced_by_attribute' => zen_db_prepare_input($_POST['products_priced_by_attribute']),
00043                             'product_is_free' => zen_db_prepare_input((int)$_POST['product_is_free']),
00044                             'product_is_call' => zen_db_prepare_input((int)$_POST['product_is_call']),
00045                             'products_quantity_mixed' => zen_db_prepare_input($_POST['products_quantity_mixed']),
00046                             'product_is_always_free_shipping' => zen_db_prepare_input((int)$_POST['product_is_always_free_shipping']),
00047                             'products_qty_box_status' => zen_db_prepare_input($_POST['products_qty_box_status']),
00048                             'products_quantity_order_max' => zen_db_prepare_input($_POST['products_quantity_order_max']),
00049                             'products_sort_order' => (int)zen_db_prepare_input($_POST['products_sort_order']),
00050                             'products_discount_type' => zen_db_prepare_input($_POST['products_discount_type']),
00051                             'products_discount_type_from' => zen_db_prepare_input($_POST['products_discount_type_from']),
00052                             'products_price_sorter' => zen_db_prepare_input($_POST['products_price_sorter'])
00053                             );
00054 
00055     // when set to none remove from database
00056     // is out dated for browsers use radio only
00057       $sql_data_array['products_image'] = zen_db_prepare_input($_POST['products_image']);
00058       $new_image= 'true';
00059 
00060     if ($_POST['image_delete'] == 1) {
00061       $sql_data_array['products_image'] = '';
00062       $new_image= 'false';
00063     }
00064 
00065 if ($_POST['image_delete'] == 1) {
00066       $sql_data_array['products_image'] = '';
00067       $new_image= 'false';
00068 }
00069 
00070     if ($action == 'insert_product') {
00071       $insert_sql_data = array( 'products_date_added' => 'now()',
00072                                 'master_categories_id' => (int)$current_category_id);
00073 
00074       $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
00075 
00076       zen_db_perform(TABLE_PRODUCTS, $sql_data_array);
00077       $products_id = zen_db_insert_id();
00078 
00079       // reset products_price_sorter for searches etc.
00080       zen_update_products_price_sorter($products_id);
00081 
00082       $db->Execute("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . "
00083                     (products_id, categories_id)
00084                     values ('" . (int)$products_id . "', '" . (int)$current_category_id . "')");
00085 
00088 
00089 
00092     } elseif ($action == 'update_product') {
00093       $update_sql_data = array( 'products_last_modified' => 'now()',
00094                                 'master_categories_id' => ($_POST['master_category'] > 0 ? zen_db_prepare_input($_POST['master_category']) : zen_db_prepare_input($_POST['master_categories_id'])));
00095 
00096       $sql_data_array = array_merge($sql_data_array, $update_sql_data);
00097 
00098       zen_db_perform(TABLE_PRODUCTS, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "'");
00099 
00100       // reset products_price_sorter for searches etc.
00101       zen_update_products_price_sorter((int)$products_id);
00102 
00105 
00106 
00109     }
00110 
00111     $languages = zen_get_languages();
00112     for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
00113       $language_id = $languages[$i]['id'];
00114 
00115       $sql_data_array = array('products_name' => zen_db_prepare_input($_POST['products_name'][$language_id]),
00116                               'products_description' => zen_db_prepare_input($_POST['products_description'][$language_id]),
00117                               'products_url' => zen_db_prepare_input($_POST['products_url'][$language_id]));
00118 
00119       if ($action == 'insert_product') {
00120         $insert_sql_data = array('products_id' => (int)$products_id,
00121                                  'language_id' => (int)$language_id);
00122 
00123         $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
00124 
00125         zen_db_perform(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array);
00126       } elseif ($action == 'update_product') {
00127         zen_db_perform(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "' and language_id = '" . (int)$language_id . "'");
00128       }
00129     }
00130 
00131     // add meta tags
00132     $languages = zen_get_languages();
00133     for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
00134       $language_id = $languages[$i]['id'];
00135 
00136       $sql_data_array = array('metatags_title' => zen_db_prepare_input($_POST['metatags_title'][$language_id]),
00137                               'metatags_keywords' => zen_db_prepare_input($_POST['metatags_keywords'][$language_id]),
00138                               'metatags_description' => zen_db_prepare_input($_POST['metatags_description'][$language_id]));
00139 
00140       if ($action == 'insert_product_meta_tags') {
00141 
00142         $insert_sql_data = array('products_id' => (int)$products_id,
00143                                  'language_id' => (int)$language_id);
00144 
00145         $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
00146 
00147         zen_db_perform(TABLE_META_TAGS_PRODUCTS_DESCRIPTION, $sql_data_array);
00148       } elseif ($action == 'update_product_meta_tags') {
00149         zen_db_perform(TABLE_META_TAGS_PRODUCTS_DESCRIPTION, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "' and language_id = '" . (int)$language_id . "'");
00150       }
00151     }
00152 
00153 
00154     // future image handler code
00155     define('IMAGE_MANAGER_HANDLER', 0);
00156     define('DIR_IMAGEMAGICK', '');
00157     if ($new_image == 'true' and IMAGE_MANAGER_HANDLER >= 1) {
00158       $src= DIR_FS_CATALOG . DIR_WS_IMAGES . zen_get_products_image((int)$products_id);
00159       $filename_small= $src;
00160       preg_match("/.*\/(.*)\.(\w*)$/", $src, $fname);
00161       list($oiwidth, $oiheight, $oitype) = getimagesize($src);
00162 
00163       $small_width= SMALL_IMAGE_WIDTH;
00164       $small_height= SMALL_IMAGE_HEIGHT;
00165       $medium_width= MEDIUM_IMAGE_WIDTH;
00166       $medium_height= MEDIUM_IMAGE_HEIGHT;
00167       $large_width= LARGE_IMAGE_WIDTH;
00168       $large_height= LARGE_IMAGE_HEIGHT;
00169 
00170       $k = max($oiheight / $small_height, $oiwidth / $small_width); //use smallest size
00171       $small_width = round($oiwidth / $k);
00172       $small_height = round($oiheight / $k);
00173 
00174       $k = max($oiheight / $medium_height, $oiwidth / $medium_width); //use smallest size
00175       $medium_width = round($oiwidth / $k);
00176       $medium_height = round($oiheight / $k);
00177 
00178       $large_width= $oiwidth;
00179       $large_height= $oiheight;
00180 
00181       $products_image = zen_get_products_image((int)$products_id);
00182       $products_image_extension = substr($products_image, strrpos($products_image, '.'));
00183       $products_image_base = preg_replace('/'.$products_image_extension.'/', '', $products_image);
00184 
00185       $filename_medium = DIR_FS_CATALOG . DIR_WS_IMAGES . 'medium/' . $products_image_base . IMAGE_SUFFIX_MEDIUM . '.' . $fname[2];
00186       $filename_large = DIR_FS_CATALOG . DIR_WS_IMAGES . 'large/' . $products_image_base . IMAGE_SUFFIX_LARGE . '.' . $fname[2];
00187 
00188       // ImageMagick
00189       if (IMAGE_MANAGER_HANDLER == '1') {
00190         copy($src, $filename_large);
00191         copy($src, $filename_medium);
00192         exec(DIR_IMAGEMAGICK . "mogrify -geometry " . $large_width . " " . $filename_large);
00193         exec(DIR_IMAGEMAGICK . "mogrify -geometry " . $medium_width . " " . $filename_medium);
00194         exec(DIR_IMAGEMAGICK . "mogrify -geometry " . $small_width . " " . $filename_small);
00195       }
00196     }
00197 
00198     zen_redirect(zen_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $products_id . (isset($_GET['page']) ? '&page=' . $_GET['page'] : '') . (isset($_POST['search']) ? '&search=' . $_POST['search'] : '') ));
00199   } else {
00200     $messageStack->add_session(ERROR_NO_DATA_TO_SAVE, 'error');
00201     zen_redirect(zen_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $products_id . (isset($_GET['page']) ? '&page=' . $_GET['page'] : '') . (isset($_POST['search']) ? '&search=' . $_POST['search'] : '') ));
00202   }
 All Data Structures Namespaces Files Functions Variables Enumerations