diff --git a/db/mariadb.sql b/db/mariadb.sql index 8bd4dc7..a852f01 100644 --- a/db/mariadb.sql +++ b/db/mariadb.sql @@ -78,9 +78,12 @@ CREATE TABLE storage ( stype tinyint(3) NOT NULL DEFAULT 0, capacity smallint(6) DEFAULT NULL, capaunit enum('kg', 'l') DEFAULT NULL, - x smallint(6) NOT NULL DEFAULT 0, + x smallint(6) UNSIGNED NOT NULL DEFAULT 0, y smallint(6) NOT NULL DEFAULT 0, z smallint(6) NOT NULL DEFAULT 0, + wx smallint(6) UNSIGNED NOT NULL DEFAULT 0, + wy smallint(6) UNSIGNED NOT NULL DEFAULT 0, + wz smallint(6) UNSIGNED NOT NULL DEFAULT 0, remarks varchar(150) DEFAULT NULL, PRIMARY KEY (sid) ); @@ -122,7 +125,7 @@ CREATE TABLE equipment ( eid smallint(6) NOT NULL AUTO_INCREMENT, vid smallint(6) NOT NULL DEFAULT 1, ename varchar(80) NOT NULL, - make varchar(40), + shortname varchar(20) DEFAULT NULL, model varchar(40), ecat tinyint(3) DEFAULT NULL, serial varchar(30), @@ -189,7 +192,8 @@ CREATE TABLE document ( title varchar(40) DEFAULT NULL, pages smallint(6) unsigned NOT NULL DEFAULT 1, remarks varchar(150) DEFAULT NULL, - PRIMARY KEY (docid) + PRIMARY KEY (docid), + UNIQUE INDEX ix_hash (hash) ) ENGINE=InnoDB; CREATE TABLE docref ( @@ -207,8 +211,9 @@ CREATE TABLE docref ( CREATE TABLE company ( compid smallint(6) NOT NULL AUTO_INCREMENT, - compname varchar(40) NOT NULL, + compname varchar(60) NOT NULL, comptype tinyint(3) NOT NULL DEFAULT 1, + shortname varchar(20) DEFAULT NULL, street varchar(30), zip varchar(10), city varchar(30), diff --git a/webgui/box.php b/webgui/box.php index fdf193e..b6a436d 100644 --- a/webgui/box.php +++ b/webgui/box.php @@ -137,8 +137,8 @@ foreach ($opt_storage as $k => $v) { elseif ($action == ACT_VIEW): // ========== VARIANT: view single record ===================================== -$sql = "SELECT label, content, color, weight, remarks " - . "FROM box " +$sql = "SELECT label, content, color, weight, box.remarks, box.sid, sname " + . "FROM box LEFT JOIN storage USING (sid) " . "WHERE boxid=?"; $sth = $pdo->prepare($sql); $sth->execute([$id]); @@ -150,6 +150,9 @@ echo '', "\n"; echo '\n"; echo '\n"; echo '\n"; +echo '\n"; echo '\n"; echo "
', _('Content'),"", $box->content, "
', _('Color'), '', format_color($box->color), "
', _('Weight'), '', format_float($box->weight, 2, 'kg'), "
', _('Storage'),"", $box->sname; +echo ''; +echo "
', _('Remarks'),"", $box->remarks, "
\n"; diff --git a/webgui/company.php b/webgui/company.php index fe43988..fe4d135 100644 --- a/webgui/company.php +++ b/webgui/company.php @@ -23,6 +23,14 @@ switch ($submit = form_get_action()) { case 'edit': $action = ACT_EDIT; break; case 'del': $action = ACT_DELETE; break; + case 'filter': + $flt = array(); + $flt['type'] = gpc_get_int($_POST, 'flt_type'); + $flt['txt'] = gpc_get_string($_POST, 'flt_txt'); + db_save_filter($flt, 208); + $action = ACT_DEFAULT; + break; + case 'insert': $p[':compname'] = gpc_get_string($_POST, 'compname'); $p[':comptype'] = gpc_get_int($_POST, 'comptype'); @@ -33,6 +41,7 @@ switch ($submit = form_get_action()) { case 'update': $p[':compid'] = $id; $p[':compname'] = gpc_get_string($_POST, 'compname'); + $p[':shortname'] = gpc_get_string($_POST, 'shortname', 20); $p[':comptype'] = gpc_get_int($_POST, 'comptype'); $p[':street'] = gpc_get_string($_POST, 'street', 30); $p[':zip'] = gpc_get_string($_POST, 'zip', 10); @@ -78,13 +87,69 @@ require 'header.php'; if ($action == ACT_DEFAULT): // ========== VARIANT: default behavior ======================================= -echo '

', $pagetitle , "

\n"; +// load filter from db +$flt = db_get_filter($user->id, 208); + +$w = array(); +$p = array(); +if ($flt->type > 0) { + $w[] = 'comptype=:comptype'; + $p[':comptype'] = $flt->type; +} +if (strlen($flt->txt) > 1) { + $w[] = '(compname LIKE :txt OR remarks LIKE :txt)'; + $p[':txt'] = '%'.$flt->txt.'%'; +} +$where = join(' AND ', $w); +$order = ' ORDER BY comptype, compname'; $sql = "SELECT compid, compname, comptype, remarks " - . "FROM company " - . "ORDER BY comptype, compname"; -$sth = $pdo->query($sql); + . "FROM company"; +if ($where) $sql .= ' WHERE ' . $where; +$sql .= $order; +$sth = $pdo->prepare($sql); +try { + $sth->execute($p); +} catch(PDOException $e) { + $g_error->Add($e->getMessage()); + $g_error->Add($sql); + $g_error->Add(print_r($p, true)); +} $res = $sth->fetchAll(); + +echo '

', $pagetitle , "

\n"; + +// Filter +$opt_special = array( + -2 => _('― all ―'), +); +?> +
+
+
Filter
+
+ + + + + +
+
+
+ +', "\n"; echo "\n"; echo ""; @@ -134,7 +199,7 @@ echo '

', _('Add Company'), "

\n"; elseif ($action == ACT_VIEW): // ========== VARIANT: view single record ===================================== -$sql = "SELECT compname, comptype, street, zip, city, country," +$sql = "SELECT compname, comptype, shortname, street, zip, city, country," . " contact, phone, email, web, customerno, contractno, remarks " . "FROM company " . "WHERE compid=?"; @@ -145,7 +210,8 @@ $company = $sth->fetch(PDO::FETCH_OBJ); echo "

", $company->compname, "

\n"; echo '', "\n"; -echo '\n"; +echo '\n"; +echo '\n"; echo '\n"; echo '\n"; echo '\n"; @@ -162,15 +228,17 @@ echo "
', _('Name'),"", $company->compname, "
', _('Name'),"", $company->compname, "
', _('Short name'),"", $company->shortname, "
', _('Type'),"", $opt_comptype[$company->comptype], "
', _('Street'),"", $company->street, "
', _('Zip, City'),"", $company->zip, ' ', $company->city, "
\n"; form_view_buttons($g_scriptname, $id); // show referenced equipment -$sql = "SELECT ename FROM equipment WHERE supplier=:id OR manufacturer=:id"; +$sql = "SELECT eid, ename FROM equipment WHERE supplier=:id OR manufacturer=:id"; $sth = $pdo->prepare($sql); $sth->bindValue(':id', $id, PDO::PARAM_INT); $sth->execute(); -if ($sth->rowCount > 0) { +if ($sth->rowCount() > 0) { echo "

Referenced in equipment:

\n"; echo "\n"; } else { @@ -197,6 +265,10 @@ $company = $sth->fetch(PDO::FETCH_OBJ); +
+ + +
+ $v) { + echo ''; +} +?> + + + + +
+ + + +', "\n"; echo "\n"; echo ""; -echo "" . _('ID') . ""; -echo "" . _('Type') . ""; -echo "" . _('Filename') . ""; -echo "" . _('Title') . ""; -echo "" . _('Links') . ""; +echo "", _('ID'), ""; +echo "", _('Type'), ""; +echo "", _('Filename'), ""; +echo "", _('Title'), ""; +echo "", _('Links'), ""; echo " "; echo "\n"; echo "\n"; foreach ($res as $row) { echo "\n"; - echo "". $row['docid'] ."\n"; - echo "". $row['doctype'] ."\n"; - echo "". $row['filename'] ."\n"; - echo "". $row['title'] ."\n"; - echo "". $row['refcount'] ."\n"; + echo "", $row['docid'], "\n"; + echo "", $opt_doctype[$row['doctype']], "\n"; + echo "", $row['filename'], "\n"; + echo "", $row['title'], "\n"; + echo "", $row['refcount'], "\n"; // Action buttons echo ""; echo '', "\n"; @@ -252,6 +309,8 @@ $document = $sth->fetch(PDO::FETCH_OBJ); echo '

', _('View Document'), "

\n"; +echo '
', "\n"; +echo '
', "\n"; echo '', "\n"; echo '\n"; if ($document->doctype == 'picture') { @@ -266,22 +325,30 @@ if ($document->doctype == 'picture') { echo ''; echo '', "\n"; } elseif (($document->doctype == 'generic')) { - $techname = 'doc-' . $document->hash . '.' . $document->extension; + $techname = sprintf('doc-%06d.%s', $document->docid, $document->extension); if ($document->mimetype == 'application/pdf') { - // TODO show preview of previewpage, ctrate thumbnail if needed - + // TODO show preview of previewpage, create thumbnail if needed + $pages = pdf_get_pagecount("$g_doc_basepath/$techname"); // Download link - echo '\n"; + echo '\n"; } } echo '\n"; echo '\n"; -echo '\n"; +echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo "
', _('Document type'),"", $document->doctype, "
', _('Drawing'), '', $document->title, '
', _('PDF'), '', $document->title ?? _('Download'), "
', _('PDF'), '', $document->title ?? _('Download'), ' (', sprintf(_('%d Pages'), $pages), ")
', _('Mimetype'),"", $document->mimetype, "
', _('Filename'),"", $document->filename, "
', _('File size'),"", $document->docsize, "
', _('File size'),"", format_filesize($document->docsize), "
', _('Upload date'),"", $document->doctime, "
', _('Title'),"", $document->title, "
', _('Remarks'),"", $document->remarks, "
\n"; +echo "
\n", '
', "\n"; // column break + +if ($document->mimetype == 'application/pdf') { + echo 'PDF-Preview', "\n"; +} + +echo "
\n
\n"; // end of columns + form_view_buttons($g_scriptname, $id); @@ -306,7 +373,8 @@ foreach ($sth->fetchAll() as $row) { echo "", $row['reftype'], ""; echo "", $row['name'], ""; echo ""; - echo ''; + echo ''; + echo ''; echo ""; echo "\n"; } diff --git a/webgui/dropdown.php b/webgui/dropdown.php index cceddc3..2f1af1b 100644 --- a/webgui/dropdown.php +++ b/webgui/dropdown.php @@ -38,7 +38,7 @@ function create_ddval_form($script, $ddid, $formtype, $row=NULL) { echo '
'; echo '
', "\n"; echo '
'; @@ -76,15 +76,7 @@ switch ($submit = form_get_action()) { $p[':ddshort'] = gpc_get_string($_POST, 'ddshort'); $p[':color'] = gpc_get_color($_POST, 'color'); $p[':sort'] = gpc_get_string($_POST, 'sort'); - $keys = array_keys($p); - $fields = join(',', array_map(function($s) { return ltrim($s, ':'); }, $keys)); - $pnames = join(',', $keys); - $sth = $pdo->prepare("INSERT INTO dropdown ($fields) VALUES ($pnames)"); - try { - $sth->execute($p); - } catch (PDOexception $e) { - $g_error->Add('SQL-Error: '. $e->getMessage()); - } + db_exec_insert('dropdown', $p); $action = ACT_EDIT; break; @@ -106,6 +98,15 @@ switch ($submit = form_get_action()) { $action = ACT_EDIT; break; + case 'delete': + // only deletable if not used anywhere! + // equipment.? + if ($v <= 0) { + $g_warning->Add(_('Selection lists are not deletable!')); + } + $g_message->Add(_('Delete not yet implemented')); + break; + default: $g_error->Add(sprintf(_('Unknown function!'), $submit)); $valid = FALSE; diff --git a/webgui/equipment.php b/webgui/equipment.php index 568e51e..2939bd1 100644 --- a/webgui/equipment.php +++ b/webgui/equipment.php @@ -27,16 +27,12 @@ switch ($submit = form_get_action()) { case 'del': $action = ACT_DELETE; break; 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->execute([json_encode($flt), $user->id]); - // Only warning in case of failure + db_save_filter($flt, 200); $action = ACT_DEFAULT; break; @@ -54,6 +50,7 @@ switch ($submit = form_get_action()) { case 'update': $p[':eid'] = $id; $p[':ename'] = gpc_get_string($_POST, 'ename'); + $p[':shortname'] = gpc_get_string($_POST, 'shortname', 20); $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 @@ -185,21 +182,6 @@ if ($action == ACT_DEFAULT): // 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', @@ -223,7 +205,7 @@ if ($flt->supp > 0) { $p[':supp'] = $flt->supp; } if (strlen($flt->txt) > 1) { - $w[] = '(ename LIKE :txt OR model LIKE :txt OR remarks LIK :txt'; + $w[] = '(ename LIKE :txt OR model LIKE :txt OR remarks LIKE :txt)'; $p[':txt'] = '%'.$flt->txt.'%'; } $where = join(' AND ', $w); @@ -231,7 +213,13 @@ $order = ' ORDER BY ename'; // get total recond count for pagination and limit $sth = $pdo->prepare("SELECT COUNT(*) FROM equipment WHERE " . $where); -$sth->execute($p); +try { + $sth->execute($p); +} catch(PDOException $e) { + $g_error->Add($e->getMessage()); + $g_error->Add($sql); + $g_error->Add(print_r($p, true)); +} $numrows = $sth->fetchColumn(); $lastpage = ceil($numrows/$g_rows_pp); $page = gpc_get_int($_REQUEST, 'p', 1); @@ -299,7 +287,7 @@ foreach ($opt_special + $opt_supplier as $k => $v) { - +
@@ -347,15 +335,6 @@ foreach ($res as $row) { - - */ echo $pagination; form_add_button($g_scriptname); @@ -394,7 +373,7 @@ elseif ($action == ACT_VIEW): // ========== VARIANT: view single record ===================================== $sql = "SELECT eid, ename, model, serial, purchdate, price, weight, " - . " supplier, manufacturer, ecat, remarks " + . " supplier, manufacturer, ecat, shortname, remarks " . "FROM equipment " . "WHERE eid=?"; $sth = $pdo->prepare($sql); @@ -408,6 +387,7 @@ echo '
'; echo '
'; echo '', "\n"; +echo '\n"; echo '\n"; echo '\n"; echo '\n"; @@ -426,7 +406,8 @@ echo '
'; prepare($sql); $sth->execute([$id]); $res = $sth->fetchAll(); @@ -438,7 +419,8 @@ foreach ($res as $row) { echo "\n"; } elseif ($row['doctype'] == 'generic') { echo ''; - echo $row['title']; + echo '', $row['title'], ''; + // echo $row['title']; echo "\n"; } } @@ -460,6 +442,26 @@ echo '
'; // 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=?"; +$sth = $pdo->prepare($sql); +$sth->execute([$id]); +if ($sth->rowCount() > 0) { + echo "\n"; +} else { + echo '

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

\n"; +} + elseif ($action == ACT_EDIT): // ========== VARIANT: edit single record ===================================== @@ -471,7 +473,7 @@ foreach ($sth->fetchAll() as $row) { } $sql = "SELECT eid, ename, model, serial, weight, price, purchdate," - . " supplier, manufacturer, ecat, remarks " + . " supplier, manufacturer, ecat, shortname, remarks " . "FROM equipment " . "WHERE eid=?"; $sth = $pdo->prepare($sql); @@ -485,6 +487,10 @@ $equipment = $sth->fetch(PDO::FETCH_OBJ); +

+ + +
manufacturer); ?>
diff --git a/webgui/equipment_js.php b/webgui/equipment_js.php deleted file mode 100644 index 59b3674..0000000 --- a/webgui/equipment_js.php +++ /dev/null @@ -1,294 +0,0 @@ -Add("Unbekannte Funktion!"); - $valid = FALSE; - -} - -// ========== ACTIONS END ===================================================== - -require 'header.php'; - -// ========== PAGE CONTENT ==================================================== - -if ($action == ACT_DEFAULT): -// ========== VARIANT: default behavior ======================================= - -echo "

$pagetitle

\n"; - -$sql = "SELECT eid, ename, make, model, serial, remarks " - . "FROM equipment " - . "ORDER BY eid"; -$sth = $pdo->query($sql); -$res = $sth->fetchAll(); -echo '
', _('Short name'),"", $equipment->shortname, "
', _('Manufacturer'),"", $opt_manufacturer[$equipment->manufacturer], "
', _('Model'),"", $equipment->model, "
', _('Serial'),"", $equipment->serial, "
', "\n"; -echo "\n"; -echo ""; -echo ""; -echo ""; -echo ""; -echo ""; -echo ""; -echo ""; -echo "\n"; -echo "\n"; -foreach ($res as $row) { - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - // Action buttons - echo "\n"; - echo "\n"; -} -// Table summary -echo "\n"; -echo '', "\n"; -echo "\n"; -echo "
" . _('Description') . "" . _('Make') . "" . _('Model') . "" . _('Serial') . "" . _('Remarks') . " 
". $row['ename'] ."". $row['make'] ."". $row['model'] ."". $row['serial'] ."". $row['remarks'] .""; - echo 'View '; - echo 'Edit'; - echo "
', sprintf(_('%d records'), count($res)), '
\n"; - -echo '', _('Add'), "\n"; - -elseif ($action == ACT_ADD): -// ========== VARIANT: add record ============================================= -?> -

-
-
- - -
-
- - -
-
- - -
-
- - -
- - -
-prepare($sql); -$sth->execute([$id]); -$equipment = $sth->fetch(PDO::FETCH_OBJ); -echo "

", $equipment->ename, "

\n"; - -// Bootstrap grid -echo '
'; -echo '
'; -echo '
'; - -echo "\n"; -echo "\n"; -echo "\n"; -echo "\n"; -echo "
", _('Make'),"", $equipment->make, "
", _('Model'),"", $equipment->model, "
", _('Serial'),"", $equipment->serial, "
\n"; - - -echo '
'; // Column break -echo '
'; -?> -

Images and documents go here

-
-
-
-
-
-

Drag and drop your image here or click to select a file.

-
-
- - -
-
-
- - -'; // col -echo '
'; // row -echo '
'; // container - -// Buttons at bottom of data area -echo '
', "\n"; -echo '', _('Edit'), "\n"; -echo ' '; -echo '', _('Delete'), "\n"; -echo ' '; -echo '', _('Back'), "\n"; -echo "
\n"; - - -elseif ($action == ACT_EDIT): -// ========== VARIANT: edit single record ===================================== - -$sql = "SELECT eid, ename, make, model, serial, remarks " - . "FROM equipment " - . "WHERE eid=?"; -$sth = $pdo->prepare($sql); -$sth->execute([$id]); -$equipment = $sth->fetch(PDO::FETCH_OBJ); -?> -

-
-
- - -
-
- - -
-
- - -
-
- - -
- - -
-", _('Unknown function call: Please report to system development!'), "

\n"; - -endif; // $action == ... -// ========== END OF VARIANTS ================================================= - -include 'footer.php'; diff --git a/webgui/globals.inc b/webgui/globals.inc index 4dffd21..1305443 100644 --- a/webgui/globals.inc +++ b/webgui/globals.inc @@ -288,24 +288,50 @@ function db_exec_insert($table, $params) { $keys = array_keys($params); $fields = join(',', array_map(function($s) { return ltrim($s, ':'); }, $keys)); $pnames = join(',', $keys); - $sth = $pdo->prepare("INSERT INTO $table ($fields) VALUES ($pnames)"); + $sql = "INSERT INTO $table ($fields) VALUES ($pnames)"; +// $sth = $pdo->prepare("INSERT INTO $table ($fields) VALUES ($pnames)"); + $sth = $pdo->prepare($sql); try { $sth->execute($params); } catch (PDOexception $e) { $g_error->Add('SQL-Error: '. $e->getMessage()); + $g_error->Add($sql); + $g_error->Add(print_r($params, true)); } return $pdo->LastInsertId(); } function db_exec_update($table, $params, $pk) { + // TODO primary key with multiple fields: $pk is an array global $pdo; global $g_error; $fields = join(',', array_map(function($s) { return ltrim($s, ':') . '=' . $s; }, array_keys($params))); - $sth = $pdo->prepare("UPDATE $table SET $fields WHERE $pk=:$pk"); + $sql = "UPDATE $table SET $fields WHERE $pk=:$pk"; + $sth = $pdo->prepare($sql); try { $sth->execute($params); } catch (PDOexception $e) { $g_error->Add('SQL-Error: '. $e->getMessage()); + $g_error->Add($sql); + $g_error->Add(print_r($params, true)); + return false; + } + return true; +} + +function db_save_filter($flt, $sno) { + global $user; + global $pdo; + global $g_warning; + $sql = "UPDATE settings SET valstr=? WHERE userid=? AND sno=?"; + $sth = $pdo->prepare($sql); + try { + $sth->execute([json_encode($flt), $user->id, $sno]); + } catch (PDOexception $e) { + $g_warning->Add('SQL-Error: '. $e->getMessage()); + $g_warning->Add($sql); + $g_warning->Add(print_r($flt, true)); + $g_warning->Add('Setting: ', $sno); return false; } return true; @@ -320,7 +346,7 @@ function get_enum($enum) { 'closed' => _('Closed'), 'defect' => _('Defect'), 'done' => _('Done'), - 'drawing' => _('Drawng'), + 'drawing' => _('Drawing'), 'equipment' => _('Equipment'), 'estimated' => _('Estimated'), 'finished' => _('Finished'), @@ -330,7 +356,7 @@ function get_enum($enum) { 'invoice' => _('Invoice'), 'locked' => _('Locked'), 'manual' => _('Manual'), - 'mono' => _('Monoholl'), + 'mono' => _('Monohull'), 'new' => _('New'), 'normal' => _('Normal'), 'ongoing' => _('Ongoing'), @@ -338,6 +364,7 @@ function get_enum($enum) { 'picture' => _('Picture'), 'planned' => _('Planned'), 'precise' => _('Precise'), + 'repairable' => _('Repairable'), 'rough' => _('Rough'), 'storage' => _('Storage'), 'task' => _('Task'), @@ -536,6 +563,27 @@ function db_get_opt_proj($vid, $default=NULL) { return $list; } +function db_get_filter($user, $sno) { + global $pdo; + global $g_warning; + $flt = new stdClass(); + $sth = $pdo->prepare("SELECT valstr FROM settings WHERE userid=? AND sno=?"); + try { + $sth->execute([$user, $sno]); + $json = $sth->fetchColumn(); + if (!$json) { + // no settings record. create empty one for later updates + $sth = $pdo->prepare("INSERT INTO settings (userid, sno, valstr) VALUES (?, ?, '{}')"); + $sth->execute([$user, $sno]); + } else { + $flt = json_decode($json); + } + } catch (PDOexception $e) { + $g_warning->Add('SQL-Error: '. $e->getMessage()); + } + return $flt; +} + function date_to_sql($var) { if (!isset($var) || $var == '') { return NULL; @@ -563,7 +611,6 @@ function float_to_sql($var) { // ========== FORM FUNCTIONS ================================================== function form_create_select($fieldname, $label, $optlist, $selval=NULL) { - //if ( echo '
', "\n"; echo '\n"; echo '
- +
- +
- +
- +
@@ -391,11 +443,11 @@ $vessel = $sth->fetch(PDO::FETCH_OBJ);
- +
- +
vid); $opt_box = db_get_opt_box($user->vid); +$opt_invcond = db_load_enum('inventory', 'invcond', true, true); // ========== ACTIONS START =================================================== @@ -26,6 +27,12 @@ switch ($submit = form_get_action()) { case 'del': $action = ACT_DELETE; break; case 'filter': + $flt = array(); + $flt['stor'] = gpc_get_string($_POST, 'flt_stor'); + //$flt['box'] = gpc_get_string($_POST, 'flt_box'); + $flt['cond'] = gpc_get_string($_POST, 'flt_cond'); + $flt['txt'] = gpc_get_string($_POST, 'flt_txt'); + db_save_filter($flt, 201); $action = ACT_DEFAULT; break; @@ -94,40 +101,113 @@ the box assignment. But this is also intentional to allow easy rearrangement. echo "

$pagetitle

\n"; +$w = array('vid=:vid'); +$p = array(':vid' => $user->vid); +if ($flt->stor == -1) { + $w[] = 'i.sid IS NULL'; +} elseif ($flt->stor > 0) { + $w[] = 'i.sid=:sid'; + $p[':sid'] = $flt->stor; +} +/*if ($flt->cond <> 'all') { + $w[] = 'indcond=:indcond'; + $p[':indcond'] = $flt->cond; +}*/ +if (strlen($flt->txt) > 1) { + $w[] = 'invname LIKE :txt'; + $p[':txt'] = '%'.$flt->txt.'%'; +} +$where = join(' AND ', $w); +$order = ' ORDER BY invname'; + $sql = "SELECT i.invid, i.invname, i.number, i.invcond, s.sname AS container " - . "FROM inventory AS i JOIN storage AS s ON (i.boxtype='storage' AND i.sid=s.sid)" - . "WHERE s.vid=:vid " - . "UNION " - . "SELECT i.invid, i.invname, i.number, i.invcond, b.label AS container " + . "FROM inventory AS i JOIN storage AS s ON (i.boxtype='storage' AND i.sid=s.sid)"; +$sql .= ' WHERE ' . $where; +$sql .= " UNION SELECT i.invid, i.invname, i.number, i.invcond, b.label AS container " . "FROM inventory AS i JOIN box AS b ON (i.boxtype='box' AND i.boxid=b.boxid) " - . " JOIN storage AS s ON (b.sid=s.sid) " - . "WHERE s.vid=:vid " - . "ORDER BY invname"; + . " JOIN storage AS s ON (b.sid=s.sid) "; +$sql .= ' WHERE ' . $where; +$sql .= $order; $sth = $pdo->prepare($sql); -$sth->bindValue(':vid', $user->vid, PDO::PARAM_INT); -$sth->execute(); +try { + $sth->execute($p); +} catch(PDOException $e) { + $g_error->Add($e->getMessage()); + $g_error->Add($sql); + $g_error->Add(print_r($p, true)); +} $res = $sth->fetchAll(); + +// Filter +$opt_special = array( + -2 => _('― all ―'), + -1 => _('― none ―') +); +?> +
+
+
Filter
+
+ + + + + + + + +
+
+
+ +', "\n"; echo "\n"; echo "\n"; -echo "" . _('Name') . "\n"; -echo "" . _('Container') . ""; -echo "" . _('Number') . ""; -echo "" . _('Condition') . ""; +echo "", _('Name'), "\n"; +echo "", _('Container'), "\n"; +echo "", _('Number'), "\n"; +echo "", _('Condition'), "\n"; +echo "\n"; echo "\n"; echo "\n"; foreach ($res as $row) { echo "\n"; echo '', $row['invname'], "\n"; - echo "". $row['container'] ."\n"; - echo "". $row['number'] ."\n"; - echo "". $row['invcond'] ."\n"; + echo "", $row['container'], "\n"; + echo "", $row['number'], "\n"; + echo "", ($opt_invcond[$row['invcond']] ?? ''), "\n"; form_action_buttons($g_scriptname, $row['invid']); echo "\n"; } // Table summary echo "\n"; -echo '', sprintf(_('%d records'), count($res)), '', "\n"; +echo '', sprintf(_('%d records'), count($res)), '', "\n"; echo "\n"; echo "\n"; diff --git a/webgui/maintenance.php b/webgui/maintenance.php index e94ad65..1cc82ea 100644 --- a/webgui/maintenance.php +++ b/webgui/maintenance.php @@ -24,6 +24,14 @@ switch ($submit = form_get_action()) { case 'edit': $action = ACT_EDIT; break; case 'del': $action = ACT_DELETE; break; + case 'filter': + $flt = array(); + $flt['equip'] = gpc_get_int($_POST, 'flt_equip'); + $flt['txt'] = gpc_get_string($_POST, 'flt_txt'); + db_save_filter($flt, 204); + $action = ACT_DEFAULT; + break; + case 'insert': $p[':vid'] = $user->vid; $p[':eid'] = gpc_get_int($_POST, 'eid'); @@ -58,8 +66,41 @@ require 'header.php'; if ($action == ACT_DEFAULT): // ========== VARIANT: default behavior ======================================= +// load filter from db +$flt = db_get_filter($user->id, 204); + echo '

', $pagetitle, "

\n"; +// Filter +$opt_special = array( + -2 => _('― all ―'), + -1 => _('― none ―') +); +?> +
+
+
Filter
+
+ + + + + +
+
+
+fetchAll(); echo '', "\n"; echo "\n"; echo ""; -echo ""; -echo ""; -echo ""; +echo ""; +echo ""; +echo ""; echo "\n"; echo "\n"; foreach ($res as $row) { @@ -145,6 +186,7 @@ if (isset($maint->eid)) { $docs = $sth->fetchAll(); } else { $maint->ename = _('n/a'); + unset($docs); } // Bootstrap grid @@ -162,15 +204,16 @@ echo ''; // Column break echo '
'; // TODO Show documents for equipment -?> -

Documents

-', "\n"; -foreach ($docs as $d) { - echo '
  • ', $d['title'] ?? $d['filename'], ' (', $d['docid'], ")
  • \n"; +echo "

    Documents

    \n"; +if (isset($docs)) { + echo '
      ', "\n"; + foreach ($docs as $d) { + echo '
    • ', $d['title'] ?? $d['filename'], ' (', $d['docid'], ")
    • \n"; + } + echo "
    \n"; +} else { + echo '

    ', _('No documents found.'), "

    \n"; } -echo "\n"; - echo '
    '; // col echo ''; // row diff --git a/webgui/manual.php b/webgui/manual.php index 8227d18..63fc19a 100644 --- a/webgui/manual.php +++ b/webgui/manual.php @@ -58,6 +58,10 @@ Kiste.

    Proviant

    Proviant ist verderblich. Es wird das Einlagerungsdatum erfaßt und das Haltbarkeitsdatum

    +

    Proviant kann einem Stauraum und somit einem Boot zugeordnet sein +oder aber frei. +Freier Proviant kann später zugeordnet +werden. Er ist erkennbar am Einkaufswagen-Symbol .

    Wartung

    Es können einmalige und wiederkehrende Wartungen erfaßt werden

    diff --git a/webgui/measurement.php b/webgui/measurement.php index a02b727..4329bfa 100644 --- a/webgui/measurement.php +++ b/webgui/measurement.php @@ -42,6 +42,14 @@ switch ($submit = form_get_action()) { case 'edit': $action = ACT_EDIT; break; case 'del': $action = ACT_DELETE; break; + case 'filter': + $flt = array(); + $flt['precision'] = gpc_get_string($_POST, 'flt_precision'); + $flt['txt'] = gpc_get_string($_POST, 'flt_txt'); + db_save_filter($flt, 207); + $action = ACT_DEFAULT; + break; + case 'insert': $p[':mname'] = gpc_get_string($_POST, 'mname'); $p[':note'] = gpc_get_string($_POST, 'note'); @@ -61,20 +69,12 @@ switch ($submit = form_get_action()) { if ($p[':eid'] == -1) { $p[':eid'] = NULL; } - $keys = array_keys($p); - $fields = join(',', array_map(function($s) { return ltrim($s, ':'); }, $keys)); - $pnames = join(',', $keys); - $sth = $pdo->prepare("INSERT INTO measurement ($fields) VALUES ($pnames)"); - try { - $sth->execute($p); - } catch (PDOexception $e) { - $g_error->Add('SQL-Error: '. $e->getMessage()); - } - $id = $pdo->LastInsertId(); + $id = db_exec_insert('measurement', $p); $action = ACT_VIEW; break; case 'update': + $p[':mid'] = $id; $p[':mname'] = gpc_get_string($_POST, 'mname'); $p[':nval'] = gpc_get_int($_POST, 'nval'); // 1 to 3 dimensions $p[':val1'] = gpc_get_int($_POST, 'val1'); @@ -94,14 +94,7 @@ switch ($submit = form_get_action()) { if ($p[':eid'] == -1) { $p[':eid'] = NULL; } - $fields = join(',', array_map(function($s) { return ltrim($s, ':') . '=' . $s; }, array_keys($p))); - $sth = $pdo->prepare("UPDATE measurement SET $fields WHERE mid=:mid"); - $p[':mid'] = $id; - try { - $sth->execute($p); - } catch (PDOexception $e) { - $g_error->Add('SQL-Error: '. $e->getMessage()); - } + db_exec_update('measurement', $p, 'mid'); $action = ACT_VIEW; break; @@ -143,6 +136,25 @@ function format_vals($n, $v1, $v2, $v3) { echo "

    $pagetitle

    \n"; +// Filter +$opt_special = array( + -2 => _('― all ―'), + -1 => _('― none ―') +); +?> + +
    +
    Filter
    +
    + + + + +
    +
    + +prepare($sql); - $sth->bindValue(':vid', $user->vid, PDO::PARAM_INT); - $sth->bindValue(':projname', $projname, PDO::PARAM_STR); - $sth->bindValue(':responsible', $responsible, PDO::PARAM_INT); - $sth->bindValue(':remarks', $remarks, PDO::PARAM_STR); - $sth->execute(); - $id = $pdo->lastInsertId(); + $p['vid'] = $user->id; + $p[':projname'] = gpc_get_string($_POST, 'projname'); + $p[':responsible'] = gpc_get_int($_POST, 'responsible'); + $p[':remarks'] = gpc_get_string($_POST, 'remarks', 150); + $id = db_exec_insert('company', $p); $action = ACT_VIEW; break; case 'update': - $projname = gpc_get_string($_POST, 'projname'); - $startdate = gpc_get_date($_POST, 'startdate'); - $duration = gpc_get_int($_POST, 'duration'); - $remarks = gpc_get_string($_POST, 'remarks', 150); - $sql = "UPDATE project " - . "SET projname=:projname," - . " startdate=:startdate," - . " duration=:duration," - . " remarks=:remarks " - . "WHERE projid=:projid"; - $sth = $pdo->prepare($sql); - $sth->bindValue(':projid', $id, PDO::PARAM_INT); - $sth->bindValue(':projname', $projname, PDO::PARAM_STR); - $sth->bindValue(':startdate', $startdate, PDO::PARAM_STR); - $sth->bindValue(':duration', $duration, PDO::PARAM_INT); - $sth->bindValue(':remarks', $remarks, PDO::PARAM_STR); - $sth->execute(); + $p[':projid'] = $id; + $p[':projname'] = gpc_get_string($_POST, 'projname'); + $p[':startdate'] = gpc_get_date($_POST, 'startdate'); + $p[':duration'] = gpc_get_int($_POST, 'duration'); + $p[':remarks'] = gpc_get_string($_POST, 'remarks', 150); + db_exec_update('project', $p, 'projid'); $action = ACT_VIEW; break; case 'delete': + // Security token needed! + if (gpc_get_string($_POST, 'token', 16) != $_SESSION['token']) { + $g_error->Add(_('Delete prohibited, invalid security token!')); + $action = ACT_VIEW; + break; + } + unset($_SESSION['token']); + // TBD $action = ACT_DEFAULT; break; diff --git a/webgui/provisions.php b/webgui/provisions.php index 7dc5623..3355cbd 100644 --- a/webgui/provisions.php +++ b/webgui/provisions.php @@ -26,6 +26,13 @@ switch ($submit = form_get_action()) { case 'edit': $action = ACT_EDIT; break; case 'del': $action = ACT_DELETE; break; + case 'filter': + $flt = array(); + $flt['txt'] = gpc_get_string($_POST, 'flt_txt'); + db_save_filter($flt, 202); + $action = ACT_DEFAULT; + break; + case 'insert': $p[':provname'] = gpc_get_string($_POST, 'provname'); $p[':number'] = gpc_get_int($_POST, 'number'); @@ -74,14 +81,44 @@ require 'header.php'; if ($action == ACT_DEFAULT): // ========== VARIANT: default behavior ======================================= -echo "

    ", $pagetitle, "

    \n"; +// load filter from db +$flt = db_get_filter($user->id, 202); -$sql = "SELECT provid, provname, number, unit, storedate, shelflife, " +$w = array('(vid=:vid OR sid IS NULL)'); +$p = array(':vid' => $user->vid); +if (strlen($flt->txt) > 1) { + $w[] = 'provname LIKE :txt'; + $p[':txt'] = '%'.$flt->txt.'%'; +} +$where = join(' AND ', $w); + +$order = ' ORDER BY provid'; + +// provisions can be assigned to a store or be free +$sql = "SELECT provid, provname, number, unit, storedate, shelflife, sid," . " DATEDIFF(shelflife, storedate) AS d0, DATEDIFF (CURDATE(), storedate) AS d1 " - . "FROM provisions " - . "ORDER BY provid"; -$sth = $pdo->query($sql); + . "FROM provisions LEFT OUTER JOIN storage USING (sid)"; +$sql .= ' WHERE ' . $where; +$sql .= $order; +$sth = $pdo->prepare($sql); +$sth->execute($p); $res = $sth->fetchAll(); + +echo "

    ", $pagetitle, "

    \n"; +?> + +
    +
    Filter
    +
    + + + +
    +
    + + +', "\n"; echo "\n"; echo "\n"; @@ -96,7 +133,7 @@ echo "\n"; echo "\n"; foreach ($res as $row) { echo "\n"; - echo "\n"; + echo "\n"; echo "\n"; echo "\n"; echo "\n"; @@ -139,7 +176,7 @@ echo '

    ', _('Add provisions'), "

    \n"; - + '- none -'] + $opt_storage); ?>
    @@ -163,8 +200,8 @@ echo '
    " . _('Activities') . "" . _('Equipment') . "" . _('Remarks') . "", _('Activities'), "", _('Equipment'), "", _('Remarks'), "
    ". $row['provname'] ."", ! isset($row['sid']) ? ' ' : '', $row['provname'], "". $row['number'] ."". $opt_unit[$row['unit']] ."". $row['storedate'] ."
    ', "\n"; echo '\n"; echo '\n"; echo '\n"; -echo '\n"; -echo '\n"; +echo '\n"; +echo '\n"; echo "
    ', _('Number'),"", $prov->number, "
    ', _('Unit'),"", $opt_unit[$prov->unit], "
    ', _('Storedate'),"", $prov->storedate, "
    ', _('Shelflife'),"", $prov->shelflife, "
    ', _('Storage'),"", $opt_storage[$prov->sid], "
    ', _('Shelflife'),"$prov->shelflife
    ', _('Storage'),"", ($opt_storage[$prov->sid] ?? ''), "
    \n"; form_view_buttons($g_scriptname, $id); diff --git a/webgui/shapes/bavaria34.svg b/webgui/shapes/bavaria34.svg index 0be0b53..5916743 100644 --- a/webgui/shapes/bavaria34.svg +++ b/webgui/shapes/bavaria34.svg @@ -1,6 +1,3 @@ - - - - - prepare($sql); - $sth->bindValue(':vid', $user->vid, PDO::PARAM_INT); - $sth->bindValue(':sname', $sname, PDO::PARAM_STR); - $sth->bindValue(':stype', $stype, PDO::PARAM_INT); - $sth->execute(); - $id = $pdo->lastInsertId(); + $p[':vid'] = $user->vid; + $p[':sname'] = gpc_get_string($_POST, 'sname'); + $p[':stype'] = gpc_get_int($_POST, 'stype'); + $id = db_exec_insert('storage', $p); $action = ACT_VIEW; break; case 'update': - $sname = gpc_get_string($_POST, 'sname'); - $x = gpc_get_int($_POST, 'x'); - $y = gpc_get_int($_POST, 'y'); - $z = gpc_get_int($_POST, 'z'); - $remarks = gpc_get_string($_POST, 'remarks', 150); - $sql = "UPDATE storage " - . "SET sname=:sname," - . " x=:x, y=:y, z=:z," - . " remarks=:remarks " - . "WHERE sid=:sid"; - $sth = $pdo->prepare($sql); - $sth->bindValue(':sid', $id, PDO::PARAM_INT); - $sth->bindValue(':sname', $sname, PDO::PARAM_STR); - $sth->bindValue(':x', $x, PDO::PARAM_INT); - $sth->bindValue(':y', $y, PDO::PARAM_INT); - $sth->bindValue(':z', $z, PDO::PARAM_INT); - $sth->bindValue(':remarks', $remarks, PDO::PARAM_STR); - $sth->execute(); + $p[':sid'] = $id; + $p[':sname'] = gpc_get_string($_POST, 'sname'); + $p[':x'] = gpc_get_int($_POST, 'x'); + $p[':y'] = gpc_get_int($_POST, 'y'); + $p[':z'] = gpc_get_int($_POST, 'z'); + $p[':wx'] = gpc_get_int($_POST, 'wx'); + $p[':wy'] = gpc_get_int($_POST, 'wy'); + $p[':wz'] = gpc_get_int($_POST, 'wz'); + $p[':remarks'] = gpc_get_string($_POST, 'remarks', 150); + db_exec_update('storage', $p, 'sid'); $action = ACT_VIEW; break; @@ -111,7 +95,7 @@ echo '

    ', $pagetitle, "

    \n"; // Storage // stype from dropdown -$sql = "SELECT sid, sname, remarks " +$sql = "SELECT sid, sname, x, y, z, remarks " . "FROM storage " . "WHERE vid=? " . "ORDER BY sid"; @@ -121,15 +105,17 @@ $res = $sth->fetchAll(); echo '', "\n"; echo "\n"; echo ""; -echo ""; -echo ""; +echo ""; +echo ""; +echo ""; echo ""; echo "\n"; echo "\n"; foreach ($res as $row) { echo "\n"; - echo "\n"; - echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; form_action_buttons($g_scriptname, $row['sid']); echo "\n"; } @@ -203,7 +189,7 @@ elseif ($action == ACT_VIEW): // ========== VARIANT: view single record ===================================== $opt_unit = db_get_options(6); -$sql = "SELECT sid, sname, stype, capacity, capaunit, x, y, z, remarks " +$sql = "SELECT sid, sname, stype, capacity, capaunit, x, y, z, wx, wy, wz, remarks " . "FROM storage " . "WHERE sid=?"; $sth = $pdo->prepare($sql); @@ -212,15 +198,16 @@ $storage = $sth->fetch(PDO::FETCH_OBJ); echo '

    ', $storage->sname, "

    \n"; echo '
    " . _('Name') . "" . _('Remarks') . "", _('Name'), "", _('Position'), "", _('Remarks'), " 
    ". $row['sname'] ."". $row['remarks'] ."", $row['sname'], "", join(',', array($row['x'] ?? '?', $row['y'] ?? '?', $row['z'])), "", $row['remarks'], "
    ', "\n"; -echo '\n"; +echo '\n"; echo '\n"; -echo '\n"; +echo '\n"; +echo '\n"; echo '\n"; echo "
    ', _('Typ'),"", $stype[$storage->stype], "
    ', _('Typ'),"", $stype[$storage->stype], "
    ', _('Capacity'),"", $storage->capacity, ' ', $storage->capaunit, "
    ', _('Location (x, y, z)'),"(", $storage->x ?? '?', ', ', $storage->y ?? '?', ', ', $storage->z, ")
    ', _('Location (x, y, z)'),"(", $storage->x, ', ', $storage->y, ', ', $storage->z, ")
    ', _('Width (wx, wy, wz)'),"(", $storage->wx, ', ', $storage->wy, ', ', $storage->wz, ")
    ', _('Remarks'),"", $storage->remarks, "
    \n"; form_view_buttons($g_scriptname, $id); -// Zugeordnete Kisten hier anzeigen +// show assigned boxes here echo '

    ', _('Boxes in storage'), "

    \n"; $sql = "SELECT boxid, label, color FROM box WHERE sid=?"; @@ -228,9 +215,15 @@ $sth = $pdo->prepare($sql); $sth->execute([$id]); $res = $sth->fetchall(); if (count($res) > 0) { + echo ''; foreach ($res as $row) { - echo "$boxid $label $color"; + echo ""; + echo '"; + echo '"; + echo ''; + echo "\n"; } + echo "
    ', $row['label'], "', $row['color'], "
    \n"; } else { echo '

    ', _('No boxes contained'), "

    \n"; } @@ -260,7 +253,7 @@ elseif ($action == ACT_EDIT): echo '

    ', _('Edit Storage'), "

    \n"; -$sql = "SELECT sid, sname, stype, remarks " +$sql = "SELECT sid, sname, stype, x, y, z, wx, wy, wz, remarks " . "FROM storage " . "WHERE sid=?"; $sth = $pdo->prepare($sql); @@ -275,16 +268,32 @@ $storage = $sth->fetch(PDO::FETCH_OBJ);
    - - + +
    +
    + +
    +
    + +
    +
    + +
    +
    - - -
    -
    - - + +
    +
    + +
    +
    + +
    +
    + +
    +