1 |
1386
|
Luisehahne
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
*
|
4 |
|
|
* @category admin
|
5 |
|
|
* @package users
|
6 |
|
|
* @author WebsiteBaker Project
|
7 |
|
|
* @copyright 2004-2009, Ryan Djurovich
|
8 |
|
|
* @copyright 2009-2011, Website Baker Org. e.V.
|
9 |
|
|
* @link http://www.websitebaker2.org/
|
10 |
|
|
* @license http://www.gnu.org/licenses/gpl.html
|
11 |
|
|
* @platform WebsiteBaker 2.8.x
|
12 |
|
|
* @requirements PHP 5.2.2 and higher
|
13 |
|
|
* @version $Id$
|
14 |
|
|
* @filesource $HeadURL$
|
15 |
|
|
* @lastmodified $Date$
|
16 |
|
|
*
|
17 |
|
|
*/
|
18 |
|
|
|
19 |
|
|
// Include config file and admin class file
|
20 |
|
|
require('../../config.php');
|
21 |
|
|
require_once(WB_PATH.'/framework/class.admin.php');
|
22 |
|
|
|
23 |
1475
|
Luisehahne
|
$action = 'cancel';
|
24 |
|
|
// Set parameter 'action' as alternative to javascript mechanism
|
25 |
|
|
$action = (isset($_POST['modify']) ? 'modify' : $action );
|
26 |
|
|
$action = (isset($_POST['delete']) ? 'delete' : $action );
|
27 |
1386
|
Luisehahne
|
|
28 |
1475
|
Luisehahne
|
switch ($action):
|
29 |
|
|
case 'modify' :
|
30 |
|
|
// Print header
|
31 |
|
|
$admin = new admin('Access', 'users_modify');
|
32 |
|
|
$user_id = intval($admin->checkIDKEY('user_id', 0, $_SERVER['REQUEST_METHOD']));
|
33 |
|
|
// Check if user id is a valid number and doesnt equal 1
|
34 |
1492
|
Luisehahne
|
if($user_id == 0){
|
35 |
|
|
$admin->print_error($MESSAGE['GENERIC_FORGOT_OPTIONS'] );
|
36 |
|
|
}
|
37 |
1475
|
Luisehahne
|
if( ($user_id < 2 ) )
|
38 |
|
|
{
|
39 |
|
|
// if($admin_header) { $admin->print_header(); }
|
40 |
|
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'] );
|
41 |
|
|
}
|
42 |
|
|
// Get existing values
|
43 |
1492
|
Luisehahne
|
$results = $database->query("SELECT * FROM `".TABLE_PREFIX."users` WHERE `user_id` = '".$user_id."'");
|
44 |
1475
|
Luisehahne
|
$user = $results->fetchRow();
|
45 |
1386
|
Luisehahne
|
|
46 |
1475
|
Luisehahne
|
// Setup template object
|
47 |
|
|
$template = new Template(THEME_PATH.'/templates');
|
48 |
|
|
$template->set_file('page', 'users_form.htt');
|
49 |
|
|
$template->set_block('page', 'main_block', 'main');
|
50 |
|
|
$template->set_var( array(
|
51 |
|
|
'ACTION_URL' => ADMIN_URL.'/users/save.php',
|
52 |
|
|
'SUBMIT_TITLE' => $TEXT['SAVE'],
|
53 |
|
|
'USER_ID' => $user['user_id'],
|
54 |
|
|
'USERNAME' => $user['username'],
|
55 |
|
|
'DISPLAY_NAME' => $user['display_name'],
|
56 |
|
|
'EMAIL' => $user['email'],
|
57 |
|
|
'ADMIN_URL' => ADMIN_URL,
|
58 |
|
|
'WB_URL' => WB_URL,
|
59 |
|
|
'THEME_URL' => THEME_URL
|
60 |
|
|
)
|
61 |
|
|
);
|
62 |
1386
|
Luisehahne
|
|
63 |
1475
|
Luisehahne
|
$template->set_var('FTAN', $admin->getFTAN());
|
64 |
|
|
if($user['active'] == 1) {
|
65 |
|
|
$template->set_var('ACTIVE_CHECKED', ' checked="checked"');
|
66 |
1386
|
Luisehahne
|
} else {
|
67 |
1475
|
Luisehahne
|
$template->set_var('DISABLED_CHECKED', ' checked="checked"');
|
68 |
|
|
}
|
69 |
|
|
// Add groups to list
|
70 |
|
|
$template->set_block('main_block', 'group_list_block', 'group_list');
|
71 |
|
|
$results = $database->query("SELECT group_id, name FROM ".TABLE_PREFIX."groups WHERE group_id != '1' ORDER BY name");
|
72 |
|
|
if($results->numRows() > 0) {
|
73 |
|
|
$template->set_var('ID', '');
|
74 |
|
|
$template->set_var('NAME', $TEXT['PLEASE_SELECT'].'...');
|
75 |
1386
|
Luisehahne
|
$template->set_var('SELECTED', '');
|
76 |
1475
|
Luisehahne
|
$template->parse('group_list', 'group_list_block', true);
|
77 |
|
|
while($group = $results->fetchRow()) {
|
78 |
|
|
$template->set_var('ID', $group['group_id']);
|
79 |
|
|
$template->set_var('NAME', $group['name']);
|
80 |
|
|
if(in_array($group['group_id'], explode(",",$user['groups_id']))) {
|
81 |
|
|
$template->set_var('SELECTED', ' selected="selected"');
|
82 |
|
|
} else {
|
83 |
|
|
$template->set_var('SELECTED', '');
|
84 |
|
|
}
|
85 |
|
|
$template->parse('group_list', 'group_list_block', true);
|
86 |
|
|
}
|
87 |
1386
|
Luisehahne
|
}
|
88 |
|
|
|
89 |
1475
|
Luisehahne
|
// Only allow the user to add a user to the Administrators group if they belong to it
|
90 |
|
|
if(in_array(1, $admin->get_groups_id()))
|
91 |
|
|
{
|
92 |
|
|
$template->set_var('ID', '1');
|
93 |
|
|
$users_groups = $admin->get_groups_name();
|
94 |
|
|
$template->set_var('NAME', $users_groups[1]);
|
95 |
1386
|
Luisehahne
|
|
96 |
1475
|
Luisehahne
|
$in_group = FALSE;
|
97 |
|
|
foreach($admin->get_groups_id() as $cur_gid){
|
98 |
|
|
if (in_array($cur_gid, explode(",", $user['groups_id']))) {
|
99 |
|
|
$in_group = TRUE;
|
100 |
|
|
}
|
101 |
|
|
}
|
102 |
1386
|
Luisehahne
|
|
103 |
1475
|
Luisehahne
|
if($in_group) {
|
104 |
|
|
$template->set_var('SELECTED', ' selected="selected"');
|
105 |
|
|
} else {
|
106 |
|
|
$template->set_var('SELECTED', '');
|
107 |
|
|
}
|
108 |
|
|
$template->parse('group_list', 'group_list_block', true);
|
109 |
|
|
} else {
|
110 |
|
|
if($results->numRows() == 0) {
|
111 |
|
|
$template->set_var('ID', '');
|
112 |
|
|
$template->set_var('NAME', $TEXT['NONE_FOUND']);
|
113 |
|
|
$template->set_var('SELECTED', ' selected="selected"');
|
114 |
|
|
$template->parse('group_list', 'group_list_block', true);
|
115 |
|
|
}
|
116 |
|
|
}
|
117 |
1386
|
Luisehahne
|
|
118 |
1475
|
Luisehahne
|
// Generate username field name
|
119 |
|
|
$username_fieldname = 'username_';
|
120 |
|
|
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
|
121 |
|
|
srand((double)microtime()*1000000);
|
122 |
|
|
$i = 0;
|
123 |
|
|
while ($i <= 7) {
|
124 |
|
|
$num = rand() % 33;
|
125 |
|
|
$tmp = substr($salt, $num, 1);
|
126 |
|
|
$username_fieldname = $username_fieldname . $tmp;
|
127 |
|
|
$i++;
|
128 |
|
|
}
|
129 |
1386
|
Luisehahne
|
|
130 |
1475
|
Luisehahne
|
// Work-out if home folder should be shown
|
131 |
|
|
if(!HOME_FOLDERS) {
|
132 |
|
|
$template->set_var('DISPLAY_HOME_FOLDERS', 'display:none;');
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
// Include the WB functions file
|
136 |
|
|
require_once(WB_PATH.'/framework/functions.php');
|
137 |
|
|
|
138 |
|
|
// Add media folders to home folder list
|
139 |
|
|
$template->set_block('main_block', 'folder_list_block', 'folder_list');
|
140 |
|
|
foreach(directory_list(WB_PATH.MEDIA_DIRECTORY) AS $name)
|
141 |
|
|
{
|
142 |
|
|
$template->set_var('NAME', str_replace(WB_PATH, '', $name));
|
143 |
|
|
$template->set_var('FOLDER', str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name));
|
144 |
|
|
if($user['home_folder'] == str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name)) {
|
145 |
|
|
$template->set_var('SELECTED', ' selected="selected"');
|
146 |
|
|
} else {
|
147 |
|
|
$template->set_var('SELECTED', ' ');
|
148 |
|
|
}
|
149 |
|
|
$template->parse('folder_list', 'folder_list_block', true);
|
150 |
|
|
}
|
151 |
|
|
|
152 |
|
|
// Insert language text and messages
|
153 |
|
|
$template->set_var(array(
|
154 |
|
|
'TEXT_RESET' => $TEXT['RESET'],
|
155 |
1492
|
Luisehahne
|
'TEXT_CANCEL' => $TEXT['CANCEL'],
|
156 |
1475
|
Luisehahne
|
'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 |
1492
|
Luisehahne
|
// Print admin footer
|
177 |
|
|
$admin->print_footer();
|
178 |
1475
|
Luisehahne
|
break;
|
179 |
|
|
case 'delete' :
|
180 |
|
|
// Print header
|
181 |
|
|
$admin = new admin('Access', 'users_delete');
|
182 |
|
|
$user_id = intval($admin->checkIDKEY('user_id', 0, $_SERVER['REQUEST_METHOD']));
|
183 |
|
|
// Check if user id is a valid number and doesnt equal 1
|
184 |
1492
|
Luisehahne
|
if($user_id == 0){
|
185 |
|
|
$admin->print_error($MESSAGE['GENERIC_FORGOT_OPTIONS'] );
|
186 |
|
|
}
|
187 |
1475
|
Luisehahne
|
if( ($user_id < 2 ) )
|
188 |
|
|
{
|
189 |
|
|
// if($admin_header) { $admin->print_header(); }
|
190 |
|
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'] );
|
191 |
|
|
}
|
192 |
1492
|
Luisehahne
|
$sql = 'SELECT `active` FROM `'.TABLE_PREFIX.'users` ';
|
193 |
|
|
$sql .= 'WHERE `user_id` = '.$user_id.'';
|
194 |
|
|
if( ($iDeleteUser = $database->get_one($sql)) == 1 ) {
|
195 |
|
|
// Delete the user
|
196 |
|
|
$database->query("UPDATE `".TABLE_PREFIX."users` SET `active` = 0 WHERE `user_id` = '".$user_id."' ");
|
197 |
|
|
} else {
|
198 |
|
|
$database->query("DELETE FROM `".TABLE_PREFIX."users` WHERE `user_id` = ".$user_id);
|
199 |
|
|
}
|
200 |
|
|
|
201 |
1475
|
Luisehahne
|
if($database->is_error()) {
|
202 |
|
|
$admin->print_error($database->get_error());
|
203 |
|
|
} else {
|
204 |
1492
|
Luisehahne
|
$admin->print_success($MESSAGE['USERS_DELETED']);
|
205 |
1475
|
Luisehahne
|
}
|
206 |
1492
|
Luisehahne
|
// Print admin footer
|
207 |
|
|
$admin->print_footer();
|
208 |
1475
|
Luisehahne
|
break;
|
209 |
|
|
default:
|
210 |
|
|
break;
|
211 |
|
|
endswitch;
|