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
+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);
|
||||
|
||||
Reference in new issue
Block a user