<?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');

$user=$userid;
if (isset($_POST['task_name'])) {
        //variables to hold our submitted data with post     
       
      
        $dateTimeZone = new DateTimeZone("Europe/Athens");
        $dateTime = new DateTime("now", $dateTimeZone);
        $timeOffset = $dateTimeZone->getOffset($dateTime);
        $date = time() + $timeOffset;

        $task_name=$_POST['task_name'];
        $task_status="0";
        $task_seen="0";
        $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("INSERT INTO tasks (task_id, task_name, task_start_date, task_start_time, task_end_date, task_end_time, task_allday, task_from, task_to, task_seen, task_status, task_details, task_ts, task_completed) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )");
            $sh->execute([NULL, $task_name, $task_start_date, $task_start_time, $task_end_date, $task_end_time, $task_allday, $user, $task_to, $task_seen, $task_status, $task_details, $date, $completed]);
            $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;
} ?>      