PageRenderTime 52ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/shop/admin/includes/modules/product_music/update_product.php

https://github.com/severnaya99/Sg-2010
PHP | 195 lines | 130 code | 38 blank | 27 comment | 23 complexity | 6fb041b8f83ec8bf9ce0b032a5c3aea9 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0, GPL-2.0
  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // |zen-cart Open Source E-commerce |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 2004 The zen-cart developers |
  7. // | |
  8. // | http://www.zen-cart.com/index.php |
  9. // | |
  10. // | Portions Copyright (c) 2003 osCommerce |
  11. // +----------------------------------------------------------------------+
  12. // | This source file is subject to version 2.0 of the GPL license, |
  13. // | that is bundled with this package in the file LICENSE, and is |
  14. // | available through the world-wide-web at the following url: |
  15. // | http://www.zen-cart.com/license/2_0.txt. |
  16. // | If you did not receive a copy of the zen-cart license and are unable |
  17. // | to obtain it through the world-wide-web, please send a note to |
  18. // | license@zen-cart.com so we can mail you a copy immediately. |
  19. // +----------------------------------------------------------------------+
  20. // $Id: update_product.php 1268 2005-04-29 03:44:30Z ajeh $
  21. //
  22. if (isset($_POST['edit_x']) || isset($_POST['edit_y'])) {
  23. $action = 'new_product';
  24. } else {
  25. if (isset($_GET['pID'])) $products_id = zen_db_prepare_input($_GET['pID']);
  26. $products_date_available = zen_db_prepare_input($_POST['products_date_available']);
  27. $products_date_available = (date('Y-m-d') < $products_date_available) ? $products_date_available : 'null';
  28. $sql_data_array = array('products_quantity' => zen_db_prepare_input($_POST['products_quantity']),
  29. 'products_type' => zen_db_prepare_input($_GET['product_type']),
  30. 'products_model' => zen_db_prepare_input($_POST['products_model']),
  31. 'products_price' => zen_db_prepare_input($_POST['products_price']),
  32. 'products_date_available' => $products_date_available,
  33. 'products_weight' => zen_db_prepare_input($_POST['products_weight']),
  34. 'products_status' => zen_db_prepare_input($_POST['products_status']),
  35. 'products_virtual' => zen_db_prepare_input($_POST['products_virtual']),
  36. 'products_tax_class_id' => zen_db_prepare_input($_POST['products_tax_class_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($_POST['product_is_free']),
  41. 'product_is_call' => zen_db_prepare_input($_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($_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' => 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. // if (isset($_POST['products_image']) && zen_not_null($_POST['products_image']) && ($_POST['products_image'] != 'none')) {
  53. if (isset($_POST['products_image']) && zen_not_null($_POST['products_image']) && (!is_numeric(strpos($_POST['products_image'],'none'))) ) {
  54. $sql_data_array['products_image'] = zen_db_prepare_input($_POST['products_image']);
  55. $new_image= 'true';
  56. } else {
  57. $sql_data_array['products_image'] = '';
  58. $new_image= 'false';
  59. }
  60. if ($action == 'insert_product') {
  61. $insert_sql_data = array( 'products_date_added' => 'now()',
  62. 'master_categories_id' => (int)$current_category_id);
  63. $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
  64. zen_db_perform(TABLE_PRODUCTS, $sql_data_array);
  65. $products_id = zen_db_insert_id();
  66. // reset products_price_sorter for searches etc.
  67. zen_update_products_price_sorter($products_id);
  68. $db->Execute("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . "
  69. (products_id, categories_id)
  70. values ('" . (int)$products_id . "', '" . (int)$current_category_id . "')");
  71. $sql_data_array = array('products_id' => $products_id,
  72. 'artists_id' => zen_db_prepare_input($_POST['artists_id']),
  73. 'record_company_id' => zen_db_prepare_input($_POST['record_company_id']),
  74. 'music_genre_id' => zen_db_prepare_input($_POST['music_genre_id']));
  75. zen_db_perform(TABLE_PRODUCT_MUSIC_EXTRA, $sql_data_array);
  76. } elseif ($action == 'update_product') {
  77. $update_sql_data = array( 'products_last_modified' => 'now()',
  78. 'master_categories_id' => ($_POST['master_category'] > 0 ? zen_db_prepare_input($_POST['master_category']) : zen_db_prepare_input($_POST['master_categories_id'])));
  79. $sql_data_array = array_merge($sql_data_array, $update_sql_data);
  80. zen_db_perform(TABLE_PRODUCTS, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "'");
  81. // reset products_price_sorter for searches etc.
  82. zen_update_products_price_sorter((int)$products_id);
  83. $sql_data_array = array('artists_id' => zen_db_prepare_input($_POST['artists_id']),
  84. 'record_company_id' => zen_db_prepare_input($_POST['record_company_id']),
  85. 'music_genre_id' => zen_db_prepare_input($_POST['music_genre_id']));
  86. zen_db_perform(TABLE_PRODUCT_MUSIC_EXTRA, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "'");
  87. }
  88. $languages = zen_get_languages();
  89. for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
  90. $language_id = $languages[$i]['id'];
  91. $sql_data_array = array('products_name' => zen_db_prepare_input($_POST['products_name'][$language_id]),
  92. 'products_description' => zen_db_prepare_input($_POST['products_description'][$language_id]),
  93. 'products_url' => zen_db_prepare_input($_POST['products_url'][$language_id]));
  94. if ($action == 'insert_product') {
  95. $insert_sql_data = array('products_id' => $products_id,
  96. 'language_id' => $language_id);
  97. $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
  98. zen_db_perform(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array);
  99. } elseif ($action == 'update_product') {
  100. zen_db_perform(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "' and language_id = '" . (int)$language_id . "'");
  101. }
  102. }
  103. // add meta tags
  104. $languages = zen_get_languages();
  105. for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
  106. $language_id = $languages[$i]['id'];
  107. $sql_data_array = array('metatags_title' => zen_db_prepare_input($_POST['metatags_title'][$language_id]),
  108. 'metatags_keywords' => zen_db_prepare_input($_POST['metatags_keywords'][$language_id]),
  109. 'metatags_description' => zen_db_prepare_input($_POST['metatags_description'][$language_id]));
  110. if ($action == 'insert_product_meta_tags') {
  111. $insert_sql_data = array('products_id' => $products_id,
  112. 'language_id' => $language_id);
  113. $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
  114. zen_db_perform(TABLE_META_TAGS_PRODUCTS_DESCRIPTION, $sql_data_array);
  115. } elseif ($action == 'update_product_meta_tags') {
  116. zen_db_perform(TABLE_META_TAGS_PRODUCTS_DESCRIPTION, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "' and language_id = '" . (int)$language_id . "'");
  117. }
  118. }
  119. // future image handler code
  120. define('IMAGE_MANAGER_HANDLER', 0);
  121. if ($new_image == 'true' and IMAGE_MANAGER_HANDLER >= 1) {
  122. $src= DIR_FS_CATALOG . DIR_WS_IMAGES . zen_get_products_image((int)$products_id);
  123. $filename_small= $src;
  124. preg_match("/.*\/(.*)\.(\w*)$/", $src, $fname);
  125. list($oiwidth, $oiheight, $oitype) = getimagesize($src);
  126. define('DIR_IMAGEMAGICK', '');
  127. $small_width= SMALL_IMAGE_WIDTH;
  128. $small_height= SMALL_IMAGE_HEIGHT;
  129. $medium_width= MEDIUM_IMAGE_WIDTH;
  130. $medium_height= MEDIUM_IMAGE_HEIGHT;
  131. $large_width= LARGE_IMAGE_WIDTH;
  132. $large_height= LARGE_IMAGE_HEIGHT;
  133. $k = max($oiheight / $small_height, $oiwidth / $small_width); //use smallest size
  134. $small_width = round($oiwidth / $k);
  135. $small_height = round($oiheight / $k);
  136. $k = max($oiheight / $medium_height, $oiwidth / $medium_width); //use smallest size
  137. $medium_width = round($oiwidth / $k);
  138. $medium_height = round($oiheight / $k);
  139. $large_width= $oiwidth;
  140. $large_height= $oiheight;
  141. $products_image = zen_get_products_image((int)$products_id);
  142. $products_image_extention = substr($products_image, strrpos($products_image, '.'));
  143. $products_image_base = ereg_replace($products_image_extention, '', $products_image);
  144. $filename_medium = DIR_FS_CATALOG . DIR_WS_IMAGES . 'medium/' . $products_image_base . IMAGE_SUFFIX_MEDIUM . '.' . $fname[2];
  145. $filename_large = DIR_FS_CATALOG . DIR_WS_IMAGES . 'large/' . $products_image_base . IMAGE_SUFFIX_LARGE . '.' . $fname[2];
  146. // ImageMagick
  147. if (IMAGE_MANAGER_HANDLER == '1') {
  148. copy($src, $filename_large);
  149. copy($src, $filename_medium);
  150. exec(DIR_IMAGEMAGICK . "mogrify -geometry " . $large_width . " " . $filename_large);
  151. exec(DIR_IMAGEMAGICK . "mogrify -geometry " . $medium_width . " " . $filename_medium);
  152. exec(DIR_IMAGEMAGICK . "mogrify -geometry " . $small_width . " " . $filename_small);
  153. }
  154. }
  155. zen_redirect(zen_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $products_id . (isset($_GET['page']) ? '&page=' . $_GET['page'] : '')));
  156. }
  157. ?>