[feladat @ 189]
authorrejo
Wed, 26 Mar 2008 14:02:59 +0000
changeset 89 61c49e66c9b0
parent 88 fa948cc3727e
child 90 d7bee09d98fe
[feladat @ 189] Added functionality for deletion of permission templates. Simplified function for getting permission template details.
edit_perm_templ.php
inc/error.inc.php
inc/users.inc.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 "    <form method=\"post\">\n";
 	echo "    <input type=\"hidden\" name=\"templ_id\" value=\"" . $id . "\">\n";
 
-	foreach ($templ_details as $templ) {
-		echo "     <table>\n";
-		echo "      <tr>\n";
-		echo "       <th>" . _('Name') . "</th>\n"; 
-		echo "       <td><input class=\"wide\" type=\"text\" name=\"templ_name\" value=\"" . $templ['name'] . "\"></td>\n";
-		echo "      </tr>\n";
-		echo "      <tr>\n";
-		echo "       <th>" . _('Description') . "</th>\n"; 
-		echo "       <td><input class=\"wide\" type=\"text\" name=\"templ_descr\" value=\"" . $templ['descr'] . "\"></td>\n";
-		echo "      </tr>\n";
-		echo "     </table>\n";
-	}
+	echo "     <table>\n";
+	echo "      <tr>\n";
+	echo "       <th>" . _('Name') . "</th>\n"; 
+	echo "       <td><input class=\"wide\" type=\"text\" name=\"templ_name\" value=\"" . $templ['name'] . "\"></td>\n";
+	echo "      </tr>\n";
+	echo "      <tr>\n";
+	echo "       <th>" . _('Description') . "</th>\n"; 
+	echo "       <td><input class=\"wide\" type=\"text\" name=\"templ_descr\" value=\"" . $templ['descr'] . "\"></td>\n";
+	echo "      </tr>\n";
+	echo "     </table>\n";
 
 	echo "     <table>\n";
 	echo "      <tr>\n";
--- 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.')); 
 
 ?>
--- 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;
 }