diff --git a/catalog/admin/categories.php b/catalog/admin/categories.php index 2c70cd389..84a18a6bf 100644 --- a/catalog/admin/categories.php +++ b/catalog/admin/categories.php @@ -264,6 +264,62 @@ } } + $pi_sort_order = 0; + $piArray = array(0); + + foreach ($HTTP_POST_FILES as $key => $value) { +// Update existing large product images + if (preg_match('/^products_image_large_([0-9]+)$/', $key, $matches)) { + $pi_sort_order++; + + $sql_data_array = array('htmlcontent' => tep_db_prepare_input($HTTP_POST_VARS['products_image_htmlcontent_' . $matches[1]]), + 'sort_order' => $pi_sort_order); + + $t = new upload($key); + $t->set_destination(DIR_FS_CATALOG_IMAGES); + if ($t->parse() && $t->save()) { + $sql_data_array['image'] = tep_db_prepare_input($t->filename); + } + + tep_db_perform(TABLE_PRODUCTS_IMAGES, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "' and id = '" . (int)$matches[1] . "'"); + + $piArray[] = (int)$matches[1]; + } elseif (preg_match('/^products_image_large_new_([0-9]+)$/', $key, $matches)) { +// Insert new large product images + $sql_data_array = array('products_id' => (int)$products_id, + 'htmlcontent' => tep_db_prepare_input($HTTP_POST_VARS['products_image_htmlcontent_new_' . $matches[1]])); + + $t = new upload($key); + $t->set_destination(DIR_FS_CATALOG_IMAGES); + if ($t->parse() && $t->save()) { + $pi_sort_order++; + + $sql_data_array['image'] = tep_db_prepare_input($t->filename); + $sql_data_array['sort_order'] = $pi_sort_order; + + tep_db_perform(TABLE_PRODUCTS_IMAGES, $sql_data_array); + + $piArray[] = tep_db_insert_id(); + } + } + } + + $product_images_query = tep_db_query("select image from " . TABLE_PRODUCTS_IMAGES . " where products_id = '" . (int)$products_id . "' and id not in (" . implode(',', $piArray) . ")"); + if (tep_db_num_rows($product_images_query)) { + while ($product_images = tep_db_fetch_array($product_images_query)) { + $duplicate_image_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_IMAGES . " where image = '" . tep_db_input($product_images['image']) . "'"); + $duplicate_image = tep_db_fetch_array($duplicate_image_query); + + if ($duplicate_image['total'] < 2) { + if (file_exists(DIR_FS_CATALOG_IMAGES . $product_images['image'])) { + @unlink(DIR_FS_CATALOG_IMAGES . $product_images['image']); + } + } + } + + tep_db_query("delete from " . TABLE_PRODUCTS_IMAGES . " where products_id = '" . (int)$products_id . "' and id not in (" . implode(',', $piArray) . ")"); + } + if (USE_CACHE == 'true') { tep_reset_cache_block('categories'); tep_reset_cache_block('also_purchased'); @@ -298,6 +354,11 @@ tep_db_query("insert into " . TABLE_PRODUCTS_DESCRIPTION . " (products_id, language_id, products_name, products_description, products_url, products_viewed) values ('" . (int)$dup_products_id . "', '" . (int)$description['language_id'] . "', '" . tep_db_input($description['products_name']) . "', '" . tep_db_input($description['products_description']) . "', '" . tep_db_input($description['products_url']) . "', '0')"); } + $product_images_query = tep_db_query("select image, htmlcontent, sort_order from " . TABLE_PRODUCTS_IMAGES . " where products_id = '" . (int)$products_id . "'"); + while ($product_images = tep_db_fetch_array($product_images_query)) { + tep_db_query("insert into " . TABLE_PRODUCTS_IMAGES . " (products_id, image, htmlcontent, sort_order) values ('" . (int)$dup_products_id . "', '" . tep_db_input($product_images['image']) . "', '" . tep_db_input($product_images['htmlcontent']) . "', '" . tep_db_input($product_images['sort_order']) . "')"); + } + tep_db_query("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . " (products_id, categories_id) values ('" . (int)$dup_products_id . "', '" . (int)$categories_id . "')"); $products_id = $dup_products_id; } @@ -330,6 +391,7 @@ 'products_quantity' => '', 'products_model' => '', 'products_image' => '', + 'products_larger_images' => array(), 'products_price' => '', 'products_weight' => '', 'products_date_added' => '', @@ -346,6 +408,14 @@ $product = tep_db_fetch_array($product_query); $pInfo->objectInfo($product); + + $product_images_query = tep_db_query("select id, image, htmlcontent, sort_order from " . TABLE_PRODUCTS_IMAGES . " where products_id = '" . (int)$product['products_id'] . "' order by sort_order"); + while ($product_images = tep_db_fetch_array($product_images_query)) { + $pInfo->products_larger_images[] = array('id' => $product_images['id'], + 'image' => $product_images['image'], + 'htmlcontent' => $product_images['htmlcontent'], + 'sort_order' => $product_images['sort_order']); + } } $manufacturers_array = array(array('id' => '', 'text' => TEXT_NONE)); @@ -520,8 +590,72 @@ function updateNet() { - - ' . tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . $pInfo->products_image; ?> + + +
Main Image (' . SMALL_IMAGE_WIDTH . ' x ' . SMALL_IMAGE_HEIGHT . 'px)
' . (tep_not_null($pInfo->products_image) ? '' . $pInfo->products_image . ' | ' : '') . tep_draw_file_field('products_image'); ?>
+ + + + Add Large Image + +
+

Please confirm the removal of the large product image.

+
+ + + + + + diff --git a/catalog/admin/includes/database_tables.php b/catalog/admin/includes/database_tables.php index f66742d35..1fe69c1bf 100644 --- a/catalog/admin/includes/database_tables.php +++ b/catalog/admin/includes/database_tables.php @@ -42,6 +42,7 @@ define('TABLE_PRODUCTS_ATTRIBUTES', 'products_attributes'); define('TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD', 'products_attributes_download'); define('TABLE_PRODUCTS_DESCRIPTION', 'products_description'); + define('TABLE_PRODUCTS_IMAGES', 'products_images'); define('TABLE_PRODUCTS_NOTIFICATIONS', 'products_notifications'); define('TABLE_PRODUCTS_OPTIONS', 'products_options'); define('TABLE_PRODUCTS_OPTIONS_VALUES', 'products_options_values'); diff --git a/catalog/admin/includes/functions/general.php b/catalog/admin/includes/functions/general.php index a8ea837a6..d8b5ff8db 100644 --- a/catalog/admin/includes/functions/general.php +++ b/catalog/admin/includes/functions/general.php @@ -951,6 +951,22 @@ function tep_remove_product($product_id) { } } + $product_images_query = tep_db_query("select image from " . TABLE_PRODUCTS_IMAGES . " where products_id = '" . (int)$product_id . "'"); + if (tep_db_num_rows($product_images_query)) { + while ($product_images = tep_db_fetch_array($product_images_query)) { + $duplicate_image_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_IMAGES . " where image = '" . tep_db_input($product_images['image']) . "'"); + $duplicate_image = tep_db_fetch_array($duplicate_image_query); + + if ($duplicate_image['total'] < 2) { + if (file_exists(DIR_FS_CATALOG_IMAGES . $product_images['image'])) { + @unlink(DIR_FS_CATALOG_IMAGES . $product_images['image']); + } + } + } + + tep_db_query("delete from " . TABLE_PRODUCTS_IMAGES . " where products_id = '" . (int)$product_id . "'"); + } + tep_db_query("delete from " . TABLE_SPECIALS . " where products_id = '" . (int)$product_id . "'"); tep_db_query("delete from " . TABLE_PRODUCTS . " where products_id = '" . (int)$product_id . "'"); tep_db_query("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$product_id . "'");