First web gui prototype
This commit is contained in:
@@ -0,0 +1,257 @@
|
||||
<?php
|
||||
/******************************************************************************
|
||||
* YMS - Yacht Management Software
|
||||
* Copyright (C) 2024 Thomas Hooge
|
||||
*
|
||||
* SPDX-License-Identifier: WTFPL
|
||||
******************************************************************************/
|
||||
|
||||
require 'globals.inc';
|
||||
$pagetitle = _('Maintenance');
|
||||
|
||||
$id = gpc_get_int($_REQUEST, 'id', 0);
|
||||
|
||||
// Equipment options
|
||||
$opt_equipment = array( 0 => _('*** unassigned ***'));
|
||||
$sql = "SELECT eid, ename FROM equipment WHERE vid=? ORDER BY ename";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$user->vid]);
|
||||
foreach ($sth->fetchAll() as $row) {
|
||||
$opt_equipment[$row['eid']] = $row['ename'];
|
||||
}
|
||||
|
||||
// ========== ACTIONS START ===================================================
|
||||
|
||||
switch ($submit = form_get_action()) {
|
||||
|
||||
case NULL: break;
|
||||
|
||||
case 'add': $action = ACT_ADD; break;
|
||||
case 'view': $action = ACT_VIEW; break;
|
||||
case 'edit': $action = ACT_EDIT; break;
|
||||
case 'del': $action = ACT_DELETE; break;
|
||||
|
||||
case 'insert':
|
||||
$eid = gpc_get_int($_POST, 'eid');
|
||||
$activities = gpc_get_string($_POST, 'activities', 80);
|
||||
$sql = "INSERT INTO maintenance "
|
||||
. " (vid, eid, activities) "
|
||||
. "VALUES "
|
||||
. " (:vid, :eid, :activities)";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->bindValue(':vid', $user->vid, PDO::PARAM_INT);
|
||||
$sth->bindValue(':eid', $eid, PDO::PARAM_INT);
|
||||
$sth->bindValue(':activities', $activities, PDO::PARAM_STR);
|
||||
$sth->execute();
|
||||
$id = $pdo->LastInsertId();
|
||||
$action = ACT_VIEW;
|
||||
break;
|
||||
|
||||
case 'update':
|
||||
$eid = gpc_get_int($_POST, 'eid');
|
||||
$activities = gpc_get_string($_POST, 'activities', 80);
|
||||
$remarks = gpc_get_string($_POST, 'remarks', 150);
|
||||
$sql = "UPDATE maintenance "
|
||||
. "SET activities=:activities,"
|
||||
. " eid=:eid,"
|
||||
. " remarks=:remarks "
|
||||
. "WHERE maintid=:maintid";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->bindValue(':maintid', $id, PDO::PARAM_INT);
|
||||
$sth->bindValue(':eid', $eid, PDO::PARAM_INT);
|
||||
$sth->bindValue(':activities', $activities, PDO::PARAM_STR);
|
||||
$sth->bindValue(':remarks', $remarks, PDO::PARAM_STR);
|
||||
$sth->execute();
|
||||
$action = ACT_VIEW;
|
||||
break;
|
||||
|
||||
default:
|
||||
$g_error->Add(sprintf(_("Unknown function '%s'!"), $submit));
|
||||
$valid = FALSE;
|
||||
}
|
||||
|
||||
// ========== ACTIONS END =====================================================
|
||||
|
||||
require 'header.php';
|
||||
|
||||
// ========== PAGE CONTENT ====================================================
|
||||
|
||||
if ($action == ACT_DEFAULT):
|
||||
// ========== VARIANT: default behavior =======================================
|
||||
|
||||
echo '<h1>', $pagetitle, "</h1>\n";
|
||||
|
||||
$sql = "SELECT m.maintid, m.activities, m.remarks, e.ename "
|
||||
. "FROM maintenance AS m LEFT OUTER JOIN equipment AS e USING (eid)"
|
||||
. "WHERE m.vid=? "
|
||||
. "ORDER BY m.maintid";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$user->vid]);
|
||||
$res = $sth->fetchAll();
|
||||
echo '<table class="table table-striped">', "\n";
|
||||
echo "<thead>\n";
|
||||
echo "<tr>";
|
||||
echo "<th>" . _('Activities') . "</th>";
|
||||
echo "<th>" . _('Equipment') . "</th>";
|
||||
echo "<th>" . _('Remarks') . "</th>";
|
||||
echo "</tr>\n";
|
||||
echo "</thead>\n";
|
||||
foreach ($res as $row) {
|
||||
echo "<tr>\n";
|
||||
echo "<td>". $row['activities'] ."</td>\n";
|
||||
echo "<td>". $row['ename'] ."</td>\n";
|
||||
echo "<td>". $row['remarks'] ."</td>\n";
|
||||
// Action buttons
|
||||
echo "<td>";
|
||||
echo '<a title="', _('View'), '" href="', $g_scriptname, '?f=view&id=', $row['maintid'], '"><i class="bi-eye"></i></a>', "\n";
|
||||
echo '<a title="', _('Edit'), '" href="', $g_scriptname, '?f=edit&id=', $row['maintid'], '"><i class="bi-pencil"></i></a>', "\n";
|
||||
echo "</td>\n";
|
||||
echo "</tr>\n";
|
||||
}
|
||||
// Table summary
|
||||
echo "<tfoot>\n";
|
||||
echo '<tr><td colspan="6">', sprintf(_('%d records'), count($res)), '</td></tr>', "\n";
|
||||
echo "</tfoot>\n";
|
||||
echo "</table>\n";
|
||||
|
||||
form_add_button($g_scriptname);
|
||||
|
||||
|
||||
elseif ($action == ACT_ADD):
|
||||
// ========== VARIANT: add record =============================================
|
||||
|
||||
echo '<h2>', _('Add Maintenance'), "</h2>\n";
|
||||
?>
|
||||
<form method="post" action="<?=$g_scriptname?>">
|
||||
<div class="mb-3">
|
||||
<label for="activities" class="form-label"><?=_('Activities')?></label>
|
||||
<input type="text" class="form-control" id="activities" name="activities">
|
||||
</div>
|
||||
<?php
|
||||
// TODO
|
||||
// Add link to equipment, perhaps later with modal dialog?
|
||||
?>
|
||||
<div class="mb-3">
|
||||
<label for="eid" class="form-label"><?=_('Equipment')?></label>
|
||||
<select name="eid" id="eid" class="form-control">
|
||||
<?php
|
||||
foreach ($opt_equipment as $k => $v) {
|
||||
echo '<option value="', $k, '">', $v, "</option>\n";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<div class="container-fluid px-0 my-3">
|
||||
<button type="submit" name="submit[insert]" class="btn btn-primary"><?=_('Save')?></button>
|
||||
<a href="<?=$g_scriptname?>" class="btn btn-secondary"><?=_('Back')?></a>
|
||||
</div>
|
||||
<?php
|
||||
elseif ($action == ACT_VIEW):
|
||||
// ========== VARIANT: view single record =====================================
|
||||
|
||||
echo '<h2>', _('View Maintenance'), "</h2>\n";
|
||||
|
||||
$sql = "SELECT m.activities, m.eid, m.remarks, e.ename "
|
||||
. "FROM maintenance AS m LEFT OUTER JOIN equipment AS e USING (eid) "
|
||||
. "WHERE m.maintid=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$id]);
|
||||
$maint = $sth->fetch(PDO::FETCH_OBJ);
|
||||
|
||||
if (isset($maint->eid)) {
|
||||
$sql = "SELECT r.docid, d.filename, d.title, d.hash, d.extension "
|
||||
. "FROM docref AS r INNER JOIN document AS d USING (docid) "
|
||||
. "WHERE r.reftype='equipment' AND r.refid=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$maint->eid]);
|
||||
$docs = $sth->fetchAll();
|
||||
} else {
|
||||
$maint->ename = _('n/a');
|
||||
}
|
||||
|
||||
// Bootstrap grid
|
||||
echo '<div class="container">';
|
||||
echo '<div class="row">';
|
||||
echo '<div class="col">';
|
||||
|
||||
echo '<table class="table">', "\n";
|
||||
echo '<tr><th>', _('Activities'),"</th><td>", $maint->activities, "</td></tr>\n";
|
||||
echo '<tr><th>', _('Equipment'),"</th><td>", $maint->ename, "</td></tr>\n";
|
||||
echo '<tr><th>', _('Remarks'),"</th><td>", $maint->remarks, "</td></tr>\n";
|
||||
echo "</table>\n";
|
||||
|
||||
echo '</div>'; // Column break
|
||||
echo '<div class="col">';
|
||||
|
||||
// TODO Show documents for equipment
|
||||
?>
|
||||
<p>Documents</p>
|
||||
<?php
|
||||
echo '<ul>', "\n";
|
||||
foreach ($docs as $d) {
|
||||
echo '<li>', $d['title'] ?? $d['filename'], ' (', $d['docid'], ")</li>\n";
|
||||
}
|
||||
echo "</ul>\n";
|
||||
|
||||
|
||||
echo '</div>'; // col
|
||||
echo '</div>'; // row
|
||||
echo '</div>'; // container
|
||||
|
||||
form_view_buttons($g_scriptname, $id);
|
||||
|
||||
elseif ($action == ACT_EDIT):
|
||||
// ========== VARIANT: edit single record =====================================
|
||||
|
||||
$sql = "SELECT activities, eid, remarks "
|
||||
. "FROM maintenance "
|
||||
. "WHERE maintid=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$id]);
|
||||
$maint = $sth->fetch(PDO::FETCH_OBJ);
|
||||
|
||||
echo '<h2>', _('Edit Maintenance'), "</h2>\n";
|
||||
|
||||
?>
|
||||
<form method="post" action="<?=$g_scriptname?>">
|
||||
<input type="hidden" name="id" value="<?=$id?>">
|
||||
<div class="mb-3">
|
||||
<label for="activities" class="form-label"><?=_('Activities')?></label>
|
||||
<input type="text" class="form-control" id="activities" name="activities" value="<?=$maint->activities ?>">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="eid" class="form-label"><?=_('Equipment')?></label>
|
||||
<select name="eid" id="eid" class="form-control">
|
||||
<?php
|
||||
foreach ($opt_equipment as $k => $v) {
|
||||
echo '<option value="', $k;
|
||||
if ($maint->eid == $k) {
|
||||
echo ' selected';
|
||||
}
|
||||
echo '">', $v, "</option>\n";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<div class="mb-3">
|
||||
<label for="remarks" class="form-label"><?=_('Remarks')?></label>
|
||||
<textarea class="form-control" id="remarks" name="remarks" rows="3"><?=$maint->remarks ?></textarea>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
form_edit_buttons($g_scriptname, $id);
|
||||
echo "</form>\n";
|
||||
|
||||
elseif ($action == ACT_DELETE):
|
||||
// ========== VARIANT: delete record ==========================================
|
||||
|
||||
echo '<h2>', _('Delete Maintenance'), "</h2>\n";
|
||||
|
||||
else:
|
||||
// ========== ERROR UNKNOWN VARIANT ===========================================
|
||||
|
||||
echo '<p>', _('Unknown function call: Please report to system development!'), "</p>\n";
|
||||
|
||||
endif; // $action == ...
|
||||
// ========== END OF VARIANTS =================================================
|
||||
|
||||
|
||||
include 'footer.php';
|
||||
Reference in New Issue
Block a user