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
*/
17
18
require('../../config.php');
19
require_once(WB_PATH.'/framework/class.admin.php');
20
$admin = new admin('Access', 'users');
21
22 1492 Luisehahne
$iUserStatus = 1;
23
$iUserStatus = ( ( $admin->get_get('status')==1 ) ? 0 : $iUserStatus );
24
unset($_GET);
25
26 1529 Luisehahne
// Setup template object, parse vars to it, then parse it
27
// Create new template object
28 1710 Luisehahne
$template = new Template(dirname($admin->correct_theme_source('users.htt')),'keep');
29 1529 Luisehahne
// $template->debug = true;
30
31 1386 Luisehahne
$template->set_file('page', 'users.htt');
32
$template->set_block('page', 'main_block', 'main');
33
$template->set_block("main_block", "manage_groups_block", "groups");
34
$template->set_var('ADMIN_URL', ADMIN_URL);
35 1475 Luisehahne
$template->set_var('FTAN', $admin->getFTAN());
36 1492 Luisehahne
$template->set_var('USER_STATUS', $iUserStatus );
37 1386 Luisehahne
38 1492 Luisehahne
$UserStatusActive = 'url('.THEME_URL.'/images/user.png)';
39
$UserStatusInactive = 'url('.THEME_URL.'/images/user_red.png)';
40
41
$sUserTitle = ($iUserStatus == 0) ? $MENU['USERS'].' '.strtolower($TEXT['ACTIVE']) : $MENU['USERS'].' '.strtolower($TEXT['DELETED']) ;
42
43
$template->set_var('TEXT_USERS', $sUserTitle.' '.$TEXT['SHOW'] );
44
$template->set_var('STATUS_ICON', ( ($iUserStatus==0) ? $UserStatusActive : $UserStatusInactive) );
45
46 1386 Luisehahne
// Get existing value from database
47 1492 Luisehahne
$sql  = 'SELECT `user_id`, `username`, `display_name`, `active` FROM `'.TABLE_PREFIX.'users` ' ;
48
$sql .= 'WHERE user_id != 1 ';
49
$sql .=     'AND active = '.$iUserStatus.' ';
50
$sql .= 'ORDER BY `display_name`,`username`';
51
52 1484 Luisehahne
$query = "SELECT user_id, username, display_name, active FROM ".TABLE_PREFIX."users WHERE user_id != '1' ORDER BY display_name,username";
53 1492 Luisehahne
$results = $database->query($sql);
54 1386 Luisehahne
if($database->is_error()) {
55
	$admin->print_error($database->get_error(), 'index.php');
56
}
57
58 1492 Luisehahne
$sUserList  = $TEXT['LIST_OPTIONS'].' ';
59
$sUserList .= ($iUserStatus == 1) ? $MENU['USERS'].' '.strtolower($TEXT['ACTIVE']) : $MENU['USERS'].' '.strtolower($TEXT['DELETED']) ;
60 1386 Luisehahne
// Insert values into the modify/remove menu
61
$template->set_block('main_block', 'list_block', 'list');
62
if($results->numRows() > 0) {
63
	// Insert first value to say please select
64
	$template->set_var('VALUE', '');
65 1492 Luisehahne
	$template->set_var('NAME', $sUserList);
66
	$template->set_var('STATUS', 'class="user-active"' );
67 1386 Luisehahne
	$template->parse('list', 'list_block', true);
68
	// Loop through users
69
	while($user = $results->fetchRow()) {
70 1478 Luisehahne
		$template->set_var('VALUE',$admin->getIDKEY($user['user_id']));
71 1492 Luisehahne
		$template->set_var('STATUS', ($user['active']==false ? 'class="user-inactive"' : 'class="user-active"') );
72 1386 Luisehahne
		$template->set_var('NAME', $user['display_name'].' ('.$user['username'].')');
73
		$template->parse('list', 'list_block', true);
74
	}
75
} else {
76
	// Insert single value to say no users were found
77
	$template->set_var('NAME', $TEXT['NONE_FOUND']);
78
	$template->parse('list', 'list_block', true);
79
}
80
81
// Insert permissions values
82
if($admin->get_permission('users_add') != true) {
83
	$template->set_var('DISPLAY_ADD', 'hide');
84
}
85
if($admin->get_permission('users_modify') != true) {
86
	$template->set_var('DISPLAY_MODIFY', 'hide');
87
}
88
if($admin->get_permission('users_delete') != true) {
89
	$template->set_var('DISPLAY_DELETE', 'hide');
90
}
91 1492 Luisehahne
$HeaderTitle = $HEADING['MODIFY_DELETE_USER'].' ';
92
$HeaderTitle .= (($iUserStatus == 1) ? strtolower($TEXT['ACTIVE']) : strtolower($TEXT['DELETED']));
93 1386 Luisehahne
// Insert language headings
94
$template->set_var(array(
95 1492 Luisehahne
		'HEADING_MODIFY_DELETE_USER' => $HeaderTitle,
96 1386 Luisehahne
		'HEADING_ADD_USER' => $HEADING['ADD_USER']
97
		)
98
);
99
// insert urls
100
$template->set_var(array(
101
		'ADMIN_URL' => ADMIN_URL,
102
		'WB_URL' => WB_URL,
103
		'THEME_URL' => THEME_URL
104
		)
105
);
106
// Insert language text and messages
107
$template->set_var(array(
108
		'TEXT_MODIFY' => $TEXT['MODIFY'],
109
		'TEXT_DELETE' => $TEXT['DELETE'],
110
		'TEXT_MANAGE_GROUPS' => ( $admin->get_permission('groups') == true ) ? $TEXT['MANAGE_GROUPS'] : "**",
111 1710 Luisehahne
		'CONFIRM_DELETE' => (($iUserStatus == 1) ? $TEXT['ARE_YOU_SURE'] : $MESSAGE['USERS_CONFIRM_DELETE'])
112 1386 Luisehahne
		)
113
);
114
if ( $admin->get_permission('groups') == true ) $template->parse("groups", "manage_groups_block", true);
115
// Parse template object
116
$template->parse('main', 'main_block', false);
117
$template->pparse('output', 'page');
118
119 1529 Luisehahne
// Setup template object, parse vars to it, then parse it
120
// Create new template object
121 1710 Luisehahne
$template = new Template(dirname($admin->correct_theme_source('users_form.htt')),'keep');
122 1529 Luisehahne
// $template->debug = true;
123 1386 Luisehahne
$template->set_file('page', 'users_form.htt');
124
$template->set_block('page', 'main_block', 'main');
125 1710 Luisehahne
$template->set_block('main_block', 'show_modify_loginname_block', 'show_modify_loginname');
126
$template->set_block('main_block', 'show_add_loginname_block', 'show_add_loginname');
127 1386 Luisehahne
$template->set_var('DISPLAY_EXTRA', 'display:none;');
128
$template->set_var('ACTIVE_CHECKED', ' checked="checked"');
129
$template->set_var('ACTION_URL', ADMIN_URL.'/users/add.php');
130
$template->set_var('SUBMIT_TITLE', $TEXT['ADD']);
131
$template->set_var('FTAN', $admin->getFTAN());
132
// insert urls
133
$template->set_var(array(
134 1710 Luisehahne
		'USER_ID' => '',
135
		'USERNAME' => '',
136
		'DISPLAY_NAME' => '',
137
		'EMAIL' => '',
138 1386 Luisehahne
		'ADMIN_URL' => ADMIN_URL,
139
		'WB_URL' => WB_URL,
140
		'THEME_URL' => THEME_URL
141
		)
142
);
143
144
// Add groups to list
145
$template->set_block('main_block', 'group_list_block', 'group_list');
146
$results = $database->query("SELECT group_id, name FROM ".TABLE_PREFIX."groups WHERE group_id != '1'");
147
if($results->numRows() > 0) {
148
	$template->set_var('ID', '');
149
	$template->set_var('NAME', $TEXT['PLEASE_SELECT'].'...');
150
	$template->set_var('SELECTED', ' selected="selected"');
151
	$template->parse('group_list', 'group_list_block', true);
152
	while($group = $results->fetchRow()) {
153
		$template->set_var('ID', $group['group_id']);
154
		$template->set_var('NAME', $group['name']);
155
		$template->set_var('SELECTED', '');
156
		$template->parse('group_list', 'group_list_block', true);
157
	}
158
}
159
// Only allow the user to add a user to the Administrators group if they belong to it
160
if(in_array(1, $admin->get_groups_id())) {
161
	$users_groups = $admin->get_groups_name();
162
	$template->set_var('ID', '1');
163
	$template->set_var('NAME', $users_groups[1]);
164
	$template->set_var('SELECTED', '');
165
	$template->parse('group_list', 'group_list_block', true);
166
} else {
167
	if($results->numRows() == 0) {
168
		$template->set_var('ID', '');
169
		$template->set_var('NAME', $TEXT['NONE_FOUND']);
170
		$template->parse('group_list', 'group_list_block', true);
171
	}
172
}
173
174
// Insert permissions values
175
if($admin->get_permission('users_add') != true) {
176
	$template->set_var('DISPLAY_ADD', 'hide');
177
}
178
179
// Generate username field name
180
$username_fieldname = 'username_';
181
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
182
srand((double)microtime()*1000000);
183
$i = 0;
184
while ($i <= 7) {
185
	$num = rand() % 33;
186
	$tmp = substr($salt, $num, 1);
187
	$username_fieldname = $username_fieldname . $tmp;
188
	$i++;
189
}
190
191
// Work-out if home folder should be shown
192
if(!HOME_FOLDERS) {
193
	$template->set_var('DISPLAY_HOME_FOLDERS', 'display:none;');
194
}
195
196
// Include the WB functions file
197
require_once(WB_PATH.'/framework/functions.php');
198
199
// Add media folders to home folder list
200
$template->set_block('main_block', 'folder_list_block', 'folder_list');
201
foreach(directory_list(WB_PATH.MEDIA_DIRECTORY) AS $name) {
202
	$template->set_var('NAME', str_replace(WB_PATH, '', $name));
203
	$template->set_var('FOLDER', str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name));
204
	$template->set_var('SELECTED', ' ');
205
	$template->parse('folder_list', 'folder_list_block', true);
206
}
207
208
// Insert language text and messages
209
$template->set_var(array(
210 1492 Luisehahne
			'TEXT_CANCEL' => $TEXT['CANCEL'],
211 1386 Luisehahne
			'TEXT_RESET' => $TEXT['RESET'],
212
			'TEXT_ACTIVE' => $TEXT['ACTIVE'],
213
			'TEXT_DISABLED' => $TEXT['DISABLED'],
214
			'TEXT_PLEASE_SELECT' => $TEXT['PLEASE_SELECT'],
215
			'TEXT_USERNAME' => $TEXT['USERNAME'],
216
			'TEXT_PASSWORD' => $TEXT['PASSWORD'],
217
			'TEXT_RETYPE_PASSWORD' => $TEXT['RETYPE_PASSWORD'],
218
			'TEXT_DISPLAY_NAME' => $TEXT['DISPLAY_NAME'],
219
			'TEXT_EMAIL' => $TEXT['EMAIL'],
220
			'TEXT_GROUP' => $TEXT['GROUP'],
221
			'TEXT_NONE' => $TEXT['NONE'],
222
			'TEXT_HOME_FOLDER' => $TEXT['HOME_FOLDER'],
223
			'USERNAME_FIELDNAME' => $username_fieldname,
224 1710 Luisehahne
			'CHANGING_PASSWORD' => $MESSAGE['USERS_CHANGING_PASSWORD']
225 1386 Luisehahne
			)
226
	);
227
228
// Parse template for add user form
229 1710 Luisehahne
$template->parse('show_modify_loginname', '', true);
230
$template->parse('show_add_loginname', 'show_add_loginname_block', true);
231 1386 Luisehahne
$template->parse('main', 'main_block', false);
232
$template->pparse('output', 'page');
233
234
$admin->print_footer();