Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         users
6
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8
 * @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: index.php 1805 2012-11-04 00:53:51Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/users/index.php $
14
 * @lastmodified    $Date: 2012-11-04 01:53:51 +0100 (Sun, 04 Nov 2012) $
15
 *
16
 */
17

    
18
$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
$admin = new admin('Access', 'users');
27

    
28
$iUserStatus = 1;
29
$iUserStatus = ( ( $admin->get_get('status')==1 ) ? 0 : $iUserStatus );
30
unset($_GET);
31

    
32
// Setup template object, parse vars to it, then parse it
33
// Create new template object
34
$template = new Template(dirname($admin->correct_theme_source('users.htt')),'keep');
35
// $template->debug = true;
36

    
37
$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
$template->set_var('FTAN', $admin->getFTAN());
42
$template->set_var('USER_STATUS', $iUserStatus );
43
$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

    
49
$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
// Get existing value from database
58
$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
$query = "SELECT user_id, username, display_name, active FROM ".TABLE_PREFIX."users WHERE user_id != '1' ORDER BY display_name,username";
64
$results = $database->query($sql);
65
if($database->is_error()) {
66
	$admin->print_error($database->get_error(), 'index.php');
67
}
68

    
69
$sUserList  = $TEXT['LIST_OPTIONS'].' ';
70
$sUserList .= ($iUserStatus == 1) ? $MENU['USERS'].' '.strtolower($TEXT['ACTIVE']) : $MENU['USERS'].' '.strtolower($TEXT['DELETED']) ;
71
// 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
	$template->set_var('NAME', $sUserList);
77
	$template->set_var('STATUS', 'class="user-active"' );
78
	$template->parse('list', 'list_block', true);
79
	// Loop through users
80
	while($user = $results->fetchRow(MYSQL_ASSOC)) {
81
		$template->set_var('VALUE',$admin->getIDKEY($user['user_id']));
82
		$template->set_var('STATUS', ($user['active']==false ? 'class="user-inactive"' : 'class="user-active"') );
83
		$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
$HeaderTitle = $HEADING['MODIFY_DELETE_USER'].' ';
103
$HeaderTitle .= (($iUserStatus == 1) ? strtolower($TEXT['ACTIVE']) : strtolower($TEXT['DELETED']));
104
// Insert language headings
105
$template->set_var(array(
106
		'HEADING_MODIFY_DELETE_USER' => $HeaderTitle,
107
		'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
		'DISPLAY_WAITING_ACTIVATION' => '',
120
		'TEXT_MODIFY' => $TEXT['MODIFY'],
121
		'TEXT_DELETE' => $TEXT['DELETE'],
122
		'TEXT_MANAGE_GROUPS' => ( $admin->get_permission('groups') == true ) ? $TEXT['MANAGE_GROUPS'] : "**",
123
		'CONFIRM_DELETE' => (($iUserStatus == 1) ? $TEXT['ARE_YOU_SURE'] : $MESSAGE['USERS_CONFIRM_DELETE'])
124
		)
125
);
126

    
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'].')'.' ['.$aUser['email'].']');
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
} else {
152
$nNumRows = 0;
153
}
154

    
155
if ( $nNumRows == 0){
156
	$template->parse('show_confirmed_activation', '');
157
}
158

    
159
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
// Setup template object, parse vars to it, then parse it
165
// Create new template object
166
$template = new Template(dirname($admin->correct_theme_source('users_form.htt')),'keep');
167
// $template->debug = true;
168
$template->set_file('page', 'users_form.htt');
169
$template->set_block('page', 'main_block', 'main');
170
$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
$template->set_var('DISPLAY_EXTRA', 'display:none;');
173
$template->set_var('ACTIVE_CHECKED', ' checked="checked"');
174

    
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
$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
		'USER_ID' => '',
186
		'USERNAME' => '',
187
		'DISPLAY_NAME' => '',
188
		'EMAIL' => '',
189
		'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
			'TEXT_CANCEL' => $TEXT['CANCEL'],
262
			'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
			'CHANGING_PASSWORD' => $MESSAGE['USERS_CHANGING_PASSWORD']
276
			)
277
	);
278

    
279
// Parse template for add user form
280
$template->parse('show_modify_loginname', '', true);
281
$template->parse('show_add_loginname', 'show_add_loginname_block', true);
282
$template->parse('main', 'main_block', false);
283
$template->pparse('output', 'page');
284

    
285
$admin->print_footer();
(2-2/4)