<?php if (isset($_REQUEST['pcode'])) { include "../classes/product.php"; $obj = new product(); $pcode = $_REQUEST['pcode']; $name = $_REQUEST['name']; $sp = $_REQUEST['sprice']; $cp = $_REQUEST['cprice']; $stock = $_REQUEST['quantity']; $obj->add_product($pcode, $name, $sp, $cp, $stock); } //echo "http://cs.ashesi.edu.gh/~csashesi/class2016/obed-nsiah/mobileweb/pos/desktop/addstock.html"; //header(Location: ../desktop/addstock.html); ?>
if (isset($_POST['submit']) && $_POST['submit'] == tr('Add New Product')) { // Perform checks if ($_POST['amount'] == '') { $template->add_message("You did not specify a product amount.", 'error'); } elseif (!is_numeric($_POST['amount'])) { $template->add_message("Invalid product amount specified.", 'error'); } elseif ($_POST['amount'] < 0) { $template->add_message("Invalid product amount specified.", 'error'); } if ($_POST['product_name'] == '') { $template->add_message("You did not specify a product name", 'error'); } // Add product, if needed if ($template->has_errors != 1) { $client = new product(); $client->add_product($_POST['amount'], $_POST['currency'], $_POST['product_name'], $_POST['description']); $template->add_message("Successfully created new product, {$_POST['product_name']}."); } // Delete checked products } elseif (isset($_POST['submit']) && $_POST['submit'] == tr('Delete Checked Products')) { // Get IDs $ids = get_chk('product_id'); // Disable foreach ($ids as $id) { if (!$id > 0) { continue; } DB::query("UPDATE products SET is_enabled = 0 WHERE id = %d", $id); } // User message $template->add_message("Successfully deleted checked products.");
function add_product() { $name = $_GET['name']; $barcode = $_GET['barcode']; $price = $_GET['price']; include_once 'product.php'; $obj = new product(); if (!$obj->connect()) { $json = '{"status":2, "products":{}, "Failed to connect to the database."}'; echo $json; exit; } if ($obj->add_product($name, $barcode, $price)) { $json = '{"status":0, "products":{}, "message":"Product added."}'; echo $json; } else { $json = '{"status":1, "products":{}, "message":"Product was not added."}'; echo $json; } }