|
|
|
@ -8,8 +8,68 @@ SPDX-License-Identifier: GPL-3.0-or-later |
|
|
|
|
*****************************************************************************/ |
|
|
|
|
|
|
|
|
|
include("includes.php"); |
|
|
|
|
|
|
|
|
|
if (isset($_REQUEST['id'])) { |
|
|
|
|
$id = (int) $_REQUEST['id'] or $id = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ========== ACTIONS START =================================================== |
|
|
|
|
switch ($submit = form_get_action()) { |
|
|
|
|
|
|
|
|
|
case NULL: break; |
|
|
|
|
|
|
|
|
|
case 'add': $action = ACT_ADD; break; |
|
|
|
|
case 'view': $action = ACT_VIEW; break; |
|
|
|
|
case 'edit': $action = ACT_EDIT; break; |
|
|
|
|
case 'del': $action = ACT_DELETE; break; |
|
|
|
|
|
|
|
|
|
case 'insert': |
|
|
|
|
$name = sanitize($_POST['assetclass_name']); |
|
|
|
|
$description = sanitize($_POST['assetclass_description']); |
|
|
|
|
$group_id = sanitize($_POST['assetclassgroup_id']); |
|
|
|
|
|
|
|
|
|
$sql = "INSERT INTO assetclass |
|
|
|
|
(assetclass_name, assetclass_description, assetclassgroup_id) |
|
|
|
|
VALUE |
|
|
|
|
(?, ?, ?)"; |
|
|
|
|
$sth = $dbh->prepare($sql); |
|
|
|
|
$sth->execute([$name, $description, $group_id]); |
|
|
|
|
$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); |
|
|
|
|
$sth->execute([$name, $description, $group_id, $id]); |
|
|
|
|
$action = ACT_VIEW; |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 'delete': |
|
|
|
|
$sth = $dbh->prepare("DELETE FROM assetclass WHERE assetclass_id=?"); |
|
|
|
|
$sth->execute([$id]); |
|
|
|
|
$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 |
|
|
|
@ -23,5 +83,77 @@ $smarty->assign("assetclasses", $sth->fetchAll(PDO::FETCH_ASSOC)); |
|
|
|
|
|
|
|
|
|
$smarty->display("assetclass.tpl"); |
|
|
|
|
|
|
|
|
|
include("footer.php"); |
|
|
|
|
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([$assetclass_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 "<p>Unknown function call: Please report to system development!</p>\n"; |
|
|
|
|
|
|
|
|
|
endif; // $action == ... |
|
|
|
|
// ========== END OF VARIANTS ================================================= |
|
|
|
|
|
|
|
|
|
$smarty->display('footer.tpl'); |
|
|
|
|
|
|
|
|
|
// include("footer.php"); |
|
|
|
|
?> |
|
|
|
|