
<?php
session_start();
session_regenerate_id(true);
require_once '../config.php';
require_once '../functions/enDecpt.php';


// $users_name=  $_SESSION['current_session']['user']['firstname'];
$id = $_GET['id'];
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$therapy = $_POST['therapy'];
$date = $_POST['appointment'];
$status = $_POST['status'];

$dbHandler = DbHandler();

if (isset($_SESSION['admin'])) {

    $sql = $dbHandler->prepare("UPDATE tbl_consultation SET a_fullname = ?, a_email = ?, a_phone = ?,
        a_therapy = ?, a_date = ?, a_status = ? WHERE id = ?");

    if (isset($_POST['submit']) != "") {
        // echo "<script>alert('we dey here')</script>";
            // echo "<script>alert('File is empty');</script>";
            $updateArticleTable = $sql->execute([$name, $email, $phone, $therapy, $date, $status, base64_url_decode($id)]);
            if ($updateArticleTable) {

                $_SESSION['success'] = "Consultation record has been updated";
                // echo "<script>alert('upload without picture in progress!')</script>";
                echo "<script>window.location='../consultation/consultation-manager.php'</script>";
            } else {
                $_SESSION['error'] = "Record does not exist!";
                // $errors[] = "Record does not exist!";
            }
            // exit();
    }
} else {
    echo "<script> window.location.assign('./logout.php'); </script>";
}
?>