From 597ac8cbe04f4b101d8b14fd78c8615b14ea8f54 Mon Sep 17 00:00:00 2001 From: Janis Steiner Date: Mon, 9 Dec 2024 16:05:56 +0000 Subject: [PATCH] switching to new verison of overview --- sys0-code/app/overview.php | 773 +++++++++++++++++------------------- sys0-code/test/overview.php | 470 ---------------------- 2 files changed, 357 insertions(+), 886 deletions(-) delete mode 100644 sys0-code/test/overview.php diff --git a/sys0-code/app/overview.php b/sys0-code/app/overview.php index b9f7d1c..84c22ef 100644 --- a/sys0-code/app/overview.php +++ b/sys0-code/app/overview.php @@ -1,79 +1,96 @@ +System0 Übersicht + // Initialize the session + session_start(); + include "../config/config.php"; + include "../api/queue.php"; + include "../assets/components.php"; + $role=$_SESSION["role"]; + $username=$_SESSION["username"]; + // Check if the user is logged in, if not then redirect him to login page + if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){ + header("location: /login/login.php"); + exit; + } + $username=htmlspecialchars($_SESSION["username"]); + $id=$_SESSION["id"]; + $_SESSION["rid"]++; - - - -load_user()"; -?> - -=$firstCharsCount+$lastCharsCount+3){ - $firstChars = substr($filePath, 0, $firstCharsCount); - - // Get the last few characters of the path - $lastChars = substr($filePath, -$lastCharsCount); - - // Return the shortened path - return $firstChars . "..." . $lastChars; - } - else{ - return $filePath; + //echo("GOT RID: ".$_GET["rid"]." Expected RID: ".$_SESSION["rid"]-1); + if(isset($_GET['free'])&&$_GET["rid"]==($_SESSION["rid"]-1)) + { + $cnt=""; + $printer_id=htmlspecialchars($_GET['free']); + $sql="select used_by_userid from printer where id=$printer_id"; + $stmt = mysqli_prepare($link, $sql); + mysqli_stmt_execute($stmt); + mysqli_stmt_store_result($stmt); + mysqli_stmt_bind_result($stmt, $cnt); + mysqli_stmt_fetch($stmt); + $sql="update printer set free=1,printing=0,cancel=0 ,used_by_userid=0 where id=$printer_id"; + $stmt = mysqli_prepare($link, $sql); + mysqli_stmt_execute($stmt); + //try to find out how much filament was used + $stmt->close(); + //load apikey etc + $url=""; + $apikey=""; + $sql="select printer_url,apikey from printer where id=$printer_id"; + $stmt = mysqli_prepare($link, $sql); + mysqli_stmt_execute($stmt); + mysqli_stmt_store_result($stmt); + mysqli_stmt_bind_result($stmt, $url,$apikey); + mysqli_stmt_fetch($stmt); + $stmt->close(); + //connect to the printer + exec("curl --max-time 10 $url/api/job?apikey=$apikey > /var/www/html/user_files/$username/finish.json"); + $fg=file_get_contents("/var/www/html/user_files/$username/finish.json"); + $json=json_decode($fg,true); + $userid=$_SESSION["id"]; + if(isset($json['job']['filament']['tool0']['volume'])){ + $filament_usage=intval($json['job']['filament']['tool0']['volume']); + $sql="UPDATE users SET filament_usage = COALESCE(filament_usage,0) + $filament_usage WHERE id = $cnt"; + $stmt = mysqli_prepare($link, $sql); + mysqli_stmt_execute($stmt); } } - $color=$_SESSION["color"]; - include "../assets/components.php"; - if(!isset($_SESSION["rid"])) - $_SESSION["rid"]=0; - $_SESSION["rid"]++; + if(isset($_GET['remove_queue'])&&$_GET["rid"]==($_SESSION["rid"]-1)) + { + $id=htmlspecialchars($_GET['remove_queue']); + $sql="delete from queue where id=$id"; + $stmt = mysqli_prepare($link, $sql); + mysqli_stmt_execute($stmt); + } + if(isset($_GET['cancel'])&&$_GET["rid"]==($_SESSION["rid"]-1)) + { + $apikey=""; + $printer_url=""; + $printer_id=htmlspecialchars($_GET['cancel']); + $sql="select used_by_userid,apikey,printer_url from printer where id=$printer_id"; + $stmt = mysqli_prepare($link, $sql); + mysqli_stmt_execute($stmt); + mysqli_stmt_store_result($stmt); + mysqli_stmt_bind_result($stmt, $cnt,$apikey,$printer_url); + mysqli_stmt_fetch($stmt); + + exec("curl -k -H \"X-Api-Key: $apikey\" -H \"Content-Type: application/json\" --data '{\"command\":\"cancel\"}' \"$printer_url/api/job\" > /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); + if($json["error"]!="") + { + echo(""); + } + else + { + $sql="update printer set cancel=1 where id=$printer_id"; + $stmt = mysqli_prepare($link, $sql); + mysqli_stmt_execute($stmt); + } + } + if(isset($_GET["set_class"]) && isset($_POST["class"])){ $class_id=htmlspecialchars($_POST["class"]); @@ -90,11 +107,20 @@ function update_cancel_modal(printer_id,rid){ $_SESSION["class"]=$class_name; $_SESSION["class_id"]=$class_id; } + ?> - Alle Drucker + + -
- +
+ +
-
-
-
- close(); - //load apikey etc - $url=""; - $apikey=""; - $sql="select printer_url,apikey from printer where id=$printer_id"; - $stmt = mysqli_prepare($link, $sql); - mysqli_stmt_execute($stmt); - mysqli_stmt_store_result($stmt); - mysqli_stmt_bind_result($stmt, $url,$apikey); - mysqli_stmt_fetch($stmt); - $stmt->close(); - //connect to the printer - exec("curl --max-time 10 $url/api/job?apikey=$apikey > /var/www/html/user_files/$username/finish.json"); - $fg=file_get_contents("/var/www/html/user_files/$username/finish.json"); - $json=json_decode($fg,true); - $userid=$_SESSION["id"]; - if(isset($json['job']['filament']['tool0']['volume'])){ - $filament_usage=intval($json['job']['filament']['tool0']['volume']); - $sql="UPDATE users SET filament_usage = COALESCE(filament_usage,0) + $filament_usage WHERE id = $cnt"; - //echo($sql); + + + + + + + + - exec("curl -k -H \"X-Api-Key: $apikey\" -H \"Content-Type: application/json\" --data '{\"command\":\"cancel\"}' \"$printer_url/api/job\" > /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); - if($json["error"]!="") - { - echo(""); - } - else - { - $sql="update printer set cancel=1 where id=$printer_id"; - $stmt = mysqli_prepare($link, $sql); - mysqli_stmt_execute($stmt); - } + + + +

Warteschlange

"); ?> -

- - - - - - - "); echo("var modal = document.getElementById('select_class');"); @@ -523,7 +464,7 @@ function update_cancel_modal(printer_id,rid){ echo(""); } ?> - - + + diff --git a/sys0-code/test/overview.php b/sys0-code/test/overview.php deleted file mode 100644 index 84c22ef..0000000 --- a/sys0-code/test/overview.php +++ /dev/null @@ -1,470 +0,0 @@ - - - -System0 Übersicht -close(); - //load apikey etc - $url=""; - $apikey=""; - $sql="select printer_url,apikey from printer where id=$printer_id"; - $stmt = mysqli_prepare($link, $sql); - mysqli_stmt_execute($stmt); - mysqli_stmt_store_result($stmt); - mysqli_stmt_bind_result($stmt, $url,$apikey); - mysqli_stmt_fetch($stmt); - $stmt->close(); - //connect to the printer - exec("curl --max-time 10 $url/api/job?apikey=$apikey > /var/www/html/user_files/$username/finish.json"); - $fg=file_get_contents("/var/www/html/user_files/$username/finish.json"); - $json=json_decode($fg,true); - $userid=$_SESSION["id"]; - if(isset($json['job']['filament']['tool0']['volume'])){ - $filament_usage=intval($json['job']['filament']['tool0']['volume']); - $sql="UPDATE users SET filament_usage = COALESCE(filament_usage,0) + $filament_usage WHERE id = $cnt"; - $stmt = mysqli_prepare($link, $sql); - mysqli_stmt_execute($stmt); - } - } - if(isset($_GET['remove_queue'])&&$_GET["rid"]==($_SESSION["rid"]-1)) - { - $id=htmlspecialchars($_GET['remove_queue']); - $sql="delete from queue where id=$id"; - $stmt = mysqli_prepare($link, $sql); - mysqli_stmt_execute($stmt); - } - if(isset($_GET['cancel'])&&$_GET["rid"]==($_SESSION["rid"]-1)) - { - $apikey=""; - $printer_url=""; - $printer_id=htmlspecialchars($_GET['cancel']); - $sql="select used_by_userid,apikey,printer_url from printer where id=$printer_id"; - $stmt = mysqli_prepare($link, $sql); - mysqli_stmt_execute($stmt); - mysqli_stmt_store_result($stmt); - mysqli_stmt_bind_result($stmt, $cnt,$apikey,$printer_url); - mysqli_stmt_fetch($stmt); - - exec("curl -k -H \"X-Api-Key: $apikey\" -H \"Content-Type: application/json\" --data '{\"command\":\"cancel\"}' \"$printer_url/api/job\" > /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); - if($json["error"]!="") - { - echo(""); - } - else - { - $sql="update printer set cancel=1 where id=$printer_id"; - $stmt = mysqli_prepare($link, $sql); - mysqli_stmt_execute($stmt); - } - } - - - if(isset($_GET["set_class"]) && isset($_POST["class"])){ - $class_id=htmlspecialchars($_POST["class"]); - $sql="update users set class_id=$class_id where username='$username'"; - $stmt = mysqli_prepare($link, $sql); - mysqli_stmt_execute($stmt); - $stmt->close(); - $sql="select name from class where id=$class_id"; - $stmt = mysqli_prepare($link, $sql); - mysqli_stmt_execute($stmt); - $class_name=""; - mysqli_stmt_bind_result($stmt, $class_name); - $stmt->close(); - $_SESSION["class"]=$class_name; - $_SESSION["class_id"]=$class_id; - } - -?> - - - - - - -
- - -
- - - - - - - - - - - - - -

Warteschlange

-
"); - $last_id=0; - $form_userid=0; - $print_on=0; - while($cnt!=0) - { - $sql="select id,filepath,from_userid,print_on from queue where id>$last_id order by id"; - $cancel=0; - $stmt = mysqli_prepare($link, $sql); - echo mysqli_error($link); - mysqli_stmt_execute($stmt); - mysqli_stmt_store_result($stmt); - mysqli_stmt_bind_result($stmt, $queue_id,$filepath,$from_userid,$print_on); - mysqli_stmt_fetch($stmt); - $filepath=basename($filepath); - $last_id=$queue_id; - echo(""); - if($print_on==-1) - echo(""); - else - echo(""); - if($_SESSION["role"][3]==="1" or $_SESSION["id"]==$from_userid) - echo(""); - - $cnt--; - } - echo("
DateiDrucken auf Druckeraus der Warteschlange entfernen
$filepathErster verfügbarer Drucker$print_on
"); - ?> - -"); - echo("var modal = document.getElementById('select_class');"); - echo("modal.classList.add('show');"); - echo("modal.style.display = 'block';"); - echo("modal.removeAttribute('aria-hidden');"); - echo("document.body.classList.add('modal-open');"); - echo(""); - } - ?> - - - -