diff --git a/sys0-code/api/uploader/check_illegal_settings.php b/sys0-code/api/uploader/check_illegal_settings.php new file mode 100644 index 0000000..a2b911c --- /dev/null +++ b/sys0-code/api/uploader/check_illegal_settings.php @@ -0,0 +1,52 @@ +$is_unsafe])); + + +function extract_param($gcode) { + // Match the pattern S followed by digits, capturing the digits + $matches = []; + $pattern = '/[S|T]([0-9]+)/'; + + if (preg_match($pattern, $gcode, $matches)) { + return (int)$matches[1]; // Return the first capture group as an integer + } else { + return false; // No match found + } +} +function check_file($path){//check file for temperature which are to high + $file = fopen($path, 'r'); + $cnt=0; + while (!feof($file)&&$cnt!=2) { + $line = fgets($file); + // Extract parameter from lines with specific commands + if (strpos($line, 'M104') !== false || strpos($line, 'M140') !== false) { + $cnt++; + $parameter = extract_param($line); + if(strpos($line, 'M104') !== false){ //extruder_temp + $ex_temp=$parameter; + } + if(strpos($line, 'M140') !== false){ //bed temp + $bed_temp=$parameter; + } + } + } + //echo("bed:$bed_temp;ex:$ex_temp"); + if($bed_temp>75 or $ex_temp>225){ + return 1; + }else{ + return 0; + } +} +?> diff --git a/sys0-code/api/uploader/check_reservations.php b/sys0-code/api/uploader/check_reservations.php new file mode 100644 index 0000000..f8c0901 --- /dev/null +++ b/sys0-code/api/uploader/check_reservations.php @@ -0,0 +1,150 @@ +$is_reserved])); + + +function find_print_time($file) { + $handle = fopen($file, "r"); + $targetPhrase = "; estimated printing time (normal mode) = "; + $time = null; + + while (($line = fgets($handle)) !== false) { + if (strpos($line, $targetPhrase) !== false) { + // Extract the time after the target phrase + $time = trim(str_replace($targetPhrase, "", $line)); + break; // Stop once the desired line is found + } + } + + fclose($handle); + + return $time; +} + + + +function check_reservation_conflict($link, $class) { + $reservation_conflict = false; + $today = date("Y-m-d"); + $time_now = date("H:i"); + $for_class = []; + + // Query for reservations that start today or extend into today + $sql = " + SELECT day, time_from, time_to, for_class + FROM reservations + WHERE day <= '$today' AND + (day = '$today' AND time_from <= '$time_now' OR day < '$today'); + "; + $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 = 0; + + if ($reservation_conflict && !in_array($class, $for_class) && $class != 0) { + $response=1; + } elseif ($class == 0 && $reservation_conflict) { + $response=2; + } + + return $response; +} + +function check_print_reservation_conflict($link, $class, $path) { + $reservation_conflict = false; + $for_class = []; + $today = date("Y-m-d"); + $time_now = date("H:i"); + + // 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"]; + } + } + + // 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 = 0; + + if ($reservation_conflict && !in_array($class, $for_class) && $class != 0) { + $response=1; + } elseif ($class == 0 && $reservation_conflict) { + $response=2; + } + + return $response; +} +?> + + + diff --git a/sys0-code/api/uploader/cloudprint.php b/sys0-code/api/uploader/cloudprint.php new file mode 100644 index 0000000..5b36f93 --- /dev/null +++ b/sys0-code/api/uploader/cloudprint.php @@ -0,0 +1,10 @@ + diff --git a/sys0-code/api/uploader/fetch_printers.php b/sys0-code/api/uploader/fetch_printers.php new file mode 100644 index 0000000..9cf6fb2 --- /dev/null +++ b/sys0-code/api/uploader/fetch_printers.php @@ -0,0 +1,29 @@ + $row['id'], + 'free' => $row['free'], + 'error_status' => $row['system_status'], + 'color' => htmlspecialchars($row['color'], ENT_QUOTES, 'UTF-8') + ]; + } + echo json_encode($printers); +?> + diff --git a/sys0-code/api/uploader/print.php b/sys0-code/api/uploader/print.php new file mode 100644 index 0000000..40b1d9b --- /dev/null +++ b/sys0-code/api/uploader/print.php @@ -0,0 +1,373 @@ + + + +
+ + +