# HG changeset patch # User rejo # Date 1206540179 0 # Node ID 61c49e66c9b04a0ade09609bb43045c96e9e018d # Parent fa948cc3727e178fa0fb94136143dc0a83b24627 [feladat @ 189] Added functionality for deletion of permission templates. Simplified function for getting permission template details. diff -r fa948cc3727e -r 61c49e66c9b0 edit_perm_templ.php --- a/edit_perm_templ.php Wed Mar 26 10:02:45 2008 +0000 +++ b/edit_perm_templ.php Wed Mar 26 14:02:59 2008 +0000 @@ -38,7 +38,7 @@ update_perm_templ_details($_POST); } - $templ_details = get_permission_template_details($id); + $templ = get_permission_template_details($id); $perms_templ = get_permissions_by_template_id($id); $perms_avail = get_permissions_by_template_id(); @@ -46,18 +46,16 @@ echo "
\n"; echo " \n"; - foreach ($templ_details as $templ) { - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
" . _('Name') . "
" . _('Description') . "
\n"; - } + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
" . _('Name') . "
" . _('Description') . "
\n"; echo " \n"; echo " \n"; diff -r fa948cc3727e -r 61c49e66c9b0 inc/error.inc.php --- a/inc/error.inc.php Wed Mar 26 10:02:45 2008 +0000 +++ b/inc/error.inc.php Wed Mar 26 14:02:59 2008 +0000 @@ -35,6 +35,7 @@ define("ERR_PERM_VIEW_ZONE", _("You do not have the permission to view this zone.")); define("ERR_PERM_EDIT_USER", _("You do not have the permission to edit this user.")); define("ERR_PERM_EDIT_PERM_TEMPL", _("You do not have the permission to edit permission templates.")); +define("ERR_PERM_DEL_PERM_TEMPL", _("You do not have the permission to delete permission templates.")); define("ERR_PERM_ADD_USER", _("You do not have the permission to add a new user.")); define("ERR_PERM_DEL_USER", _("You do not have the permission to delete this user.")); @@ -54,6 +55,7 @@ define("ERR_USER_WRONG_CURRENT_PASS", _('You didnt enter the correct current password')); define("ERR_USER_MATCH_NEW_PASS", _('The two new password fields do not match')); define("ERR_USER_EDIT", _('Error editting user')); +define("ERR_PERM_TEMPL_ASSIGNED", _('This template is assigned to at least one user')); /* OTHER */ define("ERR_INV_INPUT", _('Invalid or unexpected input given.')); @@ -87,5 +89,6 @@ define("SUC_RECORD_UPD", _('The record has been updated succesfully.')); define("SUC_RECORD_DEL", _('The record has been deleted succesfully.')); define("SUC_SM_DEL", _('The supermaster has been deleted succesfully.')); +define("SUC_PERM_TEMPL_DEL", _('The permission template has been deleted succesfully.')); ?> diff -r fa948cc3727e -r 61c49e66c9b0 inc/users.inc.php --- a/inc/users.inc.php Wed Mar 26 10:02:45 2008 +0000 +++ b/inc/users.inc.php Wed Mar 26 14:02:59 2008 +0000 @@ -230,6 +230,32 @@ return true; } +function delete_perm_templ($ptid) { + + global $db; + if (!(verify_permission(user_edit_templ_perm))) { + error(ERR_PERM_DEL_PERM_TEMPL); + } else { + $query = "SELECT id FROM users WHERE perm_templ = " . $ptid; + $result = $db->query($query); + if (PEAR::isError($result)) { error($response->getMessage()); return false; } + + if($result->numRows() > 0) { + error(ERR_PERM_TEMPL_ASSIGNED); + return false; + } else { + $query = "DELETE FROM perm_templ_items WHERE templ_id = " . $ptid; + $result = $db->query($query); + if (PEAR::isError($result)) { error($response->getMessage()); return false; } + + $query = "DELETE FROM perm_templ WHERE id = " . $ptid; + $result = $db->query($query); + if (PEAR::isError($result)) { error($response->getMessage()); return false; } + + return true; + } + } +} /* * Edit the information of an user.. sloppy implementation with too many queries.. (2) :) @@ -537,13 +563,8 @@ $result = $db->query($query); if (PEAR::isError($response)) { error($response->getMessage()); return false; } - while($details = $result->fetchRow()) { - $detail_list[] = array ( - "name" => $details['name'], - "descr" => $details['descr'] - ); - } - return $detail_list; + $details = $result->fetchRow(); + return $details; }