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 1805 Luisehahne
	while($user = $results->fetchRow(MYSQL_ASSOC)) {
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 1805 Luisehahne
            		$template->set_var('NAME', $aUser['display_name'].' ('.$aUser['username'].')'.' ['.$aUser['email'].']');
145 1804 Luisehahne
            		$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 1805 Luisehahne
} else {
152
$nNumRows = 0;
153 1804 Luisehahne
}
154
155
if ( $nNumRows == 0){
156
	$template->parse('show_confirmed_activation', '');
157
}
158
159 1386 Luisehahne
if ( $admin->get_permission('groups') == true ) $template->parse("groups", "manage_groups_block", true);
160
// Parse template object
161
$template->parse('main', 'main_block', false);
162
$template->pparse('output', 'page');
163
164 1529 Luisehahne
// Setup template object, parse vars to it, then parse it
165
// Create new template object
166 1710 Luisehahne
$template = new Template(dirname($admin->correct_theme_source('users_form.htt')),'keep');
167 1529 Luisehahne
// $template->debug = true;
168 1386 Luisehahne
$template->set_file('page', 'users_form.htt');
169
$template->set_block('page', 'main_block', 'main');
170 1710 Luisehahne
$template->set_block('main_block', 'show_modify_loginname_block', 'show_modify_loginname');
171
$template->set_block('main_block', 'show_add_loginname_block', 'show_add_loginname');
172 1386 Luisehahne
$template->set_var('DISPLAY_EXTRA', 'display:none;');
173
$template->set_var('ACTIVE_CHECKED', ' checked="checked"');
174 1804 Luisehahne
175
$template->set_var('DISPLAY_ADD', '');
176
$template->set_var('DISPLAY_MODIFY', '');
177
$template->set_var('DISABLED_CHECKED', '');
178
$template->set_var('HEADING_MODIFY_USER', '');
179
$template->set_var('DISPLAY_HOME_FOLDERS', '');
180 1386 Luisehahne
$template->set_var('ACTION_URL', ADMIN_URL.'/users/add.php');
181
$template->set_var('SUBMIT_TITLE', $TEXT['ADD']);
182
$template->set_var('FTAN', $admin->getFTAN());
183
// insert urls
184
$template->set_var(array(
185 1710 Luisehahne
		'USER_ID' => '',
186
		'USERNAME' => '',
187
		'DISPLAY_NAME' => '',
188
		'EMAIL' => '',
189 1386 Luisehahne
		'ADMIN_URL' => ADMIN_URL,
190
		'WB_URL' => WB_URL,
191
		'THEME_URL' => THEME_URL
192
		)
193
);
194
195
// Add groups to list
196
$template->set_block('main_block', 'group_list_block', 'group_list');
197
$results = $database->query("SELECT group_id, name FROM ".TABLE_PREFIX."groups WHERE group_id != '1'");
198
if($results->numRows() > 0) {
199
	$template->set_var('ID', '');
200
	$template->set_var('NAME', $TEXT['PLEASE_SELECT'].'...');
201
	$template->set_var('SELECTED', ' selected="selected"');
202
	$template->parse('group_list', 'group_list_block', true);
203
	while($group = $results->fetchRow()) {
204
		$template->set_var('ID', $group['group_id']);
205
		$template->set_var('NAME', $group['name']);
206
		$template->set_var('SELECTED', '');
207
		$template->parse('group_list', 'group_list_block', true);
208
	}
209
}
210
// Only allow the user to add a user to the Administrators group if they belong to it
211
if(in_array(1, $admin->get_groups_id())) {
212
	$users_groups = $admin->get_groups_name();
213
	$template->set_var('ID', '1');
214
	$template->set_var('NAME', $users_groups[1]);
215
	$template->set_var('SELECTED', '');
216
	$template->parse('group_list', 'group_list_block', true);
217
} else {
218
	if($results->numRows() == 0) {
219
		$template->set_var('ID', '');
220
		$template->set_var('NAME', $TEXT['NONE_FOUND']);
221
		$template->parse('group_list', 'group_list_block', true);
222
	}
223
}
224
225
// Insert permissions values
226
if($admin->get_permission('users_add') != true) {
227
	$template->set_var('DISPLAY_ADD', 'hide');
228
}
229
230
// Generate username field name
231
$username_fieldname = 'username_';
232
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
233
srand((double)microtime()*1000000);
234
$i = 0;
235
while ($i <= 7) {
236
	$num = rand() % 33;
237
	$tmp = substr($salt, $num, 1);
238
	$username_fieldname = $username_fieldname . $tmp;
239
	$i++;
240
}
241
242
// Work-out if home folder should be shown
243
if(!HOME_FOLDERS) {
244
	$template->set_var('DISPLAY_HOME_FOLDERS', 'display:none;');
245
}
246
247
// Include the WB functions file
248
require_once(WB_PATH.'/framework/functions.php');
249
250
// Add media folders to home folder list
251
$template->set_block('main_block', 'folder_list_block', 'folder_list');
252
foreach(directory_list(WB_PATH.MEDIA_DIRECTORY) AS $name) {
253
	$template->set_var('NAME', str_replace(WB_PATH, '', $name));
254
	$template->set_var('FOLDER', str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name));
255
	$template->set_var('SELECTED', ' ');
256
	$template->parse('folder_list', 'folder_list_block', true);
257
}
258
259
// Insert language text and messages
260
$template->set_var(array(
261 1492 Luisehahne
			'TEXT_CANCEL' => $TEXT['CANCEL'],
262 1386 Luisehahne
			'TEXT_RESET' => $TEXT['RESET'],
263
			'TEXT_ACTIVE' => $TEXT['ACTIVE'],
264
			'TEXT_DISABLED' => $TEXT['DISABLED'],
265
			'TEXT_PLEASE_SELECT' => $TEXT['PLEASE_SELECT'],
266
			'TEXT_USERNAME' => $TEXT['USERNAME'],
267
			'TEXT_PASSWORD' => $TEXT['PASSWORD'],
268
			'TEXT_RETYPE_PASSWORD' => $TEXT['RETYPE_PASSWORD'],
269
			'TEXT_DISPLAY_NAME' => $TEXT['DISPLAY_NAME'],
270
			'TEXT_EMAIL' => $TEXT['EMAIL'],
271
			'TEXT_GROUP' => $TEXT['GROUP'],
272
			'TEXT_NONE' => $TEXT['NONE'],
273
			'TEXT_HOME_FOLDER' => $TEXT['HOME_FOLDER'],
274
			'USERNAME_FIELDNAME' => $username_fieldname,
275 1710 Luisehahne
			'CHANGING_PASSWORD' => $MESSAGE['USERS_CHANGING_PASSWORD']
276 1386 Luisehahne
			)
277
	);
278
279
// Parse template for add user form
280 1710 Luisehahne
$template->parse('show_modify_loginname', '', true);
281
$template->parse('show_add_loginname', 'show_add_loginname_block', true);
282 1386 Luisehahne
$template->parse('main', 'main_block', false);
283
$template->pparse('output', 'page');
284
285
$admin->print_footer();