Location: PHPKode > projects > TVEz - Media Library > tvez-0.2.1/html/admin/accounts/accounts.php
<?php

# Check the administrative access
require "admin/admin_access.php";

require "admin/accounts/admin_user_form.php";
require "user/access_levels.inc";

echo '
<script>
	function clear_passwd(form) {
		form.passwd1.value = \'\';
		form.passwd2.value = \'\';
		form.passwd1.focus();
	}
	function check_user_form(form) {
		// Make sure there is a user name
		if (form.username.value.length < 1) {
			alert("'.localize_string("You must specify a username").'!");
			form.username.focus();
			return false;
		}
		// If the password is already set to the md5, we keep the old password
		// unless a new password is specified
		if (
			   (form.password.value.length < 1)
			|| (form.passwd1.value.length > 0)	) {
			// Make sure the password is not too short
			if (form.passwd1.value.length < 6) {
				alert("'.localize_string("The password must be at least ==1== characters long",6).'!");
				clear_passwd(form);
				return false;
			}
			// Make sure the passwords match
			if (form.passwd1.value != form.passwd2.value) {
				alert("'.localize_string("The passwords don't match!").'");
				clear_passwd(form);
				return false;
			}
			// Everything is OK, so md5 the password
			form.password.value = hex_md5(form.passwd1.value);		
			form.passwd1.value = form.password.value;
			form.passwd2.value = form.password.value;
		}
		return true;
	}
	</script>
';

if (isset($_REQUEST['action']) && $_REQUEST['action'] == "newuser") {
	$user['id'] = $_REQUEST['id'];
	$user['username'] = $_REQUEST['username'];
	$user['firstname'] = $_REQUEST['firstname'];
	$user['lastname'] = $_REQUEST['lastname'];
	$user['email'] = $_REQUEST['email'];
	$user['password'] = $_REQUEST['password'];
	$user['access'] = $_REQUEST['access'];
	list($success,$nada) = create_user_account($user);
	if ($success) {
		if ($_REQUEST['id'] == "")
			echo '<div class="usermsg">'.localize_string("Created an account for ==1==", $user['username']).'</div>';
		else
			echo '<div class="usermsg">'.localize_string("Edited the account for ==1==", $user['username']).'</div>';
	}
	//else echo "$nada<br>";
}
elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == "deluser") {
	if (!isset($_REQUEST['id'])) {
		echo '<div class="usermsg">'.localize_string("You must specify a user ID").'.</div>';
	} else {
		$id = $_REQUEST['id'];
		list($suc,$user) = get_user_by_id($id);
		if (! $suc) {
			echo '<div class="usermsg">'.localize_string("The specified user ID does not exist").'.</div>';
		} else {
			# Make sure we are not deleting the last admin user
			$num = 2;
			if ($user[0]['access'] == "admin") {
				list($num,$admins) = get_admin_users();
			}
			if ($num < 2) {
				echo '<div class="usermsg">'.localize_string("You may not delete the only administrator account").'.<div>';
			}
			else {
				list($deleted,$nada) = delete_user_by_id($id);
				if ($deleted) echo "<div class=\"usermsg\">".localize_string("User '==1==' was deleted", $user[0]['username']).".</div>";
				else echo '<div class="usermsg">'.localize_string("The user could not be deleted").'.<div>';
			}
		}
	}
}
if (isset($_REQUEST['action']) && $_REQUEST['action'] == "edituser") {
	if (!isset($_REQUEST['id'])) {
		echo '<div class="usermsg">'.localize_string("You must specify a user ID").'.</div>';
		admin_user_form(null);
	} else {
		$id = $_REQUEST['id'];
		list($suc,$user) = get_user_by_id($id);
		admin_user_form($user[0]);
	}
}
else
	admin_user_form(null);


# Generate a list of the accounts
list($num,$users) = get_all_users();

echo '
<table cellpadding="5" cellspacing="0" class="user" border="0" align="center">
<tr class="usertitle"><td colspan="10">'.localize_string("User Accounts").' ('.$num.')</td></tr>
<tr class="usercols"><td class="usercols">'.localize_string("Delete").'</td><td class="usercols">'.localize_string("Edit").'</td><td class="usercols">'.localize_string("Username").'</td><td class="usercols">'.localize_string("First Name").'</td><td class="usercols">'.localize_string("Last Name").'</td><td class="usercols">'.localize_string("Email").'</td><td class="usercols">'.localize_string("Access Level").'</td></tr>
';
if ($num)
	foreach ($users as $user) {
echo '<tr>';
echo '<td><a href="'.$_SERVER['PHP_SELF'].'?content=admin&page=accounts&action=deluser&id='.$user['id'].'" onclick="javascript:return confirm(\'Are you sure you want to delete user '.$user['username'].'?\');">'.localize_string("Delete").'</a>&nbsp;</td>';
echo '<td><a href="'.$_SERVER['PHP_SELF'].'?content=admin&page=accounts&action=edituser&id='.$user['id'].'">'.localize_string("Edit").'</a>&nbsp;</td>';
echo '<td>'.$user['username'].'&nbsp;</td><td>'.$user['firstname'].'&nbsp;</td><td>'.$user['lastname'].'&nbsp;</td><td>'.$user['email'].'&nbsp;</td><td>'.$accessLevels[$user['access']].'&nbsp;</td>';
echo '</tr>';
	}

echo '</table>';


?>
Return current item: TVEz - Media Library