Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.72 KB | None | 0 0
  1. <?php
  2.  
  3. require_once("site_helpers.inc.php");
  4. require_localize();
  5.  
  6. class Filter {
  7.    
  8.     static $connection = null;
  9.  
  10.     static function GetConnection() {
  11.             if(self::$connection == null) {
  12.                     require_once("user.inc.php");
  13.                     self::$connection = helper_mysql_connect();
  14.             }
  15.             return self::$connection;
  16.     }
  17.  
  18.     /**
  19.      * Output options releated to category/brands etc.
  20.      */
  21.     static function GetFilterOptions($SortFilter, $brandIds, $categoryId, $suffixDB)
  22.     {
  23.             /**
  24.              * List Brands
  25.              */
  26.             if($SortFilter === 'brands')
  27.             {
  28.                         $brandIds = array_unique($brandIds);
  29.                         $query_brands = "SELECT
  30.                                                 maerke_id,
  31.                                                 overskrift
  32.                                             FROM
  33.                                                 shop_maerke
  34.                                             WHERE
  35.                                                 maerke_id IN (" . implode(',', $brandIds) . ")
  36.                                             AND
  37.                                                 status = 1 AND overskrift != ''
  38.                                             ORDER BY
  39.                                                 overskrift
  40.                                         ";
  41.                             $res_brands = mysql_query($query_brands,self::GetConnection());
  42.  
  43.                             $output .= '
  44.                             <div class="col-lg-4 col-md-6 col-sm-24 col-sm-24" style="margin:0;padding-left:3px;">
  45.                                     <p style="padding:0;margin:0; margin-top:10px;">
  46.                                         <strong>Mærke</strong>
  47.                                     </p>
  48.                                     <select multiple="multiple" name="brands" id="brands">';
  49.  
  50.                                         while($row = mysql_fetch_assoc($res_brands)){
  51.                                             $output .= '<option value="'. $row['maerke_id'] .'">'. ucfirst($row['overskrift']) .'</option>';
  52.                                         }
  53.                             $output .= '
  54.                                     </select>
  55.                             </div>';
  56.                 }
  57.  
  58.                 /**
  59.                  * List filter: Categories/Types
  60.                  */
  61.                 if($SortFilter === 'category_filters')
  62.                 {
  63.                     $query_filter = "SELECT
  64.                                                             sf.filterID,
  65.                                                             sf.navn_dk as filter_name
  66.                                                     FROM
  67.                                                             shop_filter sf
  68.                                                     INNER JOIN
  69.                                                             shop_filter_kategori sfk ON sfk.filterID = sf.filterID
  70.                                                     WHERE
  71.                                                             sfk.kategoriID = '$categoryId'
  72.                                                     AND
  73.                                                             sf.status = 1
  74.                                                     GROUP BY
  75.                                                             sf.filterID";
  76.                                                                
  77.                             $res_filter_cat = mysql_query($query_filter, self::GetConnection() );
  78.                             while ($category_filter = mysql_fetch_assoc($res_filter_cat))
  79.                             {
  80.                                     $filterID = (int) $category_filter['filterID'];
  81.  
  82.                                     $output .='
  83.                                     <div class="col-lg-4 col-md-6 col-sm-24 col-sm-24" style="margin:0;padding-left:3px;">
  84.                                         <p style="padding:0;margin:0; margin-top:10px;">
  85.                                             <strong>'. $category_filter['filter_name'] .'</strong>
  86.                                         </p>
  87.                                         <select multiple="multiple" name="'. str_replace(' ','',strtolower($category_filter['filter_name'])) .'">';
  88.  
  89.                                                 // List types
  90.                                                 $q_types = "SELECT
  91.                                                                             typeID,
  92.                                                                             navn_dk AS type_name
  93.                                                                         FROM
  94.                                                                             shop_filter_type
  95.                                                                         WHERE
  96.                                                                             filterID = ".$filterID."
  97.                                                                     ";
  98.                                                 $res_types = mysql_query($q_types, self::GetConnection());
  99.                                                 while ($types = mysql_fetch_assoc($res_types))
  100.                                                 {
  101.                                                         $output .= "<option value='".$types['typeID']."'>".  $types['type_name'] ."</option>";
  102.                                                 }
  103.  
  104.                                     $output .= "
  105.                                         </select>
  106.                                     </div>";
  107.                             }
  108.                 }
  109.  
  110.                 return $output;
  111.     }
  112.  
  113.     /**
  114.      * Display Price options
  115.      */
  116.     static function GetFilterPriceRange()
  117.     {
  118.             $output .= '
  119.                 <div class="col-lg-4 col-md-6 col-sm-24 col-sm-24" style="margin:0;padding-left:3px;">
  120.                         <p style="padding:0;margin:0;margin-top:10px;">
  121.                             <strong>Pris</strong>
  122.                         </p>
  123.                         <div id="sortby_price" style="width:100%!important;display:inline-block;">
  124.                                 <a href="javascript:void(0);" onclick="$.filters.ToggleSortbyPrice();" class="toogleClick">
  125.                                         Vælg
  126.                                 </a>
  127.                         </div>
  128.                         <div id="togglePriceRange">
  129.                             <div class="row">
  130.                                     <div class="col-md-12">
  131.                                             <div class="form-group">
  132.                                                     <div class="input-group">
  133.                                                             <div class="form-control example-val" id="lower-value"></div>
  134.                                                             <div class="input-group-addon">Kr</div>
  135.                                                     </div>
  136.                                             </div>
  137.                                     </div>
  138.                                     <div class="col-md-12">
  139.                                             <div class="form-group">
  140.                                                     <div class="input-group">
  141.                                                             <div class="form-control example-val" id="upper-value"></div>
  142.                                                             <div class="input-group-addon">Kr</div>
  143.                                                     </div>
  144.                                             </div>
  145.                                     </div>
  146.                                 </div>
  147.                                 <div style="width:95%;float:left;margin-left:8px;margin-top:5px!important">
  148.                                     <div id="nonlinear" class="priceRanger col-lg-24 noUi-target noUi-ltr noUi-horizontal noUi-background"></div>
  149.                                 </div>
  150.                         </div>
  151.                 </div>';
  152.  
  153.                 return $output;
  154.     }
  155.    
  156.     /**
  157.      * HTML setup for filterview
  158.      */
  159.     static function HTMLSetup($brandIds,$categoryId, $suffixDB)
  160.     {
  161.             global $content;
  162.  
  163.         /*
  164.             <div class="col-lg-4 col-md-6 col-sm-24 col-sm-24" style="margin:0;padding-left:3px;">
  165.                     <p style="padding:0;margin:0; margin-top:10px;">
  166.                         <strong>Køn</strong>
  167.                     </p>
  168.                     <select multiple="multiple" name="gender" id="gender">
  169.                         <option>Herre</option>
  170.                         <option>Kvinder</option>
  171.                     </select>
  172.             </div>
  173.             <div class="col-lg-4 col-md-6 col-sm-24 col-sm-24" style="margin:0;padding-left:3px;">
  174.                     <p style="padding:0;margin:0; margin-top:10px;">
  175.                         <strong>Farve</strong>
  176.                     </p>
  177.                     <select multiple="multiple" class="form-control FilterMultiple" name="colors" id="colors">
  178.                         <option>master_colorid shop_variant</option>
  179.                     </select>
  180.             </div>
  181.             <div class="col-lg-4 col-md-6 col-sm-24 col-sm-24" style="margin:0;padding-left:3px;">
  182.                     <p style="padding:0;margin:0; margin-top:10px;">
  183.                         <strong>Størrelse</strong>
  184.                     </p>
  185.                     <select multiple="multiple" class="form-control FilterMultiple" name="sizes" id="sizes">
  186.                         <option>Sizes</option>
  187.                     </select>
  188.             </div>
  189.         */
  190.                 $output .= '
  191.                 <div class="col-lg-18 col-md-24 col-sm-24 col-xs-24" style="padding:0;margin:0;">
  192.                         '. Filter::GetFilterOptions('brands',$brandIds,false,$suffixDB) .'
  193.                         '. Filter::GetFilterOptions('category_filters',false,$categoryId,$suffixDB) .'
  194.                         '. Filter::GetFilterPriceRange() .'
  195.                 </div>';
  196.  
  197.  
  198.                 /**
  199.                  * Load required script for generating multiple select
  200.                  */
  201.  
  202.                 $avoidCache = time();
  203.                 $content['head'] .= '<link href="/css/jquery.multiselect.css?t='.$avoidCache.'" rel="stylesheet">';
  204.                 $content['end_of_body'] .= '
  205.                 <script src="/js/filtersearch/jquery.multiselect.js?t='.$avoidCache.'"></script>
  206.                 <script src="/js/filtersearch/filter.js?t='.$avoidCache.'"></script>
  207.                 <script >
  208.                     $(\'select[multiple]\').multiselect({
  209.                             columns: 3
  210.                     });
  211.                 </script>';
  212.  
  213.             return $output;
  214.     }
  215.  
  216. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement