Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Printer Ink & Toner Filter
- V1.7 for Oscommerce v2.2 RC2a
- September 2010
- Bootstrapped by Tsimi - December 2015
- osCommerce, Open Source E-Commerce Solutions
- http://www.oscommerce.com
- Copyright (c) 2015 osCommerce
- Released under the GNU General Public License
- */
- require('includes/application_top.php');
- $action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');
- if (tep_not_null($action)) {
- switch ($action) {
- case 'insert_category':
- case 'update_category':
- if (isset($HTTP_POST_VARS['printer_category_id'])) $printer_category_id = tep_db_prepare_input($HTTP_POST_VARS['printer_category_id']);
- $category_name = tep_db_prepare_input($HTTP_POST_VARS['category_name']);
- $parent_id = tep_db_prepare_input($HTTP_POST_VARS['parent_id']);
- $sort_order = tep_db_prepare_input($HTTP_POST_VARS['sort_order']);
- $sql_data_array = array('sort_order' => (int)$sort_order);
- $str = "";
- if ($action == 'insert_category') {
- if(isset($HTTP_POST_VARS['lablename']))
- {
- $lablename = tep_db_prepare_input($HTTP_POST_VARS['lablename']);
- $insert_sql_data = array('parent_id' => $parent_id, 'category_name' => $category_name, 'lablename' => $lablename);
- tep_db_perform(TABLE_PRINTER_CATEGORY, $insert_sql_data);
- $printer_category_id = tep_db_insert_id();
- //mysql_query("ALTER TABLE ".TABLE_PRODUCTS." ADD `printer_cat_".$printer_category_id."` VARCHAR( 255 ) NOT NULL");
- }
- else
- {
- $insert_sql_data = array('parent_id' => $parent_id, 'category_name' => $category_name.$str);
- tep_db_perform(TABLE_PRINTER_CATEGORY, $insert_sql_data);
- $printer_category_id = tep_db_insert_id();
- }
- } elseif ($action == 'update_category') {
- if(isset($HTTP_POST_VARS['lablename']))
- {
- $lablename = tep_db_prepare_input($HTTP_POST_VARS['lablename']);
- $update_sql_data = array('parent_id' => $parent_id, 'category_name' => $category_name, 'lablename' => $lablename);
- }
- else
- {
- $update_sql_data = array('parent_id' => $parent_id, 'category_name' => $category_name.$str);
- }
- tep_db_perform(TABLE_PRINTER_CATEGORY, $update_sql_data, 'update', "printer_category_id = '" . (int)$printer_category_id . "'");
- }
- tep_redirect(tep_href_link(FILENAME_PRINTER_CATEGORY, 'parent_id=' . $parent_id.'&printer_category_id='.$printer_category_id ));
- break;
- case 'delete_category_confirm':
- if (isset($HTTP_POST_VARS['printer_category_id']))
- {
- $printer_category_id = tep_db_prepare_input($HTTP_POST_VARS['printer_category_id']);
- $parent_id = tep_db_prepare_input($HTTP_POST_VARS['parent_id']);
- deletesubcats($printer_category_id);
- }
- tep_redirect(tep_href_link(FILENAME_PRINTER_CATEGORY, 'parent_id=' . $parent_id ));
- break;
- }
- }
- // check if the catalog image directory exists
- if (is_dir(DIR_FS_CATALOG_IMAGES)) {
- if (!is_writeable(DIR_FS_CATALOG_IMAGES)) $messageStack->add(ERROR_CATALOG_IMAGE_DIRECTORY_NOT_WRITEABLE, 'error');
- } else {
- $messageStack->add(ERROR_CATALOG_IMAGE_DIRECTORY_DOES_NOT_EXIST, 'error');
- }
- require(DIR_WS_INCLUDES . 'template_top.php');
- ?>
- <h3><?php echo HEADING_TITLE; ?></h3>
- <div class="row">
- <div class="col-md-8">
- <table class="table table-hover table-responsive table-striped">
- <thead>
- <tr>
- <th><?php echo TABLE_HEADING_CATEGORIES; ?></th>
- <th class="text-center"><?php //echo TABLE_HEADING_STATUS; ?></th>
- <th class="text-right"><?php echo TABLE_HEADING_ACTION; ?></th>
- </tr>
- </thead>
- <tbody>
- <?php
- $categories_count = 0;
- $rows = 0;
- $parent_id = 0;
- $printer_category_id = 0;
- if(isset($HTTP_GET_VARS['parent_id'])&&($HTTP_GET_VARS['parent_id']!=''))
- {
- $parent_id = $HTTP_GET_VARS['parent_id'];
- }
- if(isset($HTTP_GET_VARS['printer_category_id'])&&($HTTP_GET_VARS['printer_category_id']!=''))
- {
- $printer_category_id = $HTTP_GET_VARS['printer_category_id'];
- }
- $categories_query = tep_db_query("select * from " . TABLE_PRINTER_CATEGORY . " where parent_id = '".$parent_id."' order by category_name");
- while ($categories = tep_db_fetch_array($categories_query)) {
- $categories_count++;
- $rows++;
- if(isset($HTTP_GET_VARS['printer_category_id'])&&($HTTP_GET_VARS['printer_category_id']==$categories['printer_category_id'])){
- 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";
- } else {
- echo '<tr onclick="document.location.href=\'' . tep_href_link(FILENAME_PRINTER_CATEGORY, 'parent_id=' . $parent_id . '&printer_category_id=' . $categories['printer_category_id']) . '\'">' . "\n";
- }
- ?>
- <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> <b>' . $categories['category_name'] . '</b>'; ?></td>
- <td class="text-center"> </td>
- <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>
- </tr>
- <?php
- }
- ?>
- </tbody>
- </table>
- <div class="row mb25">
- <?php
- if (!isset($HTTP_GET_VARS['search'])) {
- ?>
- <div class="col-md-12 mb10 text-right">
- <?php
- if(isset($parent_id)&&($parent_id>0)) {
- $getparentquery = tep_db_query("select parent_id from " . TABLE_PRINTER_CATEGORY . " where printer_category_id = '".$parent_id."' ");
- $getparentquerys = tep_db_fetch_array($getparentquery);
- 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');
- }
- ?>
- <?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'); ?>
- </div>
- <?php
- }
- ?>
- <div class="col-md-5">
- <?php echo TEXT_CATEGORIES . ' ' . $categories_count . '<br>'; ?>
- </div>
- <div class="col-md-3 pull-right text-right">
- </div>
- </div>
- </div> <!-- EOF col-md-8 -->
- <div class="col-md-4">
- <?php
- switch ($action) {
- case 'new_category':
- echo '<div class="panel panel-primary">
- <div class="panel-heading"><span class="panel-title">' . TEXT_INFO_HEADING_NEW_CATEGORY . '</span></div>';
- echo '<div class="panel-body">' .
- 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) .
- TEXT_NEW_CATEGORY_INTRO . '<br />';
- if($parent_id==0) {
- $category_inputs_string = '';
- $category_inputs_string .= '<br />' . tep_draw_input_field('lablename', '');
- echo '<br />' . "Label Name" . $category_inputs_string;
- }
- $category_inputs_string = '';
- $category_inputs_string .= '<br />' . tep_draw_input_field('category_name');
- echo '<br />' . TEXT_CATEGORIES_NAME . $category_inputs_string .
- '<br /><div class="text-center">' . tep_draw_button(IMAGE_SAVE, 'fa fa-floppy-o', null, 'primary', null, 'btn-success') .
- ' ' . tep_draw_button(IMAGE_CANCEL, 'fa fa-ban icon-red', tep_href_link(FILENAME_PRINTER_CATEGORY, 'parent_id=' . $parent_id)) . '</div>' .
- '</div></div>';
- break;
- case 'edit_category':
- $getcurrentcatRS = tep_db_query("select * from " . TABLE_PRINTER_CATEGORY . " where printer_category_id = '".$printer_category_id."' ");
- $getcurrentcatROW = tep_db_fetch_array($getcurrentcatRS);
- echo '<div class="panel panel-primary">
- <div class="panel-heading"><span class="panel-title">' . TEXT_INFO_HEADING_EDIT_CATEGORY . '</span></div>';
- echo '<div class="panel-body">' .
- 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;
- if($getcurrentcatROW['parent_id']==0) {
- $category_inputs_string = '';
- $category_inputs_string .= '<br />' . tep_draw_input_field('lablename', $getcurrentcatROW['lablename']);
- echo '<br /><br />' . "Label Name" . $category_inputs_string;
- }
- $category_inputs_string = '';
- $category_inputs_string .= '<br />' . tep_draw_input_field('category_name', $getcurrentcatROW['category_name']);
- echo '<br />' . TEXT_EDIT_CATEGORIES_NAME . $category_inputs_string .
- '<br /><div class="text-center">' . tep_draw_button(IMAGE_SAVE, 'fa fa-floppy-o', null, 'primary', null, 'btn-success') .
- ' ' . 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>' .
- '</div></div>';
- break;
- case 'delete_category':
- $getcurrentcatRS = tep_db_query("select * from " . TABLE_PRINTER_CATEGORY . " where printer_category_id = '".$printer_category_id."' ");
- $getcurrentcatROW = tep_db_fetch_array($getcurrentcatRS);
- echo '<div class="panel panel-danger">
- <div class="panel-heading"><span class="panel-title">' . TEXT_INFO_HEADING_DELETE_CATEGORY . '</span></div>';
- 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 .
- '<br /><br /><strong>' . $getcurrentcatROW['category_name'] . '</strong>' .
- '<br /><br /><div class="text-center">' . tep_draw_button(IMAGE_DELETE, 'fa fa-trash-o', null, 'primary', null, 'btn-danger') .
- ' ' . 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>' .
- '</div></div>';
- break;
- default:
- if ($printer_category_id > 0) {
- $getcurrentcatRS = tep_db_query("select * from " . TABLE_PRINTER_CATEGORY . " where printer_category_id = '".$printer_category_id."' ");
- $getcurrentcatROW = tep_db_fetch_array($getcurrentcatRS);
- echo '<div class="panel panel-default">
- <div class="panel-heading"><span class="panel-title"><strong>' . $getcurrentcatROW['category_name'] . '</strong></span></div>';
- echo '<div class="panel-body">' .
- '<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') . ' ' .
- 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>';
- $chkchildROW = tep_db_fetch_array(tep_db_query("SELECT count(*) FROM " . TABLE_PRINTER_CATEGORY . " where parent_id = '".$printer_category_id."'"));
- if($chkchildROW[0]==0) {
- $str = '<a href="filter_products.php?printer_category_id='.$printer_category_id.'&parent_id='.$parent_id.'">Assign Products</a>';
- 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>';
- }
- echo '</div></div>';
- } else { // create category/product info
- echo '<div class="panel panel-default">
- <div class="panel-heading"><span class="panel-title"><strong>' . EMPTY_CATEGORY . '</strong></span></div>';
- echo '<div class="panel-body">' . TEXT_NO_CHILD_CATEGORIES_OR_PRODUCTS . '</div></div>';
- }
- break;
- }
- ?>
- </div> <!-- EOF col-md-4 //-->
- </div>
- <?php
- function deletesubcats($printer_category_id) {
- tep_db_query("delete from " . TABLE_PRINTER_CATEGORY . " where printer_category_id = '" . (int)$printer_category_id . "'");
- $subcatSQL = tep_db_query("select * from " . TABLE_PRINTER_CATEGORY . " where parent_id = '".$printer_category_id."' ");
- while($subcatROW = tep_db_fetch_array($subcatSQL)) {
- deletesubcats($subcatROW['printer_category_id']);
- if($subcatROW['parent_id']==0) {
- }
- }
- }
- require(DIR_WS_INCLUDES . 'template_bottom.php');
- require(DIR_WS_INCLUDES . 'application_bottom.php');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment