PageRenderTime 40ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/archeeadmin/includes/modules/product_music/update_product.php

https://bitbucket.org/archee/hejnarphotostore
PHP | 221 lines | 154 code | 43 blank | 24 comment | 53 complexity | 61ca3d98450d10accad4fe7ee2b95c97 MD5 | raw file
  1. <?php
  2. /**
  3. * @package admin
  4. * @copyright Copyright 2003-2010 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 15636 2010-03-07 07:00:40Z drbyte $
  8. */
  9. if (!defined('IS_ADMIN_FLAG')) {
  10. die('Illegal Access');
  11. }
  12. if (isset($_GET['pID'])) $products_id = zen_db_prepare_input($_GET['pID']);
  13. if (isset($_POST['edit_x']) || isset($_POST['edit_y'])) {
  14. $action = 'new_product';
  15. } elseif ($_POST['products_model'] . $_POST['products_url'] . $_POST['products_name'] . $_POST['products_description'] != '') {
  16. $products_date_available = zen_db_prepare_input($_POST['products_date_available']);
  17. $products_date_available = (date('Y-m-d') < $products_date_available) ? $products_date_available : 'null';
  18. // Data-cleaning to prevent MySQL5 data-type mismatch errors:
  19. $tmp_value = zen_db_prepare_input($_POST['products_quantity']);
  20. $products_quantity = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
  21. $tmp_value = zen_db_prepare_input($_POST['products_price']);
  22. $products_price = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
  23. $tmp_value = zen_db_prepare_input($_POST['products_weight']);
  24. $products_weight = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
  25. $tmp_value = zen_db_prepare_input($_POST['manufacturers_id']);
  26. $manufacturers_id = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
  27. $sql_data_array = array('products_quantity' => $products_quantity,
  28. 'products_type' => zen_db_prepare_input($_GET['product_type']),
  29. 'products_model' => zen_db_prepare_input($_POST['products_model']),
  30. 'products_price' => $products_price,
  31. 'products_date_available' => $products_date_available,
  32. 'products_weight' => $products_weight,
  33. 'products_status' => zen_db_prepare_input((int)$_POST['products_status']),
  34. 'products_virtual' => zen_db_prepare_input((int)$_POST['products_virtual']),
  35. 'products_tax_class_id' => zen_db_prepare_input((int)$_POST['products_tax_class_id']),
  36. // 'manufacturers_id' => $manufacturers_id,
  37. 'products_quantity_order_min' => zen_db_prepare_input($_POST['products_quantity_order_min']),
  38. 'products_quantity_order_units' => zen_db_prepare_input($_POST['products_quantity_order_units']),
  39. 'products_priced_by_attribute' => zen_db_prepare_input($_POST['products_priced_by_attribute']),
  40. 'product_is_free' => zen_db_prepare_input((int)$_POST['product_is_free']),
  41. 'product_is_call' => zen_db_prepare_input((int)$_POST['product_is_call']),
  42. 'products_quantity_mixed' => zen_db_prepare_input($_POST['products_quantity_mixed']),
  43. 'product_is_always_free_shipping' => zen_db_prepare_input((int)$_POST['product_is_always_free_shipping']),
  44. 'products_qty_box_status' => zen_db_prepare_input($_POST['products_qty_box_status']),
  45. 'products_quantity_order_max' => zen_db_prepare_input($_POST['products_quantity_order_max']),
  46. 'products_sort_order' => (int)zen_db_prepare_input($_POST['products_sort_order']),
  47. 'products_discount_type' => zen_db_prepare_input($_POST['products_discount_type']),
  48. 'products_discount_type_from' => zen_db_prepare_input($_POST['products_discount_type_from']),
  49. 'products_price_sorter' => zen_db_prepare_input($_POST['products_price_sorter'])
  50. );
  51. // when set to none remove from database
  52. // is out dated for browsers use radio only
  53. $sql_data_array['products_image'] = zen_db_prepare_input($_POST['products_image']);
  54. $new_image= 'true';
  55. if ($_POST['image_delete'] == 1) {
  56. $sql_data_array['products_image'] = '';
  57. $new_image= 'false';
  58. }
  59. if ($action == 'insert_product') {
  60. $insert_sql_data = array( 'products_date_added' => 'now()',
  61. 'master_categories_id' => (int)$current_category_id);
  62. $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
  63. zen_db_perform(TABLE_PRODUCTS, $sql_data_array);
  64. $products_id = zen_db_insert_id();
  65. // reset products_price_sorter for searches etc.
  66. zen_update_products_price_sorter($products_id);
  67. $db->Execute("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . "
  68. (products_id, categories_id)
  69. values ('" . (int)$products_id . "', '" . (int)$current_category_id . "')");
  70. ///////////////////////////////////////////////////////
  71. //// INSERT PRODUCT-TYPE-SPECIFIC *INSERTS* HERE //////
  72. $tmp_value = zen_db_prepare_input($_POST['artists_id']);
  73. $artists_id = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
  74. $tmp_value = zen_db_prepare_input($_POST['record_company_id']);
  75. $record_company_id = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
  76. $tmp_value = zen_db_prepare_input($_POST['music_genre_id']);
  77. $music_genre_id = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
  78. $sql_data_array = array('products_id' => $products_id,
  79. 'artists_id' => $artists_id,
  80. 'record_company_id' => $record_company_id,
  81. 'music_genre_id' => $music_genre_id );
  82. zen_db_perform(TABLE_PRODUCT_MUSIC_EXTRA, $sql_data_array);
  83. //// *END OF PRODUCT-TYPE-SPECIFIC INSERTS* ////////
  84. ///////////////////////////////////////////////////////
  85. } elseif ($action == 'update_product') {
  86. $update_sql_data = array( 'products_last_modified' => 'now()',
  87. 'master_categories_id' => ($_POST['master_category'] > 0 ? zen_db_prepare_input($_POST['master_category']) : zen_db_prepare_input($_POST['master_categories_id'])));
  88. $sql_data_array = array_merge($sql_data_array, $update_sql_data);
  89. zen_db_perform(TABLE_PRODUCTS, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "'");
  90. // reset products_price_sorter for searches etc.
  91. zen_update_products_price_sorter((int)$products_id);
  92. ///////////////////////////////////////////////////////
  93. //// INSERT PRODUCT-TYPE-SPECIFIC *UPDATES* HERE //////
  94. $tmp_value = zen_db_prepare_input($_POST['artists_id']);
  95. $artists_id = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
  96. $tmp_value = zen_db_prepare_input($_POST['record_company_id']);
  97. $record_company_id = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
  98. $tmp_value = zen_db_prepare_input($_POST['music_genre_id']);
  99. $music_genre_id = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
  100. $sql_data_array = array('artists_id' => $artists_id,
  101. 'record_company_id' => $record_company_id,
  102. 'music_genre_id' => $music_genre_id );
  103. zen_db_perform(TABLE_PRODUCT_MUSIC_EXTRA, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "'");
  104. //// *END OF PRODUCT-TYPE-SPECIFIC UPDATES* ////////
  105. ///////////////////////////////////////////////////////
  106. }
  107. $languages = zen_get_languages();
  108. for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
  109. $language_id = $languages[$i]['id'];
  110. $sql_data_array = array('products_name' => zen_db_prepare_input($_POST['products_name'][$language_id]),
  111. 'products_description' => zen_db_prepare_input($_POST['products_description'][$language_id]),
  112. 'products_url' => zen_db_prepare_input($_POST['products_url'][$language_id]));
  113. if ($action == 'insert_product') {
  114. $insert_sql_data = array('products_id' => $products_id,
  115. 'language_id' => $language_id);
  116. $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
  117. zen_db_perform(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array);
  118. } elseif ($action == 'update_product') {
  119. zen_db_perform(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "' and language_id = '" . (int)$language_id . "'");
  120. }
  121. }
  122. // add meta tags
  123. $languages = zen_get_languages();
  124. for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
  125. $language_id = $languages[$i]['id'];
  126. $sql_data_array = array('metatags_title' => zen_db_prepare_input($_POST['metatags_title'][$language_id]),
  127. 'metatags_keywords' => zen_db_prepare_input($_POST['metatags_keywords'][$language_id]),
  128. 'metatags_description' => zen_db_prepare_input($_POST['metatags_description'][$language_id]));
  129. if ($action == 'insert_product_meta_tags') {
  130. $insert_sql_data = array('products_id' => $products_id,
  131. 'language_id' => $language_id);
  132. $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
  133. zen_db_perform(TABLE_META_TAGS_PRODUCTS_DESCRIPTION, $sql_data_array);
  134. } elseif ($action == 'update_product_meta_tags') {
  135. zen_db_perform(TABLE_META_TAGS_PRODUCTS_DESCRIPTION, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "' and language_id = '" . (int)$language_id . "'");
  136. }
  137. }
  138. // future image handler code
  139. define('IMAGE_MANAGER_HANDLER', 0);
  140. define('DIR_IMAGEMAGICK', '');
  141. if ($new_image == 'true' and IMAGE_MANAGER_HANDLER >= 1) {
  142. $src= DIR_FS_CATALOG . DIR_WS_IMAGES . zen_get_products_image((int)$products_id);
  143. $filename_small= $src;
  144. preg_match("/.*\/(.*)\.(\w*)$/", $src, $fname);
  145. list($oiwidth, $oiheight, $oitype) = getimagesize($src);
  146. $small_width= SMALL_IMAGE_WIDTH;
  147. $small_height= SMALL_IMAGE_HEIGHT;
  148. $medium_width= MEDIUM_IMAGE_WIDTH;
  149. $medium_height= MEDIUM_IMAGE_HEIGHT;
  150. $large_width= LARGE_IMAGE_WIDTH;
  151. $large_height= LARGE_IMAGE_HEIGHT;
  152. $k = max($oiheight / $small_height, $oiwidth / $small_width); //use smallest size
  153. $small_width = round($oiwidth / $k);
  154. $small_height = round($oiheight / $k);
  155. $k = max($oiheight / $medium_height, $oiwidth / $medium_width); //use smallest size
  156. $medium_width = round($oiwidth / $k);
  157. $medium_height = round($oiheight / $k);
  158. $large_width= $oiwidth;
  159. $large_height= $oiheight;
  160. $products_image = zen_get_products_image((int)$products_id);
  161. $products_image_extension = substr($products_image, strrpos($products_image, '.'));
  162. $products_image_base = preg_replace('/'.$products_image_extension.'/', '', $products_image);
  163. $filename_medium = DIR_FS_CATALOG . DIR_WS_IMAGES . 'medium/' . $products_image_base . IMAGE_SUFFIX_MEDIUM . '.' . $fname[2];
  164. $filename_large = DIR_FS_CATALOG . DIR_WS_IMAGES . 'large/' . $products_image_base . IMAGE_SUFFIX_LARGE . '.' . $fname[2];
  165. // ImageMagick
  166. if (IMAGE_MANAGER_HANDLER == '1') {
  167. copy($src, $filename_large);
  168. copy($src, $filename_medium);
  169. exec(DIR_IMAGEMAGICK . "mogrify -geometry " . $large_width . " " . $filename_large);
  170. exec(DIR_IMAGEMAGICK . "mogrify -geometry " . $medium_width . " " . $filename_medium);
  171. exec(DIR_IMAGEMAGICK . "mogrify -geometry " . $small_width . " " . $filename_small);
  172. }
  173. }
  174. zen_redirect(zen_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $products_id . (isset($_GET['page']) ? '&page=' . $_GET['page'] : '') . (isset($_POST['search']) ? '&search=' . $_POST['search'] : '') ));
  175. } else {
  176. $messageStack->add_session(ERROR_NO_DATA_TO_SAVE, 'error');
  177. zen_redirect(zen_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $products_id . (isset($_GET['page']) ? '&page=' . $_GET['page'] : '') . (isset($_POST['search']) ? '&search=' . $_POST['search'] : '') ));
  178. }