working on new overview page
This commit is contained in:
@@ -47,7 +47,7 @@ while (mysqli_stmt_fetch($stmt)) {
|
|||||||
"filament_color" => $filament_color,
|
"filament_color" => $filament_color,
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($is_free == 0 && $system_status == 0) {
|
if ($is_free == 0 && $system_status == 0 && $cancel==0) {
|
||||||
exec("curl --max-time 10 $url/api/job?apikey=$apikey > /var/www/html/user_files/" . $_SESSION["username"] . "/json.json");
|
exec("curl --max-time 10 $url/api/job?apikey=$apikey > /var/www/html/user_files/" . $_SESSION["username"] . "/json.json");
|
||||||
$fg = file_get_contents("/var/www/html/user_files/" . $_SESSION["username"] . "/json.json");
|
$fg = file_get_contents("/var/www/html/user_files/" . $_SESSION["username"] . "/json.json");
|
||||||
$json = json_decode($fg, true);
|
$json = json_decode($fg, true);
|
||||||
|
|||||||
@@ -16,6 +16,84 @@
|
|||||||
}
|
}
|
||||||
$username=htmlspecialchars($_SESSION["username"]);
|
$username=htmlspecialchars($_SESSION["username"]);
|
||||||
$id=$_SESSION["id"];
|
$id=$_SESSION["id"];
|
||||||
|
$_SESSION["rid"]++;
|
||||||
|
|
||||||
|
//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";
|
||||||
|
//echo($sql);
|
||||||
|
$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("<div class='alert alert-danger' role='alert'>Beim abbrechen ist es zu einem Fehler gekommen. Bitte versuche es später erneut.</div>");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//echo("cancelling1");
|
||||||
|
$sql="update printer set cancel=1 where id=$printer_id";
|
||||||
|
$stmt = mysqli_prepare($link, $sql);
|
||||||
|
mysqli_stmt_execute($stmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<script src="/assets/js/load_page.js"></script>
|
<script src="/assets/js/load_page.js"></script>
|
||||||
@@ -64,8 +142,58 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Modals -->
|
||||||
|
|
||||||
|
<!-- cancel modal -->
|
||||||
|
<div class="modal fade" id="cancel_modal" tabindex="1" role="dialog" aria-labelledby="cancel_modal" aria-hidden="false">
|
||||||
|
<div class="modal-dialog" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title">Druck abbrechen</h5>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
Möchtest du den Druck wirklich abbrechen?
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-primary" data-bs-dismiss="modal">nicht abbrechen</button>
|
||||||
|
<a type="button" id="send_cancel_command" href="#" class="btn btn-danger">Druck abbrechen</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- class selector -->
|
||||||
|
<div class="modal fade" id="select_class" tabindex="1" role="dialog" aria-labelledby="class" aria-hidden="false">
|
||||||
|
<div class="modal-dialog" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="exampleModalLabel">Klasse angeben</h5>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<p>Hallo <?php echo(str_replace("."," ",str_replace("@kantiwattwil.ch","",$_SESSION["username"]))); ?> bitte wähle deine Klasse aus der Liste unten aus. <br>
|
||||||
|
Wenn deine Klasse nicht in der Liste ist, bitte deine Lehrperson deine Klasse in den Einstellungen hinzuzufügen.</p>
|
||||||
|
<form action="overview.php?set_class" method="post">
|
||||||
|
<select name="class">
|
||||||
|
<?php
|
||||||
|
//alle klassen auflisten
|
||||||
|
$sql="select * from class";
|
||||||
|
$stmt = mysqli_prepare($link, $sql);
|
||||||
|
$stmt->execute();
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
while($row = $result->fetch_assoc()) {
|
||||||
|
echo("<option value='".$row["id"]."'>".$row["name"]."</option>");
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<option value='0'>Lehrperson</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="submit" name="submit" class="btn btn-dark">Bestätigen</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function update_cancel_modal(printer_id,rid){
|
function update_cancel_modal(printer_id,rid){
|
||||||
@@ -114,8 +242,32 @@ function updatePrinterData(data) {
|
|||||||
printerStatus = 'Problem / Nicht betriebsbereit';
|
printerStatus = 'Problem / Nicht betriebsbereit';
|
||||||
}
|
}
|
||||||
|
|
||||||
if(printer.view==0){
|
if(printer.view==0 || printer.view==2){
|
||||||
if(own_id==printer.userid or cancel_all=="1"){
|
if(own_id==printer.userid || cancel_all=="1"){
|
||||||
|
printerCard.innerHTML = `
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">Drucker ${printer.printer_id}</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<iframe height="230px" scrolling="no" width="100%" src="/app/webcam.php?printer_id=${printer.printer_id}&username=<?php echo($username); ?>&url=${printer.url}"></iframe>
|
||||||
|
<div class="progress">
|
||||||
|
<div class="progress-bar" role="progressbar" style="width: ${printer.progress}%" aria-valuenow="${printer.progress}" aria-valuemin="0" aria-valuemax="100"></div>
|
||||||
|
</div>
|
||||||
|
<table class="table table-borderless">
|
||||||
|
<thead>
|
||||||
|
<tr><td>Status</td><td style="color: ${getColorByStatus(printer.view)}">${printerStatus}</td></tr>
|
||||||
|
<tr><td>Genutzt von</td><td>${printer.username}</td></tr>
|
||||||
|
<tr><td>Filamentfarbe</td><td>${printer.filament_color}</td></tr>
|
||||||
|
<tr><td>Erwartete Druckzeit</td><td>${printer.print_time_total}</td></tr>
|
||||||
|
<tr><td>Verbleibende Druckzeit</td><td>${printer.print_time_left}</td></tr>
|
||||||
|
<tr><td>Vergangene Druckzeit</td><td>${printer.print_time}</td></tr>
|
||||||
|
<tr><td>Datei</td><td>${printer.file}</td></tr>
|
||||||
|
</thead>
|
||||||
|
<tr><td><a class='btn btn-success' href='overview.php?free=${printer.printer_id}&rid=<?php echo($_SESSION["rid"]); ?>'>Freigeben</a></td></tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}else{
|
||||||
printerCard.innerHTML = `
|
printerCard.innerHTML = `
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title">Drucker ${printer.printer_id}</h5>
|
<h5 class="card-title">Drucker ${printer.printer_id}</h5>
|
||||||
@@ -135,11 +287,95 @@ function updatePrinterData(data) {
|
|||||||
<tr><td>Vergangene Druckzeit</td><td>${printer.print_time}</td></tr>
|
<tr><td>Vergangene Druckzeit</td><td>${printer.print_time}</td></tr>
|
||||||
<tr><td>Datei</td><td>${printer.file}</td></tr>
|
<tr><td>Datei</td><td>${printer.file}</td></tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tr><td><a class='btn btn-success' href='overview.php?free=${printer.printer_id}'>Freigeben</a></td></tr>
|
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
}else if(printer.view==1){
|
||||||
|
if(own_id==printer.userid || cancel_all=="1"){
|
||||||
|
printerCard.innerHTML = `
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">Drucker ${printer.printer_id}</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<iframe height="230px" scrolling="no" width="100%" src="/app/webcam.php?printer_id=${printer.printer_id}&username=<?php echo($username); ?>&url=${printer.url}"></iframe>
|
||||||
|
<div class="progress">
|
||||||
|
<div class="progress-bar" role="progressbar" style="width: ${printer.progress}%" aria-valuenow="${printer.progress}" aria-valuemin="0" aria-valuemax="100"></div>
|
||||||
|
</div>
|
||||||
|
<table class="table table-borderless">
|
||||||
|
<thead>
|
||||||
|
<tr><td>Status</td><td style="color: ${getColorByStatus(printer.view)}">${printerStatus}</td></tr>
|
||||||
|
<tr><td>Genutzt von</td><td>${printer.username}</td></tr>
|
||||||
|
<tr><td>Filamentfarbe</td><td>${printer.filament_color}</td></tr>
|
||||||
|
<tr><td>Erwartete Druckzeit</td><td>${printer.print_time_total}</td></tr>
|
||||||
|
<tr><td>Verbleibende Druckzeit</td><td>${printer.print_time_left}</td></tr>
|
||||||
|
<tr><td>Vergangene Druckzeit</td><td>${printer.print_time}</td></tr>
|
||||||
|
<tr><td>Datei</td><td>${printer.file}</td></tr>
|
||||||
|
</thead>
|
||||||
|
<tr><td><button class='btn btn-danger' onclick='update_cancel_modal(${printer.printer_id},<?php echo($_SESSION["rid"]); ?>)'>Abbrechen</button></td></tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}else{
|
||||||
|
printerCard.innerHTML = `
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">Drucker ${printer.printer_id}</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<iframe height="230px" scrolling="no" width="100%" src="/app/webcam.php?printer_id=${printer.printer_id}&username=<?php echo($username); ?>&url=${printer.url}"></iframe>
|
||||||
|
<div class="progress">
|
||||||
|
<div class="progress-bar" role="progressbar" style="width: ${printer.progress}%" aria-valuenow="${printer.progress}" aria-valuemin="0" aria-valuemax="100"></div>
|
||||||
|
</div>
|
||||||
|
<table class="table table-borderless">
|
||||||
|
<thead>
|
||||||
|
<tr><td>Status</td><td style="color: ${getColorByStatus(printer.view)}">${printerStatus}</td></tr>
|
||||||
|
<tr><td>Genutzt von</td><td>${printer.username}</td></tr>
|
||||||
|
<tr><td>Filamentfarbe</td><td>${printer.filament_color}</td></tr>
|
||||||
|
<tr><td>Erwartete Druckzeit</td><td>${printer.print_time_total}</td></tr>
|
||||||
|
<tr><td>Verbleibende Druckzeit</td><td>${printer.print_time_left}</td></tr>
|
||||||
|
<tr><td>Vergangene Druckzeit</td><td>${printer.print_time}</td></tr>
|
||||||
|
<tr><td>Datei</td><td>${printer.file}</td></tr>
|
||||||
|
</thead>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}else if(printer.view==3){
|
||||||
|
printerCard.innerHTML = `
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">Drucker ${printer.printer_id}</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<iframe height="230px" scrolling="no" width="100%" src="/app/webcam.php?printer_id=${printer.printer_id}&username=<?php echo($username); ?>&url=${printer.url}"></iframe>
|
||||||
|
<div class="progress">
|
||||||
|
<div class="progress-bar" role="progressbar" style="width: ${printer.progress}%" aria-valuenow="${printer.progress}" aria-valuemin="0" aria-valuemax="100"></div>
|
||||||
|
</div>
|
||||||
|
<table class="table table-borderless">
|
||||||
|
<thead>
|
||||||
|
<tr><td>Status</td><td style="color: ${getColorByStatus(printer.view)}">${printerStatus}</td></tr>
|
||||||
|
<tr><td>Filamentfarbe</td><td>${printer.filament_color}</td></tr>
|
||||||
|
</thead>
|
||||||
|
<tr><td><a class='btn btn-dark' href='print.php?preselect=${printer.printer_id}'>Drucken</a></td></tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}else if(printer.view==4){
|
||||||
|
printerCard.innerHTML = `
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">Drucker ${printer.printer_id}</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<iframe height="230px" scrolling="no" width="100%" src="/app/webcam.php?printer_id=${printer.printer_id}&username=<?php echo($username); ?>&url=${printer.url}"></iframe>
|
||||||
|
<div class="progress">
|
||||||
|
<div class="progress-bar" role="progressbar" style="width: ${printer.progress}%" aria-valuenow="${printer.progress}" aria-valuemin="0" aria-valuemax="100"></div>
|
||||||
|
</div>
|
||||||
|
<table class="table table-borderless">
|
||||||
|
<thead>
|
||||||
|
<tr><td>Status</td><td style="color: ${getColorByStatus(printer.view)}">${printerStatus}</td></tr>
|
||||||
|
</thead>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
col.appendChild(printerCard);
|
col.appendChild(printerCard);
|
||||||
@@ -167,8 +403,64 @@ function getColorByStatus(status) {
|
|||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
fetchPrinterData();
|
fetchPrinterData();
|
||||||
setInterval(fetchPrinterData, 6000); // Refresh every 60 seconds
|
setInterval(fetchPrinterData, 60000); // Refresh every 60 seconds
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
<center><h3>Warteschlange</h3></center>
|
||||||
|
<?php
|
||||||
|
$userid=$_SESSION["id"];
|
||||||
|
$cnt=0;
|
||||||
|
$filepath="";
|
||||||
|
$sql="select count(*) from queue";
|
||||||
|
$stmt = mysqli_prepare($link, $sql);
|
||||||
|
mysqli_stmt_execute($stmt);
|
||||||
|
mysqli_stmt_store_result($stmt);
|
||||||
|
mysqli_stmt_bind_result($stmt, $cnt);
|
||||||
|
mysqli_stmt_fetch($stmt);
|
||||||
|
//echo($cnt);
|
||||||
|
echo("<div class='container'><div class='row'><div class='col'><div class='overflow-auto'><table class='table'><thead><tr><th>Datei</th><th>Drucken auf Drucker</th><th>aus der Warteschlange entfernen</th></tr></thead><tbody>");
|
||||||
|
$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("<tr><td>$filepath</td>");
|
||||||
|
if($print_on==-1)
|
||||||
|
echo("<td>Erster verfügbarer Drucker</td>");
|
||||||
|
else
|
||||||
|
echo("<td>$print_on</td>");
|
||||||
|
if($_SESSION["role"][3]==="1" or $_SESSION["id"]==$from_userid)
|
||||||
|
echo("<td><form method='POST' action='?remove_queue=$queue_id&rid=".$_SESSION["rid"]."'><button type='submit' value='remove' name='remove' class='btn btn-danger'>Löschen</button></form></td></tr>");
|
||||||
|
|
||||||
|
$cnt--;
|
||||||
|
}
|
||||||
|
echo("</tbody></table></div></div></div></div>");
|
||||||
|
?>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if($_SESSION["class_id"]==""){
|
||||||
|
echo("<script>");
|
||||||
|
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("</script>");
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div id="footer"></div>
|
||||||
</body>
|
</body>
|
||||||
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user