fixing bugs in reservation system, fixing error messages, checking if print has been started from other location
This commit is contained in:
@@ -83,9 +83,28 @@ while (mysqli_stmt_fetch($stmt)) {
|
|||||||
$printer["print_status"]="Abgebrochen";
|
$printer["print_status"]="Abgebrochen";
|
||||||
$printer["full_file"]=$json["job"]["file"]["name"];
|
$printer["full_file"]=$json["job"]["file"]["name"];
|
||||||
$printer["view"]=2;
|
$printer["view"]=2;
|
||||||
}else if($system_status==0){
|
}/*else if($system_status==0){
|
||||||
$printer["print_status"]="Bereit";
|
$printer["print_status"]="Bereit";
|
||||||
$printer["view"]=3;
|
$printer["view"]=3;
|
||||||
|
}*/else if(($is_free == 1 && $system_status==0) or $system_status==99){ //check if a print has been started from another location
|
||||||
|
exec("curl --max-time 10 $url/api/job?apikey=$apikey > /var/www/html/user_files/" . $_SESSION["username"] . "/json.json");
|
||||||
|
$fg = file_get_contents("/var/www/html/user_files/" . $_SESSION["username"] . "/json.json");
|
||||||
|
$json = json_decode($fg, true);
|
||||||
|
if($json['state']=="Printing" or $system_status==99){
|
||||||
|
$printer["printer_status"]="Von anderer Quelle aus gestartet.";
|
||||||
|
$printer["progress"] = (int) $json['progress']['completion'];
|
||||||
|
$printer["file"] = short_path($json["job"]["file"]["name"], 10, 10);
|
||||||
|
$printer["full_file"]=$json["job"]["file"]["name"];
|
||||||
|
$printer["print_time_total"] = seconds_to_time(intval($json["job"]["estimatedPrintTime"]));
|
||||||
|
$printer["print_time_left"] = seconds_to_time(intval($json["progress"]["printTimeLeft"]));
|
||||||
|
$printer["print_time"] = seconds_to_time(intval($json["progress"]["printTime"]));
|
||||||
|
$printer["view"]=0;
|
||||||
|
//insert into db that this one is printing
|
||||||
|
$sql="UPDATE printer SET system_status=99 WHERE id = $printer_id";
|
||||||
|
}else{
|
||||||
|
$printer["print_status"]="Bereit";
|
||||||
|
$printer["view"]=3;
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
$printer["print_status"]="Problem / Nicht betriebsbereit";
|
$printer["print_status"]="Problem / Nicht betriebsbereit";
|
||||||
$printer["view"]=4;
|
$printer["view"]=4;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
date_default_timezone_set('Europe/Zurich');
|
||||||
function extract_param($gcode) {
|
function extract_param($gcode) {
|
||||||
// Match the pattern S followed by digits, capturing the digits
|
// Match the pattern S followed by digits, capturing the digits
|
||||||
$matches = [];
|
$matches = [];
|
||||||
@@ -54,44 +55,147 @@ function find_print_time($file) {
|
|||||||
return $time;
|
return $time;
|
||||||
}
|
}
|
||||||
|
|
||||||
function is_time_between($startTime, $endTime, $checkTime) {
|
function check_reservation_conflict($link, $class) {
|
||||||
// Convert times to timestamps
|
$reservation_conflict = false;
|
||||||
$startTimestamp = strtotime($startTime);
|
$today = date("Y-m-d");
|
||||||
$endTimestamp = strtotime($endTime);
|
$time_now = date("H:i");
|
||||||
$checkTimestamp = strtotime($checkTime);
|
$for_class = [];
|
||||||
|
|
||||||
// If end time is less than start time, it means the range crosses midnight
|
// Query for reservations that start today or extend into today
|
||||||
if ($endTimestamp < $startTimestamp) {
|
$sql = "
|
||||||
// Check if the time is between start time and midnight or between midnight and end time
|
SELECT day, time_from, time_to, for_class
|
||||||
return ($checkTimestamp >= $startTimestamp || $checkTimestamp <= $endTimestamp);
|
FROM reservations
|
||||||
} else {
|
WHERE day <= '$today' AND
|
||||||
// Normal case: check if the time is between start and end time
|
(day = '$today' AND time_from <= '$time_now' OR day < '$today');
|
||||||
return ($checkTimestamp >= $startTimestamp && $checkTimestamp <= $endTimestamp);
|
";
|
||||||
|
$stmt = $link->prepare($sql);
|
||||||
|
$stmt->execute();
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
|
||||||
|
while ($row = $result->fetch_assoc()) {
|
||||||
|
// Calculate the actual end time of the reservation
|
||||||
|
$reservation_end = strtotime($row["day"] . " " . $row["time_to"]);
|
||||||
|
$current_time = strtotime("$today $time_now");
|
||||||
|
|
||||||
|
if ($current_time <= $reservation_end) {
|
||||||
|
$reservation_conflict = true;
|
||||||
|
$for_class[] = $row["for_class"];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default value for for_class if no conflicts are found
|
||||||
|
if (empty($for_class)) {
|
||||||
|
$for_class[] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine the appropriate response based on the conflict status
|
||||||
|
$response = ['conflict' => $reservation_conflict, 'block' => false, 'message' => ''];
|
||||||
|
|
||||||
|
if ($reservation_conflict && !in_array($class, $for_class) && $class != 0) {
|
||||||
|
$response['block'] = true;
|
||||||
|
$response['message'] = "
|
||||||
|
<center>
|
||||||
|
<div style='width:50%' class='alert alert-danger' role='alert'>
|
||||||
|
Die Drucker sind zurzeit reserviert! Bitte versuche es später erneut!
|
||||||
|
</div>
|
||||||
|
</center>";
|
||||||
|
} elseif ($class == 0 && $reservation_conflict) {
|
||||||
|
$response['message'] = "
|
||||||
|
<center>
|
||||||
|
<div style='width:50%' class='alert alert-danger' role='alert'>
|
||||||
|
Die Drucker sind zurzeit reserviert!<br>
|
||||||
|
Als Lehrperson können Sie zwar jetzt trotzdem drucken, sollten es aber nur tun,
|
||||||
|
wenn Sie sicher sind, dass nicht gerade eine andere Lehrperson mit einer Klasse drucken will!
|
||||||
|
</div>
|
||||||
|
</center>";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
function time_to_seconds($print_time) {
|
function check_print_reservation_conflict($link, $class, $path) {
|
||||||
$seconds = 0;
|
$reservation_conflict = false;
|
||||||
|
$for_class = [];
|
||||||
|
$today = date("Y-m-d");
|
||||||
|
$time_now = date("H:i");
|
||||||
|
|
||||||
if (preg_match('/(\d+)h/', $print_time, $matches)) {
|
// Calculate the end time of the print
|
||||||
$seconds += $matches[1] * 3600; // hours to seconds
|
$print_time = find_print_time($path); // Assume this function is already defined
|
||||||
}
|
preg_match('/(\d+)h/', $print_time, $hours_match);
|
||||||
if (preg_match('/(\d+)m/', $print_time, $matches)) {
|
preg_match('/(\d+)m/', $print_time, $minutes_match);
|
||||||
$seconds += $matches[1] * 60; // minutes to seconds
|
$hours = isset($hours_match[1]) ? (int)$hours_match[1] : 0;
|
||||||
}
|
$minutes = isset($minutes_match[1]) ? (int)$minutes_match[1] : 0;
|
||||||
if (preg_match('/(\d+)s/', $print_time, $matches)) {
|
//echo("uses ".$minutes." Minutes and ".$hours." hours");
|
||||||
$seconds += $matches[1]; // seconds
|
$start_time = DateTime::createFromFormat('H:i', $time_now);
|
||||||
|
$end_time = clone $start_time;
|
||||||
|
$end_time->modify("+{$hours} hour");
|
||||||
|
$end_time->modify("+{$minutes} minutes");
|
||||||
|
|
||||||
|
// Query to get all relevant reservations (today and future overlaps)
|
||||||
|
$sql = "
|
||||||
|
SELECT day, time_from, time_to, for_class
|
||||||
|
FROM reservations
|
||||||
|
WHERE day >= '$today';
|
||||||
|
";
|
||||||
|
$stmt = $link->prepare($sql);
|
||||||
|
$stmt->execute();
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
|
||||||
|
// Check for conflicts with reservations
|
||||||
|
while ($row = $result->fetch_assoc()) {
|
||||||
|
$reservation_start = DateTime::createFromFormat('Y-m-d H:i', $row["day"] . ' ' . $row["time_from"]);
|
||||||
|
$reservation_end = DateTime::createFromFormat('Y-m-d H:i', $row["day"] . ' ' . $row["time_to"]);
|
||||||
|
|
||||||
|
// Adjust reservation end time for multi-day overlaps
|
||||||
|
if ($reservation_end < $reservation_start) {
|
||||||
|
$reservation_end->modify('+1 day');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $seconds;
|
// Check if the print overlaps with any reservation period
|
||||||
|
if ($start_time < $reservation_end && $end_time > $reservation_start) {
|
||||||
|
$reservation_conflict = true;
|
||||||
|
$for_class[] = $row["for_class"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default value for for_class if no conflicts are found
|
||||||
|
if (empty($for_class)) {
|
||||||
|
$for_class[] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build response based on conflict and user access
|
||||||
|
$response = ['conflict' => $reservation_conflict, 'block' => false, 'message' => ''];
|
||||||
|
|
||||||
|
if ($reservation_conflict && !in_array($class, $for_class) && $class != 0) {
|
||||||
|
$response['block'] = true;
|
||||||
|
$response['message'] = "
|
||||||
|
<center>
|
||||||
|
<div style='width:50%' class='alert alert-danger' role='alert'>
|
||||||
|
Die Drucker sind zurzeit reserviert! Bitte versuche es später erneut!
|
||||||
|
</div>
|
||||||
|
</center>";
|
||||||
|
} elseif ($class == 0 && $reservation_conflict) {
|
||||||
|
$response['message'] = "
|
||||||
|
<center>
|
||||||
|
<div style='width:50%' class='alert alert-danger' role='alert'>
|
||||||
|
Die Drucker sind zurzeit reserviert!<br>
|
||||||
|
Als Lehrperson können Sie zwar jetzt trotzdem drucken, sollten es aber nur tun,
|
||||||
|
wenn Sie sicher sind, dass nicht gerade eine andere Lehrperson mit einer Klasse drucken will!
|
||||||
|
</div>
|
||||||
|
</center>";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html data-bs-theme="dark">
|
<html data-bs-theme="dark">
|
||||||
<?php
|
<?php
|
||||||
// Initialize the session
|
// Initialize the session
|
||||||
$warning=false;
|
$warning=false;
|
||||||
|
//error / success messages are stored here and then shown in the modal
|
||||||
|
$global_err="";
|
||||||
|
$global_success="";
|
||||||
session_start();
|
session_start();
|
||||||
include "../config/config.php";
|
include "../config/config.php";
|
||||||
require_once "../log/log.php";
|
require_once "../log/log.php";
|
||||||
@@ -128,20 +232,17 @@ function time_to_seconds($print_time) {
|
|||||||
?>
|
?>
|
||||||
|
|
||||||
<?php $userid=$_SESSION["id"]; ?>
|
<?php $userid=$_SESSION["id"]; ?>
|
||||||
<?php echo(" <body style='background-color:$color'> ");?>
|
<body>
|
||||||
<div id="content"></div>
|
<div id="content"></div>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<title>Datei drucken</title>
|
<title>Datei drucken</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<br><br>
|
<br><br>
|
||||||
<?php
|
<?php
|
||||||
if(isset($_POST["printer"]))
|
if(isset($_POST["printer"]))
|
||||||
{
|
{
|
||||||
|
|
||||||
$status=0;
|
$status=0;
|
||||||
$free=0;
|
$free=0;
|
||||||
$url="";
|
$url="";
|
||||||
@@ -164,6 +265,7 @@ function time_to_seconds($print_time) {
|
|||||||
if(!in_array($filetype,$ok_ft))
|
if(!in_array($filetype,$ok_ft))
|
||||||
{
|
{
|
||||||
echo("<center><div style='width:50%' class='alert alert-danger' role='alert'>Dieser Dateityp wird nicht unterstüzt.</div></center>");
|
echo("<center><div style='width:50%' class='alert alert-danger' role='alert'>Dieser Dateityp wird nicht unterstüzt.</div></center>");
|
||||||
|
$global_err="Dieser Dateityp wird nicht unterstüzt.";
|
||||||
sys0_log("Could not upload file for ".$_SESSION["username"]." because of unknown file extension",$_SESSION["username"],"PRINT::UPLOAD::FILE::FAILED");//notes,username,type
|
sys0_log("Could not upload file for ".$_SESSION["username"]." because of unknown file extension",$_SESSION["username"],"PRINT::UPLOAD::FILE::FAILED");//notes,username,type
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -175,6 +277,7 @@ function time_to_seconds($print_time) {
|
|||||||
mysqli_stmt_execute($stmt);
|
mysqli_stmt_execute($stmt);
|
||||||
|
|
||||||
echo("<center><div style='width:50%' class='alert alert-success' role='alert'>Datei ". basename( $_FILES['file_upload']['name']). " wurde hochgeladen und an die Warteschlange gesendet</div></center>");
|
echo("<center><div style='width:50%' class='alert alert-success' role='alert'>Datei ". basename( $_FILES['file_upload']['name']). " wurde hochgeladen und an die Warteschlange gesendet</div></center>");
|
||||||
|
$global_success="Datei ". basename( $_FILES['file_upload']['name']). " wurde hochgeladen und an die Warteschlange gesendet";
|
||||||
sys0_log("user ".$_SESSION["username"]." uploaded ".basename($path)." to the queue",$_SESSION["username"],"PRINT::UPLOAD::QUEUE");//notes,username,type
|
sys0_log("user ".$_SESSION["username"]." uploaded ".basename($path)." to the queue",$_SESSION["username"],"PRINT::UPLOAD::QUEUE");//notes,username,type
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -196,7 +299,7 @@ function time_to_seconds($print_time) {
|
|||||||
mysqli_stmt_execute($stmt);
|
mysqli_stmt_execute($stmt);
|
||||||
|
|
||||||
|
|
||||||
echo("<center><div style='width:50%' class='alert alert-success' role='alert'>Datei ". basename( $_FILES['file_upload']['name']). " wurde hochgeladen und an die Warteschlange gesendet</div></center>");
|
echo("<center><div style='width:50%' class='alert alert-success' role='alert'>Datei ". basename( $_FILES['file_upload']['name']). " wurde an die Warteschlange gesendet</div></center>");
|
||||||
sys0_log("user ".$_SESSION["username"]." uploaded ".basename($path)." to the queue",$_SESSION["username"],"PRINT::UPLOAD::QUEUE");
|
sys0_log("user ".$_SESSION["username"]." uploaded ".basename($path)." to the queue",$_SESSION["username"],"PRINT::UPLOAD::QUEUE");
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -212,7 +315,6 @@ function time_to_seconds($print_time) {
|
|||||||
mysqli_stmt_fetch($stmt);
|
mysqli_stmt_fetch($stmt);
|
||||||
if($free!=1 or $status!=0)
|
if($free!=1 or $status!=0)
|
||||||
{
|
{
|
||||||
|
|
||||||
echo("<center><div style='width:50%' class='alert alert-danger' role='alert'>Der Drucker ist zur Zeit nicht verfügbar. Warte einen Moment oder versuche es mit einem anderen Drucker erneut.</div></center>");
|
echo("<center><div style='width:50%' class='alert alert-danger' role='alert'>Der Drucker ist zur Zeit nicht verfügbar. Warte einen Moment oder versuche es mit einem anderen Drucker erneut.</div></center>");
|
||||||
sys0_log("Could not start job for ".$_SESSION["username"]." with file ".basename($path)."",$_SESSION["username"],"PRINT::JOB::START::FAILED");//notes,username,type
|
sys0_log("Could not start job for ".$_SESSION["username"]." with file ".basename($path)."",$_SESSION["username"],"PRINT::JOB::START::FAILED");//notes,username,type
|
||||||
exit;
|
exit;
|
||||||
@@ -246,59 +348,16 @@ function time_to_seconds($print_time) {
|
|||||||
if(true){
|
if(true){
|
||||||
mysqli_stmt_close($stmt);
|
mysqli_stmt_close($stmt);
|
||||||
if(move_uploaded_file($_FILES['file_upload']['tmp_name'], $path)) {
|
if(move_uploaded_file($_FILES['file_upload']['tmp_name'], $path)) {
|
||||||
echo("<center><div style='width:50%' class='alert alert-success' role='alert'>Erfolg! Die Datei ". basename( $_FILES['file_upload']['name']). " wurde hochgeladen.</div></center>");
|
//echo("<center><div style='width:50%' class='alert alert-success' role='alert'>Erfolg! Die Datei ". basename( $_FILES['file_upload']['name']). " wurde hochgeladen.</div></center>");
|
||||||
echo("<center><div style='width:50%' class='alert alert-success' role='alert'>Datei wird an den 3D-Drucker gesendet...</div></center>");
|
//echo("<center><div style='width:50%' class='alert alert-success' role='alert'>Datei wird an den 3D-Drucker gesendet...</div></center>");
|
||||||
$print_time=find_print_time($path);
|
$response=check_print_reservation_conflict($link,$_SESSION["class_id"],$path);
|
||||||
//check if the printers are reserved at the time when this print finishes
|
$block=$response['block'];
|
||||||
date_default_timezone_set('Europe/Zurich');
|
|
||||||
$reservation_conflict = false;
|
|
||||||
$today = date("Y-m-d");
|
|
||||||
$time_now = date("H:i");
|
|
||||||
|
|
||||||
preg_match('/(\d+)h/', $print_time, $hours_match);
|
|
||||||
preg_match('/(\d+)m/', $print_time, $minutes_match);
|
|
||||||
$hours = isset($hours_match[1]) ? (int)$hours_match[1] : 0;
|
|
||||||
$minutes = isset($minutes_match[1]) ? (int)$minutes_match[1] : 0;
|
|
||||||
|
|
||||||
// Convert $now into a DateTime object and add hours and minutes
|
|
||||||
$time = DateTime::createFromFormat('H:i', $time_now);
|
|
||||||
$time->modify("+{$hours} hour");
|
|
||||||
$time->modify("+{$minutes} minutes");
|
|
||||||
|
|
||||||
// Format $time back into a string
|
|
||||||
$time_now = $time->format('H:i');
|
|
||||||
|
|
||||||
// Query to get reservations for the current day
|
|
||||||
$sql = "SELECT time_from, time_to, for_class FROM reservations WHERE day='$today';";
|
|
||||||
$stmt = $link->prepare($sql);
|
|
||||||
$stmt->execute();
|
|
||||||
$result = $stmt->get_result();
|
|
||||||
|
|
||||||
while ($row = $result->fetch_assoc()) {
|
|
||||||
// Check for overlap with the entire print time period
|
|
||||||
if (is_time_between($row["time_from"], $row["time_to"], $time_now)) {
|
|
||||||
$reservation_conflict = true;
|
|
||||||
$for_class[] = $row["for_class"];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure $for_class is set if no conflicts were found
|
|
||||||
if (!isset($for_class)) {
|
|
||||||
$for_class[] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Display conflict message if necessary
|
|
||||||
if ($reservation_conflict && !in_array($class, $for_class) && $class != 0) {
|
|
||||||
$block = true;
|
|
||||||
} else {
|
|
||||||
$block = false;
|
|
||||||
}
|
|
||||||
if($block==false){
|
if($block==false){
|
||||||
if(check_file($path) or isset($_POST["ignore_unsafe"])){
|
if(check_file($path) or isset($_POST["ignore_unsafe"])){
|
||||||
exec('curl -k -H "X-Api-Key: '.$apikey.'" -F "select=true" -F "print=true" -F "file=@'.$path.'" "'.$printer_url.'/api/files/local" > /var/www/html/user_files/'.$username.'/json.json');
|
exec('curl -k -H "X-Api-Key: '.$apikey.'" -F "select=true" -F "print=true" -F "file=@'.$path.'" "'.$printer_url.'/api/files/local" > /var/www/html/user_files/'.$username.'/json.json');
|
||||||
//file is on printer and ready to be printed
|
//file is on printer and ready to be printed
|
||||||
$userid=$_SESSION["id"];
|
$userid=$_SESSION["id"];
|
||||||
echo("<center><div style='width:50%' class='alert alert-success' role='alert'>Datei gesendet und Auftrag wurde gestartet.</div></center>");
|
// echo("<center><div style='width:50%' class='alert alert-success' role='alert'>Datei gesendet und Auftrag wurde gestartet.</div></center>");
|
||||||
sys0_log("user ".$_SESSION["username"]." uploaded ".basename($path)." to printer ".$_POST["printer"]."",$_SESSION["username"],"PRINT::UPLOAD::PRINTER");//notes,username,type
|
sys0_log("user ".$_SESSION["username"]." uploaded ".basename($path)." to printer ".$_POST["printer"]."",$_SESSION["username"],"PRINT::UPLOAD::PRINTER");//notes,username,type
|
||||||
$fg=file_get_contents("/var/www/html/user_files/$username/json.json");
|
$fg=file_get_contents("/var/www/html/user_files/$username/json.json");
|
||||||
$json=json_decode($fg,true);
|
$json=json_decode($fg,true);
|
||||||
@@ -317,6 +376,7 @@ function time_to_seconds($print_time) {
|
|||||||
$stmt = mysqli_prepare($link, $sql);
|
$stmt = mysqli_prepare($link, $sql);
|
||||||
mysqli_stmt_execute($stmt);
|
mysqli_stmt_execute($stmt);
|
||||||
mysqli_stmt_close($stmt);
|
mysqli_stmt_close($stmt);
|
||||||
|
echo("<center><div style='width:50%' class='alert alert-success' role='alert'>Datei gesendet und der Auftrag wurde gestartet.</div></center>");
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
$warning=true;
|
$warning=true;
|
||||||
@@ -353,57 +413,15 @@ function time_to_seconds($print_time) {
|
|||||||
if(true){
|
if(true){
|
||||||
mysqli_stmt_close($stmt);
|
mysqli_stmt_close($stmt);
|
||||||
|
|
||||||
echo("<center><div style='width:50%' class='alert alert-success' role='alert'>Datei wird an den 3D-Drucker gesendet...</div></center>");
|
//echo("<center><div style='width:50%' class='alert alert-success' role='alert'>Datei wird an den 3D-Drucker gesendet...</div></center>");
|
||||||
$print_time=find_print_time($path);
|
$response=check_print_reservation_conflict($link,$_SESSION["class_id"],$path);
|
||||||
date_default_timezone_set('Europe/Zurich');
|
$block=$response['block'];
|
||||||
$reservation_conflict = false;
|
|
||||||
$today = date("Y-m-d");
|
|
||||||
$time_now = date("H:i");
|
|
||||||
|
|
||||||
preg_match('/(\d+)h/', $print_time, $hours_match);
|
|
||||||
preg_match('/(\d+)m/', $print_time, $minutes_match);
|
|
||||||
$hours = isset($hours_match[1]) ? (int)$hours_match[1] : 0;
|
|
||||||
$minutes = isset($minutes_match[1]) ? (int)$minutes_match[1] : 0;
|
|
||||||
|
|
||||||
// Convert $now into a DateTime object and add hours and minutes
|
|
||||||
$time = DateTime::createFromFormat('H:i', $time_now);
|
|
||||||
$time->modify("+{$hours} hour");
|
|
||||||
$time->modify("+{$minutes} minutes");
|
|
||||||
|
|
||||||
// Format $time back into a string
|
|
||||||
$time_now = $time->format('H:i');
|
|
||||||
|
|
||||||
// Query to get reservations for the current day
|
|
||||||
$sql = "SELECT time_from, time_to, for_class FROM reservations WHERE day='$today';";
|
|
||||||
$stmt = $link->prepare($sql);
|
|
||||||
$stmt->execute();
|
|
||||||
$result = $stmt->get_result();
|
|
||||||
|
|
||||||
while ($row = $result->fetch_assoc()) {
|
|
||||||
// Check for overlap with the entire print time period
|
|
||||||
if (is_time_between($row["time_from"], $row["time_to"], $time_now)) {
|
|
||||||
$reservation_conflict = true;
|
|
||||||
$for_class[] = $row["for_class"];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure $for_class is set if no conflicts were found
|
|
||||||
if (!isset($for_class)) {
|
|
||||||
$for_class[] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Display conflict message if necessary
|
|
||||||
if ($reservation_conflict && !in_array($class, $for_class) && $class != 0) {
|
|
||||||
$block = true;
|
|
||||||
} else {
|
|
||||||
$block = false;
|
|
||||||
}
|
|
||||||
if($block==false){
|
if($block==false){
|
||||||
if(check_file($path) or isset($_POST["ignore_unsafe"])){
|
if(check_file($path) or isset($_POST["ignore_unsafe"])){
|
||||||
exec('curl -k -H "X-Api-Key: '.$apikey.'" -F "select=true" -F "print=true" -F "file=@'.$path.'" "'.$printer_url.'/api/files/local" > /var/www/html/user_files/'.$username.'/json.json');
|
exec('curl -k -H "X-Api-Key: '.$apikey.'" -F "select=true" -F "print=true" -F "file=@'.$path.'" "'.$printer_url.'/api/files/local" > /var/www/html/user_files/'.$username.'/json.json');
|
||||||
//file is on printer and ready to be printed
|
//file is on printer and ready to be printed
|
||||||
$userid=$_SESSION["id"];
|
$userid=$_SESSION["id"];
|
||||||
echo("<center><div style='width:50%' class='alert alert-success' role='alert'>Datei gesendet und Auftrag wurde gestartet.</div></center>");
|
//echo("<center><div style='width:50%' class='alert alert-success' role='alert'>Datei gesendet und Auftrag wurde gestartet.</div></center>");
|
||||||
sys0_log("user ".$_SESSION["username"]." uploaded ".basename($path)." to printer ".$_POST["printer"]."",$_SESSION["username"],"PRINT::UPLOAD::PRINTER");//notes,username,type
|
sys0_log("user ".$_SESSION["username"]." uploaded ".basename($path)." to printer ".$_POST["printer"]."",$_SESSION["username"],"PRINT::UPLOAD::PRINTER");//notes,username,type
|
||||||
$fg=file_get_contents("/var/www/html/user_files/$username/json.json");
|
$fg=file_get_contents("/var/www/html/user_files/$username/json.json");
|
||||||
$json=json_decode($fg,true);
|
$json=json_decode($fg,true);
|
||||||
@@ -422,6 +440,7 @@ function time_to_seconds($print_time) {
|
|||||||
$stmt = mysqli_prepare($link, $sql);
|
$stmt = mysqli_prepare($link, $sql);
|
||||||
mysqli_stmt_execute($stmt);
|
mysqli_stmt_execute($stmt);
|
||||||
mysqli_stmt_close($stmt);
|
mysqli_stmt_close($stmt);
|
||||||
|
echo("<center><div style='width:50%' class='alert alert-success' role='alert'>Datei gesendet und Auftrag wurde gestartet.</div></center>");
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
$warning=true;
|
$warning=true;
|
||||||
@@ -444,35 +463,9 @@ function time_to_seconds($print_time) {
|
|||||||
<h1>Datei drucken</h1>
|
<h1>Datei drucken</h1>
|
||||||
<!-- Reservations notice -->
|
<!-- Reservations notice -->
|
||||||
<?php
|
<?php
|
||||||
date_default_timezone_set('Europe/Zurich');
|
$response=check_reservation_conflict($link,$_SESSION["class_id"]);
|
||||||
$reservation_conflict=false;
|
echo($response['message']);
|
||||||
$today=date("Y-m-d");
|
$block=$response['block'];
|
||||||
$sql="select time_from, time_to, for_class from reservations where day='$today';";
|
|
||||||
$stmt = $link->prepare($sql);
|
|
||||||
$stmt->execute();
|
|
||||||
$result = $stmt->get_result();
|
|
||||||
//$row = $result->fetch_assoc();
|
|
||||||
$time_now=date("H:i");
|
|
||||||
|
|
||||||
while ($row = $result->fetch_assoc()) {
|
|
||||||
if (is_time_between($row["time_from"], $row["time_to"], $time_now)) {
|
|
||||||
$reservation_conflict = true;
|
|
||||||
$for_class[]=$row["for_class"];
|
|
||||||
//break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!isset($for_class))
|
|
||||||
$for_class[]=0;
|
|
||||||
if ($reservation_conflict && !in_array($class,$for_class) && $class!=0) {
|
|
||||||
echo "<center><div style='width:50%' class='alert alert-danger' role='alert'>Die Drucker sind zurzeit reserviert! Bitte versuche es später erneut!</div></center>";
|
|
||||||
$block=true;
|
|
||||||
}else if($class==0 && $reservation_conflict){
|
|
||||||
$block=false;
|
|
||||||
echo "<center><div style='width:50%' class='alert alert-danger' role='alert'>Die Drucker sind zurzeit reserviert!<br>Als Lehrperson können Sie zwar jetzt trozdem drucken, sollten es aber nur tun, wenn Sie sicher sind, dass nicht gerade eine andere Lehrperson mit einer Klasse drucken will!</div></center>";
|
|
||||||
}else{
|
|
||||||
$block=false;
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<div class="container d-flex align-items-center justify-content-center" >
|
<div class="container d-flex align-items-center justify-content-center" >
|
||||||
|
|
||||||
@@ -482,7 +475,7 @@ function time_to_seconds($print_time) {
|
|||||||
echo('<div class="custom-file">');
|
echo('<div class="custom-file">');
|
||||||
|
|
||||||
echo('<label for="file_upload" class="form-label">Zu druckende Datei</label>');
|
echo('<label for="file_upload" class="form-label">Zu druckende Datei</label>');
|
||||||
echo('<input type="file" class="form-control" type="file" name="file_upload" required accept=".gcode"> ');
|
echo('<input type="file" class="form-control" type="file" id="file_upload" name="file_upload" required accept=".gcode"> ');
|
||||||
echo('</div>');
|
echo('</div>');
|
||||||
echo('</div>');
|
echo('</div>');
|
||||||
}
|
}
|
||||||
@@ -564,7 +557,6 @@ function time_to_seconds($print_time) {
|
|||||||
echo('<label class="my-3" for="printer">Auf diesem Drucker wird deine Datei gedruckt, sobald er frei ist.</label>');
|
echo('<label class="my-3" for="printer">Auf diesem Drucker wird deine Datei gedruckt, sobald er frei ist.</label>');
|
||||||
echo('<select class="form-control selector" name="queue_printer" required>');
|
echo('<select class="form-control selector" name="queue_printer" required>');
|
||||||
|
|
||||||
|
|
||||||
//get number of printers
|
//get number of printers
|
||||||
$num_of_printers=0;
|
$num_of_printers=0;
|
||||||
$sql="select count(*) from printer where system_status=0";
|
$sql="select count(*) from printer where system_status=0";
|
||||||
@@ -658,17 +650,60 @@ function time_to_seconds($print_time) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
<div class="modal fade" id="warningModal" tabindex="-1" aria-labelledby="warningModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="warningModalLabel">Achtung!</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body" id="warningModalMessage">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="footer"></div>
|
<div id="footer"></div>
|
||||||
<script>
|
<script>
|
||||||
function show_loader(){
|
function show_loader() {
|
||||||
var spinner=document.getElementById("spinner");
|
// Get the file input element
|
||||||
spinner.style.display="block";
|
const fileInput = document.getElementById("file_upload");
|
||||||
var spinner=document.getElementById("spinner2");
|
// Check if a file is selected
|
||||||
spinner.style.display="block";
|
if(fileInput){
|
||||||
var spinner=document.getElementById("button");
|
if (!fileInput.files || fileInput.files.length === 0) {
|
||||||
spinner.style.display="none";
|
// Prevent form submission and show modal
|
||||||
|
showWarningModal("Keine Datei ausgewählt. Bitte wähle eine Datei aus!");
|
||||||
|
return false; // Prevent form submission
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start the loader spinner if a file is selected
|
||||||
|
document.getElementById("spinner").style.display = "block";
|
||||||
|
document.getElementById("spinner2").style.display = "block";
|
||||||
|
document.getElementById("button").style.display = "none";
|
||||||
|
|
||||||
|
return true; // Allow form submission
|
||||||
|
}
|
||||||
|
function showWarningModal(message) {
|
||||||
|
// Get the modal and message elements
|
||||||
|
const modal = document.getElementById("warningModal");
|
||||||
|
const modalMessage = document.getElementById("warningModalMessage");
|
||||||
|
|
||||||
|
// Check if the modal and message elements exist
|
||||||
|
if (modal && modalMessage) {
|
||||||
|
modalMessage.textContent = message; // Set the message text
|
||||||
|
const bootstrapModal = new bootstrap.Modal(modal); // Initialize the modal
|
||||||
|
bootstrapModal.show(); // Show the modal using Bootstrap's method
|
||||||
|
} else {
|
||||||
|
console.warn("Modal or modal message element not found.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user