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