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 1804 2012-11-01 22:50:49Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/users/index.php $
14
 * @lastmodified    $Date: 2012-11-01 23:50:49 +0100 (Thu, 01 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()) {
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'].')');
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
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
// Setup template object, parse vars to it, then parse it
163
// Create new template object
164
$template = new Template(dirname($admin->correct_theme_source('users_form.htt')),'keep');
165
// $template->debug = true;
166
$template->set_file('page', 'users_form.htt');
167
$template->set_block('page', 'main_block', 'main');
168
$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
$template->set_var('DISPLAY_EXTRA', 'display:none;');
171
$template->set_var('ACTIVE_CHECKED', ' checked="checked"');
172

    
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
$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
		'USER_ID' => '',
184
		'USERNAME' => '',
185
		'DISPLAY_NAME' => '',
186
		'EMAIL' => '',
187
		'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
			'TEXT_CANCEL' => $TEXT['CANCEL'],
260
			'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
			'CHANGING_PASSWORD' => $MESSAGE['USERS_CHANGING_PASSWORD']
274
			)
275
	);
276

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

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