Tsimi

filter_printer_category.php

Dec 4th, 2015
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 13.37 KB | None | 0 0
  1. <?php
  2. /*
  3.    Printer Ink & Toner Filter
  4.    V1.7 for Oscommerce v2.2 RC2a
  5.    September 2010
  6.    
  7.    Bootstrapped by Tsimi - December 2015
  8.    
  9.    osCommerce, Open Source E-Commerce Solutions
  10.    http://www.oscommerce.com
  11.  
  12.    Copyright (c) 2015 osCommerce
  13.  
  14.   Released under the GNU General Public License
  15. */
  16.  
  17.   require('includes/application_top.php');
  18.  
  19.  
  20.  
  21.   $action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');
  22.  
  23.   if (tep_not_null($action)) {
  24.     switch ($action) {
  25.      case 'insert_category':
  26.       case 'update_category':
  27.         if (isset($HTTP_POST_VARS['printer_category_id'])) $printer_category_id = tep_db_prepare_input($HTTP_POST_VARS['printer_category_id']);
  28.         $category_name = tep_db_prepare_input($HTTP_POST_VARS['category_name']);
  29.         $parent_id = tep_db_prepare_input($HTTP_POST_VARS['parent_id']);
  30.         $sort_order = tep_db_prepare_input($HTTP_POST_VARS['sort_order']);
  31.  
  32.         $sql_data_array = array('sort_order' => (int)$sort_order);
  33.         $str = "";
  34.        
  35.        
  36.         if ($action == 'insert_category') {
  37.        
  38.           if(isset($HTTP_POST_VARS['lablename']))
  39.           {
  40.             $lablename = tep_db_prepare_input($HTTP_POST_VARS['lablename']);
  41.             $insert_sql_data = array('parent_id' => $parent_id, 'category_name' => $category_name, 'lablename' => $lablename);
  42.             tep_db_perform(TABLE_PRINTER_CATEGORY, $insert_sql_data);
  43.             $printer_category_id = tep_db_insert_id();
  44.             //mysql_query("ALTER TABLE ".TABLE_PRODUCTS."  ADD `printer_cat_".$printer_category_id."` VARCHAR( 255 ) NOT NULL");
  45.           }
  46.           else
  47.           {
  48.             $insert_sql_data = array('parent_id' => $parent_id, 'category_name' => $category_name.$str);
  49.             tep_db_perform(TABLE_PRINTER_CATEGORY, $insert_sql_data);
  50.  
  51.           $printer_category_id = tep_db_insert_id();
  52.           }
  53.          
  54.         } elseif ($action == 'update_category') {
  55.          if(isset($HTTP_POST_VARS['lablename']))
  56.           {
  57.             $lablename = tep_db_prepare_input($HTTP_POST_VARS['lablename']);
  58.             $update_sql_data = array('parent_id' => $parent_id, 'category_name' => $category_name, 'lablename' => $lablename);
  59.           }
  60.           else
  61.           {
  62.             $update_sql_data = array('parent_id' => $parent_id, 'category_name' => $category_name.$str);
  63.           }
  64.  
  65.           tep_db_perform(TABLE_PRINTER_CATEGORY, $update_sql_data, 'update', "printer_category_id = '" . (int)$printer_category_id . "'");
  66.         }
  67.  
  68.        
  69.  
  70.         tep_redirect(tep_href_link(FILENAME_PRINTER_CATEGORY, 'parent_id=' . $parent_id.'&printer_category_id='.$printer_category_id ));
  71.         break;
  72.     case 'delete_category_confirm':
  73.         if (isset($HTTP_POST_VARS['printer_category_id']))
  74.         {
  75.              $printer_category_id = tep_db_prepare_input($HTTP_POST_VARS['printer_category_id']);
  76.              $parent_id = tep_db_prepare_input($HTTP_POST_VARS['parent_id']);
  77.              deletesubcats($printer_category_id);
  78.         }
  79.         tep_redirect(tep_href_link(FILENAME_PRINTER_CATEGORY, 'parent_id=' . $parent_id ));
  80.     break;
  81.     }
  82.   }
  83. // check if the catalog image directory exists
  84.   if (is_dir(DIR_FS_CATALOG_IMAGES)) {
  85.     if (!is_writeable(DIR_FS_CATALOG_IMAGES)) $messageStack->add(ERROR_CATALOG_IMAGE_DIRECTORY_NOT_WRITEABLE, 'error');
  86.   } else {
  87.     $messageStack->add(ERROR_CATALOG_IMAGE_DIRECTORY_DOES_NOT_EXIST, 'error');
  88.   }
  89.  
  90.     require(DIR_WS_INCLUDES . 'template_top.php');
  91. ?>
  92.  
  93.     <h3><?php echo HEADING_TITLE; ?></h3>
  94. <div class="row">  
  95.       <div class="col-md-8">            
  96.         <table class="table table-hover table-responsive table-striped">
  97.           <thead>
  98.             <tr>
  99.                 <th><?php echo TABLE_HEADING_CATEGORIES; ?></th>
  100.                 <th class="text-center"><?php //echo TABLE_HEADING_STATUS; ?></th>
  101.                 <th class="text-right"><?php echo TABLE_HEADING_ACTION; ?></th>
  102.             </tr>
  103.           </thead>
  104.           <tbody>
  105. <?php
  106.     $categories_count = 0;
  107.     $rows = 0;
  108.     $parent_id = 0;
  109.     $printer_category_id = 0;
  110.     if(isset($HTTP_GET_VARS['parent_id'])&&($HTTP_GET_VARS['parent_id']!=''))
  111.     {
  112.         $parent_id = $HTTP_GET_VARS['parent_id'];
  113.        
  114.     }
  115.     if(isset($HTTP_GET_VARS['printer_category_id'])&&($HTTP_GET_VARS['printer_category_id']!=''))
  116.     {
  117.         $printer_category_id = $HTTP_GET_VARS['printer_category_id'];
  118.        
  119.     }
  120.       $categories_query = tep_db_query("select * from " . TABLE_PRINTER_CATEGORY . "  where parent_id = '".$parent_id."' order by category_name");
  121.     while ($categories = tep_db_fetch_array($categories_query)) {
  122.       $categories_count++;
  123.       $rows++;
  124.      
  125.       if(isset($HTTP_GET_VARS['printer_category_id'])&&($HTTP_GET_VARS['printer_category_id']==$categories['printer_category_id'])){
  126.         echo '<tr class="info" onclick="document.location.href=\'' . tep_href_link(FILENAME_PRINTER_CATEGORY, 'parent_id=' . $parent_id . '&printer_category_id=' . $categories['printer_category_id'] . '&action=new_product_preview&read=only') . '\'">' . "\n";
  127.       } else {
  128.         echo '<tr onclick="document.location.href=\'' . tep_href_link(FILENAME_PRINTER_CATEGORY, 'parent_id=' . $parent_id . '&printer_category_id=' . $categories['printer_category_id']) . '\'">' . "\n";
  129.       }
  130. ?>
  131.                 <td><?php echo '<a href="' . tep_href_link(FILENAME_PRINTER_CATEGORY, 'parent_id='.$categories['printer_category_id']) . '">' . tep_image(DIR_WS_ICONS . 'folder.gif', ICON_FOLDER) . '</a>&nbsp;<b>' . $categories['category_name'] . '</b>'; ?></td>
  132.                 <td class="text-center">&nbsp;</td>
  133.                 <td class="text-right"><?php if(isset($HTTP_GET_VARS['printer_category_id'])&&($HTTP_GET_VARS['printer_category_id']==$categories['printer_category_id'])) { echo '<i class="fa fa-chevron-circle-right fa-lg mouse"></i>'; } else { echo '<a href="' . tep_href_link(FILENAME_PRINTER_CATEGORY, 'parent_id=' . $parent_id . '&printer_category_id=' . $categories['printer_category_id']) . '"><i class="fa fa-info-circle fa-lg" title="'. IMAGE_ICON_INFO .'"></i></a>'; } ?></td>
  134.               </tr>
  135. <?php
  136.     }
  137.  
  138. ?>
  139.         </tbody>
  140.     </table>
  141.  <div class="row mb25">
  142. <?php
  143.  if (!isset($HTTP_GET_VARS['search'])) {
  144. ?>
  145.         <div class="col-md-12 mb10 text-right">
  146.             <?php
  147.             if(isset($parent_id)&&($parent_id>0)) {
  148.                 $getparentquery = tep_db_query("select parent_id from " . TABLE_PRINTER_CATEGORY . "  where printer_category_id = '".$parent_id."' ");
  149.                 $getparentquerys = tep_db_fetch_array($getparentquery);
  150.            
  151.                 echo tep_draw_button(IMAGE_BACK, 'fa fa-chevron-left', tep_href_link(FILENAME_PRINTER_CATEGORY, $parent_id_back . 'parent_id=' . $getparentquerys['parent_id']), '', null, 'btn-default');
  152.             }
  153.             ?>
  154.            <?php echo tep_draw_button(IMAGE_NEW_CATEGORY, 'fa fa-plus', tep_href_link(FILENAME_PRINTER_CATEGORY, 'parent_id=' . $parent_id . '&printer_category_id='.$printer_category_id.'&action=new_category'), '', null, 'btn-default'); ?>
  155.         </div>     
  156. <?php
  157.   }
  158. ?>      
  159.         <div class="col-md-5">
  160.            <?php echo TEXT_CATEGORIES . '&nbsp;' . $categories_count . '<br>'; ?>
  161.         </div>
  162.         <div class="col-md-3 pull-right text-right">
  163.  
  164.         </div>
  165.     </div>
  166.    
  167.         </div> <!-- EOF col-md-8 -->          
  168.         <div class="col-md-4"> 
  169. <?php
  170.     switch ($action) {
  171.       case 'new_category':
  172.             echo '<div class="panel panel-primary">
  173.                     <div class="panel-heading"><span class="panel-title">' . TEXT_INFO_HEADING_NEW_CATEGORY . '</span></div>';
  174.  
  175.                 echo '<div class="panel-body">' .
  176.                      tep_draw_form('newcategory', FILENAME_PRINTER_CATEGORY, 'action=insert_category&parent_id=' . $parent_id, 'post', 'enctype="multipart/form-data"'). tep_draw_hidden_field('parent_id', $parent_id) .
  177.                      TEXT_NEW_CATEGORY_INTRO . '<br />';
  178.  
  179.             if($parent_id==0) {
  180.                 $category_inputs_string = '';
  181.                 $category_inputs_string .= '<br />' . tep_draw_input_field('lablename', '');
  182.                 echo '<br />' . "Label Name" . $category_inputs_string;
  183.             }
  184.                 $category_inputs_string = '';
  185.                 $category_inputs_string .= '<br />' . tep_draw_input_field('category_name');
  186.                 echo '<br />' . TEXT_CATEGORIES_NAME . $category_inputs_string .
  187.        
  188.                      '<br /><div class="text-center">' .  tep_draw_button(IMAGE_SAVE, 'fa fa-floppy-o', null, 'primary', null, 'btn-success') .
  189.                      '&nbsp;' . tep_draw_button(IMAGE_CANCEL, 'fa fa-ban icon-red', tep_href_link(FILENAME_PRINTER_CATEGORY, 'parent_id=' . $parent_id)) . '</div>' .
  190.                  '</div></div>';
  191.         break;
  192.       case 'edit_category':
  193.         $getcurrentcatRS = tep_db_query("select * from " . TABLE_PRINTER_CATEGORY . "  where printer_category_id = '".$printer_category_id."' ");
  194.         $getcurrentcatROW = tep_db_fetch_array($getcurrentcatRS);
  195.         echo '<div class="panel panel-primary">
  196.                 <div class="panel-heading"><span class="panel-title">' . TEXT_INFO_HEADING_EDIT_CATEGORY . '</span></div>';
  197.        
  198.         echo '<div class="panel-body">' .
  199.              tep_draw_form('categories', FILENAME_PRINTER_CATEGORY, 'action=update_category&parent_id=' . $parent_id, 'post', 'enctype="multipart/form-data"') . tep_draw_hidden_field('printer_category_id', $printer_category_id). tep_draw_hidden_field('parent_id', $parent_id) . TEXT_EDIT_INTRO;
  200.         if($getcurrentcatROW['parent_id']==0) {
  201.             $category_inputs_string = '';
  202.             $category_inputs_string .= '<br />' . tep_draw_input_field('lablename', $getcurrentcatROW['lablename']);
  203.             echo '<br /><br />' . "Label Name" . $category_inputs_string;
  204.         }
  205.             $category_inputs_string = '';
  206.             $category_inputs_string .= '<br />' . tep_draw_input_field('category_name', $getcurrentcatROW['category_name']);
  207.             echo '<br />' . TEXT_EDIT_CATEGORIES_NAME . $category_inputs_string .
  208.    
  209.                  '<br /><div class="text-center">' .  tep_draw_button(IMAGE_SAVE, 'fa fa-floppy-o', null, 'primary', null, 'btn-success') .
  210.                  '&nbsp;' . tep_draw_button(IMAGE_CANCEL, 'fa fa-ban icon-red', tep_href_link(FILENAME_PRINTER_CATEGORY, 'parent_id=' . $parent_id . '&printer_category_id=' . $categories['printer_category_id'])) . '</div>' .
  211.                  '</div></div>';
  212.         break;
  213.       case 'delete_category':
  214.         $getcurrentcatRS = tep_db_query("select * from " . TABLE_PRINTER_CATEGORY . "  where printer_category_id = '".$printer_category_id."' ");
  215.         $getcurrentcatROW = tep_db_fetch_array($getcurrentcatRS);
  216.         echo '<div class="panel panel-danger">
  217.                     <div class="panel-heading"><span class="panel-title">' . TEXT_INFO_HEADING_DELETE_CATEGORY . '</span></div>';
  218.  
  219.         echo '<div class="panel-body">' . tep_draw_form('categories', FILENAME_PRINTER_CATEGORY, 'action=delete_category_confirm&parent_id=' . $parent_id) . tep_draw_hidden_field('printer_category_id', $printer_category_id). tep_draw_hidden_field('parent_id', $parent_id) . TEXT_DELETE_CATEGORY_INTRO .
  220.              '<br /><br /><strong>' . $getcurrentcatROW['category_name'] . '</strong>' .
  221.        
  222.              '<br /><br /><div class="text-center">' . tep_draw_button(IMAGE_DELETE, 'fa fa-trash-o', null, 'primary', null, 'btn-danger') .  
  223.              '&nbsp;' . tep_draw_button(IMAGE_CANCEL, 'fa fa-ban icon-red', tep_href_link(FILENAME_PRINTER_CATEGORY, 'parent_id=' . $parent_id . '&printer_category_id=' . $categories['printer_category_id'])) . '</div>' .
  224.              '</div></div>';      
  225.        break;
  226.      
  227.       default:
  228.         if ($printer_category_id > 0) {
  229.             $getcurrentcatRS = tep_db_query("select * from " . TABLE_PRINTER_CATEGORY . "  where printer_category_id = '".$printer_category_id."' ");
  230.             $getcurrentcatROW = tep_db_fetch_array($getcurrentcatRS);
  231.                 echo '<div class="panel panel-default">
  232.                         <div class="panel-heading"><span class="panel-title"><strong>' . $getcurrentcatROW['category_name'] . '</strong></span></div>';
  233.                
  234.                 echo '<div class="panel-body">' .
  235.                         '<div class="text-center">' . tep_draw_button(IMAGE_EDIT, 'fa fa-pencil', tep_href_link(FILENAME_PRINTER_CATEGORY, 'parent_id=' . $parent_id . '&printer_category_id=' .$printer_category_id . '&action=edit_category'), 'primary', null, 'btn-warning') . '&nbsp;' .
  236.                         tep_draw_button(IMAGE_DELETE, 'fa fa-trash-o',tep_href_link(FILENAME_PRINTER_CATEGORY, 'parent_id=' . $parent_id . '&printer_category_id=' . $printer_category_id . '&action=delete_category'), 'primary', null, 'btn-danger') . '</div>';
  237.                
  238.                 $chkchildROW = tep_db_fetch_array(tep_db_query("SELECT count(*) FROM " . TABLE_PRINTER_CATEGORY . "  where parent_id = '".$printer_category_id."'"));
  239.                 if($chkchildROW[0]==0) {
  240.                     $str = '<a href="filter_products.php?printer_category_id='.$printer_category_id.'&parent_id='.$parent_id.'">Assign Products</a>';
  241.                     echo '<br /><div class="text-center">' . tep_draw_button('Manage Products', 'fa fa-list', tep_href_link(FILENAME_PRINTER_PRODUCTS, 'printer_category_id='.$printer_category_id.'&parent_id=' . $parent_id )) . '</div>';
  242.                 }
  243.             echo '</div></div>';
  244.         } else { // create category/product info
  245.           echo '<div class="panel panel-default">
  246.                         <div class="panel-heading"><span class="panel-title"><strong>' . EMPTY_CATEGORY . '</strong></span></div>';
  247.           echo '<div class="panel-body">' . TEXT_NO_CHILD_CATEGORIES_OR_PRODUCTS .  '</div></div>';
  248.         }
  249.         break;
  250.     }
  251. ?>
  252.   </div> <!-- EOF col-md-4 //-->
  253. </div>
  254.  
  255. <?php
  256.   function deletesubcats($printer_category_id) {
  257.    
  258.     tep_db_query("delete from " . TABLE_PRINTER_CATEGORY . " where printer_category_id = '" . (int)$printer_category_id . "'");
  259.     $subcatSQL = tep_db_query("select * from " . TABLE_PRINTER_CATEGORY . "  where parent_id = '".$printer_category_id."' ");
  260.     while($subcatROW = tep_db_fetch_array($subcatSQL)) {
  261.         deletesubcats($subcatROW['printer_category_id']);
  262.         if($subcatROW['parent_id']==0) {
  263.            
  264.         }
  265.     }
  266.    
  267. }
  268.  
  269.   require(DIR_WS_INCLUDES . 'template_bottom.php');
  270.   require(DIR_WS_INCLUDES . 'application_bottom.php');
  271. ?>
Advertisement
Add Comment
Please, Sign In to add comment