\n";
form_view_buttons($g_scriptname, $id);
-// show referenced equipment
-$sql = "SELECT eid, ename FROM equipment WHERE supplier=:id OR manufacturer=:id";
+// show referenced equipment for current vessel
+$sql = "SELECT eid, ename FROM equipment WHERE vid=:vid AND (supplier=:id OR manufacturer=:id)";
$sth = $pdo->prepare($sql);
-$sth->execute([':id' => $id]);
+$sth->execute([':vid' => $user->vid, ':id' => $id]);
if ($sth->rowCount() > 0) {
echo '
', _('Referenced in equipment'), ":
\n";
echo "
\n";
diff --git a/webgui/documents.php b/webgui/documents.php
index 99d15ab..5cb2bbc 100644
--- a/webgui/documents.php
+++ b/webgui/documents.php
@@ -91,16 +91,18 @@ switch ($submit = form_get_action()) {
}
// for images check maximum size and scale down if needed
- if (isset($_POST['noscale'])) {
- $g_message->Add(_('Image has not been scaled down'));
- } else {
- // scale down if dimensions exceed limits
- $img_maxx= $pdo->query("SELECT valint FROM settings WHERE userid=0 AND sno=20")->fetchColumn();
- $img_maxy= $pdo->query("SELECT valint FROM settings WHERE userid=0 AND sno=21")->fetchColumn();
- [$width, $height] = getimagesize($file_tmp);
- $factor = min($img_maxx / $width, $img_maxy / $height);
- if ($factor < 1) {
- image_scale($file_tmp, $file_mimetype, $width, $height, $factor);
+ if (($file_mimetype == 'image/png') or ($file_mimetype == 'image/jpeg')) {
+ if (isset($_POST['noscale'])) {
+ $g_message->Add(_('Image has not been scaled down'));
+ } else {
+ // scale down if dimensions exceed limits
+ $img_maxx= $pdo->query("SELECT valint FROM settings WHERE userid=0 AND sno=20")->fetchColumn();
+ $img_maxy= $pdo->query("SELECT valint FROM settings WHERE userid=0 AND sno=21")->fetchColumn();
+ [$width, $height] = getimagesize($file_tmp);
+ $factor = min($img_maxx / $width, $img_maxy / $height);
+ if ($factor < 1) {
+ image_scale($file_tmp, $file_mimetype, $width, $height, $factor);
+ }
}
}
@@ -590,9 +592,9 @@ foreach ($sth->fetchAll() as $row) {
$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=?";
+ . "WHERE docid=? AND vid=?";
$sth = $pdo->prepare($sql);
-$sth->execute([$id]);
+$sth->execute([$id, $user->vid]);
foreach ($sth->fetchAll() as $row) {
$references[] = $row;
$eids[] = $row['refid'];
diff --git a/webgui/globals.inc b/webgui/globals.inc
index 030653c..471fb3a 100644
--- a/webgui/globals.inc
+++ b/webgui/globals.inc
@@ -134,6 +134,15 @@ if ($g_db_scheme_version !== $g_db_scheme_required) {
$sth = $pdo->query("SELECT valint FROM settings WHERE userid=0 AND sno=4");
$g_currsym = $sth->fetchColumn();
+// allowed date formats
+$g_opt_datefmt = array(
+ 'Y-m-d' => _('YYYY-MM-DD'),
+ 'Y/m/d' => _('YYYY/MM/DD'),
+ 'd.m.Y' => _('DD.MM.YYYY'),
+ 'd/m/Y' => _('DD/MM/YYYY'),
+ 'm-d-Y' => _('MM-DD-YYYY')
+);
+
$user = User::GetInstance(); // There can be only one
if ($g_scriptname != 'login.php') {
$user->init_from_session();
diff --git a/webgui/lib/db.inc b/webgui/lib/db.inc
index 5e49a38..e4741ff 100644
--- a/webgui/lib/db.inc
+++ b/webgui/lib/db.inc
@@ -8,6 +8,20 @@
*/
+function db_get_setting($sno, $default=NULL) {
+ // TODO WIP
+ global $pdo;
+ $sql = "SELECT valint, valstr FROM settings WHERE userid=0 AND sno=?";
+ $sth = $pdo->prepare($sql);
+ try {
+ $sth->execute([$sno]);
+ } catch (Exception $e) {
+ return $default;
+ }
+ $row = $sth->fetchOne();
+ return $row;
+}
+
function db_lock_acquire($table, $key, $userid) {
global $pdo;
$token = bin2hex(random_bytes(8));
diff --git a/webgui/lib/gpc.inc b/webgui/lib/gpc.inc
index 1fb6f51..0fa16d9 100644
--- a/webgui/lib/gpc.inc
+++ b/webgui/lib/gpc.inc
@@ -83,11 +83,44 @@ function gpc_get_bool(&$GPC, $varname, $default = FALSE) {
}
function gpc_get_date(&$GPC, $varname, $default = NULL) {
- // TODO improve
- if (!isset($GPC[$varname]) || $GPC[$varname] == '') {
+ global $g_opt_datefmt;
+ if (!isset($GPC[$varname]) || !is_scalar($GPC[$varname])) {
return $default;
}
- return $GPC[$varname];
+ $value = trim((string)$GPC[$varname]);
+ if ($value === '') {
+ return $default;
+ }
+ foreach (array_keys($g_opt_datefmt) as $format) {
+ if (preg_match_all('/[Ymd]/', $format, $tokens) !== 3) {
+ continue;
+ }
+ $regex = preg_quote($format, '/');
+ $regex = str_replace('d', '(\d{2})', $regex);
+ $regex = str_replace('m', '(\d{2})', $regex);
+ $regex = str_replace('Y', '(\d{4})', $regex);
+ if (!preg_match('/^' . $regex . '$/', $value, $matches)) {
+ continue;
+ }
+ $year = $month = $day = NULL;
+ foreach ($tokens[0] as $i => $token) {
+ switch ($token) {
+ case 'Y':
+ $year = (int)$matches[$i + 1];
+ break;
+ case 'm':
+ $month = (int)$matches[$i + 1];
+ break;
+ case 'd':
+ $day = (int)$matches[$i + 1];
+ break;
+ }
+ }
+ if (checkdate($month, $day, $year)) {
+ return sprintf('%04d-%02d-%02d', $year, $month, $day);
+ }
+ }
+ return $default;
}
function gpc_get_datetime(&$GPC, $varname, $default = NULL) {
diff --git a/webgui/maintenance.php b/webgui/maintenance.php
index 11420e2..e743cbe 100644
--- a/webgui/maintenance.php
+++ b/webgui/maintenance.php
@@ -55,6 +55,8 @@ switch ($submit = form_get_action()) {
$p[':activities'] = gpc_get_string($_POST, 'activities', 80);
$p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
$p[':series'] = gpc_get_int($_POST, 'series');
+ $p[':plan_date'] = gpc_get_date($_POST, 'plan_date');
+ $p[':completion_date'] = gpc_get_date($_POST, 'completion_date');
$p[':maintstate'] = gpc_get_string($_POST, 'maintstate');
db_exec_update('maintenance', $p, 'maintid');
$action = ACT_VIEW;
@@ -247,7 +249,8 @@ elseif ($action == ACT_VIEW):
echo '
', _('View Maintenance'), "
\n";
// load maintenance record
-$sql = "SELECT m.activities, m.eid, m.remarks, m.series, m.maintstate, e.ename "
+$sql = "SELECT m.activities, m.eid, m.remarks, m.series, m.maintstate, e.ename, "
+ . "m.plan_date, m.completion_date, m.interval_hours, m.last_hours "
. "FROM maintenance AS m LEFT OUTER JOIN equipment AS e USING (eid) "
. "WHERE m.maintid=?";
$sth = $pdo->prepare($sql);
@@ -282,6 +285,10 @@ if (isset($maint->eid) and $maint->eid>0) {
echo "\n";
echo '