20
18
* along with this program; if not, write to the Free Software
21
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
* @copyright 2001 - 2011 Ampache.org
25
* @license http://opensource.org/licenses/gpl-2.0 GPLv2
26
* @link http://www.ampache.org/
29
23
require_once '../lib/init.php';
31
25
if (!Access::check('interface','100')) {
38
32
// Switch on the actions
39
33
switch ($_REQUEST['action']) {
41
if (Config::get('demo_mode')) { break; }
43
if (!Core::form_verify('edit_user','post')) {
48
/* Clean up the variables */
49
$user_id = scrub_in($_POST['user_id']);
50
$username = scrub_in($_POST['username']);
51
$fullname = scrub_in($_POST['fullname']);
52
$email = scrub_in($_POST['email']);
53
$access = scrub_in($_POST['access']);
54
$pass1 = $_POST['password_1'];
55
$pass2 = $_POST['password_2'];
57
/* Setup the temp user */
58
$client = new User($user_id);
61
if (empty($username)) {
62
Error::add('username', T_("Error Username Required"));
64
if ($pass1 !== $pass2 && !empty($pass1)) {
65
Error::add('password', T_("Error Passwords don't match"));
68
/* If we've got an error then break! */
69
if (Error::occurred()) {
70
$_REQUEST['action'] = 'show_edit';
72
} // if we've had an oops!
74
if ($access != $client->access) {
75
$client->update_access($access);
77
if ($email != $client->email) {
78
$client->update_email($email);
80
if ($username != $client->username) {
81
$client->update_username($username);
83
if ($fullname != $client->fullname) {
84
$client->update_fullname($fullname);
86
if ($pass1 == $pass2 && strlen($pass1)) {
87
$client->update_password($pass1);
90
show_confirmation(T_('User Updated'), $client->fullname . "(" . $client->username . ")" . T_('updated'), Config::get('web_path'). '/admin/users.php');
93
if (Config::get('demo_mode')) { break; }
95
if (!Core::form_verify('add_user','post')) {
100
$username = scrub_in($_POST['username']);
101
$fullname = scrub_in($_POST['fullname']);
102
$email = scrub_in($_POST['email']);
103
$access = scrub_in($_POST['access']);
104
$pass1 = $_POST['password_1'];
105
$pass2 = $_POST['password_2'];
107
if ($pass1 !== $pass2 || !strlen($pass1)) {
108
Error::add('password', T_("Error Passwords don't match"));
111
if (empty($username)) {
112
Error::add('username', T_('Error Username Required'));
115
/* make sure the username doesn't already exist */
116
if (!User::check_username($username)) {
117
Error::add('username', T_('Error Username already exists'));
120
if (!Error::occurred()) {
121
/* Attempt to create the user */
122
$user_id = User::create($username, $fullname, $email, $pass1, $access);
124
Error::add('general', T_("Error: Insert Failed"));
129
$_REQUEST['action'] = 'show_add_user';
132
if ($access == 5){ $access = T_('Guest');}
133
elseif ($access == 25){ $access = T_('User');}
134
elseif ($access == 100){ $access = T_('Admin');}
136
/* HINT: %1 Username, %2 Access num */
137
show_confirmation(T_('New User Added'),sprintf(T_('%1$s has been created with an access level of %2$s'), $username, $access), Config::get('web_path').'/admin/users.php');
140
$client = new User($_REQUEST['user_id']);
142
show_confirmation(T_('User Enabled'),$client->fullname . ' (' . $client->username . ')', Config::get('web_path'). '/admin/users.php');
145
$client = new User($_REQUEST['user_id']);
146
if ($client->disable()) {
147
show_confirmation(T_('User Disabled'),$client->fullname . ' (' . $client->username . ')', Config::get('web_path'). '/admin/users.php');
150
show_confirmation(T_('Error'), T_('Unable to Disabled last Administrator'), Config::get('web_path').'/admin/users.php');
154
if (Config::get('demo_mode')) { break; }
155
$client = new User($_REQUEST['user_id']);
156
require_once Config::get('prefix') . '/templates/show_edit_user.inc.php';
158
case 'confirm_delete':
159
if (Config::get('demo_mode')) { break; }
160
if (!Core::form_verify('delete_user')) {
164
$client = new User($_REQUEST['user_id']);
165
if ($client->delete()) {
166
show_confirmation(T_('User Deleted'), sprintf(T_('%s has been Deleted'), $client->username), Config::get('web_path'). "/admin/users.php");
169
show_confirmation(T_('Delete Error'), T_("Unable to delete last Admin User"), Config::get('web_path')."/admin/users.php");
173
if (Config::get('demo_mode')) { break; }
174
$client = new User($_REQUEST['user_id']);
175
show_confirmation(T_('Deletion Request'),
176
sprintf(T_('Are you sure you want to permanently delete %s?'), $client->fullname),
177
Config::get('web_path')."/admin/users.php?action=confirm_delete&user_id=" . $_REQUEST['user_id'],1,'delete_user');
179
/* Show IP History for the Specified User */
180
case 'show_ip_history':
181
/* get the user and their history */
182
$working_user = new User($_REQUEST['user_id']);
184
if (!isset($_REQUEST['all'])){
185
$history = $working_user->get_ip_history(0,1);
188
$history = $working_user->get_ip_history();
190
require Config::get('prefix') . '/templates/show_ip_history.inc.php';
192
case 'show_add_user':
193
if (Config::get('demo_mode')) { break; }
194
require_once Config::get('prefix') . '/templates/show_add_user.inc.php';
196
case 'show_preferences':
197
$client = new User($_REQUEST['user_id']);
198
$preferences = Preference::get_all($client->id);
199
require_once Config::get('prefix') . '/templates/show_user_preferences.inc.php';
202
$browse = new Browse();
203
$browse->reset_filters();
204
$browse->set_type('user');
205
$browse->set_simple_browse(1);
206
$browse->set_sort('name','ASC');
207
$user_ids = $browse->get_objects();
208
$browse->show_objects($user_ids);
35
if (Config::get('demo_mode')) { break; }
37
if (!Core::form_verify('edit_user','post')) {
42
/* Clean up the variables */
43
$user_id = scrub_in($_POST['user_id']);
44
$username = scrub_in($_POST['username']);
45
$fullname = scrub_in($_POST['fullname']);
46
$email = scrub_in($_POST['email']);
47
$access = scrub_in($_POST['access']);
48
$pass1 = $_POST['password_1'];
49
$pass2 = $_POST['password_2'];
51
/* Setup the temp user */
52
$client = new User($user_id);
55
if (empty($username)) {
56
Error::add('username', T_("Error Username Required"));
58
if ($pass1 !== $pass2 && !empty($pass1)) {
59
Error::add('password', T_("Error Passwords don't match"));
62
/* If we've got an error then break! */
63
if (Error::occurred()) {
64
$_REQUEST['action'] = 'show_edit';
66
} // if we've had an oops!
68
if ($access != $client->access) {
69
$client->update_access($access);
71
if ($email != $client->email) {
72
$client->update_email($email);
74
if ($username != $client->username) {
75
$client->update_username($username);
77
if ($fullname != $client->fullname) {
78
$client->update_fullname($fullname);
80
if ($pass1 == $pass2 && strlen($pass1)) {
81
$client->update_password($pass1);
84
show_confirmation(T_('User Updated'), $client->fullname . "(" . $client->username . ")" . T_('updated'), Config::get('web_path'). '/admin/users.php');
87
if (Config::get('demo_mode')) { break; }
89
if (!Core::form_verify('add_user','post')) {
94
$username = scrub_in($_POST['username']);
95
$fullname = scrub_in($_POST['fullname']);
96
$email = scrub_in($_POST['email']);
97
$access = scrub_in($_POST['access']);
98
$pass1 = $_POST['password_1'];
99
$pass2 = $_POST['password_2'];
101
if ($pass1 !== $pass2 || !strlen($pass1)) {
102
Error::add('password', T_("Error Passwords don't match"));
105
if (empty($username)) {
106
Error::add('username', T_('Error Username Required'));
109
/* make sure the username doesn't already exist */
110
if (!User::check_username($username)) {
111
Error::add('username', T_('Error Username already exists'));
114
if (!Error::occurred()) {
115
/* Attempt to create the user */
116
$user_id = User::create($username, $fullname, $email, $pass1, $access);
118
Error::add('general', T_("Error: Insert Failed"));
123
$_REQUEST['action'] = 'show_add_user';
126
if ($access == 5){ $access = T_('Guest');}
127
elseif ($access == 25){ $access = T_('User');}
128
elseif ($access == 100){ $access = T_('Admin');}
130
/* HINT: %1 Username, %2 Access num */
131
show_confirmation(T_('New User Added'),sprintf(T_('%1$s has been created with an access level of %2$s'), $username, $access), Config::get('web_path').'/admin/users.php');
134
$client = new User($_REQUEST['user_id']);
136
show_confirmation(T_('User Enabled'),$client->fullname . ' (' . $client->username . ')', Config::get('web_path'). '/admin/users.php');
139
$client = new User($_REQUEST['user_id']);
140
if ($client->disable()) {
141
show_confirmation(T_('User Disabled'),$client->fullname . ' (' . $client->username . ')', Config::get('web_path'). '/admin/users.php');
144
show_confirmation(T_('Error'), T_('Unable to Disabled last Administrator'), Config::get('web_path').'/admin/users.php');
148
if (Config::get('demo_mode')) { break; }
149
$client = new User($_REQUEST['user_id']);
150
require_once Config::get('prefix') . '/templates/show_edit_user.inc.php';
152
case 'confirm_delete':
153
if (Config::get('demo_mode')) { break; }
154
if (!Core::form_verify('delete_user')) {
158
$client = new User($_REQUEST['user_id']);
159
if ($client->delete()) {
160
show_confirmation(T_('User Deleted'), sprintf(T_('%s has been Deleted'), $client->username), Config::get('web_path'). "/admin/users.php");
163
show_confirmation(T_('Delete Error'), T_("Unable to delete last Admin User"), Config::get('web_path')."/admin/users.php");
167
if (Config::get('demo_mode')) { break; }
168
$client = new User($_REQUEST['user_id']);
169
show_confirmation(T_('Deletion Request'),
170
sprintf(T_('Are you sure you want to permanently delete %s?'), $client->fullname),
171
Config::get('web_path')."/admin/users.php?action=confirm_delete&user_id=" . $_REQUEST['user_id'],1,'delete_user');
173
/* Show IP History for the Specified User */
174
case 'show_ip_history':
175
/* get the user and their history */
176
$working_user = new User($_REQUEST['user_id']);
178
if (!isset($_REQUEST['all'])){
179
$history = $working_user->get_ip_history(0,1);
182
$history = $working_user->get_ip_history();
184
require Config::get('prefix') . '/templates/show_ip_history.inc.php';
186
case 'show_add_user':
187
if (Config::get('demo_mode')) { break; }
188
require_once Config::get('prefix') . '/templates/show_add_user.inc.php';
190
case 'show_preferences':
191
$client = new User($_REQUEST['user_id']);
192
$preferences = Preference::get_all($client->id);
193
require_once Config::get('prefix') . '/templates/show_user_preferences.inc.php';
196
$browse = new Browse();
197
$browse->reset_filters();
198
$browse->set_type('user');
199
$browse->set_simple_browse(1);
200
$browse->set_sort('name','ASC');
201
$user_ids = $browse->get_objects();
202
$browse->show_objects($user_ids);
211
205
} // end switch on action
213
207
/* Show the footer */