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 1625 2012-02-29 00:50:57Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/users/index.php $
14
 * @lastmodified    $Date: 2012-02-29 01:50:57 +0100 (Wed, 29 Feb 2012) $
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
// Create new template object
28
$template = new Template(dirname($admin->correct_theme_source('users.htt')));
29
// $template->debug = true;
30

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

    
38
$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
// Get existing value from database
47
$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
$query = "SELECT user_id, username, display_name, active FROM ".TABLE_PREFIX."users WHERE user_id != '1' ORDER BY display_name,username";
53
$results = $database->query($sql);
54
if($database->is_error()) {
55
	$admin->print_error($database->get_error(), 'index.php');
56
}
57

    
58
$sUserList  = $TEXT['LIST_OPTIONS'].' ';
59
$sUserList .= ($iUserStatus == 1) ? $MENU['USERS'].' '.strtolower($TEXT['ACTIVE']) : $MENU['USERS'].' '.strtolower($TEXT['DELETED']) ;
60
// 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
	$template->set_var('NAME', $sUserList);
66
	$template->set_var('STATUS', 'class="user-active"' );
67
	$template->parse('list', 'list_block', true);
68
	// Loop through users
69
	while($user = $results->fetchRow()) {
70
		$template->set_var('VALUE',$admin->getIDKEY($user['user_id']));
71
		$template->set_var('STATUS', ($user['active']==false ? 'class="user-inactive"' : 'class="user-active"') );
72
		$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
$HeaderTitle = $HEADING['MODIFY_DELETE_USER'].' ';
92
$HeaderTitle .= (($iUserStatus == 1) ? strtolower($TEXT['ACTIVE']) : strtolower($TEXT['DELETED']));
93
// Insert language headings
94
$template->set_var(array(
95
		'HEADING_MODIFY_DELETE_USER' => $HeaderTitle,
96
		'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
		'CONFIRM_DELETE' => (($iUserStatus == 1) ? $TEXT['ARE_YOU_SURE'] : $MESSAGE['USERS']['CONFIRM_DELETE'])
112
		)
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
// Setup template object, parse vars to it, then parse it
120
// Create new template object
121
$template = new Template(dirname($admin->correct_theme_source('users_form.htt')));
122
// $template->debug = true;
123
$template->set_file('page', 'users_form.htt');
124
$template->set_block('page', 'main_block', 'main');
125
$template->set_var('DISPLAY_EXTRA', 'display:none;');
126
$template->set_var('ACTIVE_CHECKED', ' checked="checked"');
127
$template->set_var('ACTION_URL', ADMIN_URL.'/users/add.php');
128
$template->set_var('SUBMIT_TITLE', $TEXT['ADD']);
129
$template->set_var('FTAN', $admin->getFTAN());
130
// insert urls
131
$template->set_var(array(
132
		'ADMIN_URL' => ADMIN_URL,
133
		'WB_URL' => WB_URL,
134
		'THEME_URL' => THEME_URL
135
		)
136
);
137

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

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

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

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

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

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

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

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

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