$STH->execute();
         $STH->setFetchMode(PDO::FETCH_ASSOC);
         $a = $STH->fetch();
         if (!empty($a)) {
             do {
                 $_SESSION['tickets'][$_POST['id']]['status'] = $tkst;
             } while ($a = $STH->fetch());
             echo '<script>parent.$("#statustk").val(\'1\').change();</script>';
         }
         echo '<script>parent.noty({text: "Cannot Automatically Reopen ticket",type:"error",timeout:9000});</script>';
     } catch (PDOException $e) {
         file_put_contents('PDOErrors', "File: " . $e->getFile() . ' on line ' . $e->getLine() . "\nError: " . $e->getMessage() . "\n", FILE_APPEND);
         echo '<script>parent.noty({text: "Cannot Automatically Reopen ticket",type:"error",timeout:9000});</script>';
     }
 }
 $ip = retrive_ip();
 $date = date("Y-m-d H:i:s");
 //Update last reply
 $query = "UPDATE " . $SupportTicketsTable . " SET last_reply=? WHERE id=?";
 $STH = $DBH->prepare($query);
 $STH->bindParam(1, $date, PDO::PARAM_STR);
 $STH->bindParam(2, $_POST['id'], PDO::PARAM_INT);
 $STH->execute();
 //Insert new message
 $query = "INSERT INTO " . $SupportMessagesTable . "(`user_id`,`message`,`ticket_id`,`ip_address`,`created_time`) VALUES (?,?,?,?,?);";
 $STH = $DBH->prepare($query);
 $STH->bindParam(1, $_SESSION['id'], PDO::PARAM_INT);
 $STH->bindParam(2, $_POST['message'], PDO::PARAM_STR);
 $STH->bindParam(3, $_POST['id'], PDO::PARAM_INT);
 $STH->bindParam(4, $ip, PDO::PARAM_STR);
 $STH->bindParam(5, $date, PDO::PARAM_STR);
if (!isset($_SESSION['status'])) {
    $_SESSION['redirect_url'] = curPageURL();
    header("location: ../index.php");
    exit;
}
if (isset($_SESSION['time']) && time() - $_SESSION['time'] <= 1800) {
    $_SESSION['time'] = time();
} else {
    if (isset($_SESSION['id']) && !isset($_SESSION['time']) || isset($_SESSION['time']) && time() - $_SESSION['time'] > 1800) {
        session_unset();
        session_destroy();
        header("location: ../index.php?e=expired");
        exit;
    }
}
if (isset($_SESSION['ip']) && $_SESSION['ip'] != retrive_ip()) {
    session_unset();
    session_destroy();
    header("location: ../index.php?e=local");
    exit;
}
if (!isset($_SESSION['status']) || $_SESSION['status'] > 2) {
    header("location: ../index.php");
    exit;
}
if (!isset($_SESSION['token']['act'])) {
    $_SESSION['token']['act'] = random_token(7);
}
include_once '../php/config/database.php';
if (is_file('../php/config/setting.txt')) {
    $setting = file('../php/config/setting.txt', FILE_IGNORE_NEW_LINES);