summaryrefslogtreecommitdiffstats
path: root/admin/users.php
blob: a9a5039dc58b5219640b7a5058a7ee1fe17b69e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70pre { line-height: 125%; }
td.linenos pre { color: #000000; background-color: #f0f0f0; padding-left: 5px; padding-right: 5px; }
span.linenos { color: #000000; background-color: #f0f0f0; padding-left: 5px; padding-right: 5px; }
td.linenos pre.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #00338
<?php
/*

 Copyright (c) Ampache.org
 All rights reserved.

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License v2
 as published by the Free Software Foundation.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/

require_once '../lib/init.php';

if (!Access::check('interface','100')) { 
	access_denied();
	exit();
}

show_header(); 

// Switch on the actions  
switch ($_REQUEST['action']) {
	case 'update_user':
	        if (Config::get('demo_mode')) { break; }
		
		if (!$_SESSION['forms']['adminuser'] || $_SESSION['forms']['adminuser'] != $_POST['formkey']) { 
			access_denied(); 
			exit; 
		} 

		/* Clean up the variables */
		$user_id	= scrub_in($_REQUEST['user_id']);
		$username 	= scrub_in($_REQUEST['username']);
		$fullname 	= scrub_in($_REQUEST['fullname']);
		$email 		= scrub_in($_REQUEST['email']);
		$access 	= scrub_in($_REQUEST['access']);
		$pass1 		= scrub_in($_REQUEST['password_1']);
		$pass2 		= scrub_in($_REQUEST['password_2']);
	
		/* Setup the temp user */	
	    	$client = new User($user_id);
	
		/* Verify Input */
		if (empty($username)) { 
			Error::add('username',_("Error Username Required"));
		}
		if ($pass1 !== $pass2 && !empty($pass1)) { 
			Error::add('password',_("Error Passwords don't match"));
		}

		/* If we've got an error then break! */
		if (Error::$state) { 
			$_REQUEST['action'] = 'show_edit';
			break;
		} // if we've had an oops!

		if ($access != $client->access) { 
			$client->update_access($access);
		}
		if ($email != $client->email) { 
			$client->update_email($email);
		}
		if ($username != $client->username) { 
			$client->update_username($username);
		} 
		if ($fullname != $client->fullname) {
			$client->update_fullname($fullname);
		}
		if ($pass1 == $pass2 && strlen($pass1)) { 
			$client->update_password($pass1);
		} 
		
		show_confirmation(_('User Updated'), $client->fullname . "(" . $client->username . ")" . _('updated'),'admin/users.php');
	break;
	case 'add_user':
        	if (Config::get('demo_mode')) { break; }

                if (!$_SESSION['forms']['adminuser'] || $_SESSION['forms']['adminuser'] != $_POST['formkey']) { 
                        access_denied();
                        exit;
                } 

		$username	= scrub_in($_REQUEST['username']);
		$fullname	= scrub_in($_REQUEST['fullname']);
		$email		= scrub_in($_REQUEST['email']);
		$access		= scrub_in($_REQUEST['access']);
		$pass1		= scrub_in($_REQUEST['password_1']);
		$pass2		= scrub_in($_REQUEST['password_2']);

		if ($pass1 !== $pass2 || !strlen($pass1)) { 
			Error::add('password',_("Error Passwords don't match"));
		}

		if (empty($username)) { 
			Error::add('username',_('Error Username Required'));
		}

		/* make sure the username doesn't already exist */
		if (!User::check_username($username)) { 
			Error::add('username',_('Error Username already exists'));
		} 

		if (!Error::$state) { 
			/* Attempt to create the user */
			$user_id = User::create($username, $fullname, $email, $pass1, $access);
			if (!$user_id) { 
				Error::add('general',"Error: Insert Failed");
			}
			
		} // if no errors
		else { 
			$_REQUEST['action'] = 'show_add_user';
			break;
		}
		if ($access == 5){ $access = _('Guest');}
		elseif ($access == 25){ $access = _('User');}
		elseif ($access == 100){ $access = _('Admin');}
		
		show_confirmation(_('New User Added'),__('%user% has been created with an access level of ' . $access,'%user%',$username),'admin/users.php');	
	break;
	case 'enable':
		$client = new User($_REQUEST['user_id']); 
		$client->enable(); 
		show_confirmation(_('User Enabled'),'','admin/users.php'); 
	break;
	case 'disable':
		$client = new User($_REQUEST['user_id']); 
		if ($client->disable()) { 
			show_confirmation(_('User Disabled'),'','admin/users.php'); 
		} 
		else { 
			show_confirmation(_('Error'),_('Unable to Disabled last Administrator'),'admin/users.php'); 
		} 
	break;

} // End Work Switch


/**
 * This is the second half, it handles displaying anything
 * the first half (work half) potentially has 'adjusted' the user
 * input
 */
switch ($_REQUEST['action']) { 
	case 'show_edit':
        	if (Config::get('demo_mode')) { break; }
		$client	= new User($_REQUEST['user_id']); 
		require_once Config::get('prefix') . '/templates/show_edit_user.inc.php';
	break;
	case 'confirm_delete':
	        if (Config::get('demo_mode')) { break; }
		$client = new User($_REQUEST['user_id']); 
		if ($client->delete()) { 
			show_confirmation(_('User Deleted'), "$client->username has been Deleted","admin/users.php");
		}
		else { 
			show_confirmation(_('Delete Error'), _("Unable to delete last Admin User"),"admin/users.php");
		}
	break;
	case 'delete':
        	if (Config::get('demo_mode')) { break; }
		$client = new User($_REQUEST['user_id']); 
		show_confirmation(_('Deletion Request'),
			_('Are you sure you want to permanently delete') . " $client->fullname ($client->username)?",
			"admin/users.php?action=confirm_delete&amp;user_id=" . $_REQUEST['user_id'],1);
	break;
	/* Show IP History for the Specified User */
	case 'show_ip_history':
		/* get the user and their history */
		$working_user	= new User($_REQUEST['user_id']); 
		
		if (!isset ($_REQUEST['all'])){
			$history	= $working_user->get_ip_history('',1);
		} 
		else {
			$history	= $working_user->get_ip_history('','');
		}
		require Config::get('prefix') . '/templates/show_ip_history.inc.php';
	break;
	case 'show_add_user':
	        if (Config::get('demo_mode')) { break; }
		require_once Config::get('prefix') . '/templates/show_add_user.inc.php';
	break;
	case 'show_preferences': 
		$client = new User($_REQUEST['user_id']); 
		$preferences = Preference::get_all($client->id); 	
		require_once Config::get('prefix') . '/templates/show_user_preferences.inc.php';
	break;
	default:
		Browse::reset_filters();
		Browse::set_type('user'); 
		Browse::set_simple_browse(1);
		Browse::set_sort('name','ASC');
		$user_ids = Browse::get_objects(); 
		Browse::show_objects($user_ids); 
	break;
} // end switch on action

/* Show the footer */
show_footer();

?>