prepare($sql); try { $sth->execute([$name, $description, $group_id]); } catch (PDOException $e) { $g_error->Add($e->getMessage()); } $id = $dbh->lastInsertId(); $action = ACT_VIEW; break; case 'update': $name = sanitize($_POST['assetclass_name']); $description = sanitize($_POST['assetclass_description']); $group_id = sanitize($_POST['assetclassgroup_id']); $sql = "UPDATE assetclass SET assetclass_name=?, assetclass_description=?, assetclassgroup_id=? WHERE assetclass_id=?"; $sth = $dbh->prepare($sql); try { $sth->execute([$name, $description, $group_id, $id]); } catch (PDOException $e) { $g_error->Add($e->getMessage()); } $action = ACT_VIEW; break; case 'delete': $sth = $dbh->prepare("SELECT COUNT(*) FROM asset WHERE assetclass_id=?"); $sth->execute([$id]); if ($sth->fetchColumn() > 0) { $g_warning->Add("Objektklasse kann nicht gelöscht werden, da noch zugeordnete Objekte vorhanden sind."); $action = ACT_VIEW; break; } $sth = $dbh->prepare("DELETE FROM assetclass WHERE assetclass_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 ===================================================== include("header.php"); if ($action == ACT_DEFAULT): // ========== VARIANT: default behavior ======================================= $sql = "SELECT c.assetclass_id AS id, c.assetclass_name AS name, c.assetclassgroup_id AS group_id, g.assetclassgroup_name AS group_name, g.assetclassgroup_color AS color, COUNT(a.asset_id) AS count_asset FROM assetclass AS c LEFT JOIN assetclassgroup AS g USING (assetclassgroup_id) LEFT JOIN asset AS a USING (assetclass_id) GROUP BY id, name, group_id, group_name, color ORDER BY c.assetclass_name"; $sth = $dbh->query($sql); $smarty->assign("assetclasses", $sth->fetchAll(PDO::FETCH_ASSOC)); $smarty->display("assetclass.tpl"); elseif ($action == ACT_ADD): // ========== VARIANT: add record ============================================= if (isset($_GET['assetclassgroup_id'])) { $group_id = sanitize($_GET['assetclassgroup_id']); } else { $group_id = ''; } $smarty->assign("group_id", $group_id); $smarty->assign("assetclassgroup_options", db_get_options_assetclassgroup()); $smarty->display("assetclassadd.tpl"); elseif ($action == ACT_VIEW): // ========== VARIANT: view single record ===================================== $sql = "SELECT a.assetclass_id, a.assetclass_name, g.assetclassgroup_id, a.assetclass_description, g.assetclassgroup_name, g.assetclassgroup_color FROM assetclass AS a LEFT OUTER JOIN assetclassgroup AS g USING (assetclassgroup_id) WHERE a.assetclass_id=?"; $sth = $dbh->prepare($sql); $sth->execute([$id]); $smarty->assign("assetclass", $sth->fetch(PDO::FETCH_OBJ)); $sql = "SELECT asset_id, asset_name, CONCAT(LEFT(asset_info, 80), IF(CHAR_LENGTH(asset_info)>80,'...','')) AS asset_info FROM asset WHERE assetclass_id=? ORDER BY asset_name"; $sth = $dbh->prepare($sql); $sth->execute([$id]); $smarty->assign("assets", $sth->fetchAll(PDO::FETCH_ASSOC)); $smarty->display("assetclassview.tpl"); elseif ($action == ACT_EDIT): // ========== VARIANT: edit single record ===================================== $sql = "SELECT assetclass_id AS id, assetclass_name AS name, assetclass_description AS description, assetclassgroup_id AS group_id FROM assetclass WHERE assetclass_id=?"; $sth = $dbh->prepare($sql); $sth->execute([$id]); $smarty->assign("assetclass", $sth->fetch(PDO::FETCH_OBJ)); $smarty->assign("assetclassgroup_options", db_get_options_assetclassgroup()); $smarty->display("assetclassedit.tpl"); elseif ($action == ACT_DELETE): // ========== VARIANT: delete record ========================================== $sql = "SELECT assetclass_id AS id, assetclass_name AS name FROM assetclass WHERE assetclass_id=?"; $sth = $dbh->prepare($sql); $sth->execute([$id]); $smarty->assign("assetclass", $sth->fetch(PDO::FETCH_OBJ)); $smarty->display("assetclassdel.tpl"); else: // ========== ERROR UNKNOWN VARIANT =========================================== echo "
Unknown function call: Please report to system development!
\n"; endif; // $action == ... // ========== END OF VARIANTS ================================================= $smarty->display('footer.tpl');