[ PHPXref.com ] [ Generated: Sun Jul 20 19:13:40 2008 ] [ osCommRes 1.2.0 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/includes/functions/ -> faqdesk_general.php (source)

   1  <?php
   2  /*

   3  

   4    osCommerce, Open Source E-Commerce Solutions

   5    http://www.oscommerce.com

   6  

   7    Copyright (c) 2003 osCommerce

   8    

   9    osCommRes, Services Online

  10    http://www.oscommres.com

  11  

  12    Copyright (c) 2005 osCommRes

  13  

  14    Released under the GNU General Public License

  15  */
  16  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

  17  // Generate a path to categories

  18  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

  19  function faqdesk_get_path($current_category_id = '') {
  20  global $faqPath_array;
  21  
  22  if ($current_category_id) {
  23      $cp_size = sizeof($faqPath_array);
  24      if ($cp_size == 0) {
  25          $faqPath_new = $current_category_id;
  26      } else {
  27          $faqPath_new = '';
  28          $last_category_query = tep_db_query("select parent_id from " . TABLE_FAQDESK_CATEGORIES . " where categories_id = '" . $faqPath_array[($cp_size-1)] . "'");
  29          $last_category = tep_db_fetch_array($last_category_query);
  30          $current_category_query = tep_db_query("select parent_id from " . TABLE_FAQDESK_CATEGORIES . " where categories_id = '" . $current_category_id . "'");
  31          $current_category = tep_db_fetch_array($current_category_query);
  32          if ($last_category['parent_id'] == $current_category['parent_id']) {
  33              for ($i=0; $i<($cp_size-1); $i++) {
  34                  $faqPath_new .= '_' . $faqPath_array[$i];
  35              }
  36          } else {
  37              for ($i=0; $i<$cp_size; $i++) {
  38                  $faqPath_new .= '_' . $faqPath_array[$i];
  39              }
  40          }
  41          $faqPath_new .= '_' . $current_category_id;
  42          if (substr($faqPath_new, 0, 1) == '_') {
  43              $faqPath_new = substr($faqPath_new, 1);
  44          }
  45      }
  46  } else {
  47      $faqPath_new = implode('_', $faqPath_array);
  48  }
  49  
  50  return 'faqPath=' . $faqPath_new;
  51  
  52  }
  53  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

  54  
  55  
  56  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

  57  // Parse and secure the faqPath parameter values

  58  function faqdesk_parse_category_path($faqPath) {
  59  // make sure the category IDs are integers

  60  $faqPath_array = array_map('tep_string_to_int', explode('_', $faqPath));
  61  
  62  // make sure no duplicate category IDs exist which could lock the server in a loop

  63  $tmp_array = array();
  64  $n = sizeof($faqPath_array);
  65  for ($i=0; $i<$n; $i++) {
  66      if (!in_array($faqPath_array[$i], $tmp_array)) {
  67          $tmp_array[] = $faqPath_array[$i];
  68      }
  69  }
  70  
  71  return $tmp_array;
  72  
  73  }
  74  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

  75  
  76  
  77  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

  78  // Return true if the category has subcategories

  79  // TABLES: categories

  80  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

  81  function faqdesk_has_category_subcategories($category_id) {
  82  $child_category_query = tep_db_query("select count(*) as count from " . TABLE_FAQDESK_CATEGORIES . " where parent_id = '" . $category_id . "'");
  83  $child_category = tep_db_fetch_array($child_category_query);
  84  
  85  if ($child_category['count'] > 0) {
  86      return true;
  87  } else {
  88      return false;
  89  }
  90  
  91  }
  92  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

  93  
  94  
  95  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

  96  // Construct a category path to the product

  97  // TABLES: products_to_categories

  98  function faqdesk_get_product_path($faqdesk_id) {
  99  $faqPath = '';
 100  
 101  $cat_count_sql = tep_db_query("select count(*) as count from " . TABLE_FAQDESK_TO_CATEGORIES . " where faqdesk_id = '" . $faqdesk_id . "'");
 102  $cat_count_data = tep_db_fetch_array($cat_count_sql);
 103  
 104  if ($cat_count_data['count'] == 1) {
 105      $categories = array();
 106  
 107      $cat_id_sql = tep_db_query("select categories_id from " . TABLE_FAQDESK_TO_CATEGORIES . " where faqdesk_id = '" . $faqdesk_id . "'");
 108      $cat_id_data = tep_db_fetch_array($cat_id_sql);
 109      faqdesk_get_parent_categories($categories, $cat_id_data['categories_id']);
 110  
 111      $size = sizeof($categories)-1;
 112      for ($i = $size; $i >= 0; $i--) {
 113          if ($faqPath != '') $faqPath .= '_';
 114              $faqPath .= $categories[$i];
 115      }
 116      if ($faqPath != '') $faqPath .= '_';
 117          $faqPath .= $cat_id_data['categories_id'];
 118  }
 119  
 120  return $faqPath;
 121  
 122  }
 123  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

 124  
 125  
 126  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

 127  // Recursively go through the categories and retreive all parent categories IDs

 128  // TABLES: categories

 129  function faqdesk_get_parent_categories(&$categories, $categories_id) {
 130  $parent_categories_query = tep_db_query("select parent_id from " . TABLE_FAQDESK_CATEGORIES . " where categories_id = '" . $categories_id . "'");
 131  
 132  while ($parent_categories = tep_db_fetch_array($parent_categories_query)) {
 133      if ($parent_categories['parent_id'] == 0) return true;
 134          $categories[sizeof($categories)] = $parent_categories['parent_id'];
 135          if ($parent_categories['parent_id'] != $categories_id) {
 136              faqdesk_get_parent_categories($categories, $parent_categories['parent_id']);
 137          }
 138      }
 139  }
 140  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

 141  
 142  
 143  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

 144  function faqdesk_get_categories($categories_array = '', $parent_id = '0', $indent = '') {
 145  global $languages_id;
 146  
 147  $parent_id = tep_db_prepare_input($parent_id);
 148  
 149  if (!is_array($categories_array)) $categories_array = array();
 150  
 151  $categories_query = tep_db_query(
 152  "select c.categories_id, cd.categories_name from " . TABLE_FAQDESK_CATEGORIES . " c, " . TABLE_FAQDESK_CATEGORIES_DESCRIPTION . " 
 153  cd where c.catagory_status = '1' and parent_id = '" . tep_db_input($parent_id) . "' and c.categories_id = cd.categories_id and cd.language_id = '" 
 154  . $languages_id . "' order by sort_order, cd.categories_name"
 155  );
 156  
 157  while ($categories = tep_db_fetch_array($categories_query)) {
 158      $categories_array[] = array(
 159          'id' => $categories['categories_id'],
 160          'text' => $indent . $categories['categories_name']
 161      );
 162  
 163      if ($categories['categories_id'] != $parent_id) {
 164          $categories_array = faqdesk_get_categories($categories_array, $categories['categories_id'], $indent . '&nbsp;&nbsp;');
 165      }
 166  }
 167  
 168  return $categories_array;
 169  }
 170  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

 171  
 172  
 173  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

 174  // Return all subcategory IDs

 175  // TABLES: categories

 176  function faqdesk_get_subcategories(&$subcategories_array, $parent_id = 0) {
 177  $subcategories_query = tep_db_query("select categories_id from " . TABLE_FAQDESK_CATEGORIES . " where parent_id = '" . $parent_id . "'");
 178  
 179  while ($subcategories = tep_db_fetch_array($subcategories_query)) {
 180      $subcategories_array[sizeof($subcategories_array)] = $subcategories['categories_id'];
 181      if ($subcategories['categories_id'] != $parent_id) {
 182          faqdesk_get_subcategories($subcategories_array, $subcategories['categories_id']);
 183      }
 184  }
 185  
 186  }
 187  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

 188  
 189  /*

 190  

 191      osCommerce, Open Source E-Commerce Solutions ---- http://www.oscommerce.com

 192      Copyright (c) 2002 osCommerce

 193      Released under the GNU General Public License

 194  

 195      IMPORTANT NOTE:

 196  

 197      This script is not part of the official osC distribution but an add-on contributed to the osC community.

 198      Please read the NOTE and INSTALL documents that are provided with this file for further information and installation notes.

 199  

 200      script name:    FaqDesk

 201      version:        1.2.5

 202      date:            2003-09-01

 203      author:            Carsten aka moyashi

 204      web site:        www..com

 205  

 206  */
 207  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]