Project

General

Profile

1 4 ryan
<?php
2
3 399 Ruebenwurz
// $Id$
4 4 ryan
5
/*
6
7
 Website Baker Project <http://www.websitebaker.org/>
8 915 Ruebenwurz
 Copyright (C) 2004-2009, Ryan Djurovich
9 4 ryan
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
24
*/
25
26
require('../../config.php');
27
require_once(WB_PATH.'/framework/class.admin.php');
28
$admin = new admin('Access', 'users');
29
30
// Create new template object for the modify/remove menu
31 944 Ruebenwurz
$template = new Template(THEME_PATH.'/templates');
32
$template->set_file('page', 'users.htt');
33 4 ryan
$template->set_block('page', 'main_block', 'main');
34 1044 Ruebenwurz
$template->set_block("main_block", "manage_groups_block", "groups");
35 4 ryan
$template->set_var('ADMIN_URL', ADMIN_URL);
36
37
// Get existing value from database
38
$database = new database();
39
$query = "SELECT user_id, username, display_name FROM ".TABLE_PREFIX."users WHERE user_id != '1' ORDER BY username";
40
$results = $database->query($query);
41
if($database->is_error()) {
42
	$admin->print_error($database->get_error(), 'index.php');
43
}
44
45
// Insert values into the modify/remove menu
46
$template->set_block('main_block', 'list_block', 'list');
47
if($results->numRows() > 0) {
48
	// Insert first value to say please select
49
	$template->set_var('VALUE', '');
50
	$template->set_var('NAME', $TEXT['PLEASE_SELECT'].'...');
51
	$template->parse('list', 'list_block', true);
52
	// Loop through users
53
	while($user = $results->fetchRow()) {
54
		$template->set_var('VALUE', $user['user_id']);
55
		$template->set_var('NAME', $user['display_name'].' ('.$user['username'].')');
56
		$template->parse('list', 'list_block', true);
57
	}
58
} else {
59
	// Insert single value to say no users were found
60
	$template->set_var('NAME', $TEXT['NONE_FOUND']);
61
	$template->parse('list', 'list_block', true);
62
}
63
64
// Insert permissions values
65
if($admin->get_permission('users_add') != true) {
66
	$template->set_var('DISPLAY_ADD', 'hide');
67
}
68
if($admin->get_permission('users_modify') != true) {
69
	$template->set_var('DISPLAY_MODIFY', 'hide');
70
}
71
if($admin->get_permission('users_delete') != true) {
72
	$template->set_var('DISPLAY_DELETE', 'hide');
73
}
74
75
// Insert language headings
76
$template->set_var(array(
77 1044 Ruebenwurz
		'HEADING_MODIFY_DELETE_USER' => $HEADING['MODIFY_DELETE_USER'],
78
		'HEADING_ADD_USER' => $HEADING['ADD_USER']
79
		)
80
);
81 4 ryan
// Insert language text and messages
82
$template->set_var(array(
83 1044 Ruebenwurz
		'TEXT_MODIFY' => $TEXT['MODIFY'],
84
		'TEXT_DELETE' => $TEXT['DELETE'],
85
		'TEXT_MANAGE_GROUPS' => ( $admin->get_permission('groups') == true ) ? $TEXT['MANAGE_GROUPS'] : "**",
86
		'CONFIRM_DELETE' => $MESSAGE['USERS']['CONFIRM_DELETE']
87
		)
88
);
89
if ( $admin->get_permission('groups') == true ) $template->parse("groups", "manage_groups_block", true);
90 4 ryan
// Parse template object
91
$template->parse('main', 'main_block', false);
92
$template->pparse('output', 'page');
93
94
// Setup template for add user form
95 944 Ruebenwurz
$template = new Template(THEME_PATH.'/templates');
96
$template->set_file('page', 'users_form.htt');
97 4 ryan
$template->set_block('page', 'main_block', 'main');
98
$template->set_var('DISPLAY_EXTRA', 'none');
99 1012 Ruebenwurz
$template->set_var('ACTIVE_CHECKED', ' checked="checked"');
100 4 ryan
$template->set_var('ACTION_URL', ADMIN_URL.'/users/add.php');
101
$template->set_var('SUBMIT_TITLE', $TEXT['ADD']);
102
103
// Add groups to list
104
$template->set_block('main_block', 'group_list_block', 'group_list');
105
$results = $database->query("SELECT group_id, name FROM ".TABLE_PREFIX."groups WHERE group_id != '1'");
106
if($results->numRows() > 0) {
107
	$template->set_var('ID', '');
108
	$template->set_var('NAME', $TEXT['PLEASE_SELECT'].'...');
109 1012 Ruebenwurz
	$template->set_var('SELECTED', ' selected="selected"');
110 4 ryan
	$template->parse('group_list', 'group_list_block', true);
111
	while($group = $results->fetchRow()) {
112
		$template->set_var('ID', $group['group_id']);
113
		$template->set_var('NAME', $group['name']);
114
		$template->set_var('SELECTED', '');
115
		$template->parse('group_list', 'group_list_block', true);
116
	}
117
}
118
// Only allow the user to add a user to the Administrators group if they belong to it
119 546 doc
if(in_array(1, $admin->get_groups_id())) {
120
	$users_groups = $admin->get_groups_name();
121 4 ryan
	$template->set_var('ID', '1');
122 546 doc
	$template->set_var('NAME', $users_groups[1]);
123 4 ryan
	$template->set_var('SELECTED', '');
124
	$template->parse('group_list', 'group_list_block', true);
125
} else {
126
	if($results->numRows() == 0) {
127
		$template->set_var('ID', '');
128
		$template->set_var('NAME', $TEXT['NONE_FOUND']);
129
		$template->parse('group_list', 'group_list_block', true);
130
	}
131
}
132
133
// Insert permissions values
134
if($admin->get_permission('users_add') != true) {
135
	$template->set_var('DISPLAY_ADD', 'hide');
136
}
137
138
// Generate username field name
139
$username_fieldname = 'username_';
140
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
141
srand((double)microtime()*1000000);
142
$i = 0;
143
while ($i <= 7) {
144
	$num = rand() % 33;
145
	$tmp = substr($salt, $num, 1);
146
	$username_fieldname = $username_fieldname . $tmp;
147
	$i++;
148
}
149
150
// Work-out if home folder should be shown
151
if(!HOME_FOLDERS) {
152
	$template->set_var('DISPLAY_HOME_FOLDERS', 'none');
153
}
154
155
// Include the WB functions file
156
require_once(WB_PATH.'/framework/functions.php');
157
158
// Add media folders to home folder list
159
$template->set_block('main_block', 'folder_list_block', 'folder_list');
160
foreach(directory_list(WB_PATH.MEDIA_DIRECTORY) AS $name) {
161
	$template->set_var('NAME', str_replace(WB_PATH, '', $name));
162
	$template->set_var('FOLDER', str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name));
163
	$template->set_var('SELECTED', ' ');
164
	$template->parse('folder_list', 'folder_list_block', true);
165
}
166
167
// Insert language text and messages
168
$template->set_var(array(
169 1044 Ruebenwurz
			'TEXT_RESET' => $TEXT['RESET'],
170
			'TEXT_ACTIVE' => $TEXT['ACTIVE'],
171
			'TEXT_DISABLED' => $TEXT['DISABLED'],
172
			'TEXT_PLEASE_SELECT' => $TEXT['PLEASE_SELECT'],
173
			'TEXT_USERNAME' => $TEXT['USERNAME'],
174
			'TEXT_PASSWORD' => $TEXT['PASSWORD'],
175
			'TEXT_RETYPE_PASSWORD' => $TEXT['RETYPE_PASSWORD'],
176
			'TEXT_DISPLAY_NAME' => $TEXT['DISPLAY_NAME'],
177
			'TEXT_EMAIL' => $TEXT['EMAIL'],
178
			'TEXT_GROUP' => $TEXT['GROUP'],
179
			'TEXT_NONE' => $TEXT['NONE'],
180
			'TEXT_HOME_FOLDER' => $TEXT['HOME_FOLDER'],
181
			'USERNAME_FIELDNAME' => $username_fieldname,
182
			'CHANGING_PASSWORD' => $MESSAGE['USERS']['CHANGING_PASSWORD']
183
			)
184
	);
185 4 ryan
186
// Parse template for add user form
187
$template->parse('main', 'main_block', false);
188
$template->pparse('output', 'page');
189
190
$admin->print_footer();
191
192
?>