More work an webgui

This commit is contained in:
2024-04-10 20:13:37 +02:00
parent 4b5ba85a77
commit aaa452cbb5
20 changed files with 842 additions and 359 deletions
+14 -11
View File
@@ -98,13 +98,9 @@ echo "<td></td>";
echo "</tr>\n";
foreach ($res as $row) {
echo "<tr>\n";
echo "<td>". $row['label'] ."</td>\n";
$style = 'background-color:#' . $row['color'];
if (get_color_brightness($row['color']) < 0.4) {
$style .= ';color:white';
}
echo '<td><span style="', $style,'">#'. $row['color'] ."</span></td>\n";
echo "<td>". $row['content'] ."</td>\n";
echo '<td>', $row['label'], "</td>\n";
echo '<td>', format_color(strtoupper($row['color'])), "</td>\n";
echo '<td>', $row['content'], "</td>\n";
echo '<td class="text-end">', format_float($row['weight'], 2), "</td>\n";
form_action_buttons($g_scriptname, $row['boxid']);
echo "</tr>\n";
@@ -123,7 +119,7 @@ elseif ($action == ACT_ADD):
echo '<h2>', _('Add Box'), "</h2>\n";
?>
<form method="post">
<form method="post" action="<?=$g_Scriptname?>">
<div class="mb-3">
<label for="label" class="form-label"><?=_('Label')?></label>
<input type="text" maxlength="20" class="form-control" id="label" name="label" autofocus>
@@ -167,7 +163,7 @@ echo '<h2>', $box->label, "</h2>\n";
echo '<table class="table">', "\n";
echo '<tr><th style="width:20%">', _('Content'),"</th><td>", $box->content, "</td></tr>\n";
echo '<tr><th>', _('Color'), '</th><td style="background-color:#', $box->color, '">#', $box->color, "</td></tr>\n";
echo '<tr><th>', _('Color'), '</th><td>', format_color($box->color), "</td></tr>\n";
echo '<tr><th>', _('Weight'), '</th><td>', format_float($box->weight, 2, 'kg'), "</td></tr>\n";
echo '<tr><th>', _('Remarks'),"</th><td>", $box->remarks, "</td></tr>\n";
echo "</table>\n";
@@ -176,25 +172,32 @@ form_view_buttons($g_scriptname, $id);
// Inventory in box
// WIP
$sql = "SELECT invid, invname FROM inventory WHERE boxtype='box' AND boxid=?";
$sql = "SELECT invid, invname, weight FROM inventory WHERE boxtype='box' AND boxid=?";
$sth = $pdo->prepare($sql);
$sth->execute([$id]);
$res = $sth->fetchAll();
echo '<h3>', _('Inventory in box'), "</h3>\n";
$weight_total = 0.0;
if ($res) {
echo '<table class="table table-striped">', "\n";
echo "<thead>\n";
echo "<tr>";
echo '<th>', _('Inventory'), "</th>";
echo '<th>', _('Weight'), "</th>";
echo "<td></td>";
echo "</tr>\n";
foreach ($res as $row) {
echo "<tr>\n";
echo "<td>", $row['invname'], "</td>\n";
echo "<td>", format_float($row['weight'], 2, 'kg'), "</td>\n";
form_action_buttons('inventory.php', $row['invid']);
echo "</tr>\n";
$weight_total += $row['weight'];
}
echo "<tfoot>";
echo '<tr><td></td><td>', format_float($weight_total, 2, 'kg'), '</td>', "\n";
echo "</tfoot>\n";
echo "</table>\n";
} else {
echo '<p>', _('Box is empty'), "</p>\n";
@@ -212,7 +215,7 @@ $box = $sth->fetch(PDO::FETCH_OBJ);
echo '<h2>', _('Edit Box'), "</h2>\n";
?>
<form method="post">
<form method="post" action="<?=$g_scriptname?>">
<input type="hidden" name="id" value="<?=$id?>">
<div class="mb-3">
<label for="label" class="form-label"><?=_('Label')?></label>
+137 -4
View File
@@ -11,13 +11,146 @@ $pagetitle = _('Checklists');
$id = gpc_get_int($_REQUEST, 'id', 0);
// ========== 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':
$p[':title'] = gpc_get_string($_POST, 'title');
$p[':clstate'] = gpc_get_string($_POST, 'clstate');
$id = db_exec_insert('checklist', $p);
$action = ACT_VIEW;
break;
case 'update':
$p[':title'] = gpc_get_string($_POST, 'title');
$p[':clstate'] = gpc_get_string($_POST, 'clstate');
$p[':clid'] = $id;
db_exec_update('checklist', $p, 'clid');
$action = ACT_VIEW;
break;
case 'delete':
$action = ACT_DEFAULT;
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 clid, title, clstate FROM checklist";
$sth = $pdo->query($sql);
$res = $sth->fetchAll();
?>
<p>Search will be implemented later.
This page is currently just a placeholder.</p>
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th><?=_('Title')?></th>
<th><?=_('State')?></th>
<th></th>
</tr>
</thead>
<?php
foreach ($res as $row) {
echo "<tr>\n";
echo '<td>', $row['clid'], "</td>\n";
echo '<td>', $row['title'], "</td>\n";
echo '<td>', $row['clstate'], "</td>\n";
form_action_buttons($g_scriptname, $row['clid']);
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 Checklist'), "</h2>\n";
?>
<form method="post" action="<?=$g_scriptname?>">
<div class="mb-3">
<label for="title" class="form-label"><?=_('Title')?></label>
<input type="text" class="form-control" id="title" name="title">
</div>
<?php
form_new_buttons($g_scriptname);
echo "</form>\n";
elseif ($action == ACT_VIEW):
// ========== VARIANT: view single record =====================================
$sth = $pdo->prepare("SELECT title, clstate FROM checklist WHERE clid=?");
$sth->execute([$id]);
$checklist = $sth->fetch(PDO::FETCH_OBJ);
?>
<h2><?=_('View Checklist')?></h2>
<table class="table">
<tr><th><?=_('Title')?></th><td><?=$checklist->title ?></td></tr>
<tr><th><?=_('State')?></th><td><?=get_enum($checklist->clstate)?></td></tr>
</table>
<?php
form_view_buttons($g_scriptname, $id);
elseif ($action == ACT_EDIT):
// ========== VARIANT: edit single record =====================================
$sth = $pdo->prepare("SELECT title, clstate FROM checklist WHERE clid=?");
$sth->execute([$id]);
$checklist = $sth->fetch(PDO::FETCH_OBJ);
$opt_clstate = db_load_enum('checklist', 'clstate', true, true);
echo '<h2>', _('Edit checklist'), "</h2>\n";
?>
<form method="post" action="<?=$g_scriptname?>">
<input type="hidden" name="id" value="<?=$id?>">
<div class="mb-3">
<label for="provname" class="form-label"><?=_('Name')?></label>
<input type="text" class="form-control" id="title" name="title" value="<?=$checklist->title ?>">
</div>
<?php
form_create_select('clstate', _('State'), $opt_clstate, $checklist->clstate);
form_edit_buttons($g_scriptname, $id);
echo "</form>\n";
elseif ($action == ACT_DELETE):
// ========== VARIANT: delete record ==========================================
echo '<h2>', _('Delete checklist'), "</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';
+19 -56
View File
@@ -24,65 +24,28 @@ switch ($submit = form_get_action()) {
case 'del': $action = ACT_DELETE; break;
case 'insert':
$compname = gpc_get_string($_POST, 'compname');
$comptype = gpc_get_int($_POST, 'comptype');
$sql = "INSERT INTO company "
. " (compname, comptype) "
. "VALUES "
. " (:compname, :comptype)";
$sth = $pdo->prepare($sql);
$sth->bindValue(':compname', $compname, PDO::PARAM_STR);
$sth->bindValue(':comptype', $comptype, PDO::PARAM_INT);
$sth->execute();
$id = $pdo->lastInsertId();
$p[':compname'] = gpc_get_string($_POST, 'compname');
$p[':comptype'] = gpc_get_int($_POST, 'comptype');
$id = db_exec_insert('company', $p);
$action = ACT_VIEW;
break;
case 'update':
$compname = gpc_get_string($_POST, 'compname');
$comptype = gpc_get_int($_POST, 'comptype');
$street = gpc_get_string($_POST, 'street', 30);
$zip = gpc_get_string($_POST, 'zip', 10);
$city = gpc_get_string($_POST, 'city', 30);
$country = gpc_get_string($_POST, 'country', 30);
$contact = gpc_get_string($_POST, 'contact', 30);
$phone = gpc_get_string($_POST, 'phone', 30);
$email = gpc_get_string($_POST, 'email', 50);
$web = gpc_get_string($_POST, 'web', 40);
$customerno = gpc_get_string($_POST, 'customerno', 20);
$contractno = gpc_get_string($_POST, 'contractno', 20);
$remarks = gpc_get_string($_POST, 'remarks', 150);
$sql = "UPDATE company "
. "SET compname=:compname,"
. " comptype=:comptype,"
. " street=:street,"
. " zip=:zip,"
. " city=:city,"
. " country=:country,"
. " contact=:contact,"
. " phone=:phone,"
. " email=:email,"
. " web=:web,"
. " customerno=:customerno,"
. " contractno=:contractno,"
. " remarks=:remarks "
. "WHERE compid=:compid";
$sth = $pdo->prepare($sql);
$sth->bindValue(':compid', $id, PDO::PARAM_INT);
$sth->bindValue(':compname', $compname, PDO::PARAM_STR);
$sth->bindValue(':comptype', $comptype, PDO::PARAM_INT);
$sth->bindValue(':street', $street, PDO::PARAM_STR);
$sth->bindValue(':zip', $zip, PDO::PARAM_STR);
$sth->bindValue(':city', $city, PDO::PARAM_STR);
$sth->bindValue(':country', $country, PDO::PARAM_STR);
$sth->bindValue(':contact', $contact, PDO::PARAM_STR);
$sth->bindValue(':phone', $phone, PDO::PARAM_STR);
$sth->bindValue(':email', $email, PDO::PARAM_STR);
$sth->bindValue(':web', $web, PDO::PARAM_STR);
$sth->bindValue(':customerno', $customerno, PDO::PARAM_STR);
$sth->bindValue(':contractno', $contractno, PDO::PARAM_STR);
$sth->bindValue(':remarks', $remarks, PDO::PARAM_STR);
$sth->execute();
$p[':compid'] = $id;
$p[':compname'] = gpc_get_string($_POST, 'compname');
$p[':comptype'] = gpc_get_int($_POST, 'comptype');
$p[':street'] = gpc_get_string($_POST, 'street', 30);
$p[':zip'] = gpc_get_string($_POST, 'zip', 10);
$p[':city'] = gpc_get_string($_POST, 'city', 30);
$p[':country'] = gpc_get_string($_POST, 'country', 30);
$p[':contact'] = gpc_get_string($_POST, 'contact', 30);
$p[':phone'] = gpc_get_string($_POST, 'phone', 30);
$p[':email'] = gpc_get_string($_POST, 'email', 50);
$p[':web'] = gpc_get_string($_POST, 'web', 40);
$p[':customerno'] = gpc_get_string($_POST, 'customerno', 20);
$p[':contractno'] = gpc_get_string($_POST, 'contractno', 20);
$p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
db_exec_update('company', $p, 'compid');
$action = ACT_VIEW;
break;
@@ -157,7 +120,7 @@ elseif ($action == ACT_ADD):
echo '<h2>', _('Add Company'), "</h2>\n";
?>
<form method="post">
<form method="post" action="<?=$g_scriptname?>">
<div class="mb-3">
<label for="compname" class="form-label"><?=_('Name')?></label>
<input type="text" class="form-control" id="compname" name="compname">
+16 -6
View File
@@ -24,8 +24,8 @@ switch ($submit = form_get_action()) {
case 'insert':
// WIP New standalone document
$title = gpc_get_string($_POST, 'title');
$remarks = gpc_get_string($_POST, 'remarks');
$p[':title'] = gpc_get_string($_POST, 'title');
$p[':remarks'] = gpc_get_string($_POST, 'remarks');
$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.'));
@@ -77,7 +77,16 @@ switch ($submit = form_get_action()) {
$doctype = 'picture';
break;
}
$sql = "INSERT INTO document"
$p[':doctype'] = $doctype;
$p[':mimetype'] = $file_mimetype;
$p[':filename'] = $file_name;
$p[':extension'] = $file_ext;
$p[':hash'] = $file_hash;
$p[':doctime'] = $file_timestamp;
$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"
. " (?, ?, ?, ?, ?, ?, ?)";
@@ -87,7 +96,8 @@ switch ($submit = form_get_action()) {
} catch (PDOException $e) {
$g_error->Add('SQL-Error: '. $e->getMessage());
}
$id = $pdo->lastInsertId();
$id = $pdo->lastInsertId(); */
$id = db_exec_insert('document', $p);
move_uploaded_file($file_tmp, $file_techname);
$action = ACT_VIEW;
break;
@@ -366,7 +376,7 @@ $sth->execute([$id]);
$document = $sth->fetch(PDO::FETCH_OBJ);
if ($document->doctype == 'picture') {
echo '<img width="', $g_thumb_size, '" src="doc/pic-', $document->hash, '.', $document->extension, '">';
echo '<img width="', $g_thumb_size, '" src="dl.php?id=', $document->docid, '">';
}
?>
@@ -382,7 +392,7 @@ if ($document->doctype == 'picture') {
</div>
<div class="mb-3">
<label for="remarks" class="form-label"><?=_('Remarks')?></label>
<textarea class="form-control" id="remarks" name="remarks" rows="3"><?=$storage->remarks ?></textarea>
<textarea class="form-control" id="remarks" name="remarks" rows="3"><?=$document->remarks ?></textarea>
</div>
<button type="submit" name="submit[update]" class="btn btn-primary"><?=_('Save')?></button>
<a href="<?=$g_scriptname?>?f=view&id=<?=$id?>" class="btn btn-secondary"><?=_('Back')?></a>
+5 -1
View File
@@ -187,7 +187,11 @@ foreach ($sth->fetchAll() as $row) {
echo '<td>', $row['ddval'],'</td>';
echo '<td>', $row['ddtext'], '</td>';
echo '<td>', $row['ddshort'], '</td>';
echo '<td>', $row['color'], '</td>';
if ($row['color']) {
echo '<td>', format_color($row['color']), '</td>';
} else {
echo '<td></td>';
}
echo '<td>', $row['sort'], '</td>';
echo "</tr>\n";
}
+17 -4
View File
@@ -208,6 +208,11 @@ require 'header.php';
if ($action == ACT_DEFAULT):
// ========== VARIANT: default behavior =======================================
$sort = array(
1 => 'ename',
2 => 'ename DESC'
);
$sql = "SELECT eid, ename, manufacturer, model, serial, remarks,"
. " TIMESTAMPDIFF(MONTH, purchdate, NOW()) AS age_mon "
. "FROM equipment WHERE vid=? "
@@ -221,18 +226,26 @@ echo "<h1>$pagetitle</h1>\n";
// Filter
?>
<form method="post">
<form method="post" action="<?=$g_scriptname?>">
<div id="filter" class="card">
<div class="card-header">Filter</div>
<div class="card-body">
<label>Category</label>
<select>
<label for="flt_category">Category</label>
<select id="flt_category" name="flt_category">
<?php
foreach ($opt_ecat as $k => $v) {
echo '<option value="', $k,'">', $v, '</option>';
}
?>
</select>
<label for="flt_manuf">Manufacturer</label>
<select id="flt_category" name="flt_category">
<?php
foreach ($opt_manufacturer as $k => $v) {
echo '<option value="', $k,'">', $v, '</option>';
}
?>
</select>
<button class="btn btn-sm btn-primary" title="<?=_('Apply')?>">Go</button>
</div>
</div>
@@ -292,7 +305,7 @@ elseif ($action == ACT_ADD):
// ========== VARIANT: add record =============================================
?>
<h2><?=_('Add Equipment')?></h2>
<form method="post">
<form method="post" action="<?=$g_scriptname?>">
<div class="mb-3">
<label for="ename" class="form-label"><?=_('Name')?></label>
<input type="text" class="form-control" id="ename" name="ename">
+294
View File
@@ -0,0 +1,294 @@
<?php
/******************************************************************************
* YMS - Yacht Management Software
* Copyright (C) 2024 Thomas Hooge
*
* SPDX-License-Identifier: WTFPL
******************************************************************************/
require 'globals.inc';
$pagetitle=_('Equipment');
$id = gpc_get_int($_REQUEST, 'id', 0);
// ========== 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':
break;
case 'update':
$action = ACT_VIEW;
break;
case 'delete':
$action = ACT_DEFAULT;
break;
default:
$g_error->Add("Unbekannte Funktion!");
$valid = FALSE;
}
// ========== ACTIONS END =====================================================
require 'header.php';
// ========== PAGE CONTENT ====================================================
if ($action == ACT_DEFAULT):
// ========== VARIANT: default behavior =======================================
echo "<h1>$pagetitle</h1>\n";
$sql = "SELECT eid, ename, make, model, serial, remarks "
. "FROM equipment "
. "ORDER BY eid";
$sth = $pdo->query($sql);
$res = $sth->fetchAll();
echo '<table class="table table-striped">', "\n";
echo "<thead>\n";
echo "<tr>";
echo "<th>" . _('Description') . "</th>";
echo "<th>" . _('Make') . "</th>";
echo "<th>" . _('Model') . "</th>";
echo "<th>" . _('Serial') . "</th>";
echo "<th>" . _('Remarks') . "</th>";
echo "<th>&nbsp;</th>";
echo "</tr>\n";
echo "</thead>\n";
foreach ($res as $row) {
echo "<tr>\n";
echo "<td>". $row['ename'] ."</td>\n";
echo "<td>". $row['make'] ."</td>\n";
echo "<td>". $row['model'] ."</td>\n";
echo "<td>". $row['serial'] ."</td>\n";
echo "<td>". $row['remarks'] ."</td>\n";
// Action buttons
echo "<td>";
echo '<a href="', $g_scriptname, '?f=view&id=', $row['eid'], '">View</a>&nbsp;';
echo '<a href="">Edit</a>';
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";
echo '<a href="', $g_scriptname, '?f=add" class="btn btn-info" role="button">', _('Add'), "</a>\n";
elseif ($action == ACT_ADD):
// ========== VARIANT: add record =============================================
?>
<h2><?=_('Add Equipment')?></h2>
<form method="post">
<div class="mb-3">
<label for="ename" class="form-label"><?=_('Name')?></label>
<input type="text" class="form-control" id="ename" name="ename">
</div>
<div class="mb-3">
<label for="make" class="form-label"><?=_('Make')?></label>
<input type="text" class="form-control" id="make" name="make">
</div>
<div class="mb-3">
<label for="model" class="form-label"><?=_('Model')?></label>
<input type="text" class="form-control" id="model" name="make">
</div>
<div class="mb-3">
<label for="serial" class="form-label"><?=_('Serial')?></label>
<input type="text" class="form-control" id="serial" name="serial">
</div>
<button type="submit" class="btn btn-primary"><?=_('Save')?></button>
<a href="<?=$g_scriptname?>" class="btn btn-secondary"><?=_('Back')?></a>
</form>
<?php
elseif ($action == ACT_VIEW):
// ========== VARIANT: view 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);
echo "<h2>", $equipment->ename, "</h2>\n";
// Bootstrap grid
echo '<div class="container">';
echo '<div class="row">';
echo '<div class="col">';
echo "<table>\n";
echo "<tr><td>", _('Make'),"</td><td>", $equipment->make, "</td></tr>\n";
echo "<tr><td>", _('Model'),"</td><td>", $equipment->model, "</td></tr>\n";
echo "<tr><td>", _('Serial'),"</td><td>", $equipment->serial, "</td></tr>\n";
echo "</table>\n";
echo '</div>'; // Column break
echo '<div class="col">';
?>
<p>Images and documents go here</p>
<form id="uploadform" method="post" enctype="multipart/form-data">
<div class="card">
<div class="card-body">
<div id="drop-area" class="border rounded d-flex justify-content-center align-items-center"
style="height: 200px; cursor: pointer;">
<div class="text-center" id="result">
<p>Drag and drop your image here or click to select a file.</p>
</div>
</div>
<input type="file" id="fileElem" multiple accept="image/*" class="d-none" capture="camera">
<input type="submit" name="submit" value="Upload">
</div>
</div>
</form>
<progress id="progress" value="100" max="100" style="display: none;"></progress>
<script>
let dropArea = document.getElementById("drop-area");
["dragenter", "dragover", "dragleave", "drop"].forEach((eventName) => {
dropArea.addEventListener(eventName, preventDefaults, false);
document.body.addEventListener(eventName, preventDefaults, false);
});
["dragenter", "dragover"].forEach((eventName) => {
dropArea.addEventListener(eventName, highlight, false);
});
["dragleave", "drop"].forEach((eventName) => {
dropArea.addEventListener(eventName, unhighlight, false);
});
dropArea.addEventListener("drop", handleDrop, false);
function preventDefaults(e) {
e.preventDefault();
e.stopPropagation();
}
function highlight(e) {
dropArea.classList.add("highlight");
}
function unhighlight(e) {
dropArea.classList.remove("highlight");
}
function handleDrop(e) {
let dt = e.dataTransfer;
let files = dt.files;
handleFiles(files);
}
function handleFiles(files) {
[...files].forEach(uploadFile);
}
function uploadFile(file) {
console.log("Uploading", file.name);
const form = document.querySelector("#uploadform");
const formData = new FormData();
formData.append('files[]', file);
fetch("fileupload.php", { method: "POST", body: formData }).then(
(response) => {
console.log(response);
if (response.status === 200) {
document.querySelector("#result").innerHTML = "Dateien wurden geladen";
}
});
}
dropArea.addEventListener("click", () => {
fileElem.click();
});
let fileElem = document.getElementById("fileElem");
fileElem.addEventListener("change", function (e) {
handleFiles(this.files);
});
// Previes
document.querySelector("#files").addEventListener ("change", function (evt) {
let files = event.target.files;
for (let i = 0, f; f = files[i]; i++) {
let reader = new FileReader();
reader.onload = (function(theFile) {
return function(e) {
let span = document.createElement('span');
span.innerHTML = ['<img class="thumb" src="', e.target.result, '" title="', escape(theFile.name), '"/>'].join('');
document.querySelector ('.filelist').insertBefore(span, null);
};
})(f);
reader.readAsDataURL(f);
}
})
</script>
<?php
echo '</div>'; // col
echo '</div>'; // row
echo '</div>'; // container
// Buttons at bottom of data area
echo '<div class="container">', "\n";
echo '<a href="', $g_scriptname, '?f=edit&id=', $id, '" class="btn btn-info" role="button">', _('Edit'), "</a>\n";
echo '&nbsp;';
echo '<a href="', $g_scriptname, '?f=del&id=', $id, '" class="btn btn-info" role="button">', _('Delete'), "</a>\n";
echo '&nbsp;';
echo '<a href="', $g_scriptname, '" class="btn btn-secondary" role="button">', _('Back'), "</a>\n";
echo "</div>\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);
?>
<h2><?=_('Edit Equipment')?></h2>
<form method="post">
<div class="mb-3">
<label for="ename" class="form-label"><?=_('Name')?></label>
<input type="text" class="form-control" id="ename" name="ename" value="<?=$equipment->ename ?>">
</div>
<div class="mb-3">
<label for="make" class="form-label"><?=_('Make')?></label>
<input type="text" class="form-control" id="make" name="make" value="<?=$equipment->make ?>">
</div>
<div class="mb-3">
<label for="model" class="form-label"><?=_('Model')?></label>
<input type="text" class="form-control" id="model" name="make" value="<?=$equipment->model ?>">
</div>
<div class="mb-3">
<label for="serial" class="form-label"><?=_('Serial')?></label>
<input type="text" class="form-control" id="serial" name="serial" value="<?=$equipment->serial ?>">
</div>
<button type="submit" class="btn btn-primary"><?=_('Save')?></button>
<a href="<?=$g_scriptname?>?f=view&id=<?=$id?>" class="btn btn-secondary"><?=_('Back')?></a>
</form>
<?php
elseif ($action == ACT_DELETE):
// ========== VARIANT: delete record ==========================================
else:
// ========== ERROR UNKNOWN VARIANT ===========================================
echo "<p>", _('Unknown function call: Please report to system development!'), "</p>\n";
endif; // $action == ...
// ========== END OF VARIANTS =================================================
include 'footer.php';
+121 -3
View File
@@ -280,8 +280,78 @@ function get_userlist() {
// ========== DATABASE FUNCTIONS ==============================================
function db_load_enum($table, $column) {
function db_exec_insert($table, $params) {
// $params must have keys corresponding to table fields prefixed with ':'
// e.g. $param[':field']
global $pdo;
global $g_error;
$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)");
try {
$sth->execute($params);
} catch (PDOexception $e) {
$g_error->Add('SQL-Error: '. $e->getMessage());
}
return $pdo->LastInsertId();
}
function db_exec_update($table, $params, $pk) {
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");
try {
$sth->execute($params);
} catch (PDOexception $e) {
$g_error->Add('SQL-Error: '. $e->getMessage());
return false;
}
return true;
}
function get_enum($enum) {
// Translate and beautify enums
$lookup = array(
'bad' => _('Bad'),
'box' => _('Box'),
'cat' => _('Catamaran'),
'closed' => _('Closed'),
'defect' => _('Defect'),
'done' => _('Done'),
'drawing' => _('Drawng'),
'equipment' => _('Equipment'),
'estimated' => _('Estimated'),
'finished' => _('Finished'),
'fixed' => _('Fixed'),
'generic' => _('Generic'),
'good' => _('Good'),
'invoice' => _('Invoice'),
'locked' => _('Locked'),
'manual' => _('Manual'),
'mono' => _('Monoholl'),
'new' => _('New'),
'normal' => _('Normal'),
'ongoing' => _('Ongoing'),
'open' => _('Open'),
'picture' => _('Picture'),
'planned' => _('Planned'),
'precise' => _('Precise'),
'rough' => _('Rough'),
'storage' => _('Storage'),
'task' => _('Task'),
'tri' => _('Trimaran'),
'unknown' => _('Unknown'),
'vessel' => _('Vessel'),
);
return $lookup[$enum] ?? $enum;
}
function db_load_enum($table, $column, $lookup=false, $as_dict=false) {
// returns array of enum-values as defined in database
// if lookup is true the name lookup and translaton is applied
// if as_dict is true the enum value is returned as the array key
global $pdo;
$sql = "SELECT TRIM(TRAILING ')' FROM SUBSTRING(column_type,6)) "
. "FROM information_schema.columns "
@@ -291,7 +361,20 @@ function db_load_enum($table, $column) {
// for PHP < 7.4
// return array_map(function($x) { return trim($x, "'"); }, explode(',', $sth->fetchColumn()));
// for PHP => 7.4
return array_map(fn($x) => trim($x, "'"), explode(',', $sth->fetchColumn()));
$arr = array_map(fn($x) => trim($x, "'"), explode(',', $sth->fetchColumn()));
if ($lookup) {
if ($as_dict) {
$dict = array();
foreach ($arr as $x) {
$dict[$x] = get_enum($x);
}
return $dict;
} else {
return array_map(fn($x) => get_enum($x), $arr);
}
} else {
return $arr;
}
}
function db_get_ddtext($ddid, $ddval) {
@@ -381,7 +464,25 @@ function db_get_opt_box($vid) {
return $list;
}
function db_get_opt_equip($vid) {
function db_get_opt_equip($vid, $default=NULL) {
global $pdo;
global $g_error;
if (isset($default)) {
$list = $default;
} else {
$list = array();
}
$sql = "SELECT eid, ename FROM equipment WHERE vid=? ORDER BY ename";
$sth = $pdo->prepare($sql);
try {
$sth->execute([$vid]);
} catch(PDOException $e) {
$g_error->Add($e->getMessage());
}
foreach ($sth->fetchAll(PDO::FETCH_NUM) as $rec) {
$list[$rec[0]] = $rec[1];
}
return $list;
}
function db_get_opt_manuf($default=NULL) {
@@ -504,6 +605,13 @@ function form_view_buttons($script, $id) {
echo "</div>\n";
}
function form_new_buttons($script) {
echo '<div class="container-fluid px-0 my-3">', "\n";
echo '<button type="submit" name="submit[insert]" class="btn btn-primary">', _('Save'), "</button>\n";
echo '<a href="', $script, '" class="btn btn-secondary">', _('Back'), "</a>\n";
echo "</div>\n";
}
function form_edit_buttons($script, $id) {
echo '<div class="container-fluid px-0 my-3">', "\n";
echo '<button type="submit" name="submit[update]" class="btn btn-primary">', _('Save'), "</button>\n";
@@ -660,6 +768,16 @@ function format_currency($val) {
}
}
function format_color($color) {
$colstr = '<span style="';
$style = "padding:2px 4px;border-radius:4px;background-color:#".$color;
if (get_color_brightness($color) < 0.4) {
$style .= ';color:white';
}
$colstr .= $style . '">#' . $color . '</span>' ;
return $colstr;
}
function format_filesize($size, $format=2) {
switch ($format) {
case 1: // short
+18 -5
View File
@@ -78,6 +78,8 @@ switch ($submit = form_get_action()) {
$p[':draught_min'] = gpc_get_float($_POST, 'draught_min');
$p[':displacement'] = gpc_get_int($_POST, 'displacement');
$p[':ballast'] = gpc_get_int($_POST, 'ballast');
$p[':beltpos_aft'] = gpc_get_float($_POST, 'beltpos_aft');
$p[':beltpos_bow'] = gpc_get_float($_POST, 'beltpos_bow');
$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 vessel SET $fields WHERE vid=:vid");
@@ -141,7 +143,7 @@ echo "</form>\n";
// Get current vessel data
$sql = "SELECT vesselname, model, loa, lwl, beam, draught, draught_min,"
. " displacement, ballast, remarks "
. " displacement, ballast, beltpos_aft, beltpos_bow, remarks "
. "FROM vessel "
. "WHERE vid=?";
$sth = $pdo->prepare($sql);
@@ -199,11 +201,13 @@ $vessel = $sth->fetch();
<tr><td><?=_('Draught, min.')?></td><td><?=format_float($vessel['draught_min'], 2, 'm')?></td></tr>
<tr><td><?=_('Displacement')?></td><td><?=$vessel['displacement']?>&thinsp;kg</td></tr>
<tr><td><?=_('Ballast')?></td><td><?=$vessel['ballast']?>&thinsp;kg</td></tr>
<tr><td><?=_('Belt position aft')?></td><td><?=format_float($vessel['beltpos_aft'], 2, 'm')?></td></tr>
<tr><td><?=_('Belt position bow')?></td><td><?=format_float($vessel['beltpos_bow'], 2, 'm')?></td></tr>
</table>
<?php
// Edit vessel only for captain
if ($user->role == 'captain') {
echo '<a href="', $script, '?f=edit&id=', $user->vid, '" class="btn btn-primary" role="button">', _('Edit'), "</a>\n";
echo '<a href="', $g_scriptname, '?f=edit&id=', $user->vid, '" class="btn btn-primary" role="button">', _('Edit'), "</a>\n";
}
?>
</div>
@@ -219,7 +223,8 @@ if ($user->role == 'captain') {
// Statistics
// Storage: 0 - default, 1 - tank
$stype = [ 0 => _('Default'), 1 => _('Tank')];
// $stype = [ 0 => _('Default'), 1 => _('Tank')];
$stype = db_get_options(3);
$sql = "SELECT stype, COUNT(stype) "
. "FROM storage "
. "WHERE vid=? "
@@ -301,7 +306,7 @@ elseif ($action == ACT_ADD):
echo '<h2>', _('Add additional yacht'), "</h2>\n";
?>
<form method="post">
<form method="post" action="<?=$g_scriptname?>">
<div class="mb-3">
<label for="vesselname" class="form-label"><?=_('Name')?></label>
<input type="text" class="form-control" id="vesselname" name="vesselname" required autofocus>
@@ -326,7 +331,7 @@ elseif ($action == ACT_EDIT):
// ========== VARIANT: edit single record =====================================
$sql = "SELECT vesselname, vtype, model, loa, lwl, beam, draught, draught_min,"
. " displacement, ballast, remarks "
. " displacement, ballast, beltpos_aft, beltpos_bow, remarks "
. "FROM vessel "
. "WHERE vid=?";
$sth = $pdo->prepare($sql);
@@ -372,6 +377,14 @@ $vessel = $sth->fetch(PDO::FETCH_OBJ);
<label for="ballast" class="form-label"><?=_('Ballast')?></label>
<input type="number" input-mode="decimal" min="0" max="100000" step="1" class="form-control" id="ballast" name="ballast" value="<?=$vessel->ballast ?>">
</div>
<div class="mb-3">
<label for="beltpos_aft" class="form-label"><?=_('Belt position aft')?></label>
<input type="text" class="form-control" id="beltpos_aft" name="beltpos_aft" value="<?=format_float($vessel->beltpos_aft, 2) ?>">
</div>
<div class="mb-3">
<label for="beltpos_bow" class="form-label"><?=_('Belt position bow')?></label>
<input type="text" class="form-control" id="beltpos_bow" name="beltpos_bow" value="<?=format_float($vessel->beltpos_bow, 2) ?>">
</div>
<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>
+20 -59
View File
@@ -26,67 +26,28 @@ switch ($submit = form_get_action()) {
case 'del': $action = ACT_DELETE; break;
case 'insert':
$invname = gpc_get_string($_POST, 'invname');
$number = gpc_get_int($_POST, 'number');
$boxtype = gpc_get_string($_POST, 'boxtype');
$sid = gpc_get_int($_POST, 'sid');
$boxid = gpc_get_int($_POST, 'boxid');
$sql = "INSERT INTO inventory "
. " (invname, invcond, number, boxtype, sid, boxid) "
. "VALUES "
. " (:invname, 'good', :number, :boxtype, :sid, :boxid)";
$sth = $pdo->prepare($sql);
$sth->bindValue(':invname', $invname, PDO::PARAM_STR);
$sth->bindValue(':number', $number, PDO::PARAM_INT);
$sth->bindValue(':boxtype', $boxtype, PDO::PARAM_STR);
$sth->bindValue(':sid', $sid, PDO::PARAM_INT);
$sth->bindValue(':boxid', $boxid, PDO::PARAM_INT);
try {
$sth->execute();
} catch (PDOException $e) {
$g_error->Add('SQL-Error: '. $e->getMessage());
}
$id = $pdo->LastInsertId();
$p[':invname'] = gpc_get_string($_POST, 'invname');
$p[':number'] = gpc_get_int($_POST, 'number');
$p[':boxtype'] = gpc_get_string($_POST, 'boxtype');
$p[':sid'] = gpc_get_int($_POST, 'sid');
$p[':boxid'] = gpc_get_int($_POST, 'boxid');
$p[':invcond'] = 'good';
$id = db_exec_insert('inventory', $p);
$action = ACT_VIEW;
break;
case 'update':
$invname = gpc_get_string($_POST, 'invname');
$number = gpc_get_int($_POST, 'number');
$boxtype = gpc_get_string($_POST, 'boxtype');
$sid = gpc_get_int($_POST, 'sid');
$boxid = gpc_get_int($_POST, 'boxid');
$weight = min(gpc_get_float($_POST, 'weight'), 999.99); // limit max value
$price = gpc_get_currency($_POST, 'price');
$purchdate = gpc_get_date($_POST, 'purchdate');
$invcond = gpc_get_string($_POST, 'invcond');
$sql = "UPDATE inventory "
. "SET invname=:invname,"
. " number=:number,"
. " boxtype=:boxtype,"
. " sid=:sid,"
. " boxid=:boxid,"
. " weight=:weight,"
. " price=:price,"
. " purchdate=:purchdate,"
. " invcond=:invcond "
. "WHERE invid=:invid";
$sth = $pdo->prepare($sql);
$sth->bindValue(':invid', $id, PDO::PARAM_INT);
$sth->bindValue(':invname', $invname, PDO::PARAM_STR);
$sth->bindValue(':number', $number, PDO::PARAM_INT);
$sth->bindValue(':boxtype', $boxtype, PDO::PARAM_STR);
$sth->bindValue(':sid', $sid, PDO::PARAM_INT);
$sth->bindValue(':boxid', $boxid, PDO::PARAM_INT);
$sth->bindValue(':weight', $weight);
$sth->bindValue(':price', $price);
$sth->bindValue(':purchdate', $purchdate);
$sth->bindValue(':invcond', $invcond, PDO::PARAM_STR);
try {
$sth->execute();
} catch (PDOException $e) {
$g_error->Add('SQL-Error: '. $e->getMessage());
}
$p[':invid'] = $id;
$p[':invname'] = gpc_get_string($_POST, 'invname');
$p[':number'] = gpc_get_int($_POST, 'number');
$p[':boxtype'] = gpc_get_string($_POST, 'boxtype');
$p[':sid'] = gpc_get_int($_POST, 'sid');
$p[':boxid'] = gpc_get_int($_POST, 'boxid');
$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[':invcond'] = gpc_get_string($_POST, 'invcond');
db_exec_update('inventory', $p, 'invid');
$action = ACT_VIEW;
break;
@@ -287,8 +248,8 @@ $inventory = $sth->fetch(PDO::FETCH_OBJ);
</select>
</div>
<?php
form_create_select('sid', _('Storage'), $opt_storage);
form_create_select('boxid', _('Box'), $opt_box);
form_create_select('sid', _('Storage'), $opt_storage, $inventory->sid);
form_create_select('boxid', _('Box'), $opt_box, $inventory->boxid);
?>
<div class="mb-3">
<label for="price" class="form-label"><?=sprintf(_('Price, %s'), $g_lconv['currency_symbol']); ?></label>
+14 -47
View File
@@ -11,14 +11,7 @@ $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'];
}
$opt_equipment = db_get_opt_equip($user->vid, [0 => _('*** unassigned ***')]);
// ========== ACTIONS START ===================================================
@@ -32,39 +25,25 @@ switch ($submit = form_get_action()) {
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();
$p[':vid'] = $user->vid;
$p[':eid'] = gpc_get_int($_POST, 'eid');
$p[':activities'] = gpc_get_string($_POST, 'activities', 80);
$id = db_exec_insert('maintenance', $p);
$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();
$p[':maintid'] = $id;
$p[':eid'] = gpc_get_int($_POST, 'eid');
$p[':activities'] = gpc_get_string($_POST, 'activities', 80);
$p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
db_exec_update('maintenance', $p, 'maintid');
$action = ACT_VIEW;
break;
case 'delete':
break;
default:
$g_error->Add(sprintf(_("Unknown function '%s'!"), $submit));
$valid = FALSE;
@@ -218,19 +197,7 @@ echo '<h2>', _('Edit Maintenance'), "</h2>\n";
<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>
<?php form_create_select('eid', _('Equipment'), $opt_equipment, $maint->eid); ?>
<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>
+1 -1
View File
@@ -99,7 +99,7 @@ zu erfassen.</p>
<h3>Stammdaten</h3>
<p>Diese Daten ändern sich nicht sehr häufig, sind aber für den Betrieb
essentiell. Stanndaten sind beispielsweise Firmen, Auswahllisten oder
essentiell. Stammdaten sind beispielsweise Firmen, Auswahllisten oder
auch der Stauraum.</p>
<?php
+2 -2
View File
@@ -186,7 +186,7 @@ elseif ($action == ACT_ADD):
echo '<h2>', _('Add measurement'), "</h2>\n";
?>
<form method="post">
<form method="post" action="<?=$g_scriptname?>">
<div class="mb-3">
<label for="mname" class="form-label"><?=_('Name')?></label>
<input type="text" class="form-control" id="mname" name="mname" required autofocus>
@@ -237,7 +237,7 @@ $measurement = $sth->fetch(PDO::FETCH_OBJ);
echo '<h2>', _('Edit measurement'), "</h2>\n";
?>
<form method="post">
<form method="post" action="<?=$g_scriptname?>">
<input type="hidden" name="id" value="<?=$id?>">
<div class="mb-3">
<label for="mname" class="form-label"><?=_('Name')?></label>
+2 -2
View File
@@ -136,7 +136,7 @@ elseif ($action == ACT_ADD):
echo '<h2>', _('Add provisions'), "</h2>\n";
?>
<form method="post">
<form method="post" action="<?=$g_scriptname?>">
<div class="mb-3">
<label for="provname" class="form-label"><?=_('Name')?></label>
<input type="text" class="form-control" id="provname" name="provname" required autofocus>
@@ -196,7 +196,7 @@ $prov = $sth->fetch(PDO::FETCH_OBJ);
echo '<h2>', _('Edit provision'), "</h2>\n";
?>
<form method="post">
<form method="post" action="<?=$g_scriptname?>">
<input type="hidden" name="id" value="<?=$id?>">
<div class="mb-3">
<label for="provname" class="form-label"><?=_('Name')?></label>
+1 -1
View File
@@ -19,7 +19,7 @@ echo "<h1>$pagetitle</h1>\n";
<p>Search will be implemented later.
This page is currently just a placeholder.</p>
<form method="post">
<form method="post" action="<?=$g_scriptname?>">
<div>
<label for="needle">Suche nach:</label>
<input type="text" id="needle" name="needle" value="<?=$needle?>" autofocus>
+1 -1
View File
@@ -178,7 +178,7 @@ echo '<h2>', _('Add Storage'), "</h2>\n";
?>
<form method="post">
<form method="post" action="<?=$g_scriptname?>">
<div class="mb-3">
<label for="sname" class="form-label"><?=_('Name')?></label>
<input type="text" class="form-control" id="sname" name="sname">
+2 -2
View File
@@ -117,7 +117,7 @@ elseif ($action == ACT_ADD):
echo '<h2>', _('Add Task'), "</h2>\n";
?>
<form method="post">
<form method="post" action="<?=$g_scriptname?>">
<?php
// preselect project if parameter is set
$projid = gpc_get_int($_REQUEST, 'projid');
@@ -165,7 +165,7 @@ $task = $sth->fetch(PDO::FETCH_OBJ);
echo '<h2>', _('Edit Task'), "</h2>\n";
?>
<form method="post">
<form method="post" action="<?=$g_scriptname?>">
<input type="hidden" name="id" value="<?=$id?>">
<div class="mb-3">
<label for="taskname" class="form-label"><?=_('Name')?></label>