<?php include "../../root.class.php";
$html = new html();
$db = new db_safeguard();

// var_dump($_POST);

//trim action date and remove the T with a blank space
$action_date = $_POST['action_date'] = str_replace("T", " ", $_POST['action_date']);

// echo $action_date;

// echo "<br><br>";

// echo "UPDATE `jobcards` SET `jc_no`='{$_POST['jc_no']}',`action_date`='{$action_date}',`contact_number`='{$_POST['contact_number']}',`other_number`='{$_POST['other_number']}',`alternate_number`='{$_POST['alternate_number']}',`client_name`='{$_POST['client_name']}',`contact_name`='{$_POST['contact_name']}',`address`='{$_POST['address']}',`user_id`='{$_SESSION['user_id']}', `team_assigned_id`='{$_POST['team_assigned_id']}' WHERE record_id = '{$_POST['record_id']}'";

$update_jobcard = $db->query("jobcards", "UPDATE `jobcards` SET `jc_no`='{$_POST['jc_no']}',`action_date`='{$action_date}',`contact_number`='{$_POST['contact_number']}',`other_number`='{$_POST['other_number']}',`alternate_number`='{$_POST['alternate_number']}',`client_name`='{$_POST['client_name']}',`contact_name`='{$_POST['contact_name']}',`address`='{$_POST['address']}',`user_id`='{$_SESSION['user_id']}', `team_assigned_id`='{$_POST['team_assigned_id']}' WHERE record_id = '{$_POST['record_id']}'");

// echo "<br><br>";

$work_data = $db->query("", "SELECT * FROM `work_requests` where jc_no = '{$_POST['jc_no']}'");
$work = $work_data->fetch_assoc();

// echo "SELECT * FROM `work_requests` where jc_no = '{$_POST['jc_no']}'";

// echo "<br><br>";

// echo "UPDATE `work_requests` SET `jc_no`='{$_POST['jc_no']}',`contact_number`='{$_POST['contact_number']}',`other_number`='{$_POST['other_number']}',`alternate_number`='{$_POST['alternate_number']}',`address`='{$_POST['address']}',`user_id`='{$_SESSION['user_id']}', `team_id`='{$_POST['team_assigned_id']}' WHERE record_id = '{$work['record_id']}'";

$update_jobcard = $db->query("work_requests", "UPDATE `work_requests` SET `jc_no`='{$_POST['jc_no']}',`contact_number`='{$_POST['contact_number']}',`other_number`='{$_POST['other_number']}',`alternate_number`='{$_POST['alternate_number']}',`address`='{$_POST['address']}',`user_id`='{$_SESSION['user_id']}', `team_id`='{$_POST['team_assigned_id']}' WHERE record_id = '{$work['record_id']}'");


?>

<script>alert("UPDATED SUCCESSFULLY");</script>

<?php
echo "<script>window.location.href = '../jobcards/lead_home.php';</script>";