diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-06-04 07:40:06 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-06-04 07:40:06 +0000 |
commit | 7743d70c68444fc2e20a6a4aa2f9a980203b999e (patch) | |
tree | 32d7c68ba195e429bde67e00c73ae6679159e82d /admin | |
parent | 19276f57a9eeacae7829629baa35fcb28d77419f (diff) | |
download | ampache-7743d70c68444fc2e20a6a4aa2f9a980203b999e.tar.gz ampache-7743d70c68444fc2e20a6a4aa2f9a980203b999e.tar.bz2 ampache-7743d70c68444fc2e20a6a4aa2f9a980203b999e.zip |
fixed browse users, add user, edit user
Diffstat (limited to 'admin')
-rw-r--r-- | admin/users.php | 154 |
1 files changed, 71 insertions, 83 deletions
diff --git a/admin/users.php b/admin/users.php index 75a280cf..56a6fcf5 100644 --- a/admin/users.php +++ b/admin/users.php @@ -20,28 +20,20 @@ */ -require_once ('../lib/init.php'); - +require_once '../lib/init.php'; if (!$GLOBALS['user']->has_access(100)) { access_denied(); exit(); } - -$action = scrub_in($_REQUEST['action']); $user_id = scrub_in($_REQUEST['user_id']); -show_template('header'); +show_header(); // Switch on the actions -switch ($action) { - case 'edit': - if (conf('demo_mode')) { break; } - $working_user = new User($user_id); - require_once(conf('prefix') . '/templates/show_edit_user.inc.php'); - break; +switch ($_REQUEST['action']) { case 'update_user': - if (conf('demo_mode')) { break; } + if (Config::get('demo_mode')) { break; } /* Clean up the variables */ $user_id = scrub_in($_REQUEST['user_id']); @@ -53,84 +45,79 @@ switch ($action) { $pass2 = scrub_in($_REQUEST['password_2']); /* Setup the temp user */ - $working_user = new User($user_id); + $client = new User($user_id); /* Verify Input */ if (empty($username)) { - $GLOBALS['error']->add_error('username',_("Error Username Required")); + Error::add('username',_("Error Username Required")); } - if ($pass1 !== $pass2 AND !empty($pass1)) { - $GLOBALS['error']->add_error('password',_("Error Passwords don't match")); + if ($pass1 !== $pass2 && !empty($pass1)) { + Error::add('password',_("Error Passwords don't match")); } /* If we've got an error then break! */ - if ($GLOBALS['error']->error_state) { - require_once(conf('prefix') . '/templates/show_edit_user.inc.php'); + if (Error::$state) { + $_REQUEST['action'] = 'show_edit'; break; } // if we've had an oops! - if ($access != $working_user->access) { - $working_user->update_access($access); + if ($access != $client->access) { + $client->update_access($access); } - if ($email != $working_user->email) { - $working_user->update_email($email); + if ($email != $client->email) { + $client->update_email($email); } - if ($username != $working_user->username) { - $working_user->update_username($username); + if ($username != $client->username) { + $client->update_username($username); } - if ($fullname != $working_user->fullname) { - $working_user->update_fullname($fullname); + if ($fullname != $client->fullname) { + $client->update_fullname($fullname); } if ($pass1 == $pass2 && strlen($pass1)) { - $working_user->update_password($pass1); + $client->update_password($pass1); } - show_confirmation(_('User Updated'), $working_user->fullname . "(" . $working_user->username . ")" . _('updated'),'admin/users.php'); + show_confirmation(_('User Updated'), $client->fullname . "(" . $client->username . ")" . _('updated'),'admin/users.php'); break; case 'add_user': - if (conf('demo_mode')) { break; } + if (Config::get('demo_mode')) { break; } $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)) { - $GLOBALS['error']->add_error('password',_("Error Passwords don't match")); + + if ($pass1 !== $pass2) { + Error::add('password',_("Error Passwords don't match")); } if (empty($username)) { - $GLOBALS['error']->add_error('username',_("Error Username Required")); - } - if (is_numeric($username)) { - $GLOBALS['error']->add_error('username',"Error: Due to the incompetance of the programmer numeric usernames would cause the whole of existance to cease. Please add a letter or something"); + Error::add('username',_('Error Username Required')); } /* make sure the username doesn't already exist */ - if (!check_username($username)) { - $GLOBALS['error']->add_error('username',_("Error Username already exists")); + if (!User::check_username($username)) { + Error::add('username',_('Error Username already exists')); } - if (!$GLOBALS['error']->error_state) { - + if (!Error::$state) { /* Attempt to create the user */ - if (!$user->create($username, $fullname, $email, $pass1, $access)) { - $GLOBALS['error']->add_error('general',"Error: Insert Failed"); + $user_id = User::create($username, $fullname, $email, $pass1, $access); + if (!$user_id) { + Error::add('general',"Error: Insert Failed"); } } // if no errors - - /* If we end up with an error */ - if ($GLOBALS['error']->error_state) { - $type = 'new_user'; - require_once(conf('prefix') . '/templates/show_edit_user.inc.php'); + else { + $_REQUEST['action'] = 'show_add_user'; break; } - if ($access == 5){ $access = "Guest";} - elseif ($access == 25){ $access = "User";} - elseif ($access == 100){ $access = "Admin";} + if ($access == 5){ $access = _('Guest');} + elseif ($access == 25){ $access = _('User');} + elseif ($access == 100){ $access = _('Admin');} - show_confirmation("New User Added",$username . " has been created with an access level of " . $access,"admin/users.php"); + show_confirmation(_('New User Added'),__('%user% has been created with an access level of ' . $access,'%user%',$username),'admin/users.php'); break; case 'delete': if (conf('demo_mode')) { break; } @@ -139,6 +126,35 @@ switch ($action) { _('Are you sure you want to permanently delete') . " $working_user->fullname ($working_user->username)?", "admin/users.php?action=confirm_delete&user_id=$user_id",1); break; + case 'enable': + $working_user = new User($user_id); + $working_user->enable(); + show_confirmation(_('User Enabled'),'','admin/users.php'); + break; + case 'disable': + $working_user = new User($user_id); + if ($working_user->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($user_id); + require_once Config::get('prefix') . '/templates/show_edit_user.inc.php'; + break; case 'confirm_delete': if (conf('demo_mode')) { break; } $working_user = new User($_REQUEST['user_id']); @@ -161,22 +177,8 @@ switch ($action) { require (conf('prefix') . '/templates/show_ip_history.inc.php'); break; case 'show_add_user': - if (conf('demo_mode')) { break; } - require_once(conf('prefix') . '/templates/show_add_user.inc.php'); - break; - case 'enable': - $working_user = new User($user_id); - $working_user->enable(); - show_confirmation(_('User Enabled'),'','admin/users.php'); - break; - case 'disable': - $working_user = new User($user_id); - if ($working_user->disable()) { - show_confirmation(_('User Disabled'),'','admin/users.php'); - } - else { - show_confirmation(_('Error'),_('Unable to Disabled last Administrator'),'admin/users.php'); - } + if (Config::get('demo_mode')) { break; } + require_once Config::get('prefix') . '/templates/show_add_user.inc.php'; break; case 'show_inactive': $view = new View(); @@ -201,23 +203,9 @@ switch ($action) { break; default: - // Setup the View Object - $view = new View(); - $view->import_session_view(); - - // If we are returning - if ($_REQUEST['keep_view']) { - $view->initialize(); - } - else { - $sql = "SELECT `id` FROM `user`"; - $db_results = mysql_query($sql,dbh()); - $total_items = mysql_num_rows($db_results); - $view = new View($sql,'admin/users.php','fullname',$total_items,$user->prefs['offset_limit']); - } - - $users = get_users($view->sql); - require_once(conf('prefix') . '/templates/show_users.inc.php'); + Browse::set_type('user'); + $user_ids = Browse::get_objects(); + Browse::show_objects($user_ids); break; } // end switch on action |