1
|
<?php
|
2
|
/*
|
3
|
*
|
4
|
* About WebsiteBaker
|
5
|
*
|
6
|
* Website Baker is a PHP-based Content Management System (CMS)
|
7
|
* designed with one goal in mind: to enable its users to produce websites
|
8
|
* with ease.
|
9
|
*
|
10
|
* LICENSE INFORMATION
|
11
|
*
|
12
|
* WebsiteBaker is free software; you can redistribute it and/or
|
13
|
* modify it under the terms of the GNU General Public License
|
14
|
* as published by the Free Software Foundation; either version 2
|
15
|
* of the License, or (at your option) any later version.
|
16
|
*
|
17
|
* WebsiteBaker is distributed in the hope that it will be useful,
|
18
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
20
|
* See the GNU General Public License for more details.
|
21
|
*
|
22
|
* You should have received a copy of the GNU General Public License
|
23
|
* along with this program; if not, write to the Free Software
|
24
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
25
|
*
|
26
|
* WebsiteBaker Extra Information
|
27
|
*
|
28
|
*
|
29
|
*/
|
30
|
/**
|
31
|
*
|
32
|
* @category admin
|
33
|
* @package users
|
34
|
* @author WebsiteBaker Project
|
35
|
* @copyright 2004-2009, Ryan Djurovich
|
36
|
* @copyright 2009-2010, Website Baker Org. e.V.
|
37
|
* @link http://www.websitebaker2.org/
|
38
|
* @license http://www.gnu.org/licenses/gpl.html
|
39
|
* @platform WebsiteBaker 2.8.x
|
40
|
* @requirements PHP 4.3.4 and higher
|
41
|
* @version $Id: users.php 1271 2010-01-23 02:30:24Z Luisehahne $
|
42
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/users/users.php $
|
43
|
* @lastmodified $Date: 2010-01-23 03:30:24 +0100 (Sat, 23 Jan 2010) $
|
44
|
*
|
45
|
*/
|
46
|
|
47
|
// Include config file and admin class file
|
48
|
require('../../config.php');
|
49
|
require_once(WB_PATH.'/framework/class.admin.php');
|
50
|
|
51
|
// Create new database object
|
52
|
$database = new database();
|
53
|
|
54
|
if(!isset($_POST['action']) OR ($_POST['action'] != "modify" AND $_POST['action'] != "delete")) {
|
55
|
header("Location: index.php");
|
56
|
exit(0);
|
57
|
}
|
58
|
|
59
|
// Set parameter 'action' as alternative to javascript mechanism
|
60
|
if(isset($_POST['modify']))
|
61
|
$_POST['action'] = "modify";
|
62
|
if(isset($_POST['delete']))
|
63
|
$_POST['action'] = "delete";
|
64
|
|
65
|
// Check if user id is a valid number and doesnt equal 1
|
66
|
if(!isset($_POST['user_id']) OR !is_numeric($_POST['user_id']) OR $_POST['user_id'] == 1) {
|
67
|
header("Location: index.php");
|
68
|
exit(0);
|
69
|
}
|
70
|
|
71
|
if($_POST['action'] == 'modify') {
|
72
|
// Print header
|
73
|
$admin = new admin('Access', 'users_modify');
|
74
|
// Get existing values
|
75
|
$results = $database->query("SELECT * FROM ".TABLE_PREFIX."users WHERE user_id = '".$_POST['user_id']."'");
|
76
|
$user = $results->fetchRow();
|
77
|
|
78
|
// Setup template object
|
79
|
$template = new Template(THEME_PATH.'/templates');
|
80
|
$template->set_file('page', 'users_form.htt');
|
81
|
$template->set_block('page', 'main_block', 'main');
|
82
|
$template->set_var( array(
|
83
|
'ACTION_URL' => ADMIN_URL.'/users/save.php',
|
84
|
'SUBMIT_TITLE' => $TEXT['SAVE'],
|
85
|
'USER_ID' => $user['user_id'],
|
86
|
'USERNAME' => $user['username'],
|
87
|
'DISPLAY_NAME' => $user['display_name'],
|
88
|
'EMAIL' => $user['email'],
|
89
|
'ADMIN_URL' => ADMIN_URL,
|
90
|
'WB_URL' => WB_URL,
|
91
|
'WB_PATH' => WB_PATH,
|
92
|
'THEME_URL' => THEME_URL
|
93
|
)
|
94
|
);
|
95
|
if($user['active'] == 1) {
|
96
|
$template->set_var('ACTIVE_CHECKED', ' checked="checked"');
|
97
|
} else {
|
98
|
$template->set_var('DISABLED_CHECKED', ' checked="checked"');
|
99
|
}
|
100
|
// Add groups to list
|
101
|
$template->set_block('main_block', 'group_list_block', 'group_list');
|
102
|
$results = $database->query("SELECT group_id, name FROM ".TABLE_PREFIX."groups WHERE group_id != '1'");
|
103
|
if($results->numRows() > 0) {
|
104
|
$template->set_var('ID', '');
|
105
|
$template->set_var('NAME', $TEXT['PLEASE_SELECT'].'...');
|
106
|
$template->set_var('SELECTED', '');
|
107
|
$template->parse('group_list', 'group_list_block', true);
|
108
|
while($group = $results->fetchRow()) {
|
109
|
$template->set_var('ID', $group['group_id']);
|
110
|
$template->set_var('NAME', $group['name']);
|
111
|
if(in_array($group['group_id'], explode(",",$user['groups_id']))) {
|
112
|
$template->set_var('SELECTED', ' selected="selected"');
|
113
|
} else {
|
114
|
$template->set_var('SELECTED', '');
|
115
|
}
|
116
|
$template->parse('group_list', 'group_list_block', true);
|
117
|
}
|
118
|
}
|
119
|
// Only allow the user to add a user to the Administrators group if they belong to it
|
120
|
if(in_array(1, $admin->get_groups_id())) {
|
121
|
$template->set_var('ID', '1');
|
122
|
$users_groups = $admin->get_groups_name();
|
123
|
$template->set_var('NAME', $users_groups[1]);
|
124
|
|
125
|
$in_group = FALSE;
|
126
|
foreach($admin->get_groups_id() as $cur_gid){
|
127
|
if (in_array($cur_gid, explode(",", $user['groups_id']))) {
|
128
|
$in_group = TRUE;
|
129
|
}
|
130
|
}
|
131
|
|
132
|
if($in_group) {
|
133
|
$template->set_var('SELECTED', ' selected="selected"');
|
134
|
} else {
|
135
|
$template->set_var('SELECTED', '');
|
136
|
}
|
137
|
$template->parse('group_list', 'group_list_block', true);
|
138
|
} else {
|
139
|
if($results->numRows() == 0) {
|
140
|
$template->set_var('ID', '');
|
141
|
$template->set_var('NAME', $TEXT['NONE_FOUND']);
|
142
|
$template->set_var('SELECTED', ' selected="selected"');
|
143
|
$template->parse('group_list', 'group_list_block', true);
|
144
|
}
|
145
|
}
|
146
|
|
147
|
// Generate username field name
|
148
|
$username_fieldname = 'username_';
|
149
|
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
|
150
|
srand((double)microtime()*1000000);
|
151
|
$i = 0;
|
152
|
while ($i <= 7) {
|
153
|
$num = rand() % 33;
|
154
|
$tmp = substr($salt, $num, 1);
|
155
|
$username_fieldname = $username_fieldname . $tmp;
|
156
|
$i++;
|
157
|
}
|
158
|
|
159
|
// Work-out if home folder should be shown
|
160
|
if(!HOME_FOLDERS) {
|
161
|
$template->set_var('DISPLAY_HOME_FOLDERS', 'display:none;');
|
162
|
}
|
163
|
|
164
|
// Include the WB functions file
|
165
|
require_once(WB_PATH.'/framework/functions.php');
|
166
|
|
167
|
// Add media folders to home folder list
|
168
|
$template->set_block('main_block', 'folder_list_block', 'folder_list');
|
169
|
foreach(directory_list(WB_PATH.MEDIA_DIRECTORY) AS $name)
|
170
|
{
|
171
|
$template->set_var('NAME', str_replace(WB_PATH, '', $name));
|
172
|
$template->set_var('FOLDER', str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name));
|
173
|
if($user['home_folder'] == str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name)) {
|
174
|
$template->set_var('SELECTED', ' selected="selected"');
|
175
|
} else {
|
176
|
$template->set_var('SELECTED', ' ');
|
177
|
}
|
178
|
$template->parse('folder_list', 'folder_list_block', true);
|
179
|
}
|
180
|
|
181
|
// Insert language text and messages
|
182
|
$template->set_var(array(
|
183
|
'TEXT_RESET' => $TEXT['RESET'],
|
184
|
'TEXT_ACTIVE' => $TEXT['ACTIVE'],
|
185
|
'TEXT_DISABLED' => $TEXT['DISABLED'],
|
186
|
'TEXT_PLEASE_SELECT' => $TEXT['PLEASE_SELECT'],
|
187
|
'TEXT_USERNAME' => $TEXT['USERNAME'],
|
188
|
'TEXT_PASSWORD' => $TEXT['PASSWORD'],
|
189
|
'TEXT_RETYPE_PASSWORD' => $TEXT['RETYPE_PASSWORD'],
|
190
|
'TEXT_DISPLAY_NAME' => $TEXT['DISPLAY_NAME'],
|
191
|
'TEXT_EMAIL' => $TEXT['EMAIL'],
|
192
|
'TEXT_GROUP' => $TEXT['GROUP'],
|
193
|
'TEXT_NONE' => $TEXT['NONE'],
|
194
|
'TEXT_HOME_FOLDER' => $TEXT['HOME_FOLDER'],
|
195
|
'USERNAME_FIELDNAME' => $username_fieldname,
|
196
|
'CHANGING_PASSWORD' => $MESSAGE['USERS']['CHANGING_PASSWORD'],
|
197
|
'HEADING_MODIFY_USER' => $HEADING['MODIFY_USER']
|
198
|
)
|
199
|
);
|
200
|
|
201
|
// Parse template object
|
202
|
$template->parse('main', 'main_block', false);
|
203
|
$template->pparse('output', 'page');
|
204
|
} elseif($_POST['action'] == 'delete') {
|
205
|
// Print header
|
206
|
$admin = new admin('Access', 'users_delete');
|
207
|
// Delete the user
|
208
|
$database->query("DELETE FROM ".TABLE_PREFIX."users WHERE user_id = '".$_POST['user_id']."' LIMIT 1");
|
209
|
if($database->is_error()) {
|
210
|
$admin->print_error($database->get_error());
|
211
|
} else {
|
212
|
$admin->print_success($MESSAGE['USERS']['DELETED']);
|
213
|
}
|
214
|
}
|
215
|
|
216
|
// Print admin footer
|
217
|
$admin->print_footer();
|
218
|
|
219
|
?>
|