<?php
include $_SERVER['DOCUMENT_ROOT'] . '/classes/autoload.php';
$order_id = $_POST['record_id'];
$clause = str_replace('"', '', $_POST['clause']);
$description = str_replace('"', '', $_POST['description']);
$clause = str_replace("'", '', $clause);
$description = str_replace("'", '', $description);
$db->query("orders", "UPDATE orders SET `user_id` = '{$_SESSION['user_id']}', `clause` = '$clause', `description` = '$description', `order_date` = '{$_POST['order_date']}',`user_id` = {$_SESSION['user_id']} WHERE record_id = '{$_POST['record_id']}'");


$db->query("order_checklist", "DELETE FROM order_checklist WHERE `order_id` = '$order_id'");
$stokc_items_arr = $_POST['list'];
$index = 0;
foreach ($stokc_items_arr as $item_name) {
    if (empty($item_name))
        continue;
    $db->query("order_checklist", "INSERT INTO order_checklist (`order_id`,`text`) VALUES('$order_id','$item_name')");
    $index++;
}
header("location:home.php");