prepare($sql); try { $sth->execute([$name, $color, $desc]); } catch (PDOException $e) { $g_error->Add($e->getMessage()); } $id = $dbh->lastInsertId(); $action = ACT_VIEW; break; case 'update': $acg_name = sanitize($_POST['acg_name']); $acg_desc = sanitize($_POST['acg_description']); $acg_color = preg_replace("|[^a-zA-Z0-9]|", "", strtoupper(sanitize($_POST['acg_color']))); $sql = "UPDATE assetclassgroup SET assetclassgroup_name=?, assetclassgroup_color=?, assetclassgroup_description=? WHERE assetclassgroup_id=?"; $sth = $dbh->prepare($sql); try { $sth->execute([$acg_name, $acg_color, $acg_desc, $id]); } catch (PDOException $e) { $g_error->Add($e->getMessage()); } $action = ACT_VIEW; break; case 'delete': $sth = $dbh->prepare("DELETE FROM assetclassgroup WHERE assetclassgroup_id=?"); try { $sth->execute([$id]); } catch (PDOException $e) { $g_error->Add($e->getMessage()); } $action = ACT_DEFAULT; break; default: $g_error->Add(submit_error($submit)); $valid = FALSE; } // ========== ACTIONS END ===================================================== $smarty->assign("scripts", 'jscolor.js'); include("header.php"); if ($action == ACT_DEFAULT): // ========== VARIANT: default behavior ======================================= $sql = "SELECT g.assetclassgroup_id AS id, g.assetclassgroup_name AS name, g.assetclassgroup_color AS color, g.assetclassgroup_description AS description, COUNT(c.assetclass_id) AS count_class FROM assetclassgroup AS g LEFT JOIN assetclass AS c USING (assetclassgroup_id) GROUP BY id, name, color, description ORDER BY g.assetclassgroup_name"; $sth = $dbh->query($sql); $smarty->assign('assetclassgroups', $sth->fetchAll(PDO::FETCH_ASSOC)); $smarty->display("assetclassgroup.tpl"); elseif ($action == ACT_ADD): // ========== VARIANT: add record ============================================= $smarty->display("assetclassgroupadd.tpl"); elseif ($action == ACT_VIEW): // ========== VARIANT: view single record ===================================== $sql = "SELECT assetclassgroup_id AS id, assetclassgroup_name AS name, assetclassgroup_color AS color, assetclassgroup_description AS description FROM assetclassgroup WHERE assetclassgroup_id=?"; $sth = $dbh->prepare($sql); $sth->execute([$id]); $smarty->assign("assetclassgroup", $sth->fetch(PDO::FETCH_OBJ)); $sql = "SELECT assetclass_id, assetclass_name FROM assetclass WHERE assetclassgroup_id=? ORDER BY assetclass_name"; $sth = $dbh->prepare($sql); $sth->execute([$id]); $smarty->assign("assetclasses", $sth->fetchAll(PDO::FETCH_ASSOC)); $smarty->display("assetclassgroupview.tpl"); elseif ($action == ACT_EDIT): // ========== VARIANT: edit single record ===================================== $sql = "SELECT assetclassgroup_id AS id, assetclassgroup_name AS name, assetclassgroup_color AS color, assetclassgroup_description AS description FROM assetclassgroup WHERE assetclassgroup_id=?"; $sth = $dbh->prepare($sql); $sth->execute([$id]); $smarty->assign("assetclassgroup", $sth->fetch(PDO::FETCH_OBJ)); $smarty->display("assetclassgroupedit.tpl"); elseif ($action == ACT_DELETE): // ========== VARIANT: delete record ========================================== $sql = "SELECT assetclassgroup_id AS id, assetclassgroup_name AS name FROM assetclassgroup WHERE assetclassgroup_id=?"; $sth = $dbh->prepare($sql); $sth->execute([$id]); $smarty->assign("assetclassgroup", $sth->fetch(PDO::FETCH_OBJ)); $smarty->display("assetclassgroupdel.tpl"); else: // ========== ERROR UNKNOWN VARIANT =========================================== echo "
Unknown function call: Please report to system development!
\n"; endif; // $action == ... // ========== END OF VARIANTS ================================================= $smarty->display('footer.tpl');