fixing some bugs in uploader
This commit is contained in:
@@ -6,5 +6,9 @@
|
||||
}
|
||||
$username=$_SESSION["username"];
|
||||
$path = "/var/www/html/user_files/$username/";
|
||||
$public_path = "/var/www/html/user_files/public/";
|
||||
if($_GET["pc"]=="1")
|
||||
$_SESSION["current_file"]=$public_path.$_GET["file"];
|
||||
else
|
||||
$_SESSION["current_file"]=$path.$_GET["file"];
|
||||
?>
|
||||
|
||||
@@ -7,8 +7,10 @@ session_start();
|
||||
exit;
|
||||
}
|
||||
$username=$_SESSION["username"];
|
||||
if($_GET["pc"]=="1")
|
||||
echo(get_base64_preview("/var/www/html/user_files/public/".$_GET["file"]));
|
||||
else
|
||||
echo(get_base64_preview("/var/www/html/user_files/$username/".$_GET["file"]));
|
||||
|
||||
function get_base64_preview($filename){
|
||||
$base64="";
|
||||
$file=fopen($filename,"r");
|
||||
|
||||
@@ -469,43 +469,68 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
<center><h3>Warteschlange</h3></center>
|
||||
<?php
|
||||
|
||||
$userid = $_SESSION["id"];
|
||||
$cnt = 0;
|
||||
$filepath="";
|
||||
$sql="select count(*) from queue";
|
||||
$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>");
|
||||
mysqli_stmt_close($stmt);
|
||||
|
||||
$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;
|
||||
|
||||
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>Auftrag von</th>
|
||||
<th>Aus der Warteschlange entfernen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>";
|
||||
|
||||
while ($cnt > 0) {
|
||||
$sql = "SELECT q.id, q.filepath, q.from_userid, q.print_on, u.username
|
||||
FROM queue q
|
||||
JOIN users u ON q.from_userid = u.id
|
||||
WHERE q.id > ?
|
||||
ORDER BY q.id LIMIT 1";
|
||||
|
||||
$stmt = mysqli_prepare($link, $sql);
|
||||
echo mysqli_error($link);
|
||||
mysqli_stmt_bind_param($stmt, "i", $last_id);
|
||||
mysqli_stmt_execute($stmt);
|
||||
mysqli_stmt_store_result($stmt);
|
||||
mysqli_stmt_bind_result($stmt, $queue_id,$filepath,$from_userid,$print_on);
|
||||
mysqli_stmt_bind_result($stmt, $queue_id, $filepath, $from_userid, $print_on, $from_user);
|
||||
mysqli_stmt_fetch($stmt);
|
||||
mysqli_stmt_close($stmt);
|
||||
|
||||
if (!$queue_id) break; // Exit if no more entries
|
||||
|
||||
$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>");
|
||||
|
||||
echo "<tr>
|
||||
<td>{$filepath}</td>
|
||||
<td>" . ($print_on == -1 ? "Erster verfügbarer Drucker" : htmlspecialchars($print_on)) . "</td>
|
||||
<td>{$from_user}</td>";
|
||||
|
||||
if ($_SESSION["role"][3] === "1" || $_SESSION["id"] == $from_userid) {
|
||||
echo "<td>
|
||||
<form method='POST' action='?remove_queue={$queue_id}&rid={$_SESSION["rid"]}'>
|
||||
<button type='submit' name='remove' class='btn btn-danger'>Löschen</button>
|
||||
</form>
|
||||
</td>";
|
||||
}
|
||||
echo "</tr>";
|
||||
|
||||
$cnt--;
|
||||
}
|
||||
echo("</tbody></table></div></div></div></div>");
|
||||
|
||||
echo "</tbody></table></div></div></div></div>";
|
||||
?>
|
||||
|
||||
<?php
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
<?php
|
||||
if(isset($_GET["cloudprint"])){
|
||||
echo("<script>let cloudprint=1;</script>");
|
||||
echo '<script>fetch("/api/uploader/image_preview.php?file='.$_GET["cloudprint"].'").then(res => res.text()).then(data => document.getElementById("preview").src = "data:image/png;base64," + data).catch(err => console.error("Error:", err));</script>';
|
||||
echo '<script>fetch("/api/uploader/image_preview.php?file='.$_GET["cloudprint"].'&pc='.isset($_GET["pc"]).'").then(res => res.text()).then(data => document.getElementById("preview").src = "data:image/png;base64," + data).catch(err => console.error("Error:", err));</script>';
|
||||
}else{
|
||||
echo("<script>let cloudprint=0;</script>");
|
||||
}
|
||||
@@ -96,6 +96,9 @@
|
||||
if(item.error_status==0){
|
||||
if(item.free==1){
|
||||
option.textContent = `Drucker ${item.id} - ${item.color}`;
|
||||
if(preselectId==null){
|
||||
option.selected="true";
|
||||
}
|
||||
}else{
|
||||
option.textContent = `Drucker ${item.id} - ${item.color} - Warteschlange`;
|
||||
}
|
||||
@@ -108,6 +111,44 @@
|
||||
})
|
||||
.catch(error => console.error("Error fetching data:", error));
|
||||
});
|
||||
async function reload_printer_selection(){
|
||||
document.getElementById("selectOption").innerHTML = "";
|
||||
const selectElement = document.getElementById("selectOption");
|
||||
const apiUrl = "/api/uploader/fetch_printers.php"; // Replace with your actual API URL
|
||||
function getUrlParam(name) {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
return urlParams.get(name);
|
||||
}
|
||||
|
||||
const preselectId = getUrlParam("preselect"); // Get "preselect" value from URL
|
||||
const option_1 = document.createElement("option");
|
||||
option_1.value = "not_set";
|
||||
option_1.textContent = "Bitte wähle einen Drucker";
|
||||
selectElement.appendChild(option_1);
|
||||
fetch(apiUrl)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
data.forEach(item => {
|
||||
const option = document.createElement("option");
|
||||
option.value = item.id;
|
||||
if(item.error_status==0){
|
||||
if(item.free==1){
|
||||
option.textContent = `Drucker ${item.id} - ${item.color}`;
|
||||
if(preselectId==null){
|
||||
option.selected="true";
|
||||
}
|
||||
}else{
|
||||
option.textContent = `Drucker ${item.id} - ${item.color} - Warteschlange`;
|
||||
}
|
||||
if (item.id == preselectId) {
|
||||
option.selected = true;
|
||||
}
|
||||
selectElement.appendChild(option);
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(error => console.error("Error fetching data:", error));
|
||||
}
|
||||
async function start_upload(use_checks){
|
||||
document.getElementById("close_progress_modal2").click();
|
||||
//main function handles the steps from user pressing upload button via checking params to starting job via api
|
||||
@@ -142,7 +183,7 @@
|
||||
}
|
||||
}else{
|
||||
//just tell the server what the file is.
|
||||
await fetch("/api/uploader/cloudprint.php?file=<?php echo($_GET['cloudprint']); ?>");
|
||||
await fetch("/api/uploader/cloudprint.php?file=<?php echo($_GET['cloudprint']); ?>&pc=<?php echo(isset($_GET['pc'])); ?>");
|
||||
}
|
||||
global_error="";
|
||||
//check if there is a reservation ongoing during this print
|
||||
@@ -208,6 +249,7 @@
|
||||
return;
|
||||
}
|
||||
show_close_button();
|
||||
reload_printer_selection();
|
||||
}
|
||||
|
||||
function add_circumvent_link(progressContent) {
|
||||
|
||||
Reference in New Issue
Block a user