fixing bug where lookahead would not work for cloudprint

This commit is contained in:
Janis Steiner
2024-10-28 15:07:26 +00:00
parent 5bc68a502c
commit 10640917a0

View File

@@ -354,50 +354,50 @@ function time_to_seconds($print_time) {
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>");
$printing_time=find_print_time($path); $print_time=find_print_time($path);
date_default_timezone_set('Europe/Zurich'); date_default_timezone_set('Europe/Zurich');
$reservation_conflict = false; $reservation_conflict = false;
$today = date("Y-m-d"); $today = date("Y-m-d");
$time_now = date("H:i"); $time_now = date("H:i");
preg_match('/(\d+)h/', $print_time, $hours_match); preg_match('/(\d+)h/', $print_time, $hours_match);
preg_match('/(\d+)m/', $print_time, $minutes_match); preg_match('/(\d+)m/', $print_time, $minutes_match);
$hours = isset($hours_match[1]) ? (int)$hours_match[1] : 0; $hours = isset($hours_match[1]) ? (int)$hours_match[1] : 0;
$minutes = isset($minutes_match[1]) ? (int)$minutes_match[1] : 0; $minutes = isset($minutes_match[1]) ? (int)$minutes_match[1] : 0;
// Convert $now into a DateTime object and add hours and minutes // Convert $now into a DateTime object and add hours and minutes
$time = DateTime::createFromFormat('H:i', $time_now); $time = DateTime::createFromFormat('H:i', $time_now);
$time->modify("+{$hours} hour"); $time->modify("+{$hours} hour");
$time->modify("+{$minutes} minutes"); $time->modify("+{$minutes} minutes");
// Format $time back into a string // Format $time back into a string
$time_now = $time->format('H:i'); $time_now = $time->format('H:i');
// Query to get reservations for the current day // Query to get reservations for the current day
$sql = "SELECT time_from, time_to, for_class FROM reservations WHERE day='$today';"; $sql = "SELECT time_from, time_to, for_class FROM reservations WHERE day='$today';";
$stmt = $link->prepare($sql); $stmt = $link->prepare($sql);
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
// Check for overlap with the entire print time period // Check for overlap with the entire print time period
if (is_time_between($row["time_from"], $row["time_to"], $time_now)) { if (is_time_between($row["time_from"], $row["time_to"], $time_now)) {
$reservation_conflict = true; $reservation_conflict = true;
$for_class[] = $row["for_class"]; $for_class[] = $row["for_class"];
} }
} }
// Ensure $for_class is set if no conflicts were found // Ensure $for_class is set if no conflicts were found
if (!isset($for_class)) { if (!isset($for_class)) {
$for_class[] = 0; $for_class[] = 0;
} }
// Display conflict message if necessary // Display conflict message if necessary
if ($reservation_conflict && !in_array($class, $for_class) && $class != 0) { if ($reservation_conflict && !in_array($class, $for_class) && $class != 0) {
$block = true; $block = true;
} else { } else {
$block = false; $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');