75 or $ex_temp>225){
return 0;
}else{
return 1;
}
}
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 is_time_between($startTime, $endTime, $checkTime) {
// Convert times to timestamps
$startTimestamp = strtotime($startTime);
$endTimestamp = strtotime($endTime);
$checkTimestamp = strtotime($checkTime);
// If end time is less than start time, it means the range crosses midnight
if ($endTimestamp < $startTimestamp) {
// Check if the time is between start time and midnight or between midnight and end time
return ($checkTimestamp >= $startTimestamp || $checkTimestamp <= $endTimestamp);
} else {
// Normal case: check if the time is between start and end time
return ($checkTimestamp >= $startTimestamp && $checkTimestamp <= $endTimestamp);
}
}
function time_to_seconds($print_time) {
$seconds = 0;
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
}
return $seconds;
}
?>
load_user()";
test_queue($link);
?>
");?>
");
sys0_log("Could not upload file for ".$_SESSION["username"]." because of unknown file extension",$_SESSION["username"],"PRINT::UPLOAD::FILE::FAILED");//notes,username,type
}
else
{
//check if print key is valid:
$print_key=htmlspecialchars($_POST["print_key"]);
$sql="SELECT id from print_key where print_key='$print_key'";
$stmt = mysqli_prepare($link, $sql);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
//if(mysqli_stmt_num_rows($stmt) == 1){ turned off because user does not need to have a printer key
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;
}
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("
Datei gesendet und Auftrag wurde gestartet.
");
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");
$json=json_decode($fg,true);
if($json['effectivePrint']==false or $json["effectiveSelect"]==false)
{
echo("
Ein Fehler ist aufgetreten und der Vorgang konnte nicht gestartet werden. Warte einen Moment und versuche es dann erneut.
");
sys0_log("Could not start job for ".$_SESSION["username"]."with file ".basename($path)."",$_SESSION["username"],"PRINT::JOB::START::FAILED");//notes,username,type
}
else
{
$sql="update printer set free=0, printing=1,mail_sent=0, used_by_userid=$userid where id=$printer_id";
$stmt = mysqli_prepare($link, $sql);
mysqli_stmt_execute($stmt);
//delete printer key:
$sql="DELETE from print_key where print_key='$print_key'";
$stmt = mysqli_prepare($link, $sql);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
}
}else{
$warning=true;
echo("
Achtung, deine Bett oder Extruder Temperatur ist sehr hoch eingestellt. Dies wird zur zerstörung des Druckes und somit zu Müll führen. Bitte setze diese Temperaturen tiefer in den Einstellungen deines Slicers.
");
}
}else{
echo "
Dein Druck konnte nicht gestartet werden, da er nicht fertig wäre, befor eine andere Klasse die Drucker reserviert hat.
";
}
}
else
{
echo("
Ein Fehler beim Uploaden der Datei ist aufgetreten! Versuche es erneut!
");
}
}
else{
echo("
Der Druckschlüssel ist nicht gültig. Evtl. wurde er bereits benutzt. Versuche es erneut!
");
}
}
unset($_FILES['file']);
}
if(isset($_GET["cloudprint"])){
if(!isset($_GET["pc"]))
$path = "/var/www/html/user_files/$username/".$_GET["cloudprint"];
else
$path = "/var/www/html/user_files/public/".$_GET["cloudprint"];
//check if print key is valid:
$print_key=htmlspecialchars($_POST["print_key"]);
$sql="SELECT id from print_key where print_key='$print_key'";
$stmt = mysqli_prepare($link, $sql);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
//if(mysqli_stmt_num_rows($stmt) == 1){ turned off because user does not need to have a printer key
if(true){
mysqli_stmt_close($stmt);
echo("
Datei wird an den 3D-Drucker gesendet...
");
$print_time=find_print_time($path);
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(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("
Datei gesendet und Auftrag wurde gestartet.
");
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");
$json=json_decode($fg,true);
if($json['effectivePrint']==false or $json["effectiveSelect"]==false)
{
echo("
Ein Fehler ist aufgetreten und der Vorgang konnte nicht gestartet werden. Warte einen Moment und versuche es dann erneut.
");
sys0_log("Could not start job for ".$_SESSION["username"]."with file ".basename($path)."",$_SESSION["username"],"PRINT::JOB::START::FAILED");//notes,username,type
}
else
{
$sql="update printer set free=0, printing=1,mail_sent=0, used_by_userid=$userid where id=$printer_id";
$stmt = mysqli_prepare($link, $sql);
mysqli_stmt_execute($stmt);
//delete printer key:
$sql="DELETE from print_key where print_key='$print_key'";
$stmt = mysqli_prepare($link, $sql);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
}
}else{
$warning=true;
echo("
Achtung, deinen Bett oder Extruder Temperatur ist sehr hoch eingestellt. Dies wird zur zerstörung des Druckes und somit zu Müll führen. Bitte setze diese Temperaturen tiefer in den Einstellungen deines Slicers.
");
}
}else{
echo "
Dein Druck konnte nicht gestartet werden, da er nicht fertig wäre, befor eine andere Klasse die Drucker reserviert hat.
";
}
}
else{
echo("
Der Druckschlüssel ist nicht gültig. Evtl. wurde er bereits benutzt. Versuche es erneut!
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!
";
}else{
$block=false;
}
?>
');
}
else{
echo ('
');
echo('
');
echo("
Cloudfile: ".$_GET["cloudprint"]."
");
echo('
');
echo('
');
}
?>
');
echo('');
echo('');
echo('
');
}
?>
");
echo(" ");
}
?>
');
echo('
');
echo('Hochladen...');
echo('');
echo('
');
}else{
echo "
Die Drucker sind zurzeit reserviert! Bitte versuche es später erneut!