/includes/index_filters/music_genre_filter.php

https://github.com/ZenMagick/zc-base · PHP · 219 lines · 195 code · 2 blank · 22 comment · 45 complexity · f399dd66247a4fdad7822fdeb5b5e22c MD5 · raw file

  1. <?php
  2. /**
  3. * music_genre_filter.php for index filters
  4. *
  5. * index filter for the music product type
  6. * show the products of a specified music_genre
  7. *
  8. * @package productTypes
  9. * @copyright Copyright 2003-2010 Zen Cart Development Team
  10. * @copyright Portions Copyright 2003 osCommerce
  11. * @todo Need to add/fine-tune ability to override or insert entry-points on a per-product-type basis
  12. * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
  13. * @version $Id: music_genre_filter.php 15628 2010-03-07 01:21:55Z drbyte $
  14. */
  15. if (!defined('IS_ADMIN_FLAG')) {
  16. die('Illegal Access');
  17. }
  18. if (isset($_GET['sort']) && strlen($_GET['sort']) > 3) {
  19. $_GET['sort'] = substr($_GET['sort'], 0, 3);
  20. }
  21. if (isset($_GET['alpha_filter_id']) && (int)$_GET['alpha_filter_id'] > 0) {
  22. $alpha_sort = " and pd.products_name LIKE '" . chr((int)$_GET['alpha_filter_id']) . "%' ";
  23. } else {
  24. $alpha_sort = '';
  25. }
  26. if (!isset($select_column_list)) $select_column_list = "";
  27. // show the products of a specified music_genre
  28. if (isset($_GET['music_genre_id']))
  29. {
  30. if (isset($_GET['filter_id']) && zen_not_null($_GET['filter_id']))
  31. {
  32. // We are asked to show only a specific category
  33. $listing_sql = "select " . $select_column_list . " p.products_id, p.products_type, p.master_categories_id, p.products_price, p.products_tax_class_id, pd.products_description, if(s.status = 1, s.specials_new_products_price, NULL) AS specials_new_products_price, IF(s.status = 1, s.specials_new_products_price, p.products_price) as final_price, p.products_sort_order, p.product_is_call, p.product_is_always_free_shipping, p.products_qty_box_status
  34. from " . TABLE_PRODUCTS . " p, " .
  35. TABLE_PRODUCTS_DESCRIPTION . " pd, " .
  36. TABLE_PRODUCT_MUSIC_EXTRA . " pme left join " . TABLE_SPECIALS . " s on pme.products_id = s.products_id, " .
  37. TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " .
  38. TABLE_MUSIC_GENRE . " m
  39. where m.music_genre_id = '" . (int)$_GET['music_genre_id'] . "'
  40. and p.products_id = pme.products_id
  41. and p.products_status = 1
  42. and pme.music_genre_id = m.music_genre_id
  43. and pme.products_id = p2c.products_id
  44. and pd.products_id = p2c.products_id
  45. and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
  46. and p2c.categories_id = '" . (int)$_GET['filter_id'] . "'" .
  47. $alpha_sort;
  48. } else {
  49. // We show them all
  50. $listing_sql = "select " . $select_column_list . " pme.products_id, p.products_type, p.master_categories_id, p.products_price, p.products_tax_class_id, pd.products_description, IF(s.status = 1, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status = 1, s.specials_new_products_price, p.products_price) as final_price, p.products_sort_order, p.product_is_call, p.product_is_always_free_shipping, p.products_qty_box_status
  51. from " . TABLE_PRODUCTS . " p, " .
  52. TABLE_PRODUCTS_DESCRIPTION . " pd, " .
  53. TABLE_PRODUCT_MUSIC_EXTRA . " pme left join " . TABLE_SPECIALS . " s on pme.products_id = s.products_id, " .
  54. TABLE_MUSIC_GENRE . " m
  55. where m.music_genre_id = '" . (int)$_GET['music_genre_id'] . "'
  56. and p.products_id = pme.products_id
  57. and p.products_status = 1
  58. and pd.products_id = pme.products_id
  59. and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
  60. and pme.music_genre_id = m.music_genre_id" .
  61. $alpha_sort;
  62. }
  63. } else {
  64. // show the products in a given category
  65. if (isset($_GET['filter_id']) && zen_not_null($_GET['filter_id']))
  66. {
  67. // We are asked to show only specific category
  68. $listing_sql = "select " . $select_column_list . " p.products_id, p.products_type, p.master_categories_id, m.music_genre_id, p.products_price, p.products_tax_class_id, pd.products_description, IF(s.status = 1, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status = 1, s.specials_new_products_price, p.products_price) as final_price, p.products_sort_order, p.product_is_call, p.product_is_always_free_shipping, p.products_qty_box_status
  69. from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " .
  70. TABLE_PRODUCTS_DESCRIPTION . " pd, " .
  71. TABLE_MUSIC_GENRE . " m, " .
  72. TABLE_PRODUCT_MUSIC_EXTRA . " pme, " .
  73. TABLE_PRODUCTS_TO_CATEGORIES . " p2c
  74. where p.products_status = 1
  75. and pme.music_genre_id = m.music_genre_id
  76. and m.music_genre_id = '" . (int)$_GET['filter_id'] . "'
  77. and p.products_id = p2c.products_id
  78. and pd.products_id = p2c.products_id
  79. and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
  80. and p2c.categories_id = '" . (int)$current_category_id . "'" .
  81. $alpha_sort;
  82. } else {
  83. // We show them all
  84. if ($current_categories_id) {
  85. $listing_sql = "select " . $select_column_list . " p.products_id, p.products_type, p.master_categories_id, m.music_genre_id, p.products_price, p.products_tax_class_id, pd.products_description, IF(s.status = 1, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status = 1, s.specials_new_products_price, p.products_price) as final_price, p.products_sort_order, p.product_is_call, p.product_is_always_free_shipping, p.products_qty_box_status
  86. from " . TABLE_PRODUCTS . " p, " .
  87. TABLE_PRODUCTS_DESCRIPTION . " pd, " .
  88. TABLE_PRODUCT_MUSIC_EXTRA . " pme left join " . TABLE_SPECIALS . " s on pme.products_id = s.products_id, " .
  89. TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " .
  90. TABLE_MUSIC_GENRE . " m
  91. where m.music_genre_id = pme.music_genre_id
  92. and p.products_id = pme.products_id
  93. and p.products_status = 1
  94. and pd.products_id = pme.products_id
  95. and p2c.products_id = p.products_id
  96. and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
  97. and p2c.categories_id = '" . (int)$current_category_id . "'" .
  98. $alpha_sort;
  99. } else {
  100. $listing_sql = "select " . $select_column_list . " p.products_id, p.products_type, p.master_categories_id, m.music_genre_id, p.products_price, p.products_tax_class_id, pd.products_description, IF(s.status = 1, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status = 1, s.specials_new_products_price, p.products_price) as final_price, p.products_sort_order, p.product_is_call, p.product_is_always_free_shipping, p.products_qty_box_status
  101. from " . TABLE_PRODUCTS . " p, " .
  102. TABLE_PRODUCTS_DESCRIPTION . " pd, " .
  103. TABLE_PRODUCT_MUSIC_EXTRA . " pme left join " . TABLE_SPECIALS . " s on pme.products_id = s.products_id, " .
  104. TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " .
  105. TABLE_MUSIC_GENRE . " m
  106. where m.music_genre_id = pme.music_genre_id
  107. and p.products_id = pme.products_id
  108. and p.products_status = 1
  109. and pd.products_id = pme.products_id
  110. and p2c.products_id = p.products_id
  111. and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'" .
  112. $alpha_sort;
  113. }
  114. }
  115. }
  116. // set the default sort order setting from the Admin when not defined by customer
  117. if (!isset($_GET['sort']) and PRODUCT_LISTING_DEFAULT_SORT_ORDER != '') {
  118. $_GET['sort'] = PRODUCT_LISTING_DEFAULT_SORT_ORDER;
  119. }
  120. $listing_sql = str_replace('m.manufacturers_name', 'm.music_genre_name as manufacturers_name', $listing_sql);
  121. if (isset($column_list)) {
  122. if ( (!isset($_GET['sort'])) || (isset($_GET['sort']) && !preg_match('/[1-8][ad]/', $_GET['sort'])) || (substr($_GET['sort'], 0, 1) > sizeof($column_list)) )
  123. {
  124. for ($i=0, $n=sizeof($column_list); $i<$n; $i++)
  125. {
  126. if ($column_list[$i] == 'PRODUCT_LIST_NAME')
  127. {
  128. $_GET['sort'] = $i+1 . 'a';
  129. $listing_sql .= " order by p.products_sort_order, pd.products_name";
  130. break;
  131. }
  132. }
  133. // if set to nothing use products_sort_order and PRODUCTS_LIST_NAME is off
  134. if (PRODUCT_LISTING_DEFAULT_SORT_ORDER == '') {
  135. $_GET['sort'] = '20a';
  136. }
  137. } else {
  138. $sort_col = substr($_GET['sort'], 0 , 1);
  139. $sort_order = substr($_GET['sort'], 1);
  140. switch ($column_list[$sort_col-1])
  141. {
  142. case 'PRODUCT_LIST_MODEL':
  143. $listing_sql .= " order by p.products_model " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
  144. break;
  145. case 'PRODUCT_LIST_NAME':
  146. $listing_sql .= " order by pd.products_name " . ($sort_order == 'd' ? 'desc' : '');
  147. break;
  148. case 'PRODUCT_LIST_MANUFACTURER':
  149. $listing_sql .= " order by m.music_genre_name " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
  150. break;
  151. case 'PRODUCT_LIST_QUANTITY':
  152. $listing_sql .= " order by p.products_quantity " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
  153. break;
  154. case 'PRODUCT_LIST_IMAGE':
  155. $listing_sql .= " order by pd.products_name";
  156. break;
  157. case 'PRODUCT_LIST_WEIGHT':
  158. $listing_sql .= " order by p.products_weight " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
  159. break;
  160. case 'PRODUCT_LIST_PRICE':
  161. $listing_sql .= " order by p.products_price_sorter " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
  162. break;
  163. }
  164. }
  165. }
  166. // optional Product List Filter
  167. if (PRODUCT_LIST_FILTER > 0)
  168. {
  169. if (isset($_GET['music_genre_id']))
  170. {
  171. $filterlist_sql = "select distinct c.categories_id as id, cd.categories_name as name
  172. from " . TABLE_PRODUCTS . " p, " .
  173. TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " .
  174. TABLE_CATEGORIES . " c, " .
  175. TABLE_CATEGORIES_DESCRIPTION . " cd, " .
  176. TABLE_PRODUCT_MUSIC_EXTRA . " pme
  177. where p.products_status = 1
  178. and pme.products_id = p2c.products_id
  179. and p.products_id = p2c.products_id
  180. and p2c.categories_id = c.categories_id
  181. and p2c.categories_id = cd.categories_id
  182. and cd.language_id = '" . (int)$_SESSION['languages_id'] . "'
  183. and pme.music_genre_id = '" . (int)$_GET['music_genre_id'] . "'
  184. order by cd.categories_name";
  185. } else {
  186. $filterlist_sql= "select distinct m.music_genre_id as id, m.music_genre_name as name
  187. from " . TABLE_PRODUCTS . " p, " .
  188. TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " .
  189. TABLE_PRODUCT_MUSIC_EXTRA . " pme, " .
  190. TABLE_MUSIC_GENRE . " m
  191. where p.products_status = 1
  192. and pme.music_genre_id = m.music_genre_id
  193. and p.products_id = p2c.products_id
  194. and pme.products_id = p.products_id
  195. and p2c.categories_id = '" . (int)$current_category_id . "'
  196. order by m.music_genre_name";
  197. }
  198. $getoption_set = false;
  199. $filterlist = $db->Execute($filterlist_sql);
  200. $do_filter_list = false;
  201. if ($filterlist->RecordCount() > 1)
  202. {
  203. $do_filter_list = true;
  204. if (isset($_GET['music_genre_id']))
  205. {
  206. $getoption_set = true;
  207. $get_option_variable = 'music_genre_id';
  208. $options = array(array('id' => '', 'text' => TEXT_ALL_CATEGORIES));
  209. } else {
  210. $options = array(array('id' => '', 'text' => TEXT_ALL_MUSIC_GENRE));
  211. }
  212. while (!$filterlist->EOF) {
  213. $options[] = array('id' => $filterlist->fields['id'], 'text' => $filterlist->fields['name']);
  214. $filterlist->MoveNext();
  215. }
  216. }
  217. }