<?php

session_start();

require_once('database.php');



//login admin

if(isset($_POST['login']))

{

    $email=$_POST['email'];

    $password=$_POST['password'];

    

    //$query="SELECT * from admin where email='$email' && password='$password'";
    $query="SELECT * from admin where email='$email'";
    $rec=db::getRecord($query);

    

    if($rec)

    { 
        if (password_verify($password, $rec['password']))
        {
          /* The password is correct. */
          $_SESSION['email']=$email;
          echo "<script>location='index.php'</script>";
        }
       
    }
    echo "<script>location='login.php?status=1'</script>";

}



//add image

if (isset($_POST['submit_product'])) {

$target_dir = "uploads/appetizers/";

$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);

$uploadOk = 1;

$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));

// Check if image file is a actual image or fake image

if(isset($_POST["submit_images"])) {

    $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);

    if($check !== false) {

        echo "File is an image - " . $check["mime"] . ".";

        $uploadOk = 1;

    } else {

        echo "File is not an image.";

        $uploadOk = 0;

    }

}



// Allow certain file formats

if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"

&& $imageFileType != "gif" ) {

    echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";

    $uploadOk = 0;

}

// Check if $uploadOk is set to 0 by an error

if ($uploadOk == 0) {

    echo "Sorry, your file was not uploaded.";

// if everything is ok, try to upload file

} else {

    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {

        echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";

    } else {

        echo "Sorry, there was an error uploading your file.";

    }

}

    $name = $_POST['name'];

    $description = $_POST['description'];

    $code = $_POST['code'];

    $price=$_POST['price'];

    

    $query="INSERT INTO products_appetizer(product_name,product_desc,product_code,product_image,product_price)

    VALUES('$name','$description','$code','$target_file','$price')";

    $insert=db::query($query);

    echo "<script>location='add_product.php'</script>";	

}



//update profile Data



if(isset($_POST['edit_profile'])){

$target_dir = "uploads/";

$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);

$uploadOk = 1;

$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));

// Check if image file is a actual image or fake image

if(isset($_POST["submit_images"])) {

    $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);

    if($check !== false) {

        echo "File is an image - " . $check["mime"] . ".";

        $uploadOk = 1;

    } else {

        echo "File is not an image.";

        $uploadOk = 0;

    }

}



// Allow certain file formats

if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"

&& $imageFileType != "gif" ) {

    echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";

    $uploadOk = 0;

}

// Check if $uploadOk is set to 0 by an error

if ($uploadOk == 0) {

    echo "Sorry, your file was not uploaded.";

// if everything is ok, try to upload file

} else {

    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {

        echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";

    } else {

        echo "Sorry, there was an error uploading your file.";

    }

}

    $id='1';

    $name=$_POST['name'];

    $phone=$_POST['phone'];

    $email=$_POST['email'];

    $password=$_POST['password'];

    $about=$_POST['about'];

    $query="Update admin SET name='$name',phone='$phone',email='$email',password='$password',about='$about',image='$target_file' WHERE id='$id'";

    $update=db::query($query);   

    echo "<script>location='user.php'</script>";

    

}

//delete Reservation



if(isset($_GET['id_recordid'])) {

	 $id=$_GET['id_recordid'];

	 $query="DELETE FROM reservation WHERE id='$id'";

	 $delete=db::query($query);

	 echo "<script>location='reservation.php'</script>";

}

//delete order_record



if(isset($_GET['id_record_delete_id'])) {

	 $id=$_GET['id_record_delete_id'];

	 $query="DELETE FROM order_items WHERE customer_id='$id'";

	 $delete=db::query($query);

     $query2="DELETE FROM order_information WHERE customer_id='$id'";

	 $delete2=db::query($query2);

	 echo "<script>location='active_order.php'</script>";

}

//update status Data



if(isset($_POST['edit_status'])){

    $id=$_POST['order_id'];

    $status=$_POST['status'];

    $query="Update order_information SET status='$status' WHERE order_id='$id'";

    $update=db::query($query);   

    echo "<script>location='active_order.php'</script>";

    

}



?>