Guest User

Untitled

a guest
Nov 20th, 2011
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 66.46 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) 2010 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.     // ULTIMATE Seo Urls 5 PRO by FWR Media
  22.     // If the action will affect the cache entries
  23.     if ( $action == 'insert' || $action == 'update' || $action == 'setflag' ) {
  24.       tep_reset_cache_data_usu5( 'reset' );
  25.     }
  26.     switch ($action) {
  27.       case 'setflag':
  28.         if ( ($HTTP_GET_VARS['flag'] == '0') || ($HTTP_GET_VARS['flag'] == '1') ) {
  29.           if (isset($HTTP_GET_VARS['pID'])) {
  30.             tep_set_product_status($HTTP_GET_VARS['pID'], $HTTP_GET_VARS['flag']);
  31.           }
  32.  
  33.           if (USE_CACHE == 'true') {
  34.             tep_reset_cache_block('categories');
  35.             tep_reset_cache_block('also_purchased');
  36.           }
  37.         }
  38.  
  39.         tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $HTTP_GET_VARS['cPath'] . '&pID=' . $HTTP_GET_VARS['pID']));
  40.         break;
  41.       case 'insert_category':
  42.       case 'update_category':
  43.         if (isset($HTTP_POST_VARS['categories_id'])) $categories_id = tep_db_prepare_input($HTTP_POST_VARS['categories_id']);
  44.         $sort_order = tep_db_prepare_input($HTTP_POST_VARS['sort_order']);
  45.  
  46.         $sql_data_array = array('sort_order' => (int)$sort_order);
  47.  
  48.         if ($action == 'insert_category') {
  49.           $insert_sql_data = array('parent_id' => $current_category_id,
  50.                                    'date_added' => 'now()');
  51.  
  52.           $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
  53.  
  54.           tep_db_perform(TABLE_CATEGORIES, $sql_data_array);
  55.  
  56.           $categories_id = tep_db_insert_id();
  57.         } elseif ($action == 'update_category') {
  58.           $update_sql_data = array('last_modified' => 'now()');
  59.  
  60.           $sql_data_array = array_merge($sql_data_array, $update_sql_data);
  61.  
  62.           tep_db_perform(TABLE_CATEGORIES, $sql_data_array, 'update', "categories_id = '" . (int)$categories_id . "'");
  63.         }
  64.  
  65.         $languages = tep_get_languages();
  66.         for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
  67.           $categories_name_array = $HTTP_POST_VARS['categories_name'];
  68.  
  69.           $language_id = $languages[$i]['id'];
  70.  
  71.           $sql_data_array = array('categories_name' => tep_db_prepare_input($categories_name_array[$language_id]));
  72.  
  73.           if ($action == 'insert_category') {
  74.             $insert_sql_data = array('categories_id' => $categories_id,
  75.                                      'language_id' => $languages[$i]['id']);
  76.  
  77.             $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
  78.  
  79.             tep_db_perform(TABLE_CATEGORIES_DESCRIPTION, $sql_data_array);
  80.           } elseif ($action == 'update_category') {
  81.             tep_db_perform(TABLE_CATEGORIES_DESCRIPTION, $sql_data_array, 'update', "categories_id = '" . (int)$categories_id . "' and language_id = '" . (int)$languages[$i]['id'] . "'");
  82.           }
  83.         }
  84.  
  85.         $categories_image = new upload('categories_image');
  86.         $categories_image->set_destination(DIR_FS_CATALOG_IMAGES);
  87.  
  88.         if ($categories_image->parse() && $categories_image->save()) {
  89.           tep_db_query("update " . TABLE_CATEGORIES . " set categories_image = '" . tep_db_input($categories_image->filename) . "' where categories_id = '" . (int)$categories_id . "'");
  90.         }
  91.  
  92.         if (USE_CACHE == 'true') {
  93.           tep_reset_cache_block('categories');
  94.           tep_reset_cache_block('also_purchased');
  95.         }
  96.  
  97.         tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&cID=' . $categories_id));
  98.         break;
  99.       case 'delete_category_confirm':
  100.         if (isset($HTTP_POST_VARS['categories_id'])) {
  101.           $categories_id = tep_db_prepare_input($HTTP_POST_VARS['categories_id']);
  102.  
  103.           $categories = tep_get_category_tree($categories_id, '', '0', '', true);
  104.           $products = array();
  105.           $products_delete = array();
  106.  
  107.           for ($i=0, $n=sizeof($categories); $i<$n; $i++) {
  108.             $product_ids_query = tep_db_query("select products_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id = '" . (int)$categories[$i]['id'] . "'");
  109.  
  110.             while ($product_ids = tep_db_fetch_array($product_ids_query)) {
  111.               $products[$product_ids['products_id']]['categories'][] = $categories[$i]['id'];
  112.             }
  113.           }
  114.  
  115.           reset($products);
  116.           while (list($key, $value) = each($products)) {
  117.             $category_ids = '';
  118.  
  119.             for ($i=0, $n=sizeof($value['categories']); $i<$n; $i++) {
  120.               $category_ids .= "'" . (int)$value['categories'][$i] . "', ";
  121.             }
  122.             $category_ids = substr($category_ids, 0, -2);
  123.  
  124.             $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 . ")");
  125.             $check = tep_db_fetch_array($check_query);
  126.             if ($check['total'] < '1') {
  127.               $products_delete[$key] = $key;
  128.             }
  129.           }
  130.  
  131. // removing categories can be a lengthy process
  132.           tep_set_time_limit(0);
  133.           for ($i=0, $n=sizeof($categories); $i<$n; $i++) {
  134.             tep_remove_category($categories[$i]['id']);
  135.           }
  136.  
  137.           reset($products_delete);
  138.           while (list($key) = each($products_delete)) {
  139.             tep_remove_product($key);
  140.           }
  141.         }
  142.  
  143.         if (USE_CACHE == 'true') {
  144.           tep_reset_cache_block('categories');
  145.           tep_reset_cache_block('also_purchased');
  146.         }
  147.  
  148.         tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath));
  149.         break;
  150.       case 'delete_product_confirm':
  151.         if (isset($HTTP_POST_VARS['products_id']) && isset($HTTP_POST_VARS['product_categories']) && is_array($HTTP_POST_VARS['product_categories'])) {
  152.           $product_id = tep_db_prepare_input($HTTP_POST_VARS['products_id']);
  153.           $product_categories = $HTTP_POST_VARS['product_categories'];
  154.  
  155.           for ($i=0, $n=sizeof($product_categories); $i<$n; $i++) {
  156.             tep_db_query("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$product_id . "' and categories_id = '" . (int)$product_categories[$i] . "'");
  157.           }
  158.  
  159.           $product_categories_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$product_id . "'");
  160.           $product_categories = tep_db_fetch_array($product_categories_query);
  161.  
  162.           if ($product_categories['total'] == '0') {
  163.             tep_remove_product($product_id);
  164.           }
  165.         /* Optional Related Products (ORP) */
  166.           tep_db_query("delete from " . TABLE_PRODUCTS_RELATED_PRODUCTS . " where pop_products_id_master = '" . (int)$product_id . "'");
  167.           tep_db_query("delete from " . TABLE_PRODUCTS_RELATED_PRODUCTS . " where pop_products_id_slave = '" . (int)$product_id . "'");
  168.         //ORP: end
  169.         }
  170.  
  171.         if (USE_CACHE == 'true') {
  172.           tep_reset_cache_block('categories');
  173.           tep_reset_cache_block('also_purchased');
  174.         }
  175.  
  176.         tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath));
  177.         break;
  178.       case 'move_category_confirm':
  179.         if (isset($HTTP_POST_VARS['categories_id']) && ($HTTP_POST_VARS['categories_id'] != $HTTP_POST_VARS['move_to_category_id'])) {
  180.           $categories_id = tep_db_prepare_input($HTTP_POST_VARS['categories_id']);
  181.           $new_parent_id = tep_db_prepare_input($HTTP_POST_VARS['move_to_category_id']);
  182.  
  183.           $path = explode('_', tep_get_generated_category_path_ids($new_parent_id));
  184.  
  185.           if (in_array($categories_id, $path)) {
  186.             $messageStack->add_session(ERROR_CANNOT_MOVE_CATEGORY_TO_PARENT, 'error');
  187.  
  188.             tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&cID=' . $categories_id));
  189.           } else {
  190.             tep_db_query("update " . TABLE_CATEGORIES . " set parent_id = '" . (int)$new_parent_id . "', last_modified = now() where categories_id = '" . (int)$categories_id . "'");
  191.  
  192.             if (USE_CACHE == 'true') {
  193.               tep_reset_cache_block('categories');
  194.               tep_reset_cache_block('also_purchased');
  195.             }
  196.  
  197.             tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $new_parent_id . '&cID=' . $categories_id));
  198.           }
  199.         }
  200.  
  201.         break;
  202.       case 'move_product_confirm':
  203.         $products_id = tep_db_prepare_input($HTTP_POST_VARS['products_id']);
  204.         $new_parent_id = tep_db_prepare_input($HTTP_POST_VARS['move_to_category_id']);
  205.  
  206.         $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 . "'");
  207.         $duplicate_check = tep_db_fetch_array($duplicate_check_query);
  208.         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 . "'");
  209.  
  210.         if (USE_CACHE == 'true') {
  211.           tep_reset_cache_block('categories');
  212.           tep_reset_cache_block('also_purchased');
  213.         }
  214.  
  215.         tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $new_parent_id . '&pID=' . $products_id));
  216.         break;
  217.       case 'insert_product':
  218.       case 'update_product':
  219.         if (isset($HTTP_GET_VARS['pID'])) $products_id = tep_db_prepare_input($HTTP_GET_VARS['pID']);
  220.         $products_date_available = tep_db_prepare_input($HTTP_POST_VARS['products_date_available']);
  221.  
  222.         $products_date_available = (date('Y-m-d') < $products_date_available) ? $products_date_available : 'null';
  223.        
  224.        
  225.  
  226.         $sql_data_array = array('products_quantity' => (int)tep_db_prepare_input($HTTP_POST_VARS['products_quantity']),
  227.                                 'products_model' => tep_db_prepare_input($HTTP_POST_VARS['products_model']),
  228.                                 'products_price' => tep_db_prepare_input($HTTP_POST_VARS['products_price']),
  229.                                 'products_date_available' => $products_date_available,
  230.                                 'products_weight' => (float)tep_db_prepare_input($HTTP_POST_VARS['products_weight']),
  231.                                 'products_status' => tep_db_prepare_input($HTTP_POST_VARS['products_status']),
  232.                                 'products_tax_class_id' => tep_db_prepare_input($HTTP_POST_VARS['products_tax_class_id']),
  233.                                 'manufacturers_id' => (int)tep_db_prepare_input($HTTP_POST_VARS['manufacturers_id']));
  234.                                
  235.                                
  236.         $products_image = new upload('products_image');
  237.         $products_image->set_destination(DIR_FS_CATALOG_IMAGES);
  238.         if ($products_image->parse() && $products_image->save()) {
  239.           $sql_data_array['products_image'] = tep_db_prepare_input($products_image->filename);
  240.         }
  241.  
  242.         if ($action == 'insert_product') {
  243.           $insert_sql_data = array('products_date_added' => 'now()');
  244.  
  245.           $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
  246.  
  247.           tep_db_perform(TABLE_PRODUCTS, $sql_data_array);
  248.           $products_id = tep_db_insert_id();
  249.  
  250.  
  251.           tep_db_query("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . " (products_id, categories_id) values ('" . (int)$products_id . "', '" . (int)$current_category_id . "')");
  252.           tep_db_query("insert into " . TABLE_PRODUCTS_TO_COLORS . " (products_id, color_id) values ('" . (int)$products_id . "', '" . (int)$colorid . "')");
  253.          
  254.         } elseif ($action == 'update_product') {
  255.           $update_sql_data = array('products_last_modified' => 'now()');
  256.  
  257.           $sql_data_array = array_merge($sql_data_array, $update_sql_data);
  258.  
  259.           tep_db_perform(TABLE_PRODUCTS, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "'");
  260.          
  261.          // First, delete all n entries of colors-to-products
  262. tep_db_query("delete from " . TABLE_PRODUCTS_TO_COLORS . " WHERE products_id = '" . (int)$products_id . "'");
  263.  
  264.      // now insert colors from form-request
  265. if (is_array($_GET['color_id'])) {
  266.          foreach ($_GET['color_id'] as $colorid) {
  267.                      tep_db_query("insert into " . TABLE_PRODUCTS_TO_COLORS . " (products_id, color_id) values ('" . (int)$products_id . "', '" . (int)$colorid . "')");
  268.          }
  269. }
  270.  
  271.         }
  272.  
  273.         $languages = tep_get_languages();
  274.         for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
  275.           $language_id = $languages[$i]['id'];
  276.  
  277.           $sql_data_array = array('products_name' => tep_db_prepare_input($HTTP_POST_VARS['products_name'][$language_id]),
  278.                                   'products_description' => tep_db_prepare_input($HTTP_POST_VARS['products_description'][$language_id]),
  279.                                   'products_url' => tep_db_prepare_input($HTTP_POST_VARS['products_url'][$language_id]));
  280.  
  281.           if ($action == 'insert_product') {
  282.             $insert_sql_data = array('products_id' => $products_id,
  283.                                      'language_id' => $language_id);
  284.  
  285.             $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
  286.  
  287.             tep_db_perform(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array);
  288.           } elseif ($action == 'update_product') {
  289.             tep_db_perform(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "' and language_id = '" . (int)$language_id . "'");
  290.           }
  291.         }
  292.  
  293.         $pi_sort_order = 0;
  294.         $piArray = array(0);
  295.  
  296.         foreach ($HTTP_POST_FILES as $key => $value) {
  297. // Update existing large product images
  298.           if (preg_match('/^products_image_large_([0-9]+)$/', $key, $matches)) {
  299.             $pi_sort_order++;
  300.  
  301.             $sql_data_array = array('htmlcontent' => tep_db_prepare_input($HTTP_POST_VARS['products_image_htmlcontent_' . $matches[1]]),
  302.                                     'sort_order' => $pi_sort_order);
  303.  
  304.             $t = new upload($key);
  305.             $t->set_destination(DIR_FS_CATALOG_IMAGES);
  306.             if ($t->parse() && $t->save()) {
  307.               $sql_data_array['image'] = tep_db_prepare_input($t->filename);
  308.             }
  309.  
  310.             tep_db_perform(TABLE_PRODUCTS_IMAGES, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "' and id = '" . (int)$matches[1] . "'");
  311.  
  312.             $piArray[] = (int)$matches[1];
  313.           } elseif (preg_match('/^products_image_large_new_([0-9]+)$/', $key, $matches)) {
  314. // Insert new large product images
  315.             $sql_data_array = array('products_id' => (int)$products_id,
  316.                                     'htmlcontent' => tep_db_prepare_input($HTTP_POST_VARS['products_image_htmlcontent_new_' . $matches[1]]));
  317.  
  318.             $t = new upload($key);
  319.             $t->set_destination(DIR_FS_CATALOG_IMAGES);
  320.             if ($t->parse() && $t->save()) {
  321.               $pi_sort_order++;
  322.  
  323.               $sql_data_array['image'] = tep_db_prepare_input($t->filename);
  324.               $sql_data_array['sort_order'] = $pi_sort_order;
  325.  
  326.               tep_db_perform(TABLE_PRODUCTS_IMAGES, $sql_data_array);
  327.  
  328.               $piArray[] = tep_db_insert_id();
  329.             }
  330.           }
  331.         }
  332.  
  333.         $product_images_query = tep_db_query("select image from " . TABLE_PRODUCTS_IMAGES . " where products_id = '" . (int)$products_id . "' and id not in (" . implode(',', $piArray) . ")");
  334.         if (tep_db_num_rows($product_images_query)) {
  335.           while ($product_images = tep_db_fetch_array($product_images_query)) {
  336.             $duplicate_image_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_IMAGES . " where image = '" . tep_db_input($product_images['image']) . "'");
  337.             $duplicate_image = tep_db_fetch_array($duplicate_image_query);
  338.  
  339.             if ($duplicate_image['total'] < 2) {
  340.               if (file_exists(DIR_FS_CATALOG_IMAGES . $product_images['image'])) {
  341.                 @unlink(DIR_FS_CATALOG_IMAGES . $product_images['image']);
  342.               }
  343.             }
  344.           }
  345.  
  346.           tep_db_query("delete from " . TABLE_PRODUCTS_IMAGES . " where products_id = '" . (int)$products_id . "' and id not in (" . implode(',', $piArray) . ")");
  347.         }
  348.  
  349.         if (USE_CACHE == 'true') {
  350.           tep_reset_cache_block('categories');
  351.           tep_reset_cache_block('also_purchased');
  352.         }
  353.  
  354.         tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $products_id));
  355.         break;
  356.       case 'copy_to_confirm':
  357.         if (isset($HTTP_POST_VARS['products_id']) && isset($HTTP_POST_VARS['categories_id'])) {
  358.           $products_id = tep_db_prepare_input($HTTP_POST_VARS['products_id']);
  359.           $categories_id = tep_db_prepare_input($HTTP_POST_VARS['categories_id']);
  360.  
  361.           if ($HTTP_POST_VARS['copy_as'] == 'link') {
  362.             if ($categories_id != $current_category_id) {
  363.               $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 . "'");
  364.               $check = tep_db_fetch_array($check_query);
  365.               if ($check['total'] < '1') {
  366.                 tep_db_query("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . " (products_id, categories_id) values ('" . (int)$products_id . "', '" . (int)$categories_id . "')");
  367.               }
  368.             } else {
  369.               $messageStack->add_session(ERROR_CANNOT_LINK_TO_SAME_CATEGORY, 'error');
  370.             }
  371.           } elseif ($HTTP_POST_VARS['copy_as'] == 'duplicate') {
  372.             $product_query = tep_db_query("select products_quantity, products_model, products_image, products_price, products_date_available, products_weight, products_tax_class_id, manufacturers_id from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
  373.             $product = tep_db_fetch_array($product_query);
  374.  
  375.             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'] . "')");
  376.             $dup_products_id = tep_db_insert_id();
  377.  
  378.             $description_query = tep_db_query("select language_id, products_name, products_description, products_url from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$products_id . "'");
  379.             while ($description = tep_db_fetch_array($description_query)) {
  380.               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')");
  381.             }
  382.  
  383.             $product_images_query = tep_db_query("select image, htmlcontent, sort_order from " . TABLE_PRODUCTS_IMAGES . " where products_id = '" . (int)$products_id . "'");
  384.             while ($product_images = tep_db_fetch_array($product_images_query)) {
  385.               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']) . "')");
  386.             }
  387.  
  388.             tep_db_query("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . " (products_id, categories_id) values ('" . (int)$dup_products_id . "', '" . (int)$categories_id . "')");
  389.             $products_id = $dup_products_id;
  390.           }
  391.  
  392.           if (USE_CACHE == 'true') {
  393.             tep_reset_cache_block('categories');
  394.             tep_reset_cache_block('also_purchased');
  395.           }
  396.         }
  397.  
  398.         tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $categories_id . '&pID=' . $products_id));
  399.         break;
  400.     }
  401.   }
  402.  
  403. // check if the catalog image directory exists
  404.   if (is_dir(DIR_FS_CATALOG_IMAGES)) {
  405.     if (!tep_is_writable(DIR_FS_CATALOG_IMAGES)) $messageStack->add(ERROR_CATALOG_IMAGE_DIRECTORY_NOT_WRITEABLE, 'error');
  406.   } else {
  407.     $messageStack->add(ERROR_CATALOG_IMAGE_DIRECTORY_DOES_NOT_EXIST, 'error');
  408.   }
  409.  
  410.   require(DIR_WS_INCLUDES . 'template_top.php');
  411.  
  412.   if ($action == 'new_product') {
  413.     $parameters = array('products_name' => '',
  414.                        'products_description' => '',
  415.                        'products_url' => '',
  416.                        'products_id' => '',
  417.                        'products_quantity' => '',
  418.                        'products_model' => '',
  419.                        'products_image' => '',
  420.                        'products_larger_images' => array(),
  421.                        'products_price' => '',
  422.                        'products_weight' => '',
  423.                        'products_date_added' => '',
  424.                        'products_last_modified' => '',
  425.                        'products_date_available' => '',
  426.                        'products_status' => '',
  427.                        'products_tax_class_id' => '',
  428.                        'manufacturers_id' => '');
  429.                        
  430.     $colorid = array ('products_id' => '',
  431.                         'color_id' => '');
  432.    
  433.  
  434.     $pInfo = new objectInfo($parameters);
  435.    
  436.    
  437.  
  438.     if (isset($HTTP_GET_VARS['pID']) && empty($HTTP_POST_VARS)) {
  439.       $product_query = tep_db_query("select pd.products_name, pd.products_description, 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, cid.color_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_COLORS . " cid  where p.products_id = '" . (int)$HTTP_GET_VARS['pID'] . "' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "'");
  440.       $product = tep_db_fetch_array($product_query);
  441.  
  442.       $pInfo->objectInfo($product);
  443.  
  444.       $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");
  445.      
  446.       while ($product_images = tep_db_fetch_array($product_images_query)) {
  447.         $pInfo->products_larger_images[] = array('id' => $product_images['id'],
  448.                                                  'image' => $product_images['image'],
  449.                                                  'htmlcontent' => $product_images['htmlcontent'],
  450.                                                  'sort_order' => $product_images['sort_order']);
  451.       }
  452.     }
  453.  
  454.    
  455.  
  456.     $manufacturers_array = array(array('id' => '', 'text' => TEXT_NONE));
  457.     $manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name");
  458.     while ($manufacturers = tep_db_fetch_array($manufacturers_query)) {
  459.       $manufacturers_array[] = array('id' => $manufacturers['manufacturers_id'],
  460.                                      'text' => $manufacturers['manufacturers_name']);
  461.     }
  462.  
  463.     $tax_class_array = array(array('id' => '0', 'text' => TEXT_NONE));
  464.     $tax_class_query = tep_db_query("select tax_class_id, tax_class_title from " . TABLE_TAX_CLASS . " order by tax_class_title");
  465.     while ($tax_class = tep_db_fetch_array($tax_class_query)) {
  466.       $tax_class_array[] = array('id' => $tax_class['tax_class_id'],
  467.                                  'text' => $tax_class['tax_class_title']);
  468.     }
  469.  
  470.     $languages = tep_get_languages();
  471.  
  472.     if (!isset($pInfo->products_status)) $pInfo->products_status = '1';
  473.     switch ($pInfo->products_status) {
  474.       case '0': $in_status = false; $out_status = true; break;
  475.       case '1':
  476.       default: $in_status = true; $out_status = false;
  477.     }
  478.    
  479.     $form_action = (isset($HTTP_GET_VARS['pID'])) ? 'update_product' : 'insert_product';
  480. ?>
  481. <script type="text/javascript"><!--
  482. var tax_rates = new Array();
  483. <?php
  484.     for ($i=0, $n=sizeof($tax_class_array); $i<$n; $i++) {
  485.       if ($tax_class_array[$i]['id'] > 0) {
  486.         echo 'tax_rates["' . $tax_class_array[$i]['id'] . '"] = ' . tep_get_tax_rate_value($tax_class_array[$i]['id']) . ';' . "\n";
  487.       }
  488.     }
  489. ?>
  490.  
  491. function doRound(x, places) {
  492.   return Math.round(x * Math.pow(10, places)) / Math.pow(10, places);
  493. }
  494.  
  495. function getTaxRate() {
  496.   var selected_value = document.forms["new_product"].products_tax_class_id.selectedIndex;
  497.   var parameterVal = document.forms["new_product"].products_tax_class_id[selected_value].value;
  498.  
  499.   if ( (parameterVal > 0) && (tax_rates[parameterVal] > 0) ) {
  500.     return tax_rates[parameterVal];
  501.   } else {
  502.     return 0;
  503.   }
  504. }
  505.  
  506. function updateGross() {
  507.   var taxRate = getTaxRate();
  508.   var grossValue = document.forms["new_product"].products_price.value;
  509.  
  510.   if (taxRate > 0) {
  511.     grossValue = grossValue * ((taxRate / 100) + 1);
  512.   }
  513.  
  514.   document.forms["new_product"].products_price_gross.value = doRound(grossValue, 4);
  515. }
  516.  
  517. function updateNet() {
  518.   var taxRate = getTaxRate();
  519.   var netValue = document.forms["new_product"].products_price_gross.value;
  520.  
  521.   if (taxRate > 0) {
  522.     netValue = netValue / ((taxRate / 100) + 1);
  523.   }
  524.  
  525.   document.forms["new_product"].products_price.value = doRound(netValue, 4);
  526. }
  527. //--></script>
  528.     <?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"'); ?>
  529.     <table border="0" width="100%" cellspacing="0" cellpadding="2">
  530.       <tr>
  531.         <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
  532.           <tr>
  533.             <td class="pageHeading"><?php echo sprintf(TEXT_NEW_PRODUCT, tep_output_generated_category_path($current_category_id)); ?></td>
  534.             <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
  535.           </tr>
  536.         </table></td>
  537.       </tr>
  538.       <tr>
  539.         <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  540.       </tr>
  541.       <tr>
  542.         <td><table border="0" cellspacing="0" cellpadding="2">
  543.           <tr>
  544.             <td class="main"><?php echo TEXT_PRODUCTS_STATUS; ?></td>
  545.             <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>
  546.           </tr>
  547.           <tr>
  548.             <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  549.           </tr>
  550.           <tr>
  551.             <td class="main"><?php echo TEXT_PRODUCTS_DATE_AVAILABLE; ?></td>
  552.             <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>
  553.           </tr>
  554.           <tr>
  555.             <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  556.           </tr>
  557.           <tr>
  558.             <td class="main"><?php echo TEXT_PRODUCTS_MANUFACTURER; ?></td>
  559.             <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>
  560.           </tr>
  561.           <tr>
  562.             <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  563.           </tr>
  564. <?php
  565.     for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
  566. ?>
  567.           <tr>
  568.             <td class="main"><?php if ($i == 0) echo TEXT_PRODUCTS_NAME; ?></td>
  569.             <td class="main"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('products_name[' . $languages[$i]['id'] . ']', (isset($products_name[$languages[$i]['id']]) ? stripslashes($products_name[$languages[$i]['id']]) : tep_get_products_name($pInfo->products_id, $languages[$i]['id']))); ?></td>
  570.           </tr>
  571. <?php
  572.     }
  573. ?>
  574.           <tr>
  575.             <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  576.           </tr>
  577.           <tr bgcolor="#ebebff">
  578.             <td class="main"><?php echo TEXT_PRODUCTS_TAX_CLASS; ?></td>
  579.             <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>
  580.           </tr>
  581.           <tr bgcolor="#ebebff">
  582.             <td class="main"><?php echo TEXT_PRODUCTS_PRICE_NET; ?></td>
  583.             <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>
  584.           </tr>
  585.           <tr bgcolor="#ebebff">
  586.             <td class="main"><?php echo TEXT_PRODUCTS_PRICE_GROSS; ?></td>
  587.             <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>
  588.           </tr>
  589.           <tr>
  590.             <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  591.           </tr>
  592. <script type="text/javascript"><!--
  593. updateGross();
  594. //--></script>
  595. <?php
  596.     for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
  597. ?>
  598.           <tr>
  599.             <td class="main" valign="top"><?php if ($i == 0) echo TEXT_PRODUCTS_DESCRIPTION; ?></td>
  600.             <td><table border="0" cellspacing="0" cellpadding="0">
  601.               <tr>
  602.                 <td class="main" valign="top"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']); ?>&nbsp;</td>
  603.                 <td class="main"><?php echo tep_draw_textarea_field('products_description[' . $languages[$i]['id'] . ']', 'soft', '70', '15', (isset($products_description[$languages[$i]['id']]) ? stripslashes($products_description[$languages[$i]['id']]) : tep_get_products_description($pInfo->products_id, $languages[$i]['id']))); ?></td>
  604.               </tr>
  605.             </table></td>
  606.           </tr>
  607. <?php
  608.     }
  609. ?>
  610.           <tr>
  611.             <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  612.           </tr>
  613.           <tr>
  614.                 <td class="main">Colors</td>
  615.                 <td class="main"><?php echo '&nbsp;Green' . tep_draw_checkbox_field('color_id[]', 1, in_array('1', $colorid->color_id)) . '
  616.                     &nbsp;Turquoise' . tep_draw_checkbox_field($colorid->color_id, 2); ?></td>
  617.           </tr>
  618.  
  619.             <td class="main"><?php echo TEXT_PRODUCTS_QUANTITY; ?></td>
  620.             <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_quantity', $pInfo->products_quantity); ?></td>
  621.           </tr>
  622.           <tr>
  623.             <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  624.           </tr>
  625.           <tr>
  626.             <td class="main"><?php echo TEXT_PRODUCTS_MODEL; ?></td>
  627.             <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_model', $pInfo->products_model); ?></td>
  628.           </tr>
  629.           <tr>
  630.             <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  631.           </tr>
  632.           <tr>
  633.             <td class="main" valign="top"><?php echo TEXT_PRODUCTS_IMAGE; ?></td>
  634.             <td class="main" style="padding-left: 30px;">
  635.               <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="' . DIR_WS_CATALOG_IMAGES . $pInfo->products_image . '" target="_blank">' . $pInfo->products_image . '</a> &#124; ' : '') . tep_draw_file_field('products_image'); ?></div>
  636.  
  637.               <ul id="piList">
  638. <?php
  639.     $pi_counter = 0;
  640.  
  641.     foreach ($pInfo->products_larger_images as $pi) {
  642.       $pi_counter++;
  643.  
  644.       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="' . 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>';
  645.     }
  646. ?>
  647.               </ul>
  648.  
  649.               <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>
  650.  
  651. <div id="piDelConfirm" title="<?php echo TEXT_PRODUCTS_LARGE_IMAGE_DELETE_TITLE; ?>">
  652.   <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>
  653. </div>
  654.  
  655. <style type="text/css">
  656. #piList { list-style-type: none; margin: 0; padding: 0; }
  657. #piList li { margin: 5px 0; padding: 2px; }
  658. </style>
  659.  
  660. <script type="text/javascript">
  661. $('#piList').sortable({
  662.   containment: 'parent'
  663. });
  664.  
  665. var piSize = <?php echo $pi_counter; ?>;
  666.  
  667. function addNewPiForm() {
  668.   piSize++;
  669.  
  670.   $('#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>');
  671. }
  672.  
  673. var piDelConfirmId = 0;
  674.  
  675. $('#piDelConfirm').dialog({
  676.   autoOpen: false,
  677.   resizable: false,
  678.   draggable: false,
  679.   modal: true,
  680.   buttons: {
  681.     'Delete': function() {
  682.       $('#piId' + piDelConfirmId).effect('blind').remove();
  683.       $(this).dialog('close');
  684.     },
  685.     Cancel: function() {
  686.       $(this).dialog('close');
  687.     }
  688.   }
  689. });
  690.  
  691. function showPiDelConfirm(piId) {
  692.   piDelConfirmId = piId;
  693.  
  694.   $('#piDelConfirm').dialog('open');
  695. }
  696. </script>
  697.  
  698.             </td>
  699.           </tr>
  700.           <tr>
  701.             <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  702.           </tr>
  703. <?php
  704.     for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
  705. ?>
  706.           <tr>
  707.             <td class="main"><?php if ($i == 0) echo TEXT_PRODUCTS_URL . '<br /><small>' . TEXT_PRODUCTS_URL_WITHOUT_HTTP . '</small>'; ?></td>
  708.             <td class="main"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $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>
  709.           </tr>
  710. <?php
  711.     }
  712. ?>
  713.           <tr>
  714.             <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  715.           </tr>
  716.           <tr>
  717.             <td class="main"><?php echo TEXT_PRODUCTS_WEIGHT; ?></td>
  718.             <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('products_weight', $pInfo->products_weight); ?></td>
  719.           </tr>
  720.         </table></td>
  721.       </tr>
  722.       <tr>
  723.         <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  724.       </tr>
  725.       <tr>
  726.         <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>
  727.       </tr>
  728.     </table>
  729.  
  730. <script type="text/javascript">
  731. $('#products_date_available').datepicker({
  732.   dateFormat: 'yy-mm-dd'
  733. });
  734. </script>
  735.  
  736.     </form>
  737. <?php
  738.   } elseif ($action == 'new_product_preview') {
  739.     $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_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'] . "'");
  740.     $product = tep_db_fetch_array($product_query);
  741.  
  742.     $pInfo = new objectInfo($product);
  743.     $products_image_name = $pInfo->products_image;
  744.  
  745.     $languages = tep_get_languages();
  746.     for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
  747.       $pInfo->products_name = tep_get_products_name($pInfo->products_id, $languages[$i]['id']);
  748.       $pInfo->products_description = tep_get_products_description($pInfo->products_id, $languages[$i]['id']);
  749.       $pInfo->products_url = tep_get_products_url($pInfo->products_id, $languages[$i]['id']);
  750. ?>
  751.     <table border="0" width="100%" cellspacing="0" cellpadding="2">
  752.       <tr>
  753.         <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
  754.           <tr>
  755.             <td class="pageHeading"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . $pInfo->products_name; ?></td>
  756.             <td class="pageHeading" align="right"><?php echo $currencies->format($pInfo->products_price); ?></td>
  757.           </tr>
  758.         </table></td>
  759.       </tr>
  760.       <tr>
  761.         <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  762.       </tr>
  763.       <tr>
  764.         <td class="main"><?php echo tep_image(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>
  765.       </tr>
  766. <?php
  767.       if ($pInfo->products_url) {
  768. ?>
  769.       <tr>
  770.         <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  771.       </tr>
  772.       <tr>
  773.         <td class="main"><?php echo sprintf(TEXT_PRODUCT_MORE_INFORMATION, $pInfo->products_url); ?></td>
  774.       </tr>
  775. <?php
  776.       }
  777. ?>
  778.       <tr>
  779.         <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  780.       </tr>
  781. <?php
  782.       if ($pInfo->products_date_available > date('Y-m-d')) {
  783. ?>
  784.       <tr>
  785.         <td align="center" class="smallText"><?php echo sprintf(TEXT_PRODUCT_DATE_AVAILABLE, tep_date_long($pInfo->products_date_available)); ?></td>
  786.       </tr>
  787. <?php
  788.       } else {
  789. ?>
  790.       <tr>
  791.         <td align="center" class="smallText"><?php echo sprintf(TEXT_PRODUCT_DATE_ADDED, tep_date_long($pInfo->products_date_added)); ?></td>
  792.       </tr>
  793. <?php
  794.       }
  795. ?>
  796.       <tr>
  797.         <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  798.       </tr>
  799. <?php
  800.     }
  801.  
  802.     if (isset($HTTP_GET_VARS['origin'])) {
  803.       $pos_params = strpos($HTTP_GET_VARS['origin'], '?', 0);
  804.       if ($pos_params != false) {
  805.         $back_url = substr($HTTP_GET_VARS['origin'], 0, $pos_params);
  806.         $back_url_params = substr($HTTP_GET_VARS['origin'], $pos_params + 1);
  807.       } else {
  808.         $back_url = $HTTP_GET_VARS['origin'];
  809.         $back_url_params = '';
  810.       }
  811.     } else {
  812.       $back_url = FILENAME_CATEGORIES;
  813.       $back_url_params = 'cPath=' . $cPath . '&pID=' . $pInfo->products_id;
  814.     }
  815. ?>
  816.       <tr>
  817.         <td align="right" class="smallText"><?php echo tep_draw_button(IMAGE_BACK, 'triangle-1-w', tep_href_link($back_url, $back_url_params, 'NONSSL')); ?></td>
  818.       </tr>
  819.     </table>
  820. <?php
  821.   } else {
  822. ?>
  823.     <table border="0" width="100%" cellspacing="0" cellpadding="2">
  824.       <tr>
  825.         <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
  826.           <tr>
  827.             <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
  828.             <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', 1, HEADING_IMAGE_HEIGHT); ?></td>
  829.             <td align="right"><table border="0" width="100%" cellspacing="0" cellpadding="0">
  830.               <tr>
  831.                 <td class="smallText" align="right">
  832. <?php
  833.     echo tep_draw_form('search', FILENAME_CATEGORIES, '', 'get');
  834.     echo HEADING_TITLE_SEARCH . ' ' . tep_draw_input_field('search');
  835.     echo tep_hide_session_id() . '</form>';
  836. ?>
  837.                 </td>
  838.               </tr>
  839.               <tr>
  840.                 <td class="smallText" align="right">
  841. <?php
  842.     echo tep_draw_form('goto', FILENAME_CATEGORIES, '', 'get');
  843.     echo HEADING_TITLE_GOTO . ' ' . tep_draw_pull_down_menu('cPath', tep_get_category_tree(), $current_category_id, 'onchange="this.form.submit();"');
  844.     echo tep_hide_session_id() . '</form>';
  845. ?>
  846.                 </td>
  847.               </tr>
  848.             </table></td>
  849.           </tr>
  850.         </table></td>
  851.       </tr>
  852.       <script type="text/javascript">
  853. $(function() {
  854.     var fixHelper = function(e, ui) {
  855.        ui.children().each(function() {
  856.           $(this).width($(this).width()
  857.        );
  858.     });
  859.     return ui;
  860.     };
  861.  
  862.     $('#sortprod tbody').sortable({
  863.        helper: fixHelper,
  864.        opacity: 0.7,
  865.        containment: 'parent',
  866.        update: function(event, ui) {
  867.           var paramString;    
  868.           $('#sortprod tr').each(function(index) {
  869.               paramString += $(this).attr('id')+',';
  870.           });
  871.           $.post("sortprod.php", { ids: paramString },
  872.              function(data) {
  873.              //alert(data);
  874.           });
  875.        }
  876.     }).disableSelection();
  877.  
  878. });
  879. </script>
  880.       <tr>
  881.         <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
  882.           <tr>
  883.             <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2" <? if ($cPath) echo 'id="sortprod"'; ?>>
  884.              
  885.               <tr class="dataTableHeadingRow">
  886.                 <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_CATEGORIES_PRODUCTS; ?></td>
  887.                 <td class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_STATUS; ?></td>
  888.                 <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
  889.               </tr>
  890. <?php
  891.     $categories_count = 0;
  892.     $rows = 0;
  893.     if (isset($HTTP_GET_VARS['search'])) {
  894.       $search = tep_db_prepare_input($HTTP_GET_VARS['search']);
  895.  
  896.       $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");
  897.     } else {
  898.       $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");
  899.     }
  900.     while ($categories = tep_db_fetch_array($categories_query)) {
  901.       $categories_count++;
  902.       $rows++;
  903.  
  904. // Get parent_id for subcategories if search
  905.       if (isset($HTTP_GET_VARS['search'])) $cPath= $categories['parent_id'];
  906.  
  907.       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')) {
  908.         $category_childs = array('childs_count' => tep_childs_in_category_count($categories['categories_id']));
  909.         $category_products = array('products_count' => tep_products_in_category_count($categories['categories_id']));
  910.  
  911.         $cInfo_array = array_merge($categories, $category_childs, $category_products);
  912.         $cInfo = new objectInfo($cInfo_array);
  913.       }
  914.  
  915.       if (isset($cInfo) && is_object($cInfo) && ($categories['categories_id'] == $cInfo->categories_id) ) {
  916.         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";
  917.       } else {
  918.         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";
  919.       }
  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 p.extra_sort,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 p.extra_sort,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 class="dataTableRowSelected ui-state-default" 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') . '\'" id="'. $products['products_id'] .'">' . "\n";
  952.       } else {
  953.         echo '              <tr class="dataTableRow ui-state-default" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $products['products_id']) . '\'" id="'. $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(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $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(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $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(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')) . tep_draw_button('Related', 'link', tep_href_link(FILENAME_RELATED_PRODUCTS, 'products_id_view=' . $pInfo->products_id)));
  1111.            
  1112.            
  1113.            
  1114.            
  1115.             $contents[] = array('text' => '<br />' . TEXT_DATE_ADDED . ' ' . tep_date_short($pInfo->products_date_added));
  1116.             if (tep_not_null($pInfo->products_last_modified)) $contents[] = array('text' => TEXT_LAST_MODIFIED . ' ' . tep_date_short($pInfo->products_last_modified));
  1117.             if (date('Y-m-d') < $pInfo->products_date_available) $contents[] = array('text' => TEXT_DATE_AVAILABLE . ' ' . tep_date_short($pInfo->products_date_available));
  1118.             $contents[] = array('text' => '<br />' . tep_info_image($pInfo->products_image, $pInfo->products_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '<br />' . $pInfo->products_image);
  1119.             $contents[] = array('text' => '<br />' . TEXT_PRODUCTS_PRICE_INFO . ' ' . $currencies->format($pInfo->products_price) . '<br />' . TEXT_PRODUCTS_QUANTITY_INFO . ' ' . $pInfo->products_quantity);
  1120.             $contents[] = array('text' => '<br />' . TEXT_PRODUCTS_AVERAGE_RATING . ' ' . number_format($pInfo->average_rating, 2) . '%');
  1121.           }
  1122.         } else { // create category/product info
  1123.           $heading[] = array('text' => '<strong>' . EMPTY_CATEGORY . '</strong>');
  1124.  
  1125.           $contents[] = array('text' => TEXT_NO_CHILD_CATEGORIES_OR_PRODUCTS);
  1126.         }
  1127.         break;
  1128.     }
  1129.  
  1130.     if ( (tep_not_null($heading)) && (tep_not_null($contents)) ) {
  1131.       echo '            <td width="25%" valign="top">' . "\n";
  1132.  
  1133.       $box = new box;
  1134.       echo $box->infoBox($heading, $contents);
  1135.  
  1136.       echo '            </td>' . "\n";
  1137.     }
  1138. ?>
  1139.           </tr>
  1140.         </table></td>
  1141.       </tr>
  1142.     </table>
  1143. <?php
  1144.   }
  1145.  
  1146.   require(DIR_WS_INCLUDES . 'template_bottom.php');
  1147.   require(DIR_WS_INCLUDES . 'application_bottom.php');
  1148. ?>
  1149.  
  1150.  
Add Comment
Please, Sign In to add comment