~ubuntu-branches/debian/sid/ampache/sid

« back to all changes in this revision

Viewing changes to admin/users.php

  • Committer: Package Import Robot
  • Author(s): Charlie Smotherman
  • Date: 2013-08-27 13:19:48 UTC
  • mfrom: (1.2.9)
  • Revision ID: package-import@ubuntu.com-20130827131948-1czew0zxn6u70dtv
Tags: 3.6-rzb2752+dfsg-1
* New upsteam snapshot.  Contains important bug fixes to the installer.
* Correct typo in ampache-common.postrm.
* Remove courtousy copy of php-getid3, during repack.  Closes: #701526
* Update package to use dh_linktree to make the needed sym links to the
  needed system libs that were removed during repack.
* Update debian/rules to reflect upstreams removing/moving of modules.
* Update debian/ampache-common.install to reflect upstreams removal of files.
* Updated to use new apache2.4 API. Closes: #669756
* Updated /debian/po/de.po thx David Prévot for the patch.  Closes:  #691963
* M3U import is now ordered, fixed upstream.  Closes: #684984
* Text input area has been resized so IPv6 addresses will now fit, fixed
  upstream.  Closes:  #716230
* Added ampache-common.preinst to make sure that the courtousy copies of code
  dirs are empty so dh_linktree can do it's magic on upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
 
/* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */
 
2
/* vim:set softtabstop=4 shiftwidth=4 expandtab: */
3
3
/**
4
 
 * Admin Users
5
 
 *
6
4
 *
7
5
 * LICENSE: GNU General Public License, version 2 (GPLv2)
8
 
 * Copyright (c) 2001 - 2011 Ampache.org All Rights Reserved
 
6
 * Copyright 2001 - 2013 Ampache.org
9
7
 *
10
8
 * This program is free software; you can redistribute it and/or
11
9
 * modify it under the terms of the GNU General Public License v2
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.
22
20
 *
23
 
 * @package     Ampache
24
 
 * @copyright   2001 - 2011 Ampache.org
25
 
 * @license     http://opensource.org/licenses/gpl-2.0 GPLv2
26
 
 * @link        http://www.ampache.org/
27
21
 */
28
22
 
29
23
require_once '../lib/init.php';
30
24
 
31
25
if (!Access::check('interface','100')) {
32
 
        access_denied();
33
 
        exit();
 
26
    UI::access_denied();
 
27
    exit();
34
28
}
35
29
 
36
 
show_header();
 
30
UI::show_header();
37
31
 
38
32
// Switch on the actions
39
33
switch ($_REQUEST['action']) {
40
 
        case 'update_user':
41
 
                if (Config::get('demo_mode')) { break; }
42
 
 
43
 
                if (!Core::form_verify('edit_user','post')) {
44
 
                        access_denied();
45
 
                        exit;
46
 
                }
47
 
 
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'];
56
 
 
57
 
                /* Setup the temp user */
58
 
                $client = new User($user_id);
59
 
 
60
 
                /* Verify Input */
61
 
                if (empty($username)) {
62
 
                        Error::add('username', T_("Error Username Required"));
63
 
                }
64
 
                if ($pass1 !== $pass2 && !empty($pass1)) {
65
 
                        Error::add('password', T_("Error Passwords don't match"));
66
 
                }
67
 
 
68
 
                /* If we've got an error then break! */
69
 
                if (Error::occurred()) {
70
 
                        $_REQUEST['action'] = 'show_edit';
71
 
                        break;
72
 
                } // if we've had an oops!
73
 
 
74
 
                if ($access != $client->access) {
75
 
                        $client->update_access($access);
76
 
                }
77
 
                if ($email != $client->email) {
78
 
                        $client->update_email($email);
79
 
                }
80
 
                if ($username != $client->username) {
81
 
                        $client->update_username($username);
82
 
                }
83
 
                if ($fullname != $client->fullname) {
84
 
                        $client->update_fullname($fullname);
85
 
                }
86
 
                if ($pass1 == $pass2 && strlen($pass1)) {
87
 
                        $client->update_password($pass1);
88
 
                }
89
 
 
90
 
                show_confirmation(T_('User Updated'), $client->fullname . "(" . $client->username . ")" . T_('updated'), Config::get('web_path'). '/admin/users.php');
91
 
        break;
92
 
        case 'add_user':
93
 
                if (Config::get('demo_mode')) { break; }
94
 
 
95
 
                if (!Core::form_verify('add_user','post')) {
96
 
                        access_denied();
97
 
                        exit;
98
 
                }
99
 
 
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'];
106
 
 
107
 
                if ($pass1 !== $pass2 || !strlen($pass1)) {
108
 
                        Error::add('password', T_("Error Passwords don't match"));
109
 
                }
110
 
 
111
 
                if (empty($username)) {
112
 
                        Error::add('username', T_('Error Username Required'));
113
 
                }
114
 
 
115
 
                /* make sure the username doesn't already exist */
116
 
                if (!User::check_username($username)) {
117
 
                        Error::add('username', T_('Error Username already exists'));
118
 
                }
119
 
 
120
 
                if (!Error::occurred()) {
121
 
                        /* Attempt to create the user */
122
 
                        $user_id = User::create($username, $fullname, $email, $pass1, $access);
123
 
                        if (!$user_id) {
124
 
                                Error::add('general', T_("Error: Insert Failed"));
125
 
                        }
126
 
 
127
 
                } // if no errors
128
 
                else {
129
 
                        $_REQUEST['action'] = 'show_add_user';
130
 
                        break;
131
 
                }
132
 
                if ($access == 5){ $access = T_('Guest');}
133
 
                elseif ($access == 25){ $access = T_('User');}
134
 
                elseif ($access == 100){ $access = T_('Admin');}
135
 
 
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');
138
 
        break;
139
 
        case 'enable':
140
 
                $client = new User($_REQUEST['user_id']);
141
 
                $client->enable();
142
 
                show_confirmation(T_('User Enabled'),$client->fullname . ' (' . $client->username . ')', Config::get('web_path'). '/admin/users.php');
143
 
        break;
144
 
        case 'disable':
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');
148
 
                }
149
 
                else {
150
 
                        show_confirmation(T_('Error'), T_('Unable to Disabled last Administrator'), Config::get('web_path').'/admin/users.php');
151
 
                }
152
 
        break;
153
 
        case 'show_edit':
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';
157
 
        break;
158
 
        case 'confirm_delete':
159
 
                if (Config::get('demo_mode')) { break; }
160
 
                if (!Core::form_verify('delete_user')) {
161
 
                        access_denied();
162
 
                        exit;
163
 
                }
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");
167
 
                }
168
 
                else {
169
 
                        show_confirmation(T_('Delete Error'), T_("Unable to delete last Admin User"), Config::get('web_path')."/admin/users.php");
170
 
                }
171
 
        break;
172
 
        case 'delete':
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&amp;user_id=" . $_REQUEST['user_id'],1,'delete_user');
178
 
        break;
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']);
183
 
 
184
 
                if (!isset($_REQUEST['all'])){
185
 
                        $history        = $working_user->get_ip_history(0,1);
186
 
                }
187
 
                else {
188
 
                        $history        = $working_user->get_ip_history();
189
 
                }
190
 
                require Config::get('prefix') . '/templates/show_ip_history.inc.php';
191
 
        break;
192
 
        case 'show_add_user':
193
 
                        if (Config::get('demo_mode')) { break; }
194
 
                require_once Config::get('prefix') . '/templates/show_add_user.inc.php';
195
 
        break;
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';
200
 
        break;
201
 
        default:
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);
209
 
                $browse->store();
210
 
        break;
 
34
    case 'update_user':
 
35
        if (Config::get('demo_mode')) { break; }
 
36
 
 
37
        if (!Core::form_verify('edit_user','post')) {
 
38
            UI::access_denied();
 
39
            exit;
 
40
        }
 
41
 
 
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'];
 
50
 
 
51
        /* Setup the temp user */
 
52
        $client = new User($user_id);
 
53
 
 
54
        /* Verify Input */
 
55
        if (empty($username)) {
 
56
            Error::add('username', T_("Error Username Required"));
 
57
        }
 
58
        if ($pass1 !== $pass2 && !empty($pass1)) {
 
59
            Error::add('password', T_("Error Passwords don't match"));
 
60
        }
 
61
 
 
62
        /* If we've got an error then break! */
 
63
        if (Error::occurred()) {
 
64
            $_REQUEST['action'] = 'show_edit';
 
65
            break;
 
66
        } // if we've had an oops!
 
67
 
 
68
        if ($access != $client->access) {
 
69
            $client->update_access($access);
 
70
        }
 
71
        if ($email != $client->email) {
 
72
            $client->update_email($email);
 
73
        }
 
74
        if ($username != $client->username) {
 
75
            $client->update_username($username);
 
76
        }
 
77
        if ($fullname != $client->fullname) {
 
78
            $client->update_fullname($fullname);
 
79
        }
 
80
        if ($pass1 == $pass2 && strlen($pass1)) {
 
81
            $client->update_password($pass1);
 
82
        }
 
83
 
 
84
        show_confirmation(T_('User Updated'), $client->fullname . "(" . $client->username . ")" . T_('updated'), Config::get('web_path'). '/admin/users.php');
 
85
    break;
 
86
    case 'add_user':
 
87
        if (Config::get('demo_mode')) { break; }
 
88
 
 
89
        if (!Core::form_verify('add_user','post')) {
 
90
            UI::access_denied();
 
91
            exit;
 
92
        }
 
93
 
 
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'];
 
100
 
 
101
        if ($pass1 !== $pass2 || !strlen($pass1)) {
 
102
            Error::add('password', T_("Error Passwords don't match"));
 
103
        }
 
104
 
 
105
        if (empty($username)) {
 
106
            Error::add('username', T_('Error Username Required'));
 
107
        }
 
108
 
 
109
        /* make sure the username doesn't already exist */
 
110
        if (!User::check_username($username)) {
 
111
            Error::add('username', T_('Error Username already exists'));
 
112
        }
 
113
 
 
114
        if (!Error::occurred()) {
 
115
            /* Attempt to create the user */
 
116
            $user_id = User::create($username, $fullname, $email, $pass1, $access);
 
117
            if (!$user_id) {
 
118
                Error::add('general', T_("Error: Insert Failed"));
 
119
            }
 
120
 
 
121
        } // if no errors
 
122
        else {
 
123
            $_REQUEST['action'] = 'show_add_user';
 
124
            break;
 
125
        }
 
126
        if ($access == 5){ $access = T_('Guest');}
 
127
        elseif ($access == 25){ $access = T_('User');}
 
128
        elseif ($access == 100){ $access = T_('Admin');}
 
129
 
 
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');
 
132
    break;
 
133
    case 'enable':
 
134
        $client = new User($_REQUEST['user_id']);
 
135
        $client->enable();
 
136
        show_confirmation(T_('User Enabled'),$client->fullname . ' (' . $client->username . ')', Config::get('web_path'). '/admin/users.php');
 
137
    break;
 
138
    case 'disable':
 
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');
 
142
        }
 
143
        else {
 
144
            show_confirmation(T_('Error'), T_('Unable to Disabled last Administrator'), Config::get('web_path').'/admin/users.php');
 
145
        }
 
146
    break;
 
147
    case 'show_edit':
 
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';
 
151
    break;
 
152
    case 'confirm_delete':
 
153
        if (Config::get('demo_mode')) { break; }
 
154
        if (!Core::form_verify('delete_user')) {
 
155
            UI::access_denied();
 
156
            exit;
 
157
        }
 
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");
 
161
        }
 
162
        else {
 
163
            show_confirmation(T_('Delete Error'), T_("Unable to delete last Admin User"), Config::get('web_path')."/admin/users.php");
 
164
        }
 
165
    break;
 
166
    case 'delete':
 
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&amp;user_id=" . $_REQUEST['user_id'],1,'delete_user');
 
172
    break;
 
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']);
 
177
 
 
178
        if (!isset($_REQUEST['all'])){
 
179
            $history    = $working_user->get_ip_history(0,1);
 
180
        }
 
181
        else {
 
182
            $history    = $working_user->get_ip_history();
 
183
        }
 
184
        require Config::get('prefix') . '/templates/show_ip_history.inc.php';
 
185
    break;
 
186
    case 'show_add_user':
 
187
            if (Config::get('demo_mode')) { break; }
 
188
        require_once Config::get('prefix') . '/templates/show_add_user.inc.php';
 
189
    break;
 
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';
 
194
    break;
 
195
    default:
 
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);
 
203
        $browse->store();
 
204
    break;
211
205
} // end switch on action
212
206
 
213
207
/* Show the footer */
214
 
show_footer();
 
208
UI::show_footer();
215
209
 
216
210
?>