예제 #1
0
require '../model/database.php';
require '../model/category.php';
require '../model/category_db.php';
require '../model/product.php';
require '../model/product_db.php';
if (isset($_POST['action'])) {
    $action = $_POST['action'];
} else {
    if (isset($_GET['action'])) {
        $action = $_GET['action'];
    } else {
        $action = 'list_products';
    }
}
if ($action == 'list_products') {
    $category_id = $_GET['category_id'];
    if (empty($category_id)) {
        $category_id = 1;
    }
    $current_category = CategoryDB::getCategory($category_id);
    $categories = CategoryDB::getCategories();
    $products = ProductDB::getProductsByCategory($category_id);
    include 'product_list.php';
} else {
    if ($action == 'view_product') {
        $categories = CategoryDB::getCategories();
        $product_id = $_GET['product_id'];
        $product = ProductDB::getProduct($product_id);
        include 'product_view.php';
    }
}
예제 #2
0
파일: index.php 프로젝트: j-jm/web182
$action = filter_input(INPUT_POST, 'action');
if ($action == NULL) {
    $action = filter_input(INPUT_GET, 'action');
    if ($action == NULL) {
        $action = 'list_products';
    }
}
if ($action == 'list_products') {
    $category_id = filter_input(INPUT_GET, 'category_id', FILTER_VALIDATE_INT);
    if ($category_id == NULL || $category_id == FALSE) {
        $category_id = 1;
    }
    // Get product and category data
    $current_category = $categoryDB->getCategory($category_id);
    $categories = $categoryDB->getCategories();
    $products = $productDB->getProductsByCategory($category_id);
    // Display the product list
    include 'product_list.php';
} else {
    if ($action == 'delete_product') {
        // Get the IDs
        $product_id = filter_input(INPUT_POST, 'product_id', FILTER_VALIDATE_INT);
        $category_id = filter_input(INPUT_POST, 'category_id', FILTER_VALIDATE_INT);
        // Delete the product
        $productDB->deleteProduct($product_id);
        // Display the Product List page for the current category
        header("Location: .?category_id={$category_id}");
    } else {
        if ($action == 'show_add_form') {
            $categories = $categoryDB->getCategories();
            include 'product_add.php';