Webgui: ongoing development

This commit is contained in:
2026-06-24 13:46:03 +02:00
parent f109e2621f
commit 42df35f1a0
26 changed files with 536 additions and 293 deletions
+53 -30
View File
@@ -7,6 +7,7 @@
******************************************************************************/
require 'globals.inc';
require 'lib/gpc.inc';
require 'lib/fileutils.inc';
$pagetitle = _('Documents');
@@ -78,6 +79,9 @@ switch ($submit = form_get_action()) {
if ($file_type != $file_mimetype) {
$g_warning->Add(sprintf(_("Mimetype mismatch: '%s'."), $file_type));
}
// TODO for images check maximum size and scale down if needed
// ok let's go
$file_hash = md5_file($file_tmp);
$file_timestamp = date('Y-m-d H:i:s', filemtime($file_tmp));
@@ -140,39 +144,44 @@ switch ($submit = form_get_action()) {
case 'delete':
// Security token needed!
/*if (gpc_get_string($_POST, 'token', 16) != $_SESSION['token']) {
if (gpc_get_string($_POST, 'token', 16) != $_SESSION['token']) {
$g_error->Add(_('Delete prohibited, invalid security token!'));
$action = ACT_VIEW;
break;
}
unset($_SESSION['token']);
*/
// get document details
$sql = "SELECT doctype, extension FROM document WHERE docid=?";
$sth = $pdo->prepare($sql);
$sth->execute([$id]);
$doc = $sth->fetch(PDO::FETCH_OBJ);
// clean thumbs
$thumbdir = $g_doc_basepath . '/thumbs/';
$pattern = sprintf('%s-%06d*', $g_doc_typemap[$doctype], $docid);
$pattern = sprintf('%s-%06d*', $g_doc_typemap[$doc->doctype], $id);
$g_success->Add("Remove thumbs: type=$doc->doctype pattern=$pattern");
foreach (glob($thumbdir . $pattern) as $f) {
// unlink($f);
unlink($f);
$g_success->Add($f);
}
// remove references
$nref = db_exec_delete('docref', 'docid=?', $id);
if ($nref > 0) {
$g_success->Add(sprintf(_('Removed %d references'), $nref));
}
// remove document
$g_success->Add(_('Deleted document %s'), $docfilename);
// sprintf('%s/%s-%06d.%s', $g_doc_basepath, $dtmap[$row['doctype']], $docid, $row['extension']);
/*
$docfilename = sprintf('%s/%s-%06d.%s', $g_doc_basepath, $g_doc_typemap[$doc->doctype], $id, $doc->extension);
unlink($docfilename);
$g_success->Add(sprintf(_('Deleted document %s'), $docfilename));
// remove record from database
$sth = $pdo->prepare("DELETE FROM document WHERE docid=?");
try {
$sth->execute([$id]);
} catch (PDOexception $e) {
$g_error->Add(sprintf(_('SQL-Error: %s', $e->getMessage())));
}*/
//$action = ACT_DEFAULT;
$action = ACT_DELETE;
$g_error->Add(sprintf(_('SQL-Error: %s'), $e->getMessage()));
$action = ACT_DELETE;
break;
}
$action = ACT_DEFAULT;
break;
case 'addref':
@@ -266,7 +275,7 @@ WHERE r.reftype='equipment' AND e.vid=:vid
*/
// get total recond count for pagination and limit
// get total record count for pagination and limit
$sql = "SELECT COUNT(DISTINCT docid) FROM document LEFT OUTER JOIN docref USING (docid)";
if ($where) $sql .= ' WHERE ' . $where;
$sth = $pdo->prepare($sql);
@@ -402,7 +411,7 @@ echo '<h2>', _('Add Document'), "</h2>\n";
<label for="files" class="form-label"><?=_('Document')?></label>
<input class="form-control" type="file" id="files" name="files" onchange="preview()">
<img id="frame" src="" class="img-fluid">
<button class="btn btn-secondary" onclick="clearimg();return false;"><?=_('Clear')?></button>
<button type="button" class="btn btn-secondary" onclick="clearimg();return false;"><?=_('Clear selection')?></button>
<script>
function preview() {
var images = ["image/png", "image/jpeg", "image/svg+xml"];
@@ -414,8 +423,8 @@ echo '<h2>', _('Add Document'), "</h2>\n";
}
}
function clearimg() {
document.getElementById('file').value = null;
frame.src = "";
document.getElementById('files').value = '';
frame.src = '';
}
</script>
</div>
@@ -438,13 +447,12 @@ $sth = $pdo->prepare($sql);
$sth->execute([$id]);
$document = $sth->fetch(PDO::FETCH_OBJ);
echo '<h2>', _('View Document'), "</h2>\n";
echo '<div class="row">', "\n";
echo '<div class="col">', "\n";
echo '<table class="table table-borderless">', "\n";
echo '<tr><th scope="row" style="width:20%">', _('Document type'),"</th><td>", $document->doctype, "</td></tr>\n";
echo '<tr><th scope="row" style="width:20%">', _('Document type'),"</th><td>", get_enum($document->doctype), "</td></tr>\n";
if ($document->doctype == 'picture') {
$techname = sprintf('pic-%06d.%s', $document->docid, $document->extension);
echo '<tr><th scope="row">', _('Preview'), '</th><td>';
@@ -452,6 +460,7 @@ if ($document->doctype == 'picture') {
echo '<div class="image-gallery">';
echo '<a href="#" data-bs-toggle="modal" data-bs-target="#imageModal">';
// echo '<img width="', $g_thumb_size, '" src="dl.php?id=', $document->docid, '&t=s" alt="', $document->title, '">';
echo '<img width="', $g_thumb_size, '" src="dl.php?id=', $document->docid, '" alt="', $document->title, '">';
echo '</a>';
echo '</div>'; // gallery
@@ -473,7 +482,12 @@ if ($document->doctype == 'picture') {
// echo '</a>';
echo "</td></tr>\n";
echo '<th scope="row">Image extents</th>';
[$width, $height] = getimagesize($g_doc_basepath . '/' . $techname);
echo '<td>', $width, 'x', $height, 'px';
echo "</td></tr>";
} elseif (($document->doctype == 'drawing')) {
// TODO preview with popup
$techname = sprintf('drw-%06d.%s', $document->docid, $document->extension);
echo '<tr><th scope="row">', _('Drawing'), '</th>';
echo '<td><img src="dl.php?id=', $document->docid, '" alt="', $document->title, '"></td></tr>', "\n";
@@ -559,21 +573,26 @@ foreach ($sth->fetchAll() as $row) {
echo '<table class="table table-sm">', "\n";
echo "<thead>\n";
echo "<tr>";
echo "<th>#</th>\n";
echo '<th style="width:20%">' . _('Type') . "</th>";
echo "<th>" . _('Used by') . "</th>";
echo "<td></td>";
echo "</tr>\n";
echo "</thead>\n";
$i = 0;
foreach ($references as $ref) {
$i++;
echo "<tr>";
echo "<td>", $ref['reftype'], "</td>";
echo "<td>", $i;
if ($ref['reftype'] == 'equipment') {
echo '<a title="', _('View'), '" href="equipment.php?f=view&id=', $ref['refid'],'"><i class="bi-eye ms-2"></i></a>';
} elseif ($ref['reftype'] == 'company') {
echo '<a title="', _('View'), '" href="company.php?f=view&id=', $ref['refid'],'"><i class="bi-eye ms-2"></i></a>';
}
echo "</td>";
echo "<td>", get_enum($ref['reftype']), "</td>";
echo "<td>", $ref['target'], "</td>";
echo "<td>";
if ($ref['reftype'] == 'equipment') {
echo '<a title="', _('View'), '" href="equipment.php?f=view&id=', $ref['refid'],'"><i class="bi-eye"></i></a>';
} elseif ($ref['reftype'] == 'company') {
echo '<a title="', _('View'), '" href="company.php?f=view&id=', $ref['refid'],'"><i class="bi-eye"></i></a>';
}
echo '<a title="', _('Remove reference'), '" href="', $g_scriptname, '?f=delref&id=', $id, '&drid=', $ref['drid'], '"><i class="bi-trash"></i></a>';
echo "</td>";
echo "</tr>\n";
@@ -721,7 +740,6 @@ if ($document->mimetype == 'application/pdf') {
elseif ($action == ACT_DELETE):
// ========== VARIANT: delete record ==========================================
$sql = "SELECT docid, doctype, mimetype, filename, extension, title "
. "FROM document "
. "WHERE docid=?";
@@ -729,17 +747,22 @@ $sth = $pdo->prepare($sql);
$sth->execute([$id]);
$document = $sth->fetch(PDO::FETCH_OBJ);
$sql = "SELECT COUNT(*) FROM docref WHERE docid=?";
$sth = $pdo->prepare($sql);
$sth->execute([$id]);
$nref = $sth->fetchColumn();
echo '<h2>', _('Delete Document'), "</h2>\n";
echo '<p>', sprintf(_('Record no. %d'), $id), "</p>\n";
echo '<p>Dokument: ', $document->filename, "</p>";
echo '<p>Title: ', $document->title, "</p>";
echo '<p>Dokument: ', $document->filename, "</p>\n";
echo '<p>Title: ', $document->title, "</p>\n";
echo '<p>References: ', $nref, "<p>\n";
echo '<p>', _('Deleting a document item is final. There is no way back. Only delete if you are absolute sure.'), "</p>\n";
$_SESSION['token'] = bin2hex(random_bytes(8));
form_delete_buttons($g_scriptname, $id, $_SESSION['token']);
else:
// ========== ERROR UNKNOWN VARIANT ===========================================