Tsimi

filter_printer_products.php

Dec 4th, 2015
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.32 KB | None | 0 0
  1. <?php
  2. /*
  3.    Parts Filter
  4.    
  5.    Bootstrapped by Tsimi - December 2015
  6.    
  7.    osCommerce, Open Source E-Commerce Solutions
  8.    http://www.oscommerce.com
  9.    Copyright (c) 2015 osCommerce
  10.    Released under the GNU General Public License
  11. */
  12.  
  13. require('includes/application_top.php');
  14.  
  15.  $printer_category_id = $_REQUEST['printer_category_id'];
  16.  $parent_id = $_REQUEST['parent_id'];
  17.  
  18.  if(isset($_REQUEST['printer_category_id'])&&($_REQUEST['printer_category_id']!='')) {
  19.     $vehcat_query = tep_db_query("SELECT * FROM ".TABLE_PRINTER_CATEGORY." WHERE printer_category_id = '".$_REQUEST['printer_category_id']."'");
  20.     $vehcat_row = tep_db_fetch_array($vehcat_query);
  21.  }
  22.  
  23.  $action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');
  24.  
  25. // Ultimate SEO URLs v2.1
  26. // If the action will affect the cache entries
  27.     if ( preg_match("(insert|update|setflag)", $action) ) include_once('includes/reset_seo_cache.php');
  28.  
  29.   if (tep_not_null($action)) {
  30.     switch ($action) {
  31.      case 'assign_products':
  32.         $productids = "";
  33.        // $mediacat_ref_no = "";
  34.        // $mediacat_quantity = "";
  35.         $selvalarray = array();
  36.         $pagearray = array();
  37.         $remproductarray = array();
  38.  
  39.         //$products_query_raw = 'select distinct p.products_id, p.products_model, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, p.products_id, p.products_mediacat_ref_no, p.products_mediacat_quantity from '.TABLE_PRODUCTS.' p, '.TABLE_PRODUCTS_DESCRIPTION.' pd,  '.TABLE_PRINTER_CATEGORY.' pc where p.products_id = pd.products_id and p.products_id = pc.printer_category_id and pd.language_id = "'.(int)$languages_id.'" and pc.printer_category_id = "'.(int)$printer_category_id.'" order by pd.products_id asc';
  40.         // working original query
  41.         $products_query_raw = 'select distinct p.products_id, p.products_model, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, p.products_id from '.TABLE_PRODUCTS.' p, '.TABLE_PRODUCTS_DESCRIPTION.' pd, '.TABLE_PRINTER_CATEGORY.' pc where p.products_id = pd.products_id and pd.language_id = "'.(int)$languages_id.'" and pc.printer_category_id = "'.$printer_category_id.'" order by pd.products_name asc';
  42.        
  43.         $products_query = tep_db_query($products_query_raw);
  44.         $products_split = new splitPageResults($_REQUEST['page'], MAX_DISPLAY_SEARCH_RESULTS, $products_query_raw, $products_query_numrows);
  45.         $products_query = tep_db_query($products_query_raw);
  46.  
  47.         while ($products = tep_db_fetch_array($products_query)) {
  48.             array_push($pagearray,$products['products_id']);
  49.         }
  50.  
  51.         if(isset($HTTP_POST_VARS['productids'])) {
  52.             foreach($HTTP_POST_VARS['productids'] as $val) {
  53.                 if($val!='') {
  54.                     array_push($selvalarray,$val);
  55.                     $productids .= $val.",";
  56.                 }
  57.             }
  58.         }
  59.  
  60.         foreach($pagearray as $val) {
  61.          if(!in_array($val,$selvalarray)) {
  62.           array_push($remproductarray,$val);
  63.          }
  64.         }
  65.  
  66.         $olderdata = $vehcat_row['productids'];
  67.  
  68.         $finaldata = "";
  69.         if($olderdata!='') {
  70.              $oldprodarray = explode(",",$olderdata);
  71.              foreach($oldprodarray as $val) {
  72.                     if(!in_array($val,$remproductarray)) {
  73.                         if(!in_array($val,$selvalarray)) {
  74.                          array_push($selvalarray,$val);
  75.                         }
  76.                    }
  77.              }
  78.  
  79.             $productids = "";
  80.             foreach($selvalarray as $val) {
  81.               $productids .= $val.",";
  82.             }
  83.               $finaldata = substr($productids,0,-1);
  84.         } else {
  85.           $finaldata = substr($productids,0,-1);
  86.         }
  87.  
  88.         $update_sql_data = array('productids' => $finaldata);
  89.  
  90.         tep_db_perform(TABLE_PRINTER_CATEGORY, $update_sql_data, 'update', "printer_category_id = '" . (int)$printer_category_id . "'");
  91.         tep_redirect(tep_href_link(FILENAME_PRINTER_PRODUCTS, 'parent_id=' . $parent_id.'&printer_category_id='.$printer_category_id.'&page='.$_REQUEST['page'] ));
  92.         break;
  93.  
  94.     }
  95.   }
  96.  
  97.   require(DIR_WS_INCLUDES . 'template_top.php');
  98.  
  99.   $vehcat_query = tep_db_query("SELECT * FROM ".TABLE_PRINTER_CATEGORY." WHERE printer_category_id = '".$_REQUEST['printer_category_id']."'");
  100.   $vehcat_row = tep_db_fetch_array($vehcat_query);
  101.   $prodidsarr = explode(",",$vehcat_row['productids']);
  102.  
  103.     require(DIR_WS_INCLUDES . 'functions/filter_test.php');
  104. ?>
  105.  
  106. <div class="row">
  107.   <div class="col-md-7">
  108.     <h3><?php echo HEADING_TITLE." ".$vehcat_row['category_name']; ?></h3>
  109.   </div>
  110.    <div class="col-md-4 text-right">
  111.     <?php echo tep_draw_form('printerfilter', FILENAME_PRINTER_PRODUCTS, 'action=assign_products&parent_id='.$parent_id.'&printer_category_id='.$printer_category_id.'&page='.$_REQUEST['page'], 'post');?>
  112.         <?php echo tep_draw_button(IMAGE_GO_BACK, 'fa fa-chevron-left', tep_href_link(FILENAME_PRINTER_CATEGORY, 'printer_category_id='.$printer_category_id.'&parent_id=' . $parent_id), 'primary') . '&nbsp;' . tep_draw_button(IMAGE_BUTTON_SAVE, 'fa fa-floppy-o', null, null, null, 'btn-success'); ?>
  113.    </div>
  114. </div>
  115.  
  116. <div class="table-responsive">
  117. <table class="table table-condensed table-hover header">
  118.         <thead><!-- table head-->
  119.             <tr>
  120.                <th><?php echo TABLE_HEADING_PRODUCT_ID; ?></th>
  121.                <th><?php echo TABLE_HEADING_PRODUCT_MODEL;?></th>
  122.                <th><?php echo TABLE_HEADING_PRODUCT_NAME;?></th>
  123.                <th><?php echo TABLE_HEADING_PRODUCT_CATEGORY_NAME;?></th>
  124.                <th><?php echo TABLE_HEADING_PRODUCT_SELECT;?></th>
  125.             </tr>
  126.         </thead>
  127.  
  128.         <tbody>
  129.             <?php
  130.                 //$products_query_raw = 'select distinct p.products_id, p.products_model, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, p.products_id, p.products_mediacat_ref_no, p.products_mediacat_quantity from '.TABLE_PRODUCTS.' p, '.TABLE_PRODUCTS_DESCRIPTION.' pd where p.products_id = pd.products_id and pd.language_id = "'.(int)$languages_id.'" order by pd.products_id asc';
  131.                 $products_query_raw = 'select distinct p.products_id, p.products_model, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, p.products_id from '.TABLE_PRODUCTS.' p, '.TABLE_PRODUCTS_DESCRIPTION.' pd where p.products_id = pd.products_id and pd.language_id = "'.(int)$languages_id.'" order by pd.products_id asc';
  132.                
  133.                 $products_split = new splitPageResults($_REQUEST['page'], '70', $products_query_raw, $products_query_numrows);
  134.                 $products_query = tep_db_query($products_query_raw);
  135.                 while ($products = tep_db_fetch_array($products_query)) {
  136.  
  137.                 if ( strpos( tep_get_product_path($products['products_id']), "_" ) == FALSE  ) {
  138.                   $result = tep_get_category_name2( tep_get_product_path( $products['products_id'] ) );
  139.                 } else {
  140.                    $pieces = explode("_", tep_get_product_path($products['products_id']) );
  141.                    $categories_array = array();
  142.                    $categories_array = tep_get_categories( $categories_array, $pieces[0] );
  143.                      for ( $j = 0 ; $j < count($categories_array) ; $j++ ) {
  144.                      if ( $categories_array[ $j ]['id'] == $pieces[ count( $pieces ) - 1 ] ) {
  145.                        $result =  $categories_array[ $j ][ 'text' ];
  146.                break;
  147.                      }
  148.                    }
  149.                  }
  150.             ?>
  151. <?php if(in_array($products['products_id'],$prodidsarr)) { ?>
  152. <tr bgcolor="#cccccc">
  153. <?php } else { ?>
  154. <tr>
  155. <?php } ?>
  156.  
  157.  
  158.   <td class="col-md-1"><?php echo $products['products_id'];?></td>
  159.   <td class="col-md-2"><?php echo $products['products_model'];?></td>
  160.   <td class="col-md-2"><?php echo $products['products_name'];?></td>
  161.   <td class="col-md-2"><?php echo $result; ?></td>
  162.   <!--<td class="col-md-1"><input type="checkbox" name="productids[]" value="<?php echo $products['products_id'];?>" <?php if(in_array($products['products_id'],$prodidsarr)) echo 'checked';?> /></td> //-->
  163.   <td class="col-md-1"><input type="checkbox" name="productids[]" value="<?php echo $products['products_id'];?>" <?php if(in_array($products['products_id'],$prodidsarr)) echo 'checked';?> /></td>
  164.  
  165. <?php
  166.    
  167.    } // End of while
  168. ?>
  169.  
  170.   </tr>
  171.  </tbody>
  172. </table>
  173. </div>
  174. <div class="row">
  175.     <div class="col-xs-11 text-right">
  176.         <?php echo tep_draw_button(IMAGE_GO_BACK, 'fa fa-chevron-left', tep_href_link(FILENAME_PRINTER_CATEGORY, 'printer_category_id='.$printer_category_id.'&parent_id=' . $parent_id), 'primary') . '&nbsp;' . tep_draw_button(IMAGE_BUTTON_SAVE, 'fa fa-floppy-o', null, null, null, 'btn-success'); ?>
  177.     </div>
  178. </div>
  179. </form>
  180.  
  181. <!-- body_eof //-->
  182. <?php
  183.   require(DIR_WS_INCLUDES . 'template_bottom.php');
  184.   require(DIR_WS_INCLUDES . 'application_bottom.php');
  185. ?>
Advertisement
Add Comment
Please, Sign In to add comment