$last_id and printing=1 ORDER BY id"; $cancel=0; $stmt = mysqli_prepare($link, $sql); mysqli_stmt_execute($stmt); mysqli_stmt_store_result($stmt); mysqli_stmt_bind_result($stmt, $is_free,$printer_id,$url,$apikey,$cancel,$used_by_userid,$mail_sent); mysqli_stmt_fetch($stmt); $last_id=$printer_id; //printer is printing exec("curl --max-time 10 $url/api/job?apikey=$apikey > /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); $used_by_user=""; $telegram_id=""; $notification_telegram=0; $notification_mail=0; $sql="select username,telegram_id,notification_telegram,notification_mail from users where id=$used_by_userid"; $stmt = mysqli_prepare($link, $sql); mysqli_stmt_execute($stmt); mysqli_stmt_store_result($stmt); mysqli_stmt_bind_result($stmt, $used_by_user,$telegram_id,$notification_telegram,$notification_mail); mysqli_stmt_fetch($stmt); $username3=explode("@",$used_by_user); $username2=$username3[0]; $progress=(int) $json['progress']['completion']; if($progress<0) $progress=-$progress; $file=$json['job']['file']['name']; if($progress==100){ //print finished //check if mail has not been sent: if($mail_sent==0 && $notification_telegram==1){ //send telegram message echo("sending telegram for printer $printer_id
"); $text = urlencode("Hi $username2\nDein Druck auf Drucker $printer_id ist fertig\nDatei, welche du gedruckt hast: $file\n"); exec("curl \"https://api.telegram.org/$api/sendMessage?chat_id=$telegram_id&text=$text\""); $sql="update printer set mail_sent=1 where id=$printer_id"; $stmt = mysqli_prepare($link, $sql); mysqli_stmt_execute($stmt); } if($mail_sent==0 && $notification_mail==1) { echo("sending mail for printer $printer_id
"); $mail=<<Dein 3D-Druck auf Drucker $printer_id ist fertig.
Bitte hole diesen ab und vergiss nicht den Drucker danach freizugeben!
Deine Aufträge: https://app.ksw3d.ch/system0/html/php/login/v3/php/overview.php?private
Datei, welche du gedruckt hast: $file

Vielen dank für dein Vertrauen in uns!
Code Camp 2024
"}]}' EOF; $out=""; exec($mail,$out); $sql="update printer set mail_sent=1 where id=$printer_id"; $stmt = mysqli_prepare($link, $sql); mysqli_stmt_execute($stmt); } } else if($cancel==1){ //print cancelled } //else: print still running $cnt--; } ?>