<?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 server_copy where id = (:id) LIMIT 1";
$orderInfoQuery = $dbh->prepare($orderInfoSql);
$orderInfoQuery->bindParam(':id',$id,PDO::PARAM_STR);
$orderInfoQuery->execute();


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

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

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

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