More work an webgui
This commit is contained in:
+20
-59
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user