[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/admin/order_editor/ -> functions.php (source)

   1  <?php
   2  /*
   3   $Id: functions.php v5.0 07/19/2007 djmonkey1 Exp $
   4  
   5    osCommerce, Open Source E-Commerce Solutions
   6    http://www.oscommerce.com
   7  
   8    Copyright (c) 2003 osCommerce
   9  
  10    Released under the GNU General Public License
  11  */
  12  
  13  
  14    // Function to change quotes to HTML equivalents for form inputs
  15    function oe_html_quotes($string) {
  16      return str_replace("'", "&#39;", $string);
  17      
  18    }
  19  
  20    ///originally written by Josh Dechant for the MOECTOE suite
  21    ///tweaked by djmonkey1 for Order Editor 2.7 and up   
  22    function oe_js_zone_list($country, $form, $field, $id, $id2) {
  23      $countries_query = tep_db_query("select distinct zone_country_id from " . TABLE_ZONES . " order by zone_country_id");
  24      $num_country = 1;
  25      $output_string = '';
  26      while ($countries = tep_db_fetch_array($countries_query)) {
  27        if ($num_country == 1) {
  28          $output_string .= '  if (' . $country . ' == "' . $countries['zone_country_id'] . '") {' . "\n";
  29        } else {
  30          $output_string .= '  } else if (' . $country . ' == "' . $countries['zone_country_id'] . '") {' . "\n";
  31        }
  32  
  33        $states_query = tep_db_query("select zone_name, zone_id from " . TABLE_ZONES . " where zone_country_id = '" . $countries['zone_country_id'] . "' order by zone_name");
  34  
  35        $num_state = 1;
  36        while ($states = tep_db_fetch_array($states_query)) {
  37          if ($num_state == '1') $output_string .= '    ' . $form . '[' . $field . '].options[0] = new Option("' . PLEASE_SELECT . '", "");' . "\n";
  38          $output_string .= '    ' . $form . '[' . $field . '].options[' . $num_state . '] = new Option("' . $states['zone_name'] . '", "' . $states['zone_id'] . '");' . "\n";
  39          $num_state++;
  40        }
  41        $output_string .= '    setStateVisibility(' . $id . ', "hidden", ' . $id2 . ');' . "\n";
  42        $num_country++;
  43      }
  44      $output_string .= '  } else {' . "\n" .
  45                        '    ' . $form . '[' . $field . '].options[0] = new Option("' . ENTRY_TYPE_BELOW . '", "");' . "\n" .
  46                        '    setStateVisibility(' . $id . ', "visible", ' . $id2 . ');' . "\n" . 
  47                        '  }' . "\n";
  48  
  49      return $output_string;
  50    }
  51   
  52  
  53      // Return the tax description for a zone / class
  54      //kept the tep_ prefix here as the Low Order Fee module uses this function 
  55    function tep_get_tax_description($class_id, $country_id, $zone_id) {
  56      $tax_query = tep_db_query("select tax_description 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 . "' order by tr.tax_priority");
  57      if (tep_db_num_rows($tax_query)) {
  58        $tax_description = '';
  59        while ($tax = tep_db_fetch_array($tax_query)) {
  60          $tax_description .= $tax['tax_description'] . ' + ';
  61        }
  62        $tax_description = substr($tax_description, 0, -3);
  63  
  64        return $tax_description;
  65      } else {
  66        return ENTRY_TAX;
  67      }
  68    }
  69    
  70    
  71    function oe_get_country_id($country_name) {
  72      $country_id_query = tep_db_query("select countries_id from " . TABLE_COUNTRIES . " where countries_name = '" . $country_name . "'");
  73      if (!tep_db_num_rows($country_id_query)) {
  74        return false;
  75      }
  76      else {
  77        $country_id_row = tep_db_fetch_array($country_id_query);
  78        return $country_id_row['countries_id'];
  79      }
  80    }
  81    
  82    function oe_get_country_iso_code_2($country_id) {
  83      $country_iso_query = tep_db_query("select countries_iso_code_2 from " . TABLE_COUNTRIES . " where countries_id = '" . (int)$country_id . "'");
  84      if (!tep_db_num_rows($country_iso_query)) {
  85        return false;
  86      } else {
  87        $country_iso_row = tep_db_fetch_array($country_iso_query);
  88        return $country_iso_row['countries_iso_code_2'];
  89      }
  90    }
  91  
  92    function oe_get_country_iso_code_3($country_id) {
  93      $country_iso_query = tep_db_query("select countries_iso_code_3 from " . TABLE_COUNTRIES . " where countries_id = '" . (int)$country_id . "'");
  94      if (!tep_db_num_rows($country_iso_query)) {
  95        return false;
  96      } else {
  97        $country_iso_row = tep_db_fetch_array($country_iso_query);
  98        return $country_iso_row['countries_iso_code_3'];
  99      }
 100    }
 101  
 102    function oe_get_zone_id($country_id, $zone_name) {
 103      $zone_id_query = tep_db_query("select zone_id from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country_id . "' and (zone_name = '" . $zone_name . "' OR zone_code = '" . $zone_name . "')");
 104      if (!tep_db_num_rows($zone_id_query)) {
 105        return false;
 106      }
 107      else {
 108        $zone_id_row = tep_db_fetch_array($zone_id_query);
 109        return $zone_id_row['zone_id'];
 110      }
 111    }
 112    
 113   
 114    //Used to workaround problems associated with apostrophes, double quotes, and line breaks 
 115    function oe_html_no_quote($string) {
 116    $string=str_replace('&#39;', '', $string);
 117    $string=str_replace("'", "", $string);
 118    $string=str_replace('"', '', $string);
 119    $string=preg_replace("/\\r\\n|\\n|\\r/", "<BR>", $string); 
 120    return $string;
 121      
 122    }
 123  
 124  
 125   // Output a selection field - alias function for oe_draw_checkbox_field() and oe_draw_radio_field()
 126   //I had to draw up custom functions in order to pass parameters with checkbox fields, maybe radio fields too someday
 127    function oe_draw_selection_field($name, $type, $value = '', $checked = false, $compare = '', $parameters = '') {
 128      $selection = '<input type="' . tep_output_string($type) . '" name="' . tep_output_string($name) . '"';
 129  
 130      if (tep_not_null($value)) $selection .= ' value="' . tep_output_string($value) . '"';
 131      
 132      if (tep_not_null($parameters)) $selection .=  ' ' . $parameters;
 133  
 134  
 135      if ( ($checked == true) || (isset($GLOBALS[$name]) && is_string($GLOBALS[$name]) && ($GLOBALS[$name] == 'on')) || (isset($value) && isset($GLOBALS[$name]) && (stripslashes($GLOBALS[$name]) == $value)) || (tep_not_null($value) && tep_not_null($compare) && ($value == $compare)) ) {
 136        $selection .= ' CHECKED';
 137      }
 138  
 139      $selection .= '>';
 140  
 141      return $selection;
 142    }
 143  
 144  ////
 145  // Output a form checkbox field
 146    function oe_draw_checkbox_field($name, $value = '', $checked = false, $compare = '', $parameters = '') {
 147      return oe_draw_selection_field($name, 'checkbox', $value, $checked, $compare, $parameters);
 148    }
 149  
 150  ////
 151  // Output a form radio field
 152    function oe_draw_oe_radio_field($name, $value = '', $checked = false, $compare = '', $parameters = '') {
 153      return or_draw_selection_field($name, 'radio', $value, $checked, $compare, $parameters);
 154    }
 155  
 156  ////
 157  
 158    function oe_get_subcategories(&$subcategories_array, $parent_id = 0) {
 159      $subcategories_query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$parent_id . "'");
 160      while ($subcategories = tep_db_fetch_array($subcategories_query)) {
 161        $subcategories_array[sizeof($subcategories_array)] = $subcategories['categories_id'];
 162        if ($subcategories['categories_id'] != $parent_id) {
 163          oe_get_subcategories($subcategories_array, $subcategories['categories_id']);
 164        }
 165      }
 166    }
 167  
 168    function oe_select_ot_options($key_value, $key = 'ORDER_EDITOR_ALLOWED_OT_MODULES') {
 169      //$required_ot_totals = oe_required_ot();
 170      $installed_ot_modules = explode(';', MODULE_ORDER_TOTAL_INSTALLED);
 171      $return_string = '';
 172      reset($installed_ot_modules);
 173      $i=0;
 174      while (list(, $value) = each($installed_ot_modules)) {
 175        $ot_class = substr($value, 0, strrpos($value, '.'));
 176        //if (in_array($ot_class, $required_ot_totals)) continue;
 177        
 178        $name = (($key) ? 'configuration[' . $key . '][' . $i . ']' : 'configuration_value');
 179        $return_string .= '<br><input type="checkbox" name="' . $name . '" value="' . $ot_class . '"';
 180        $key_values = explode(", ", $key_value);
 181        if (in_array($ot_class, $key_values)) $return_string .= ' checked="checked"';
 182        $return_string .= '> ' . $ot_class;
 183        $i++;
 184      }  
 185    
 186      return $return_string;
 187    }
 188    
 189    function oe_generate_search_SQL($keywords_array, $fields_array, $search_type='OR') {
 190      $search_string = '';
 191      $end_trim = 0;
 192      
 193      switch ($search_type) {
 194        case 'OR': 
 195        case 'AND':
 196          $end_trim = strlen($search_type)+2;
 197          foreach($fields_array as $field) {
 198            foreach($keywords_array as $keyword) {
 199              $search_string .= "$field like '%$keyword%' $search_type ";
 200            }
 201          }
 202          break;
 203      
 204        case '(OR)AND':
 205          $end_trim = 5;
 206          foreach($fields_array as $field) {
 207            $search_string .= '(';
 208            foreach($keywords_array as $keyword) {
 209              $search_string .= "$field like '%$keyword%' OR ";
 210            }          
 211            $search_string = substr($search_string, 0, -4);          
 212            $search_string .= ') AND ';
 213            $end_trim = 5;
 214          }
 215          break;
 216  
 217        case '()OR':
 218          $end_trim = 4;
 219          foreach($fields_array as $field) {
 220            $search_string .= '(';
 221            
 222            if ($keywords_array) {
 223              foreach($keywords_array as $keyword) {
 224                $search_string .= "$field like '%$keyword%' OR ";
 225              }
 226            } else {
 227              $search_string .= $field;
 228            }
 229            
 230            $search_string .= ') OR ';
 231          }
 232          break;
 233  
 234      }   
 235      
 236      return substr($search_string, 0, -$end_trim);
 237    }
 238    
 239    function oe_clean_SQL_keywords($keywords_array) {
 240      $new_keywords_array = array();
 241  
 242      foreach($keywords_array as $keyword) {
 243        $keyword = ereg_replace("(,)|('s)", "", $keyword);
 244        $new_keywords_array[] = $keyword;
 245      }
 246      
 247      return $new_keywords_array;
 248    }
 249    
 250    function oe_iconv($string) {
 251      if (function_exists('iconv')) {
 252         return iconv('UTF-8', CHARSET . '//TRANSLIT', $string);
 253          } else {
 254        return $string;
 255      }
 256    }
 257  ?>


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