More webgui development
This commit is contained in:
+167
-29
@@ -7,9 +7,12 @@
|
||||
******************************************************************************/
|
||||
|
||||
require 'globals.inc';
|
||||
require 'lib/fileutils.inc';
|
||||
|
||||
$pagetitle = _('Documents');
|
||||
|
||||
$id = gpc_get_int($_REQUEST, 'id', 0);
|
||||
$page = gpc_get_int($_REQUEST, 'p', 1);
|
||||
|
||||
// ========== ACTIONS START ===================================================
|
||||
|
||||
@@ -38,7 +41,6 @@ switch ($submit = form_get_action()) {
|
||||
$action = ACT_ADD;
|
||||
break;
|
||||
}
|
||||
$mimetypes = ['image/png', 'image/jpeg', 'image/svg+xml', 'application/pdf'];
|
||||
$nerr = 0;
|
||||
$file_name = $_FILES['files']['name'];
|
||||
$file_tmp = $_FILES['files']['tmp_name'];
|
||||
@@ -46,7 +48,7 @@ switch ($submit = form_get_action()) {
|
||||
$file_size = $_FILES['files']['size'];
|
||||
$file_ext = strtolower(end(explode('.', $_FILES['files']['name'])));
|
||||
$file_mimetype = mime_content_type($file_tmp);
|
||||
if (!in_array($file_mimetype, $mimetypes)) {
|
||||
if (!in_array($file_mimetype, $g_doc_mimetypes)) {
|
||||
$g_error->Add(sprintf(_("Mimetype '%s' not allowed for upload."), $file_mimetype));
|
||||
$action = ACT_ADD;
|
||||
break;
|
||||
@@ -68,6 +70,12 @@ switch ($submit = form_get_action()) {
|
||||
$action = ACT_VIEW;
|
||||
break;
|
||||
}
|
||||
|
||||
if ($file_size > $g_doc_maxsize) {
|
||||
$g_error->Add(sprintf(_('File to big: %s.%s'), $file_name, $file_type));
|
||||
break;
|
||||
}
|
||||
|
||||
switch ($file_mimetype) {
|
||||
case 'application/pdf':
|
||||
$p[':doctype'] = 'generic';
|
||||
@@ -100,6 +108,7 @@ switch ($submit = form_get_action()) {
|
||||
|
||||
case 'update':
|
||||
$p[':docid'] = $id;
|
||||
$p[':doctype'] = gpc_get_string($_POST, 'doctype');
|
||||
$p[':filename'] = gpc_get_string($_POST, 'filename');
|
||||
$p[':title'] = gpc_get_string($_POST, 'title', 40);
|
||||
$p['remarks'] = gpc_get_string($_POST, 'remarks', 150);
|
||||
@@ -109,23 +118,53 @@ 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;
|
||||
}
|
||||
$action = ACT_DEFAULT;
|
||||
unset($_SESSION['token']);
|
||||
*/
|
||||
$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);
|
||||
foreach (glob($thumbdir . $pattern) as $f) {
|
||||
// unlink($f);
|
||||
$g_success->Add($f);
|
||||
}
|
||||
|
||||
// remove document
|
||||
$g_success->Add(_('Deleted document %s'), $docfilename);
|
||||
// sprintf('%s/%s-%06d.%s', $g_doc_basepath, $dtmap[$row['doctype']], $docid, $row['extension']);
|
||||
/*
|
||||
$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;
|
||||
break;
|
||||
|
||||
case 'addref':
|
||||
$eid = gpc_get_int($_POST, 'eid');
|
||||
$opt_reftype = db_load_enum('docref', 'reftype');
|
||||
$refid = gpc_get_int($_POST, 'refid');
|
||||
$reftype = gpc_get_enum($_POST, 'reftype', $opt_reftype, 'equipment');
|
||||
$sql = "INSERT INTO docref "
|
||||
. " (docid, refid, reftype) "
|
||||
. "VALUES "
|
||||
. " (:docid, :refid, 'equipment')";
|
||||
. " (:docid, :refid, :reftype)";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->bindValue(':docid', $id, PDO::PARAM_INT);
|
||||
$sth->bindValue(':refid', $eid, PDO::PARAM_INT);
|
||||
$sth->bindValue(':refid', $refid, PDO::PARAM_INT);
|
||||
$sth->bindValue(':reftype', $reftype, PDO::PARAM_STR);
|
||||
$sth->execute();
|
||||
$action = ACT_VIEW;
|
||||
break;
|
||||
@@ -300,13 +339,14 @@ elseif ($action == ACT_VIEW):
|
||||
/* mutool: preview of page thumbs */
|
||||
|
||||
$sql = "SELECT docid, doctype, mimetype, filename, extension, hash,"
|
||||
. " docsize, doctime, title, remarks "
|
||||
. " docsize, doctime, title, pages, remarks "
|
||||
. "FROM document "
|
||||
. "WHERE docid=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$id]);
|
||||
$document = $sth->fetch(PDO::FETCH_OBJ);
|
||||
|
||||
|
||||
echo '<h2>', _('View Document'), "</h2>\n";
|
||||
|
||||
echo '<div class="row">', "\n";
|
||||
@@ -314,25 +354,32 @@ 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";
|
||||
if ($document->doctype == 'picture') {
|
||||
$techname = 'pic-' . $document->hash . '.' . $document->extension;
|
||||
$techname = sprintf('pic-%06d.%s', $document->docid, $document->extension);
|
||||
echo '<tr><th scope="row">', _('Preview'), '</th><td>';
|
||||
// echo '<a href="doc/', $techname, '" target="_blank"><img width="', $g_thumb_size, '" src="doc/', $techname, '" alt="', $document->title, '"></a>';
|
||||
echo '<a href="dl.php?id=', $document->docid, '" target="_blank">';
|
||||
echo '<img width="', $g_thumb_size, '" src="dl.php?id=', $document->docid, '" alt="', $document->title, '">';
|
||||
echo '</a>';
|
||||
echo "</td></tr>\n";
|
||||
} elseif (($document->doctype == 'drawing')) {
|
||||
echo '<tr><th scope="row">', _('Drawing'), '</th>';
|
||||
echo '<td><img src="dl.php?id=', $document->docid, '" alt="', $document->title, '"></td></tr>', "\n";
|
||||
} elseif (($document->doctype == 'generic')) {
|
||||
$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";
|
||||
} elseif (in_array($document->doctype, ['generic', 'manual', 'invoice'])) {
|
||||
$techname = sprintf('doc-%06d.%s', $document->docid, $document->extension);
|
||||
if ($document->mimetype == 'application/pdf') {
|
||||
// TODO show preview of previewpage, create thumbnail if needed
|
||||
$pages = pdf_get_pagecount("$g_doc_basepath/$techname");
|
||||
// read page count from pdf file:
|
||||
// $pdfpages = pdf_get_pagecount("$g_doc_basepath/$techname");
|
||||
echo '<tr><th scope="row">', _('PDF'), '</th><td>';
|
||||
// Download link
|
||||
echo '<tr><th scope="row">', _('PDF'), '</th><td><a href="dl.php?id=', $document->docid, '">', $document->title ?? _('Download'), '</a> (', sprintf(_('%d Pages'), $pages), ")</td></tr>\n";
|
||||
echo '<a href="dl.php?id=', $document->docid, '">', $document->title ?? _('Download'), '</a> (', sprintf(_('%d Pages'), $document->pages), ')';
|
||||
echo "</td></tr>\n";
|
||||
}
|
||||
}
|
||||
if ($document->docsize == 0) {
|
||||
// update get current size in db
|
||||
$document->docsize = file_fix_filesize($document->docid, "$g_doc_basepath/$techname");
|
||||
}
|
||||
|
||||
echo '<tr><th scope="row">', _('Mimetype'),"</th><td>", $document->mimetype, "</td></tr>\n";
|
||||
echo '<tr><th scope="row">', _('Filename'),"</th><td>", $document->filename, "</td></tr>\n";
|
||||
echo '<tr><th scope="row">', _('File size'),"</th><td>", format_filesize($document->docsize), "</td></tr>\n";
|
||||
@@ -341,10 +388,15 @@ echo '<tr><th scope="row">', _('Title'),"</th><td>", $document->title, "</td></t
|
||||
echo '<tr><th scope="row">', _('Remarks'),"</th><td>", $document->remarks, "</td></tr>\n";
|
||||
echo "</table>\n";
|
||||
|
||||
echo "</div>\n", '<div class="col">', "\n"; // column break
|
||||
echo "</div>\n", '<div class="col text-center">', "\n"; // column break
|
||||
|
||||
if ($document->mimetype == 'application/pdf') {
|
||||
echo '<img src="dl.php?id=', $document->docid,'&t=l" alt="PDF-Preview">', "\n";
|
||||
echo '<img src="dl.php?id=', $document->docid, '&p=', $page, '&t=l" alt="PDF-Preview">', "\n";
|
||||
if ($document->pages > 1) {
|
||||
$pagination = get_pagination($g_scriptname, 'f=view&id='.$id, $page, $document->pages, true);
|
||||
echo $pagination;
|
||||
// $pagination;
|
||||
}
|
||||
}
|
||||
|
||||
echo "</div>\n</div>\n"; // end of columns
|
||||
@@ -353,11 +405,32 @@ form_view_buttons($g_scriptname, $id);
|
||||
|
||||
|
||||
echo '<h3>', _('Document references'), "</h3>\n";
|
||||
$sql = "SELECT drid, reftype, ename AS name, eid "
|
||||
$references = array();
|
||||
|
||||
// Equipment
|
||||
$eids = array();
|
||||
$sql = "SELECT drid, reftype, refid, ename AS target "
|
||||
. "FROM docref INNER JOIN equipment ON (docref.reftype='equipment' AND docref.refid=equipment.eid) "
|
||||
. "WHERE docid=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$id]);
|
||||
foreach ($sth->fetchAll() as $row) {
|
||||
$references[] = $row;
|
||||
$eids[] = $row['refid'];
|
||||
}
|
||||
|
||||
// Companies
|
||||
$compids = array();
|
||||
$sql = "SELECT drid, reftype, refid, compname AS target "
|
||||
. "FROM docref INNER JOIN company ON (docref.reftype='company' AND docref.refid=company.compid) "
|
||||
. "WHERE docid=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$id]);
|
||||
foreach ($sth->fetchAll() as $row) {
|
||||
$references[] = $row;
|
||||
$compids[] = $row['refid'];
|
||||
}
|
||||
|
||||
echo '<table class="table table-sm">', "\n";
|
||||
echo "<thead>\n";
|
||||
echo "<tr>";
|
||||
@@ -366,20 +439,25 @@ echo "<th>" . _('Used by') . "</th>";
|
||||
echo "<td></td>";
|
||||
echo "</tr>\n";
|
||||
echo "</thead>\n";
|
||||
$eids = array();
|
||||
foreach ($sth->fetchAll() as $row) {
|
||||
$eids[] = $row['eid'];
|
||||
foreach ($references as $ref) {
|
||||
echo "<tr>";
|
||||
echo "<td>", $row['reftype'], "</td>";
|
||||
echo "<td>", $row['name'], "</td>";
|
||||
echo "<td>", $ref['reftype'], "</td>";
|
||||
echo "<td>", $ref['target'], "</td>";
|
||||
echo "<td>";
|
||||
echo '<a title="', _('View'), '" href="equipment.php?f=view&id=', $row['eid'],'"><i class="bi-eye"></i></a>';
|
||||
echo '<a title="', _('Remove'), '" href="', $g_scriptname, '?f=delref&id=', $id, '&drid=', $row['drid'], '"><i class="bi-trash"></i></a>';
|
||||
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";
|
||||
}
|
||||
echo "</table>\n";
|
||||
|
||||
// New references
|
||||
echo '<h4>', _('Add new reference'), "</h4>\n";
|
||||
|
||||
// Equipment options
|
||||
// Do not include equipment that has already been referenced in the list!
|
||||
$opt_equipment = array();
|
||||
@@ -394,14 +472,43 @@ foreach ($sth->fetchAll() as $row) {
|
||||
?>
|
||||
<form method="post" action="<?=$g_scriptname?>">
|
||||
<input type="hidden" name="id" value="<?=$id?>">
|
||||
<select name="eid">
|
||||
<input type="hidden" name="reftype" value="equipment">
|
||||
<label for="eid"><?=_('Equipment')?></label>
|
||||
<select name="refid" id="eid">
|
||||
<?php
|
||||
foreach ($opt_equipment as $k => $v) {
|
||||
echo '<option value="', $k, '">', $v, "</option>\n";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<button class="btn btn-secondary" name="submit[addref]">Referenzieren</button>
|
||||
<button class="btn btn-sm btn-secondary" name="submit[addref]">Referenzieren</button>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
$opt_company = array();
|
||||
$sql = "SELECT compid, compname FROM company ORDER BY compname";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute();
|
||||
foreach ($sth->fetchAll() as $row) {
|
||||
if (!in_array($row['eid'], $compids)) {
|
||||
$opt_company[$row['compid']] = $row['compname'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<form method="post" action="<?=$g_scriptname?>">
|
||||
<input type="hidden" name="id" value="<?=$id?>">
|
||||
<input type="hidden" name="reftype" value="company">
|
||||
<label for="compid"><?=_('Company')?></label>
|
||||
<select name="refid" id="compid">
|
||||
<?php
|
||||
foreach ($opt_company as $k => $v) {
|
||||
echo '<option value="', $k, '">', $v, "</option>\n";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<button class="btn btn-sm btn-secondary" name="submit[addref]">Referenzieren</button>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
@@ -411,7 +518,7 @@ elseif ($action == ACT_EDIT):
|
||||
|
||||
echo '<h2>', _('Edit Document'), "</h2>\n";
|
||||
|
||||
$sql = "SELECT docid, doctype, filename, extension, hash, title, remarks "
|
||||
$sql = "SELECT docid, doctype, mimetype, filename, extension, hash, title, remarks "
|
||||
. "FROM document "
|
||||
. "WHERE docid=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
@@ -433,6 +540,20 @@ if ($document->doctype == 'picture') {
|
||||
<label for="title" class="form-label"><?=_('Title')?></label>
|
||||
<input type="text" class="form-control" id="title" name="title" value="<?=$document->title ?>">
|
||||
</div>
|
||||
<?php
|
||||
if ($document->mimetype == 'application/pdf') {
|
||||
echo '<div class="mb-3">', "\n";
|
||||
$opt_doctype = array(
|
||||
'generic' => _('Generic'),
|
||||
'manual' => _('Manual'),
|
||||
'invoice' => _('Invoice')
|
||||
) ;
|
||||
form_create_select('doctype', _('Document type'), $opt_doctype, $document->doctype);
|
||||
echo "</div>";
|
||||
} else {
|
||||
echo '<input type="hidden" name="doctype" value="', $document->doctype, '">', "\n";
|
||||
}
|
||||
?>
|
||||
<div class="mb-3">
|
||||
<label for="remarks" class="form-label"><?=_('Remarks')?></label>
|
||||
<textarea class="form-control" id="remarks" name="remarks" rows="3"><?=$document->remarks ?></textarea>
|
||||
@@ -445,7 +566,24 @@ if ($document->doctype == 'picture') {
|
||||
elseif ($action == ACT_DELETE):
|
||||
// ========== VARIANT: delete record ==========================================
|
||||
|
||||
|
||||
$sql = "SELECT docid, doctype, mimetype, filename, extension, title "
|
||||
. "FROM document "
|
||||
. "WHERE docid=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$id]);
|
||||
$document = $sth->fetch(PDO::FETCH_OBJ);
|
||||
|
||||
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>', _('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 ===========================================
|
||||
|
||||
Reference in New Issue
Block a user