From 0c09ce29162579822bcfd2255268723c9d4bff43 Mon Sep 17 00:00:00 2001 From: Thomas Hooge Date: Tue, 30 Apr 2024 19:38:28 +0200 Subject: [PATCH] More webgui development --- db/mariadb.sql | 28 ++++- db/minimal.sql | 3 +- webgui/box.php | 20 +++- webgui/checklist.php | 14 ++- webgui/company.php | 21 ++++ webgui/dl.php | 83 +++++++------- webgui/documents.php | 196 ++++++++++++++++++++++++++++----- webgui/equipment.php | 45 ++++++-- webgui/footer.php | 1 + webgui/globals.inc | 98 +++++++++++++---- webgui/index.php | 9 +- webgui/inventory.php | 33 +++--- webgui/lib/fileutils.inc | 25 +++++ webgui/maintenance.php | 41 ++++++- webgui/manual.php | 5 +- webgui/measurement.php | 29 ++++- webgui/note.php | 229 +++++++++++++++++++++++++++++++++++++++ webgui/search.php | 54 ++++++++- webgui/storage.php | 2 +- webgui/tag.php | 192 ++++++++++++++++++++++++++++++++ webgui/task.php | 83 ++++++++++++-- 21 files changed, 1056 insertions(+), 155 deletions(-) create mode 100644 webgui/lib/fileutils.inc create mode 100644 webgui/note.php create mode 100644 webgui/tag.php diff --git a/db/mariadb.sql b/db/mariadb.sql index a852f01..b0262ed 100644 --- a/db/mariadb.sql +++ b/db/mariadb.sql @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: WTFPL */ -/* MariaDB Scheme +/* MariaDB Scheme Version: 1 */ CREATE TABLE user ( @@ -19,7 +19,7 @@ CREATE TABLE user ( E.g. the currently selected boat. Users logged in via the web are allowed to write to this table. Therefore a separate table and not additional fields in the user data record. - + userid=0: Global program settings sno=0: db_scheme_version sno=1: doc_base_path @@ -95,6 +95,7 @@ CREATE TABLE tag ( tagid smallint(6) NOT NULL AUTO_INCREMENT, tagname varchar(20) NOT NULL, color char(6) DEFAULT NULL, + description varchar(80) DEFAULT NULL, PRIMARY KEY (tagid), UNIQUE INDEX ix_tagname (tagname) ); @@ -102,7 +103,7 @@ CREATE TABLE tag ( CREATE TABLE tagref ( tagid smallint(6) NOT NULL, objid smallint(6) NOT NULL, - objtype enum('equip','inv','prov','doc') NOT NULL, + objtype enum('equip','inv','prov','doc', 'proj', 'task', 'maint') NOT NULL, PRIMARY KEY (tagid, objid, objtype) ); @@ -111,6 +112,7 @@ CREATE TABLE tagref ( CREATE TABLE box ( boxid smallint(6) NOT NULL AUTO_INCREMENT, sid smallint(6) NOT NULL, + boxtype tinyint(3) DEFAULT NULL, parent int(10) DEFAULT NULL, label varchar(20) DEFAULT NULL, color char(6) DEFAULT NULL, @@ -141,7 +143,7 @@ CREATE TABLE equipment ( CREATE TABLE inventory ( invid int(10) NOT NULL AUTO_INCREMENT, invname varchar(80) NOT NULL, - boxtype enum('storage','box') NOT NULL DEFAULT 'storage', + conttype enum('storage','box') NOT NULL DEFAULT 'storage', sid smallint(6) NOT NULL DEFAULT 1, boxid smallint(6) NOT NULL DEFAULT 1, number smallint(6) UNSIGNED NOT NULL DEFAULT 1, @@ -198,7 +200,7 @@ CREATE TABLE document ( CREATE TABLE docref ( drid int(10) NOT NULL AUTO_INCREMENT, - reftype enum('vessel', 'box', 'equipment', 'project', 'task', 'user') NOT NULL DEFAULT 'vessel', + reftype enum('vessel', 'box', 'equipment', 'project', 'task', 'user', 'company') NOT NULL DEFAULT 'vessel', docid smallint(6) NOT NULL, refid smallint(6) NOT NULL, PRIMARY KEY (drid), @@ -260,12 +262,26 @@ CREATE TABLE project ( CREATE TABLE task ( taskid int(10) NOT NULL AUTO_INCREMENT, + vid smallint(6) DEFAULT NULL, projid smallint(6) DEFAULT NULL, taskname varchar(60) NOT NULL, - taskstate enum('new','finished') NOT NULL DEFAULT 'new', + priority enum('high','medium','low') DEFAULT NULL, + taskstate enum('pending','waiting','deleted','completed') NOT NULL DEFAULT 'pending', + plandate date DEFAULT NULL, + duedate date DEFAULT NULL, + started datetime DEFAULT NULL, + finished datetime DEFAULT NULL, PRIMARY KEY (taskid) ); +CREATE TABLE note ( + noteid int(10) NOT NULL AUTO_INCREMENT, + notetype enum('task','maint') NOT NULL DEFAULT 'task', + refid smallint(6) NOT NULL, + annotation text NOT NULL, + PRIMARY KEY (noteid) +); + CREATE TABLE checklist ( clid smallint(6) NOT NULL AUTO_INCREMENT, title varchar(30) NOT NULL, diff --git a/db/minimal.sql b/db/minimal.sql index 2200f02..922fa14 100644 --- a/db/minimal.sql +++ b/db/minimal.sql @@ -26,7 +26,8 @@ INSERT INTO dropdown (ddid, ddval, ddtext) VALUES (0, 5, 'Proviantkategorien'), (0, 6, 'Provianteinheiten'), (0, 7, 'Sicherungstypen'), -(0, 8 , 'Einheiten'); +(0, 8, 'Einheiten'), +(0, 9, 'Kistentypen'); INSERT INTO dropdown (ddid, ddval, ddtext, flags) VALUES (2, 1, 'Lieferant', 'fixed'), diff --git a/webgui/box.php b/webgui/box.php index b6a436d..b26633d 100644 --- a/webgui/box.php +++ b/webgui/box.php @@ -20,6 +20,8 @@ foreach ($sth->fetchAll() as $row) { $opt_storage[$row['sid']] = $row['sname']; } +$opt_boxtype = db_get_options(9); + // ========== ACTIONS START =================================================== switch ($submit = form_get_action()) { @@ -42,6 +44,8 @@ switch ($submit = form_get_action()) { case 'update': $p[':boxid'] = $id; + $p[':boxtype'] = gpc_get_int($_POST, 'boxtype'); + if ($p[':boxtype'] == -1) $p[':boxtype'] = NULL; $p[':label'] = gpc_get_string($_POST, 'label'); $p[':content'] = gpc_get_string($_POST, 'content'); $p[':color'] = gpc_get_color($_POST, 'color'); @@ -67,7 +71,7 @@ if ($action == ACT_DEFAULT): echo "

$pagetitle

\n"; -$sql = "SELECT boxid, sid, label, color, content, weight, remarks " +$sql = "SELECT boxid, boxtype, sid, label, color, content, weight, remarks " . "FROM box " . "ORDER BY label"; $sth = $pdo->query($sql); @@ -76,6 +80,7 @@ echo '', "\n"; echo "\n"; echo ""; echo ""; +echo ""; echo ""; echo ""; echo '"; @@ -84,6 +89,7 @@ echo "\n"; foreach ($res as $row) { echo "\n"; echo '\n"; + echo '\n"; echo '\n"; echo '\n"; echo '\n"; @@ -137,7 +143,7 @@ foreach ($opt_storage as $k => $v) { elseif ($action == ACT_VIEW): // ========== VARIANT: view single record ===================================== -$sql = "SELECT label, content, color, weight, box.remarks, box.sid, sname " +$sql = "SELECT boxtype, label, content, color, weight, box.remarks, box.sid, sname " . "FROM box LEFT JOIN storage USING (sid) " . "WHERE boxid=?"; $sth = $pdo->prepare($sql); @@ -147,7 +153,8 @@ $box = $sth->fetch(PDO::FETCH_OBJ); echo '

', $box->label, "

\n"; echo '
" . _('Label') . "" . _('Type') . "" . _('Color') . "" . _('Content') . "', _('Weight'), "
', $row['label'], "', ($opt_boxtype[$row['boxtype']] ?? ''), "', format_color(strtoupper($row['color'])), "', $row['content'], "', format_float($row['weight'], 2), "
', "\n"; -echo '\n"; +echo '\n"; +echo '\n"; echo '\n"; echo '\n"; echo ''; + echo '\n"; + echo "\n"; + echo '\n"; + echo '\n"; + echo ""; } // ========== COMMON FUNCTIONS ================================================ @@ -795,6 +819,16 @@ function gpc_get_color(&$GPC, $varname, $default = NULL) { return strtoupper($color); } +function gpc_get_enum(&$GPC, $varname, $values, $default = NULL) { + if (!isset($GPC[$varname]) or (strlen(trim($GPC[$varname])) == 0)) { + return $default; + } + if (! in_array($GPC[$varname], $values)) { + return $default; + } + return $GPC[$varname]; +} + function format_float($val, $decimals = 2, $suffix = '') { global $g_lconv; if (!isset($val) || $val == '') { @@ -860,45 +894,65 @@ function format_filesize($size, $format=2) { return $size_string; } -function get_pagination($script, $page, $lastpage) { +function format_measurement($n, $unit, $v1, $v2, $v3) { + $m = ''; + switch ($n) { + case 1: + $m = "$v1 $unit"; + break; + case 2: + $m = "$v1×$v2 $unit"; + break; + case 3: + $m = "$v1×$v2×$v3 $unit"; + break; + } + return $m; +} + +function get_pagination($script, $param, $page, $lastpage, $small=false) { // no direct output, returns string for multiple output if ($lastpage < 2) { return ''; } + $psep = empty($param) ? '?' : "?$param&"; + $out = '\n"; diff --git a/webgui/index.php b/webgui/index.php index 53eddd2..1ea7a37 100644 --- a/webgui/index.php +++ b/webgui/index.php @@ -28,8 +28,8 @@ switch ($submit = form_get_action()) { } catch (PDOException $e) { $g_error->Add('SQL-Error: '. $e->getMessage()); } - $g_message->Add(sprintf(_('Selected vessel %d'), $vid)); $user->load_vessel(); + $g_message->Add(sprintf(_('Selected vessel %d: %s'), $vid, $user->vessel)); break; case 'insert': @@ -310,19 +310,17 @@ echo '\n"; // Inventory // All items from vessel storage and all items from boxes in vessel storage $sql = "SELECT SUM(n) FROM (" - . "SELECT COUNT(*) AS n FROM inventory JOIN storage USING (sid) WHERE boxtype='storage' AND vid=:vid " + . "SELECT COUNT(*) AS n FROM inventory JOIN storage USING (sid) WHERE conttype='storage' AND vid=:vid " . "UNION " - . "SELECT COUNT(*) AS n FROM inventory JOIN box USING (boxid) JOIN storage ON (box.sid=storage.sid) WHERE boxtype='box' AND vid=:vid" + . "SELECT COUNT(*) AS n FROM inventory JOIN box USING (boxid) JOIN storage ON (box.sid=storage.sid) WHERE conttype='box' AND vid=:vid" . ") AS x"; $sth = $pdo->prepare($sql); $sth->bindValue(':vid', $user->vid, PDO::PARAM_INT); $sth->execute(); -// Tasks echo '"; echo '\n"; - echo "
', _('Content'),"", $box->content, "
', _('Box type'),"", ($opt_boxtype[$box->boxtype] ?? ''), "
', _('Content'),"", $box->content, "
', _('Color'), '', format_color($box->color), "
', _('Weight'), '', format_float($box->weight, 2, 'kg'), "
', _('Storage'),"", $box->sname; @@ -160,7 +167,7 @@ form_view_buttons($g_scriptname, $id); // Inventory in box // WIP -$sql = "SELECT invid, invname, weight FROM inventory WHERE boxtype='box' AND boxid=?"; +$sql = "SELECT invid, invname, weight FROM inventory WHERE conttype='box' AND boxid=?"; $sth = $pdo->prepare($sql); $sth->execute([$id]); $res = $sth->fetchAll(); @@ -194,13 +201,15 @@ if ($res) { elseif ($action == ACT_EDIT): // ========== VARIANT: edit single record ===================================== -$sql = "SELECT label, content, color, weight, remarks " +$sql = "SELECT boxtype, label, content, color, weight, remarks " . "FROM box " . "WHERE boxid=?"; $sth = $pdo->prepare($sql); $sth->execute([$id]); $box = $sth->fetch(PDO::FETCH_OBJ); +$opt_none = [ -1 => _('― none ―')]; + echo '

', _('Edit Box'), "

\n"; ?>
@@ -209,6 +218,7 @@ echo '

', _('Edit Box'), "

\n"; +boxtype); ?>
diff --git a/webgui/checklist.php b/webgui/checklist.php index a8d3a7c..a91e8ba 100644 --- a/webgui/checklist.php +++ b/webgui/checklist.php @@ -10,6 +10,19 @@ require 'globals.inc'; $pagetitle = _('Checklists'); $id = gpc_get_int($_REQUEST, 'id', 0); +$c = gpc_get_int($_REQUEST, 'c', -1); + +function create_clitem_form($script, $clid, $formtype, $row=NULL) { + + // formtype: insert or update + $update = ($formtype == 'update'); + echo ''; + echo ''; + if ($update) { + echo ''; + } + +} // ========== ACTIONS START =================================================== @@ -24,7 +37,6 @@ switch ($submit = form_get_action()) { case 'insert': $p[':title'] = gpc_get_string($_POST, 'title'); - $p[':clstate'] = gpc_get_string($_POST, 'clstate'); $id = db_exec_insert('checklist', $p); $action = ACT_VIEW; break; diff --git a/webgui/company.php b/webgui/company.php index fe4d135..99dee33 100644 --- a/webgui/company.php +++ b/webgui/company.php @@ -245,6 +245,27 @@ if ($sth->rowCount() > 0) { echo '

', _('Not referenced in any equipment'), "

\n"; } +// show referenced invoices + +$sql = "SELECT docid, refid, filename, title " + . "FROM docref AS r JOIN document AS d USING (docid) " + . "WHERE reftype='company' AND refid=?"; +$sth = $pdo->prepare($sql); +$sth->execute([$id]); +if ($sth->rowCount() > 0) { + echo "

Invoices:

\n"; + echo "
    \n"; + foreach ($sth->fetchAll() as $row) { + echo "
  • "; + echo '', $row['filename'], "\n"; + echo ' ', $row['title']; + echo "
  • \n"; + } + echo "
\n"; +} else { + echo '

', _('No invoices'), "

\n"; +} + elseif ($action == ACT_EDIT): // ========== VARIANT: edit single record ===================================== diff --git a/webgui/dl.php b/webgui/dl.php index ba6d5db..1306d68 100644 --- a/webgui/dl.php +++ b/webgui/dl.php @@ -18,85 +18,88 @@ */ require 'globals.inc'; +require 'lib/fileutils.inc'; $docid = gpc_get_int($_GET, 'id'); if (! isset($docid)) { exit(1); } +$page = gpc_get_int($_REQUEST, 'p', 1); + $thumb = gpc_get_string($_GET, 't', 1); $size = array ('s' => 120, 'm' => 240, 'l' => '320'); if (!array_key_exists($thumb, $size)) { unset($thumb); } -$sql = "SELECT doctype, docsize, mimetype, hash, extension, filename FROM document WHERE docid=?"; +$sql = "SELECT doctype, docsize, mimetype, hash, extension, filename, pages FROM document WHERE docid=?"; $sth = $pdo->prepare($sql); $sth->execute([$docid]); -$row = $sth->fetch(); -$dtmap = array( - 'generic' => 'doc', - 'manual' => 'man', - 'invoice' => 'inv', - 'picture' => 'pic', - 'drawing' => 'drw'); +$doc = $sth->fetch(PDO::FETCH_OBJ); // alter Dateiname // $ofn = sprintf("%s-%s.%s", $dtmap[$row['doctype']], $row['hash'], $row['extension']) -$file = sprintf("%s/%s-%s.%s", $g_doc_basepath, $dtmap[$row['doctype']], $row['hash'], $row['extension']); -if (file_exists($file)) { +// $file = sprintf("%s/%s-%s.%s", $g_doc_basepath, $g_doc_typemap[$row['doctype']], $row['hash'], $row['extension']); +/*if (file_exists($file)) { // Hash-Dateinamen: Umbenennen in neues Format // document-format: ttt-nnnnnn.eee // thumbnail-format: ttt-nnnnnn-ppp-s.eee - $fnew = sprintf('%s/%s-%06d.%s', $g_doc_basepath, $dtmap[$row['doctype']], $docid, $row['extension']); + $fnew = sprintf('%s/%s-%06d.%s', $g_doc_basepath, $g_doc_typemap[$row['doctype']], $docid, $row['extension']); rename($file, $fnew); $file = $fnew; -} else { - $file = sprintf('%s/%s-%06d.%s', $g_doc_basepath, $dtmap[$row['doctype']], $docid, $row['extension']); -} +} else { */ + $file = sprintf('%s/%s-%06d.%s', $g_doc_basepath, $g_doc_typemap[$doc->doctype], $docid, $doc->extension); +// } if (isset($thumb)) { - $page = 1; // could be variable in future - if ($row['mimetype'] == 'application/pdf') { - // PDF creates PNG-thumbnails - $thumbname = sprintf('%s-%06d-%03d-%s.png', $dtmap[$row['doctype']], $docid, $page, $thumb); - } else { - $thumbname = sprintf('%s-%06d-%03d-%s.%s', $dtmap[$row['doctype']], $docid, $page, $thumb, $row['extension']); + if ($page < 1) { + $page = 1; + } elseif ($page > $doc->pages) { + $page = $doc->pages; } - $thumbpath = $g_doc_basepath . '/thumb/' . $thumbname; - if (!file_exists($thumbpath)) { - list($width, $height) = getimagesize($file); - $factor = $size[$thumb] / max($width, $height); - // scale down - if ($row['mimetype'] == 'image/jpeg') { - $orig = imagecreatefromjpeg($file); - $scaled = imagescale($orig, $width * $factor, $height * $factor, IMG_BICUBIC); - imagejpeg($scaled, $thumbpath, 85); - $file = $thumbpath; - $filename = $thumbname; - $fsize = 0; // let's calc later - } elseif ($row['mimetype'] == 'image/png') { - $orig = imagecreatefrompng($file); - } elseif ($row['mimetype'] == 'application/pdf') { - // create preview image from first page of png - // mutool draw -o .png -w .pdf + if ($doc->mimetype == 'application/pdf') { + // PDF creates PNG-thumbnails + $thumbname = sprintf('%s-%06d-%03d-%s.png', $g_doc_typemap[$doc->doctype], $docid, $page, $thumb); + $thumbpath = $g_doc_basepath . '/thumb/' . $thumbname; + if (!file_exists($thumbpath)) { exec("/usr/bin/mutool draw -o {$thumbpath} -w {$size[$thumb]} $file $page", $output, $retval); } + } else { + $thumbname = sprintf('%s-%06d-%03d-%s.%s', $g_doc_typemap[$doc->doctype], $docid, $page, $thumb, $doc->extension); + $thumbpath = $g_doc_basepath . '/thumb/' . $thumbname; + if (!file_exists($thumbpath)) { + list($width, $height) = getimagesize($file); + $factor = $size[$thumb] / max($width, $height); + // scale down + if ($doc->mimetype == 'image/jpeg') { + $orig = imagecreatefromjpeg($file); + $scaled = imagescale($orig, $width * $factor, $height * $factor, IMG_BICUBIC); + imagejpeg($scaled, $thumbpath, 85); + $file = $thumbpath; + $filename = $thumbname; + $fsize = 0; // let's calc later + } elseif ($doc->mimetype == 'image/png') { + $orig = imagecreatefrompng($file); + } elseif ($doc_>mimetype == 'image/xml+svg') { + // TODO anything here? + } + } } $file = $thumbpath; $filename = $thumbname; $fsize = 0; // let's calc later } else { // normal - $filename = $row['filename']; - $fsize = $row['docsize']; + $filename = $doc->filename; + $fsize = $doc->docsize; } if (file_exists($file)) { // send file to caller header('Content-Description: File Transfer'); - header('Content-Type: ' . $row['mimetype']); + header('Content-Type: ' . $doc->mimetype); header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); diff --git a/webgui/documents.php b/webgui/documents.php index 1cd85c7..530969e 100644 --- a/webgui/documents.php +++ b/webgui/documents.php @@ -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 '

', _('View Document'), "

\n"; echo '
', "\n"; @@ -314,25 +354,32 @@ echo '
', "\n"; echo '', "\n"; echo '\n"; if ($document->doctype == 'picture') { - $techname = 'pic-' . $document->hash . '.' . $document->extension; + $techname = sprintf('pic-%06d.%s', $document->docid, $document->extension); echo '\n"; } elseif (($document->doctype == 'drawing')) { - echo ''; - echo '', "\n"; -} elseif (($document->doctype == 'generic')) { + $techname = sprintf('drw-%06d.%s', $document->docid, $document->extension); + echo ''; + echo '', "\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 '\n"; + echo '', $document->title ?? _('Download'), ' (', sprintf(_('%d Pages'), $document->pages), ')'; + echo "\n"; } } +if ($document->docsize == 0) { + // update get current size in db + $document->docsize = file_fix_filesize($document->docid, "$g_doc_basepath/$techname"); +} + echo '\n"; echo '\n"; echo '\n"; @@ -341,10 +388,15 @@ echo '\n"; echo "
', _('Document type'),"", $document->doctype, "
', _('Preview'), ''; -// echo '', $document->title, ''; echo ''; echo '', $document->title, ''; echo ''; echo "
', _('Drawing'), '', $document->title, '
', _('Drawing'), '', $document->title, '
', _('PDF'), ''; // Download link - echo '
', _('PDF'), '', $document->title ?? _('Download'), ' (', sprintf(_('%d Pages'), $pages), ")
', _('Mimetype'),"", $document->mimetype, "
', _('Filename'),"", $document->filename, "
', _('File size'),"", format_filesize($document->docsize), "
', _('Title'),"", $document->title, "', _('Remarks'),"", $document->remarks, "
\n"; -echo "
\n", '
', "\n"; // column break +echo "
\n", '
', "\n"; // column break if ($document->mimetype == 'application/pdf') { - echo 'PDF-Preview', "\n"; + echo 'PDF-Preview', "\n"; + if ($document->pages > 1) { + $pagination = get_pagination($g_scriptname, 'f=view&id='.$id, $page, $document->pages, true); + echo $pagination; + // $pagination; + } } echo "
\n
\n"; // end of columns @@ -353,11 +405,32 @@ form_view_buttons($g_scriptname, $id); echo '

', _('Document references'), "

\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 '', "\n"; echo "\n"; echo ""; @@ -366,20 +439,25 @@ echo ""; echo ""; echo "\n"; echo "\n"; -$eids = array(); -foreach ($sth->fetchAll() as $row) { - $eids[] = $row['eid']; +foreach ($references as $ref) { echo ""; - echo ""; - echo ""; + echo ""; + echo ""; echo ""; echo "\n"; } echo "
" . _('Used by') . "
", $row['reftype'], "", $row['name'], "", $ref['reftype'], "", $ref['target'], ""; - echo ''; - echo ''; + if ($ref['reftype'] == 'equipment') { + echo ''; + } elseif ($ref['reftype'] == 'company') { + echo ''; + } + echo ''; echo "
\n"; +// New references +echo '

', _('Add new reference'), "

\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) { ?> - + + - + + + +prepare($sql); +$sth->execute(); +foreach ($sth->fetchAll() as $row) { + if (!in_array($row['eid'], $compids)) { + $opt_company[$row['compid']] = $row['compname']; + } +} + + +?> +
+ + + + +
', _('Edit Document'), "\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') {
+mimetype == 'application/pdf') { + echo '
', "\n"; + $opt_doctype = array( + 'generic' => _('Generic'), + 'manual' => _('Manual'), + 'invoice' => _('Invoice') + ) ; + form_create_select('doctype', _('Document type'), $opt_doctype, $document->doctype); + echo "
"; +} else { + echo '', "\n"; +} +?>
@@ -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 '

', _('Delete Document'), "

\n"; +echo '

', sprintf(_('Record no. %d'), $id), "

\n"; +echo '

Dokument: ', $document->filename, "

"; +echo '

Title: ', $document->title, "

"; + +echo '

', _('Deleting a document item is final. There is no way back. Only delete if you are absolute sure.'), "

\n"; + +$_SESSION['token'] = bin2hex(random_bytes(8)); +form_delete_buttons($g_scriptname, $id, $_SESSION['token']); + else: // ========== ERROR UNKNOWN VARIANT =========================================== diff --git a/webgui/equipment.php b/webgui/equipment.php index 2939bd1..7948469 100644 --- a/webgui/equipment.php +++ b/webgui/equipment.php @@ -14,6 +14,7 @@ $id = gpc_get_int($_REQUEST, 'id', 0); $opt_supplier = db_get_opt_supp(array(-1 => _('--- unknown ---'))); $opt_manufacturer = db_get_opt_manuf(array(-1 => _('--- unknown ---'))); $opt_ecat = db_get_options(4); // Equipment categories +$opt_unit = db_get_options(8); // ========== ACTIONS START =================================================== @@ -102,7 +103,6 @@ switch ($submit = form_get_action()) { break; } $extensions = ['jpg', 'png']; - $mimetypes = ['image/png', 'image/jpeg', 'image/svg+xml', 'application/pdf']; $all_files = count($_FILES ["files"]["tmp_name"]); $nerr = 0; for ($i = 0; $i < $all_files; $i++) { @@ -113,7 +113,7 @@ switch ($submit = form_get_action()) { $file_ext = strtolower(end(explode('.', $_FILES['files']['name'][$i]))); // $file = $g_doc_basepath . '/' . $file_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)); $nerr += 1; } @@ -121,7 +121,7 @@ switch ($submit = form_get_action()) { $g_error->Add(_('Filetype not allowed for upload:') . ' ' . $file_type); $nerr += 1; } - if ($file_size > 2097152) { + if ($file_size > $g_doc_maxsize) { $g_error->Add(sprintf(_('File to big: %s.%s'), $file_name, $file_type)); $nerr += 1; } @@ -249,7 +249,7 @@ $opt_special = array(
Filter
- + - + - + - +
@@ -294,7 +294,7 @@ foreach ($opt_special + $opt_supplier as $k => $v) { '; // container // Buttons at bottom of data area form_view_buttons($g_scriptname, $id); - // Maintenance records - echo '

', _('Maintenances'), "

"; $sql = "SELECT maintid, series, activities FROM maintenance WHERE eid=?"; @@ -461,6 +459,33 @@ if ($sth->rowCount() > 0) { } else { echo '

', _('No maintenance records found.'), "

\n"; } +echo '

', "\n"; +echo ''; +echo _('Add maintenance'), "\n"; +echo "
\n"; + +// Measurement records +echo '

', _('Measurements'), "

"; + +$sql = "SELECT mid, mname, nval, val1, val2, val3, unit, accuracy FROM measurement WHERE eid=?"; +$sth = $pdo->prepare($sql); +$sth->execute([$id]); +if ($sth->rowCount() > 0) { + echo "
    \n"; + foreach ($sth->fetchAll() as $row) { + echo "
  • ", $row['mname'], ': '; + echo format_measurement($row['nval'], $opt_unit[$row['unit']], $row['val1'], $row['val2'], $row['val3']); + echo ' '; + echo "
  • \n"; + } + echo "
\n"; +} else { + echo '

', _('No measurement records found.'), "

\n"; +} +echo '

', "\n"; +echo ''; +echo _('Add measurement'), "\n"; +echo "
\n"; elseif ($action == ACT_EDIT): // ========== VARIANT: edit single record ===================================== diff --git a/webgui/footer.php b/webgui/footer.php index de8fe0c..b00c536 100644 --- a/webgui/footer.php +++ b/webgui/footer.php @@ -3,5 +3,6 @@
+ diff --git a/webgui/globals.inc b/webgui/globals.inc index 1305443..0318b9c 100644 --- a/webgui/globals.inc +++ b/webgui/globals.inc @@ -63,8 +63,11 @@ if ($g_scriptname != 'login.php') { $_SESSION['prelogin'] = $_SERVER['REQUEST_URI']; header_location('login.php'); } + $g_referrer = $_SESSION['coming_from']; + $_SESSION['coming_from'] = $g_scriptname; } +// database $pdo = new PDO("mysql:host=$g_db_host;dbname=$g_db_schema;charset=utf8mb4", $g_db_username, $g_db_password); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); @@ -81,6 +84,9 @@ if ($g_scriptname != 'login.php') { $action = NULL; $valid = FALSE; +// document storage +$g_doc_mimetypes = ['image/png', 'image/jpeg', 'image/svg+xml', 'application/pdf']; + // Initialize message system $g_message = new Message; $g_success = new MessageSuccess; @@ -353,9 +359,12 @@ function get_enum($enum) { 'fixed' => _('Fixed'), 'generic' => _('Generic'), 'good' => _('Good'), + 'high' => _('High'), 'invoice' => _('Invoice'), 'locked' => _('Locked'), + 'low' => _('Low'), 'manual' => _('Manual'), + 'mediim' => _('Medium'), 'mono' => _('Monohull'), 'new' => _('New'), 'normal' => _('Normal'), @@ -642,13 +651,13 @@ function form_add_button($script, $id=NULL, $idname='id') { echo "
\n"; } -function form_view_buttons($script, $id) { +function form_view_buttons($script, $id, $backlink=NULL) { echo '
', "\n"; echo '', _('Edit'), "\n"; echo ' '; echo '', _('Delete'), "\n"; echo ' '; - echo '', _('Back'), "\n"; + echo '', _('Back'), "\n"; echo "
\n"; } @@ -673,8 +682,23 @@ function form_delete_buttons($script, $id, $token) { echo '', "\n"; echo '\n"; echo '', _('Back'), "\n"; - echo "\n"; echo "\n"; + echo "\n"; +} + +function form_tag_assignment($script, $id) { + echo '
', _('Tags'), "
', _('Tag assignment'), "
', "\n"; + echo '
'; + echo '', "\n"; + echo '', "\n"; + echo '', "\n"; + echo '', "\n"; + echo "
', _('Count'), '', $sth->fetchColumn(), "
', _('Inventory') , "
', _('Count'), '', $sth->fetchColumn(), "
\n"; ?> @@ -344,6 +342,7 @@ echo "\n";