Some database improvements and associated changes in webgui
This commit is contained in:
@@ -14,6 +14,7 @@ There can be a difference because not all items have a weight entered
|
||||
*/
|
||||
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
|
||||
$pagetitle = _('Boxes');
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
|
||||
$pagetitle = _('Cables');
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
|
||||
$pagetitle = _('Checklists');
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
|
||||
$pagetitle=_('Company');
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
require 'lib/fileutils.inc';
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
|
||||
$pagetitle = _('Lists');
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
|
||||
$pagetitle = _('Fuses');
|
||||
|
||||
+29
-4
@@ -114,14 +114,25 @@ try {
|
||||
$sth = $pdo->query("SELECT valint FROM settings WHERE userid=0 AND sno=0");
|
||||
} catch (PDOException $e) {
|
||||
if ($e->getCode() == 1146) {
|
||||
echo '<pre>';
|
||||
echo 'Settings table not found! Perhaps database is not initialized';
|
||||
echo '</pre>';
|
||||
echo "<pre>\n";
|
||||
echo "Settings table not found! Perhaps database is not initialized?\n";
|
||||
echo "</pre>\n";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
$g_db_scheme_version = $sth->fetchColumn();
|
||||
// TODO Check version
|
||||
$g_db_scheme_required = 1;
|
||||
// Schema version check
|
||||
if ($g_db_scheme_version !== $g_db_scheme_required) {
|
||||
echo "<pre>\n";
|
||||
echo "Database schema is wrong: detected version $g_db_scheme_version, but required version $g_db_scheme_required!\n";
|
||||
echo "</pre>\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// currency symbol is global
|
||||
$sth = $pdo->query("SELECT valint FROM settings WHERE userid=0 AND sno=4");
|
||||
$g_currsym = $sth->fetchColumn();
|
||||
|
||||
$user = User::GetInstance(); // There can be only one
|
||||
if ($g_scriptname != 'login.php') {
|
||||
@@ -1269,6 +1280,20 @@ function format_date($date) {
|
||||
return date($user->datefmt, $timestamp);
|
||||
}
|
||||
|
||||
function format_datetime($datetime, $seconds=false) {
|
||||
// datetime is string in ISO format
|
||||
global $user;
|
||||
if (empty($datetime)) {
|
||||
return '';
|
||||
}
|
||||
$timestamp = strtotime($datetime);
|
||||
if ($timestamp === false) {
|
||||
return '';
|
||||
}
|
||||
$timefmt = $seconds ? 'H:i:s' : 'H:i';
|
||||
return date($user->datefmt. ' ' . $timefmt, $timestamp);
|
||||
}
|
||||
|
||||
function format_color($color) {
|
||||
$colstr = '<span style="';
|
||||
$style = "padding:2px 4px;border-radius:4px;background-color:#".$color;
|
||||
|
||||
+3
-2
@@ -7,6 +7,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
require 'lib/svg.inc';
|
||||
|
||||
@@ -488,7 +489,7 @@ echo '<h2>', _('Add additional yacht'), "</h2>\n";
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="remarks" class="form-label"><?=_('Remarks')?></label>
|
||||
<textarea class="form-control" id="remarks" name="remarks" rows="3"><?=$project->remarks ?></textarea>
|
||||
<textarea class="form-control" id="remarks" name="remarks" rows="3"></textarea>
|
||||
</div>
|
||||
<div class="container-fluid px-0 my-3">
|
||||
<button type="submit" name="submit[insert]" class="btn btn-primary"><?=_('Save')?></button>
|
||||
@@ -602,7 +603,7 @@ form_create_select('sid', _('Default Storage'), $g_opt_none + $opt_storage, $ves
|
||||
?>
|
||||
<div class="mb-3">
|
||||
<label for="remarks" class="form-label"><?=_('Remarks')?></label>
|
||||
<textarea class="form-control" id="remarks" name="remarks" rows="3"><?=$vessel->remarks ?></textarea>
|
||||
<textarea class="form-control" id="remarks" name="remarks" rows="3"><?=h($vessel->remarks, br:true)?></textarea>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
|
||||
$pagetitle=_('Inventory');
|
||||
|
||||
@@ -8,3 +8,50 @@
|
||||
|
||||
*/
|
||||
|
||||
function db_lock_acquire($table, $key, $userid) {
|
||||
global $pdo;
|
||||
$token = bin2hex(random_bytes(8));
|
||||
// first try new lock
|
||||
$sql = "INSERT INTO recordlock (lock_table, lock_key, token, userid) "
|
||||
. "VALUES (?, ?, ?, ?)";
|
||||
try {
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$table, $key, $token, $userid]);
|
||||
return $token;
|
||||
} catch (PDOException $e) {
|
||||
if ($e->errorInfo[1] != 1062) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
// lazy locking: lock exists but is old, so we use it
|
||||
$sql = "UPDATE recordlock "
|
||||
. "SET token=?, userid=?, "
|
||||
. "created_at=CURRENT_TIMESTAMP, last_seen=CURRENT_TIMESTAMP "
|
||||
. "WHERE lock_table=? AND lock_key=? "
|
||||
. "AND last_seen<CURRENT_TIMESTAMP-INTERVAL 5 MINUTE";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$token, $userid, $table, $key]);
|
||||
if ($stmt->rowCount() === 1) {
|
||||
return $token;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function db_lock_refresh($token) {
|
||||
global $pdo;
|
||||
$sql = "UPDATE recordlock "
|
||||
. "SET last_seen=CURRENT_TIMESTAMP "
|
||||
. "WHERE token=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$token]);
|
||||
return $sth->rowCount() === 1;
|
||||
}
|
||||
|
||||
|
||||
function db_lock_release($token) {
|
||||
global $pdo;
|
||||
$sql = "DELETE FROM recordlock WHERE token=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$token]);
|
||||
return $sth->rowCount() === 1;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
|
||||
$pagetitle = _('Maintenance');
|
||||
@@ -288,7 +289,7 @@ echo '</div>'; // Column break
|
||||
echo '<div class="col">';
|
||||
|
||||
// TODO Show documents for equipment
|
||||
echo "<h4>Documents</h4>\n";
|
||||
echo '<h4>Documents for ', h($maint->ename), "</h4>\n";
|
||||
if (isset($docs)) {
|
||||
echo '<ul>', "\n";
|
||||
foreach ($docs as $d) {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
|
||||
// TODO move to somewhere else
|
||||
|
||||
+8
-3
@@ -7,6 +7,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
|
||||
$pagetitle = _('Note');
|
||||
@@ -30,6 +31,7 @@ switch ($submit = form_get_action()) {
|
||||
$p[':notetype'] = gpc_get_enum($_POST, 'notetype', $opt_notetype, 'task');
|
||||
$p[':refid'] = gpc_get_int($_POST, 'refid');
|
||||
$p[':annotation'] = gpc_get_string($_POST, 'annotation');
|
||||
$p[':created_by'] = $user->id;
|
||||
$id = db_exec_insert('note', $p);
|
||||
$caller = gpc_get_string($_POST, 'caller');
|
||||
$callid = $p[':refid'];
|
||||
@@ -171,7 +173,9 @@ elseif ($action == ACT_VIEW):
|
||||
|
||||
echo '<h2>', _('View Note'), "</h2>\n";
|
||||
|
||||
$sql = "SELECT refid, notetype, annotation FROM note WHERE noteid=?";
|
||||
$sql = "SELECT n.refid, n.notetype, n.annotation, n.created_at, u.displayname "
|
||||
. "FROM note AS n LEFT OUTER JOIN user AS u ON (n.created_by=u.userid) "
|
||||
. "WHERE noteid=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$id]);
|
||||
$note = $sth->fetch(PDO::FETCH_OBJ);
|
||||
@@ -184,9 +188,10 @@ echo '<table class="table">', "\n";
|
||||
echo '<tr><th>', _('Reference'),"</th><td>", $note->refid, "</td></tr>\n";
|
||||
echo '<tr><th>', _('Type'),"</th><td>", $note->notetype, "</td></tr>\n";
|
||||
echo '<tr><th>', _('Annotation'),"</th><td>", nl2br($note->annotation), "</td></tr>\n";
|
||||
echo '<tr><th>', _('Created at'),"</th><td>", format_datetime($note->created_at), "</td></tr>\n";
|
||||
echo '<tr><th>', _('Created by'),"</th><td>", h($note->displayname), "</td></tr>\n";
|
||||
echo "</table>\n";
|
||||
|
||||
|
||||
$link = $note->notetype == 'task' ? 'task.php' : 'maintenance.php';
|
||||
// echo '<p><a href="', $link, '?f=view&id=', $note->refid, '">', _('Parent'), "</a></p>\n";
|
||||
form_view_buttons($g_scriptname, $id, $link.'?f=view&id='.$note->refid);
|
||||
@@ -205,7 +210,7 @@ echo '<h2>', _('Edit Note'), "</h2>\n";
|
||||
<input type="hidden" name="id" value="<?=$id?>">
|
||||
<div class="mb-3">
|
||||
<label for="annotation" class="form-label"><?=_('Annotation')?></label>
|
||||
<textarea class="form-control" id="annotation" name="annotation" rows="5" autofocus><?=$note->annotation;?></textarea>
|
||||
<textarea class="form-control" id="annotation" name="annotation" rows="5" autofocus><?=h($note->annotation, br:true);?></textarea>
|
||||
</div>
|
||||
<?php
|
||||
form_edit_buttons($g_scriptname, $id);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
|
||||
$pagetitle = _('Projects');
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
|
||||
$pagetitle=_('Provisions');
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
|
||||
$pagetitle = _('Search');
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
|
||||
$pagetitle = _('Settings');
|
||||
@@ -22,6 +23,11 @@ switch ($submit = form_get_action()) {
|
||||
// global settings
|
||||
if ($user->role == 'captain') {
|
||||
$p[':userid'] = 0;
|
||||
$p[':sno'] = 4;
|
||||
$p[':valstr'] = gpc_get_string($_POST, 'currsym', 3, '€');
|
||||
db_exec_update('settings', $p, $pk);
|
||||
$p[':valstr'] = NULL;
|
||||
// image dimensions
|
||||
$p[':sno'] = 20;
|
||||
$p[':valint'] = gpc_get_int($_POST, 'maximgx');
|
||||
db_exec_update('settings', $p, $pk);
|
||||
@@ -101,6 +107,7 @@ if ($res = $sth->fetch(PDO::FETCH_NUM)) {
|
||||
$sth->execute([$user->id, $rowspp]);
|
||||
}
|
||||
|
||||
$currsym = $pdo->query("SELECT valstr FROM settings WHERE userid=0 AND sno=4")->fetchColumn();
|
||||
$maximgx = $pdo->query("SELECT valint FROM settings WHERE userid=0 AND sno=20")->fetchColumn();
|
||||
$maximgy = $pdo->query("SELECT valint FROM settings WHERE userid=0 AND sno=21")->fetchColumn();
|
||||
|
||||
@@ -131,6 +138,10 @@ form_create_select('datefmt', _('Date format'), $opt_datefmt, $datefmt);
|
||||
if ($user->role == 'captain'):
|
||||
?>
|
||||
<h2><?=_('global for all users')?></h2>
|
||||
<div class="mb-3">
|
||||
<label for="currsym" class="form-label"><?=_('Currency symbol')?></label>
|
||||
<input type="text" class="form-control" id="currsym" name="currsym" maxlength="3" value=<?=$currsym?>>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="maximgx" class="form-label"><?=_('Maximal image width')?></label>
|
||||
<input type="text" class="form-control" id="maximgx" name="maximgx" maxlength="4" value=<?=$maximgx?>>
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
|
||||
$pagetitle = _('Storage');
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
|
||||
$pagetitle = _('Tags');
|
||||
|
||||
+10
-2
@@ -7,6 +7,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
|
||||
$pagetitle = _('Task');
|
||||
@@ -73,6 +74,7 @@ switch ($submit = form_get_action()) {
|
||||
$p[':finished'] = gpc_get_datetime($_POST, 'finished');
|
||||
$p[':taskstate'] = gpc_get_enum($_POST, 'taskstate', array_keys($opt_state));
|
||||
$p[':responsible'] = gpc_get_int($_POST, 'responsible');
|
||||
$p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
|
||||
db_exec_update('task', $p, 'taskid');
|
||||
$action = ACT_VIEW;
|
||||
break;
|
||||
@@ -297,7 +299,7 @@ elseif ($action == ACT_VIEW):
|
||||
|
||||
$sql = "SELECT t.taskname, t.priority, t.plandate, t.duedate,"
|
||||
. " t.started, t.finished, t.taskstate, t.responsible,"
|
||||
. " u.displayname, p.projname "
|
||||
. " t.remarks, u.displayname, p.projname "
|
||||
. "FROM task AS t LEFT JOIN project AS p USING (projid) "
|
||||
. " LEFT JOIN user AS u ON (t.responsible=u.userid) "
|
||||
. "WHERE taskid=?";
|
||||
@@ -316,6 +318,7 @@ echo '<tr><th>', _('Started at'),"</th><td>", $task->started, "</td></tr>\n";
|
||||
echo '<tr><th>', _('Finished at'),"</th><td>", $task->finished, "</td></tr>\n";
|
||||
echo '<tr><th>', _('Status'),"</th><td>", $opt_state[$task->taskstate], "</td></tr>\n";
|
||||
echo '<tr><th>', _('Responsible'),"</th><td>", $task->displayname, "</td></tr>\n";
|
||||
echo '<tr><th>', _('Remarks'),"</th><td>", h($task->remarks, br:true), "</td></tr>\n";
|
||||
echo "</table>\n";
|
||||
|
||||
form_view_buttons($g_scriptname, $id);
|
||||
@@ -392,7 +395,12 @@ form_create_select('priority', _('Priority'), $opt_none + $opt_priority, $task->
|
||||
<?php
|
||||
form_create_select('taskstate', _('Status'), $opt_state, $task->taskstate);
|
||||
form_create_select('responsible', _('Responsible'), $opt_user, $user->id);
|
||||
|
||||
?>
|
||||
<div class="mb-3">
|
||||
<label for="remarks" class="form-label"><?=_('Remarks')?></label>
|
||||
<textarea class="form-control" id="remarks" name="remarks" rows="3"><?=h($task->remarks, br:true)?></textarea>
|
||||
</div>
|
||||
<?php
|
||||
form_edit_buttons($g_scriptname, $id);
|
||||
echo "</form>\n";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user