users.php
changeset 82 c255196bc447
parent 79 0c0aa144356a
child 99 a4b469dac161
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");
       
    24 verify_permission(user_view_others) ? $perm_view_others = "1" : $perm_view_others = "0" ;
       
    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" ;
       
    27 verify_permission(templ_perm_edit) ? $perm_templ_perm_edit = "1" : $perm_templ_perm_edit = "0" ;
       
    28 verify_permission(is_ueberuser) ? $perm_is_godlike = "1" : $perm_is_godlike = "0" ; 
    23 
    29 
    24 if(isset($_POST["submit"])
    30 if (isset($_POST['commit'])) {
    25 && isset($_POST['username']) && $_POST["username"] != ""
    31 	foreach ($_POST['user'] as $user) {
    26 && isset($_POST['password']) && $_POST["password"] != "" 
    32 		update_user_details($user);
    27 && isset($_POST['fullname']) && $_POST["fullname"] != ""
       
    28 && isset($_POST['email']) && $_POST["email"] != ""
       
    29 && isset($_POST['level']) && $_POST["level"] > 0)
       
    30 {
       
    31 	if(substr_count($_POST["username"], " ") == 0)
       
    32 	{
       
    33 		if(strlen($_POST["password"]) < 8)
       
    34 		{
       
    35 		$error = _('Password length should be at least 8 characters.');
       
    36 		}
       
    37 		else
       
    38 		{
       
    39 			add_user($_POST["username"], $_POST["password"], $_POST["fullname"], $_POST["email"], $_POST["level"], $_POST["description"], $_POST["active"]);
       
    40 			clean_page("users.php");
       
    41 		}
       
    42 	}
    33 	}
    43         else
       
    44         {
       
    45         	$error = _('Usernames can\'t contain spaces');
       
    46         }
       
    47 }
       
    48 elseif(isset($_POST["submit"]))
       
    49 {
       
    50 	$error = _('Please fill in all fields');
       
    51 }
    34 }
    52 
    35 
    53 include_once("inc/header.inc.php");
    36 $users = get_user_detail_list("");
    54 if (isset($error) && $error != "") 
    37 echo "    <h2>" . _('User admin') . "</h2>\n";
    55 {
    38 echo "    <form method=\"post\">\n";
    56 ?>
    39 echo "     <table>\n";
    57 	<div class="error"><?php echo $error ; ?></div>
    40 echo "      <tr>\n";
    58 <?php
    41 echo "       <th>&nbsp;</th>\n";
       
    42 echo "       <th>" . _('Username') . "</th>\n";
       
    43 echo "       <th>" . _('Fullname') . "</th>\n";
       
    44 echo "       <th>" . _('Description') . "</th>\n";
       
    45 echo "       <th>" . _('Emailaddress') . "</th>\n";
       
    46 echo "       <th>" . _('Template') . "</th>\n";
       
    47 echo "       <th>" . _('Enabled') . "</th>\n";
       
    48 echo "      </tr>\n";
       
    49 
       
    50 foreach ($users as $user) {
       
    51 	if ($user['active'] == "1" ) {
       
    52 		$active = " checked";
       
    53 	} else {
       
    54 		$active = "";
       
    55 	}
       
    56 	echo "      <input type=\"hidden\" name=\"user[" . $user['uid'] . "][uid]\" value=\"" . $user['uid'] . "\">\n";
       
    57 	echo "      <tr>\n";
       
    58 	echo "       <td>\n";
       
    59 	if (($user['uid'] == $_SESSION["userid"] && $perm_edit_own == "1") || ($user['uid'] != $_SESSION["userid"] && $perm_edit_others == "1" )) {
       
    60 		echo "        <a href=\"edit_user.php?id=" . $user['uid'] . "\"><img src=\"images/edit.gif\" alt=\"[ " . _('Edit user') . "\" ]></a>\n";
       
    61 		echo "        <a href=\"delete_user.php?id=" . $user['uid'] . "\"><img src=\"images/delete.gif\" alt=\"[ " . _('Delete user') . "\" ]></a>\n";
       
    62 	} else {
       
    63 		echo "        &nbsp;\n";
       
    64 	}
       
    65 	echo "       </td>\n";
       
    66 	echo "       <td><input type=\"text\" name=\"user[" . $user['uid'] . "][username]\" value=\"" . $user['username'] . "\"></td>\n";
       
    67 	echo "       <td><input type=\"text\" name=\"user[" . $user['uid'] . "][fullname]\" value=\"" . $user['fullname'] . "\"></td>\n";
       
    68 	echo "       <td><input type=\"text\" name=\"user[" . $user['uid'] . "][descr]\" value=\"" . $user['descr'] . "\"></td>\n";
       
    69 	echo "       <td><input type=\"text\" name=\"user[" . $user['uid'] . "][email]\" value=\"" . $user['email'] . "\"></td>\n";
       
    70 	echo "       <td>\n";
       
    71 	echo "        <select name=\"user[" . $user['uid'] . "][templ_id]\">\n";
       
    72 
       
    73 	foreach (list_permission_templates() as $template) {
       
    74 		($template['id'] == $user['tpl_id']) ? $select = " SELECTED" : $select = "" ;
       
    75 		echo "          <option value=\"" . $template['id'] . "\"" . $select . ">" . $template['name'] . "</option>\n";
       
    76 	}
       
    77 	echo "         </select>\n";
       
    78 	echo "       </td>\n";
       
    79 	echo "       <td><input type=\"checkbox\" name=\"user[" . $user['uid'] . "][active]\"" . $active . "></td>\n";
       
    80 	echo "      </tr>\n";
    59 }
    81 }
    60 ?>
    82 
    61     <h2><?php echo _('User admin'); ?></h2>
    83 echo "     </table>\n";
    62 <?php
    84 echo "     <input type=\"submit\" class=\"button\" name=\"commit\" value=\"" . _('Commit changes') . "\">\n";
    63 if (!level(10)) 
    85 echo "    </form>\n";
    64 {
    86 
    65 	error(ERR_LEVEL_10);
    87 echo "    <p>\n";
       
    88 if ($perm_templ_perm_edit == "1") {
       
    89 	echo _('Edit') . " <a href=\"list_perm_templ.php\">" . _('permission templates') . "</a>. \n";
    66 }
    90 }
    67 ?>
       
    68      <h3><?php echo _('Current users'); ?></h3>
       
    69 <?php
       
    70 $users = show_users('');
       
    71 ?>  
       
    72 
    91 
    73       <table>
    92 if (verify_permission(user_add_new)) {
    74        <tr>
    93 	echo _('Add') . " <a href=\"add_user.php\">" . _('user') . "</a>. \n";
    75         <th>&nbsp;</th>
       
    76         <th><?php echo _('Name'); ?></th>
       
    77         <th><?php echo _('Zones'); ?> (<?php echo _('access'); ?>)</th>
       
    78         <th><?php echo _('Zones'); ?> (<?php echo _('owner'); ?>)</th>
       
    79         <th><?php echo _('Zone list'); ?></th>
       
    80         <th><?php echo _('Level'); ?></th>
       
    81         <th><?php echo _('Status'); ?></th>
       
    82        </tr>
       
    83 <?php
       
    84 $users = show_users('',ROWSTART,ROWAMOUNT);
       
    85 foreach ($users as $c)
       
    86 {
       
    87         $domains = get_domains_from_userid($c["id"]);
       
    88 	$num_zones_access = count($domains);
       
    89 ?>
       
    90        <tr>
       
    91         <td class="n"><a href="delete_user.php?id=<?php echo $c["id"] ?>"><img src="images/delete.gif" alt="[ <?php echo _('Delete user'); ?> ]"></a></td>
       
    92         <td class="n"><a href="edit_user.php?id=<?php echo $c["id"] ?>"><?php echo $c["fullname"] ?></A> (<?php echo $c["username"] ?>)</td>
       
    93         <td class="n"><?php echo $num_zones_access ?></td>
       
    94         <td class="n"><?php echo $c["numdomains"] ?></td>
       
    95         <td class="n">
       
    96         <?php
       
    97         foreach ($domains as $d)
       
    98         {
       
    99                 ?><a href="delete_domain.php?id=<?php echo $d["id"] ?>"><img src="images/delete.gif" alt="[ <?php echo _('Delete domain'); ?> ]"></a>&nbsp;<a href="edit.php?id=<?php echo $d["id"] ?>"><?php echo $d["name"] ?><?php if ($d["partial"] == "1") { echo " *"; } ; ?></a><br><?php
       
   100         }
       
   101         ?></td>
       
   102 	<td class="n"><?php echo $c["level"] ?></td>
       
   103 	<td class="n"><?php echo get_status($c["active"]) ?></td>
       
   104        </tr><?php
       
   105         print "\n";
       
   106 }
    94 }
   107 ?>
    95 echo "    </p>\n";
   108        
       
   109       </table>
       
   110       <p><?php echo _('Users may only change some of the records of zones marked with an (*).'); ?></p>
       
   111       <p><?php echo _('Number of users') ;?>: <?php echo count($users); ?>.</p>
       
   112       <div class="showmax">
       
   113 <?php
       
   114 show_pages(count($users),ROWAMOUNT);
       
   115 ?>
       
   116       </div> <?php // eo div showmax ?>
       
   117 
    96 
   118       <h3><?php echo _('Create new user'); ?></h3>
    97 
   119       <form method="post" action="users.php">
       
   120        <table>
       
   121         <tr>
       
   122          <td class="n"><?php echo _('User name'); ?>:</td>
       
   123          <td class="n"><input type="text" class="input" name="username" value="<?php if (isset($error)) print $_POST["username"]; ?>"></td>
       
   124 	</tr>
       
   125 	<tr>
       
   126 	 <td class="n"><?php echo _('Full name'); ?>:</td>
       
   127 	 <td class="n"><input type="text" class="input" NAME="fullname" VALUE="<?php if (isset($error)) print $_POST["fullname"]; ?>"></td>
       
   128 	</tr>
       
   129 	<tr>
       
   130 	 <td class="n"><?php echo _('Password'); ?>:</td>
       
   131 	 <td class="n"><input type="password" class="input" NAME="password" VALUE="<?php if (isset($error)) print $_POST["password"]; ?>"></td>
       
   132 	</tr>
       
   133 	<tr>
       
   134 	 <td class="n"><?php echo _('E-mail'); ?>:</td>
       
   135 	 <td class="n"><input type="text" class="input" NAME="email" VALUE="<?php if (isset($error)) print $_POST["email"]; ?>"></td>
       
   136 	</tr>
       
   137 	<tr>
       
   138 	 <td class="n"><?php echo _('User level'); ?>:</td>
       
   139 	 <td class="n">
       
   140 	  <select name="level">
       
   141 	   <option value="1">1 (<?php echo leveldescription(1) ?>)</option>
       
   142 	   <option value="5">5 (<?php echo leveldescription(5) ?>)</option>
       
   143 	   <option value="10">10 (<?php echo leveldescription(10) ?>)</option>
       
   144 	  </select>
       
   145 	 </td>
       
   146 	</tr>
       
   147         <tr>
       
   148 	 <td class="n"><?php echo _('Description'); ?>:</td>
       
   149 	 <td class="n"><textarea rows="6" cols="30" class="inputarea" name="description"><?php if (isset($error)) print $_POST["description"]; ?></textarea></td>
       
   150 	</tr>
       
   151 	<tr>
       
   152 	 <td class="n"><?php echo _('Active'); ?>:</td>
       
   153 	 <td class="n"><input type="checkbox" name="active" value="1" checked></td>
       
   154 	</tr>
       
   155 	<tr>
       
   156 	 <td class="n">&nbsp;</td>
       
   157 	 <td class="n"><input type="submit" class="button" name="submit" value="<?php echo _('Add user'); ?>"></td>
       
   158 	</tr>
       
   159        </table>
       
   160       </form>
       
   161 <?php
       
   162 include_once("inc/footer.inc.php");
    98 include_once("inc/footer.inc.php");
   163 ?>
    99 ?>