<?php
session_start();
error_reporting(0);
include('includes/config.php');
if (strlen($_SESSION['adminlogin']) == 0) {
	header('location:index.php');
    die();
}

if(!isset($_GET['id']) || empty($_GET['id']) || !is_numeric($_GET['id'])){
    header('location: signDash.php?noid');
    die();
}

$id = $_GET['id'];
//get order info
$orderInfoSql = "SELECT * FROM sign where id = (:id) LIMIT 1";
$orderInfoQuery = $dbh->prepare($orderInfoSql);
$orderInfoQuery->bindParam(':id',$id,PDO::PARAM_STR);
$orderInfoQuery->execute();


if($orderInfoQuery->rowCount() <= 0){
    header('location: signDash.php?OrderNotFound');
    die();
}
//get order info
$orderInfoDetail = $orderInfoQuery->fetchAll(PDO::FETCH_OBJ);

if($orderInfoDetail[0]->status == 0){
    header('location: signDash.php?notDeletable');
    die();
}

// change status for deleted
$sqlForUpdate = "UPDATE sign SET status = 0 WHERE `sign`.`id` = (:id)";
$queryForUpdate = $dbh->prepare($sqlForUpdate);
$queryForUpdate->bindParam(':id',$id,PDO::PARAM_INT);
$queryForUpdate->execute();

//unlink file
unlink('sainCopy/'.$orderInfoDetail[0]->url);
//redirect
header('location: signDash.php?success');
    die();