Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         users
6
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       2009-2011, Website Baker 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 1529 2011-11-25 05:03:32Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/users/index.php $
14
 * @lastmodified    $Date: 2011-11-25 06:03:32 +0100 (Fri, 25 Nov 2011) $
15
 *
16
*/
17

    
18
require('../../config.php');
19
require_once(WB_PATH.'/framework/class.admin.php');
20
$admin = new admin('Access', 'users');
21

    
22
$iUserStatus = 1;
23
$iUserStatus = ( ( $admin->get_get('status')==1 ) ? 0 : $iUserStatus );
24
unset($_GET);
25

    
26
// Setup template object, parse vars to it, then parse it
27
$ThemePath = realpath(WB_PATH.$admin->correct_theme_source('users.htt'));
28
// Create new template object
29
$template = new Template($ThemePath);
30
// $template->debug = true;
31

    
32
$template->set_file('page', 'users.htt');
33
$template->set_block('page', 'main_block', 'main');
34
$template->set_block("main_block", "manage_groups_block", "groups");
35
$template->set_var('ADMIN_URL', ADMIN_URL);
36
$template->set_var('FTAN', $admin->getFTAN());
37
$template->set_var('USER_STATUS', $iUserStatus );
38

    
39
$UserStatusActive = 'url('.THEME_URL.'/images/user.png)';
40
$UserStatusInactive = 'url('.THEME_URL.'/images/user_red.png)';
41

    
42
$sUserTitle = ($iUserStatus == 0) ? $MENU['USERS'].' '.strtolower($TEXT['ACTIVE']) : $MENU['USERS'].' '.strtolower($TEXT['DELETED']) ;
43

    
44
$template->set_var('TEXT_USERS', $sUserTitle.' '.$TEXT['SHOW'] );
45
$template->set_var('STATUS_ICON', ( ($iUserStatus==0) ? $UserStatusActive : $UserStatusInactive) );
46

    
47
// Get existing value from database
48
$sql  = 'SELECT `user_id`, `username`, `display_name`, `active` FROM `'.TABLE_PREFIX.'users` ' ;
49
$sql .= 'WHERE user_id != 1 ';
50
$sql .=     'AND active = '.$iUserStatus.' ';
51
$sql .= 'ORDER BY `display_name`,`username`';
52

    
53
$query = "SELECT user_id, username, display_name, active FROM ".TABLE_PREFIX."users WHERE user_id != '1' ORDER BY display_name,username";
54
$results = $database->query($sql);
55
if($database->is_error()) {
56
	$admin->print_error($database->get_error(), 'index.php');
57
}
58

    
59
$sUserList  = $TEXT['LIST_OPTIONS'].' ';
60
$sUserList .= ($iUserStatus == 1) ? $MENU['USERS'].' '.strtolower($TEXT['ACTIVE']) : $MENU['USERS'].' '.strtolower($TEXT['DELETED']) ;
61
// Insert values into the modify/remove menu
62
$template->set_block('main_block', 'list_block', 'list');
63
if($results->numRows() > 0) {
64
	// Insert first value to say please select
65
	$template->set_var('VALUE', '');
66
	$template->set_var('NAME', $sUserList);
67
	$template->set_var('STATUS', 'class="user-active"' );
68
	$template->parse('list', 'list_block', true);
69
	// Loop through users
70
	while($user = $results->fetchRow()) {
71
		$template->set_var('VALUE',$admin->getIDKEY($user['user_id']));
72
		$template->set_var('STATUS', ($user['active']==false ? 'class="user-inactive"' : 'class="user-active"') );
73
		$template->set_var('NAME', $user['display_name'].' ('.$user['username'].')');
74
		$template->parse('list', 'list_block', true);
75
	}
76
} else {
77
	// Insert single value to say no users were found
78
	$template->set_var('NAME', $TEXT['NONE_FOUND']);
79
	$template->parse('list', 'list_block', true);
80
}
81

    
82
// Insert permissions values
83
if($admin->get_permission('users_add') != true) {
84
	$template->set_var('DISPLAY_ADD', 'hide');
85
}
86
if($admin->get_permission('users_modify') != true) {
87
	$template->set_var('DISPLAY_MODIFY', 'hide');
88
}
89
if($admin->get_permission('users_delete') != true) {
90
	$template->set_var('DISPLAY_DELETE', 'hide');
91
}
92
$HeaderTitle = $HEADING['MODIFY_DELETE_USER'].' ';
93
$HeaderTitle .= (($iUserStatus == 1) ? strtolower($TEXT['ACTIVE']) : strtolower($TEXT['DELETED']));
94
// Insert language headings
95
$template->set_var(array(
96
		'HEADING_MODIFY_DELETE_USER' => $HeaderTitle,
97
		'HEADING_ADD_USER' => $HEADING['ADD_USER']
98
		)
99
);
100
// insert urls
101
$template->set_var(array(
102
		'ADMIN_URL' => ADMIN_URL,
103
		'WB_URL' => WB_URL,
104
		'THEME_URL' => THEME_URL
105
		)
106
);
107
// Insert language text and messages
108
$template->set_var(array(
109
		'TEXT_MODIFY' => $TEXT['MODIFY'],
110
		'TEXT_DELETE' => $TEXT['DELETE'],
111
		'TEXT_MANAGE_GROUPS' => ( $admin->get_permission('groups') == true ) ? $TEXT['MANAGE_GROUPS'] : "**",
112
		'CONFIRM_DELETE' => (($iUserStatus == 1) ? $TEXT['ARE_YOU_SURE'] : $MESSAGE['USERS']['CONFIRM_DELETE'])
113
		)
114
);
115
if ( $admin->get_permission('groups') == true ) $template->parse("groups", "manage_groups_block", true);
116
// Parse template object
117
$template->parse('main', 'main_block', false);
118
$template->pparse('output', 'page');
119

    
120
// Setup template object, parse vars to it, then parse it
121
$ThemePath = realpath(WB_PATH.$admin->correct_theme_source('users_form.htt'));
122
// Create new template object
123
$template = new Template($ThemePath);
124
// $template->debug = true;
125
$template->set_file('page', 'users_form.htt');
126
$template->set_block('page', 'main_block', 'main');
127
$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
		'ADMIN_URL' => ADMIN_URL,
135
		'WB_URL' => WB_URL,
136
		'THEME_URL' => THEME_URL
137
		)
138
);
139

    
140
// Add groups to list
141
$template->set_block('main_block', 'group_list_block', 'group_list');
142
$results = $database->query("SELECT group_id, name FROM ".TABLE_PREFIX."groups WHERE group_id != '1'");
143
if($results->numRows() > 0) {
144
	$template->set_var('ID', '');
145
	$template->set_var('NAME', $TEXT['PLEASE_SELECT'].'...');
146
	$template->set_var('SELECTED', ' selected="selected"');
147
	$template->parse('group_list', 'group_list_block', true);
148
	while($group = $results->fetchRow()) {
149
		$template->set_var('ID', $group['group_id']);
150
		$template->set_var('NAME', $group['name']);
151
		$template->set_var('SELECTED', '');
152
		$template->parse('group_list', 'group_list_block', true);
153
	}
154
}
155
// Only allow the user to add a user to the Administrators group if they belong to it
156
if(in_array(1, $admin->get_groups_id())) {
157
	$users_groups = $admin->get_groups_name();
158
	$template->set_var('ID', '1');
159
	$template->set_var('NAME', $users_groups[1]);
160
	$template->set_var('SELECTED', '');
161
	$template->parse('group_list', 'group_list_block', true);
162
} else {
163
	if($results->numRows() == 0) {
164
		$template->set_var('ID', '');
165
		$template->set_var('NAME', $TEXT['NONE_FOUND']);
166
		$template->parse('group_list', 'group_list_block', true);
167
	}
168
}
169

    
170
// Insert permissions values
171
if($admin->get_permission('users_add') != true) {
172
	$template->set_var('DISPLAY_ADD', 'hide');
173
}
174

    
175
// Generate username field name
176
$username_fieldname = 'username_';
177
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
178
srand((double)microtime()*1000000);
179
$i = 0;
180
while ($i <= 7) {
181
	$num = rand() % 33;
182
	$tmp = substr($salt, $num, 1);
183
	$username_fieldname = $username_fieldname . $tmp;
184
	$i++;
185
}
186

    
187
// Work-out if home folder should be shown
188
if(!HOME_FOLDERS) {
189
	$template->set_var('DISPLAY_HOME_FOLDERS', 'display:none;');
190
}
191

    
192
// Include the WB functions file
193
require_once(WB_PATH.'/framework/functions.php');
194

    
195
// Add media folders to home folder list
196
$template->set_block('main_block', 'folder_list_block', 'folder_list');
197
foreach(directory_list(WB_PATH.MEDIA_DIRECTORY) AS $name) {
198
	$template->set_var('NAME', str_replace(WB_PATH, '', $name));
199
	$template->set_var('FOLDER', str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name));
200
	$template->set_var('SELECTED', ' ');
201
	$template->parse('folder_list', 'folder_list_block', true);
202
}
203

    
204
// Insert language text and messages
205
$template->set_var(array(
206
			'TEXT_CANCEL' => $TEXT['CANCEL'],
207
			'TEXT_RESET' => $TEXT['RESET'],
208
			'TEXT_ACTIVE' => $TEXT['ACTIVE'],
209
			'TEXT_DISABLED' => $TEXT['DISABLED'],
210
			'TEXT_PLEASE_SELECT' => $TEXT['PLEASE_SELECT'],
211
			'TEXT_USERNAME' => $TEXT['USERNAME'],
212
			'TEXT_PASSWORD' => $TEXT['PASSWORD'],
213
			'TEXT_RETYPE_PASSWORD' => $TEXT['RETYPE_PASSWORD'],
214
			'TEXT_DISPLAY_NAME' => $TEXT['DISPLAY_NAME'],
215
			'TEXT_EMAIL' => $TEXT['EMAIL'],
216
			'TEXT_GROUP' => $TEXT['GROUP'],
217
			'TEXT_NONE' => $TEXT['NONE'],
218
			'TEXT_HOME_FOLDER' => $TEXT['HOME_FOLDER'],
219
			'USERNAME_FIELDNAME' => $username_fieldname,
220
			'CHANGING_PASSWORD' => $MESSAGE['USERS']['CHANGING_PASSWORD']
221
			)
222
	);
223

    
224
// Parse template for add user form
225
$template->parse('main', 'main_block', false);
226
$template->pparse('output', 'page');
227

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