1 |
4
|
ryan
|
<?php
|
2 |
|
|
|
3 |
399
|
Ruebenwurz
|
// $Id$
|
4 |
4
|
ryan
|
|
5 |
|
|
/*
|
6 |
|
|
|
7 |
|
|
Website Baker Project <http://www.websitebaker.org/>
|
8 |
915
|
Ruebenwurz
|
Copyright (C) 2004-2009, Ryan Djurovich
|
9 |
4
|
ryan
|
|
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 |
|
|
require('../../config.php');
|
27 |
|
|
require_once(WB_PATH.'/framework/class.admin.php');
|
28 |
|
|
$admin = new admin('Access', 'users');
|
29 |
|
|
|
30 |
|
|
// Create new template object for the modify/remove menu
|
31 |
|
|
$template = new Template(ADMIN_PATH.'/users');
|
32 |
|
|
$template->set_file('page', 'template.html');
|
33 |
|
|
$template->set_block('page', 'main_block', 'main');
|
34 |
|
|
$template->set_var('ADMIN_URL', ADMIN_URL);
|
35 |
|
|
|
36 |
|
|
// Get existing value from database
|
37 |
|
|
$database = new database();
|
38 |
|
|
$query = "SELECT user_id, username, display_name FROM ".TABLE_PREFIX."users WHERE user_id != '1' ORDER BY username";
|
39 |
|
|
$results = $database->query($query);
|
40 |
|
|
if($database->is_error()) {
|
41 |
|
|
$admin->print_error($database->get_error(), 'index.php');
|
42 |
|
|
}
|
43 |
|
|
|
44 |
|
|
// Insert values into the modify/remove menu
|
45 |
|
|
$template->set_block('main_block', 'list_block', 'list');
|
46 |
|
|
if($results->numRows() > 0) {
|
47 |
|
|
// Insert first value to say please select
|
48 |
|
|
$template->set_var('VALUE', '');
|
49 |
|
|
$template->set_var('NAME', $TEXT['PLEASE_SELECT'].'...');
|
50 |
|
|
$template->parse('list', 'list_block', true);
|
51 |
|
|
// Loop through users
|
52 |
|
|
while($user = $results->fetchRow()) {
|
53 |
|
|
$template->set_var('VALUE', $user['user_id']);
|
54 |
|
|
$template->set_var('NAME', $user['display_name'].' ('.$user['username'].')');
|
55 |
|
|
$template->parse('list', 'list_block', true);
|
56 |
|
|
}
|
57 |
|
|
} else {
|
58 |
|
|
// Insert single value to say no users were found
|
59 |
|
|
$template->set_var('NAME', $TEXT['NONE_FOUND']);
|
60 |
|
|
$template->parse('list', 'list_block', true);
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
// Insert permissions values
|
64 |
|
|
if($admin->get_permission('users_add') != true) {
|
65 |
|
|
$template->set_var('DISPLAY_ADD', 'hide');
|
66 |
|
|
}
|
67 |
|
|
if($admin->get_permission('users_modify') != true) {
|
68 |
|
|
$template->set_var('DISPLAY_MODIFY', 'hide');
|
69 |
|
|
}
|
70 |
|
|
if($admin->get_permission('users_delete') != true) {
|
71 |
|
|
$template->set_var('DISPLAY_DELETE', 'hide');
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
// Insert language headings
|
75 |
|
|
$template->set_var(array(
|
76 |
|
|
'HEADING_MODIFY_DELETE_USER' => $HEADING['MODIFY_DELETE_USER'],
|
77 |
|
|
'HEADING_ADD_USER' => $HEADING['ADD_USER']
|
78 |
|
|
)
|
79 |
|
|
);
|
80 |
|
|
// Insert language text and messages
|
81 |
|
|
$template->set_var(array(
|
82 |
|
|
'TEXT_MODIFY' => $TEXT['MODIFY'],
|
83 |
|
|
'TEXT_DELETE' => $TEXT['DELETE'],
|
84 |
|
|
'TEXT_MANAGE_GROUPS' => $TEXT['MANAGE_GROUPS'],
|
85 |
|
|
'CONFIRM_DELETE' => $MESSAGE['USERS']['CONFIRM_DELETE']
|
86 |
|
|
)
|
87 |
|
|
);
|
88 |
|
|
|
89 |
|
|
// Parse template object
|
90 |
|
|
$template->parse('main', 'main_block', false);
|
91 |
|
|
$template->pparse('output', 'page');
|
92 |
|
|
|
93 |
|
|
// Setup template for add user form
|
94 |
|
|
$template = new Template(ADMIN_PATH.'/users');
|
95 |
|
|
$template->set_file('page', 'user_form.html');
|
96 |
|
|
$template->set_block('page', 'main_block', 'main');
|
97 |
|
|
$template->set_var('DISPLAY_EXTRA', 'none');
|
98 |
|
|
$template->set_var('ACTIVE_CHECKED', 'checked');
|
99 |
|
|
$template->set_var('ACTION_URL', ADMIN_URL.'/users/add.php');
|
100 |
|
|
$template->set_var('SUBMIT_TITLE', $TEXT['ADD']);
|
101 |
|
|
|
102 |
|
|
// Add groups to list
|
103 |
|
|
$template->set_block('main_block', 'group_list_block', 'group_list');
|
104 |
|
|
$results = $database->query("SELECT group_id, name FROM ".TABLE_PREFIX."groups WHERE group_id != '1'");
|
105 |
|
|
if($results->numRows() > 0) {
|
106 |
|
|
$template->set_var('ID', '');
|
107 |
|
|
$template->set_var('NAME', $TEXT['PLEASE_SELECT'].'...');
|
108 |
|
|
$template->set_var('SELECTED', 'selected');
|
109 |
|
|
$template->parse('group_list', 'group_list_block', true);
|
110 |
|
|
while($group = $results->fetchRow()) {
|
111 |
|
|
$template->set_var('ID', $group['group_id']);
|
112 |
|
|
$template->set_var('NAME', $group['name']);
|
113 |
|
|
$template->set_var('SELECTED', '');
|
114 |
|
|
$template->parse('group_list', 'group_list_block', true);
|
115 |
|
|
}
|
116 |
|
|
}
|
117 |
|
|
// Only allow the user to add a user to the Administrators group if they belong to it
|
118 |
546
|
doc
|
if(in_array(1, $admin->get_groups_id())) {
|
119 |
|
|
$users_groups = $admin->get_groups_name();
|
120 |
4
|
ryan
|
$template->set_var('ID', '1');
|
121 |
546
|
doc
|
$template->set_var('NAME', $users_groups[1]);
|
122 |
4
|
ryan
|
$template->set_var('SELECTED', '');
|
123 |
|
|
$template->parse('group_list', 'group_list_block', true);
|
124 |
|
|
} else {
|
125 |
|
|
if($results->numRows() == 0) {
|
126 |
|
|
$template->set_var('ID', '');
|
127 |
|
|
$template->set_var('NAME', $TEXT['NONE_FOUND']);
|
128 |
|
|
$template->parse('group_list', 'group_list_block', true);
|
129 |
|
|
}
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
// Insert permissions values
|
133 |
|
|
if($admin->get_permission('users_add') != true) {
|
134 |
|
|
$template->set_var('DISPLAY_ADD', 'hide');
|
135 |
|
|
}
|
136 |
|
|
|
137 |
|
|
// Generate username field name
|
138 |
|
|
$username_fieldname = 'username_';
|
139 |
|
|
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
|
140 |
|
|
srand((double)microtime()*1000000);
|
141 |
|
|
$i = 0;
|
142 |
|
|
while ($i <= 7) {
|
143 |
|
|
$num = rand() % 33;
|
144 |
|
|
$tmp = substr($salt, $num, 1);
|
145 |
|
|
$username_fieldname = $username_fieldname . $tmp;
|
146 |
|
|
$i++;
|
147 |
|
|
}
|
148 |
|
|
|
149 |
|
|
// Work-out if home folder should be shown
|
150 |
|
|
if(!HOME_FOLDERS) {
|
151 |
|
|
$template->set_var('DISPLAY_HOME_FOLDERS', 'none');
|
152 |
|
|
}
|
153 |
|
|
|
154 |
|
|
// Include the WB functions file
|
155 |
|
|
require_once(WB_PATH.'/framework/functions.php');
|
156 |
|
|
|
157 |
|
|
// Add media folders to home folder list
|
158 |
|
|
$template->set_block('main_block', 'folder_list_block', 'folder_list');
|
159 |
|
|
foreach(directory_list(WB_PATH.MEDIA_DIRECTORY) AS $name) {
|
160 |
|
|
$template->set_var('NAME', str_replace(WB_PATH, '', $name));
|
161 |
|
|
$template->set_var('FOLDER', str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name));
|
162 |
|
|
$template->set_var('SELECTED', ' ');
|
163 |
|
|
$template->parse('folder_list', 'folder_list_block', true);
|
164 |
|
|
}
|
165 |
|
|
|
166 |
|
|
// Insert language text and messages
|
167 |
|
|
$template->set_var(array(
|
168 |
|
|
'TEXT_RESET' => $TEXT['RESET'],
|
169 |
|
|
'TEXT_ACTIVE' => $TEXT['ACTIVE'],
|
170 |
|
|
'TEXT_DISABLED' => $TEXT['DISABLED'],
|
171 |
|
|
'TEXT_PLEASE_SELECT' => $TEXT['PLEASE_SELECT'],
|
172 |
|
|
'TEXT_USERNAME' => $TEXT['USERNAME'],
|
173 |
|
|
'TEXT_PASSWORD' => $TEXT['PASSWORD'],
|
174 |
|
|
'TEXT_RETYPE_PASSWORD' => $TEXT['RETYPE_PASSWORD'],
|
175 |
|
|
'TEXT_DISPLAY_NAME' => $TEXT['DISPLAY_NAME'],
|
176 |
|
|
'TEXT_EMAIL' => $TEXT['EMAIL'],
|
177 |
|
|
'TEXT_GROUP' => $TEXT['GROUP'],
|
178 |
|
|
'TEXT_NONE' => $TEXT['NONE'],
|
179 |
|
|
'TEXT_HOME_FOLDER' => $TEXT['HOME_FOLDER'],
|
180 |
|
|
'USERNAME_FIELDNAME' => $username_fieldname,
|
181 |
|
|
'CHANGING_PASSWORD' => $MESSAGE['USERS']['CHANGING_PASSWORD']
|
182 |
|
|
)
|
183 |
|
|
);
|
184 |
|
|
|
185 |
|
|
// Parse template for add user form
|
186 |
|
|
$template->parse('main', 'main_block', false);
|
187 |
|
|
$template->pparse('output', 'page');
|
188 |
|
|
|
189 |
|
|
$admin->print_footer();
|
190 |
|
|
|
191 |
|
|
?>
|