[ Index ]
 

Code source de Zen Cart E-Commerce Shopping Cart 1.3.7.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/admin/includes/modules/product_music/ -> update_product.php (source)

   1  <?php
   2  /**

   3   * @package admin

   4   * @copyright Copyright 2003-2006 Zen Cart Development Team

   5   * @copyright Portions Copyright 2003 osCommerce

   6   * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0

   7   * @version $Id: update_product.php 4178 2006-08-20 18:47:54Z ajeh $

   8   */
   9    if (!defined('IS_ADMIN_FLAG')) {
  10      die('Illegal Access');
  11    }
  12    if (isset($_POST['edit_x']) || isset($_POST['edit_y'])) {
  13      $action = 'new_product';
  14    } else {
  15      if (isset($_GET['pID'])) $products_id = zen_db_prepare_input($_GET['pID']);
  16      $products_date_available = zen_db_prepare_input($_POST['products_date_available']);
  17  
  18      $products_date_available = (date('Y-m-d') < $products_date_available) ? $products_date_available : 'null';
  19  
  20      // Data-cleaning to prevent MySQL5 data-type mismatch errors:

  21      $tmp_value = zen_db_prepare_input($_POST['products_quantity']);
  22      $products_quantity = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
  23      $tmp_value = zen_db_prepare_input($_POST['products_price']);
  24      $products_price = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
  25      $tmp_value = zen_db_prepare_input($_POST['products_weight']);
  26      $products_weight = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
  27      $tmp_value = zen_db_prepare_input($_POST['manufacturers_id']);
  28      $manufacturers_id = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
  29  
  30      $sql_data_array = array('products_quantity' => $products_quantity,
  31                              'products_type' => zen_db_prepare_input($_GET['product_type']),
  32                              'products_model' => zen_db_prepare_input($_POST['products_model']),
  33                              'products_price' => $products_price,
  34                              'products_date_available' => $products_date_available,
  35                              'products_weight' => $products_weight,
  36                              'products_status' => zen_db_prepare_input($_POST['products_status']),
  37                              'products_virtual' => zen_db_prepare_input($_POST['products_virtual']),
  38                              'products_tax_class_id' => zen_db_prepare_input($_POST['products_tax_class_id']),
  39    //                          'manufacturers_id' => $manufacturers_id,

  40                              'products_quantity_order_min' => zen_db_prepare_input($_POST['products_quantity_order_min']),
  41                              'products_quantity_order_units' => zen_db_prepare_input($_POST['products_quantity_order_units']),
  42                              'products_priced_by_attribute' => zen_db_prepare_input($_POST['products_priced_by_attribute']),
  43                              'product_is_free' => zen_db_prepare_input($_POST['product_is_free']),
  44                              'product_is_call' => zen_db_prepare_input($_POST['product_is_call']),
  45                              'products_quantity_mixed' => zen_db_prepare_input($_POST['products_quantity_mixed']),
  46                              'product_is_always_free_shipping' => zen_db_prepare_input($_POST['product_is_always_free_shipping']),
  47                              'products_qty_box_status' => zen_db_prepare_input($_POST['products_qty_box_status']),
  48                              'products_quantity_order_max' => zen_db_prepare_input($_POST['products_quantity_order_max']),
  49                              'products_sort_order' => (int)zen_db_prepare_input($_POST['products_sort_order']),
  50                              'products_discount_type' => zen_db_prepare_input($_POST['products_discount_type']),
  51                              'products_discount_type_from' => zen_db_prepare_input($_POST['products_discount_type_from']),
  52                              'products_price_sorter' => zen_db_prepare_input($_POST['products_price_sorter'])
  53                              );
  54  
  55      // when set to none remove from database

  56      // if (isset($_POST['products_image']) && zen_not_null($_POST['products_image']) && ($_POST['products_image'] != 'none')) {

  57      if (isset($_POST['products_image']) && zen_not_null($_POST['products_image']) && (!is_numeric(strpos($_POST['products_image'],'none'))) ) {
  58        $sql_data_array['products_image'] = zen_db_prepare_input($_POST['products_image']);
  59        $new_image= 'true';
  60      } else {
  61        $sql_data_array['products_image'] = '';
  62        $new_image= 'false';
  63      }
  64  
  65  if ($_POST['image_delete'] == 1) {
  66        $sql_data_array['products_image'] = '';
  67        $new_image= 'false';
  68  }
  69  
  70      if ($action == 'insert_product') {
  71        $insert_sql_data = array( 'products_date_added' => 'now()',
  72                                  'master_categories_id' => (int)$current_category_id);
  73  
  74        $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
  75  
  76        zen_db_perform(TABLE_PRODUCTS, $sql_data_array);
  77        $products_id = zen_db_insert_id();
  78  
  79        // reset products_price_sorter for searches etc.

  80        zen_update_products_price_sorter($products_id);
  81  
  82        $db->Execute("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . "
  83                      (products_id, categories_id)
  84                      values ('" . (int)$products_id . "', '" . (int)$current_category_id . "')");
  85  
  86        ///////////////////////////////////////////////////////

  87        //// INSERT PRODUCT-TYPE-SPECIFIC *INSERTS* HERE //////

  88        $tmp_value = zen_db_prepare_input($_POST['artists_id']);
  89        $artists_id = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
  90        $tmp_value = zen_db_prepare_input($_POST['record_company_id']);
  91        $record_company_id = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
  92        $tmp_value = zen_db_prepare_input($_POST['music_genre_id']);
  93        $music_genre_id = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
  94  
  95        $sql_data_array = array('products_id' => $products_id,
  96                                'artists_id' => $artists_id,
  97                                'record_company_id' => $record_company_id,
  98                                'music_genre_id' => $music_genre_id );
  99  
 100        zen_db_perform(TABLE_PRODUCT_MUSIC_EXTRA, $sql_data_array);
 101  
 102        ////    *END OF PRODUCT-TYPE-SPECIFIC INSERTS* ////////

 103        ///////////////////////////////////////////////////////

 104      } elseif ($action == 'update_product') {
 105        $update_sql_data = array( 'products_last_modified' => 'now()',
 106                                  'master_categories_id' => ($_POST['master_category'] > 0 ? zen_db_prepare_input($_POST['master_category']) : zen_db_prepare_input($_POST['master_categories_id'])));
 107  
 108        $sql_data_array = array_merge($sql_data_array, $update_sql_data);
 109  
 110        zen_db_perform(TABLE_PRODUCTS, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "'");
 111  
 112        // reset products_price_sorter for searches etc.

 113        zen_update_products_price_sorter((int)$products_id);
 114  
 115        ///////////////////////////////////////////////////////

 116        //// INSERT PRODUCT-TYPE-SPECIFIC *UPDATES* HERE //////

 117  
 118        $tmp_value = zen_db_prepare_input($_POST['artists_id']);
 119        $artists_id = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
 120        $tmp_value = zen_db_prepare_input($_POST['record_company_id']);
 121        $record_company_id = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
 122        $tmp_value = zen_db_prepare_input($_POST['music_genre_id']);
 123        $music_genre_id = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
 124  
 125        $sql_data_array = array('artists_id' => $artists_id,
 126                                'record_company_id' => $record_company_id,
 127                                'music_genre_id' => $music_genre_id );
 128  
 129        zen_db_perform(TABLE_PRODUCT_MUSIC_EXTRA, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "'");
 130  
 131        ////    *END OF PRODUCT-TYPE-SPECIFIC UPDATES* ////////

 132        ///////////////////////////////////////////////////////

 133      }
 134  
 135      $languages = zen_get_languages();
 136      for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
 137        $language_id = $languages[$i]['id'];
 138  
 139        $sql_data_array = array('products_name' => zen_db_prepare_input($_POST['products_name'][$language_id]),
 140                                'products_description' => zen_db_prepare_input($_POST['products_description'][$language_id]),
 141                                'products_url' => zen_db_prepare_input($_POST['products_url'][$language_id]));
 142  
 143        if ($action == 'insert_product') {
 144          $insert_sql_data = array('products_id' => $products_id,
 145                                   'language_id' => $language_id);
 146  
 147          $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
 148  
 149          zen_db_perform(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array);
 150        } elseif ($action == 'update_product') {
 151          zen_db_perform(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "' and language_id = '" . (int)$language_id . "'");
 152        }
 153      }
 154  
 155      // add meta tags

 156      $languages = zen_get_languages();
 157      for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
 158        $language_id = $languages[$i]['id'];
 159  
 160        $sql_data_array = array('metatags_title' => zen_db_prepare_input($_POST['metatags_title'][$language_id]),
 161                                'metatags_keywords' => zen_db_prepare_input($_POST['metatags_keywords'][$language_id]),
 162                                'metatags_description' => zen_db_prepare_input($_POST['metatags_description'][$language_id]));
 163  
 164        if ($action == 'insert_product_meta_tags') {
 165  
 166          $insert_sql_data = array('products_id' => $products_id,
 167                                   'language_id' => $language_id);
 168  
 169          $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
 170  
 171          zen_db_perform(TABLE_META_TAGS_PRODUCTS_DESCRIPTION, $sql_data_array);
 172        } elseif ($action == 'update_product_meta_tags') {
 173          zen_db_perform(TABLE_META_TAGS_PRODUCTS_DESCRIPTION, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "' and language_id = '" . (int)$language_id . "'");
 174        }
 175      }
 176  
 177  
 178      // future image handler code

 179      define('IMAGE_MANAGER_HANDLER', 0);
 180      define('DIR_IMAGEMAGICK', '');
 181      if ($new_image == 'true' and IMAGE_MANAGER_HANDLER >= 1) {
 182        $src= DIR_FS_CATALOG . DIR_WS_IMAGES . zen_get_products_image((int)$products_id);
 183        $filename_small= $src;
 184        preg_match("/.*\/(.*)\.(\w*)$/", $src, $fname);
 185        list($oiwidth, $oiheight, $oitype) = getimagesize($src);
 186  
 187        $small_width= SMALL_IMAGE_WIDTH;
 188        $small_height= SMALL_IMAGE_HEIGHT;
 189        $medium_width= MEDIUM_IMAGE_WIDTH;
 190        $medium_height= MEDIUM_IMAGE_HEIGHT;
 191        $large_width= LARGE_IMAGE_WIDTH;
 192        $large_height= LARGE_IMAGE_HEIGHT;
 193  
 194        $k = max($oiheight / $small_height, $oiwidth / $small_width); //use smallest size

 195        $small_width = round($oiwidth / $k);
 196        $small_height = round($oiheight / $k);
 197  
 198        $k = max($oiheight / $medium_height, $oiwidth / $medium_width); //use smallest size

 199        $medium_width = round($oiwidth / $k);
 200        $medium_height = round($oiheight / $k);
 201  
 202        $large_width= $oiwidth;
 203        $large_height= $oiheight;
 204  
 205        $products_image = zen_get_products_image((int)$products_id);
 206        $products_image_extension = substr($products_image, strrpos($products_image, '.'));
 207        $products_image_base = ereg_replace($products_image_extension, '', $products_image);
 208  
 209        $filename_medium = DIR_FS_CATALOG . DIR_WS_IMAGES . 'medium/' . $products_image_base . IMAGE_SUFFIX_MEDIUM . '.' . $fname[2];
 210        $filename_large = DIR_FS_CATALOG . DIR_WS_IMAGES . 'large/' . $products_image_base . IMAGE_SUFFIX_LARGE . '.' . $fname[2];
 211  
 212        // ImageMagick

 213        if (IMAGE_MANAGER_HANDLER == '1') {
 214          copy($src, $filename_large);
 215          copy($src, $filename_medium);
 216          exec(DIR_IMAGEMAGICK . "mogrify -geometry " . $large_width . " " . $filename_large);
 217          exec(DIR_IMAGEMAGICK . "mogrify -geometry " . $medium_width . " " . $filename_medium);
 218          exec(DIR_IMAGEMAGICK . "mogrify -geometry " . $small_width . " " . $filename_small);
 219        }
 220      }
 221  
 222      zen_redirect(zen_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $products_id . (isset($_GET['page']) ? '&page=' . $_GET['page'] : '')));
 223    }
 224  ?>


Généré le : Mon Nov 26 16:45:43 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics