Refactored assetclassgroup

master
Thomas Hooge 2 years ago
parent ccdcfb968c
commit c63b500d77
  1. 2
      assetclass.php
  2. 128
      assetclassgroup.php
  3. 18
      assetclassgroupadd.php
  4. 26
      assetclassgroupdel.php
  5. 30
      assetclassgroupedit.php
  6. 37
      assetclassgroupview.php
  7. 8
      submit.php
  8. 2
      tpl/assetclass.tpl
  9. 2
      tpl/assetclassgroup.tpl
  10. 6
      tpl/assetclassgroupadd.tpl
  11. 7
      tpl/assetclassgroupdel.tpl
  12. 7
      tpl/assetclassgroupedit.tpl
  13. 8
      tpl/assetclassgroupview.tpl
  14. 2
      tpl/assetclassview.tpl

@ -154,6 +154,4 @@ endif; // $action == ...
// ========== END OF VARIANTS =================================================
$smarty->display('footer.tpl');
// include("footer.php");
?>

@ -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['acg_name']);
$color = preg_replace("|[^a-zA-Z0-9]|", "", strtoupper(sanitize($_POST['acg_color'])));
$desc = sanitize($_POST['acg_description']);
$sql = "INSERT INTO assetclassgroup
(assetclassgroup_name, assetclassgroup_color, assetclassgroup_description)
VALUE
(?, ?, ?)";
$sth = $dbh->prepare($sql);
$sth->execute([$name, $color, $desc]);
$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);
$sth->execute([$acg_name, $acg_color, $acg_desc, $id]);
$action = ACT_VIEW;
break;
case 'delete':
$sth = $dbh->prepare("DELETE FROM assetclassgroup WHERE assetclassgroup_id=?");
$sth->execute([$id]);
$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
@ -20,6 +80,68 @@ $sth = $dbh->query($sql);
$smarty->assign('assetclassgroups', $sth->fetchAll(PDO::FETCH_ASSOC));
$smarty->display("assetclassgroup.tpl");
include("footer.php");
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 "<p>Unknown function call: Please report to system development!</p>\n";
endif; // $action == ...
// ========== END OF VARIANTS =================================================
$smarty->display('footer.tpl');
?>

@ -1,18 +0,0 @@
<?php
/*****************************************************************************
IP Reg, a PHP/MySQL IPAM tool
Copyright (C) 2007-2009 Wietse Warendorff (up to v0.5)
Copyright (C) 2011-2023 Thomas Hooge
SPDX-License-Identifier: GPL-3.0-or-later
*****************************************************************************/
include("includes.php");
$smarty->assign("scripts", 'jscolor.js');
include("header.php");
$smarty->display("assetclassgroupadd.tpl");
include("footer.php");
?>

@ -1,26 +0,0 @@
<?php
/*****************************************************************************
IP Reg, a PHP/MySQL IPAM tool
Copyright (C) 2007-2009 Wietse Warendorff (up to v0.5)
Copyright (C) 2011-2023 Thomas Hooge
SPDX-License-Identifier: GPL-3.0-or-later
*****************************************************************************/
include("includes.php");
$assetclassgroup_id = sanitize($_GET['assetclassgroup_id']);
include("header.php");
$sql = "SELECT assetclassgroup_id AS id, assetclassgroup_name AS name
FROM assetclassgroup
WHERE assetclassgroup_id=?";
$sth = $dbh->prepare($sql);
$sth->execute([$assetclassgroup_id]);
$smarty->assign("assetclassgroup", $sth->fetch(PDO::FETCH_OBJ));
$smarty->display("assetclassgroupdel.tpl");
include("footer.php");
?>

@ -1,30 +0,0 @@
<?php
/*****************************************************************************
IP Reg, a PHP/MySQL IPAM tool
Copyright (C) 2007-2009 Wietse Warendorff (up to v0.5)
Copyright (C) 2011-2023 Thomas Hooge
SPDX-License-Identifier: GPL-3.0-or-later
*****************************************************************************/
include("includes.php");
$assetclassgroup_id = sanitize($_GET['assetclassgroup_id']);
$smarty->assign("scripts", 'jscolor.js');
include("header.php");
$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([$assetclassgroup_id]);
$smarty->assign("assetclassgroup", $sth->fetch(PDO::FETCH_OBJ));
$smarty->display("assetclassgroupedit.tpl");
include("footer.php");
?>

@ -1,37 +0,0 @@
<?php
/*****************************************************************************
IP Reg, a PHP/MySQL IPAM tool
Copyright (C) 2007-2009 Wietse Warendorff (up to v0.5)
Copyright (C) 2011-2023 Thomas Hooge
SPDX-License-Identifier: GPL-3.0-or-later
*****************************************************************************/
include("includes.php");
$assetclassgroup_id = sanitize($_GET['assetclassgroup_id']);
include("header.php");
$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([$assetclassgroup_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([$assetclassgroup_id]);
$smarty->assign("assetclasses", $sth->fetchAll(PDO::FETCH_ASSOC));
$smarty->display("assetclassgroupview.tpl");
include("footer.php");
?>

@ -133,7 +133,7 @@ if (isset($_POST['add'])) {
$sth->execute([$name, $description, $group_id]);
header_location("assetclassview.php?assetclass_id=" . $dbh->lastInsertId());
break; */
break;
case ("assetclassgroup") :
$name = sanitize($_POST['acg_name']);
@ -148,7 +148,7 @@ if (isset($_POST['add'])) {
$sth->execute([$name, $color, $desc]);
header_location("assetclassgroupview.php?assetclassgroup_id=" . $dbh->lastInsertId());
break;
break; */
case ("assignnodetoasset") :
$node_ip = sanitize($_POST['node_ip']);
@ -406,7 +406,7 @@ if (isset($_POST['del'])) {
$sth->execute([$assetclass_id]);
header_location("assetclass.php");
break; */
break;
case ("assetclassgroup") :
$assetclassgroup_id = sanitize($_POST['assetclassgroup_id']);
@ -415,7 +415,7 @@ if (isset($_POST['del'])) {
$sth->execute([$assetclassgroup_id]);
header_location("assetclassgroup.php");
break;
break; */
case ("location") :
$location_id = sanitize($_POST['location_id']);

@ -31,7 +31,7 @@
</td>
<td class="value">
<img src="image.php?color={$assetclass.color}" alt="#{$assetclass.color}">
<a href="assetclassgroupview.php?assetclassgroup_id={$assetclass.group_id}">{$assetclass.group_name}</a>
<a href="assetclassgroup.php?f=view&id={$assetclass.group_id}">{$assetclass.group_name}</a>
</td>
<td class="label">
{$assetclass.count_asset}

@ -6,7 +6,7 @@
</td>
<td align="right">
{if $suser_add || $suser_admin}
<a href="assetclassgroupadd.php"><img src="image.php?icon=add" alt="{$lang_assetclassgroup_add}" {if $suser_tooltips}title="{$lang_assetclassgroup_add}" {/if}/></a>
<a href="assetclassgroup.php?f=add"><img src="image.php?icon=add" alt="{$lang_assetclassgroup_add}" {if $suser_tooltips}title="{$lang_assetclassgroup_add}" {/if}/></a>
{/if}
</td>
</tr>

@ -1,5 +1,4 @@
<form method="POST" action="submit.php">
<input type="hidden" name="add" value="assetclassgroup">
<form method="POST" action="assetclassgroup.php">
<table class="title">
<tr>
@ -8,7 +7,7 @@
</td>
<td align="right">
<a href="#" onClick="history.go(-1)"><img src="image.php?icon=cancel" alt="{$lang_cancel}" {if $suser_tooltips}title="{$lang_cancel}" {/if}/></a>
<input type="image" src="image.php?icon=save" alt="{$lang_submit}" {if $suser_tooltips}title="{$lang_submit}" {/if}/>
<input type="image" name="submit[insert]" src="images/page_save.png" alt="{$lang_submit}" {if $suser_tooltips}title="{$lang_submit}" {/if}/>
</td>
</tr>
</table>
@ -47,4 +46,5 @@
</td>
</tr>
</table>
</form>

@ -1,6 +1,5 @@
<form method="POST" action="submit.php">
<input type="hidden" name="del" value="assetclassgroup">
<input type="hidden" name="assetclassgroup_id" value="{$assetclassgroup->id}">
<form method="POST" action="assetclassgroup.php">
<input type="hidden" name="id" value="{$assetclassgroup->id}">
<table class="title">
<tr>
@ -28,7 +27,7 @@
{$lang_assetclassgroup_name}
</td>
<td class="value">
<a href="assetclassgroupview.php?assetclassgroup_id={$assetclassgroup->id}">{$assetclassgroup->name}</a>
<a href="assetclassgroup.php?f=view&id={$assetclassgroup->id}">{$assetclassgroup->name}</a>
</td>
</tr>
</table>

@ -1,6 +1,5 @@
<form method="POST" action="submit.php">
<input type="hidden" name="edit" value="assetclassgroup">
<input type="hidden" name="acg_id" value="{$assetclassgroup->id}">
<form method="POST" action="assetclassgroup.php">
<input type="hidden" name="id" value="{$assetclassgroup->id}">
<table class="title">
<tr>
@ -10,7 +9,7 @@
</td>
<td align="right">
<a href="#" onClick="history.go(-1)"><img src="image.php?icon=back" alt="{$lang_cancel}" {if $suser_tooltips}title="{$lang_cancel}" {/if}/></a>
<input type="image" src="image.php?icon=save" alt="{$lang_submit}" {if $suser_tooltips}title="{$lang_submit}" {/if}/>
<input type="image" name="submit[update]" src="images/page_save.png" alt="{$lang_submit}" {if $suser_tooltips}title="{$lang_submit}" {/if}/>
</td>
</tr>
</table>

@ -6,13 +6,13 @@
</td>
<td align="right">
{if $suser_add}
<a href="assetclassgroupadd.php?assetclassgroup_id={$assetclassgroup->id}"><img src="image.php?icon=add" alt="{$lang_assetclassgroup_add}" {if $suser_tooltips}title="{$lang_assetclassgroup_add}" {/if}/></a>
<a href="assetclassgroup.php?f=add&id={$assetclassgroup->id}"><img src="image.php?icon=add" alt="{$lang_assetclassgroup_add}" {if $suser_tooltips}title="{$lang_assetclassgroup_add}" {/if}/></a>
{/if}
{if $suser_edit}
<a href="assetclassgroupedit.php?assetclassgroup_id={$assetclassgroup->id}"><img src="image.php?icon=edit" alt="{$lang_assetclassgroup_edit}" {if $suser_tooltips}title="{$lang_assetclassgroup_edit}" {/if}/></a>
<a href="assetclassgroup.php?f=edit&id={$assetclassgroup->id}"><img src="image.php?icon=edit" alt="{$lang_assetclassgroup_edit}" {if $suser_tooltips}title="{$lang_assetclassgroup_edit}" {/if}/></a>
{/if}
{if $suser_delete}
<a href="assetclassgroupdel.php?assetclassgroup_id={$assetclassgroup->id}"><img src="image.php?icon=delete" alt="{$lang_assetclassgroup_del}" {if $suser_tooltips}title="{$lang_assetclassgroup_del}" {/if}/></a>
<a href="assetclassgroup.php?f=del&id={$assetclassgroup->id}"><img src="image.php?icon=delete" alt="{$lang_assetclassgroup_del}" {if $suser_tooltips}title="{$lang_assetclassgroup_del}" {/if}/></a>
{/if}
</td>
</tr>
@ -32,7 +32,7 @@
{$lang_assetclassgroup_name}
</td>
<td class="value">
<a href="assetclassgroupview.php?assetclassgroup_id={$assetclassgroup->id}">{$assetclassgroup->name}</a>
<a href="assetclassgroup.php?f=view&id={$assetclassgroup->id}">{$assetclassgroup->name}</a>
</td>
</tr>
<tr>

@ -62,7 +62,7 @@
</td>
<td class="value">
<img src="image.php?color={$assetclass->assetclassgroup_color}" alt="#{$assetclass->assetclassgroup_color}">
<a href="assetclassgroupview.php?assetclassgroup_id={$assetclass->assetclassgroup_id}">{$assetclass->assetclassgroup_name}</a><br>
<a href="assetclassgroup.php?f=view&id={$assetclass->assetclassgroup_id}">{$assetclass->assetclassgroup_name}</a><br>
</td>
</tr>
</table>