[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/admin/includes/functions/ -> general.php (source)

   1  <?php
   2  /*

   3  $Id: general.php 14 2006-07-28 17:42:07Z user $

   4  

   5    osCMax Power E-Commerce

   6    http://oscdox.com

   7  

   8    Copyright 2006 osCMax

   9  

  10    Released under the GNU General Public License

  11  */
  12  
  13  // BOF: MOD - Admin w/access levels

  14  //Check login and file access

  15  function tep_admin_check_login() {
  16    global $PHP_SELF, $login_groups_id;
  17    if (!tep_session_is_registered('login_id')) {
  18      tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
  19    } else {
  20      $filename = basename( $PHP_SELF );
  21      if ($filename != FILENAME_DEFAULT && $filename != FILENAME_FORBIDDEN && $filename != FILENAME_LOGOFF && $filename != FILENAME_ADMIN_ACCOUNT && $filename != FILENAME_POPUP_IMAGE && $filename != 'packingslip.php' && $filename != 'invoice.php') {
  22        $db_file_query = tep_db_query("select admin_files_name from " . TABLE_ADMIN_FILES . " where FIND_IN_SET( '" . $login_groups_id . "', admin_groups_id) and admin_files_name = '" . $filename . "'");
  23        if (!tep_db_num_rows($db_file_query)) {
  24          tep_redirect(tep_href_link(FILENAME_FORBIDDEN));
  25        }
  26      }
  27    }
  28  }
  29  
  30  ////

  31  //Return 'true' or 'false' value to display boxes and files in index.php and column_left.php

  32  function tep_admin_check_boxes($filename, $boxes='') {
  33    global $login_groups_id;
  34  
  35    $is_boxes = 1;
  36    if ($boxes == 'sub_boxes') {
  37      $is_boxes = 0;
  38    }
  39    $dbquery = tep_db_query("select admin_files_id from " . TABLE_ADMIN_FILES . " where FIND_IN_SET( '" . $login_groups_id . "', admin_groups_id) and admin_files_is_boxes = '" . $is_boxes . "' and admin_files_name = '" . $filename . "'");
  40  
  41    $return_value = false;
  42    if (tep_db_num_rows($dbquery)) {
  43      $return_value = true;
  44    }
  45    return $return_value;
  46  }
  47  
  48  ////

  49  //Return files stored in box that can be accessed by user

  50  function tep_admin_files_boxes($filename, $sub_box_name) {
  51    global $login_groups_id;
  52    $sub_boxes = '';
  53  
  54    $dbquery = tep_db_query("select admin_files_name from " . TABLE_ADMIN_FILES . " where FIND_IN_SET( '" . $login_groups_id . "', admin_groups_id) and admin_files_is_boxes = '0' and admin_files_name = '" . $filename . "'");
  55    if (tep_db_num_rows($dbquery)) {
  56      $sub_boxes = '<a href="' . tep_href_link($filename) . '" class="menuBoxContentLink">' . $sub_box_name . '</a><br>';
  57    }
  58    return $sub_boxes;
  59  }
  60  
  61  ////

  62  //Get selected file for index.php

  63  function tep_selected_file($filename) {
  64    global $login_groups_id;
  65    $randomize = FILENAME_ADMIN_ACCOUNT;
  66  
  67    $dbquery = tep_db_query("select admin_files_id as boxes_id from " . TABLE_ADMIN_FILES . " where FIND_IN_SET( '" . $login_groups_id . "', admin_groups_id) and admin_files_is_boxes = '1' and admin_files_name = '" . $filename . "'");
  68    if (tep_db_num_rows($dbquery)) {
  69      $boxes_id = tep_db_fetch_array($dbquery);
  70      $randomize_query = tep_db_query("select admin_files_name from " . TABLE_ADMIN_FILES . " where FIND_IN_SET( '" . $login_groups_id . "', admin_groups_id) and admin_files_is_boxes = '0' and admin_files_to_boxes = '" . $boxes_id['boxes_id'] . "'");
  71      if (tep_db_num_rows($randomize_query)) {
  72        $file_selected = tep_db_fetch_array($randomize_query);
  73        $randomize = $file_selected['admin_files_name'];
  74      }
  75    }
  76    return $randomize;
  77  }
  78  // EOF: MOD - Admin w/access levels

  79  
  80  ////

  81  // Redirect to another page or site

  82    function tep_redirect($url) {
  83      global $logger;
  84  // BOF: MS2 update 501112-Added

  85      if ( (strstr($url, "\n") != false) || (strstr($url, "\r") != false) ) {
  86        tep_redirect(tep_href_link(FILENAME_DEFAULT, '', 'NONSSL', false));
  87      }
  88  // EOF: MS2 update 501112-Added

  89  
  90      header('Location: ' . $url);
  91  
  92      if (STORE_PAGE_PARSE_TIME == 'true') {
  93        if (!is_object($logger)) $logger = new logger;
  94        $logger->timer_stop();
  95      }
  96  
  97      exit;
  98    }
  99  
 100  ////

 101  // Parse the data used in the html tags to ensure the tags will not break

 102    function tep_parse_input_field_data($data, $parse) {
 103      return strtr(trim($data), $parse);
 104    }
 105  
 106    function tep_output_string($string, $translate = false, $protected = false) {
 107      if ($protected == true) {
 108        return htmlspecialchars($string);
 109      } else {
 110        if ($translate == false) {
 111          return tep_parse_input_field_data($string, array('"' => '&quot;'));
 112        } else {
 113          return tep_parse_input_field_data($string, $translate);
 114        }
 115      }
 116    }
 117  
 118    function tep_output_string_protected($string) {
 119      return tep_output_string($string, false, true);
 120    }
 121  
 122    function tep_sanitize_string($string) {
 123      $string = ereg_replace(' +', ' ', $string);
 124  
 125      return preg_replace("/[<>]/", '_', $string);
 126    }
 127  
 128    function tep_customers_name($customers_id) {
 129      $customers = tep_db_query("select customers_firstname, customers_lastname from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$customers_id . "'");
 130      $customers_values = tep_db_fetch_array($customers);
 131  
 132      return $customers_values['customers_firstname'] . ' ' . $customers_values['customers_lastname'];
 133    }
 134  
 135    function tep_get_path($current_category_id = '') {
 136      global $cPath_array;
 137  
 138      if ($current_category_id == '') {
 139        $cPath_new = implode('_', $cPath_array);
 140      } else {
 141        if (sizeof($cPath_array) == 0) {
 142          $cPath_new = $current_category_id;
 143        } else {
 144          $cPath_new = '';
 145          $last_category_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . (int)$cPath_array[(sizeof($cPath_array)-1)] . "'");
 146          $last_category = tep_db_fetch_array($last_category_query);
 147  
 148          $current_category_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . (int)$current_category_id . "'");
 149          $current_category = tep_db_fetch_array($current_category_query);
 150  
 151          if ($last_category['parent_id'] == $current_category['parent_id']) {
 152            for ($i = 0, $n = sizeof($cPath_array) - 1; $i < $n; $i++) {
 153              $cPath_new .= '_' . $cPath_array[$i];
 154            }
 155          } else {
 156            for ($i = 0, $n = sizeof($cPath_array); $i < $n; $i++) {
 157              $cPath_new .= '_' . $cPath_array[$i];
 158            }
 159          }
 160  
 161          $cPath_new .= '_' . $current_category_id;
 162  
 163          if (substr($cPath_new, 0, 1) == '_') {
 164            $cPath_new = substr($cPath_new, 1);
 165          }
 166        }
 167      }
 168  
 169      return 'cPath=' . $cPath_new;
 170    }
 171  
 172    function tep_get_all_get_params($exclude_array = '') {
 173      global $HTTP_GET_VARS;
 174  
 175      if ($exclude_array == '') $exclude_array = array();
 176  
 177      $get_url = '';
 178  
 179      reset($HTTP_GET_VARS);
 180      while (list($key, $value) = each($HTTP_GET_VARS)) {
 181        if (($key != tep_session_name()) && ($key != 'error') && (!in_array($key, $exclude_array))) $get_url .= $key . '=' . $value . '&';
 182      }
 183  
 184      return $get_url;
 185    }
 186  
 187    function tep_date_long($raw_date) {
 188      if ( ($raw_date == '0000-00-00 00:00:00') || ($raw_date == '') ) return false;
 189  
 190      $year = (int)substr($raw_date, 0, 4);
 191      $month = (int)substr($raw_date, 5, 2);
 192      $day = (int)substr($raw_date, 8, 2);
 193      $hour = (int)substr($raw_date, 11, 2);
 194      $minute = (int)substr($raw_date, 14, 2);
 195      $second = (int)substr($raw_date, 17, 2);
 196  
 197      return strftime(DATE_FORMAT_LONG, mktime($hour, $minute, $second, $month, $day, $year));
 198    }
 199  
 200  ////

 201  // Output a raw date string in the selected locale date format

 202  // $raw_date needs to be in this format: YYYY-MM-DD HH:MM:SS

 203  // NOTE: Includes a workaround for dates before 01/01/1970 that fail on windows servers

 204    function tep_date_short($raw_date) {
 205      if ( ($raw_date == '0000-00-00 00:00:00') || ($raw_date == '') ) return false;
 206  
 207      $year = substr($raw_date, 0, 4);
 208      $month = (int)substr($raw_date, 5, 2);
 209      $day = (int)substr($raw_date, 8, 2);
 210      $hour = (int)substr($raw_date, 11, 2);
 211      $minute = (int)substr($raw_date, 14, 2);
 212      $second = (int)substr($raw_date, 17, 2);
 213  
 214      if (@date('Y', mktime($hour, $minute, $second, $month, $day, $year)) == $year) {
 215        return date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, $year));
 216      } else {
 217        return ereg_replace('2037' . '$', $year, date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, 2037)));
 218      }
 219  
 220    }
 221  
 222    function tep_datetime_short($raw_datetime) {
 223      if ( ($raw_datetime == '0000-00-00 00:00:00') || ($raw_datetime == '') ) return false;
 224  
 225      $year = (int)substr($raw_datetime, 0, 4);
 226      $month = (int)substr($raw_datetime, 5, 2);
 227      $day = (int)substr($raw_datetime, 8, 2);
 228      $hour = (int)substr($raw_datetime, 11, 2);
 229      $minute = (int)substr($raw_datetime, 14, 2);
 230      $second = (int)substr($raw_datetime, 17, 2);
 231  
 232      return strftime(DATE_TIME_FORMAT, mktime($hour, $minute, $second, $month, $day, $year));
 233    }
 234  
 235    function tep_get_category_tree($parent_id = '0', $spacing = '', $exclude = '', $category_tree_array = '', $include_itself = false) {
 236      global $languages_id;
 237  
 238      if (!is_array($category_tree_array)) $category_tree_array = array();
 239      if ( (sizeof($category_tree_array) < 1) && ($exclude != '0') ) $category_tree_array[] = array('id' => '0', 'text' => TEXT_TOP);
 240  
 241      if ($include_itself) {
 242        $category_query = tep_db_query("select cd.categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " cd where cd.language_id = '" . (int)$languages_id . "' and cd.categories_id = '" . (int)$parent_id . "'");
 243        $category = tep_db_fetch_array($category_query);
 244        $category_tree_array[] = array('id' => $parent_id, 'text' => $category['categories_name']);
 245      }
 246  
 247      $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' and c.parent_id = '" . (int)$parent_id . "' order by c.sort_order, cd.categories_name");
 248      while ($categories = tep_db_fetch_array($categories_query)) {
 249        if ($exclude != $categories['categories_id']) $category_tree_array[] = array('id' => $categories['categories_id'], 'text' => $spacing . $categories['categories_name']);
 250        $category_tree_array = tep_get_category_tree($categories['categories_id'], $spacing . '&nbsp;&nbsp;&nbsp;', $exclude, $category_tree_array);
 251      }
 252  
 253      return $category_tree_array;
 254    }
 255  
 256    function tep_draw_products_pull_down($name, $parameters = '', $exclude = '') {
 257      global $currencies, $languages_id;
 258  
 259      if ($exclude == '') {
 260        $exclude = array();
 261      }
 262  
 263      $select_string = '<select name="' . $name . '"';
 264  
 265      if ($parameters) {
 266        $select_string .= ' ' . $parameters;
 267      }
 268  
 269      $select_string .= '>';
 270  // BOF: MOD - Separate Price Per Customer

 271        $all_groups=array();
 272        $customers_groups_query = tep_db_query("select customers_group_name, customers_group_id from " . TABLE_CUSTOMERS_GROUPS . " order by customers_group_id ");
 273        while ($existing_groups =  tep_db_fetch_array($customers_groups_query)) {
 274            $all_groups[$existing_groups['customers_group_id']]=$existing_groups['customers_group_name'];
 275        }
 276  // EOF: MOD - Separate Price Per Customer

 277  
 278      $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by products_name");
 279      while ($products = tep_db_fetch_array($products_query)) {
 280  
 281  // BOF: MOD - Separate Price Per Customer

 282  //      if (!in_array($products['products_id'], $exclude)) {

 283  //        $select_string .= '<option value="' . $products['products_id'] . '">' . $products['products_name'] . ' (' . $currencies->format($products['products_price']) . ')</option>';

 284       if (!in_array($products['products_id'], $exclude)) {
 285           $price_query=tep_db_query("select customers_group_price, customers_group_id from " . TABLE_PRODUCTS_GROUPS . " where products_id = " . $products['products_id']);
 286           $product_prices=array();
 287           while($prices_array=tep_db_fetch_array($price_query)){
 288               $product_prices[$prices_array['customers_group_id']]=$prices_array['customers_group_price'];
 289           }
 290           reset($all_groups);
 291           $price_string="";
 292           $sde=0;
 293           while(list($sdek,$sdev)=each($all_groups)){
 294               if (!in_array((int)$products['products_id'].":".(int)$sdek, $exclude)) {
 295                   if($sde)
 296                      $price_string.=", ";
 297                   $price_string.=$sdev.": ".$currencies->format(isset($product_prices[$sdek]) ? $product_prices[$sdek]:$products['products_price']);
 298                   $sde=1;
 299               }
 300           }
 301           $select_string .= '<option value="' . $products['products_id'] . '">' . $products['products_name'] . ' (' . $price_string . ')</option>\n';
 302  // EOF: MOD - Separate Price Per Customer

 303        }
 304      }
 305  
 306      $select_string .= '</select>';
 307  
 308      return $select_string;
 309    }
 310  
 311    function tep_options_name($options_id) {
 312      global $languages_id;
 313  
 314      $options = tep_db_query("select products_options_name from " . TABLE_PRODUCTS_OPTIONS . " where products_options_id = '" . (int)$options_id . "' and language_id = '" . (int)$languages_id . "'");
 315      $options_values = tep_db_fetch_array($options);
 316  
 317      return $options_values['products_options_name'];
 318    }
 319  
 320    function tep_values_name($values_id) {
 321      global $languages_id;
 322  
 323      $values = tep_db_query("select products_options_values_name from " . TABLE_PRODUCTS_OPTIONS_VALUES . " where products_options_values_id = '" . (int)$values_id . "' and language_id = '" . (int)$languages_id . "'");
 324      $values_values = tep_db_fetch_array($values);
 325  
 326      return $values_values['products_options_values_name'];
 327    }
 328  
 329    function tep_info_image($image, $alt, $width = '', $height = '') {
 330      if (tep_not_null($image) && (file_exists(DIR_FS_CATALOG_IMAGES . $image)) ) {
 331        $image = tep_image(DIR_WS_CATALOG_IMAGES . $image, $alt, $width, $height);
 332      } else {
 333        $image = TEXT_IMAGE_NONEXISTENT;
 334      }
 335  
 336      return $image;
 337    }
 338  
 339    function tep_break_string($string, $len, $break_char = '-') {
 340      $l = 0;
 341      $output = '';
 342      for ($i=0, $n=strlen($string); $i<$n; $i++) {
 343        $char = substr($string, $i, 1);
 344        if ($char != ' ') {
 345          $l++;
 346        } else {
 347          $l = 0;
 348        }
 349        if ($l > $len) {
 350          $l = 1;
 351          $output .= $break_char;
 352        }
 353        $output .= $char;
 354      }
 355  
 356      return $output;
 357    }
 358  
 359    function tep_get_country_name($country_id) {
 360      $country_query = tep_db_query("select countries_name from " . TABLE_COUNTRIES . " where countries_id = '" . (int)$country_id . "'");
 361  
 362      if (!tep_db_num_rows($country_query)) {
 363        return $country_id;
 364      } else {
 365        $country = tep_db_fetch_array($country_query);
 366        return $country['countries_name'];
 367      }
 368    }
 369  
 370    function tep_get_zone_name($country_id, $zone_id, $default_zone) {
 371      $zone_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country_id . "' and zone_id = '" . (int)$zone_id . "'");
 372      if (tep_db_num_rows($zone_query)) {
 373        $zone = tep_db_fetch_array($zone_query);
 374        return $zone['zone_name'];
 375      } else {
 376        return $default_zone;
 377      }
 378    }
 379  
 380    function tep_not_null($value) {
 381      if (is_array($value)) {
 382        if (sizeof($value) > 0) {
 383          return true;
 384        } else {
 385          return false;
 386        }
 387      } else {
 388        if ( (is_string($value) || is_int($value)) && ($value != '') && ($value != 'NULL') && (strlen(trim($value)) > 0)) {
 389          return true;
 390        } else {
 391          return false;
 392        }
 393      }
 394    }
 395  
 396    function tep_browser_detect($component) {
 397      global $HTTP_USER_AGENT;
 398  
 399      return stristr($HTTP_USER_AGENT, $component);
 400    }
 401  
 402    function tep_tax_classes_pull_down($parameters, $selected = '') {
 403      $select_string = '<select ' . $parameters . '>';
 404      $classes_query = tep_db_query("select tax_class_id, tax_class_title from " . TABLE_TAX_CLASS . " order by tax_class_title");
 405      while ($classes = tep_db_fetch_array($classes_query)) {
 406        $select_string .= '<option value="' . $classes['tax_class_id'] . '"';
 407        if ($selected == $classes['tax_class_id']) $select_string .= ' SELECTED';
 408        $select_string .= '>' . $classes['tax_class_title'] . '</option>';
 409      }
 410      $select_string .= '</select>';
 411  
 412      return $select_string;
 413    }
 414  
 415    function tep_geo_zones_pull_down($parameters, $selected = '') {
 416      $select_string = '<select ' . $parameters . '>';
 417      $zones_query = tep_db_query("select geo_zone_id, geo_zone_name from " . TABLE_GEO_ZONES . " order by geo_zone_name");
 418      while ($zones = tep_db_fetch_array($zones_query)) {
 419        $select_string .= '<option value="' . $zones['geo_zone_id'] . '"';
 420        if ($selected == $zones['geo_zone_id']) $select_string .= ' SELECTED';
 421        $select_string .= '>' . $zones['geo_zone_name'] . '</option>';
 422      }
 423      $select_string .= '</select>';
 424  
 425      return $select_string;
 426    }
 427  
 428    function tep_get_geo_zone_name($geo_zone_id) {
 429      $zones_query = tep_db_query("select geo_zone_name from " . TABLE_GEO_ZONES . " where geo_zone_id = '" . (int)$geo_zone_id . "'");
 430  
 431      if (!tep_db_num_rows($zones_query)) {
 432        $geo_zone_name = $geo_zone_id;
 433      } else {
 434        $zones = tep_db_fetch_array($zones_query);
 435        $geo_zone_name = $zones['geo_zone_name'];
 436      }
 437  
 438      return $geo_zone_name;
 439    }
 440  
 441    function tep_address_format($address_format_id, $address, $html, $boln, $eoln) {
 442      $address_format_query = tep_db_query("select address_format as format from " . TABLE_ADDRESS_FORMAT . " where address_format_id = '" . (int)$address_format_id . "'");
 443      $address_format = tep_db_fetch_array($address_format_query);
 444  
 445      $company = tep_output_string_protected($address['company']);
 446      if (isset($address['firstname']) && tep_not_null($address['firstname'])) {
 447        $firstname = tep_output_string_protected($address['firstname']);
 448        $lastname = tep_output_string_protected($address['lastname']);
 449      } elseif (isset($address['name']) && tep_not_null($address['name'])) {
 450        $firstname = tep_output_string_protected($address['name']);
 451        $lastname = '';
 452      } else {
 453        $firstname = '';
 454        $lastname = '';
 455      }
 456      $street = tep_output_string_protected($address['street_address']);
 457      $suburb = tep_output_string_protected($address['suburb']);
 458      $city = tep_output_string_protected($address['city']);
 459      $state = tep_output_string_protected($address['state']);
 460      if (isset($address['country_id']) && tep_not_null($address['country_id'])) {
 461        $country = tep_get_country_name($address['country_id']);
 462  
 463        if (isset($address['zone_id']) && tep_not_null($address['zone_id'])) {
 464          $state = tep_get_zone_code($address['country_id'], $address['zone_id'], $state);
 465        }
 466      } elseif (isset($address['country']) && tep_not_null($address['country'])) {
 467        $country = tep_output_string_protected($address['country']);
 468      } else {
 469        $country = '';
 470      }
 471      $postcode = tep_output_string_protected($address['postcode']);
 472      $zip = $postcode;
 473  
 474      if ($html) {
 475  // HTML Mode

 476        $HR = '<hr>';
 477        $hr = '<hr>';
 478        if ( ($boln == '') && ($eoln == "\n") ) { // Values not specified, use rational defaults
 479          $CR = '<br>';
 480          $cr = '<br>';
 481          $eoln = $cr;
 482        } else { // Use values supplied
 483          $CR = $eoln . $boln;
 484          $cr = $CR;
 485        }
 486      } else {
 487  // Text Mode

 488        $CR = $eoln;
 489        $cr = $CR;
 490        $HR = '----------------------------------------';
 491        $hr = '----------------------------------------';
 492      }
 493  
 494      $statecomma = '';
 495      $streets = $street;
 496      if ($suburb != '') $streets = $street . $cr . $suburb;
 497      if ($country == '') $country = tep_output_string_protected($address['country']);
 498      if ($state != '') $statecomma = $state . ', ';
 499  
 500      $fmt = $address_format['format'];
 501      eval("\$address = \"$fmt\";");
 502  
 503      if ( (ACCOUNT_COMPANY == 'true') && (tep_not_null($company)) ) {
 504        $address = $company . $cr . $address;
 505      }
 506  
 507      return $address;
 508    }
 509  
 510    ////////////////////////////////////////////////////////////////////////////////////////////////

 511    //

 512    // Function    : tep_get_zone_code

 513    //

 514    // Arguments   : country           country code string

 515    //               zone              state/province zone_id

 516    //               def_state         default string if zone==0

 517    //

 518    // Return      : state_prov_code   state/province code

 519    //

 520    // Description : Function to retrieve the state/province code (as in FL for Florida etc)

 521    //

 522    ////////////////////////////////////////////////////////////////////////////////////////////////

 523    function tep_get_zone_code($country, $zone, $def_state) {
 524  
 525      $state_prov_query = tep_db_query("select zone_code from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country . "' and zone_id = '" . (int)$zone . "'");
 526  
 527      if (!tep_db_num_rows($state_prov_query)) {
 528        $state_prov_code = $def_state;
 529      }
 530      else {
 531        $state_prov_values = tep_db_fetch_array($state_prov_query);
 532        $state_prov_code = $state_prov_values['zone_code'];
 533      }
 534  
 535      return $state_prov_code;
 536    }
 537  
 538    function tep_get_uprid($prid, $params) {
 539      $uprid = $prid;
 540      if ( (is_array($params)) && (!strstr($prid, '{')) ) {
 541        while (list($option, $value) = each($params)) {
 542          $uprid = $uprid . '{' . $option . '}' . $value;
 543        }
 544      }
 545  
 546      return $uprid;
 547    }
 548  
 549    function tep_get_prid($uprid) {
 550      $pieces = explode('{', $uprid);
 551  
 552      return $pieces[0];
 553    }
 554  
 555    function tep_get_languages() {
 556      $languages_query = tep_db_query("select languages_id, name, code, image, directory from " . TABLE_LANGUAGES . " order by sort_order");
 557      while ($languages = tep_db_fetch_array($languages_query)) {
 558        $languages_array[] = array('id' => $languages['languages_id'],
 559                                   'name' => $languages['name'],
 560                                   'code' => $languages['code'],
 561                                   'image' => $languages['image'],
 562                                   'directory' => $languages['directory']);
 563      }
 564  
 565      return $languages_array;
 566    }
 567  
 568    function tep_get_category_name($category_id, $language_id) {
 569      $category_query = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . (int)$category_id . "' and language_id = '" . (int)$language_id . "'");
 570      $category = tep_db_fetch_array($category_query);
 571  
 572      return $category['categories_name'];
 573    }
 574  
 575    function tep_get_orders_status_name($orders_status_id, $language_id = '') {
 576      global $languages_id;
 577  
 578      if (!$language_id) $language_id = $languages_id;
 579      $orders_status_query = tep_db_query("select orders_status_name from " . TABLE_ORDERS_STATUS . " where orders_status_id = '" . (int)$orders_status_id . "' and language_id = '" . (int)$language_id . "'");
 580      $orders_status = tep_db_fetch_array($orders_status_query);
 581  
 582      return $orders_status['orders_status_name'];
 583    }
 584  
 585    function tep_get_orders_status() {
 586      global $languages_id;
 587  
 588      $orders_status_array = array();
 589      $orders_status_query = tep_db_query("select orders_status_id, orders_status_name from " . TABLE_ORDERS_STATUS . " where language_id = '" . (int)$languages_id . "' order by orders_status_id");
 590      while ($orders_status = tep_db_fetch_array($orders_status_query)) {
 591        $orders_status_array[] = array('id' => $orders_status['orders_status_id'],
 592                                       'text' => $orders_status['orders_status_name']);
 593      }
 594  
 595      return $orders_status_array;
 596    }
 597  
 598    function tep_get_products_name($product_id, $language_id = 0) {
 599      global $languages_id;
 600  
 601      if ($language_id == 0) $language_id = $languages_id;
 602      $product_query = tep_db_query("select products_name from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$product_id . "' and language_id = '" . (int)$language_id . "'");
 603      $product = tep_db_fetch_array($product_query);
 604  
 605      return $product['products_name'];
 606    }
 607  
 608    function tep_get_products_description($product_id, $language_id) {
 609      $product_query = tep_db_query("select products_description from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$product_id . "' and language_id = '" . (int)$language_id . "'");
 610      $product = tep_db_fetch_array($product_query);
 611  
 612      return $product['products_description'];
 613    }
 614  
 615    function tep_get_products_url($product_id, $language_id) {
 616      $product_query = tep_db_query("select products_url from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$product_id . "' and language_id = '" . (int)$language_id . "'");
 617      $product = tep_db_fetch_array($product_query);
 618  
 619      return $product['products_url'];
 620    }
 621  
 622  ////

 623  // Return the manufacturers URL in the needed language

 624  // TABLES: manufacturers_info

 625    function tep_get_manufacturer_url($manufacturer_id, $language_id) {
 626      $manufacturer_query = tep_db_query("select manufacturers_url from " . TABLE_MANUFACTURERS_INFO . " where manufacturers_id = '" . (int)$manufacturer_id . "' and languages_id = '" . (int)$language_id . "'");
 627      $manufacturer = tep_db_fetch_array($manufacturer_query);
 628  
 629      return $manufacturer['manufacturers_url'];
 630    }
 631  
 632  ////

 633  // Wrapper for class_exists() function

 634  // This function is not available in all PHP versions so we test it before using it.

 635    function tep_class_exists($class_name) {
 636      if (function_exists('class_exists')) {
 637        return class_exists($class_name);
 638      } else {
 639        return true;
 640      }
 641    }
 642  
 643  ////

 644  // Count how many products exist in a category

 645  // TABLES: products, products_to_categories, categories

 646    function tep_products_in_category_count($categories_id, $include_deactivated = false) {
 647      $products_count = 0;
 648  
 649      if ($include_deactivated) {
 650        $products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$categories_id . "'");
 651      } else {
 652        $products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p.products_status = '1' and p2c.categories_id = '" . (int)$categories_id . "'");
 653      }
 654  
 655      $products = tep_db_fetch_array($products_query);
 656  
 657      $products_count += $products['total'];
 658  
 659      $childs_query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$categories_id . "'");
 660      if (tep_db_num_rows($childs_query)) {
 661        while ($childs = tep_db_fetch_array($childs_query)) {
 662          $products_count += tep_products_in_category_count($childs['categories_id'], $include_deactivated);
 663        }
 664      }
 665  
 666      return $products_count;
 667    }
 668  
 669  ////

 670  // Count how many subcategories exist in a category

 671  // TABLES: categories

 672    function tep_childs_in_category_count($categories_id) {
 673      $categories_count = 0;
 674  
 675      $categories_query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$categories_id . "'");
 676      while ($categories = tep_db_fetch_array($categories_query)) {
 677        $categories_count++;
 678        $categories_count += tep_childs_in_category_count($categories['categories_id']);
 679      }
 680  
 681      return $categories_count;
 682    }
 683  
 684  ////

 685  // Returns an array with countries

 686  // TABLES: countries

 687    function tep_get_countries($default = '') {
 688      $countries_array = array();
 689      if ($default) {
 690        $countries_array[] = array('id' => '',
 691                                   'text' => $default);
 692      }
 693      $countries_query = tep_db_query("select countries_id, countries_name from " . TABLE_COUNTRIES . " order by countries_name");
 694      while ($countries = tep_db_fetch_array($countries_query)) {
 695        $countries_array[] = array('id' => $countries['countries_id'],
 696                                   'text' => $countries['countries_name']);
 697      }
 698  
 699      return $countries_array;
 700    }
 701  
 702  ////

 703  // return an array with country zones

 704    function tep_get_country_zones($country_id) {
 705      $zones_array = array();
 706      $zones_query = tep_db_query("select zone_id, zone_name from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country_id . "' order by zone_name");
 707      while ($zones = tep_db_fetch_array($zones_query)) {
 708        $zones_array[] = array('id' => $zones['zone_id'],
 709                               'text' => $zones['zone_name']);
 710      }
 711  
 712      return $zones_array;
 713    }
 714  
 715    function tep_prepare_country_zones_pull_down($country_id = '') {
 716  // preset the width of the drop-down for Netscape

 717      $pre = '';
 718      if ( (!tep_browser_detect('MSIE')) && (tep_browser_detect('Mozilla/4')) ) {
 719        for ($i=0; $i<45; $i++) $pre .= '&nbsp;';
 720      }
 721  
 722      $zones = tep_get_country_zones($country_id);
 723  
 724      if (sizeof($zones) > 0) {
 725        $zones_select = array(array('id' => '', 'text' => PLEASE_SELECT));
 726        $zones = array_merge($zones_select, $zones);
 727      } else {
 728        $zones = array(array('id' => '', 'text' => TYPE_BELOW));
 729  // create dummy options for Netscape to preset the height of the drop-down

 730        if ( (!tep_browser_detect('MSIE')) && (tep_browser_detect('Mozilla/4')) ) {
 731          for ($i=0; $i<9; $i++) {
 732            $zones[] = array('id' => '', 'text' => $pre);
 733          }
 734        }
 735      }
 736  
 737      return $zones;
 738    }
 739  
 740  ////

 741  // Get list of address_format_id's

 742    function tep_get_address_formats() {
 743      $address_format_query = tep_db_query("select address_format_id from " . TABLE_ADDRESS_FORMAT . " order by address_format_id");
 744      $address_format_array = array();
 745      while ($address_format_values = tep_db_fetch_array($address_format_query)) {
 746        $address_format_array[] = array('id' => $address_format_values['address_format_id'],
 747                                        'text' => $address_format_values['address_format_id']);
 748      }
 749      return $address_format_array;
 750    }
 751  
 752  ////

 753  // Alias function for Store configuration values in the Administration Tool

 754    function tep_cfg_pull_down_country_list($country_id) {
 755      return tep_draw_pull_down_menu('configuration_value', tep_get_countries(), $country_id);
 756    }
 757  
 758    function tep_cfg_pull_down_zone_list($zone_id) {
 759      return tep_draw_pull_down_menu('configuration_value', tep_get_country_zones(STORE_COUNTRY), $zone_id);
 760    }
 761  
 762    function tep_cfg_pull_down_tax_classes($tax_class_id, $key = '') {
 763      $name = (($key) ? 'configuration[' . $key . ']' : 'configuration_value');
 764  
 765      $tax_class_array = array(array('id' => '0', 'text' => TEXT_NONE));
 766      $tax_class_query = tep_db_query("select tax_class_id, tax_class_title from " . TABLE_TAX_CLASS . " order by tax_class_title");
 767      while ($tax_class = tep_db_fetch_array($tax_class_query)) {
 768        $tax_class_array[] = array('id' => $tax_class['tax_class_id'],
 769                                   'text' => $tax_class['tax_class_title']);
 770      }
 771  
 772      return tep_draw_pull_down_menu($name, $tax_class_array, $tax_class_id);
 773    }
 774  
 775  // BOF: MOD - QT Pro

 776  // Function to build menu of available class files given a file prefix

 777  // Used for configuring plug-ins for product information attributes

 778    function tep_cfg_pull_down_class_files($prefix, $current_file) {
 779      $d=DIR_FS_CATALOG . DIR_WS_CLASSES;
 780      $function_directory = dir ($d);
 781  
 782      while (false !== ($function = $function_directory->read())) {
 783        if (preg_match('/^'.$prefix.'(.+)\.php$/',$function,$function_name)) {
 784            $file_list[]=array('id'=>$function_name[1], 'text'=>$function_name[1]);
 785        }
 786      }
 787      $function_directory->close();
 788  
 789      return tep_draw_pull_down_menu('configuration_value', $file_list, $current_file);
 790    }
 791  // EOF: MOD - QT Pro

 792  
 793  ////

 794  // Function to read in text area in admin

 795   function tep_cfg_textarea($text) {
 796      return tep_draw_textarea_field('configuration_value', false, 35, 5, $text);
 797    }
 798  
 799    function tep_cfg_get_zone_name($zone_id) {
 800      $zone_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_id = '" . (int)$zone_id . "'");
 801  
 802      if (!tep_db_num_rows($zone_query)) {
 803        return $zone_id;
 804      } else {
 805        $zone = tep_db_fetch_array($zone_query);
 806        return $zone['zone_name'];
 807      }
 808    }
 809  
 810  ////

 811  // Sets the status of a banner

 812    function tep_set_banner_status($banners_id, $status) {
 813      if ($status == '1') {
 814        return tep_db_query("update " . TABLE_BANNERS . " set status = '1', expires_impressions = NULL, expires_date = NULL, date_status_change = NULL where banners_id = '" . $banners_id . "'");
 815      } elseif ($status == '0') {
 816        return tep_db_query("update " . TABLE_BANNERS . " set status = '0', date_status_change = now() where banners_id = '" . $banners_id . "'");
 817      } else {
 818        return -1;
 819      }
 820    }
 821  
 822  ////

 823  // Sets the status of a product

 824    function tep_set_product_status($products_id, $status) {
 825      if ($status == '1') {
 826        return tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '1', products_last_modified = now() where products_id = '" . (int)$products_id . "'");
 827      } elseif ($status == '0') {
 828        return tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0', products_last_modified = now() where products_id = '" . (int)$products_id . "'");
 829      } else {
 830        return -1;
 831      }
 832    }
 833  
 834  ////

 835  // Sets the status of a product on special

 836    function tep_set_specials_status($specials_id, $status) {
 837      if ($status == '1') {
 838        return tep_db_query("update " . TABLE_SPECIALS . " set status = '1', expires_date = NULL, date_status_change = NULL where specials_id = '" . (int)$specials_id . "'");
 839      } elseif ($status == '0') {
 840        return tep_db_query("update " . TABLE_SPECIALS . " set status = '0', date_status_change = now() where specials_id = '" . (int)$specials_id . "'");
 841      } else {
 842        return -1;
 843      }
 844    }
 845  
 846  ////

 847  // Return a product's special price (returns nothing if there is no offer)

 848  // TABLES: products

 849    function tep_get_products_special_price($product_id) {
 850  // BOF: MOD - Separate Pricing Per Customer

 851  //  $product_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$product_id . "' and status");

 852      global $sppc_customer_group_id;
 853  
 854      if(!tep_session_is_registered('sppc_customer_group_id')) {
 855        $customer_group_id = '0';
 856      } else {
 857        $customer_group_id = $sppc_customer_group_id;
 858      }
 859      $product_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$product_id . "' and status and customers_group_id = '" . (int)$customer_group_id . "'");
 860  // EOF: MOD - Separate_Pricing Per Customer

 861  
 862      $product = tep_db_fetch_array($product_query);
 863  
 864      return $product['specials_new_products_price'];
 865    }
 866  
 867  
 868  ////

 869  // Sets timeout for the current script.

 870  // Cant be used in safe mode.

 871    function tep_set_time_limit($limit) {
 872      if (!get_cfg_var('safe_mode')) {
 873        set_time_limit($limit);
 874      }
 875    }
 876  
 877  ////

 878  // Alias function for Store configuration values in the Administration Tool

 879    function tep_cfg_select_option($select_array, $key_value, $key = '') {
 880      $string = '';
 881  
 882      for ($i=0, $n=sizeof($select_array); $i<$n; $i++) {
 883        $name = ((tep_not_null($key)) ? 'configuration[' . $key . ']' : 'configuration_value');
 884  
 885        $string .= '<br><input type="radio" name="' . $name . '" value="' . $select_array[$i] . '"';
 886  
 887        if ($key_value == $select_array[$i]) $string .= ' CHECKED';
 888  
 889        $string .= '> ' . $select_array[$i];
 890      }
 891  
 892      return $string;
 893    }
 894  
 895  ////

 896  // Alias function for module configuration keys

 897    function tep_mod_select_option($select_array, $key_name, $key_value) {
 898      reset($select_array);
 899      while (list($key, $value) = each($select_array)) {
 900        if (is_int($key)) $key = $value;
 901        $string .= '<br><input type="radio" name="configuration[' . $key_name . ']" value="' . $key . '"';
 902        if ($key_value == $key) $string .= ' CHECKED';
 903        $string .= '> ' . $value;
 904      }
 905  
 906      return $string;
 907    }
 908  
 909  // BOF: MOD - USPS Methods 2.5

 910  // Alias function for Store configuration values in the Administration Tool

 911    function tep_cfg_select_multioption($select_array, $key_value, $key = '') {
 912      for ($i=0; $i<sizeof($select_array); $i++) {
 913        $name = (($key) ? 'configuration[' . $key . '][]' :
 914  'configuration_value');
 915        $string .= '<br><input type="checkbox" name="' . $name . '" value="' .
 916  $select_array[$i] . '"';
 917        $key_values = explode( ", ", $key_value);
 918        if ( in_array($select_array[$i], $key_values) ) $string .= ' CHECKED';
 919        $string .= '> ' . $select_array[$i];
 920      }
 921      $string .= '<input type="hidden" name="' . $name . '" value="--none--">';
 922      return $string;
 923    }
 924  // EOF: MOD - USPS Methods 2.5

 925  
 926  ////

 927  // Retreive server information

 928    function tep_get_system_information() {
 929      global $HTTP_SERVER_VARS;
 930  
 931      $db_query = tep_db_query("select now() as datetime");
 932      $db = tep_db_fetch_array($db_query);
 933  
 934      list($system, $host, $kernel) = preg_split('/[\s,]+/', @exec('uname -a'), 5);
 935  
 936      return array('date' => tep_datetime_short(date('Y-m-d H:i:s')),
 937                   'system' => $system,
 938                   'kernel' => $kernel,
 939                   'host' => $host,
 940                   'ip' => gethostbyname($host),
 941                   'uptime' => @exec('uptime'),
 942                   'http_server' => $HTTP_SERVER_VARS['SERVER_SOFTWARE'],
 943                   'php' => PHP_VERSION,
 944                   'zend' => (function_exists('zend_version') ? zend_version() : ''),
 945                   'db_server' => DB_SERVER,
 946                   'db_ip' => gethostbyname(DB_SERVER),
 947                   'db_version' => 'MySQL ' . (function_exists('mysql_get_server_info') ? mysql_get_server_info() : ''),
 948                   'db_date' => tep_datetime_short($db['datetime']));
 949    }
 950  
 951    function tep_generate_category_path($id, $from = 'category', $categories_array = '', $index = 0) {
 952      global $languages_id;
 953  
 954      if (!is_array($categories_array)) $categories_array = array();
 955  
 956      if ($from == 'product') {
 957        $categories_query = tep_db_query("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$id . "'");
 958        while ($categories = tep_db_fetch_array($categories_query)) {
 959          if ($categories['categories_id'] == '0') {
 960            $categories_array[$index][] = array('id' => '0', 'text' => TEXT_TOP);
 961          } else {
 962            $category_query = tep_db_query("select cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = '" . (int)$categories['categories_id'] . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "'");
 963            $category = tep_db_fetch_array($category_query);
 964            $categories_array[$index][] = array('id' => $categories['categories_id'], 'text' => $category['categories_name']);
 965            if ( (tep_not_null($category['parent_id'])) && ($category['parent_id'] != '0') ) $categories_array = tep_generate_category_path($category['parent_id'], 'category', $categories_array, $index);
 966            $categories_array[$index] = array_reverse($categories_array[$index]);
 967          }
 968          $index++;
 969        }
 970      } elseif ($from == 'category') {
 971        $category_query = tep_db_query("select cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = '" . (int)$id . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "'");
 972        $category = tep_db_fetch_array($category_query);
 973        $categories_array[$index][] = array('id' => $id, 'text' => $category['categories_name']);
 974        if ( (tep_not_null($category['parent_id'])) && ($category['parent_id'] != '0') ) $categories_array = tep_generate_category_path($category['parent_id'], 'category', $categories_array, $index);
 975      }
 976  
 977      return $categories_array;
 978    }
 979  
 980    function tep_output_generated_category_path($id, $from = 'category') {
 981      $calculated_category_path_string = '';
 982      $calculated_category_path = tep_generate_category_path($id, $from);
 983      for ($i=0, $n=sizeof($calculated_category_path); $i<$n; $i++) {
 984        for ($j=0, $k=sizeof($calculated_category_path[$i]); $j<$k; $j++) {
 985          $calculated_category_path_string .= $calculated_category_path[$i][$j]['text'] . '&nbsp;&gt;&nbsp;';
 986        }
 987        $calculated_category_path_string = substr($calculated_category_path_string, 0, -16) . '<br>';
 988      }
 989      $calculated_category_path_string = substr($calculated_category_path_string, 0, -4);
 990  
 991      if (strlen($calculated_category_path_string) < 1) $calculated_category_path_string = TEXT_TOP;
 992  
 993      return $calculated_category_path_string;
 994    }
 995  
 996    function tep_get_generated_category_path_ids($id, $from = 'category') {
 997      $calculated_category_path_string = '';
 998      $calculated_category_path = tep_generate_category_path($id, $from);
 999      for ($i=0, $n=sizeof($calculated_category_path); $i<$n; $i++) {
1000        for ($j=0, $k=sizeof($calculated_category_path[$i]); $j<$k; $j++) {
1001          $calculated_category_path_string .= $calculated_category_path[$i][$j]['id'] . '_';
1002        }
1003        $calculated_category_path_string = substr($calculated_category_path_string, 0, -1) . '<br>';
1004      }
1005      $calculated_category_path_string = substr($calculated_category_path_string, 0, -4);
1006  
1007      if (strlen($calculated_category_path_string) < 1) $calculated_category_path_string = TEXT_TOP;
1008  
1009      return $calculated_category_path_string;
1010    }
1011  
1012    function tep_remove_category($category_id) {
1013      $category_image_query = tep_db_query("select categories_image from " . TABLE_CATEGORIES . " where categories_id = '" . (int)$category_id . "'");
1014      $category_image = tep_db_fetch_array($category_image_query);
1015  
1016      $duplicate_image_query = tep_db_query("select count(*) as total from " . TABLE_CATEGORIES . " where categories_image = '" . tep_db_input($category_image['categories_image']) . "'");
1017      $duplicate_image = tep_db_fetch_array($duplicate_image_query);
1018  
1019      if ($duplicate_image['total'] < 2) {
1020        if (file_exists(DIR_FS_CATALOG_IMAGES . $category_image['categories_image'])) {
1021          @unlink(DIR_FS_CATALOG_IMAGES . $category_image['categories_image']);
1022        }
1023      }
1024  
1025      tep_db_query("delete from " . TABLE_CATEGORIES . " where categories_id = '" . (int)$category_id . "'");
1026      tep_db_query("delete from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . (int)$category_id . "'");
1027      tep_db_query("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id = '" . (int)$category_id . "'");
1028  
1029      if (USE_CACHE == 'true') {
1030        tep_reset_cache_block('categories');
1031        tep_reset_cache_block('also_purchased');
1032      }
1033    }
1034  
1035    function tep_remove_product($product_id) {
1036      $product_image_query = tep_db_query("select products_image from " . TABLE_PRODUCTS . " where products_id = '" . (int)$product_id . "'");
1037      $product_image = tep_db_fetch_array($product_image_query);
1038  
1039      $duplicate_image_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " where products_image = '" . tep_db_input($product_image['products_image']) . "'");
1040      $duplicate_image = tep_db_fetch_array($duplicate_image_query);
1041  
1042      if ($duplicate_image['total'] < 2) {
1043        if (file_exists(DIR_FS_CATALOG_IMAGES . $product_image['products_image'])) {
1044          @unlink(DIR_FS_CATALOG_IMAGES . $product_image['products_image']);
1045        }
1046      }
1047  
1048      tep_db_query("delete from " . TABLE_SPECIALS . " where products_id = '" . (int)$product_id . "'");
1049      tep_db_query("delete from " . TABLE_PRODUCTS . " where products_id = '" . (int)$product_id . "'");
1050  // LINE ADDED: MOD - Separate Price per Customer

1051      tep_db_query("delete from " . TABLE_PRODUCTS_GROUPS . " where products_id = '" . (int)$product_id . "'");
1052      tep_db_query("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$product_id . "'");
1053      tep_db_query("delete from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$product_id . "'");
1054      tep_db_query("delete from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$product_id . "'");
1055      tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where products_id = '" . (int)$product_id . "' or products_id like '" . (int)$product_id . "{%'");
1056      tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where products_id = '" . (int)$product_id . "' or products_id like '" . (int)$product_id . "{%'");
1057   
1058  // BOF: MOD - Wishlist addition to delete products from the wishlist when deleted 

1059      tep_db_query("delete from " . TABLE_WISHLIST . " where products_id = '" . (int)$product_id . "'"); 
1060      tep_db_query("delete from " . TABLE_WISHLIST_ATTRIBUTES . " where products_id = '" . (int)$product_id . "'"); 
1061  // EOF: MOD - Wishlist addition to delete products from the wishlist when deleted 

1062   
1063      $product_reviews_query = tep_db_query("select reviews_id from " . TABLE_REVIEWS . " where products_id = '" . (int)$product_id . "'");
1064      while ($product_reviews = tep_db_fetch_array($product_reviews_query)) {
1065        tep_db_query("delete from " . TABLE_REVIEWS_DESCRIPTION . " where reviews_id = '" . (int)$product_reviews['reviews_id'] . "'");
1066      }
1067      tep_db_query("delete from " . TABLE_REVIEWS . " where products_id = '" . (int)$product_id . "'");
1068  
1069      if (USE_CACHE == 'true') {
1070        tep_reset_cache_block('categories');
1071        tep_reset_cache_block('also_purchased');
1072      }
1073    }
1074  
1075    function tep_remove_order($order_id, $restock = false) {
1076      if ($restock == 'on') {
1077  // BOF: MOD - QT Pro

1078  //old $order_query = tep_db_query("select products_id, products_quantity from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$order_id . "'");

1079  //    while ($order = tep_db_fetch_array($order_query)) {

1080  //      tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity = products_quantity + " . $order['products_quantity'] . ", products_ordered = products_ordered - " . $order['products_quantity'] . " where products_id = '" . (int)$order['products_id'] . "'");

1081        $order_query = tep_db_query("select products_id, products_quantity, products_stock_attributes from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$order_id . "'");
1082        while ($order = tep_db_fetch_array($order_query)) {
1083          $product_stock_adjust = 0;
1084            if (tep_not_null($order['products_stock_attributes'])) {
1085            if ($order['products_stock_attributes'] != '$$DOWNLOAD$$') {
1086              $attributes_stock_query = tep_db_query("SELECT products_stock_quantity
1087                                                      FROM " . TABLE_PRODUCTS_STOCK . "
1088                                                      WHERE products_stock_attributes = '" . $order['products_stock_attributes'] . "'
1089                                                      AND products_id = '" . (int)$order['products_id'] . "'");
1090              if (tep_db_num_rows($attributes_stock_query) > 0) {
1091                  $attributes_stock_values = tep_db_fetch_array($attributes_stock_query);
1092                  tep_db_query("UPDATE " . TABLE_PRODUCTS_STOCK . "
1093                                SET products_stock_quantity = products_stock_quantity + '" . (int)$order['products_quantity'] . "'
1094                                WHERE products_stock_attributes = '" . $order['products_stock_attributes'] . "'
1095                                AND products_id = '" . (int)$order['products_id'] . "'");
1096                  $product_stock_adjust = min($order['products_quantity'],  $order['products_quantity']+$attributes_stock_values['products_stock_quantity']);
1097              } else {
1098                  tep_db_query("INSERT into " . TABLE_PRODUCTS_STOCK . "
1099                                (products_id, products_stock_attributes, products_stock_quantity)
1100                                VALUES ('" . (int)$order['products_id'] . "', '" . $order['products_stock_attributes'] . "', '" . (int)$order['products_quantity'] . "')");
1101                  $product_stock_adjust = $order['products_quantity'];
1102              }
1103            }
1104          } else {
1105              $product_stock_adjust = $order['products_quantity'];
1106          }
1107          tep_db_query("UPDATE " . TABLE_PRODUCTS . "
1108                        SET products_quantity = products_quantity + " . $product_stock_adjust . ", products_ordered = products_ordered - " . (int)$order['products_quantity'] . "
1109                        WHERE products_id = '" . (int)$order['products_id'] . "'");
1110  // EOF: MOD - QT Pro

1111        }
1112      }
1113      tep_db_query("delete from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'");
1114      tep_db_query("delete from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$order_id . "'");
1115      tep_db_query("delete from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_id = '" . (int)$order_id . "'");
1116      tep_db_query("delete from " . TABLE_ORDERS_STATUS_HISTORY . " where orders_id = '" . (int)$order_id . "'");
1117      tep_db_query("delete from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$order_id . "'");
1118    }
1119  
1120    function tep_reset_cache_block($cache_block) {
1121      global $cache_blocks;
1122  
1123      for ($i=0, $n=sizeof($cache_blocks); $i<$n; $i++) {
1124        if ($cache_blocks[$i]['code'] == $cache_block) {
1125          if ($cache_blocks[$i]['multiple']) {
1126            if ($dir = @opendir(DIR_FS_CACHE)) {
1127              while ($cache_file = readdir($dir)) {
1128                $cached_file = $cache_blocks[$i]['file'];
1129                $languages = tep_get_languages();
1130                for ($j=0, $k=sizeof($languages); $j<$k; $j++) {
1131                  $cached_file_unlink = ereg_replace('-language', '-' . $languages[$j]['directory'], $cached_file);
1132                  if (ereg('^' . $cached_file_unlink, $cache_file)) {
1133                    @unlink(DIR_FS_CACHE . $cache_file);
1134                  }
1135                }
1136              }
1137              closedir($dir);
1138            }
1139          } else {
1140            $cached_file = $cache_blocks[$i]['file'];
1141            $languages = tep_get_languages();
1142            for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
1143              $cached_file = ereg_replace('-language', '-' . $languages[$i]['directory'], $cached_file);
1144              @unlink(DIR_FS_CACHE . $cached_file);
1145            }
1146          }
1147          break;
1148        }
1149      }
1150    }
1151  
1152    function tep_get_file_permissions($mode) {
1153  // determine type

1154      if ( ($mode & 0xC000) == 0xC000) { // unix domain socket
1155        $type = 's';
1156      } elseif ( ($mode & 0x4000) == 0x4000) { // directory
1157        $type = 'd';
1158      } elseif ( ($mode & 0xA000) == 0xA000) { // symbolic link
1159        $type = 'l';
1160      } elseif ( ($mode & 0x8000) == 0x8000) { // regular file
1161        $type = '-';
1162      } elseif ( ($mode & 0x6000) == 0x6000) { //bBlock special file
1163        $type = 'b';
1164      } elseif ( ($mode & 0x2000) == 0x2000) { // character special file
1165        $type = 'c';
1166      } elseif ( ($mode & 0x1000) == 0x1000) { // named pipe
1167        $type = 'p';
1168      } else { // unknown
1169        $type = '?';
1170      }
1171  
1172  // determine permissions

1173      $owner['read']    = ($mode & 00400) ? 'r' : '-';
1174      $owner['write']   = ($mode & 00200) ? 'w' : '-';
1175      $owner['execute'] = ($mode & 00100) ? 'x' : '-';
1176      $group['read']    = ($mode & 00040) ? 'r' : '-';
1177      $group['write']   = ($mode & 00020) ? 'w' : '-';
1178      $group['execute'] = ($mode & 00010) ? 'x' : '-';
1179      $world['read']    = ($mode & 00004) ? 'r' : '-';
1180      $world['write']   = ($mode & 00002) ? 'w' : '-';
1181      $world['execute'] = ($mode & 00001) ? 'x' : '-';
1182  
1183  // adjust for SUID, SGID and sticky bit

1184      if ($mode & 0x800 ) $owner['execute'] = ($owner['execute'] == 'x') ? 's' : 'S';
1185      if ($mode & 0x400 ) $group['execute'] = ($group['execute'] == 'x') ? 's' : 'S';
1186      if ($mode & 0x200 ) $world['execute'] = ($world['execute'] == 'x') ? 't' : 'T';
1187  
1188      return $type .
1189             $owner['read'] . $owner['write'] . $owner['execute'] .
1190             $group['read'] . $group['write'] . $group['execute'] .
1191             $world['read'] . $world['write'] . $world['execute'];
1192    }
1193  
1194    function tep_remove($source) {
1195      global $messageStack, $tep_remove_error;
1196  
1197      if (isset($tep_remove_error)) $tep_remove_error = false;
1198  
1199      if (is_dir($source)) {
1200        $dir = dir($source);
1201        while ($file = $dir->read()) {
1202          if ( ($file != '.') && ($file != '..') ) {
1203            if (is_writeable($source . '/' . $file)) {
1204              tep_remove($source . '/' . $file);
1205            } else {
1206              $messageStack->add(sprintf(ERROR_FILE_NOT_REMOVEABLE, $source . '/' . $file), 'error');
1207              $tep_remove_error = true;
1208            }
1209          }
1210        }
1211        $dir->close();
1212  
1213        if (is_writeable($source)) {
1214          rmdir($source);
1215        } else {
1216          $messageStack->add(sprintf(ERROR_DIRECTORY_NOT_REMOVEABLE, $source), 'error');
1217          $tep_remove_error = true;
1218        }
1219      } else {
1220        if (is_writeable($source)) {
1221          unlink($source);
1222        } else {
1223          $messageStack->add(sprintf(ERROR_FILE_NOT_REMOVEABLE, $source), 'error');
1224          $tep_remove_error = true;
1225        }
1226      }
1227    }
1228  
1229  ////

1230  // Output the tax percentage with optional padded decimals

1231    function tep_display_tax_value($value, $padding = TAX_DECIMAL_PLACES) {
1232      if (strpos($value, '.')) {
1233        $loop = true;
1234        while ($loop) {
1235          if (substr($value, -1) == '0') {
1236            $value = substr($value, 0, -1);
1237          } else {
1238            $loop = false;
1239            if (substr($value, -1) == '.') {
1240              $value = substr($value, 0, -1);
1241            }
1242          }
1243        }
1244      }
1245  
1246      if ($padding > 0) {
1247        if ($decimal_pos = strpos($value, '.')) {
1248          $decimals = strlen(substr($value, ($decimal_pos+1)));
1249          for ($i=$decimals; $i<$padding; $i++) {
1250            $value .= '0';
1251          }
1252        } else {
1253          $value .= '.';
1254          for ($i=0; $i<$padding; $i++) {
1255            $value .= '0';
1256          }
1257        }
1258      }
1259  
1260      return $value;
1261    }
1262  
1263    function tep_mail($to_name, $to_email_address, $email_subject, $email_text, $from_email_name, $from_email_address) {
1264      if (SEND_EMAILS != 'true') return false;
1265  
1266      // Instantiate a new mail object

1267      $message = new email(array('X-Mailer: osCommerce'));
1268  
1269      // Build the text version

1270      $text = strip_tags($email_text);
1271      if (EMAIL_USE_HTML == 'true') {
1272        $message->add_html($email_text, $text);
1273      } else {
1274        $message->add_text($text);
1275      }
1276  
1277      // Send message

1278      $message->build_message();
1279      $message->send($to_name, $to_email_address, $from_email_name, $from_email_address, $email_subject);
1280    }
1281  
1282    function tep_get_tax_class_title($tax_class_id) {
1283      if ($tax_class_id == '0') {
1284        return TEXT_NONE;
1285      } else {
1286        $classes_query = tep_db_query("select tax_class_title from " . TABLE_TAX_CLASS . " where tax_class_id = '" . (int)$tax_class_id . "'");
1287        $classes = tep_db_fetch_array($classes_query);
1288  
1289        return $classes['tax_class_title'];
1290      }
1291    }
1292  
1293    function tep_banner_image_extension() {
1294      if (function_exists('imagetypes')) {
1295        if (imagetypes() & IMG_PNG) {
1296          return 'png';
1297        } elseif (imagetypes() & IMG_JPG) {
1298          return 'jpg';
1299        } elseif (imagetypes() & IMG_GIF) {
1300          return 'gif';
1301        }
1302      } elseif (function_exists('imagecreatefrompng') && function_exists('imagepng')) {
1303        return 'png';
1304      } elseif (function_exists('imagecreatefromjpeg') && function_exists('imagejpeg')) {
1305        return 'jpg';
1306      } elseif (function_exists('imagecreatefromgif') && function_exists('imagegif')) {
1307        return 'gif';
1308      }
1309  
1310      return false;
1311    }
1312  
1313  ////

1314  // Wrapper function for round() for php3 compatibility

1315    function tep_round($value, $precision) {
1316      if (PHP_VERSION < 4) {
1317        $exp = pow(10, $precision);
1318        return round($value * $exp) / $exp;
1319      } else {
1320        return round($value, $precision);
1321      }
1322    }
1323  
1324  ////

1325  // Add tax to a products price

1326    function tep_add_tax($price, $tax, $override = false) {
1327      if ( ( (DISPLAY_PRICE_WITH_TAX == 'true') || ($override == true) ) && ($tax > 0) ) {
1328        return $price + tep_calculate_tax($price, $tax);
1329      } else {
1330        return $price;
1331      }
1332    }
1333  
1334  // Calculates Tax rounding the result

1335    function tep_calculate_tax($price, $tax) {
1336      return $price * $tax / 100;
1337    }
1338  
1339  ////

1340  // Returns the tax rate for a zone / class

1341  // TABLES: tax_rates, zones_to_geo_zones

1342    function tep_get_tax_rate($class_id, $country_id = -1, $zone_id = -1) {
1343      global $customer_zone_id, $customer_country_id;
1344  
1345      if ( ($country_id == -1) && ($zone_id == -1) ) {
1346        if (!tep_session_is_registered('customer_id')) {
1347          $country_id = STORE_COUNTRY;
1348          $zone_id = STORE_ZONE;
1349        } else {
1350          $country_id = $customer_country_id;
1351          $zone_id = $customer_zone_id;
1352        }
1353      }
1354  
1355      $tax_query = tep_db_query("select sum(tax_rate) as tax_rate from " . TABLE_TAX_RATES . " tr left join " . TABLE_ZONES_TO_GEO_ZONES . " za on (tr.tax_zone_id = za.geo_zone_id) left join " . TABLE_GEO_ZONES . " tz on (tz.geo_zone_id = tr.tax_zone_id) where (za.zone_country_id is null or za.zone_country_id = '0' or za.zone_country_id = '" . (int)$country_id . "') and (za.zone_id is null or za.zone_id = '0' or za.zone_id = '" . (int)$zone_id . "') and tr.tax_class_id = '" . (int)$class_id . "' group by tr.tax_priority");
1356      if (tep_db_num_rows($tax_query)) {
1357        $tax_multiplier = 1.0;
1358        while ($tax = tep_db_fetch_array($tax_query)) {
1359          $tax_multiplier *= 1.0 + ($tax['tax_rate'] / 100);
1360        }
1361        return ($tax_multiplier - 1.0) * 100;
1362      } else {
1363        return 0;
1364      }
1365    }
1366  
1367  ////

1368  // Returns the tax rate for a tax class

1369  // TABLES: tax_rates

1370    function tep_get_tax_rate_value($class_id) {
1371      $tax_query = tep_db_query("select SUM(tax_rate) as tax_rate from " . TABLE_TAX_RATES . " where tax_class_id = '" . (int)$class_id . "' group by tax_priority");
1372      if (tep_db_num_rows($tax_query)) {
1373        $tax_multiplier = 0;
1374        while ($tax = tep_db_fetch_array($tax_query)) {
1375          $tax_multiplier += $tax['tax_rate'];
1376        }
1377        return $tax_multiplier;
1378      } else {
1379        return 0;
1380      }
1381    }
1382  
1383    function tep_call_function($function, $parameter, $object = '') {
1384      if ($object == '') {
1385        return call_user_func($function, $parameter);
1386      } elseif (PHP_VERSION < 4) {
1387        return call_user_method($function, $object, $parameter);
1388      } else {
1389        return call_user_func(array($object, $function), $parameter);
1390      }
1391    }
1392  
1393    function tep_get_zone_class_title($zone_class_id) {
1394      if ($zone_class_id == '0') {
1395        return TEXT_NONE;
1396      } else {
1397        $classes_query = tep_db_query("select geo_zone_name from " . TABLE_GEO_ZONES . " where geo_zone_id = '" . (int)$zone_class_id . "'");
1398        $classes = tep_db_fetch_array($classes_query);
1399  
1400        return $classes['geo_zone_name'];
1401      }
1402    }
1403  
1404    function tep_cfg_pull_down_zone_classes($zone_class_id, $key = '') {
1405      $name = (($key) ? 'configuration[' . $key . ']' : 'configuration_value');
1406  
1407      $zone_class_array = array(array('id' => '0', 'text' => TEXT_NONE));
1408      $zone_class_query = tep_db_query("select geo_zone_id, geo_zone_name from " . TABLE_GEO_ZONES . " order by geo_zone_name");
1409      while ($zone_class = tep_db_fetch_array($zone_class_query)) {
1410        $zone_class_array[] = array('id' => $zone_class['geo_zone_id'],
1411                                    'text' => $zone_class['geo_zone_name']);
1412      }
1413  
1414      return tep_draw_pull_down_menu($name, $zone_class_array, $zone_class_id);
1415    }
1416  
1417    function tep_cfg_pull_down_order_statuses($order_status_id, $key = '') {
1418      global $languages_id;
1419  
1420      $name = (($key) ? 'configuration[' . $key . ']' : 'configuration_value');
1421  
1422      $statuses_array = array(array('id' => '0', 'text' => TEXT_DEFAULT));
1423      $statuses_query = tep_db_query("select orders_status_id, orders_status_name from " . TABLE_ORDERS_STATUS . " where language_id = '" . (int)$languages_id . "' order by orders_status_name");
1424      while ($statuses = tep_db_fetch_array($statuses_query)) {
1425        $statuses_array[] = array('id' => $statuses['orders_status_id'],
1426                                  'text' => $statuses['orders_status_name']);
1427      }
1428  
1429      return tep_draw_pull_down_menu($name, $statuses_array, $order_status_id);
1430    }
1431  
1432    function tep_get_order_status_name($order_status_id, $language_id = '') {
1433      global $languages_id;
1434  
1435      if ($order_status_id < 1) return TEXT_DEFAULT;
1436  
1437      if (!is_numeric($language_id)) $language_id = $languages_id;
1438  
1439      $status_query = tep_db_query("select orders_status_name from " . TABLE_ORDERS_STATUS . " where orders_status_id = '" . (int)$order_status_id . "' and language_id = '" . (int)$language_id . "'");
1440      $status = tep_db_fetch_array($status_query);
1441  
1442      return $status['orders_status_name'];
1443    }
1444  
1445  ////

1446  // Return a random value

1447    function tep_rand($min = null, $max = null) {
1448      static $seeded;
1449  
1450      if (!$seeded) {
1451        mt_srand((double)microtime()*1000000);
1452        $seeded = true;
1453      }
1454  
1455      if (isset($min) && isset($max)) {
1456        if ($min >= $max) {
1457          return $min;
1458        } else {
1459          return mt_rand($min, $max);
1460        }
1461      } else {
1462        return mt_rand();
1463      }
1464    }
1465  
1466  // nl2br() prior PHP 4.2.0 did not convert linefeeds on all OSs (it only converted \n)

1467    function tep_convert_linefeeds($from, $to, $string) {
1468      if ((PHP_VERSION < "4.0.5") && is_array($from)) {
1469        return ereg_replace('(' . implode('|', $from) . ')', $to, $string);
1470      } else {
1471        return str_replace($from, $to, $string);
1472      }
1473    }
1474  
1475    function tep_string_to_int($string) {
1476      return (int)$string;
1477    }
1478  
1479  ////

1480  // Parse and secure the cPath parameter values

1481    function tep_parse_category_path($cPath) {
1482  // make sure the category IDs are integers

1483      $cPath_array = array_map('tep_string_to_int', explode('_', $cPath));
1484  
1485  // make sure no duplicate category IDs exist which could lock the server in a loop

1486      $tmp_array = array();
1487      $n = sizeof($cPath_array);
1488      for ($i=0; $i<$n; $i++) {
1489        if (!in_array($cPath_array[$i], $tmp_array)) {
1490          $tmp_array[] = $cPath_array[$i];
1491        }
1492      }
1493  
1494      return $tmp_array;
1495    }
1496  
1497  // BOF: MOD - Order Editor

1498  //////create a pull down for all payment installed payment methods for Order Editor configuration

1499  // Get list of all payment modules available

1500    function tep_cfg_pull_down_payment_methods() {
1501    global $language;
1502    $enabled_payment = array();
1503    $module_directory = DIR_FS_CATALOG_MODULES . 'payment/';
1504    $file_extension = '.php';
1505  
1506    if ($dir = @dir($module_directory)) {
1507      while ($file = $dir->read()) {
1508        if (!is_dir( $module_directory . $file)) {
1509          if (substr($file, strrpos($file, '.')) == $file_extension) {
1510            $directory_array[] = $file;
1511          }
1512        }
1513      }
1514      sort($directory_array);
1515      $dir->close();
1516    }
1517  
1518    // For each available payment module, check if enabled

1519    for ($i=0, $n=sizeof($directory_array); $i<$n; $i++) {
1520      $file = $directory_array[$i];
1521  
1522      include(DIR_FS_CATALOG_LANGUAGES . $language . '/modules/payment/' . $file);
1523      include($module_directory . $file);
1524  
1525      $class = substr($file, 0, strrpos($file, '.'));
1526      if (tep_class_exists($class)) {
1527        $module = new $class;
1528        if ($module->check() > 0) {
1529          // If module enabled create array of titles

1530            $enabled_payment[] = array('id' => $module->title, 'text' => $module->title);
1531          
1532        }
1533     }
1534   }
1535                   
1536      $enabled_payment[] = array('id' => 'Other', 'text' => 'Other');    
1537          
1538          //draw the dropdown menu for payment methods and default to the order value

1539        return tep_draw_pull_down_menu('configuration_value', $enabled_payment, '', ''); 
1540          }
1541  /////end payment method dropdown

1542  // EOF: MOD - Order Editor

1543  
1544  // LINE ADDED: MOD - Downloads Controller

1545    require (DIR_WS_FUNCTIONS . 'downloads_controller.php');
1546  
1547  // LINE ADDED: MOD - IndvShip

1548  //require(DIR_WS_FUNCTIONS . 'indvship_status.php');

1549  
1550  // BOF: MOD - FedEx functions

1551    function tep_ship_request($shipData,$ship_type,$order) {
1552  
1553      $fed = new FedExDC($shipData[0][10],$shipData[1][498]);
1554  
1555      $ship_Ret = $fed->$ship_type($shipData);
1556      // todo: add appropriate error checking for at least some of the possible errors

1557      if ($error = $fed->getError()) {
1558        // in case the ship date is a holiday, check for the error and correct the date

1559        // todo: correct the date!

1560        if (preg_match('/FF43/',$error)) {
1561          echo 'You cannot schedule a pickup on a weekend or holiday! Please go back and change
1562          the pickup date.';
1563          die();
1564        } else {
1565          echo 'This transaction could not be completed. Please note the error message
1566                below.<br><br>';
1567          die("ERROR: ". $error);
1568        }
1569  
1570      // if successful, we get the tracking number, write the label *.png file to images/fedex,

1571      // and display the label

1572      } else {
1573        $trackNum = $ship_Ret[29];
1574        // decode and save label, named for the tracking number

1575        $fed->label(DIR_WS_FEDEX_LABELS . $trackNum . '.png');
1576      }
1577      return $trackNum;
1578    }
1579  // EOF: MOD - FedEx functions

1580  
1581  // BOF: MOD - Ultimate SEO URLs - by Chemo

1582  // Funtion to reset SEO URLs database cache entries

1583    function tep_reset_cache_data_seo_urls($action){
1584      switch ($action){
1585        case 'reset':
1586          tep_db_query("DELETE FROM cache WHERE cache_name LIKE '%seo_urls%'");
1587          tep_db_query("UPDATE configuration SET configuration_value='false' WHERE configuration_key='SEO_URLS_CACHE_RESET'");
1588          break;
1589        default:
1590          break;
1591      }
1592      # The return value is used to set the value upon viewing

1593      # It's NOT returining a false to indicate failure!!

1594      return 'false';
1595    }
1596  // EOF: MOD - Ultimate SEO URLs - by Chemo

1597  
1598  // BOF: MOD - WebMakers.com Pull the shipping method used on an order

1599  // Return orders shipping method

1600    function tep_get_orders_shipping_method($order_id) {
1601      $check_order_query= tep_db_query("select title from " . TABLE_ORDERS_TOTAL . " where orders_id='" . $order_id . "' and class='ot_shipping'");
1602      $check_order= tep_db_fetch_array($check_order_query);
1603      if (SHOW_INVOICE_SHIPPING=='2' and ($check_order['title']=='United Parcel Service' or $check_order['title']=='United States Postal Service')) {
1604        // return short version on UPS and USPS

1605        $short_shipping_end= strpos($check_order['title'], '');
1606        $short_shipping= substr($check_order['title'], 1, $short_shipping_end);
1607        return $short_shipping;
1608      } else {
1609        // return normal shipping

1610        return $check_order['title'];
1611      }
1612    }
1613  // EOF: MOD - WebMakers.com Pull the shipping method used on an order

1614    // >>> BEGIN REGISTER_GLOBALS

1615    // Work-around functions to allow disabling of register_globals in php.ini

1616    // These functions perform a similar operation as the 'link_session_variable'

1617    // function added to .../functions/sessions.php but for the GET, POST, etc

1618    // variables

1619    //

1620    // Parameters:

1621    // var_name - Name of session variable

1622    //

1623    // Returns:

1624    // None

1625    function link_get_variable($var_name)
1626    {
1627      // Map global to GET variable

1628      if (isset($_GET[$var_name]))
1629      {
1630        $GLOBALS[$var_name] =& $_GET[$var_name];
1631      }
1632    }
1633  
1634    function link_post_variable($var_name)
1635    {
1636      // Map global to POST variable

1637      if (isset($_POST[$var_name]))
1638      {
1639        $GLOBALS[$var_name] =& $_POST[$var_name];
1640      }
1641    }
1642  // <<< END REGISTER_GLOBALS

1643  ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7