Guest User

Categories.php

a guest
Jul 10th, 2014
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 68.84 KB | None | 0 0
  1. <?php
  2. /*
  3.   $Id$
  4.  
  5.   osCommerce, Open Source E-Commerce Solutions
  6.   http://www.oscommerce.com
  7.  
  8.   Copyright (c) 2014 osCommerce
  9.  
  10.   Released under the GNU General Public License
  11. */
  12.  
  13.   require('includes/application_top.php');
  14.  
  15.   require(DIR_WS_CLASSES . 'currencies.php');
  16.   $currencies = new currencies();
  17.  
  18.   $action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');
  19.  
  20.   if (tep_not_null($action)) {
  21.     switch ($action) {
  22.       case 'setflag':
  23.         if ( ($HTTP_GET_VARS['flag'] == '0') || ($HTTP_GET_VARS['flag'] == '1') ) {
  24.           if (isset($HTTP_GET_VARS['pID'])) {
  25.             tep_set_product_status($HTTP_GET_VARS['pID'], $HTTP_GET_VARS['flag']);
  26.           }
  27.  
  28.           if (USE_CACHE == 'true') {
  29.             tep_reset_cache_block('categories');
  30.             tep_reset_cache_block('also_purchased');
  31.           }
  32.         }
  33.  
  34.         tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $HTTP_GET_VARS['cPath'] . '&pID=' . $HTTP_GET_VARS['pID']));
  35.         break;
  36.       case 'insert_category':
  37.       case 'update_category':
  38.         if (isset($HTTP_POST_VARS['categories_id'])) $categories_id = tep_db_prepare_input($HTTP_POST_VARS['categories_id']);
  39.         $sort_order = tep_db_prepare_input($HTTP_POST_VARS['sort_order']);
  40.  
  41.         $sql_data_array = array('sort_order' => (int)$sort_order);
  42.  
  43.         if ($action == 'insert_category') {
  44.           $insert_sql_data = array('parent_id' => $current_category_id,
  45.                                    'date_added' => 'now()');
  46.  
  47.           $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
  48.  
  49.           tep_db_perform(TABLE_CATEGORIES, $sql_data_array);
  50.  
  51.           $categories_id = tep_db_insert_id();
  52.         } elseif ($action == 'update_category') {
  53.           $update_sql_data = array('last_modified' => 'now()');
  54.  
  55.           $sql_data_array = array_merge($sql_data_array, $update_sql_data);
  56.  
  57.           tep_db_perform(TABLE_CATEGORIES, $sql_data_array, 'update', "categories_id = '" . (int)$categories_id . "'");
  58.         }
  59.  
  60.         $languages = tep_get_languages();
  61.         for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
  62.           $categories_name_array = $HTTP_POST_VARS['categories_name'];
  63.  
  64.           $language_id = $languages[$i]['id'];
  65.  
  66.           $sql_data_array = array('categories_name' => tep_db_prepare_input($categories_name_array[$language_id]));
  67.  
  68.           if ($action == 'insert_category') {
  69.             $insert_sql_data = array('categories_id' => $categories_id,
  70.                                      'language_id' => $languages[$i]['id']);
  71.  
  72.             $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
  73.  
  74.             tep_db_perform(TABLE_CATEGORIES_DESCRIPTION, $sql_data_array);
  75.           } elseif ($action == 'update_category') {
  76.             tep_db_perform(TABLE_CATEGORIES_DESCRIPTION, $sql_data_array, 'update', "categories_id = '" . (int)$categories_id . "' and language_id = '" . (int)$languages[$i]['id'] . "'");
  77.           }
  78.         }
  79.  
  80.         $categories_image = new upload('categories_image');
  81.         $categories_image->set_destination(DIR_FS_CATALOG_IMAGES);
  82.  
  83.         if ($categories_image->parse() && $categories_image->save()) {
  84.           tep_db_query("update " . TABLE_CATEGORIES . " set categories_image = '" . tep_db_input($categories_image->filename) . "' where categories_id = '" . (int)$categories_id . "'");
  85.         }
  86.  
  87.         if (USE_CACHE == 'true') {
  88.           tep_reset_cache_block('categories');
  89.           tep_reset_cache_block('also_purchased');
  90.         }
  91.  
  92.         tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&cID=' . $categories_id));
  93.         break;
  94.       case 'delete_category_confirm':
  95.         if (isset($HTTP_POST_VARS['categories_id'])) {
  96.           $categories_id = tep_db_prepare_input($HTTP_POST_VARS['categories_id']);
  97.  
  98.           $categories = tep_get_category_tree($categories_id, '', '0', '', true);
  99.           $products = array();
  100.           $products_delete = array();
  101.  
  102.           for ($i=0, $n=sizeof($categories); $i<$n; $i++) {
  103.             $product_ids_query = tep_db_query("select products_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id = '" . (int)$categories[$i]['id'] . "'");
  104.  
  105.             while ($product_ids = tep_db_fetch_array($product_ids_query)) {
  106.               $products[$product_ids['products_id']]['categories'][] = $categories[$i]['id'];
  107.             }
  108.           }
  109.  
  110.           reset($products);
  111.           while (list($key, $value) = each($products)) {
  112.             $category_ids = '';
  113.  
  114.             for ($i=0, $n=sizeof($value['categories']); $i<$n; $i++) {
  115.               $category_ids .= "'" . (int)$value['categories'][$i] . "', ";
  116.             }
  117.             $category_ids = substr($category_ids, 0, -2);
  118.  
  119.             $check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$key . "' and categories_id not in (" . $category_ids . ")");
  120.             $check = tep_db_fetch_array($check_query);
  121.             if ($check['total'] < '1') {
  122.               $products_delete[$key] = $key;
  123.             }
  124.           }
  125.  
  126. // removing categories can be a lengthy process
  127.           tep_set_time_limit(0);
  128.           for ($i=0, $n=sizeof($categories); $i<$n; $i++) {
  129.             tep_remove_category($categories[$i]['id']);
  130.           }
  131.  
  132.           reset($products_delete);
  133.           while (list($key) = each($products_delete)) {
  134.             tep_remove_product($key);
  135.           }
  136.         }
  137.  
  138.         if (USE_CACHE == 'true') {
  139.           tep_reset_cache_block('categories');
  140.           tep_reset_cache_block('also_purchased');
  141.         }
  142.  
  143.         tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath));
  144.         break;
  145.       case 'delete_product_confirm':
  146.         if (isset($HTTP_POST_VARS['products_id']) && isset($HTTP_POST_VARS['product_categories']) && is_array($HTTP_POST_VARS['product_categories'])) {
  147.           $product_id = tep_db_prepare_input($HTTP_POST_VARS['products_id']);
  148.           $product_categories = $HTTP_POST_VARS['product_categories'];
  149.  
  150.           for ($i=0, $n=sizeof($product_categories); $i<$n; $i++) {
  151.             tep_db_query("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$product_id . "' and categories_id = '" . (int)$product_categories[$i] . "'");
  152.           }
  153.  
  154.           $product_categories_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$product_id . "'");
  155.           $product_categories = tep_db_fetch_array($product_categories_query);
  156.  
  157.           if ($product_categories['total'] == '0') {
  158.             tep_remove_product($product_id);
  159.           }
  160.         }
  161.  
  162.         if (USE_CACHE == 'true') {
  163.           tep_reset_cache_block('categories');
  164.           tep_reset_cache_block('also_purchased');
  165.         }
  166.  
  167.         tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath));
  168.         break;
  169.       case 'move_category_confirm':
  170.         if (isset($HTTP_POST_VARS['categories_id']) && ($HTTP_POST_VARS['categories_id'] != $HTTP_POST_VARS['move_to_category_id'])) {
  171.           $categories_id = tep_db_prepare_input($HTTP_POST_VARS['categories_id']);
  172.           $new_parent_id = tep_db_prepare_input($HTTP_POST_VARS['move_to_category_id']);
  173.  
  174.           $path = explode('_', tep_get_generated_category_path_ids($new_parent_id));
  175.  
  176.           if (in_array($categories_id, $path)) {
  177.             $messageStack->add_session(ERROR_CANNOT_MOVE_CATEGORY_TO_PARENT, 'error');
  178.  
  179.             tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&cID=' . $categories_id));
  180.           } else {
  181.             tep_db_query("update " . TABLE_CATEGORIES . " set parent_id = '" . (int)$new_parent_id . "', last_modified = now() where categories_id = '" . (int)$categories_id . "'");
  182.  
  183.             if (USE_CACHE == 'true') {
  184.               tep_reset_cache_block('categories');
  185.               tep_reset_cache_block('also_purchased');
  186.             }
  187.  
  188.             tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $new_parent_id . '&cID=' . $categories_id));
  189.           }
  190.         }
  191.  
  192.         break;
  193.       case 'move_product_confirm':
  194.         $products_id = tep_db_prepare_input($HTTP_POST_VARS['products_id']);
  195.         $new_parent_id = tep_db_prepare_input($HTTP_POST_VARS['move_to_category_id']);
  196.  
  197.         $duplicate_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$products_id . "' and categories_id = '" . (int)$new_parent_id . "'");
  198.         $duplicate_check = tep_db_fetch_array($duplicate_check_query);
  199.         if ($duplicate_check['total'] < 1) tep_db_query("update " . TABLE_PRODUCTS_TO_CATEGORIES . " set categories_id = '" . (int)$new_parent_id . "' where products_id = '" . (int)$products_id . "' and categories_id = '" . (int)$current_category_id . "'");
  200.  
  201.         if (USE_CACHE == 'true') {
  202.           tep_reset_cache_block('categories');
  203.           tep_reset_cache_block('also_purchased');
  204.         }
  205.  
  206.         tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $new_parent_id . '&pID=' . $products_id));
  207.         break;
  208.       case 'insert_product':
  209.       case 'update_product':
  210.         if (isset($HTTP_GET_VARS['pID'])) $products_id = tep_db_prepare_input($HTTP_GET_VARS['pID']);
  211.         $products_date_available = tep_db_prepare_input($HTTP_POST_VARS['products_date_available']);
  212.  
  213.         $products_date_available = (date('Y-m-d') < $products_date_available) ? $products_date_available : 'null';
  214.  
  215.         $sql_data_array = array('products_quantity' => (int)tep_db_prepare_input($HTTP_POST_VARS['products_quantity']),
  216.                                 // Canada Post OST Start
  217.                                 'products_description_short' => tep_db_prepare_input($HTTP_POST_VARS['products_description_short']),
  218.                                 'products_tariff' => tep_db_prepare_input($HTTP_POST_VARS['products_tariff']),
  219.                                 // Canada Post OST End
  220.                                 'products_model' => tep_db_prepare_input($HTTP_POST_VARS['products_model']),
  221.                                 'products_price' => tep_db_prepare_input($HTTP_POST_VARS['products_price']),
  222.                                 'products_date_available' => $products_date_available,
  223.                                 'products_weight' => (float)tep_db_prepare_input($HTTP_POST_VARS['products_weight']),
  224.                                 // Canada Post OST Start
  225.                                 'products_length' => tep_db_prepare_input($HTTP_POST_VARS['products_length']),
  226.                                 'products_height' => tep_db_prepare_input($HTTP_POST_VARS['products_height']),
  227.                                 'products_width' => tep_db_prepare_input($HTTP_POST_VARS['products_width']),
  228.                                 'products_ready_to_ship' => tep_db_prepare_input($HTTP_POST_VARS['products_ready_to_ship']),
  229.                                 // Canada Post OST End
  230.                                 'products_status' => tep_db_prepare_input($HTTP_POST_VARS['products_status']),
  231.                                 'products_tax_class_id' => tep_db_prepare_input($HTTP_POST_VARS['products_tax_class_id']),
  232.                                 'manufacturers_id' => (int)tep_db_prepare_input($HTTP_POST_VARS['manufacturers_id']));
  233.  
  234.         $products_image = new upload('products_image');
  235.         $products_image->set_destination(DIR_FS_CATALOG_IMAGES);
  236.         if ($products_image->parse() && $products_image->save()) {
  237.           $sql_data_array['products_image'] = tep_db_prepare_input($products_image->filename);
  238.         }
  239.  
  240.         if ($action == 'insert_product') {
  241.           $insert_sql_data = array('products_date_added' => 'now()');
  242.  
  243.           $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
  244.  
  245.           tep_db_perform(TABLE_PRODUCTS, $sql_data_array);
  246.           $products_id = tep_db_insert_id();
  247.  
  248.           tep_db_query("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . " (products_id, categories_id) values ('" . (int)$products_id . "', '" . (int)$current_category_id . "')");
  249.         } elseif ($action == 'update_product') {
  250.           $update_sql_data = array('products_last_modified' => 'now()');
  251.  
  252.           $sql_data_array = array_merge($sql_data_array, $update_sql_data);
  253.  
  254.           tep_db_perform(TABLE_PRODUCTS, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "'");
  255.         }
  256.  
  257.         $languages = tep_get_languages();
  258.         for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
  259.           $language_id = $languages[$i]['id'];
  260.  
  261.           $sql_data_array = array('products_name' => tep_db_prepare_input($HTTP_POST_VARS['products_name'][$language_id]),
  262.                                   'products_description' => tep_db_prepare_input($HTTP_POST_VARS['products_description'][$language_id]),
  263.                                   'products_url' => tep_db_prepare_input($HTTP_POST_VARS['products_url'][$language_id]));
  264.  
  265.           if ($action == 'insert_product') {
  266.             $insert_sql_data = array('products_id' => $products_id,
  267.                                      'language_id' => $language_id);
  268.  
  269.             $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
  270.  
  271.             tep_db_perform(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array);
  272.           } elseif ($action == 'update_product') {
  273.             tep_db_perform(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "' and language_id = '" . (int)$language_id . "'");
  274.           }
  275.         }
  276.  
  277.         $pi_sort_order = 0;
  278.         $piArray = array(0);
  279.  
  280.         foreach ($HTTP_POST_FILES as $key => $value) {
  281. // Update existing large product images
  282.           if (preg_match('/^products_image_large_([0-9]+)$/', $key, $matches)) {
  283.             $pi_sort_order++;
  284.  
  285.             $sql_data_array = array('htmlcontent' => tep_db_prepare_input($HTTP_POST_VARS['products_image_htmlcontent_' . $matches[1]]),
  286.                                     'sort_order' => $pi_sort_order);
  287.  
  288.             $t = new upload($key);
  289.             $t->set_destination(DIR_FS_CATALOG_IMAGES);
  290.             if ($t->parse() && $t->save()) {
  291.               $sql_data_array['image'] = tep_db_prepare_input($t->filename);
  292.             }
  293.  
  294.             tep_db_perform(TABLE_PRODUCTS_IMAGES, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "' and id = '" . (int)$matches[1] . "'");
  295.  
  296.             $piArray[] = (int)$matches[1];
  297.           } elseif (preg_match('/^products_image_large_new_([0-9]+)$/', $key, $matches)) {
  298. // Insert new large product images
  299.             $sql_data_array = array('products_id' => (int)$products_id,
  300.                                     'htmlcontent' => tep_db_prepare_input($HTTP_POST_VARS['products_image_htmlcontent_new_' . $matches[1]]));
  301.  
  302.             $t = new upload($key);
  303.             $t->set_destination(DIR_FS_CATALOG_IMAGES);
  304.             if ($t->parse() && $t->save()) {
  305.               $pi_sort_order++;
  306.  
  307.               $sql_data_array['image'] = tep_db_prepare_input($t->filename);
  308.               $sql_data_array['sort_order'] = $pi_sort_order;
  309.  
  310.               tep_db_perform(TABLE_PRODUCTS_IMAGES, $sql_data_array);
  311.  
  312.               $piArray[] = tep_db_insert_id();
  313.             }
  314.           }
  315.         }
  316.  
  317.         $product_images_query = tep_db_query("select image from " . TABLE_PRODUCTS_IMAGES . " where products_id = '" . (int)$products_id . "' and id not in (" . implode(',', $piArray) . ")");
  318.         if (tep_db_num_rows($product_images_query)) {
  319.           while ($product_images = tep_db_fetch_array($product_images_query)) {
  320.             $duplicate_image_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_IMAGES . " where image = '" . tep_db_input($product_images['image']) . "'");
  321.             $duplicate_image = tep_db_fetch_array($duplicate_image_query);
  322.  
  323.             if ($duplicate_image['total'] < 2) {
  324.               if (file_exists(DIR_FS_CATALOG_IMAGES . $product_images['image'])) {
  325.                 @unlink(DIR_FS_CATALOG_IMAGES . $product_images['image']);
  326.               }
  327.             }
  328.           }
  329.  
  330.           tep_db_query("delete from " . TABLE_PRODUCTS_IMAGES . " where products_id = '" . (int)$products_id . "' and id not in (" . implode(',', $piArray) . ")");
  331.         }
  332.  
  333.         if (USE_CACHE == 'true') {
  334.           tep_reset_cache_block('categories');
  335.           tep_reset_cache_block('also_purchased');
  336.         }
  337.  
  338.         tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $products_id));
  339.         break;
  340.       case 'copy_to_confirm':
  341.         if (isset($HTTP_POST_VARS['products_id']) && isset($HTTP_POST_VARS['categories_id'])) {
  342.           $products_id = tep_db_prepare_input($HTTP_POST_VARS['products_id']);
  343.           $categories_id = tep_db_prepare_input($HTTP_POST_VARS['categories_id']);
  344.  
  345.           if ($HTTP_POST_VARS['copy_as'] == 'link') {
  346.             if ($categories_id != $current_category_id) {
  347.               $check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$products_id . "' and categories_id = '" . (int)$categories_id . "'");
  348.               $check = tep_db_fetch_array($check_query);
  349.               if ($check['total'] < '1') {
  350.                 tep_db_query("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . " (products_id, categories_id) values ('" . (int)$products_id . "', '" . (int)$categories_id . "')");
  351.               }
  352.             } else {
  353.               $messageStack->add_session(ERROR_CANNOT_LINK_TO_SAME_CATEGORY, 'error');
  354.             }
  355.           } elseif ($HTTP_POST_VARS['copy_as'] == 'duplicate') {
  356.            
  357.             // Canada Post OST adding," p.products_description_short, p.products_tariff, p.products_length, p.products_width, p.products_height, p.products_ready_to_ship
  358.             $product_query = tep_db_query("select pd.products_name, pd.products_description, p.products_description_short, p.products_tariff, pd.products_url, p.products_id, p.products_quantity, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_date_added, p.products_last_modified, date_format(p.products_date_available, '%Y-%m-%d') as products_date_available, p.products_status, p.products_tax_class_id, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$HTTP_GET_VARS['pID'] . "' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "'");
  359.             $product = tep_db_fetch_array($product_query);
  360.  
  361.             tep_db_query("insert into " . TABLE_PRODUCTS . " (products_quantity, products_model,products_image, products_price, products_date_added, products_date_available, products_weight, products_status, products_tax_class_id, manufacturers_id) values ('" . tep_db_input($product['products_quantity']) . "', '" . tep_db_input($product['products_model']) . "', '" . tep_db_input($product['products_image']) . "', '" . tep_db_input($product['products_price']) . "',  now(), " . (empty($product['products_date_available']) ? "null" : "'" . tep_db_input($product['products_date_available']) . "'") . ", '" . tep_db_input($product['products_weight']) . "', '0', '" . (int)$product['products_tax_class_id'] . "', '" . (int)$product['manufacturers_id'] . "')");
  362.             $dup_products_id = tep_db_insert_id();
  363.  
  364.             $description_query = tep_db_query("select language_id, products_name, products_description, products_url from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$products_id . "'");
  365.             while ($description = tep_db_fetch_array($description_query)) {
  366.               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')");
  367.             }
  368.  
  369.             $product_images_query = tep_db_query("select image, htmlcontent, sort_order from " . TABLE_PRODUCTS_IMAGES . " where products_id = '" . (int)$products_id . "'");
  370.             while ($product_images = tep_db_fetch_array($product_images_query)) {
  371.               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']) . "')");
  372.             }
  373.  
  374.             tep_db_query("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . " (products_id, categories_id) values ('" . (int)$dup_products_id . "', '" . (int)$categories_id . "')");
  375.             $products_id = $dup_products_id;
  376.           }
  377.  
  378.           if (USE_CACHE == 'true') {
  379.             tep_reset_cache_block('categories');
  380.             tep_reset_cache_block('also_purchased');
  381.           }
  382.         }
  383.  
  384.         tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $categories_id . '&pID=' . $products_id));
  385.         break;
  386.     }
  387.   }
  388.  
  389. // check if the catalog image directory exists
  390.   if (is_dir(DIR_FS_CATALOG_IMAGES)) {
  391.     if (!tep_is_writable(DIR_FS_CATALOG_IMAGES)) $messageStack->add(ERROR_CATALOG_IMAGE_DIRECTORY_NOT_WRITEABLE, 'error');
  392.   } else {
  393.     $messageStack->add(ERROR_CATALOG_IMAGE_DIRECTORY_DOES_NOT_EXIST, 'error');
  394.   }
  395.  
  396.   require(DIR_WS_INCLUDES . 'template_top.php');
  397.  
  398.   if ($action == 'new_product') {
  399.     $parameters = array('products_name' => '',
  400.                        'products_description' => '',
  401.                        // Canada Post OST Start
  402.                        'products_description_short' => '',
  403.                        'products_tariff' => '',
  404.                         // Canada Post OST End
  405.                        'products_url' => '',
  406.                        'products_id' => '',
  407.                        'products_quantity' => '',
  408.                        'products_model' => '',
  409.                        'products_image' => '',
  410.                        'products_larger_images' => array(),
  411.                        'products_price' => '',
  412.                        'products_weight' => '',
  413.                        // Canada Post OST Start
  414.                        'products_length' => '',
  415.                        'products_height' => '',
  416.                        'products_width' => '',
  417.                        'products_ready_to_ship' => '',
  418.                        // Canada Post OST End
  419.                        'products_date_added' => '',
  420.                        'products_last_modified' => '',
  421.                        'products_date_available' => '',
  422.                        'products_status' => '',
  423.                        'products_tax_class_id' => '',
  424.                        'manufacturers_id' => '');
  425.  
  426.     $pInfo = new objectInfo($parameters);
  427.  
  428.     if (isset($HTTP_GET_VARS['pID']) && empty($HTTP_POST_VARS)) {
  429.       // Canada Post OST adding, "p.products_description_short, p.products_tariff, p.products_length, p.products_width, p.products_height, p.products_ready_to_ship"
  430.       $product_query = tep_db_query("select pd.products_name, pd.products_description, p.products_description_short, p.products_tariff, pd.products_url, p.products_id, p.products_quantity, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_length, p.products_width, p.products_height, p.products_ready_to_ship, p.products_date_added, p.products_last_modified, date_format(p.products_date_available, '%Y-%m-%d') as products_date_available, p.products_status, p.products_tax_class_id, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$HTTP_GET_VARS['pID'] . "' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "'");
  431.       $product = tep_db_fetch_array($product_query);
  432.  
  433.       $pInfo->objectInfo($product);
  434.  
  435.       $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");
  436.       while ($product_images = tep_db_fetch_array($product_images_query)) {
  437.         $pInfo->products_larger_images[] = array('id' => $product_images['id'],
  438.                                                  'image' => $product_images['image'],
  439.                                                  'htmlcontent' => $product_images['htmlcontent'],
  440.                                                  'sort_order' => $product_images['sort_order']);
  441.       }
  442.     }
  443.  
  444.     $manufacturers_array = array(array('id' => '', 'text' => TEXT_NONE));
  445.     $manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name");
  446.     while ($manufacturers = tep_db_fetch_array($manufacturers_query)) {
  447.       $manufacturers_array[] = array('id' => $manufacturers['manufacturers_id'],
  448.                                      'text' => $manufacturers['manufacturers_name']);
  449.     }
  450.  
  451.     $tax_class_array = array(array('id' => '0', 'text' => TEXT_NONE));
  452.     $tax_class_query = tep_db_query("select tax_class_id, tax_class_title from " . TABLE_TAX_CLASS . " order by tax_class_title");
  453.     while ($tax_class = tep_db_fetch_array($tax_class_query)) {
  454.       $tax_class_array[] = array('id' => $tax_class['tax_class_id'],
  455.                                  'text' => $tax_class['tax_class_title']);
  456.     }
  457.  
  458.     $languages = tep_get_languages();
  459.  
  460.     if (!isset($pInfo->products_status)) $pInfo->products_status = '1';
  461.     switch ($pInfo->products_status) {
  462.       case '0': $in_status = false; $out_status = true; break;
  463.       case '1':
  464.       default: $in_status = true; $out_status = false;
  465.     }
  466.  
  467.     $form_action = (isset($HTTP_GET_VARS['pID'])) ? 'update_product' : 'insert_product';
  468. ?>
  469. <script type="text/javascript"><!--
  470. var tax_rates = new Array();
  471. <?php
  472.     for ($i=0, $n=sizeof($tax_class_array); $i<$n; $i++) {
  473.       if ($tax_class_array[$i]['id'] > 0) {
  474.         echo 'tax_rates["' . $tax_class_array[$i]['id'] . '"] = ' . tep_get_tax_rate_value($tax_class_array[$i]['id']) . ';' . "\n";
  475.       }
  476.     }
  477. ?>
  478.  
  479. function doRound(x, places) {
  480.   return Math.round(x * Math.pow(10, places)) / Math.pow(10, places);
  481. }
  482.  
  483. function getTaxRate() {
  484.   var selected_value = document.forms["new_product"].products_tax_class_id.selectedIndex;
  485.   var parameterVal = document.forms["new_product"].products_tax_class_id[selected_value].value;
  486.  
  487.   if ( (parameterVal > 0) && (tax_rates[parameterVal] > 0) ) {
  488.     return tax_rates[parameterVal];
  489.   } else {
  490.     return 0;
  491.   }
  492. }
  493.  
  494. function updateGross() {
  495.   var taxRate = getTaxRate();
  496.   var grossValue = document.forms["new_product"].products_price.value;
  497.  
  498.   if (taxRate > 0) {
  499.     grossValue = grossValue * ((taxRate / 100) + 1);
  500.   }
  501.  
  502.   document.forms["new_product"].products_price_gross.value = doRound(grossValue, 4);
  503. }
  504.  
  505. function updateNet() {
  506.   var taxRate = getTaxRate();
  507.   var netValue = document.forms["new_product"].products_price_gross.value;
  508.  
  509.   if (taxRate > 0) {
  510.     netValue = netValue / ((taxRate / 100) + 1);
  511.   }
  512.  
  513.   document.forms["new_product"].products_price.value = doRound(netValue, 4);
  514. }
  515. //--></script>
  516.     <?php echo tep_draw_form('new_product', FILENAME_CATEGORIES, 'cPath=' . $cPath . (isset($HTTP_GET_VARS['pID']) ? '&pID=' . $HTTP_GET_VARS['pID'] : '') . '&action=' . $form_action, 'post', 'enctype="multipart/form-data"'); ?>
  517.     <table border="0" width="100%" cellspacing="0" cellpadding="2">
  518.       <tr>
  519.         <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
  520.           <tr>
  521.             <td class="pageHeading"><?php echo sprintf(TEXT_NEW_PRODUCT, tep_output_generated_category_path($current_category_id)); ?></td>
  522.             <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
  523.           </tr>
  524.         </table></td>
  525.       </tr>
  526.       <tr>
  527.         <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  528.       </tr>
  529.       <tr>
  530.         <td><table border="0" cellspacing="0" cellpadding="2">
  531.           <tr>
  532.             <td class="main"><?php echo TEXT_PRODUCTS_STATUS; ?></td>
  533.             <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_radio_field('products_status', '1', $in_status) . '&nbsp;' . TEXT_PRODUCT_AVAILABLE . '&nbsp;' . tep_draw_radio_field('products_status', '0', $out_status) . '&nbsp;' . TEXT_PRODUCT_NOT_AVAILABLE; ?></td>
  534.           </tr>
  535.           <tr>
  536.             <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  537.           </tr>
  538.           <tr>
  539.             <td class="main"><?php echo TEXT_PRODUCTS_DATE_AVAILABLE; ?></td>
  540.             <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_date_available', $pInfo->products_date_available, 'id="products_date_available"') . ' <small>(YYYY-MM-DD)</small>'; ?></td>
  541.           </tr>
  542.           <tr>
  543.             <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  544.           </tr>
  545.           <tr>
  546.             <td class="main"><?php echo TEXT_PRODUCTS_MANUFACTURER; ?></td>
  547.             <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_pull_down_menu('manufacturers_id', $manufacturers_array, $pInfo->manufacturers_id); ?></td>
  548.           </tr>
  549.           <tr>
  550.             <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  551.           </tr>
  552. <?php
  553.     for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
  554. ?>
  555.           <tr>
  556.             <td class="main"><?php if ($i == 0) echo TEXT_PRODUCTS_NAME; ?></td>
  557.             <td class="main"><?php echo tep_image(tep_catalog_href_link(DIR_WS_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], '', 'SSL'), $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('products_name[' . $languages[$i]['id'] . ']', (empty($pInfo->products_id) ? '' : tep_get_products_name($pInfo->products_id, $languages[$i]['id']))); ?></td>
  558.           </tr>
  559. <?php
  560.     }
  561. ?>
  562.           <!-- Canada Post OST Start -->
  563.           <tr>
  564.             <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  565.           </tr>
  566.           <tr bgcolor="#ffffdd">
  567.             <td class="main">Short Description:</td>
  568.             <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_description_short', $pInfo->products_description_short); ?></td>
  569.           </tr>
  570.           <tr bgcolor="#ffffdd">
  571.             <td class="main"><a href="http://www.cbsa-asfc.gc.ca/trade-commerce/tariff-tarif/tariff2007/01-99/table-e.html" target="_blank">HS Tariff</a>:</td>
  572.             <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_tariff', $pInfo->products_tariff); ?></td>
  573.           </tr>
  574.           <!-- Canada Post OST End -->
  575.           <tr>
  576.             <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  577.           </tr>
  578.           <tr bgcolor="#ebebff">
  579.             <td class="main"><?php echo TEXT_PRODUCTS_TAX_CLASS; ?></td>
  580.             <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_pull_down_menu('products_tax_class_id', $tax_class_array, $pInfo->products_tax_class_id, 'onchange="updateGross()"'); ?></td>
  581.           </tr>
  582.           <tr bgcolor="#ebebff">
  583.             <td class="main"><?php echo TEXT_PRODUCTS_PRICE_NET; ?></td>
  584.             <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_price', $pInfo->products_price, 'onkeyup="updateGross()"'); ?></td>
  585.           </tr>
  586.           <tr bgcolor="#ebebff">
  587.             <td class="main"><?php echo TEXT_PRODUCTS_PRICE_GROSS; ?></td>
  588.             <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_price_gross', $pInfo->products_price, 'onkeyup="updateNet()"'); ?></td>
  589.           </tr>
  590.           <tr>
  591.             <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  592.           </tr>
  593. <script type="text/javascript"><!--
  594. updateGross();
  595. //--></script>
  596. <?php
  597.     for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
  598. ?>
  599.           <tr>
  600.             <td class="main" valign="top"><?php if ($i == 0) echo TEXT_PRODUCTS_DESCRIPTION; ?></td>
  601.             <td><table border="0" cellspacing="0" cellpadding="0">
  602.               <tr>
  603.                 <td class="main" valign="top"><?php echo tep_image(tep_catalog_href_link(DIR_WS_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], '', 'SSL'), $languages[$i]['name']); ?>&nbsp;</td>
  604.                 <td class="main"><?php echo tep_draw_textarea_field('products_description[' . $languages[$i]['id'] . ']', 'soft', '70', '15', (empty($pInfo->products_id) ? '' : tep_get_products_description($pInfo->products_id, $languages[$i]['id']))); ?></td>
  605.               </tr>
  606.             </table></td>
  607.           </tr>
  608. <?php
  609.     }
  610. ?>
  611.           <tr>
  612.             <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  613.           </tr>
  614.           <tr>
  615.             <td class="main"><?php echo TEXT_PRODUCTS_QUANTITY; ?></td>
  616.             <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_quantity', $pInfo->products_quantity); ?></td>
  617.           </tr>
  618.           <tr>
  619.             <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  620.           </tr>
  621.           <tr>
  622.             <td class="main"><?php echo TEXT_PRODUCTS_MODEL; ?></td>
  623.             <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_model', $pInfo->products_model); ?></td>
  624.           </tr>
  625.           <tr>
  626.             <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  627.           </tr>
  628.           <tr>
  629.             <td class="main" valign="top"><?php echo TEXT_PRODUCTS_IMAGE; ?></td>
  630.             <td class="main" style="padding-left: 30px;">
  631.               <div><?php echo '<strong>' . TEXT_PRODUCTS_MAIN_IMAGE . ' <small>(' . SMALL_IMAGE_WIDTH . ' x ' . SMALL_IMAGE_HEIGHT . 'px)</small></strong><br />' . (tep_not_null($pInfo->products_image) ? '<a href="' . HTTP_CATALOG_SERVER . DIR_WS_CATALOG_IMAGES . $pInfo->products_image . '" target="_blank">' . $pInfo->products_image . '</a> &#124; ' : '') . tep_draw_file_field('products_image'); ?></div>
  632.  
  633.               <ul id="piList">
  634. <?php
  635.     $pi_counter = 0;
  636.  
  637.     foreach ($pInfo->products_larger_images as $pi) {
  638.       $pi_counter++;
  639.  
  640.       echo '                <li id="piId' . $pi_counter . '" class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s" style="float: right;"></span><a href="#" onclick="showPiDelConfirm(' . $pi_counter . ');return false;" class="ui-icon ui-icon-trash" style="float: right;"></a><strong>' . TEXT_PRODUCTS_LARGE_IMAGE . '</strong><br />' . tep_draw_file_field('products_image_large_' . $pi['id']) . '<br /><a href="' . HTTP_CATALOG_SERVER . DIR_WS_CATALOG_IMAGES . $pi['image'] . '" target="_blank">' . $pi['image'] . '</a><br /><br />' . TEXT_PRODUCTS_LARGE_IMAGE_HTML_CONTENT . '<br />' . tep_draw_textarea_field('products_image_htmlcontent_' . $pi['id'], 'soft', '70', '3', $pi['htmlcontent']) . '</li>';
  641.     }
  642. ?>
  643.               </ul>
  644.  
  645.               <a href="#" onclick="addNewPiForm();return false;"><span class="ui-icon ui-icon-plus" style="float: left;"></span><?php echo TEXT_PRODUCTS_ADD_LARGE_IMAGE; ?></a>
  646.  
  647. <div id="piDelConfirm" title="<?php echo TEXT_PRODUCTS_LARGE_IMAGE_DELETE_TITLE; ?>">
  648.   <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span><?php echo TEXT_PRODUCTS_LARGE_IMAGE_CONFIRM_DELETE; ?></p>
  649. </div>
  650.  
  651. <style type="text/css">
  652. #piList { list-style-type: none; margin: 0; padding: 0; }
  653. #piList li { margin: 5px 0; padding: 2px; }
  654. </style>
  655.  
  656. <script type="text/javascript">
  657. $('#piList').sortable({
  658.   containment: 'parent'
  659. });
  660.  
  661. var piSize = <?php echo $pi_counter; ?>;
  662.  
  663. function addNewPiForm() {
  664.   piSize++;
  665.  
  666.   $('#piList').append('<li id="piId' + piSize + '" class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s" style="float: right;"></span><a href="#" onclick="showPiDelConfirm(' + piSize + ');return false;" class="ui-icon ui-icon-trash" style="float: right;"></a><strong><?php echo TEXT_PRODUCTS_LARGE_IMAGE; ?></strong><br /><input type="file" name="products_image_large_new_' + piSize + '" /><br /><br /><?php echo TEXT_PRODUCTS_LARGE_IMAGE_HTML_CONTENT; ?><br /><textarea name="products_image_htmlcontent_new_' + piSize + '" wrap="soft" cols="70" rows="3"></textarea></li>');
  667. }
  668.  
  669. var piDelConfirmId = 0;
  670.  
  671. $('#piDelConfirm').dialog({
  672.   autoOpen: false,
  673.   resizable: false,
  674.   draggable: false,
  675.   modal: true,
  676.   buttons: {
  677.     'Delete': function() {
  678.       $('#piId' + piDelConfirmId).effect('blind').remove();
  679.       $(this).dialog('close');
  680.     },
  681.     Cancel: function() {
  682.       $(this).dialog('close');
  683.     }
  684.   }
  685. });
  686.  
  687. function showPiDelConfirm(piId) {
  688.   piDelConfirmId = piId;
  689.  
  690.   $('#piDelConfirm').dialog('open');
  691. }
  692. </script>
  693.  
  694.             </td>
  695.           </tr>
  696.           <tr>
  697.             <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  698.           </tr>
  699. <?php
  700.     for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
  701. ?>
  702.           <tr>
  703.             <td class="main"><?php if ($i == 0) echo TEXT_PRODUCTS_URL . '<br /><small>' . TEXT_PRODUCTS_URL_WITHOUT_HTTP . '</small>'; ?></td>
  704.             <td class="main"><?php echo tep_image(tep_catalog_href_link(DIR_WS_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], '', 'SSL'), $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('products_url[' . $languages[$i]['id'] . ']', (isset($products_url[$languages[$i]['id']]) ? stripslashes($products_url[$languages[$i]['id']]) : tep_get_products_url($pInfo->products_id, $languages[$i]['id']))); ?></td>
  705.           </tr>
  706. <?php
  707.     }
  708. ?>
  709.           <tr>
  710.             <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  711.           </tr>
  712.           <tr>
  713.             <td class="main"><?php echo TEXT_PRODUCTS_WEIGHT; ?></td>
  714.             <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_weight', $pInfo->products_weight); ?></td>
  715.           </tr>
  716.           <!-- Canada Post OST Start -->
  717.           <tr>
  718.             <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  719.           </tr>
  720.           <tr>
  721.             <td class="main"><?php echo TEXT_PRODUCTS_LENGTH; ?></td>
  722.             <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_length', $pInfo->products_length); ?></td>
  723.           </tr>
  724.           <tr>
  725.             <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  726.           </tr>
  727.           <tr>
  728.             <td class="main"><?php echo TEXT_PRODUCTS_WIDTH; ?></td>
  729.             <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_width', $pInfo->products_width); ?></td>
  730.           </tr>
  731.           <tr>
  732.             <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  733.           </tr>
  734.           <tr>
  735.             <td class="main"><?php echo TEXT_PRODUCTS_HEIGHT; ?></td>
  736.             <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_height', $pInfo->products_height); ?></td>
  737.           </tr>
  738.           <tr>
  739.             <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  740.           </tr>
  741.           <tr>
  742.             <td class="main"><?php echo TEXT_PRODUCTS_READY_TO_SHIP; ?></td>
  743.             <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_checkbox_field('products_ready_to_ship', '1', $pInfo->products_ready_to_ship) . '&nbsp;' . TEXT_PRODUCTS_READY_TO_SHIP_SELECTION . '&nbsp;' ?></td>
  744.           </tr>
  745.           <tr>
  746.             <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  747.           </tr>
  748.           <!-- Canada Post OST End -->
  749.         </table></td>
  750.       </tr>
  751.       <tr>
  752.         <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  753.       </tr>
  754.       <tr>
  755.         <td class="smallText" align="right"><?php echo tep_draw_hidden_field('products_date_added', (tep_not_null($pInfo->products_date_added) ? $pInfo->products_date_added : date('Y-m-d'))) . tep_draw_button(IMAGE_SAVE, 'disk', null, 'primary') . tep_draw_button(IMAGE_CANCEL, 'close', tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . (isset($HTTP_GET_VARS['pID']) ? '&pID=' . $HTTP_GET_VARS['pID'] : ''))); ?></td>
  756.       </tr>
  757.     </table>
  758.  
  759. <script type="text/javascript">
  760. $('#products_date_available').datepicker({
  761.   dateFormat: 'yy-mm-dd'
  762. });
  763. </script>
  764.  
  765.     </form>
  766. <?php
  767.   } elseif ($action == 'new_product_preview') {
  768.     // Canada Post OST adding, "p.products_description_short, p.products_tariff, p.products_length, p.products_width, p.products_height, p.products_ready_to_ship"
  769.     $product_query = tep_db_query("select p.products_id, pd.language_id, pd.products_name, pd.products_description, pd.products_url, p.products_quantity, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_length, p.products_width, p.products_height, p.products_ready_to_ship, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status, p.manufacturers_id  from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and p.products_id = '" . (int)$HTTP_GET_VARS['pID'] . "'");
  770.     $product = tep_db_fetch_array($product_query);
  771.  
  772.     $pInfo = new objectInfo($product);
  773.     $products_image_name = $pInfo->products_image;
  774.  
  775.     $languages = tep_get_languages();
  776.     for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
  777.       $pInfo->products_name = tep_get_products_name($pInfo->products_id, $languages[$i]['id']);
  778.       $pInfo->products_description = tep_get_products_description($pInfo->products_id, $languages[$i]['id']);
  779.       $pInfo->products_url = tep_get_products_url($pInfo->products_id, $languages[$i]['id']);
  780. ?>
  781.     <table border="0" width="100%" cellspacing="0" cellpadding="2">
  782.       <tr>
  783.         <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
  784.           <tr>
  785.             <td class="pageHeading"><?php echo tep_image(tep_catalog_href_link(DIR_WS_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], '', 'SSL'), $languages[$i]['name']) . '&nbsp;' . $pInfo->products_name; ?></td>
  786.             <td class="pageHeading" align="right"><?php echo $currencies->format($pInfo->products_price); ?></td>
  787.           </tr>
  788.         </table></td>
  789.       </tr>
  790.       <tr>
  791.         <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  792.       </tr>
  793.       <tr>
  794.         <td class="main"><?php echo tep_image(HTTP_CATALOG_SERVER . DIR_WS_CATALOG_IMAGES . $products_image_name, $pInfo->products_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'align="right" hspace="5" vspace="5"') . $pInfo->products_description; ?></td>
  795.       </tr>
  796. <?php
  797.       if ($pInfo->products_url) {
  798. ?>
  799.       <tr>
  800.         <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  801.       </tr>
  802.       <tr>
  803.         <td class="main"><?php echo sprintf(TEXT_PRODUCT_MORE_INFORMATION, $pInfo->products_url); ?></td>
  804.       </tr>
  805. <?php
  806.       }
  807. ?>
  808.       <tr>
  809.         <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  810.       </tr>
  811. <?php
  812.       if ($pInfo->products_date_available > date('Y-m-d')) {
  813. ?>
  814.       <tr>
  815.         <td align="center" class="smallText"><?php echo sprintf(TEXT_PRODUCT_DATE_AVAILABLE, tep_date_long($pInfo->products_date_available)); ?></td>
  816.       </tr>
  817. <?php
  818.       } else {
  819. ?>
  820.       <tr>
  821.         <td align="center" class="smallText"><?php echo sprintf(TEXT_PRODUCT_DATE_ADDED, tep_date_long($pInfo->products_date_added)); ?></td>
  822.       </tr>
  823. <?php
  824.       }
  825. ?>
  826.       <tr>
  827.         <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  828.       </tr>
  829. <?php
  830.     }
  831.  
  832.     if (isset($HTTP_GET_VARS['origin'])) {
  833.       $pos_params = strpos($HTTP_GET_VARS['origin'], '?', 0);
  834.       if ($pos_params != false) {
  835.         $back_url = substr($HTTP_GET_VARS['origin'], 0, $pos_params);
  836.         $back_url_params = substr($HTTP_GET_VARS['origin'], $pos_params + 1);
  837.       } else {
  838.         $back_url = $HTTP_GET_VARS['origin'];
  839.         $back_url_params = '';
  840.       }
  841.     } else {
  842.       $back_url = FILENAME_CATEGORIES;
  843.       $back_url_params = 'cPath=' . $cPath . '&pID=' . $pInfo->products_id;
  844.     }
  845. ?>
  846.       <tr>
  847.         <td align="right" class="smallText"><?php echo tep_draw_button(IMAGE_BACK, 'triangle-1-w', tep_href_link($back_url, $back_url_params)); ?></td>
  848.       </tr>
  849.     </table>
  850. <?php
  851.   } else {
  852. ?>
  853.     <table border="0" width="100%" cellspacing="0" cellpadding="2">
  854.       <tr>
  855.         <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
  856.           <tr>
  857.             <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
  858.             <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', 1, HEADING_IMAGE_HEIGHT); ?></td>
  859.             <td align="right"><table border="0" width="100%" cellspacing="0" cellpadding="0">
  860.               <tr>
  861.                 <td class="smallText" align="right">
  862. <?php
  863.     echo tep_draw_form('search', FILENAME_CATEGORIES, '', 'get');
  864.     echo HEADING_TITLE_SEARCH . ' ' . tep_draw_input_field('search');
  865.     echo tep_hide_session_id() . '</form>';
  866. ?>
  867.                 </td>
  868.               </tr>
  869.               <tr>
  870.                 <td class="smallText" align="right">
  871. <?php
  872.     echo tep_draw_form('goto', FILENAME_CATEGORIES, '', 'get');
  873.     echo HEADING_TITLE_GOTO . ' ' . tep_draw_pull_down_menu('cPath', tep_get_category_tree(), $current_category_id, 'onchange="this.form.submit();"');
  874.     echo tep_hide_session_id() . '</form>';
  875. ?>
  876.                 </td>
  877.               </tr>
  878.             </table></td>
  879.           </tr>
  880.         </table></td>
  881.       </tr>
  882.       <tr>
  883.         <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
  884.           <tr>
  885.             <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
  886.               <tr class="dataTableHeadingRow">
  887.                 <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_CATEGORIES_PRODUCTS; ?></td>
  888.                 <td class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_STATUS; ?></td>
  889.                 <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
  890.               </tr>
  891. <?php
  892.     $categories_count = 0;
  893.     $rows = 0;
  894.     if (isset($HTTP_GET_VARS['search'])) {
  895.       $search = tep_db_prepare_input($HTTP_GET_VARS['search']);
  896.  
  897.       $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.categories_image, c.parent_id, c.sort_order, c.date_added, c.last_modified from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' and cd.categories_name like '%" . tep_db_input($search) . "%' order by c.sort_order, cd.categories_name");
  898.     } else {
  899.       $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.categories_image, c.parent_id, c.sort_order, c.date_added, c.last_modified from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$current_category_id . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' order by c.sort_order, cd.categories_name");
  900.     }
  901.     while ($categories = tep_db_fetch_array($categories_query)) {
  902.       $categories_count++;
  903.       $rows++;
  904.  
  905. // Get parent_id for subcategories if search
  906.       if (isset($HTTP_GET_VARS['search'])) $cPath= $categories['parent_id'];
  907.  
  908.       if ((!isset($HTTP_GET_VARS['cID']) && !isset($HTTP_GET_VARS['pID']) || (isset($HTTP_GET_VARS['cID']) && ($HTTP_GET_VARS['cID'] == $categories['categories_id']))) && !isset($cInfo) && (substr($action, 0, 3) != 'new')) {
  909.         $category_childs = array('childs_count' => tep_childs_in_category_count($categories['categories_id']));
  910.         $category_products = array('products_count' => tep_products_in_category_count($categories['categories_id']));
  911.  
  912.         $cInfo_array = array_merge($categories, $category_childs, $category_products);
  913.         $cInfo = new objectInfo($cInfo_array);
  914.       }
  915.  
  916.       if (isset($cInfo) && is_object($cInfo) && ($categories['categories_id'] == $cInfo->categories_id) ) {
  917.         echo '              <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_CATEGORIES, tep_get_path($categories['categories_id'])) . '\'">' . "\n";
  918.       } else {
  919.         echo '              <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&cID=' . $categories['categories_id']) . '\'">' . "\n";
  920.       }
  921. ?>
  922.                 <td class="dataTableContent"><?php echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, tep_get_path($categories['categories_id'])) . '">' . tep_image(DIR_WS_ICONS . 'folder.gif', ICON_FOLDER) . '</a>&nbsp;<strong>' . $categories['categories_name'] . '</strong>'; ?></td>
  923.                 <td class="dataTableContent" align="center">&nbsp;</td>
  924.                 <td class="dataTableContent" align="right"><?php if (isset($cInfo) && is_object($cInfo) && ($categories['categories_id'] == $cInfo->categories_id) ) { echo tep_image(DIR_WS_IMAGES . 'icon_arrow_right.gif', ''); } else { echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&cID=' . $categories['categories_id']) . '">' . tep_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; } ?>&nbsp;</td>
  925.               </tr>
  926. <?php
  927.     }
  928.  
  929.     $products_count = 0;
  930.     if (isset($HTTP_GET_VARS['search'])) {
  931.       $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_quantity, p.products_image, p.products_price, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status, p2c.categories_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = p2c.products_id and pd.products_name like '%" . tep_db_input($search) . "%' order by pd.products_name");
  932.     } else {
  933.       $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_quantity, p.products_image, p.products_price, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$current_category_id . "' order by pd.products_name");
  934.     }
  935.     while ($products = tep_db_fetch_array($products_query)) {
  936.       $products_count++;
  937.       $rows++;
  938.  
  939. // Get categories_id for product if search
  940.       if (isset($HTTP_GET_VARS['search'])) $cPath = $products['categories_id'];
  941.  
  942.       if ( (!isset($HTTP_GET_VARS['pID']) && !isset($HTTP_GET_VARS['cID']) || (isset($HTTP_GET_VARS['pID']) && ($HTTP_GET_VARS['pID'] == $products['products_id']))) && !isset($pInfo) && !isset($cInfo) && (substr($action, 0, 3) != 'new')) {
  943. // find out the rating average from customer reviews
  944.         $reviews_query = tep_db_query("select (avg(reviews_rating) / 5 * 100) as average_rating from " . TABLE_REVIEWS . " where products_id = '" . (int)$products['products_id'] . "'");
  945.         $reviews = tep_db_fetch_array($reviews_query);
  946.         $pInfo_array = array_merge($products, $reviews);
  947.         $pInfo = new objectInfo($pInfo_array);
  948.       }
  949.  
  950.       if (isset($pInfo) && is_object($pInfo) && ($products['products_id'] == $pInfo->products_id) ) {
  951.         echo '              <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $products['products_id'] . '&action=new_product_preview') . '\'">' . "\n";
  952.       } else {
  953.         echo '              <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $products['products_id']) . '\'">' . "\n";
  954.       }
  955. ?>
  956.                 <td class="dataTableContent"><?php echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $products['products_id'] . '&action=new_product_preview') . '">' . tep_image(DIR_WS_ICONS . 'preview.gif', ICON_PREVIEW) . '</a>&nbsp;' . $products['products_name']; ?></td>
  957.                 <td class="dataTableContent" align="center">
  958. <?php
  959.       if ($products['products_status'] == '1') {
  960.         echo tep_image(DIR_WS_IMAGES . 'icon_status_green.gif', IMAGE_ICON_STATUS_GREEN, 10, 10) . '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_CATEGORIES, 'action=setflag&flag=0&pID=' . $products['products_id'] . '&cPath=' . $cPath) . '">' . tep_image(DIR_WS_IMAGES . 'icon_status_red_light.gif', IMAGE_ICON_STATUS_RED_LIGHT, 10, 10) . '</a>';
  961.       } else {
  962.         echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'action=setflag&flag=1&pID=' . $products['products_id'] . '&cPath=' . $cPath) . '">' . tep_image(DIR_WS_IMAGES . 'icon_status_green_light.gif', IMAGE_ICON_STATUS_GREEN_LIGHT, 10, 10) . '</a>&nbsp;&nbsp;' . tep_image(DIR_WS_IMAGES . 'icon_status_red.gif', IMAGE_ICON_STATUS_RED, 10, 10);
  963.       }
  964. ?></td>
  965.                 <td class="dataTableContent" align="right"><?php if (isset($pInfo) && is_object($pInfo) && ($products['products_id'] == $pInfo->products_id)) { echo tep_image(DIR_WS_IMAGES . 'icon_arrow_right.gif', ''); } else { echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; } ?>&nbsp;</td>
  966.               </tr>
  967. <?php
  968.     }
  969.  
  970.     $cPath_back = '';
  971.     if (sizeof($cPath_array) > 0) {
  972.       for ($i=0, $n=sizeof($cPath_array)-1; $i<$n; $i++) {
  973.         if (empty($cPath_back)) {
  974.           $cPath_back .= $cPath_array[$i];
  975.         } else {
  976.           $cPath_back .= '_' . $cPath_array[$i];
  977.         }
  978.       }
  979.     }
  980.  
  981.     $cPath_back = (tep_not_null($cPath_back)) ? 'cPath=' . $cPath_back . '&' : '';
  982. ?>
  983.               <tr>
  984.                 <td colspan="3"><table border="0" width="100%" cellspacing="0" cellpadding="2">
  985.                   <tr>
  986.                     <td class="smallText"><?php echo TEXT_CATEGORIES . '&nbsp;' . $categories_count . '<br />' . TEXT_PRODUCTS . '&nbsp;' . $products_count; ?></td>
  987.                     <td align="right" class="smallText"><?php if (sizeof($cPath_array) > 0) echo tep_draw_button(IMAGE_BACK, 'triangle-1-w', tep_href_link(FILENAME_CATEGORIES, $cPath_back . 'cID=' . $current_category_id)); if (!isset($HTTP_GET_VARS['search'])) echo tep_draw_button(IMAGE_NEW_CATEGORY, 'plus', tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&action=new_category')) . tep_draw_button(IMAGE_NEW_PRODUCT, 'plus', tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&action=new_product')); ?>&nbsp;</td>
  988.                   </tr>
  989.                 </table></td>
  990.               </tr>
  991.             </table></td>
  992. <?php
  993.     $heading = array();
  994.     $contents = array();
  995.     switch ($action) {
  996.       case 'new_category':
  997.         $heading[] = array('text' => '<strong>' . TEXT_INFO_HEADING_NEW_CATEGORY . '</strong>');
  998.  
  999.         $contents = array('form' => tep_draw_form('newcategory', FILENAME_CATEGORIES, 'action=insert_category&cPath=' . $cPath, 'post', 'enctype="multipart/form-data"'));
  1000.         $contents[] = array('text' => TEXT_NEW_CATEGORY_INTRO);
  1001.  
  1002.         $category_inputs_string = '';
  1003.         $languages = tep_get_languages();
  1004.         for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
  1005.           $category_inputs_string .= '<br />' . tep_image(tep_catalog_href_link(DIR_WS_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], '', 'SSL'), $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('categories_name[' . $languages[$i]['id'] . ']');
  1006.         }
  1007.  
  1008.         $contents[] = array('text' => '<br />' . TEXT_CATEGORIES_NAME . $category_inputs_string);
  1009.         $contents[] = array('text' => '<br />' . TEXT_CATEGORIES_IMAGE . '<br />' . tep_draw_file_field('categories_image'));
  1010.         $contents[] = array('text' => '<br />' . TEXT_SORT_ORDER . '<br />' . tep_draw_input_field('sort_order', '', 'size="2"'));
  1011.         $contents[] = array('align' => 'center', 'text' => '<br />' . tep_draw_button(IMAGE_SAVE, 'disk', null, 'primary') . tep_draw_button(IMAGE_CANCEL, 'close', tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath)));
  1012.         break;
  1013.       case 'edit_category':
  1014.         $heading[] = array('text' => '<strong>' . TEXT_INFO_HEADING_EDIT_CATEGORY . '</strong>');
  1015.  
  1016.         $contents = array('form' => tep_draw_form('categories', FILENAME_CATEGORIES, 'action=update_category&cPath=' . $cPath, 'post', 'enctype="multipart/form-data"') . tep_draw_hidden_field('categories_id', $cInfo->categories_id));
  1017.         $contents[] = array('text' => TEXT_EDIT_INTRO);
  1018.  
  1019.         $category_inputs_string = '';
  1020.         $languages = tep_get_languages();
  1021.         for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
  1022.           $category_inputs_string .= '<br />' . tep_image(tep_catalog_href_link(DIR_WS_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], '', 'SSL'), $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('categories_name[' . $languages[$i]['id'] . ']', tep_get_category_name($cInfo->categories_id, $languages[$i]['id']));
  1023.         }
  1024.  
  1025.         $contents[] = array('text' => '<br />' . TEXT_EDIT_CATEGORIES_NAME . $category_inputs_string);
  1026.         $contents[] = array('text' => '<br />' . tep_image(HTTP_CATALOG_SERVER . DIR_WS_CATALOG_IMAGES . $cInfo->categories_image, $cInfo->categories_name) . '<br />' . DIR_WS_CATALOG_IMAGES . '<br /><strong>' . $cInfo->categories_image . '</strong>');
  1027.         $contents[] = array('text' => '<br />' . TEXT_EDIT_CATEGORIES_IMAGE . '<br />' . tep_draw_file_field('categories_image'));
  1028.         $contents[] = array('text' => '<br />' . TEXT_EDIT_SORT_ORDER . '<br />' . tep_draw_input_field('sort_order', $cInfo->sort_order, 'size="2"'));
  1029.         $contents[] = array('align' => 'center', 'text' => '<br />' . tep_draw_button(IMAGE_SAVE, 'disk', null, 'primary') . tep_draw_button(IMAGE_CANCEL, 'close', tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&cID=' . $cInfo->categories_id)));
  1030.         break;
  1031.       case 'delete_category':
  1032.         $heading[] = array('text' => '<strong>' . TEXT_INFO_HEADING_DELETE_CATEGORY . '</strong>');
  1033.  
  1034.         $contents = array('form' => tep_draw_form('categories', FILENAME_CATEGORIES, 'action=delete_category_confirm&cPath=' . $cPath) . tep_draw_hidden_field('categories_id', $cInfo->categories_id));
  1035.         $contents[] = array('text' => TEXT_DELETE_CATEGORY_INTRO);
  1036.         $contents[] = array('text' => '<br /><strong>' . $cInfo->categories_name . '</strong>');
  1037.         if ($cInfo->childs_count > 0) $contents[] = array('text' => '<br />' . sprintf(TEXT_DELETE_WARNING_CHILDS, $cInfo->childs_count));
  1038.         if ($cInfo->products_count > 0) $contents[] = array('text' => '<br />' . sprintf(TEXT_DELETE_WARNING_PRODUCTS, $cInfo->products_count));
  1039.         $contents[] = array('align' => 'center', 'text' => '<br />' . tep_draw_button(IMAGE_DELETE, 'trash', null, 'primary') . tep_draw_button(IMAGE_CANCEL, 'close', tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&cID=' . $cInfo->categories_id)));
  1040.         break;
  1041.       case 'move_category':
  1042.         $heading[] = array('text' => '<strong>' . TEXT_INFO_HEADING_MOVE_CATEGORY . '</strong>');
  1043.  
  1044.         $contents = array('form' => tep_draw_form('categories', FILENAME_CATEGORIES, 'action=move_category_confirm&cPath=' . $cPath) . tep_draw_hidden_field('categories_id', $cInfo->categories_id));
  1045.         $contents[] = array('text' => sprintf(TEXT_MOVE_CATEGORIES_INTRO, $cInfo->categories_name));
  1046.         $contents[] = array('text' => '<br />' . sprintf(TEXT_MOVE, $cInfo->categories_name) . '<br />' . tep_draw_pull_down_menu('move_to_category_id', tep_get_category_tree(), $current_category_id));
  1047.         $contents[] = array('align' => 'center', 'text' => '<br />' . tep_draw_button(IMAGE_MOVE, 'arrow-4', null, 'primary') . tep_draw_button(IMAGE_CANCEL, 'close', tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&cID=' . $cInfo->categories_id)));
  1048.         break;
  1049.       case 'delete_product':
  1050.         $heading[] = array('text' => '<strong>' . TEXT_INFO_HEADING_DELETE_PRODUCT . '</strong>');
  1051.  
  1052.         $contents = array('form' => tep_draw_form('products', FILENAME_CATEGORIES, 'action=delete_product_confirm&cPath=' . $cPath) . tep_draw_hidden_field('products_id', $pInfo->products_id));
  1053.         $contents[] = array('text' => TEXT_DELETE_PRODUCT_INTRO);
  1054.         $contents[] = array('text' => '<br /><strong>' . $pInfo->products_name . '</strong>');
  1055.  
  1056.         $product_categories_string = '';
  1057.         $product_categories = tep_generate_category_path($pInfo->products_id, 'product');
  1058.         for ($i = 0, $n = sizeof($product_categories); $i < $n; $i++) {
  1059.           $category_path = '';
  1060.           for ($j = 0, $k = sizeof($product_categories[$i]); $j < $k; $j++) {
  1061.             $category_path .= $product_categories[$i][$j]['text'] . '&nbsp;&gt;&nbsp;';
  1062.           }
  1063.           $category_path = substr($category_path, 0, -16);
  1064.           $product_categories_string .= tep_draw_checkbox_field('product_categories[]', $product_categories[$i][sizeof($product_categories[$i])-1]['id'], true) . '&nbsp;' . $category_path . '<br />';
  1065.         }
  1066.         $product_categories_string = substr($product_categories_string, 0, -4);
  1067.  
  1068.         $contents[] = array('text' => '<br />' . $product_categories_string);
  1069.         $contents[] = array('align' => 'center', 'text' => '<br />' . tep_draw_button(IMAGE_DELETE, 'trash', null, 'primary') . tep_draw_button(IMAGE_CANCEL, 'close', tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $pInfo->products_id)));
  1070.         break;
  1071.       case 'move_product':
  1072.         $heading[] = array('text' => '<strong>' . TEXT_INFO_HEADING_MOVE_PRODUCT . '</strong>');
  1073.  
  1074.         $contents = array('form' => tep_draw_form('products', FILENAME_CATEGORIES, 'action=move_product_confirm&cPath=' . $cPath) . tep_draw_hidden_field('products_id', $pInfo->products_id));
  1075.         $contents[] = array('text' => sprintf(TEXT_MOVE_PRODUCTS_INTRO, $pInfo->products_name));
  1076.         $contents[] = array('text' => '<br />' . TEXT_INFO_CURRENT_CATEGORIES . '<br /><strong>' . tep_output_generated_category_path($pInfo->products_id, 'product') . '</strong>');
  1077.         $contents[] = array('text' => '<br />' . sprintf(TEXT_MOVE, $pInfo->products_name) . '<br />' . tep_draw_pull_down_menu('move_to_category_id', tep_get_category_tree(), $current_category_id));
  1078.         $contents[] = array('align' => 'center', 'text' => '<br />' . tep_draw_button(IMAGE_MOVE, 'arrow-4', null, 'primary') . tep_draw_button(IMAGE_CANCEL, 'close', tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $pInfo->products_id)));
  1079.         break;
  1080.       case 'copy_to':
  1081.         $heading[] = array('text' => '<strong>' . TEXT_INFO_HEADING_COPY_TO . '</strong>');
  1082.  
  1083.         $contents = array('form' => tep_draw_form('copy_to', FILENAME_CATEGORIES, 'action=copy_to_confirm&cPath=' . $cPath) . tep_draw_hidden_field('products_id', $pInfo->products_id));
  1084.         $contents[] = array('text' => TEXT_INFO_COPY_TO_INTRO);
  1085.         $contents[] = array('text' => '<br />' . TEXT_INFO_CURRENT_CATEGORIES . '<br /><strong>' . tep_output_generated_category_path($pInfo->products_id, 'product') . '</strong>');
  1086.         $contents[] = array('text' => '<br />' . TEXT_CATEGORIES . '<br />' . tep_draw_pull_down_menu('categories_id', tep_get_category_tree(), $current_category_id));
  1087.         $contents[] = array('text' => '<br />' . TEXT_HOW_TO_COPY . '<br />' . tep_draw_radio_field('copy_as', 'link', true) . ' ' . TEXT_COPY_AS_LINK . '<br />' . tep_draw_radio_field('copy_as', 'duplicate') . ' ' . TEXT_COPY_AS_DUPLICATE);
  1088.         $contents[] = array('align' => 'center', 'text' => '<br />' . tep_draw_button(IMAGE_COPY, 'copy', null, 'primary') . tep_draw_button(IMAGE_CANCEL, 'close', tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $pInfo->products_id)));
  1089.         break;
  1090.       default:
  1091.         if ($rows > 0) {
  1092.           if (isset($cInfo) && is_object($cInfo)) { // category info box contents
  1093.             $category_path_string = '';
  1094.             $category_path = tep_generate_category_path($cInfo->categories_id);
  1095.             for ($i=(sizeof($category_path[0])-1); $i>0; $i--) {
  1096.               $category_path_string .= $category_path[0][$i]['id'] . '_';
  1097.             }
  1098.             $category_path_string = substr($category_path_string, 0, -1);
  1099.  
  1100.             $heading[] = array('text' => '<strong>' . $cInfo->categories_name . '</strong>');
  1101.  
  1102.             $contents[] = array('align' => 'center', 'text' => tep_draw_button(IMAGE_EDIT, 'document', tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $category_path_string . '&cID=' . $cInfo->categories_id . '&action=edit_category')) . tep_draw_button(IMAGE_DELETE, 'trash', tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $category_path_string . '&cID=' . $cInfo->categories_id . '&action=delete_category')) . tep_draw_button(IMAGE_MOVE, 'arrow-4', tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $category_path_string . '&cID=' . $cInfo->categories_id . '&action=move_category')));
  1103.             $contents[] = array('text' => '<br />' . TEXT_DATE_ADDED . ' ' . tep_date_short($cInfo->date_added));
  1104.             if (tep_not_null($cInfo->last_modified)) $contents[] = array('text' => TEXT_LAST_MODIFIED . ' ' . tep_date_short($cInfo->last_modified));
  1105.             $contents[] = array('text' => '<br />' . tep_info_image($cInfo->categories_image, $cInfo->categories_name, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT) . '<br />' . $cInfo->categories_image);
  1106.             $contents[] = array('text' => '<br />' . TEXT_SUBCATEGORIES . ' ' . $cInfo->childs_count . '<br />' . TEXT_PRODUCTS . ' ' . $cInfo->products_count);
  1107.           } elseif (isset($pInfo) && is_object($pInfo)) { // product info box contents
  1108.             $heading[] = array('text' => '<strong>' . tep_get_products_name($pInfo->products_id, $languages_id) . '</strong>');
  1109.  
  1110.             $contents[] = array('align' => 'center', 'text' => tep_draw_button(IMAGE_EDIT, 'document', tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $pInfo->products_id . '&action=new_product')) . tep_draw_button(IMAGE_DELETE, 'trash', tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $pInfo->products_id . '&action=delete_product')) . tep_draw_button(IMAGE_MOVE, 'arrow-4', tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $pInfo->products_id . '&action=move_product')) . tep_draw_button(IMAGE_COPY_TO, 'copy', tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $pInfo->products_id . '&action=copy_to')));
  1111.             $contents[] = array('text' => '<br />' . TEXT_DATE_ADDED . ' ' . tep_date_short($pInfo->products_date_added));
  1112.             if (tep_not_null($pInfo->products_last_modified)) $contents[] = array('text' => TEXT_LAST_MODIFIED . ' ' . tep_date_short($pInfo->products_last_modified));
  1113.             if (date('Y-m-d') < $pInfo->products_date_available) $contents[] = array('text' => TEXT_DATE_AVAILABLE . ' ' . tep_date_short($pInfo->products_date_available));
  1114.             $contents[] = array('text' => '<br />' . tep_info_image($pInfo->products_image, $pInfo->products_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '<br />' . $pInfo->products_image);
  1115.             $contents[] = array('text' => '<br />' . TEXT_PRODUCTS_PRICE_INFO . ' ' . $currencies->format($pInfo->products_price) . '<br />' . TEXT_PRODUCTS_QUANTITY_INFO . ' ' . $pInfo->products_quantity);
  1116.             $contents[] = array('text' => '<br />' . TEXT_PRODUCTS_AVERAGE_RATING . ' ' . number_format($pInfo->average_rating, 2) . '%');
  1117.           }
  1118.         } else { // create category/product info
  1119.           $heading[] = array('text' => '<strong>' . EMPTY_CATEGORY . '</strong>');
  1120.  
  1121.           $contents[] = array('text' => TEXT_NO_CHILD_CATEGORIES_OR_PRODUCTS);
  1122.         }
  1123.         break;
  1124.     }
  1125.  
  1126.     if ( (tep_not_null($heading)) && (tep_not_null($contents)) ) {
  1127.       echo '            <td width="25%" valign="top">' . "\n";
  1128.  
  1129.       $box = new box;
  1130.       echo $box->infoBox($heading, $contents);
  1131.  
  1132.       echo '            </td>' . "\n";
  1133.     }
  1134. ?>
  1135.           </tr>
  1136.         </table></td>
  1137.       </tr>
  1138.     </table>
  1139. <?php
  1140.   }
  1141.  
  1142.   require(DIR_WS_INCLUDES . 'template_bottom.php');
  1143.   require(DIR_WS_INCLUDES . 'application_bottom.php');
  1144. ?>
Add Comment
Please, Sign In to add comment