Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         users
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id: index.php 1492 2011-08-11 14:53:12Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/users/index.php $
15
 * @lastmodified    $Date: 2011-08-11 16:53:12 +0200 (Thu, 11 Aug 2011) $
16
 *
17
*/
18

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

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

    
27
// Create new template object for the modify/remove menu
28
$template = new Template(THEME_PATH.'/templates');
29
$template->set_file('page', 'users.htt');
30
$template->set_block('page', 'main_block', 'main');
31
$template->set_block("main_block", "manage_groups_block", "groups");
32
$template->set_var('ADMIN_URL', ADMIN_URL);
33
$template->set_var('FTAN', $admin->getFTAN());
34
$template->set_var('USER_STATUS', $iUserStatus );
35

    
36
$UserStatusActive = 'url('.THEME_URL.'/images/user.png)';
37
$UserStatusInactive = 'url('.THEME_URL.'/images/user_red.png)';
38

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

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

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

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

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

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

    
117
// Setup template for add user form
118
$template = new Template(THEME_PATH.'/templates');
119
$template->set_file('page', 'users_form.htt');
120
$template->set_block('page', 'main_block', 'main');
121
$template->set_var('DISPLAY_EXTRA', 'display:none;');
122
$template->set_var('ACTIVE_CHECKED', ' checked="checked"');
123
$template->set_var('ACTION_URL', ADMIN_URL.'/users/add.php');
124
$template->set_var('SUBMIT_TITLE', $TEXT['ADD']);
125
$template->set_var('FTAN', $admin->getFTAN());
126
// insert urls
127
$template->set_var(array(
128
		'ADMIN_URL' => ADMIN_URL,
129
		'WB_URL' => WB_URL,
130
		'THEME_URL' => THEME_URL
131
		)
132
);
133

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

    
164
// Insert permissions values
165
if($admin->get_permission('users_add') != true) {
166
	$template->set_var('DISPLAY_ADD', 'hide');
167
}
168

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

    
181
// Work-out if home folder should be shown
182
if(!HOME_FOLDERS) {
183
	$template->set_var('DISPLAY_HOME_FOLDERS', 'display:none;');
184
}
185

    
186
// Include the WB functions file
187
require_once(WB_PATH.'/framework/functions.php');
188

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

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

    
218
// Parse template for add user form
219
$template->parse('main', 'main_block', false);
220
$template->pparse('output', 'page');
221

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