<?php 
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include('../include/auth.php');
include('../include/lskfjwfe.php');
include('../include/header.php');
$fid=$_GET['id'];
$user=$userid;
if (isset($_POST['task_name'])) {
        //variables to hold our submitted data with post     
       
        $fid=$_POST['fid'];
        $dateTimeZone = new DateTimeZone("Europe/Athens");
        $dateTime = new DateTime("now", $dateTimeZone);
        $timeOffset = $dateTimeZone->getOffset($dateTime);
        $date = time() + $timeOffset;

        $task_name=$_POST['task_name'];
        $task_status=$_POST['task_status'];
        $task_seen=$_POST['task_seen'];
        $task_to=$_POST['task_to'];
        $task_details=$_POST['task_details'];
        $task_start_date=$_POST['task_start_date'];
        $task_start_time=$_POST['task_start_time'];
        $task_end_date=$_POST['task_end_date'];
        $task_end_time=$_POST['task_end_time'];
        $task_allday=$_POST['task_allday'];
       
if($task_status=='1'){
    $completed=$date;
}
   else{$completed='0';} 

        $db3->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        
        try {
            $db3->beginTransaction();
        
            $sh = $db3->prepare("UPDATE tasks SET task_status=?, task_seen=?, task_completed=?, task_name=?, task_to=?, task_details=?, task_start_date=?, task_start_time=?, task_end_date=?, task_end_time=?, task_allday=? WHERE task_id=? ");
            $sh->execute([$task_status, $task_seen, $completed, $task_name, $task_to, $task_details, $task_start_date, $task_start_time, $task_end_date, $task_end_time, $task_allday, $fid]);
        
            $db3->commit();
            echo "<div class='alert alert-success'>Record Updated Succesfully</div><script>";
            echo "window.history.go(-1);";
         echo "</script>";;
        } catch ( Exception $e ) {
            $db3->rollBack();
            echo "<div class='alert alert-danger'>Error updating record: </div>" . $e->getMessage();
        }
        $db3= null;
} ?>      