<?php

    session_start();

    require './connect.php';
    require './SendEmail.php';

    if(!isset($_POST['order_id'])) {
        header("Location: ./PendingOrders.php");
        die();
    }

    $res = mysqli_query($conn, "SELECT * FROM orders WHERE id={$_POST['order_id']};");

    if(mysqli_num_rows($res) >= 1) {
        $row = $res->fetch_assoc();
        mysqli_query($conn, "UPDATE orders SET status = 'x' WHERE id={$_POST['order_id']}");
        $email = mysqli_query($conn, "SELECT email FROM users WHERE user_id={$row['user_id']}")->fetch_assoc()['email'];
        SendMail($email, "InnovaDB Update\n", "Your order with id({$row['id']}) has been DISCARDED\n");
    }

    header("Location: ./PendingOrders.php");
    die();
?>