edit_user.php
author rejo
Thu, 27 Mar 2008 20:46:22 +0000
changeset 104 7fef233c99df
parent 103 17908bb62723
child 110 455405c757e1
permissions -rw-r--r--
[feladat @ 204] Bugfix. Even if one did have the 'add supermasters' right, the menu option wasn't shown. Reported by Maarten te Paske.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
     1
<?php
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
     2
47
ae140472d97c [feladat @ 94]
rejo
parents: 43
diff changeset
     3
/*  PowerAdmin, a friendly web-based admin tool for PowerDNS.
ae140472d97c [feladat @ 94]
rejo
parents: 43
diff changeset
     4
 *  See <https://rejo.zenger.nl/poweradmin> for more details.
ae140472d97c [feladat @ 94]
rejo
parents: 43
diff changeset
     5
 *
ae140472d97c [feladat @ 94]
rejo
parents: 43
diff changeset
     6
 *  Copyright 2007, 2008  Rejo Zenger <rejo@zenger.nl>
ae140472d97c [feladat @ 94]
rejo
parents: 43
diff changeset
     7
 *
ae140472d97c [feladat @ 94]
rejo
parents: 43
diff changeset
     8
 *  This program is free software: you can redistribute it and/or modify
ae140472d97c [feladat @ 94]
rejo
parents: 43
diff changeset
     9
 *  it under the terms of the GNU General Public License as published by
ae140472d97c [feladat @ 94]
rejo
parents: 43
diff changeset
    10
 *  the Free Software Foundation, either version 3 of the License, or
ae140472d97c [feladat @ 94]
rejo
parents: 43
diff changeset
    11
 *  (at your option) any later version.
ae140472d97c [feladat @ 94]
rejo
parents: 43
diff changeset
    12
 *
ae140472d97c [feladat @ 94]
rejo
parents: 43
diff changeset
    13
 *  This program is distributed in the hope that it will be useful,
ae140472d97c [feladat @ 94]
rejo
parents: 43
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
ae140472d97c [feladat @ 94]
rejo
parents: 43
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ae140472d97c [feladat @ 94]
rejo
parents: 43
diff changeset
    16
 *  GNU General Public License for more details.
ae140472d97c [feladat @ 94]
rejo
parents: 43
diff changeset
    17
 *
ae140472d97c [feladat @ 94]
rejo
parents: 43
diff changeset
    18
 *  You should have received a copy of the GNU General Public License
ae140472d97c [feladat @ 94]
rejo
parents: 43
diff changeset
    19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
ae140472d97c [feladat @ 94]
rejo
parents: 43
diff changeset
    20
 */
ae140472d97c [feladat @ 94]
rejo
parents: 43
diff changeset
    21
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    22
require_once("inc/toolkit.inc.php");
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    23
include_once("inc/header.inc.php");
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    24
82
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    25
$edit_id = "-1";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    26
if (isset($_GET['id']) && v_num($_GET['id'])) {
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    27
	$edit_id = $_GET['id'];
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    28
}
82
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    29
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    30
verify_permission(user_edit_own) ? $perm_edit_own = "1" : $perm_edit_own = "0" ;
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    31
verify_permission(user_edit_others) ? $perm_edit_others = "1" : $perm_edit_others = "0" ;
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    32
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    33
if ($edit_id == "-1") {
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    34
	error(ERR_INV_INPUT);
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    35
} elseif (($edit_id == $_SESSION["userid"] && $perm_edit_own == "1") || ($edit_id != $_SESSION["userid"] && $perm_edit_others == "1" )) {
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    36
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    37
	if($_POST["commit"]) {
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    38
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    39
		$i_username = "-1";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    40
		$i_fullname = "-1";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    41
		$i_email = "-1";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    42
		$i_description = "-1";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    43
		$i_password = "-1";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    44
		$i_perm_templ = "0";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    45
		$i_active = "0";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    46
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    47
		if (isset($_POST['username'])) {
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    48
			$i_username = $_POST['username'];
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    49
		}
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    50
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    51
		if (isset($_POST['fullname'])) {
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    52
			$i_fullname = $_POST['fullname'];
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    53
		}
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    54
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    55
		if (isset($_POST['email'])) {
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    56
			$i_email = $_POST['email'];
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    57
		}
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    58
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    59
		if (isset($_POST['description'])) {
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    60
			$i_description = $_POST['description'];
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    61
		}
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    62
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    63
		if (isset($_POST['password'])) {
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    64
			$i_password = $_POST['password'];
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    65
		}
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    66
		
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    67
		if (isset($_POST['perm_templ']) && v_num($_POST['perm_templ'])) {
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    68
			$i_perm_templ = $_POST['perm_templ'];
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    69
		}
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    70
		
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    71
		if (isset($_POST['active']) && v_num($_POST['active'])) {
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    72
			$i_active = $_POST['active'];
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    73
		}
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    74
		
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    75
		if ( $i_username == "-1" || $i_fullname == "-1" || $i_email < "1" || $i_description == "-1" || $i_password == "-1" ) {
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    76
			error(ERR_INV_INPUT);
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    77
		} else {
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    78
			if($i_username != "" && $i_perm_templ > "0" && $i_fullname) {
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    79
				if(!isset($i_active)) {
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    80
					$active = 0;
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    81
				} else {
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    82
					$active = 1;
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    83
				}
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    84
				if(edit_user($edit_id, $i_username, $i_fullname, $i_email, $i_perm_templ, $i_description, $active, $i_password)) {
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    85
					success(SUC_USER_UPD);
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    86
				} 
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    87
			}
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    88
		}
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    89
	}
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    90
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    91
	$users = get_user_detail_list($edit_id)	;
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    92
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    93
	foreach ($users as $user) {
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    94
		
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    95
		(($user['active']) == "1") ? $check = " CHECKED" : $check = "" ;
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    96
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    97
		echo "     <h2>" . _('Edit user') . " \"" . $user['fullname'] . "\"</h2>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    98
		echo "     <form method=\"post\">\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
    99
		echo "      <input type=\"hidden\" name=\"number\" value=\"" . $edit_id . "\">\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   100
		echo "      <table>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   101
		echo "       <tr>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   102
		echo "        <td class=\"n\">" . _('Username') . "</td>\n"; 
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   103
		echo "        <td class=\"n\"><input type=\"text\" class=\"input\" name=\"username\" value=\"" . $user['username'] . "\"></td>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   104
		echo "       </tr>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   105
		echo "       <tr>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   106
		echo "        <td class=\"n\">" . _('Fullname') . "</td>\n"; 
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   107
		echo "        <td class=\"n\"><input type=\"text\" class=\"input\" name=\"fullname\" value=\"" . $user['fullname'] . "\"></td>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   108
		echo "       </tr>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   109
		echo "       <tr>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   110
		echo "        <td class=\"n\">" . _('Password') . "</td>\n";
103
17908bb62723 [feladat @ 203]
rejo
parents: 82
diff changeset
   111
		echo "        <td class=\"n\"><input type=\"password\" class=\"input\" name=\"password\"></td>\n";
82
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   112
		echo "       </tr>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   113
		echo "       <tr>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   114
		echo "        <td class=\"n\">" . _('Email') . "</td>\n"; 
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   115
		echo "        <td class=\"n\"><input type=\"text\" class=\"input\" name=\"email\" value=\"" . $user['email'] . "\"></td>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   116
		echo "       </tr>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   117
		echo "       <tr>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   118
		echo "        <td class=\"n\">" . _('Permission template') . "</td>\n"; 
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   119
		echo "        <td class=\"n\">\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   120
		echo "         <select name=\"perm_templ\">\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   121
		foreach (list_permission_templates() as $template) {
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   122
			($template['id'] == $user['tpl_id']) ? $select = " SELECTED" : $select = "" ;
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   123
			echo "          <option value=\"" . $template['id'] . "\"" . $select . ">" . $template['name'] . "</option>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   124
		}
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   125
		echo "         </select>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   126
		echo "       </td>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   127
		echo "       </tr>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   128
		echo "       <tr>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   129
		echo "        <td class=\"n\">" . _('Description') . "</td>\n"; 
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   130
		echo "        <td class=\"n\"><textarea rows=\"4\" cols=\"30\" class=\"inputarea\" name=\"description\">" . $user['descr'] . "</textarea></td>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   131
		echo "       </tr>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   132
		echo "       <tr>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   133
		echo "        <td class=\"n\">" . _('Enabled') . "</td>\n"; 
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   134
		echo "        <td class=\"n\"><input type=\"checkbox\" class=\"input\" name=\"active\" value=\"1\"" . $check . "></td>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   135
		echo "       </tr>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   136
		echo "       <tr>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   137
	echo "        <td class=\"n\">&nbsp;</td>\n"; 
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   138
		echo "        <td class=\"n\"><input type=\"submit\" class=\"button\" name=\"commit\" value=\"" . _('Commit changes') . "\"></td>\n"; 
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   139
		echo "      </table>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   140
		echo "     </form>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   141
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   142
		echo "     <p>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   143
		printf("      This user has been assigned the \"%s\" permission template.", $user['tpl_name']);
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   144
		if ($user['tpl_descr'] != "") { 
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   145
			echo " The description for this template is: \"" . $user['tpl_descr'] . "\".";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   146
		}
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   147
		echo " Based on this template, this user has the following permissions:";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   148
		echo "     </p>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   149
		echo "     <ul>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   150
		foreach (get_permissions_by_template_id($user['tpl_id']) as $item) {
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   151
			echo "      <li>" . $item['descr'] . " (" . $item['name'] . ")</li>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   152
		}
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   153
		echo "     </ul>\n";
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   154
	}
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   155
} else {
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   156
	error(ERR_PERM_EDIT_USER);
c255196bc447 [feladat @ 182]
rejo
parents: 73
diff changeset
   157
}
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   158
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   159
include_once("inc/footer.inc.php");
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   160
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
   161
?>