delete_user.php
changeset 82 c255196bc447
parent 73 8a239565e9b3
child 110 455405c757e1
equal deleted inserted replaced
81:c72d6d51f3d3 82:c255196bc447
    18  *  You should have received a copy of the GNU General Public License
    18  *  You should have received a copy of the GNU General Public License
    19  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
    20  */
    20  */
    21 
    21 
    22 require_once("inc/toolkit.inc.php");
    22 require_once("inc/toolkit.inc.php");
       
    23 include_once("inc/header.inc.php");
    23 
    24 
    24 $id = ($_POST["id"]) ? $_POST["id"] : $_GET["id"];
    25 verify_permission(user_edit_own) ? $perm_edit_own = "1" : $perm_edit_own = "0" ;
       
    26 verify_permission(user_edit_others) ? $perm_edit_others = "1" : $perm_edit_others = "0" ;
    25 
    27 
    26 if(isset($id)) 
    28 if (!(isset($_GET['id']) && v_num($_GET['id']))) {
    27 {
    29 	error(ERR_INV_INPUT);
    28 	if($_POST["confirm"] == '1') 
    30 	include_once("inc/footer.inc.php");
    29 	{                
    31 	exit;
    30                 $domain = is_array($_POST["domain"]) ? $_POST["domain"] : $domain = array();
    32 } else {
    31                 $delete = is_array($_POST["delete"]) ? $_POST["delete"] : $delete = array();
    33 	$uid = $_GET['id'];
    32                 
    34 }
    33 		if(count($domain) > 0) 
    35 
    34 		{
    36 if ($_POST['commit']) {
    35 			foreach ($domain as $dom => $newowner) 
    37 	if (delete_user($uid,$_POST['zone'])) {
    36 			{
    38 		success(SUC_USER_DEL);	
    37 				if (!in_array($dom, $delete)) 
    39 	}
    38 				{
    40 } else {
    39 					add_owner($dom, $newowner);
    41 
    40                                 }
    42 	if (($uid != $_SESSION['userid'] && !verify_permission(user_edit_others)) || ($uid == $_SESSION['userid'] && !verify_permission(user_edit_own))) {
    41                         }
    43 		error(ERR_PERM_DEL_USER);
    42                 }
    44 		include_once("inc/footer.inc.php");
    43                 if(count($delete) > 0) 
    45 		exit;
    44                 {
    46 	} else {
    45                 	foreach ($delete as $del) 
    47 		$fullname = get_fullname_from_userid($uid);
    46                 	{
    48 		$zones = get_zones("own",$uid);
    47                 		delete_domain($del);
    49 
       
    50 		echo "     <h2>" . _('Delete user') . " \"" . $fullname . "\"</h2>\n";
       
    51 		echo "     <form method=\"post\">\n";
       
    52 		echo "      <table>\n";
       
    53 
       
    54 		if (count($zones) > 0) {
       
    55 
       
    56 			$users = show_users();
       
    57 
       
    58 			echo "       <tr>\n";
       
    59 			echo "        <td colspan=\"5\">\n";
       
    60 
       
    61 			echo "         " . _('You are about to delete a user. This user is owner for a number of zones. Please decide what to do with these zones.') . "\n";
       
    62 			echo "        </td>\n";
       
    63 			echo "       </tr>\n";
       
    64 
       
    65 			echo "       <tr>\n";
       
    66 			echo "        <th>" . _('Zone') . "</th>\n";
       
    67 			echo "        <th>" . _('Delete') . "</th>\n";
       
    68 			echo "        <th>" . _('Leave') . "</th>\n";
       
    69 			echo "        <th>" . _('Add new owner') . "</th>\n";
       
    70 			echo "        <th>" . _('Owner to be added') . "</th>\n";
       
    71 			echo "       </tr>\n";
       
    72 
       
    73 			foreach ($zones as $zone) {
       
    74 				echo "       <input type=\"hidden\" name=\"zone[" . $zone['id'] . "][zid]\" value=\"" . $zone['id'] . "\">\n";
       
    75 				echo "       <tr>\n";
       
    76 				echo "        <td>" . $zone['name'] . "</td>\n";
       
    77 				echo "        <td><input type=\"radio\" name=\"zone[" . $zone['id'] . "][target]\" value=\"delete\"></td>\n";
       
    78 				echo "        <td><input type=\"radio\" name=\"zone[" . $zone['id'] . "][target]\" value=\"leave\" CHECKED></td>\n";
       
    79 				echo "        <td><input type=\"radio\" name=\"zone[" . $zone['id'] . "][target]\" value=\"new_owner\"></td>\n";
       
    80 				echo "        <td>\n";
       
    81 				echo "         <select name=\"zone[" . $zone['id'] . "][newowner]\">\n";
       
    82 
       
    83 				foreach ($users as $user) {
       
    84 					echo "          <option value=\"" . $user["id"] . "\">" . $user["fullname"] . "</option>\n";
       
    85 				}
       
    86 
       
    87 				echo "         </select>\n";
       
    88 				echo "        </td>\n";
       
    89 				echo "       </tr>\n";
       
    90 
    48 			}
    91 			}
    49 		}
    92 		}
    50 		
    93 		echo "       <tr>\n";
    51                 delete_user($id);
    94 		echo "        <td colspan=\"5\">\n";
    52                 clean_page("users.php");
       
    53         }
       
    54         include_once("inc/header.inc.php");
       
    55         ?>
       
    56 	
       
    57     <h3><?php echo _('Delete user'); ?> "<?php echo get_fullname_from_userid($id) ?>"</h3>
       
    58      <form method="post">
       
    59         <?php
       
    60         $domains = get_domains_from_userid($id);
       
    61         if (count($domains) > 0) 
       
    62         {
       
    63         	echo _('This user has access to the following zone(s)'); ?> :<BR><?php
       
    64                 $users = show_users($id);
       
    65                 if(count($users) < 1) 
       
    66                 {
       
    67                         $add = " CHECKED DISABLED";
       
    68                         $no_users = 1;
       
    69                 }
       
    70                 ?>
       
    71                 <table>
       
    72                  <tr>
       
    73 		  <td class="n">Delete</td>
       
    74 		  <td class="n">Name</td>
       
    75 		<?php if (!$no_users) { ?>
       
    76 		  <td class="n">New owner</td>
       
    77 		<?php } ?>
       
    78 		 </tr>
       
    79                 <?php
       
    80                 foreach ($domains as $d) 
       
    81                 {
       
    82                         ?>
       
    83                  <tr>
       
    84 		  <td class="n" align="center"><?php
       
    85                         if ($no_users) 
       
    86                      	{ 
       
    87                      		?><input type="hidden" name="delete[]" value="<?php echo $d["id"] ?>"><?php
       
    88                         } 
       
    89                         ?><input type="checkbox"<?php echo $add ?> name="delete[]" value="<?php echo $d["id"] ?>"></td><td class="n"><?php echo $d["name"] ?></td><td class="n"><?php 
       
    90                         if (!$no_users) 
       
    91                         { 
       
    92                         	?><select name="domain[<?php echo $d["id"] ?>]"><?php
       
    93                         	foreach($users as $u) 
       
    94                         	{
       
    95                         	        ?><option value="<?php echo $u["id"] ?>"><?php echo $u["fullname"] ?></option><?php
       
    96                         	}
       
    97                         	?></select></td><?php 
       
    98                         } 
       
    99                         ?></tr><?php
       
   100                 }
       
   101                 ?></table><?php
       
   102         }
       
   103         
       
   104         $message = _('You are going to delete this user, are you sure?');
       
   105         if(($numrows = $db->queryOne("SELECT count(id) FROM zones WHERE owner=".$db->quote($id))) != 0)
       
   106         {
       
   107         	$message .= " " . _('This user has access to ') . $numrows . _(' zones, by deleting him you will also delete these zones.');
       
   108         }
       
   109 
    95 
   110         ?>
    96 		echo "         " . _('Really delete this user?') . "\n";
   111         <font class="warning"><?php echo $message ?></font><br>
    97 		echo "        </td>\n";
   112         <input type="hidden" name="id" value="<?php echo $id ?>">
    98 		echo "       </tr>\n";
   113         <input type="hidden" name="confirm" value="1">
    99 
   114         <input type="submit" class="button" value="<?php echo _('Yes'); ?>"> <input type="button" class="button" OnClick="location.href='users.php'" value="<?php echo _('No'); ?>"></FORM>
   100 		echo "      </table>\n";
   115         <?php
   101 		echo "     <input type=\"submit\" class=\"button\" name=\"commit\" value=\"" . _('Comit changes') . "\">\n";
   116         include_once("inc/footer.inc.php");
   102 		echo "     </form>\n";
   117 } 
   103 	}
   118 else 
       
   119 {
       
   120         message("Nothing to do!");
       
   121 }
   104 }
   122 
   105 include_once("inc/footer.inc.php");
       
   106 ?>