Project

General

Profile

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