public function delete() { if (!isset($_POST['del_prod_id'])) { echo '2'; return; } $prod_id = (int) $_POST['del_prod_id']; if ($prod_id <= 0) { echo '2'; return; } $productDAO = new ProductDAO(DataSource::getInstance()); $result = $productDAO->delete($prod_id); echo (string) $result; }
if (isset($_POST['action'])) { //if the user wants to modify a product if ($_POST['action'] == 'Modify') { if (isset($_POST["radioval"])) { //We put the idproduct in a session to use it in modify_product.php header('Location: modify_product.php?idproduct=' . $_POST["radioval"] . '&idcategory=' . $_GET['idcategory'] . '&idspecification=' . $_GET['idspecification']); } else { echo '<span class="text-danger">*' . t('Please select a product') . '</span>'; } } //if the user wants to delete a product if ($_POST['action'] == 'Delete') { if (isset($_POST["radioval"])) { $daoprod = new ProductDAO(); //we delete the product with the id that the user chooses with the radiobutton $resprod = $daoprod->delete($_POST["radioval"]); } else { //display an error message if the user hasn't selected a product to modify/delete echo '<span class="text-danger">*' . t('Please select a product') . '</span>'; } } } //select all the categories in the database $category_dao = new CategoryDAO(); $categories = $category_dao->getAllCategories(); $specification_dao = new SpecificationDAO(); $page['title'] = 'Manage products'; require '../../include/header.inc'; require '../../include/index.inc'; ?>