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[':description'] = gpc_get_string($_POST, 'description'); $id = db_exec_insert('fuse', $p); $action = ACT_VIEW; break; case 'update': $p[':fuseid'] = $id; $p[':fnumber'] = gpc_get_string($_POST, 'fuseid'); $p[':current'] = gpc_get_float($_POST, 'current'); $p[':cableid'] = gpc_get_int($_POST, 'cableid'); $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[':description'] = gpc_get_string($_POST, 'description'); $p[':remarks'] = gpc_get_string($_POST, 'remarks'); db_exec_update('tag', $p, 'tagid'); $action = ACT_VIEW; break; case 'delete': // Security token needed! if (gpc_get_string($_POST, 'token', 16) != $_SESSION['token']) { $g_error->Add(_('Delete prohibited, invalid security token!')); $action = ACT_VIEW; break; } // tagref have to be empty // TODO $action = ACT_DEFAULT; break; default: $g_error->Add(sprintf(_('Unknown function!'), $submit)); $valid = FALSE; } // ========== ACTIONS END ===================================================== require 'header.php'; // ========== PAGE CONTENT ==================================================== if ($action == ACT_DEFAULT): // ========== VARIANT: default behavior ======================================= // lookup tables $opt_ftype_short = db_get_options(7, '', true); // load filter from db $flt = db_get_filter($user->id, 212); $w = array('vid=:vid'); $p = array(':vid' => $user->vid); if ($flt->location == -1) { $w[] = 'location IS NULL'; } elseif ($flt->location > 0) { $w[] = 'location=:location'; $p[':location'] = $flt->location; } if (strlen($flt->txt) > 1) { $w[] = 'description LIKE :txt'; $p[':txt'] = '%'.$flt->txt.'%'; } $where = join(' AND ', $w); $order = ' ORDER BY fnumber'; echo "

$pagetitle

\n"; // Filter ?>
Filter
location); ?>
prepare($sql); $sth->execute($p); $res = $sth->fetchAll(); echo '', "\n"; echo "\n"; echo "\n"; echo ''; echo '"; echo '"; echo '"; echo '"; echo '"; echo ""; echo "\n"; echo "\n"; $i = 1; foreach ($res as $row) { echo "\n"; echo '\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; // Edit current record button echo "\n"; echo "\n"; } // Table summary table_rec_summary($i0, $i, $numrows, 6); echo "
#', pgettext('number', 'Number'), "', _('Type'), "', _('Current'), "', _('Location'), "', _('Description'), "
', $i++; echo '', "\n"; echo "F", $row['fnumber'], "",$opt_ftype_short[$row['ftype']], "", $row['current'], "A", $opt_location[$row['location']], "", $row['description'], ""; echo '', "\n"; echo "
\n"; form_add_button($g_scriptname); elseif ($action == ACT_ADD): // ========== VARIANT: add record ============================================= echo '

', _('Add fuse'), "

\n"; // calc next free fuse number for convenience $sql = "SELECT max(fnumber) FROM fuse WHERE vid=?"; $sth = $pdo->prepare($sql); $sth->execute([$user->vid]); $fnumber = $sth->fetchColumn() + 1; ?>
\n"; elseif ($action == ACT_VIEW): // ========== VARIANT: view single record ===================================== $sql = "SELECT fnumber, ftype, current, cableid, eid, location, description, remarks " . "FROM fuse " . "WHERE fuseid=?"; $sth = $pdo->prepare($sql); $sth->execute([$id]); $fuse = $sth->fetch(PDO::FETCH_OBJ); echo '

', _('View fuse'), "

\n"; echo '', "\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo "
', _('Fuse'),"F", $fuse->fnumber, "
', _('Description'),"", $fuse->description, "
', _('Type'),"", $opt_ftype[$fuse->ftype], "
', _('Current'),"", $fuse->current, "A
', _('Location'),"", $opt_location[$fuse->location], "
', _('Cable'),"", $fuse->cableid, "
', _('Equipment'),"", $fuse->eid, "
', _('Remarks'),"", nl2br($fuse->remarks), "
\n"; form_view_buttons($g_scriptname, $id); elseif ($action == ACT_EDIT): // ========== VARIANT: edit single record ===================================== $sql = "SELECT fnumber, description " . "FROM fuse " . "WHERE fuseid=?"; $sth = $pdo->prepare($sql); $sth->execute([$id]); $fuse = $sth->fetch(PDO::FETCH_OBJ); echo '

', _('Edit fuse'), "

\n"; ?>
\n"; elseif ($action == ACT_DELETE): // ========== VARIANT: delete record ========================================== echo '

', _('Delete fuse'), "

\n"; $sql = "SELECT fusename, description FROM fuse WHERE fuseid=?"; $sth = $pdo->prepare($sql); $sth->execute([$id]); if ($sth->rowCount() > 0) { foreach ($sth->fetchAll() as $row) { echo '', $row['objid'], '/', $row['objtype'], "\n"; } } else { echo _('Fuse is not used anywhere'); $_SESSION['token'] = bin2hex(random_bytes(8)); form_delete_buttons($g_scriptname, $id, $_SESSION['token']); } else: // ========== ERROR UNKNOWN VARIANT =========================================== echo '

', _('Unknown function call: Please report to system development!'), "

\n"; endif; // $action == ... // ========== END OF VARIANTS ================================================= include 'footer.php';