ZenCart_Documentation  1.5.0
http://www.collinsharper.com
C:/xampp/htdocs/zen-cart/admin/includes/modules/products_previous_next.php
Go to the documentation of this file.
00001 <?php
00009 if (!defined('IS_ADMIN_FLAG')) {
00010   die('Illegal Access');
00011 }
00012 
00014 // BOF PREVIOUS NEXT
00015 
00016   if ($prev_next_list=='') {
00017 // calculate the previous and next
00018 
00019     $check_type = $db->Execute("select products_type from " . TABLE_PRODUCTS . " where products_id='" . (int)$products_filter . "'");
00020     define('PRODUCT_INFO_PREVIOUS_NEXT_SORT', zen_get_configuration_key_value_layout('PRODUCT_INFO_PREVIOUS_NEXT_SORT', $check_type->fields['products_type']));
00021 
00022     // sort order
00023     switch(PRODUCT_INFO_PREVIOUS_NEXT_SORT) {
00024       case (0):
00025         $prev_next_order= ' order by LPAD(p.products_id,11,"0")';
00026         break;
00027       case (1):
00028         $prev_next_order= " order by pd.products_name";
00029         break;
00030       case (2):
00031         $prev_next_order= " order by p.products_model";
00032         break;
00033       case (3):
00034         $prev_next_order= " order by p.products_price, pd.products_name";
00035         break;
00036       case (4):
00037         $prev_next_order= " order by p.products_price, p.products_model";
00038         break;
00039       case (5):
00040         $prev_next_order= " order by pd.products_name, p.products_model";
00041         break;
00042       default:
00043         $prev_next_order= " order by pd.products_name";
00044         break;
00045       }
00046 
00047 
00048 // set current category
00049     $current_category_id = (isset($_GET['current_category_id']) ? (int)$_GET['current_category_id'] : $current_category_id);
00050 
00051     if (!$current_category_id) {
00052       $sql = "SELECT categories_id
00053               from   " . TABLE_PRODUCTS_TO_CATEGORIES . "
00054               where  products_id ='" .  (int)$products_filter . "'";
00055 
00056       $cPath_row = $db->Execute($sql);
00057       $current_category_id = $cPath_row->fields['categories_id'];
00058     }
00059 
00060     $sql = "select p.products_id, pd.products_name
00061             from   " . TABLE_PRODUCTS . " p, "
00062                      . TABLE_PRODUCTS_DESCRIPTION . " pd, "
00063                      . TABLE_PRODUCTS_TO_CATEGORIES . " ptc
00064             where  p.products_id = pd.products_id and pd.language_id= '" . (int)$_SESSION['languages_id'] . "' and p.products_id = ptc.products_id and ptc.categories_id = '" . (int)$current_category_id . "'" .
00065             $prev_next_order
00066             ;
00067 
00068     $products_ids = $db->Execute($sql);
00069   }
00070 
00071 // reset if not already set for display
00072   ($_GET['products_filter'] == '' ? (int)$_GET['products_filter'] = $products_filter : '');
00073   ($_GET['current_category_id'] == '' ? (int)$_GET['current_category_id'] = $current_category_id : '');
00074 
00075   while (!$products_ids->EOF) {
00076     $id_array[] = $products_ids->fields['products_id'];
00077     $products_ids->MoveNext();
00078   }
00079 
00080 // if invalid product id skip
00081   if (is_array($id_array)) {
00082     reset ($id_array);
00083     $counter = 0;
00084     while (list($key, $value) = each ($id_array)) {
00085       if ($value == $products_filter) {
00086         $position = $counter;
00087         if ($key == 0) {
00088           $previous = -1; // it was the first to be found
00089         } else {
00090           $previous = $id_array[$key - 1];
00091         }
00092         if ($id_array[$key + 1]) {
00093           $next_item = $id_array[$key + 1];
00094         } else {
00095           $next_item = $id_array[0];
00096         }
00097       }
00098       $last = $value;
00099       $counter++;
00100     }
00101 
00102     if ($previous == -1) $previous = $last;
00103 
00104     $sql = "select categories_name
00105             from   " . TABLE_CATEGORIES_DESCRIPTION . "
00106             where  categories_id = '" . (int)$current_category_id . "' AND language_id = '" . (int)$_SESSION['languages_id'] . "'";
00107 
00108     $category_name_row = $db->Execute($sql);
00109   } // if is_array
00110 
00111 /*
00112   if (strstr($PHP_SELF, FILENAME_PRODUCTS_PRICE_MANAGER)) {
00113     $curr_page = FILENAME_PRODUCTS_PRICE_MANAGER;
00114   } else {
00115     $curr_page = FILENAME_ATTRIBUTES_CONTROLLER;
00116   }
00117 */
00118 
00119   switch(true) {
00120   case (strstr($PHP_SELF, FILENAME_ATTRIBUTES_CONTROLLER)):
00121     $curr_page = FILENAME_ATTRIBUTES_CONTROLLER;
00122     break;
00123   case (strstr($PHP_SELF, FILENAME_PRODUCTS_TO_CATEGORIES)):
00124     $curr_page = FILENAME_PRODUCTS_TO_CATEGORIES;
00125     break;
00126   default:
00127     $curr_page = FILENAME_PRODUCTS_PRICE_MANAGER;
00128     break;
00129   }
00130 // to display use products_previous_next_display.php
 All Data Structures Namespaces Files Functions Variables Enumerations