<?php
include "../../root.class.php";
$db = new db_safeguard();

var_dump($_POST);

$date = date("Y-m-d H:i", strtotime("+2 Hours"));
$index = 1;
while ($index <= count($_POST) + 2) {

    if ($_POST['log_' . $index] != '') {
        echo $_POST['log_' . $index];
        $db->query("work_order_logs", "INSERT INTO `work_order_logs`(`work_order_id`, `log`, `user_id`,`date_time`) VALUES ({$_POST['work_order_id']},'{$_POST['log_' . $index . '']}',{$_SESSION['user_id']},'$date')");
    }


    $index++;
}
$index = 1;
while ($index <= count($_POST) + 2) {

    if ($_POST['resource_' . $index] != '') {
        echo $_POST['resource_' . $index];
        $db->query("work_order_resources", "INSERT INTO `work_order_resources`(`type`, `link`, `user_id`, `date_time`, `work_order_id`, `name`) VALUES ('FILE','{$_POST['file_' . $index]}',{$_SESSION['user_id']},'$date',{$_POST['work_order_id']},'{$_POST['resource_' . $index]}')");

    }


    $index++;
}
echo " <script> window.location.href = 'work_order.php?record_id={$_POST['work_order_id']}'; </script> ";
