Webgui fixed cables and fuses, parts of code reorganized
This commit is contained in:
1 parent
9d09b1e120
commit
5641e1706f
25 files changed
+497
-427
No files matched your search
+4
-3
@@ -16,6 +16,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';
|
||||
require 'lib/form.inc';
|
||||
|
||||
$pagetitle = _('Boxes');
|
||||
|
||||
@@ -118,7 +119,7 @@ foreach ($res as $row) {
|
||||
echo '<td>', ($opt_boxtype[$row['boxtype']] ?? ''), "</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";
|
||||
echo '<td class="text-end">', format_float($row['weight'], 2, 'kg'), "</td>\n";
|
||||
// Edit current record button
|
||||
echo "<td>";
|
||||
echo '<a title="', _('Edit'), '" href="', $g_scriptname, '?f=edit&id=', $row['boxid'], '"><i class="bi-pencil"></i></a>', "\n";
|
||||
@@ -126,8 +127,8 @@ foreach ($res as $row) {
|
||||
echo "</tr>\n";
|
||||
}
|
||||
// Table summary
|
||||
$numrows = count($res);
|
||||
table_rec_summary($i, $numrows, $numrows, 6);
|
||||
//$numrows = count($res);
|
||||
//table_rec_summary(1, $numrows, $numrows, 6);
|
||||
echo "</table>\n";
|
||||
|
||||
form_add_button('box.php');
|
||||
|
||||
+18
-7
@@ -9,6 +9,7 @@
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
require 'lib/form.inc';
|
||||
|
||||
$pagetitle = _('Cables');
|
||||
|
||||
@@ -31,6 +32,7 @@ switch ($submit = form_get_action()) {
|
||||
|
||||
case 'filter':
|
||||
$flt = array();
|
||||
$flt['type'] = gpc_get_int($_POST, 'flt_type');
|
||||
$flt['txt'] = gpc_get_string($_POST, 'flt_txt');
|
||||
db_save_filter($flt, 211);
|
||||
$action = ACT_DEFAULT;
|
||||
@@ -95,7 +97,7 @@ if ($action == ACT_DEFAULT):
|
||||
// ========== VARIANT: default behavior =======================================
|
||||
|
||||
// load filter from db
|
||||
$flt = db_get_filter($user->id, 211, ['txt']);
|
||||
$flt = db_get_filter($user->id, 211, ['txt', 'type']);
|
||||
|
||||
$w = array('vid=:vid');
|
||||
$p = array(':vid' => $user->vid);
|
||||
@@ -104,6 +106,13 @@ if (strlen($flt->txt) > 1) {
|
||||
$w[] = 'cablename LIKE :txt OR remarks LIKE :txt';
|
||||
$p[':txt'] = '%'.$flt->txt.'%';
|
||||
}
|
||||
if ($flt->type == -1) {
|
||||
$w[] = 'cabletype IS NULL';
|
||||
} elseif ($flt->type > 0) {
|
||||
$w[] = 'cabletype=:cabletype';
|
||||
$p[':type'] = $flt->type;
|
||||
}
|
||||
|
||||
$where = join(' AND ', $w);
|
||||
$order = ' ORDER BY cablename';
|
||||
|
||||
@@ -115,10 +124,10 @@ echo "<h1>$pagetitle</h1>\n";
|
||||
<div id="filter" class="card">
|
||||
<div class="card-header"><i class="bi bi-funnel me-2"></i>Filter</div>
|
||||
<div class="card-body d-flex flex-wrap gap-3">
|
||||
<div class="d-flex flex-nowrap gap-2">
|
||||
<label for="flt_txt">Text</label>
|
||||
<input type="text" class="form-control" name="flt_txt" maxlength="30" value="<?=$flt->txt ?? ''?>">
|
||||
</div>
|
||||
<?php
|
||||
filter_create_select('flt_type', _('Type'), $g_opt_all + $g_opt_none + $opt_cabletype, $flt->type);
|
||||
filter_create_text('flt_txt', _('Text'), $flt->text, 30, 45);
|
||||
?>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<button name="submit[filter]" class="btn btn-sm btn-primary" title="<?=_('Apply')?>"><?=_('Go')?></button>
|
||||
@@ -128,7 +137,7 @@ echo "<h1>$pagetitle</h1>\n";
|
||||
</form>
|
||||
<?php
|
||||
|
||||
$sql = "SELECT cableid, cablename, conductors, length, xsection, color, cablecond "
|
||||
$sql = "SELECT cableid, cablename, cabletype, conductors, length, xsection, color, cablecond "
|
||||
. "FROM cable ";
|
||||
$sql .= ' WHERE ' . $where;
|
||||
$sql .= $order;
|
||||
@@ -143,6 +152,7 @@ echo "<tr>\n";
|
||||
echo '<th>#</th>';
|
||||
echo '<th>', _('Cable'), "</th>";
|
||||
echo '<th>', _('Name'), "</th>";
|
||||
echo '<th>', _('Type'), "</th>";
|
||||
echo '<th>', _('Conductors'), "</th>";
|
||||
echo '<th>', _('Length'), "</th>";
|
||||
echo '<th>', _('Cross section'), "</th>";
|
||||
@@ -160,6 +170,7 @@ foreach ($res as $row) {
|
||||
echo "</td>\n";
|
||||
echo "<td>", $row['cableid'], "</td>\n";
|
||||
echo "<td>", $row['cablename'], "</td>\n";
|
||||
echo "<td>", $row['cabletype'], "</td>\n";
|
||||
echo "<td>", $row['conductors'], "</td>\n";
|
||||
echo "<td>", $row['length'], "m</td>\n";
|
||||
echo "<td>", $row['xsection'], "mm²</td>\n";
|
||||
@@ -171,7 +182,7 @@ foreach ($res as $row) {
|
||||
echo "</tr>\n";
|
||||
}
|
||||
// Table summary
|
||||
table_rec_summary(1, $i, $i, 9);
|
||||
// table_rec_summary(1, $i-1, $i-1, 10);
|
||||
echo "</table>\n";
|
||||
|
||||
form_add_button($g_scriptname);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
require 'lib/form.inc';
|
||||
|
||||
$pagetitle = _('Checklists');
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
require 'lib/form.inc';
|
||||
|
||||
$pagetitle=_('Company');
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ doctype icons
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
require 'lib/form.inc';
|
||||
require 'lib/fileutils.inc';
|
||||
|
||||
$pagetitle = _('Documents');
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
require 'lib/form.inc';
|
||||
|
||||
$pagetitle = _('Lists');
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
require 'lib/form.inc';
|
||||
require 'lib/fileutils.inc';
|
||||
require 'lib/signalk.inc';
|
||||
|
||||
|
||||
+40
-20
@@ -9,6 +9,7 @@
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
require 'lib/form.inc';
|
||||
|
||||
$pagetitle = _('Fuses');
|
||||
|
||||
@@ -31,6 +32,7 @@ switch ($submit = form_get_action()) {
|
||||
case 'filter':
|
||||
$flt = array();
|
||||
$flt['location'] = gpc_get_int($_POST, 'flt_location');
|
||||
$flt['type'] = gpc_get_int($_POST, 'flt_type');
|
||||
$flt['txt'] = gpc_get_string($_POST, 'flt_txt');
|
||||
db_save_filter($flt, 212);
|
||||
$action = ACT_DEFAULT;
|
||||
@@ -43,10 +45,10 @@ switch ($submit = form_get_action()) {
|
||||
|
||||
case 'insert':
|
||||
$p[':vid'] = $user->vid;
|
||||
$p[':fnumber'] = gpc_get_int($_POST, 'fnumber');;
|
||||
$p[':ftype'] = gpc_get_int($_POST, 'ftype');;
|
||||
$p[':current'] = gpc_get_int($_POST, 'current');;
|
||||
$p[':location'] = gpc_get_int($_POST, 'location');;
|
||||
$p[':fnumber'] = gpc_get_int($_POST, 'fnumber');
|
||||
$p[':ftype'] = gpc_get_int($_POST, 'ftype', NULL, -1);
|
||||
$p[':current'] = gpc_get_int($_POST, 'current');
|
||||
$p[':location'] = gpc_get_int($_POST, 'location');
|
||||
$p[':description'] = gpc_get_string($_POST, 'description');
|
||||
$id = db_exec_insert('fuse', $p);
|
||||
db_set_revision('table', TBL_FUSES);
|
||||
@@ -55,11 +57,13 @@ switch ($submit = form_get_action()) {
|
||||
|
||||
case 'update':
|
||||
$p[':fuseid'] = $id;
|
||||
$p[':fnumber'] = gpc_get_string($_POST, 'fuseid');
|
||||
$p[':fnumber'] = gpc_get_int($_POST, 'fnumber');
|
||||
$p[':ftype'] = gpc_get_int($_POST, 'ftype', [-1]);
|
||||
$p[':current'] = gpc_get_float($_POST, 'current');
|
||||
$p[':cableid'] = gpc_get_int($_POST, 'cableid');
|
||||
$p[':eid'] = gpc_get_int($_POST, 'id');
|
||||
$p[':location'] = gpc_get_int($_POST, 'location');
|
||||
$p[':color'] = gpc_get_color($_POST, 'color');
|
||||
$p[':cableid'] = gpc_get_int($_POST, 'cableid', NULL, -1);
|
||||
$p[':eid'] = gpc_get_int($_POST, 'id', [-1]);
|
||||
$p[':location'] = gpc_get_int($_POST, 'location', NULL, -1);
|
||||
$p[':description'] = gpc_get_string($_POST, 'description');
|
||||
$p[':remarks'] = gpc_get_string($_POST, 'remarks');
|
||||
db_exec_update('fuse', $p, 'fuseid');
|
||||
@@ -98,7 +102,7 @@ if ($action == ACT_DEFAULT):
|
||||
$opt_ftype_short = db_get_options(DD_FUSE_TYPE, '', true);
|
||||
|
||||
// load filter from db
|
||||
$flt = db_get_filter($user->id, 212, ['txt','location']);
|
||||
$flt = db_get_filter($user->id, 212, ['txt', 'location', 'type']);
|
||||
|
||||
$w = array('vid=:vid');
|
||||
$p = array(':vid' => $user->vid);
|
||||
@@ -109,6 +113,12 @@ if ($flt->location == -1) {
|
||||
$w[] = 'location=:location';
|
||||
$p[':location'] = $flt->location;
|
||||
}
|
||||
if ($flt->type == -1) {
|
||||
$w[] = 'ftype IS NULL';
|
||||
} elseif ($flt->type > 0) {
|
||||
$w[] = 'ftype=:ftype';
|
||||
$p[':ftype'] = $flt->type;
|
||||
}
|
||||
if (strlen($flt->txt) > 1) {
|
||||
$w[] = 'description LIKE :txt';
|
||||
$p[':txt'] = '%'.$flt->txt.'%';
|
||||
@@ -126,11 +136,9 @@ echo "<h1>$pagetitle</h1>\n";
|
||||
<div class="card-body d-flex flex-wrap gap-3">
|
||||
<?php
|
||||
filter_create_select('flt_location', _('Location'), $g_opt_all + $g_opt_none + $opt_location, $flt->location);
|
||||
filter_create_select('flt_type', _('Type'), $g_opt_all + $g_opt_none + $opt_ftype, $flt->type);
|
||||
filter_create_text('flt_txt', _('Description'), $flt->text, 30, 45);
|
||||
?>
|
||||
<div class="d-flex flex-nowrap gap-2">
|
||||
<label for="flt_txt"><?=_('Description')?></label>
|
||||
<input type="text" class="form-control" name="flt_txt" size="15" maxlength="30" value="<?=$flt->txt ?? ''?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<button name="submit[filter]" class="btn btn-sm btn-primary" title="<?=_('Apply')?>"><?=_('Go')?></button>
|
||||
@@ -140,7 +148,7 @@ filter_create_select('flt_location', _('Location'), $g_opt_all + $g_opt_none + $
|
||||
</form>
|
||||
<?php
|
||||
|
||||
$sql = "SELECT fuseid, fnumber, ftype, location, current, description "
|
||||
$sql = "SELECT fuseid, fnumber, ftype, location, current, color, description "
|
||||
. "FROM fuse";
|
||||
$sql .= ' WHERE ' . $where;
|
||||
$sql .= $order;
|
||||
@@ -156,6 +164,7 @@ echo '<th>#</th>';
|
||||
echo '<th>', pgettext('number', 'Number'), "</th>";
|
||||
echo '<th>', _('Type'), "</th>";
|
||||
echo '<th>', _('Current'), "</th>";
|
||||
echo '<th>', _('Color'), "</th>";
|
||||
echo '<th>', _('Location'), "</th>";
|
||||
echo '<th>', _('Description'), "</th>";
|
||||
echo "<th></th>";
|
||||
@@ -170,6 +179,7 @@ foreach ($res as $row) {
|
||||
echo "<td>F", $row['fnumber'], "</td>\n";
|
||||
echo "<td>",$opt_ftype_short[$row['ftype']], "</td>\n";
|
||||
echo "<td>", $row['current'], "A</td>\n";
|
||||
echo '<td>', format_color(strtoupper($row['color'])), "</td>\n";
|
||||
echo "<td>", $opt_location[$row['location']], "</td>\n";
|
||||
echo "<td>", $row['description'], "</td>\n";
|
||||
// Edit current record button
|
||||
@@ -179,7 +189,7 @@ foreach ($res as $row) {
|
||||
echo "</tr>\n";
|
||||
}
|
||||
// Table summary
|
||||
table_rec_summary($i0, $i, $numrows, 6);
|
||||
//table_rec_summary(1, $i-1, $i-1, 6);
|
||||
echo "</table>\n";
|
||||
|
||||
form_add_button($g_scriptname);
|
||||
@@ -189,7 +199,7 @@ elseif ($action == ACT_ADD):
|
||||
|
||||
echo '<h2>', _('Add fuse'), "</h2>\n";
|
||||
|
||||
// calc next free fuse number for convenience
|
||||
// FIXME calc next free fuse number for convenience
|
||||
$sql = "SELECT max(fnumber) FROM fuse WHERE vid=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$user->vid]);
|
||||
@@ -205,7 +215,9 @@ $fnumber = $sth->fetchColumn() + 1;
|
||||
<label for="note" class="form-label"><?=_('Description')?></label>
|
||||
<input type="text" class="form-control" id="description" name="description" autofocus>
|
||||
</div>
|
||||
<?php form_create_select('ftype', _('Type'), $opt_ftype); ?>
|
||||
<?php
|
||||
form_create_select('ftype', _('Type'), $g_opt_none + $opt_ftype);
|
||||
?>
|
||||
<div class="mb-3">
|
||||
<label for="current" class="form-label"><?=_('Current, Ampere')?></label>
|
||||
<input type="text" class="form-control" id="current" name="current" required>
|
||||
@@ -218,7 +230,7 @@ echo "</form>\n";
|
||||
elseif ($action == ACT_VIEW):
|
||||
// ========== VARIANT: view single record =====================================
|
||||
|
||||
$sql = "SELECT fnumber, ftype, current, cableid, eid, location, description, remarks "
|
||||
$sql = "SELECT fnumber, ftype, current, cableid, eid, location, description, color, remarks "
|
||||
. "FROM fuse "
|
||||
. "WHERE vid=? AND fuseid=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
@@ -232,6 +244,7 @@ echo '<tr><th style="width:20%">', _('Fuse'),"</th><td>F", $fuse->fnumber, "</td
|
||||
echo '<tr><th>', _('Description'),"</th><td>", $fuse->description, "</td></tr>\n";
|
||||
echo '<tr><th>', _('Type'),"</th><td>", $opt_ftype[$fuse->ftype], "</td></tr>\n";
|
||||
echo '<tr><th>', _('Current'),"</th><td>", $fuse->current, "A</td></tr>\n";
|
||||
echo '<tr><th>', _('Color'),"</th><td>", format_color($fuse->color), "</td></tr>\n";
|
||||
echo '<tr><th>', _('Location'),"</th><td>", $opt_location[$fuse->location], "</td></tr>\n";
|
||||
echo '<tr><th>', _('Cable'),"</th><td>", $fuse->cableid, "</td></tr>\n";
|
||||
echo '<tr><th>', _('Equipment'),"</th><td>", $fuse->eid, "</td></tr>\n";
|
||||
@@ -246,7 +259,7 @@ elseif ($action == ACT_EDIT):
|
||||
$opt_cable = db_get_opt_cable($user->vid);
|
||||
$opt_equipment = db_get_opt_equip($user->vid);
|
||||
|
||||
$sql = "SELECT fnumber, ftype, current, cableid, eid, location, description, remarks "
|
||||
$sql = "SELECT fnumber, ftype, current, cableid, eid, location, description, color, remarks "
|
||||
. "FROM fuse "
|
||||
. "WHERE fuseid=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
@@ -259,8 +272,11 @@ echo '<h2>', _('Edit fuse'), "</h2>\n";
|
||||
<input type="hidden" name="id" value="<?=$id?>">
|
||||
<div class="mb-3">
|
||||
<label for="fnumber" class="form-label"><?=_('Fuse number')?></label>
|
||||
<input type="text" class="form-control" id="fnumber" name="fnumber" value="<?=$fuse->fnumber ?>">
|
||||
<input type="number" class="form-control" id="fnumber" name="fnumber" value="<?=$fuse->fnumber ?>">
|
||||
</div>
|
||||
<?php
|
||||
form_create_select('ftype', _('Type'), $g_opt_none + $opt_ftype, $fuse->ftype);
|
||||
?>
|
||||
<div class="mb-3">
|
||||
<label for="note" class="form-label"><?=_('Description')?></label>
|
||||
<input type="text" class="form-control" id="description" name="description" value="<?=h($fuse->description)?>">
|
||||
@@ -269,6 +285,10 @@ echo '<h2>', _('Edit fuse'), "</h2>\n";
|
||||
<label for="current" class="form-label"><?=_('Current')?></label>
|
||||
<input type="text" class="form-control" id="current" name="current" value="<?=format_float($fuse->current) ?>">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="color" class="form-label"><?=_('Color')?></label>
|
||||
<input type="color" name="color" id="color" class="form-control" value="#<?=$fuse->color;?>">
|
||||
</div>
|
||||
<?php
|
||||
form_create_select('location', _('Location'), $g_opt_none + $opt_location, $fuse->location);
|
||||
form_create_select('cableid', _('Cable'), $g_opt_none + $opt_cable, $fuse->cableid);
|
||||
|
||||
+69
-390
@@ -464,155 +464,7 @@ function get_userlist() {
|
||||
|
||||
// ========== DATABASE FUNCTIONS ==============================================
|
||||
|
||||
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);
|
||||
$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 false;
|
||||
}
|
||||
return $pdo->LastInsertId();
|
||||
}
|
||||
|
||||
function db_exec_update($table, $params, $pk) {
|
||||
// primary key can be a single field name or multiple fields: $pk is an array
|
||||
global $pdo;
|
||||
global $g_error;
|
||||
// remove primary key fields from list of fields to update
|
||||
if (is_array($pk)) {
|
||||
if (count($pk) == 1) {
|
||||
$pk = $pk[0];
|
||||
$fields = $params;
|
||||
unset($fields[':'.$pk]);
|
||||
$where = "$pk=:$pk";
|
||||
} else {
|
||||
$pkparams = array_map(fn($value) => ':' . $value, $pk);
|
||||
$fields = array_diff_key($params, array_flip($pkparams));
|
||||
$where = join(' AND ', array_map(fn($s) => "$s=:$s", $pk));
|
||||
}
|
||||
} else {
|
||||
$fields = $params;
|
||||
unset($fields[':'.$pk]);
|
||||
$where = "$pk=:$pk";
|
||||
}
|
||||
$fieldlist = join(', ', array_map(fn($s) => ltrim($s, ':') . '=' . $s, array_keys($fields)));
|
||||
$sql = "UPDATE $table SET $fieldlist WHERE $where";
|
||||
$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_exec_delete($table, $condition, $params) {
|
||||
// WIP untested!
|
||||
// condition contains the where part of the sql statement
|
||||
// params are values for placeholders in condition
|
||||
// returns the number of deleted records
|
||||
global $pdo;
|
||||
global $g_error;
|
||||
// convert params to array if single value is given
|
||||
if (!is_array($params)) {
|
||||
$params = [$params];
|
||||
}
|
||||
$sql = "DELETE FROM $table";
|
||||
if (!empty($condition)) {
|
||||
$sql .= ' WHERE ' . $condition;
|
||||
}
|
||||
$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 -1;
|
||||
}
|
||||
return $sth->rowCount();
|
||||
}
|
||||
|
||||
|
||||
function get_enum($enum) {
|
||||
// translate and beautify enums
|
||||
$lookup = array(
|
||||
'NULL' => _('n/a'),
|
||||
'active' => _('Active'),
|
||||
'bad' => _('Bad'),
|
||||
'box' => _('Box'),
|
||||
'cable' => _('Cable'),
|
||||
'cat' => _('Catamaran'),
|
||||
'completed' => _('Completed'),
|
||||
'closed' => _('Closed'),
|
||||
'company' => _('Company'),
|
||||
'day' => _('Day'),
|
||||
'defect' => _('Defect'),
|
||||
'deleted' => _('Deleted'),
|
||||
'done' => _('Done'),
|
||||
'drawing' => _('Drawing'),
|
||||
'equipment' => _('Equipment'),
|
||||
'estimated' => _('Estimated'),
|
||||
'excellent' => _('Excellent'),
|
||||
'fair' => _('Fair'),
|
||||
'finished' => _('Finished'),
|
||||
'fixed' => _('Fixed'),
|
||||
'fuse' => _('Fuse'),
|
||||
'generic' => _('Generic'),
|
||||
'good' => _('Good'),
|
||||
'high' => _('High'),
|
||||
'historic' => _('Historic'),
|
||||
'invoice' => _('Invoice'),
|
||||
'locked' => _('Locked'),
|
||||
'low' => _('Low'),
|
||||
'manual' => _('Manual'),
|
||||
'medium' => _('Medium'),
|
||||
'missed' => _('Missed'),
|
||||
'mono' => _('Monohull'),
|
||||
'month' => _('Month'),
|
||||
'new' => _('New'),
|
||||
'none' => _('None'),
|
||||
'normal' => _('Normal'),
|
||||
'ongoing' => _('Ongoing'),
|
||||
'open' => _('Open'),
|
||||
'ordered' => _('Ordered'),
|
||||
'paused' => _('Paused'),
|
||||
'pending' => _('Pending'),
|
||||
'picture' => _('Picture'),
|
||||
'plan' => _('Planned'),
|
||||
'precise' => _('Precise'),
|
||||
'project' => _('Project'),
|
||||
'quarter' => _('Quarter'),
|
||||
'removed' => _('Removed'),
|
||||
'repairable' => _('Repairable'),
|
||||
'rough' => _('Rough'),
|
||||
'skipped' => _('Skipped'),
|
||||
'storage' => _('Storage'),
|
||||
'task' => _('Task'),
|
||||
'tri' => _('Trimaran'),
|
||||
'unknown' => _('Unknown'),
|
||||
'user' => _('User'),
|
||||
'vessel' => _('Vessel'),
|
||||
'waiting' => _('Waiting'),
|
||||
'week' => _('Week'),
|
||||
);
|
||||
return $lookup[$enum] ?? $enum;
|
||||
}
|
||||
// TODO transfer to lib/db.inc
|
||||
|
||||
function db_load_enum($table, $column, $lookup=false, $as_dict=false, $check_null=false) {
|
||||
// returns array of enum-values as defined in database
|
||||
@@ -840,247 +692,6 @@ function float_to_sql($var) {
|
||||
}
|
||||
}
|
||||
|
||||
// ========== FORM FUNCTIONS ==================================================
|
||||
|
||||
function form_get_action() {
|
||||
if (!isset($_POST['submit'])) {
|
||||
if (isset($_GET['f'])) {
|
||||
$submit = $_GET['f'];
|
||||
// strip parameters
|
||||
/* $pos = strpos($submit, '?');
|
||||
if ($pos > 2) {
|
||||
$submit = substr($submit, 0, $pos);
|
||||
} */
|
||||
} else {
|
||||
$submit = NULL;
|
||||
}
|
||||
} else {
|
||||
$submit = $_POST['submit'];
|
||||
}
|
||||
if (is_array($submit)) {
|
||||
$submit = key($submit);
|
||||
}
|
||||
return strtolower($submit);
|
||||
}
|
||||
|
||||
function form_create_numeric($fieldname, $label, $min=NULL, $max=NULL, $step=NULL, $value=NULL) {
|
||||
// TODO WIP
|
||||
// step = any float
|
||||
// step = 0.01 float
|
||||
// step = 1 integer
|
||||
echo '<div class="mb-3">', "\n";
|
||||
echo '<input type="number"';
|
||||
echo ">\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function form_create_text($fieldname, $label, $maxlen=NULL, $value=NULL) {
|
||||
// create generic text entry with assigned label
|
||||
// TODO required, errortext
|
||||
echo '<div class="mb-3">', "\n";
|
||||
echo '<label for="', $fieldname, '" class="form-label">', $label, "</label>\n";
|
||||
echo '<input type="text" class="form-control" id="', $fieldname, '" name="', $fieldname, '"';
|
||||
if ($maxlen !== NULL) {
|
||||
echo ' maxlength="', $maxlen, '"';
|
||||
}
|
||||
if ($value !== NULL) {
|
||||
echo ' value="', h($value), '"';
|
||||
}
|
||||
echo ">\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function form_create_textarea($fieldname, $label, $rows=3, $maxlen=NULL, $value=NULL) {
|
||||
echo '<div class="mb-3">', "\n";
|
||||
echo '<label for="', $fieldname, '" class="form-label">', $label, "</label>\n";
|
||||
echo '<textarea class="form-control" id="', $fieldname, '" name="', $fieldname, '"';
|
||||
echo ' rows="', $rows, '"';
|
||||
if ($maxlen !== NULL) {
|
||||
echo ' maxlength="', $maxlen, '"';
|
||||
}
|
||||
echo '>';
|
||||
if ($value !== NULL) {
|
||||
echo h($value);
|
||||
}
|
||||
echo "</textarea>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function form_create_color($fieldname, $label, $value=NULL) {
|
||||
// value has to be 6char hex
|
||||
echo '<div class="mb-3">', "\n";
|
||||
echo '<label for="', $fieldname, '" class="form-label">', $label, "</label>\n";
|
||||
echo '<input type="color" class="form-control" id="', $fieldname, '" name="', $fieldname, '"';
|
||||
if ($value !== NULL) {
|
||||
echo ' value="#', $value, '"';
|
||||
}
|
||||
echo ">\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function form_create_select($fieldname, $label, $optlist, $selval=NULL, $multiple=FALSE) {
|
||||
echo '<div class="mb-3">', "\n";
|
||||
echo '<label for="', $fieldname, '">', $label, "</label>\n";
|
||||
echo '<select class="form-select" name="', $fieldname,'" id="', $fieldname, $multiple ? ' multiple' : '', '">', "\n";
|
||||
foreach ($optlist as $k => $v) {
|
||||
echo '<option value="', $k, '"';
|
||||
if (isset($selval) and ($k == $selval)) {
|
||||
echo ' selected';
|
||||
}
|
||||
echo '>', $v, "</option>\n";
|
||||
}
|
||||
echo "</select>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function form_create_option($fieldname, $label) {
|
||||
// TBD
|
||||
}
|
||||
|
||||
function form_create_check($fieldname, $label, $checked) {
|
||||
// create single checkbox with assigned label
|
||||
echo '<div class="mb-3">', "\n";
|
||||
echo '<input type="checkbox" class="form-check-input" name="', $fieldname, '" id="', $fieldname, '"';
|
||||
if ($checked) {
|
||||
echo ' checked';
|
||||
}
|
||||
echo ">\n";
|
||||
echo '<label for="', $fieldname, '">', $label, "</label>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function form_create_checks($fieldname, $label, $optlist, $selected = []) {
|
||||
// create multiple combined checkboxes with title
|
||||
echo '<fieldset class="mb-3">', "\n";
|
||||
echo '<legend class="fs-6 mb-1 border-bottom pb-1">', $label, "</legend>\n";
|
||||
echo '<div class="d-flex flex-wrap gap-3">';
|
||||
foreach ($optlist as $k => $v) {
|
||||
echo '<div class="form-check">', "\n";
|
||||
$checked = in_array($k, $selected, true) ? ' checked' : '';
|
||||
echo '<label class="form-check-label">';
|
||||
echo '<input type="checkbox" class="form-check-input" name="', $fieldname, '[', $k, ']"', $checked, '>';
|
||||
echo $v;
|
||||
echo '</label>';
|
||||
echo "</div>\n";
|
||||
}
|
||||
echo "</div>\n";
|
||||
echo "</fieldset>\n";
|
||||
}
|
||||
|
||||
function form_add_button($script, $id=NULL, $idname='id') {
|
||||
echo '<div class="container-fluid px-0 my-3">', "\n";
|
||||
echo '<a href="', $script, '?f=add';
|
||||
if (isset($id)) {
|
||||
echo '&'.$idname.'='.$id;
|
||||
}
|
||||
echo '" class="btn btn-primary" role="button">', _('Add'), "</a>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function form_view_buttons($script, $id, $backlink=NULL) {
|
||||
echo '<div class="container-fluid px-0 my-3">', "\n";
|
||||
echo '<a href="', $script, '?f=edit&id=', $id, '" class="btn btn-primary" role="button">', _('Edit'), "</a>\n";
|
||||
echo ' ';
|
||||
echo '<a href="', $script, '?f=del&id=', $id, '" class="btn btn-secondary" role="button">', _('Delete'), "</a>\n";
|
||||
echo ' ';
|
||||
echo '<a href="', $backlink ?? $script, '" class="btn btn-secondary">', _('Back'), "</a>\n";
|
||||
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";
|
||||
echo '<a href="', $script, '?f=view&id=', $id, '" class="btn btn-secondary">', _('Back'), "</a>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function form_delete_buttons($script, $id, $token) {
|
||||
echo '<div class="container-fluid px-0 my-3">', "\n";
|
||||
echo '<form method="post" action="', $script, '">', "\n";
|
||||
echo '<input type="hidden" name="id" value="', $id .'">', "\n";
|
||||
echo '<input type="hidden" name="token" value="', $token, '">', "\n";
|
||||
echo '<button type="submit" name="submit[delete]" class="btn btn-primary">', _('Delete'), "</button>\n";
|
||||
echo '<a href="', $script, '?f=view&id=', $id, '" class="btn btn-secondary">', _('Back'), "</a>\n";
|
||||
echo "</form>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function form_tag_assignment($script, $id, $tags) {
|
||||
echo '<tr>';
|
||||
echo '<th>', _('Tags'), "</th>\n";
|
||||
echo '<td>', $tags, '</td>';
|
||||
echo "</tr>\n<tr>";
|
||||
echo '<th>', _('Tag assignment'), "</th>\n";
|
||||
echo '<td><form method="post" action="', $script, '">', "\n";
|
||||
echo '<div class="form-floating">';
|
||||
echo '<input type="hidden" name="id" value="', $id .'">', "\n";
|
||||
echo '<label>', _('(Separate by comma)'), '</label>', "\n";
|
||||
echo '<input type="text" maxlength="80" class="form-control" name="tagstring" value="', $tags, '">', "\n";
|
||||
echo '<input type="submit">', "\n";
|
||||
echo "</div></form></td></td>\n";
|
||||
echo "</tr>";
|
||||
}
|
||||
|
||||
function filter_create_text($fieldname, $label, $value, $size=NULL, $maxlength=NULL) {
|
||||
echo '<div class="d-flex flex-nowrap gap-2 align-items-start">', "\n";
|
||||
echo '<label for="', $fieldname,'">', $label,'</label>', "\n";
|
||||
echo '<input class="form-control" type="text" name="', $fieldname, '"';
|
||||
if (isset($size)) {
|
||||
echo ' size="', $size,'"';
|
||||
}
|
||||
if (isset($maxlength)) {
|
||||
echo ' maxlength="', $maxlength, '"';
|
||||
}
|
||||
echo ' value="', h($value), '">', "\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function filter_create_select($fieldname, $label, $optlist, $selval=NULL, $multiple=FALSE) {
|
||||
// - Wenn multiple gesetzt ist, muß selval ein array sein
|
||||
// ansonsten ein einfacher String
|
||||
/* if ($multiple) {
|
||||
if (!is_array($selval)) {
|
||||
}
|
||||
} */
|
||||
echo '<div class="d-flex flex-nowrap gap-2 align-items-start">', "\n";
|
||||
echo '<label for="', $fieldname,'">', $label,'</label>', "\n";
|
||||
echo '<select class="form-select" id="', $fieldname, '" name="', $fieldname, '"', $multiple ? ' multiple' : '', ">\n";
|
||||
foreach ($optlist as $k => $v) {
|
||||
echo '<option value="', $k, '"';
|
||||
if ($k == $selval) {
|
||||
echo ' selected';
|
||||
}
|
||||
echo '>', $v, '</option>', "\n";
|
||||
}
|
||||
echo "</select>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function filter_create_checks($fieldname, $label, $optlist, $selected = []) {
|
||||
// TODO WIP
|
||||
echo '<fieldset class="mb-3">', "\n";
|
||||
echo '<legend class="fs-6 mb-1 border-bottom pb-1">', $label, "</legend>\n";
|
||||
echo '<div class="d-flex flex-wrap gap-3">', "\n";
|
||||
foreach ($optlist as $k => $v) {
|
||||
echo '<div class="form-check">', "\n";
|
||||
$checked = in_array($k, $selected, true) ? ' checked' : '';
|
||||
echo '<label class="form-check-label">', "\n";
|
||||
echo '<input type="checkbox" class="form-check-input" name="', $fieldname, '[', $k, ']"', $checked, ">\n";
|
||||
echo $v, "\n";
|
||||
echo "</label>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
echo "</div>\n";
|
||||
echo "</fieldset>\n";
|
||||
}
|
||||
|
||||
// ========== FORMAT FUNCTIONS ================================================
|
||||
|
||||
function format_float($val, $decimals = 2, $suffix = '') {
|
||||
@@ -1131,6 +742,9 @@ function format_datetime($datetime, $seconds=false) {
|
||||
}
|
||||
|
||||
function format_color($color) {
|
||||
if (empty($color)) {
|
||||
return '';
|
||||
}
|
||||
$colstr = '<span style="';
|
||||
$style = "padding:2px 4px;border-radius:4px;background-color:#".$color;
|
||||
if (get_color_brightness($color) < 0.4) {
|
||||
@@ -1252,6 +866,71 @@ function pgettext($context, $msgid) {
|
||||
}
|
||||
}
|
||||
|
||||
function get_enum($enum) {
|
||||
// translate and beautify enums
|
||||
$lookup = array(
|
||||
'NULL' => _('n/a'),
|
||||
'active' => _('Active'),
|
||||
'bad' => _('Bad'),
|
||||
'box' => _('Box'),
|
||||
'cable' => _('Cable'),
|
||||
'cat' => _('Catamaran'),
|
||||
'completed' => _('Completed'),
|
||||
'closed' => _('Closed'),
|
||||
'company' => _('Company'),
|
||||
'day' => _('Day'),
|
||||
'defect' => _('Defect'),
|
||||
'deleted' => _('Deleted'),
|
||||
'done' => _('Done'),
|
||||
'drawing' => _('Drawing'),
|
||||
'equipment' => _('Equipment'),
|
||||
'estimated' => _('Estimated'),
|
||||
'excellent' => _('Excellent'),
|
||||
'fair' => _('Fair'),
|
||||
'finished' => _('Finished'),
|
||||
'fixed' => _('Fixed'),
|
||||
'fuse' => _('Fuse'),
|
||||
'generic' => _('Generic'),
|
||||
'good' => _('Good'),
|
||||
'high' => _('High'),
|
||||
'historic' => _('Historic'),
|
||||
'invoice' => _('Invoice'),
|
||||
'locked' => _('Locked'),
|
||||
'low' => _('Low'),
|
||||
'manual' => _('Manual'),
|
||||
'medium' => _('Medium'),
|
||||
'missed' => _('Missed'),
|
||||
'mono' => _('Monohull'),
|
||||
'month' => _('Month'),
|
||||
'new' => _('New'),
|
||||
'none' => _('None'),
|
||||
'normal' => _('Normal'),
|
||||
'ongoing' => _('Ongoing'),
|
||||
'open' => _('Open'),
|
||||
'ordered' => _('Ordered'),
|
||||
'paused' => _('Paused'),
|
||||
'pending' => _('Pending'),
|
||||
'picture' => _('Picture'),
|
||||
'plan' => _('Planned'),
|
||||
'precise' => _('Precise'),
|
||||
'project' => _('Project'),
|
||||
'quarter' => _('Quarter'),
|
||||
'removed' => _('Removed'),
|
||||
'repairable' => _('Repairable'),
|
||||
'rough' => _('Rough'),
|
||||
'skipped' => _('Skipped'),
|
||||
'storage' => _('Storage'),
|
||||
'task' => _('Task'),
|
||||
'tri' => _('Trimaran'),
|
||||
'unknown' => _('Unknown'),
|
||||
'user' => _('User'),
|
||||
'vessel' => _('Vessel'),
|
||||
'waiting' => _('Waiting'),
|
||||
'week' => _('Week'),
|
||||
);
|
||||
return $lookup[$enum] ?? $enum;
|
||||
}
|
||||
|
||||
function get_color_brightness($color, $default=0.5) {
|
||||
// returns a value between 0 and 1
|
||||
// color is a 6 char hex string
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
require 'lib/form.inc';
|
||||
require 'lib/svg.inc';
|
||||
|
||||
$pagetitle = _('Start');
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
require 'lib/form.inc';
|
||||
|
||||
$pagetitle=_('Inventory');
|
||||
|
||||
|
||||
@@ -10,6 +10,90 @@
|
||||
|
||||
// ========== GENERIC FUNCTIONS ===============================================
|
||||
|
||||
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);
|
||||
$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 false;
|
||||
}
|
||||
return $pdo->LastInsertId();
|
||||
}
|
||||
|
||||
function db_exec_update($table, $params, $pk) {
|
||||
// primary key can be a single field name or multiple fields: $pk is an array
|
||||
global $pdo;
|
||||
global $g_error;
|
||||
// remove primary key fields from list of fields to update
|
||||
if (is_array($pk)) {
|
||||
if (count($pk) == 1) {
|
||||
$pk = $pk[0];
|
||||
$fields = $params;
|
||||
unset($fields[':'.$pk]);
|
||||
$where = "$pk=:$pk";
|
||||
} else {
|
||||
$pkparams = array_map(fn($value) => ':' . $value, $pk);
|
||||
$fields = array_diff_key($params, array_flip($pkparams));
|
||||
$where = join(' AND ', array_map(fn($s) => "$s=:$s", $pk));
|
||||
}
|
||||
} else {
|
||||
$fields = $params;
|
||||
unset($fields[':'.$pk]);
|
||||
$where = "$pk=:$pk";
|
||||
}
|
||||
$fieldlist = join(', ', array_map(fn($s) => ltrim($s, ':') . '=' . $s, array_keys($fields)));
|
||||
$sql = "UPDATE $table SET $fieldlist WHERE $where";
|
||||
$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_exec_delete($table, $condition, $params) {
|
||||
// WIP untested!
|
||||
// condition contains the where part of the sql statement
|
||||
// params are values for placeholders in condition
|
||||
// returns the number of deleted records
|
||||
global $pdo;
|
||||
global $g_error;
|
||||
// convert params to array if single value is given
|
||||
if (!is_array($params)) {
|
||||
$params = [$params];
|
||||
}
|
||||
$sql = "DELETE FROM $table";
|
||||
if (!empty($condition)) {
|
||||
$sql .= ' WHERE ' . $condition;
|
||||
}
|
||||
$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 -1;
|
||||
}
|
||||
return $sth->rowCount();
|
||||
}
|
||||
|
||||
function db_get_setting($sno, $userid, $autocreate=false, $default=NULL) {
|
||||
global $pdo;
|
||||
global $g_error;
|
||||
|
||||
@@ -0,0 +1,256 @@
|
||||
<?php
|
||||
/******************************************************************************
|
||||
* YMS - Yacht Management Software
|
||||
* Copyright (C) 2024-2026 Thomas Hooge
|
||||
*
|
||||
* SPDX-License-Identifier: WTFPL
|
||||
******************************************************************************
|
||||
|
||||
*/
|
||||
|
||||
// ========== FORM FUNCTIONS ==================================================
|
||||
|
||||
function form_get_action() {
|
||||
if (!isset($_POST['submit'])) {
|
||||
if (isset($_GET['f'])) {
|
||||
$submit = $_GET['f'];
|
||||
// strip parameters
|
||||
/* $pos = strpos($submit, '?');
|
||||
if ($pos > 2) {
|
||||
$submit = substr($submit, 0, $pos);
|
||||
} */
|
||||
} else {
|
||||
$submit = NULL;
|
||||
}
|
||||
} else {
|
||||
$submit = $_POST['submit'];
|
||||
}
|
||||
if (is_array($submit)) {
|
||||
$submit = key($submit);
|
||||
}
|
||||
return strtolower($submit);
|
||||
}
|
||||
|
||||
function form_tag_assignment($script, $id, $tags) {
|
||||
echo '<tr>';
|
||||
echo '<th>', _('Tags'), "</th>\n";
|
||||
echo '<td>', $tags, '</td>';
|
||||
echo "</tr>\n<tr>";
|
||||
echo '<th>', _('Tag assignment'), "</th>\n";
|
||||
echo '<td><form method="post" action="', $script, '">', "\n";
|
||||
echo '<div class="form-floating">';
|
||||
echo '<input type="hidden" name="id" value="', $id .'">', "\n";
|
||||
echo '<label>', _('(Separate by comma)'), '</label>', "\n";
|
||||
echo '<input type="text" maxlength="80" class="form-control" name="tagstring" value="', $tags, '">', "\n";
|
||||
echo '<input type="submit">', "\n";
|
||||
echo "</div></form></td></td>\n";
|
||||
echo "</tr>";
|
||||
}
|
||||
|
||||
// ========== FORM FIELDS =====================================================
|
||||
|
||||
function form_create_numeric($fieldname, $label, $min=NULL, $max=NULL, $step=NULL, $value=NULL) {
|
||||
// TODO WIP
|
||||
// step = any float
|
||||
// step = 0.01 float
|
||||
// step = 1 integer
|
||||
echo '<div class="mb-3">', "\n";
|
||||
echo '<input type="number"';
|
||||
echo ">\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function form_create_text($fieldname, $label, $maxlen=NULL, $value=NULL) {
|
||||
// create generic text entry with assigned label
|
||||
// TODO required, errortext
|
||||
echo '<div class="mb-3">', "\n";
|
||||
echo '<label for="', $fieldname, '" class="form-label">', $label, "</label>\n";
|
||||
echo '<input type="text" class="form-control" id="', $fieldname, '" name="', $fieldname, '"';
|
||||
if ($maxlen !== NULL) {
|
||||
echo ' maxlength="', $maxlen, '"';
|
||||
}
|
||||
if ($value !== NULL) {
|
||||
echo ' value="', h($value), '"';
|
||||
}
|
||||
echo ">\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function form_create_textarea($fieldname, $label, $rows=3, $maxlen=NULL, $value=NULL) {
|
||||
echo '<div class="mb-3">', "\n";
|
||||
echo '<label for="', $fieldname, '" class="form-label">', $label, "</label>\n";
|
||||
echo '<textarea class="form-control" id="', $fieldname, '" name="', $fieldname, '"';
|
||||
echo ' rows="', $rows, '"';
|
||||
if ($maxlen !== NULL) {
|
||||
echo ' maxlength="', $maxlen, '"';
|
||||
}
|
||||
echo '>';
|
||||
if ($value !== NULL) {
|
||||
echo h($value);
|
||||
}
|
||||
echo "</textarea>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function form_create_color($fieldname, $label, $value=NULL) {
|
||||
// value has to be 6char hex
|
||||
echo '<div class="mb-3">', "\n";
|
||||
echo '<label for="', $fieldname, '" class="form-label">', $label, "</label>\n";
|
||||
echo '<input type="color" class="form-control" id="', $fieldname, '" name="', $fieldname, '"';
|
||||
if ($value !== NULL) {
|
||||
echo ' value="#', $value, '"';
|
||||
}
|
||||
echo ">\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function form_create_select($fieldname, $label, $optlist, $selval=NULL, $multiple=FALSE) {
|
||||
echo '<div class="mb-3">', "\n";
|
||||
echo '<label for="', $fieldname, '">', $label, "</label>\n";
|
||||
echo '<select class="form-select" name="', $fieldname,'" id="', $fieldname, $multiple ? ' multiple' : '', '">', "\n";
|
||||
foreach ($optlist as $k => $v) {
|
||||
echo '<option value="', $k, '"';
|
||||
if (isset($selval) and ($k == $selval)) {
|
||||
echo ' selected';
|
||||
}
|
||||
echo '>', $v, "</option>\n";
|
||||
}
|
||||
echo "</select>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function form_create_option($fieldname, $label) {
|
||||
// TBD
|
||||
}
|
||||
|
||||
function form_create_check($fieldname, $label, $checked) {
|
||||
// create single checkbox with assigned label
|
||||
echo '<div class="mb-3">', "\n";
|
||||
echo '<input type="checkbox" class="form-check-input" name="', $fieldname, '" id="', $fieldname, '"';
|
||||
if ($checked) {
|
||||
echo ' checked';
|
||||
}
|
||||
echo ">\n";
|
||||
echo '<label for="', $fieldname, '">', $label, "</label>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function form_create_checks($fieldname, $label, $optlist, $selected = []) {
|
||||
// create multiple combined checkboxes with title
|
||||
echo '<fieldset class="mb-3">', "\n";
|
||||
echo '<legend class="fs-6 mb-1 border-bottom pb-1">', $label, "</legend>\n";
|
||||
echo '<div class="d-flex flex-wrap gap-3">';
|
||||
foreach ($optlist as $k => $v) {
|
||||
echo '<div class="form-check">', "\n";
|
||||
$checked = in_array($k, $selected, true) ? ' checked' : '';
|
||||
echo '<label class="form-check-label">';
|
||||
echo '<input type="checkbox" class="form-check-input" name="', $fieldname, '[', $k, ']"', $checked, '>';
|
||||
echo $v;
|
||||
echo '</label>';
|
||||
echo "</div>\n";
|
||||
}
|
||||
echo "</div>\n";
|
||||
echo "</fieldset>\n";
|
||||
}
|
||||
|
||||
// ========== FORM BUTTONS ====================================================
|
||||
|
||||
function form_add_button($script, $id=NULL, $idname='id') {
|
||||
echo '<div class="container-fluid px-0 my-3">', "\n";
|
||||
echo '<a href="', $script, '?f=add';
|
||||
if (isset($id)) {
|
||||
echo '&'.$idname.'='.$id;
|
||||
}
|
||||
echo '" class="btn btn-primary" role="button">', _('Add'), "</a>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function form_view_buttons($script, $id, $backlink=NULL) {
|
||||
echo '<div class="container-fluid px-0 my-3">', "\n";
|
||||
echo '<a href="', $script, '?f=edit&id=', $id, '" class="btn btn-primary" role="button">', _('Edit'), "</a>\n";
|
||||
echo ' ';
|
||||
echo '<a href="', $script, '?f=del&id=', $id, '" class="btn btn-secondary" role="button">', _('Delete'), "</a>\n";
|
||||
echo ' ';
|
||||
echo '<a href="', $backlink ?? $script, '" class="btn btn-secondary">', _('Back'), "</a>\n";
|
||||
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";
|
||||
echo '<a href="', $script, '?f=view&id=', $id, '" class="btn btn-secondary">', _('Back'), "</a>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function form_delete_buttons($script, $id, $token) {
|
||||
echo '<div class="container-fluid px-0 my-3">', "\n";
|
||||
echo '<form method="post" action="', $script, '">', "\n";
|
||||
echo '<input type="hidden" name="id" value="', $id .'">', "\n";
|
||||
echo '<input type="hidden" name="token" value="', $token, '">', "\n";
|
||||
echo '<button type="submit" name="submit[delete]" class="btn btn-primary">', _('Delete'), "</button>\n";
|
||||
echo '<a href="', $script, '?f=view&id=', $id, '" class="btn btn-secondary">', _('Back'), "</a>\n";
|
||||
echo "</form>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
// ========== FILTER FIELDS ===================================================
|
||||
|
||||
function filter_create_text($fieldname, $label, $value, $size=NULL, $maxlength=NULL) {
|
||||
echo '<div class="d-flex flex-nowrap gap-2 align-items-start">', "\n";
|
||||
echo '<label for="', $fieldname,'">', $label,'</label>', "\n";
|
||||
echo '<input class="form-control" type="text" name="', $fieldname, '"';
|
||||
if (isset($size)) {
|
||||
echo ' size="', $size,'"';
|
||||
}
|
||||
if (isset($maxlength)) {
|
||||
echo ' maxlength="', $maxlength, '"';
|
||||
}
|
||||
echo ' value="', h($value), '">', "\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function filter_create_select($fieldname, $label, $optlist, $selval=NULL, $multiple=FALSE) {
|
||||
// - Wenn multiple gesetzt ist, muß selval ein array sein
|
||||
// ansonsten ein einfacher String
|
||||
/* if ($multiple) {
|
||||
if (!is_array($selval)) {
|
||||
}
|
||||
} */
|
||||
echo '<div class="d-flex flex-nowrap gap-2 align-items-start">', "\n";
|
||||
echo '<label for="', $fieldname,'">', $label,'</label>', "\n";
|
||||
echo '<select class="form-select" id="', $fieldname, '" name="', $fieldname, '"', $multiple ? ' multiple' : '', ">\n";
|
||||
foreach ($optlist as $k => $v) {
|
||||
echo '<option value="', $k, '"';
|
||||
if ($k == $selval) {
|
||||
echo ' selected';
|
||||
}
|
||||
echo '>', $v, '</option>', "\n";
|
||||
}
|
||||
echo "</select>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
function filter_create_checks($fieldname, $label, $optlist, $selected = []) {
|
||||
// TODO WIP
|
||||
echo '<fieldset class="mb-3">', "\n";
|
||||
echo '<legend class="fs-6 mb-1 border-bottom pb-1">', $label, "</legend>\n";
|
||||
echo '<div class="d-flex flex-wrap gap-3">', "\n";
|
||||
foreach ($optlist as $k => $v) {
|
||||
echo '<div class="form-check">', "\n";
|
||||
$checked = in_array($k, $selected, true) ? ' checked' : '';
|
||||
echo '<label class="form-check-label">', "\n";
|
||||
echo '<input type="checkbox" class="form-check-input" name="', $fieldname, '[', $k, ']"', $checked, ">\n";
|
||||
echo $v, "\n";
|
||||
echo "</label>\n";
|
||||
echo "</div>\n";
|
||||
}
|
||||
echo "</div>\n";
|
||||
echo "</fieldset>\n";
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
require 'lib/form.inc';
|
||||
|
||||
$pagetitle = _('Maintenance');
|
||||
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ require 'header.php';
|
||||
|
||||
<p class="p-3 mb-3 bg-info-subtle border border-info-subtle rounded">
|
||||
<i class="bi bi-info-circle-fill me-2"></i>
|
||||
Hinweis: Es handelt sich hier um eine Vorschau (Version <?=$g_version?>)!<br>
|
||||
Hinweis: Es handelt sich hier um eine frühe Version (v<?=$g_version?>)!<br>
|
||||
Einige Funktionen sind noch nicht oder nicht vollständig implementiert.
|
||||
Rückmeldungen sind immer willkommen!</p>
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
require 'lib/form.inc';
|
||||
|
||||
// TODO move to somewhere else
|
||||
function format_vals($n, $v1, $v2, $v3) {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
require 'lib/form.inc';
|
||||
|
||||
$pagetitle = _('Note');
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
require 'lib/form.inc';
|
||||
|
||||
$pagetitle = _('Projects');
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
require 'lib/form.inc';
|
||||
|
||||
$pagetitle=_('Provisions');
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
require 'lib/form.inc';
|
||||
|
||||
$pagetitle = _('Search');
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
require 'lib/form.inc';
|
||||
|
||||
$pagetitle = _('Settings');
|
||||
|
||||
|
||||
+5
-4
@@ -9,6 +9,7 @@
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
require 'lib/form.inc';
|
||||
|
||||
$pagetitle = _('Storage');
|
||||
|
||||
@@ -150,8 +151,8 @@ foreach ($res as $row) {
|
||||
echo "</tr>\n";
|
||||
}
|
||||
// Table summary
|
||||
$numrows = count($res);
|
||||
table_rec_summary($i, $numrows, $numrows, 5);
|
||||
// $numrows = count($res);
|
||||
// table_rec_summary($i, $numrows, $numrows, 5);
|
||||
echo "</table>\n";
|
||||
|
||||
form_add_button($g_scriptname);
|
||||
@@ -191,8 +192,8 @@ foreach ($res as $row) {
|
||||
echo "</tr>\n";
|
||||
}
|
||||
// Table summary
|
||||
$numrows = count($res);
|
||||
table_rec_summary($i, $numrows, $numrows, 5);
|
||||
// $numrows = count($res);
|
||||
// table_rec_summary($i, $numrows, $numrows, 5);
|
||||
echo "</table>\n";
|
||||
|
||||
form_add_button('box.php');
|
||||
|
||||
+3
-1
@@ -9,6 +9,7 @@
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
require 'lib/form.inc';
|
||||
|
||||
$pagetitle = _('Tags');
|
||||
|
||||
@@ -141,7 +142,8 @@ foreach ($res as $row) {
|
||||
echo "</tr>\n";
|
||||
}
|
||||
// Table summary
|
||||
table_rec_summary($i0, $i, $numrows, 6);
|
||||
$numrows = count($res);
|
||||
table_rec_summary(1, $i, $numrows, 6);
|
||||
echo "</table>\n";
|
||||
|
||||
form_add_button($g_scriptname);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
require 'globals.inc';
|
||||
require 'lib/db.inc';
|
||||
require 'lib/gpc.inc';
|
||||
require 'lib/form.inc';
|
||||
|
||||
$pagetitle = _('Task');
|
||||
|
||||
|
||||
Reference in new issue
Block a user