Webgui: fix and improve cables and fuses

This commit is contained in:
2026-08-29 14:27:16 +02:00
parent ac4b994398
commit 125a7bba56
4 changed files with 37 additions and 16 deletions
+2 -1
View File
@@ -67,7 +67,8 @@ INSERT INTO dropdown (ddid, ddval, ddtext) VALUES
(0, 8, 'Einheiten'), (0, 8, 'Einheiten'),
(0, 9, 'Kistentypen'), (0, 9, 'Kistentypen'),
(0, 10, 'Sicherungsblöcke'), -- fuse locations (0, 10, 'Sicherungsblöcke'), -- fuse locations
(0, 11, 'Kabeltypen'); (0, 11, 'Kabeltypen'),
(0, 12, 'Technische Kabel-Bezeichnung');
INSERT INTO dropdown (ddid, ddval, ddtext, flags) VALUES INSERT INTO dropdown (ddid, ddval, ddtext, flags) VALUES
(2, 1, 'Lieferant', 'fixed'), (2, 1, 'Lieferant', 'fixed'),
+12 -8
View File
@@ -14,6 +14,7 @@ $pagetitle = _('Cables');
$id = gpc_get_int($_REQUEST, 'id', 0); $id = gpc_get_int($_REQUEST, 'id', 0);
$opt_cabletype = db_get_options(11); $opt_cabletype = db_get_options(11);
$opt_techname = db_get_options(12);
$opt_cablecond = db_load_enum('cable', 'cablecond', true, true); $opt_cablecond = db_load_enum('cable', 'cablecond', true, true);
// ========== ACTIONS START =================================================== // ========== ACTIONS START ===================================================
@@ -52,6 +53,7 @@ switch ($submit = form_get_action()) {
$p[':cableid'] = $id; $p[':cableid'] = $id;
$p[':cablename'] = gpc_get_string($_POST, 'cablename'); $p[':cablename'] = gpc_get_string($_POST, 'cablename');
$p[':cabletype'] = gpc_get_int($_POST, 'cabletype'); $p[':cabletype'] = gpc_get_int($_POST, 'cabletype');
$p[':techname'] = gpc_get_int($_POST, 'techname');
$p[':length'] = gpc_get_float($_POST, 'length'); $p[':length'] = gpc_get_float($_POST, 'length');
$p[':conductors'] = gpc_get_int($_POST, 'conductors'); $p[':conductors'] = gpc_get_int($_POST, 'conductors');
$p[':xsection'] = gpc_get_float($_POST, 'xsection'); $p[':xsection'] = gpc_get_float($_POST, 'xsection');
@@ -146,14 +148,14 @@ foreach ($res as $row) {
echo "<td>", $row['length'], "m</td>\n"; echo "<td>", $row['length'], "m</td>\n";
echo "<td>", $row['xsection'], "mm²</td>\n"; echo "<td>", $row['xsection'], "mm²</td>\n";
echo "<td>", format_color($row['color']), "</td>\n"; echo "<td>", format_color($row['color']), "</td>\n";
echo "<td>", $row['condition'], "</td>\n"; echo "<td>", get_enum($row['cablecond']), "</td>\n";
echo "<td>"; echo "<td>";
echo '<a title="', _('Edit'), '" href="', $g_scriptname, '?f=edit&id=', $row['cableid'], '"><i class="bi-pencil"></i></a>', "\n"; echo '<a title="', _('Edit'), '" href="', $g_scriptname, '?f=edit&id=', $row['cableid'], '"><i class="bi-pencil"></i></a>', "\n";
echo "</td>\n"; echo "</td>\n";
echo "</tr>\n"; echo "</tr>\n";
} }
// Table summary // Table summary
table_rec_summary($i0, $i, $numrows, 6); table_rec_summary(1, $i, $i, 9);
echo "</table>\n"; echo "</table>\n";
form_add_button($g_scriptname); form_add_button($g_scriptname);
@@ -177,8 +179,8 @@ echo '<h2>', _('Add Cable'), "</h2>\n";
form_create_select('cabletype', _('Type'), $g_opt_none + $opt_cabletype); form_create_select('cabletype', _('Type'), $g_opt_none + $opt_cabletype);
?> ?>
<div class="mb-3"> <div class="mb-3">
<label for="note" class="form-label"><?=_('Conductors')?></label> <label for="note" class="form-label"><?=_('Number of conductors')?></label>
<input type="text" class="form-control" id="conductors" name="conductors"> <input type="number" class="form-control" id="conductors" name="conductors">
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="note" class="form-label"><?=_('Cross section, mm²')?></label> <label for="note" class="form-label"><?=_('Cross section, mm²')?></label>
@@ -191,7 +193,7 @@ echo "</form>\n";
elseif ($action == ACT_VIEW): elseif ($action == ACT_VIEW):
// ========== VARIANT: view single record ===================================== // ========== VARIANT: view single record =====================================
$sql = "SELECT cablename, cabletype, length, conductors, diameter, xsection," $sql = "SELECT cablename, cabletype, techname, length, conductors, diameter, xsection,"
. " weight, color, supplier, manufacturer, cablecond, remarks " . " weight, color, supplier, manufacturer, cablecond, remarks "
. "FROM cable " . "FROM cable "
. "WHERE cableid=?"; . "WHERE cableid=?";
@@ -204,6 +206,7 @@ echo '<h2>', _('View cable'), "</h2>\n";
echo '<table class="table">', "\n"; echo '<table class="table">', "\n";
echo '<tr><th style="width:20%">', _('Cable'),"</th><td>", $cable->cablename, "</td></tr>\n"; echo '<tr><th style="width:20%">', _('Cable'),"</th><td>", $cable->cablename, "</td></tr>\n";
echo '<tr><th>', _('Type'),"</th><td>", $opt_cabletype[$cable->cabletype], "</td></tr>\n"; echo '<tr><th>', _('Type'),"</th><td>", $opt_cabletype[$cable->cabletype], "</td></tr>\n";
echo '<tr><th>', _('Techname'),"</th><td>", $opt_techname[$cable->techname], "</td></tr>\n";
echo '<tr><th>', _('Length'),"</th><td>", format_float($cable->length, 1, 'm'), "</td></tr>\n"; echo '<tr><th>', _('Length'),"</th><td>", format_float($cable->length, 1, 'm'), "</td></tr>\n";
echo '<tr><th>', _('Conductors'),"</th><td>", $cable->conductors, "</td></tr>\n"; echo '<tr><th>', _('Conductors'),"</th><td>", $cable->conductors, "</td></tr>\n";
echo '<tr><th>', _('Diameter'),"</th><td>", format_float($cable->diameter, 1, 'mm'), "</td></tr>\n"; echo '<tr><th>', _('Diameter'),"</th><td>", format_float($cable->diameter, 1, 'mm'), "</td></tr>\n";
@@ -219,7 +222,7 @@ form_view_buttons($g_scriptname, $id);
elseif ($action == ACT_EDIT): elseif ($action == ACT_EDIT):
// ========== VARIANT: edit single record ===================================== // ========== VARIANT: edit single record =====================================
$sql = "SELECT cablename, cabletype, length, conductors, diameter, xsection," $sql = "SELECT cablename, cabletype, techname, length, conductors, diameter, xsection,"
. " weight, color, supplier, manufacturer, cablecond, remarks " . " weight, color, supplier, manufacturer, cablecond, remarks "
. "FROM cable " . "FROM cable "
. "WHERE cableid=?"; . "WHERE cableid=?";
@@ -237,14 +240,15 @@ echo '<h2>', _('Edit cable'), "</h2>\n";
</div> </div>
<?php <?php
form_create_select('cabletype', _('Type'), $g_opt_none + $opt_cabletype, $cable->cabletype); form_create_select('cabletype', _('Type'), $g_opt_none + $opt_cabletype, $cable->cabletype);
form_create_select('techname', _('Techname'), $g_opt_none + $opt_techname, $cable->techname);
?> ?>
<div class="mb-3"> <div class="mb-3">
<label for="note" class="form-label"><?=_('Length, m')?></label> <label for="note" class="form-label"><?=_('Length, m')?></label>
<input type="text" class="form-control" id="length" name="length" value="<?=format_float($cable->length, 1);?>"> <input type="text" class="form-control" id="length" name="length" value="<?=format_float($cable->length, 1);?>">
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="note" class="form-label"><?=_('Conductors')?></label> <label for="note" class="form-label"><?=_('Number of conductors')?></label>
<input type="text" class="form-control" id="conductors" name="conductors" value="<?=$cable->conductors;?>"> <input type="number" class="form-control" id="conductors" name="conductors" value="<?=$cable->conductors;?>">
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="note" class="form-label"><?=_('Diameter, mm')?></label> <label for="note" class="form-label"><?=_('Diameter, mm')?></label>
+21 -6
View File
@@ -57,11 +57,10 @@ switch ($submit = form_get_action()) {
$p[':current'] = gpc_get_float($_POST, 'current'); $p[':current'] = gpc_get_float($_POST, 'current');
$p[':cableid'] = gpc_get_int($_POST, 'cableid'); $p[':cableid'] = gpc_get_int($_POST, 'cableid');
$p[':eid'] = gpc_get_int($_POST, 'id'); $p[':eid'] = gpc_get_int($_POST, 'id');
$p[':weight'] = min(gpc_get_float($_POST, 'weight'), 9.99); // limit max value
$p[':location'] = gpc_get_int($_POST, 'location'); $p[':location'] = gpc_get_int($_POST, 'location');
$p[':description'] = gpc_get_string($_POST, 'description'); $p[':description'] = gpc_get_string($_POST, 'description');
$p[':remarks'] = gpc_get_string($_POST, 'remarks'); $p[':remarks'] = gpc_get_string($_POST, 'remarks');
db_exec_update('tag', $p, 'tagid'); db_exec_update('fuse', $p, 'fuseid');
$action = ACT_VIEW; $action = ACT_VIEW;
break; break;
@@ -219,9 +218,9 @@ elseif ($action == ACT_VIEW):
$sql = "SELECT fnumber, ftype, current, cableid, eid, location, description, remarks " $sql = "SELECT fnumber, ftype, current, cableid, eid, location, description, remarks "
. "FROM fuse " . "FROM fuse "
. "WHERE fuseid=?"; . "WHERE vid=? AND fuseid=?";
$sth = $pdo->prepare($sql); $sth = $pdo->prepare($sql);
$sth->execute([$id]); $sth->execute([$user->vid, $id]);
$fuse = $sth->fetch(PDO::FETCH_OBJ); $fuse = $sth->fetch(PDO::FETCH_OBJ);
echo '<h2>', _('View fuse'), "</h2>\n"; echo '<h2>', _('View fuse'), "</h2>\n";
@@ -242,7 +241,10 @@ form_view_buttons($g_scriptname, $id);
elseif ($action == ACT_EDIT): elseif ($action == ACT_EDIT):
// ========== VARIANT: edit single record ===================================== // ========== VARIANT: edit single record =====================================
$sql = "SELECT fnumber, description " $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 "
. "FROM fuse " . "FROM fuse "
. "WHERE fuseid=?"; . "WHERE fuseid=?";
$sth = $pdo->prepare($sql); $sth = $pdo->prepare($sql);
@@ -254,13 +256,26 @@ echo '<h2>', _('Edit fuse'), "</h2>\n";
<form method="post" action="<?=$g_scriptname?>"> <form method="post" action="<?=$g_scriptname?>">
<input type="hidden" name="id" value="<?=$id?>"> <input type="hidden" name="id" value="<?=$id?>">
<div class="mb-3"> <div class="mb-3">
<label for="mname" class="form-label"><?=pgettext('number', 'Number')?></label> <label for="fnumber" class="form-label"><?=_('Fuse number')?></label>
<input type="text" class="form-control" id="fnumber" name="fnumber" value="<?=$fuse->fnumber ?>"> <input type="text" class="form-control" id="fnumber" name="fnumber" value="<?=$fuse->fnumber ?>">
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="note" class="form-label"><?=_('Description')?></label> <label for="note" class="form-label"><?=_('Description')?></label>
<input type="text" class="form-control" id="description" name="description" value="<?=h($fuse->description)?>"> <input type="text" class="form-control" id="description" name="description" value="<?=h($fuse->description)?>">
</div> </div>
<div class="mb-3">
<label for="current" class="form-label"><?=_('Current')?></label>
<input type="text" class="form-control" id="current" name="current" value="<?=format_float($fuse->current) ?>">
</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);
form_create_select('eid', _('Equipment'), $g_opt_none + $opt_equipment, $fuse->eid);
?>
<div class="mb-3">
<label for="remarks" class="form-label"><?=_('Remarks')?></label>
<textarea class="form-control" id="remarks" name="remarks" rows="3"><?=h($fuse->remarks, br:true)?></textarea>
</div>
<?php <?php
form_edit_buttons($g_scriptname, $id); form_edit_buttons($g_scriptname, $id);
+2 -1
View File
@@ -945,7 +945,8 @@ function db_get_opt_cable($vid, $default=NULL) {
$list = array(); $list = array();
} }
$sql = "SELECT cableid, cablename FROM cable WHERE vid=? ORDER BY cablename"; $sql = "SELECT cableid, cablename FROM cable WHERE vid=? ORDER BY cablename";
$sth = $pdo->query($sql); $sth = $pdo->prepare($sql);
$sth->execute([$vid]);
foreach ($sth->fetchAll(PDO::FETCH_NUM) as $row) { foreach ($sth->fetchAll(PDO::FETCH_NUM) as $row) {
$list[$row[0]] = h($row[1]); $list[$row[0]] = h($row[1]);
} }