Project

General

Profile

1 1386 Luisehahne
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         users
6 1529 Luisehahne
 * @author          Ryan Djurovich, WebsiteBaker Project
7 1710 Luisehahne
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8 1386 Luisehahne
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id$
13
 * @filesource		$HeadURL$
14
 * @lastmodified    $Date$
15
 *
16 1804 Luisehahne
 */
17 1386 Luisehahne
18 1804 Luisehahne
$config_file = realpath('../../config.php');
19
if(file_exists($config_file) && !defined('WB_URL'))
20
{
21
	require_once($config_file);
22
}
23
24
if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
25
26 1386 Luisehahne
$admin = new admin('Access', 'users');
27
28 1492 Luisehahne
$iUserStatus = 1;
29
$iUserStatus = ( ( $admin->get_get('status')==1 ) ? 0 : $iUserStatus );
30
unset($_GET);
31
32 1529 Luisehahne
// Setup template object, parse vars to it, then parse it
33
// Create new template object
34 1710 Luisehahne
$template = new Template(dirname($admin->correct_theme_source('users.htt')),'keep');
35 1529 Luisehahne
// $template->debug = true;
36
37 1386 Luisehahne
$template->set_file('page', 'users.htt');
38
$template->set_block('page', 'main_block', 'main');
39
$template->set_block("main_block", "manage_groups_block", "groups");
40
$template->set_var('ADMIN_URL', ADMIN_URL);
41 1475 Luisehahne
$template->set_var('FTAN', $admin->getFTAN());
42 1492 Luisehahne
$template->set_var('USER_STATUS', $iUserStatus );
43 1804 Luisehahne
$template->set_var('DISPLAY_ADD', '');
44
$template->set_var('DISPLAY_MODIFY', '');
45
$template->set_var('DISABLED_CHECKED', '');
46
$template->set_var('HEADING_MODIFY_USER', '');
47
$template->set_var('DISPLAY_HOME_FOLDERS', '');
48 1386 Luisehahne
49 1492 Luisehahne
$UserStatusActive = 'url('.THEME_URL.'/images/user.png)';
50
$UserStatusInactive = 'url('.THEME_URL.'/images/user_red.png)';
51
52
$sUserTitle = ($iUserStatus == 0) ? $MENU['USERS'].' '.strtolower($TEXT['ACTIVE']) : $MENU['USERS'].' '.strtolower($TEXT['DELETED']) ;
53
54
$template->set_var('TEXT_USERS', $sUserTitle.' '.$TEXT['SHOW'] );
55
$template->set_var('STATUS_ICON', ( ($iUserStatus==0) ? $UserStatusActive : $UserStatusInactive) );
56
57 1386 Luisehahne
// Get existing value from database
58 1492 Luisehahne
$sql  = 'SELECT `user_id`, `username`, `display_name`, `active` FROM `'.TABLE_PREFIX.'users` ' ;
59
$sql .= 'WHERE user_id != 1 ';
60
$sql .=     'AND active = '.$iUserStatus.' ';
61
$sql .= 'ORDER BY `display_name`,`username`';
62
63 1484 Luisehahne
$query = "SELECT user_id, username, display_name, active FROM ".TABLE_PREFIX."users WHERE user_id != '1' ORDER BY display_name,username";
64 1492 Luisehahne
$results = $database->query($sql);
65 1386 Luisehahne
if($database->is_error()) {
66
	$admin->print_error($database->get_error(), 'index.php');
67
}
68
69 1492 Luisehahne
$sUserList  = $TEXT['LIST_OPTIONS'].' ';
70
$sUserList .= ($iUserStatus == 1) ? $MENU['USERS'].' '.strtolower($TEXT['ACTIVE']) : $MENU['USERS'].' '.strtolower($TEXT['DELETED']) ;
71 1386 Luisehahne
// Insert values into the modify/remove menu
72
$template->set_block('main_block', 'list_block', 'list');
73
if($results->numRows() > 0) {
74
	// Insert first value to say please select
75
	$template->set_var('VALUE', '');
76 1492 Luisehahne
	$template->set_var('NAME', $sUserList);
77
	$template->set_var('STATUS', 'class="user-active"' );
78 1386 Luisehahne
	$template->parse('list', 'list_block', true);
79
	// Loop through users
80
	while($user = $results->fetchRow()) {
81 1478 Luisehahne
		$template->set_var('VALUE',$admin->getIDKEY($user['user_id']));
82 1492 Luisehahne
		$template->set_var('STATUS', ($user['active']==false ? 'class="user-inactive"' : 'class="user-active"') );
83 1386 Luisehahne
		$template->set_var('NAME', $user['display_name'].' ('.$user['username'].')');
84
		$template->parse('list', 'list_block', true);
85
	}
86
} else {
87
	// Insert single value to say no users were found
88
	$template->set_var('NAME', $TEXT['NONE_FOUND']);
89
	$template->parse('list', 'list_block', true);
90
}
91
92
// Insert permissions values
93
if($admin->get_permission('users_add') != true) {
94
	$template->set_var('DISPLAY_ADD', 'hide');
95
}
96
if($admin->get_permission('users_modify') != true) {
97
	$template->set_var('DISPLAY_MODIFY', 'hide');
98
}
99
if($admin->get_permission('users_delete') != true) {
100
	$template->set_var('DISPLAY_DELETE', 'hide');
101
}
102 1492 Luisehahne
$HeaderTitle = $HEADING['MODIFY_DELETE_USER'].' ';
103
$HeaderTitle .= (($iUserStatus == 1) ? strtolower($TEXT['ACTIVE']) : strtolower($TEXT['DELETED']));
104 1386 Luisehahne
// Insert language headings
105
$template->set_var(array(
106 1492 Luisehahne
		'HEADING_MODIFY_DELETE_USER' => $HeaderTitle,
107 1386 Luisehahne
		'HEADING_ADD_USER' => $HEADING['ADD_USER']
108
		)
109
);
110
// insert urls
111
$template->set_var(array(
112
		'ADMIN_URL' => ADMIN_URL,
113
		'WB_URL' => WB_URL,
114
		'THEME_URL' => THEME_URL
115
		)
116
);
117
// Insert language text and messages
118
$template->set_var(array(
119 1804 Luisehahne
		'DISPLAY_WAITING_ACTIVATION' => '',
120 1386 Luisehahne
		'TEXT_MODIFY' => $TEXT['MODIFY'],
121
		'TEXT_DELETE' => $TEXT['DELETE'],
122
		'TEXT_MANAGE_GROUPS' => ( $admin->get_permission('groups') == true ) ? $TEXT['MANAGE_GROUPS'] : "**",
123 1710 Luisehahne
		'CONFIRM_DELETE' => (($iUserStatus == 1) ? $TEXT['ARE_YOU_SURE'] : $MESSAGE['USERS_CONFIRM_DELETE'])
124 1386 Luisehahne
		)
125
);
126 1804 Luisehahne
127
$template->set_block('main_block', 'show_confirmed_activation_block', 'show_confirmed_activation');
128
if($admin->ami_group_member('1')) {
129
        $template->set_block('show_confirmed_activation_block', 'list_confirmed_activation_block', 'list_confirmed_activation');
130
    	$template->set_var('DISPLAY_WAITING_ACTIVATION', 'Users waiting for activation');
131
		$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'users` ';
132
		$sql .= 'WHERE `confirm_timeout` != 0 ';
133
        $sql .=   'AND `active` = 0 ';
134
        $sql .=   'AND `user_id` != 1 ';
135
        if( ($oRes = $database->query($sql)) ) {
136
        	$template->set_var('DISPLAY_DELETE', '');
137
//        	$template->set_var('NAME', 'User waiting for activation');
138
//        	$template->set_var('STATUS', '' );
139
        	// Loop through users
140
            if($nNumRows = $oRes->numRows()) {
141
            	while($aUser = $oRes->fetchRow(MYSQL_ASSOC)) {
142
            		$template->set_var('VALUE',$admin->getIDKEY($aUser['user_id']));
143
               		$template->set_var('STATUS', '') ;
144
            		$template->set_var('NAME', $aUser['display_name'].' ('.$aUser['username'].')');
145
            		$template->parse('list_confirmed_activation', 'list_confirmed_activation_block', true);
146
            	}
147
            	$template->parse('show_confirmed_activation', 'show_confirmed_activation_block',true);
148
            }
149
        } else { $nNumRows = 0; }
150
151
}
152
153
if ( $nNumRows == 0){
154
	$template->parse('show_confirmed_activation', '');
155
}
156
157 1386 Luisehahne
if ( $admin->get_permission('groups') == true ) $template->parse("groups", "manage_groups_block", true);
158
// Parse template object
159
$template->parse('main', 'main_block', false);
160
$template->pparse('output', 'page');
161
162 1529 Luisehahne
// Setup template object, parse vars to it, then parse it
163
// Create new template object
164 1710 Luisehahne
$template = new Template(dirname($admin->correct_theme_source('users_form.htt')),'keep');
165 1529 Luisehahne
// $template->debug = true;
166 1386 Luisehahne
$template->set_file('page', 'users_form.htt');
167
$template->set_block('page', 'main_block', 'main');
168 1710 Luisehahne
$template->set_block('main_block', 'show_modify_loginname_block', 'show_modify_loginname');
169
$template->set_block('main_block', 'show_add_loginname_block', 'show_add_loginname');
170 1386 Luisehahne
$template->set_var('DISPLAY_EXTRA', 'display:none;');
171
$template->set_var('ACTIVE_CHECKED', ' checked="checked"');
172 1804 Luisehahne
173
$template->set_var('DISPLAY_ADD', '');
174
$template->set_var('DISPLAY_MODIFY', '');
175
$template->set_var('DISABLED_CHECKED', '');
176
$template->set_var('HEADING_MODIFY_USER', '');
177
$template->set_var('DISPLAY_HOME_FOLDERS', '');
178 1386 Luisehahne
$template->set_var('ACTION_URL', ADMIN_URL.'/users/add.php');
179
$template->set_var('SUBMIT_TITLE', $TEXT['ADD']);
180
$template->set_var('FTAN', $admin->getFTAN());
181
// insert urls
182
$template->set_var(array(
183 1710 Luisehahne
		'USER_ID' => '',
184
		'USERNAME' => '',
185
		'DISPLAY_NAME' => '',
186
		'EMAIL' => '',
187 1386 Luisehahne
		'ADMIN_URL' => ADMIN_URL,
188
		'WB_URL' => WB_URL,
189
		'THEME_URL' => THEME_URL
190
		)
191
);
192
193
// Add groups to list
194
$template->set_block('main_block', 'group_list_block', 'group_list');
195
$results = $database->query("SELECT group_id, name FROM ".TABLE_PREFIX."groups WHERE group_id != '1'");
196
if($results->numRows() > 0) {
197
	$template->set_var('ID', '');
198
	$template->set_var('NAME', $TEXT['PLEASE_SELECT'].'...');
199
	$template->set_var('SELECTED', ' selected="selected"');
200
	$template->parse('group_list', 'group_list_block', true);
201
	while($group = $results->fetchRow()) {
202
		$template->set_var('ID', $group['group_id']);
203
		$template->set_var('NAME', $group['name']);
204
		$template->set_var('SELECTED', '');
205
		$template->parse('group_list', 'group_list_block', true);
206
	}
207
}
208
// Only allow the user to add a user to the Administrators group if they belong to it
209
if(in_array(1, $admin->get_groups_id())) {
210
	$users_groups = $admin->get_groups_name();
211
	$template->set_var('ID', '1');
212
	$template->set_var('NAME', $users_groups[1]);
213
	$template->set_var('SELECTED', '');
214
	$template->parse('group_list', 'group_list_block', true);
215
} else {
216
	if($results->numRows() == 0) {
217
		$template->set_var('ID', '');
218
		$template->set_var('NAME', $TEXT['NONE_FOUND']);
219
		$template->parse('group_list', 'group_list_block', true);
220
	}
221
}
222
223
// Insert permissions values
224
if($admin->get_permission('users_add') != true) {
225
	$template->set_var('DISPLAY_ADD', 'hide');
226
}
227
228
// Generate username field name
229
$username_fieldname = 'username_';
230
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
231
srand((double)microtime()*1000000);
232
$i = 0;
233
while ($i <= 7) {
234
	$num = rand() % 33;
235
	$tmp = substr($salt, $num, 1);
236
	$username_fieldname = $username_fieldname . $tmp;
237
	$i++;
238
}
239
240
// Work-out if home folder should be shown
241
if(!HOME_FOLDERS) {
242
	$template->set_var('DISPLAY_HOME_FOLDERS', 'display:none;');
243
}
244
245
// Include the WB functions file
246
require_once(WB_PATH.'/framework/functions.php');
247
248
// Add media folders to home folder list
249
$template->set_block('main_block', 'folder_list_block', 'folder_list');
250
foreach(directory_list(WB_PATH.MEDIA_DIRECTORY) AS $name) {
251
	$template->set_var('NAME', str_replace(WB_PATH, '', $name));
252
	$template->set_var('FOLDER', str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name));
253
	$template->set_var('SELECTED', ' ');
254
	$template->parse('folder_list', 'folder_list_block', true);
255
}
256
257
// Insert language text and messages
258
$template->set_var(array(
259 1492 Luisehahne
			'TEXT_CANCEL' => $TEXT['CANCEL'],
260 1386 Luisehahne
			'TEXT_RESET' => $TEXT['RESET'],
261
			'TEXT_ACTIVE' => $TEXT['ACTIVE'],
262
			'TEXT_DISABLED' => $TEXT['DISABLED'],
263
			'TEXT_PLEASE_SELECT' => $TEXT['PLEASE_SELECT'],
264
			'TEXT_USERNAME' => $TEXT['USERNAME'],
265
			'TEXT_PASSWORD' => $TEXT['PASSWORD'],
266
			'TEXT_RETYPE_PASSWORD' => $TEXT['RETYPE_PASSWORD'],
267
			'TEXT_DISPLAY_NAME' => $TEXT['DISPLAY_NAME'],
268
			'TEXT_EMAIL' => $TEXT['EMAIL'],
269
			'TEXT_GROUP' => $TEXT['GROUP'],
270
			'TEXT_NONE' => $TEXT['NONE'],
271
			'TEXT_HOME_FOLDER' => $TEXT['HOME_FOLDER'],
272
			'USERNAME_FIELDNAME' => $username_fieldname,
273 1710 Luisehahne
			'CHANGING_PASSWORD' => $MESSAGE['USERS_CHANGING_PASSWORD']
274 1386 Luisehahne
			)
275
	);
276
277
// Parse template for add user form
278 1710 Luisehahne
$template->parse('show_modify_loginname', '', true);
279
$template->parse('show_add_loginname', 'show_add_loginname_block', true);
280 1386 Luisehahne
$template->parse('main', 'main_block', false);
281
$template->pparse('output', 'page');
282
283
$admin->print_footer();