diff --git a/db/mariadb.sql b/db/mariadb.sql
index 1fdd94a..8bd4dc7 100644
--- a/db/mariadb.sql
+++ b/db/mariadb.sql
@@ -146,6 +146,7 @@ CREATE TABLE inventory (
price decimal(12,2) DEFAULT NULL,
purchdate date DEFAULT NULL,
invcond enum('unknown','good','normal','bad','repairable','defect') NOT NULL default 'unknown',
+ remarks varchar(150) DEFAULT NULL,
PRIMARY KEY (invid),
INDEX ix_invname (invname)
);
@@ -189,16 +190,20 @@ CREATE TABLE document (
pages smallint(6) unsigned NOT NULL DEFAULT 1,
remarks varchar(150) DEFAULT NULL,
PRIMARY KEY (docid)
-);
+) ENGINE=InnoDB;
CREATE TABLE docref (
drid int(10) NOT NULL AUTO_INCREMENT,
- reftype enum('vessel', 'box', 'equipment', 'project', 'task') NOT NULL DEFAULT 'vessel',
+ reftype enum('vessel', 'box', 'equipment', 'project', 'task', 'user') NOT NULL DEFAULT 'vessel',
docid smallint(6) NOT NULL,
refid smallint(6) NOT NULL,
PRIMARY KEY (drid),
- UNIQUE INDEX ix_docref (docid, refid)
-);
+ UNIQUE INDEX ix_docref (docid, refid),
+ FOREIGN KEY fx_docref_doc (docid)
+ REFERENCES document (docid)
+ ON DELETE RESTRICT
+ ON UPDATE CASCADE
+) ENGINE=InnoDB;
CREATE TABLE company (
compid smallint(6) NOT NULL AUTO_INCREMENT,
diff --git a/webgui/box.php b/webgui/box.php
index a91019f..fdf193e 100644
--- a/webgui/box.php
+++ b/webgui/box.php
@@ -36,33 +36,18 @@ switch ($submit = form_get_action()) {
$p[':sid'] = gpc_get_int($_POST, 'sid');
$p[':content'] = gpc_get_string($_POST, 'content');
$p[':remarks'] = gpc_get_string($_POST, 'remarks');
- $keys = array_keys($p);
- $fields = join(',', array_map(function($s) { return ltrim($s, ':'); }, $keys));
- $pnames = join(',', $keys);
- $sth = $pdo->prepare("INSERT INTO box ($fields) VALUES ($pnames)");
- try {
- $sth->execute($p);
- } catch (PDOexception $e) {
- $g_error->Add('SQL-Error: '. $e->getMessage());
- }
- $id = $pdo->LastInsertId();
+ $id = db_exec_insert('box', $p);
$action = ACT_VIEW;
break;
case 'update':
+ $p[':boxid'] = $id;
$p[':label'] = gpc_get_string($_POST, 'label');
$p[':content'] = gpc_get_string($_POST, 'content');
$p[':color'] = gpc_get_color($_POST, 'color');
$p[':weight'] = min(gpc_get_float($_POST, 'weight'), 99.99);
$p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
- $fields = join(',', array_map(function($s) { return ltrim($s, ':') . '=' . $s; }, array_keys($p)));
- $sth = $pdo->prepare("UPDATE box SET $fields WHERE boxid=:boxid");
- $p[':boxid'] = $id;
- try {
- $sth->execute($p);
- } catch (PDOexception $e) {
- $g_error->Add('SQL-Error: '. $e->getMessage());
- }
+ db_exec_update('box', $p, 'boxid');
$action = ACT_VIEW;
break;
diff --git a/webgui/config.inc-sample b/webgui/config.inc-sample
index ee48b72..8a703b3 100644
--- a/webgui/config.inc-sample
+++ b/webgui/config.inc-sample
@@ -38,3 +38,6 @@ $g_doc_maxsize = 1024*1024*16; // 16 MB
$g_storage_limit = 1024; // MB
$g_thumb_size = 120;
+
+$g_rows_pp = 10; // pagination limit
+
diff --git a/webgui/documents.php b/webgui/documents.php
index cc760c6..e690ada 100644
--- a/webgui/documents.php
+++ b/webgui/documents.php
@@ -24,9 +24,7 @@ switch ($submit = form_get_action()) {
case 'insert':
// WIP New standalone document
- $p[':title'] = gpc_get_string($_POST, 'title');
- $p[':remarks'] = gpc_get_string($_POST, 'remarks');
- $g_message->Add(print_r($_FILES, true));
+ // debug $g_message->Add(print_r($_FILES, true));
if (empty($_FILES['files']['tmp_name']) ) {
$g_warning->Add(_('No file for upload submitted. Try again by selecting a file first.'));
$action = ACT_ADD;
@@ -66,6 +64,7 @@ switch ($submit = form_get_action()) {
case 'application/pdf':
$file_techname = $g_doc_basepath . '/doc-'.$file_hash.'.'.$file_ext;
$doctype = 'generic';
+ // $p['pages'] = pdf_get_pagecount($file_tmp);
break;
case 'image/svg+xml':
$file_techname = $g_doc_basepath . '/drw-'.$file_hash.'.'.$file_ext;
@@ -86,41 +85,17 @@ switch ($submit = form_get_action()) {
$p[':docsize'] = $file_size;
$p[':title'] = gpc_get_string($_POST, 'title');
$p[':remarks'] = gpc_get_string($_POST, 'remarks');
-/* $sql = "INSERT INTO document"
- . " (doctype, filename, extension, hash, doctime, docsize, mimetype) "
- . "VALUES"
- . " (?, ?, ?, ?, ?, ?, ?)";
- $sth = $pdo->prepare($sql);
- try {
- $sth->execute([$doctype, $file_name, $file_ext, $file_hash, $file_timestamp, $file_size, $file_mimetype]);
- } catch (PDOException $e) {
- $g_error->Add('SQL-Error: '. $e->getMessage());
- }
- $id = $pdo->lastInsertId(); */
$id = db_exec_insert('document', $p);
move_uploaded_file($file_tmp, $file_techname);
$action = ACT_VIEW;
break;
case 'update':
- $filename = gpc_get_string($_POST, 'filename');
- $title = gpc_get_string($_POST, 'title', 40);
- $remarks = gpc_get_string($_POST, 'remarks', 150);
- $sql = "UPDATE document "
- . "SET filename=:filename,"
- . " title=:title,"
- . " remarks=:remarks "
- . "WHERE docid=:docid";
- $sth = $pdo->prepare($sql);
- $sth->bindValue(':docid', $id, PDO::PARAM_INT);
- $sth->bindValue(':filename', $filename, PDO::PARAM_STR);
- $sth->bindValue(':title', $title, PDO::PARAM_STR);
- $sth->bindValue(':remarks', $remarks, PDO::PARAM_STR);
- try {
- $sth->execute();
- } catch (PDOException $e) {
- $g_error->Add('SQL-Error: '. $e->getMessage());
- }
+ $p[':docid'] = $id;
+ $p['filename'] = gpc_get_string($_POST, 'filename');
+ $p['title'] = gpc_get_string($_POST, 'title', 40);
+ $p['remarks'] = gpc_get_string($_POST, 'remarks', 150);
+ db_exec_update('document', $p, 'docid');
$action = ACT_VIEW;
break;
diff --git a/webgui/dropdown.php b/webgui/dropdown.php
index 3809c63..cceddc3 100644
--- a/webgui/dropdown.php
+++ b/webgui/dropdown.php
@@ -236,7 +236,7 @@ foreach ($sth->fetchAll() as $row) {
echo '
', $row['ddval'],' | ';
echo '', $row['ddtext'], ' | ';
echo '', $row['ddshort'], ' | ';
- echo '', $row['color'], ' | ';
+ echo '', format_color($row['color']), ' | ';
echo '', $row['sort'], ' | ';
// Action links
echo '';
diff --git a/webgui/equipment.php b/webgui/equipment.php
index 0cedd22..568e51e 100644
--- a/webgui/equipment.php
+++ b/webgui/equipment.php
@@ -11,8 +11,8 @@ $pagetitle = _('Equipment');
$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_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
// ========== ACTIONS START ===================================================
@@ -26,72 +26,47 @@ switch ($submit = form_get_action()) {
case 'edit': $action = ACT_EDIT; break;
case 'del': $action = ACT_DELETE; break;
- case 'insert':
- $ename = gpc_get_string($_POST, 'ename');
- $ecat = gpc_get_int($_POST, 'category');
- $manufacturer = gpc_get_int($_POST, 'manufacturer');
- $model = gpc_get_string($_POST, 'model');
- $remarks = gpc_get_string($_POST, 'remarks', 150);
- $sql = "INSERT INTO equipment "
- . " (vid, ename, manufacturer, model, ecat, remarks) "
- . "VALUES "
- . " (:vid, :ename, :manufacturer, :model, :ecat, :remarks)";
+ case 'filter':
+ // TODO save new filter settings
+ $flt = array();
+ $flt['cat'] = gpc_get_int($_POST, 'flt_category');
+ $flt['manuf'] = gpc_get_int($_POST, 'flt_manuf');
+ $flt['supp'] = gpc_get_int($_POST, 'flt_supp');
+ $flt['txt'] = gpc_get_string($_POST, 'flt_txt');
+ $sql = "UPDATE settings SET valstr=? WHERE userid=? AND sno=200";
$sth = $pdo->prepare($sql);
- $sth->bindValue(':vid', $user->vid, PDO::PARAM_INT);
- $sth->bindValue(':ename', $ename, PDO::PARAM_STR);
- $sth->bindValue(':model', $model, PDO::PARAM_STR);
- $sth->bindValue(':ecat', $ecat, PDO::PARAM_INT);
- $sth->bindValue(':manufacturer', $manufacturer, PDO::PARAM_INT);
- $sth->bindValue(':remarks', $remarks, PDO::PARAM_STR);
- try {
- $sth->execute();
- } catch (PDOException $e) {
- $g_error->Add('SQL-Error: '. $e->getMessage());
- }
- $id = $pdo->lastInsertId();
+ $sth->execute([json_encode($flt), $user->id]);
+ // Only warning in case of failure
+ $action = ACT_DEFAULT;
+ break;
+
+ case 'insert':
+ $p[':vid'] = $user->vid;
+ $p[':ename'] = gpc_get_string($_POST, 'ename');
+ $p[':ecat'] = gpc_get_int($_POST, 'category');
+ $p[':manufacturer'] = gpc_get_int($_POST, 'manufacturer');
+ $p[':model'] = gpc_get_string($_POST, 'model');
+ $p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
+ $id = db_exec_insert('equipment', $p);
$action = ACT_VIEW;
break;
case 'update':
- $ename = gpc_get_string($_POST, 'ename');
- $model = gpc_get_string($_POST, 'model');
- $serial = gpc_get_string($_POST, 'serial');
- $weight = min(gpc_get_float($_POST, 'weight'), 999.99); // limit max value
- $price = gpc_get_currency($_POST, 'price');
- $purchdate = gpc_get_date($_POST, 'purchdate');
- $supplier = gpc_get_int($_POST, 'supplier');
- $manufacturer = gpc_get_int($_POST, 'manufacturer');
- $ecat = gpc_get_int($_POST, 'category');
- $remarks = gpc_get_string($_POST, 'remarks', 150);
- $sql = "UPDATE equipment "
- . "SET ename=:ename,"
- . " model=:model,"
- . " serial=:serial,"
- . " weight=:weight,"
- . " price=:price,"
- . " purchdate=:purchdate,"
- . " supplier=:supplier,"
- . " manufacturer=:manufacturer,"
- . " ecat=:ecat,"
- . " remarks=:remarks "
- . "WHERE eid=:eid";
- $sth = $pdo->prepare($sql);
- $sth->bindValue(':eid', $id, PDO::PARAM_INT);
- $sth->bindValue(':ename', $ename, PDO::PARAM_STR);
- $sth->bindValue(':model', $model, PDO::PARAM_STR);
- $sth->bindValue(':serial', $serial, PDO::PARAM_STR);
- $sth->bindValue(':weight', $weight);
- $sth->bindValue(':price', $price);
- $sth->bindValue(':purchdate', $purchdate, PDO::PARAM_STR);
- $sth->bindValue(':supplier', $supplier, PDO::PARAM_INT);
- $sth->bindValue(':manufacturer', $manufacturer, PDO::PARAM_INT);
- $sth->bindValue(':ecat', $ecat, PDO::PARAM_INT);
- $sth->bindValue(':remarks', $remarks, PDO::PARAM_STR);
- try {
- $sth->execute();
- } catch (PDOException $e) {
- $g_error->Add('SQL-Error: '. $e->getMessage());
- }
+ $p[':eid'] = $id;
+ $p[':ename'] = gpc_get_string($_POST, 'ename');
+ $p[':model'] = gpc_get_string($_POST, 'model');
+ $p[':serial'] = gpc_get_string($_POST, 'serial');
+ $p[':weight'] = min(gpc_get_float($_POST, 'weight'), 999.99); // limit max value
+ $p[':price'] = gpc_get_currency($_POST, 'price');
+ $p[':purchdate'] = gpc_get_date($_POST, 'purchdate');
+ $p[':supplier'] = gpc_get_int($_POST, 'supplier');
+ if ($p[':supplier'] <= 0) $p[':supplier'] = NULL;
+ $p[':manufacturer'] = gpc_get_int($_POST, 'manufacturer');
+ if ($p[':manufacturer'] <= 0) $p[':manufacturer'] = NULL;
+ $p[':ecat'] = gpc_get_int($_POST, 'category');
+ if ($p[':ecat'] <= 0) $p[':ecat'] = NULL;
+ $p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
+ db_exec_update('equipment', $p, 'eid');
$action = ACT_VIEW;
break;
@@ -208,24 +183,80 @@ require 'header.php';
if ($action == ACT_DEFAULT):
// ========== VARIANT: default behavior =======================================
+// load filter from db
+$flt = db_get_filter($user->id, 200);
+/*$flt = new stdClass();
+$sth = $pdo->prepare("SELECT valstr FROM settings WHERE userid=? AND sno=200");
+try {
+ $sth->execute([$user->id]);
+ $json = $sth->fetchColumn();
+ if (!$json) {
+ // no settings record. create empty one for later updates
+ $sth = $pdo->prepare("INSERT INTO settings (userid, sno, valstr) VALUES (?, 200, '[]')");
+ $sth->execute([$user->id]);
+ } else {
+ $flt = json_decode($json);
+ }
+} catch (PDOexception $e) {
+ $g_warning->Add('SQL-Error: '. $e->getMessage());
+} */
+
$sort = array(
1 => 'ename',
2 => 'ename DESC'
);
+$w = array('vid=:vid');
+$p = array(':vid' => $user->vid);
+if ($flt->cat == -1) {
+ $w[] = 'ecat IS NULL';
+} elseif ($flt->cat > 0) {
+ $w[] = 'ecat=:ecat';
+ $p[':ecat'] = $flt->cat;
+}
+if ($flt->manuf > 0) {
+ $w[] = 'manufacturer=:manuf';
+ $p[':manuf'] = $flt->manuf;
+}
+if ($flt->supp > 0) {
+ $w[] = 'supplier=:supp';
+ $p[':supp'] = $flt->supp;
+}
+if (strlen($flt->txt) > 1) {
+ $w[] = '(ename LIKE :txt OR model LIKE :txt OR remarks LIK :txt';
+ $p[':txt'] = '%'.$flt->txt.'%';
+}
+$where = join(' AND ', $w);
+$order = ' ORDER BY ename';
+
+// get total recond count for pagination and limit
+$sth = $pdo->prepare("SELECT COUNT(*) FROM equipment WHERE " . $where);
+$sth->execute($p);
+$numrows = $sth->fetchColumn();
+$lastpage = ceil($numrows/$g_rows_pp);
+$page = gpc_get_int($_REQUEST, 'p', 1);
+
$sql = "SELECT eid, ename, manufacturer, model, serial, remarks,"
. " TIMESTAMPDIFF(MONTH, purchdate, NOW()) AS age_mon "
- . "FROM equipment WHERE vid=? "
- . "ORDER BY eid";
+ . "FROM equipment";
+$sql .= ' WHERE ' . $where;
+$sql .= $order;
+
+// if pagination:
+$sql .= ' LIMIT ' . ($page - 1) * $g_rows_pp . ',' . $g_rows_pp;
+
$sth = $pdo->prepare($sql);
-$sth->execute([$user->vid]);
+$sth->execute($p);
$res = $sth->fetchAll();
echo "$pagetitle\n";
// Filter
+$opt_special = array(
+ -2 => _('― all ―'),
+ -1 => _('― none ―')
+);
?>
-
', "\n";
echo "\n";
-echo "";
-echo "| " . _('Description') . " | ";
-echo "" . _('Manufacturer') . " | ";
-echo "" . _('Model') . " | ";
-echo "" . _('Serial') . " | ";
-echo "" . _('Age') . " | ";
-echo "" . _('Remarks') . " | ";
+echo ' ';
+echo '| ', _('Description'), " | ";
+echo '', _('Manufacturer'), " | ";
+echo '', _('Model'), " | ";
+echo '', _('Serial'), " | ";
+echo '', _('Age'), " | ";
+echo '', _('Remarks'), " | ";
echo " | ";
echo " \n";
echo "\n";
@@ -275,20 +332,22 @@ foreach ($res as $row) {
$age = sprintf(_('%dy'), intdiv($row['age_mon'], 12));
}
echo " | \n";
- echo "| ". $row['ename'] ." | \n";
- echo "". $opt_manufacturer[$row['manufacturer']] ." | \n";
- echo "". $row['model'] ." | \n";
- echo "". $row['serial'] ." | \n";
- echo "". $age ." | \n";
- echo "". $row['remarks'] ." | \n";
+ echo "", $row['ename'], " | \n";
+ echo "", ($opt_manufacturer[$row['manufacturer']] ?? ''), " | \n";
+ echo "", $row['model'], " | \n";
+ echo "", $row['serial'], " | \n";
+ echo "", $age, " | \n";
+ echo "", $row['remarks'], " | \n";
// Action buttons
form_action_buttons($g_scriptname, $row['eid']);
}
?>
- |
+ |
+
-
- */
+echo $pagination;
form_add_button($g_scriptname);
elseif ($action == ACT_ADD):
// ========== VARIANT: add record =============================================
+
+// filter used to preselect fields
+$flt = db_get_filter($user->id, 200);
?>
=_('Add Equipment')?>
\n";