+ Die Drucker sind zurzeit reserviert!
+ 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!
+
+
";
+ }
+
+ return $response;
}
-function time_to_seconds($print_time) {
- $seconds = 0;
+function check_print_reservation_conflict($link, $class, $path) {
+ $reservation_conflict = false;
+ $for_class = [];
+ $today = date("Y-m-d");
+ $time_now = date("H:i");
- if (preg_match('/(\d+)h/', $print_time, $matches)) {
- $seconds += $matches[1] * 3600; // hours to seconds
- }
- if (preg_match('/(\d+)m/', $print_time, $matches)) {
- $seconds += $matches[1] * 60; // minutes to seconds
- }
- if (preg_match('/(\d+)s/', $print_time, $matches)) {
- $seconds += $matches[1]; // seconds
+ // Calculate the end time of the print
+ $print_time = find_print_time($path); // Assume this function is already defined
+ 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;
+ //echo("uses ".$minutes." Minutes and ".$hours." hours");
+ $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');
+ }
+
+ // 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"];
+ }
}
- return $seconds;
+ // 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'] = "
+
+
+ Die Drucker sind zurzeit reserviert! Bitte versuche es später erneut!
+
+ Die Drucker sind zurzeit reserviert!
+ 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!
+
");
+ $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
}
else
@@ -175,6 +277,7 @@ function time_to_seconds($print_time) {
mysqli_stmt_execute($stmt);
echo("
Datei ". basename( $_FILES['file_upload']['name']). " wurde hochgeladen und an die Warteschlange gesendet
");
+ $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
}
else
@@ -196,7 +299,7 @@ function time_to_seconds($print_time) {
mysqli_stmt_execute($stmt);
- echo("
Datei ". basename( $_FILES['file_upload']['name']). " wurde hochgeladen und an die Warteschlange gesendet
");
+ echo("
Datei ". basename( $_FILES['file_upload']['name']). " wurde an die Warteschlange gesendet
");
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);
if($free!=1 or $status!=0)
{
-
echo("
Der Drucker ist zur Zeit nicht verfügbar. Warte einen Moment oder versuche es mit einem anderen Drucker erneut.
");
sys0_log("Could not start job for ".$_SESSION["username"]." with file ".basename($path)."",$_SESSION["username"],"PRINT::JOB::START::FAILED");//notes,username,type
exit;
@@ -246,59 +348,16 @@ function time_to_seconds($print_time) {
if(true){
mysqli_stmt_close($stmt);
if(move_uploaded_file($_FILES['file_upload']['tmp_name'], $path)) {
- echo("
Erfolg! Die Datei ". basename( $_FILES['file_upload']['name']). " wurde hochgeladen.
");
- echo("
Datei wird an den 3D-Drucker gesendet...
");
- $print_time=find_print_time($path);
- //check if the printers are reserved at the time when this print finishes
- 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;
- }
+ //echo("
Erfolg! Die Datei ". basename( $_FILES['file_upload']['name']). " wurde hochgeladen.
");
+ //echo("
Datei wird an den 3D-Drucker gesendet...
");
+ $response=check_print_reservation_conflict($link,$_SESSION["class_id"],$path);
+ $block=$response['block'];
if($block==false){
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');
//file is on printer and ready to be printed
$userid=$_SESSION["id"];
- echo("
Die Drucker sind zurzeit reserviert! 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!