<?php

require_once "../controllers/DbConnection.php";
require_once "../controllers/Product.php";
echo $_GET['id'];
$pro = new Product(DbConnection::getConnection());
$result = $pro->delete_product($_GET['id']);
header("location: ../views/Show_Products.php");
//var_dump($result->fetch_assoc());
        if ($errmsg == '') {
            function check_input($data)
            {
                $data = trim($data);
                $data = stripslashes($data);
                $data = htmlspecialchars($data);
                $data = mysql_real_escape_string($data);
                return $data;
            }
            $Productid = check_input($_POST['Productid']);
            $Product_name = check_input($_POST['Product_name']);
            $Product_type = check_input($_POST['Product_type']);
            $Product_price = check_input($_POST['Product_price']);
            $Product_description = check_input($_POST['Product_description']);
            $Productobj = new Product();
            if ($Productobj->delete_product($Productid, $Product_name, $Product_type, $Product_price, $Product_description)) {
                $msg .= 'Product Details successfully Deleted.<br>';
                $Productid = "";
                $Product_name = "";
                $Product_type = "";
                $Product_price = "";
                $Product_description = "";
            } else {
                $errmsg .= '!Opps Some thing went wrong.<br>';
            }
        }
    }
}
include_once "../../includes/dbclose.inc.php";
require_once "../layouts/user_header.php";
?>
$price1 = $_REQUEST['price'];
$image_name1 = $_REQUEST['image_name'];
$description1 = $_REQUEST['description'];
if ($_FILES["image_path"]["error"] > 0) {
    echo "<font size = '5'><font color=\"#e31919\">Error: NO CHOSEN FILE <br />";
    echo "<p><font size = '5'><font color=\"#e31919\">INSERT TO DATABASE FAILED";
} else {
    $uploaddir = "images/";
    move_uploaded_file($_FILES["image_path"]["tmp_name"], "{$uploaddir}" . $_FILES["image_path"]["name"]);
    echo "<font size = '5'><font color=\"#0CF44A\">SAVED<br>";
}
$file1 = "{$uploaddir}" . $_FILES["image_path"]["name"];
switch ($_REQUEST['operation']) {
    case "add":
        $product->add_product("product_details", "product_name,price,image_name,image_path,description", "'{$product_name}','{$price}','{$image_name}','{$file}','{$description}'");
        break;
    case "update":
        $product->update_product("product_details", "product_name='{$product_name1}',price='{$price1}',image_name='{$image_name1}',image_path='{$file1}',description='{$description1}'", "product_id='{$product_id1}'");
        break;
    case "delete_rec":
        $product->delete_product("product_details", "product_id='{$product_id}'");
        break;
    case "view":
        $product->view_product($product_list, $table);
        break;
    case "view_single":
        $product->view_single_product($product_list, $table, $condition);
        break;
    default:
        echo "<H3 color='red'>Invalid Option Please Try again!</h3>";
}