File: fwphp/01mater/shop/admin/category/index.php

Recommend this page to a friend!
  Classes of Slavko Srakocic  >  B12 PHP FW  >  fwphp/01mater/shop/admin/category/index.php  >  Download  
File: fwphp/01mater/shop/admin/category/index.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: B12 PHP FW
Manage database records with a PDO CRUD interface
Author: By
Last change: ver 7.0.5 mnu, msg, mkd FUNCTIONAL namespaces, CRUD PDO trait, pretty URL-s
Date: 1 month ago
Size: 1,678 bytes
 

Contents

Class file image Download

<?php
//require_once('../../util/m ain.php');
require_once('util/secure_conn.php');
require_once(
'util/valid_admin.php');

require_once(
'model/admin_db.php');
require_once(
'model/product_db.php');
require_once(
'model/category_db.php');

$action = strtolower(filter_input(INPUT_POST, 'action'));
if (
$action == NULL) {
   
$action = strtolower(filter_input(INPUT_GET, 'action'));
    if (
$action == NULL) {
       
$action = 'list_categories';
    }
}

switch (
$action) {
    case
'list_categories':
       
$categories = get_categories();

        include(
'category_list.php');
        break;
    case
'delete_category':
       
$category_id = filter_input(INPUT_POST, 'category_id',
               
FILTER_VALIDATE_INT);

       
delete_category($category_id);
       
       
header("Location: .");
        break;
    case
'add_category':
       
$name = filter_input(INPUT_POST, 'name');

       
// Validate inputs
       
if (empty($name)) {
           
display_error('You must include a name for the category.
                           Please try again.'
);
        } else {
           
$category_id = add_category($name);
        }

       
header("Location: .");
        break;
    case
'update_category':
       
$category_id = filter_input(INPUT_POST, 'category_id',
               
FILTER_VALIDATE_INT);
       
$name = filter_input(INPUT_POST, 'name');

       
// Validate inputs
       
if (empty($name)) {
           
display_error('You must include a name for the category.
                          Please try again.'
);
        } else {
           
update_category($category_id, $name);
        }

       
header("Location: .");
        break;
}

?>

For more information send a message to info at phpclasses dot org.