Project

General

Profile

1 4 ryan
<?php
2
3 286 stefan
// $Id$
4 4 ryan
5
/*
6
7
 Website Baker Project <http://www.websitebaker.org/>
8 399 Ruebenwurz
 Copyright (C) 2004-2007, 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
// Include config file and admin class file
27
require('../../config.php');
28
require_once(WB_PATH.'/framework/class.admin.php');
29
30
// Create new database object
31
$database = new database();
32
33
if(!isset($_POST['action']) OR $_POST['action'] != "modify" AND $_POST['action'] != "delete") {
34
	header("Location: index.php");
35 286 stefan
	exit(0);
36 4 ryan
}
37
38
// Check if user id is a valid number and doesnt equal 1
39
if(!isset($_POST['user_id']) OR !is_numeric($_POST['user_id']) OR $_POST['user_id'] == 1) {
40
	header("Location: index.php");
41 286 stefan
	exit(0);
42 4 ryan
}
43
44
if($_POST['action'] == 'modify') {
45
	// Print header
46
	$admin = new admin('Access', 'users_modify');
47
	// Get existing values
48
	$results = $database->query("SELECT * FROM ".TABLE_PREFIX."users WHERE user_id = '".$_POST['user_id']."'");
49
	$user = $results->fetchRow();
50
51
	// Setup template object
52
	$template = new Template(ADMIN_PATH.'/users');
53
	$template->set_file('page', 'user_form.html');
54
	$template->set_block('page', 'main_block', 'main');
55
	$template->set_var(	array(
56
										'ACTION_URL' => ADMIN_URL.'/users/save.php',
57
										'SUBMIT_TITLE' => $TEXT['SAVE'],
58
										'USER_ID' => $user['user_id'],
59
										'USERNAME' => $user['username'],
60
										'DISPLAY_NAME' => $user['display_name'],
61
										'EMAIL' => $user['email']
62
										)
63
							);
64
	if($user['active'] == 1) {
65
		$template->set_var('ACTIVE_CHECKED', ' checked');
66
	} else {
67
		$template->set_var('DISABLED_CHECKED', ' checked');
68
	}
69
	// Add groups to list
70
	$template->set_block('main_block', 'group_list_block', 'group_list');
71
	$results = $database->query("SELECT group_id, name FROM ".TABLE_PREFIX."groups WHERE group_id != '1'");
72
	if($results->numRows() > 0) {
73
		$template->set_var('ID', '');
74
		$template->set_var('NAME', $TEXT['PLEASE_SELECT'].'...');
75
		$template->set_var('SELECTED', '');
76
		$template->parse('group_list', 'group_list_block', true);
77
		while($group = $results->fetchRow()) {
78
			$template->set_var('ID', $group['group_id']);
79
			$template->set_var('NAME', $group['name']);
80
			if($user['group_id'] == $group['group_id']) {
81
				$template->set_var('SELECTED', 'selected');
82
			} else {
83
				$template->set_var('SELECTED', '');
84
			}
85
			$template->parse('group_list', 'group_list_block', true);
86
		}
87
	}
88
	// Only allow the user to add a user to the Administrators group if they belong to it
89
	if($admin->get_group_id() == 1) {
90
		$template->set_var('ID', '1');
91
		$template->set_var('NAME', $admin->get_group_name());
92
		if($user['group_id'] == $admin->get_group_id()) {
93
			$template->set_var('SELECTED', 'selected');
94
		} else {
95
			$template->set_var('SELECTED', '');
96
		}
97
		$template->parse('group_list', 'group_list_block', true);
98
	} else {
99
		if($results->numRows() == 0) {
100
			$template->set_var('ID', '');
101
			$template->set_var('NAME', $TEXT['NONE_FOUND']);
102
			$template->set_var('SELECTED', 'selected');
103
			$template->parse('group_list', 'group_list_block', true);
104
		}
105
	}
106
107
	// Generate username field name
108
	$username_fieldname = 'username_';
109
	$salt = "abchefghjkmnpqrstuvwxyz0123456789";
110
	srand((double)microtime()*1000000);
111
	$i = 0;
112
	while ($i <= 7) {
113
		$num = rand() % 33;
114
		$tmp = substr($salt, $num, 1);
115
		$username_fieldname = $username_fieldname . $tmp;
116
		$i++;
117
	}
118
119
	// Work-out if home folder should be shown
120
	if(!HOME_FOLDERS) {
121
		$template->set_var('DISPLAY_HOME_FOLDERS', 'none');
122
	}
123
124
	// Include the WB functions file
125
	require_once(WB_PATH.'/framework/functions.php');
126
127
	// Add media folders to home folder list
128
	$template->set_block('main_block', 'folder_list_block', 'folder_list');
129
	foreach(directory_list(WB_PATH.MEDIA_DIRECTORY) AS $name) {
130
		$template->set_var('NAME', str_replace(WB_PATH, '', $name));
131
		$template->set_var('FOLDER', str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name));
132
		if($user['home_folder'] == str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name)) {
133
			$template->set_var('SELECTED', ' selected');
134
		} else {
135
			$template->set_var('SELECTED', ' ');
136
		}
137
		$template->parse('folder_list', 'folder_list_block', true);
138
	}
139
140
	// Insert language text and messages
141
	$template->set_var(array(
142
									'TEXT_RESET' => $TEXT['RESET'],
143
									'TEXT_ACTIVE' => $TEXT['ACTIVE'],
144
									'TEXT_DISABLED' => $TEXT['DISABLED'],
145
									'TEXT_PLEASE_SELECT' => $TEXT['PLEASE_SELECT'],
146
									'TEXT_USERNAME' => $TEXT['USERNAME'],
147
									'TEXT_PASSWORD' => $TEXT['PASSWORD'],
148
									'TEXT_RETYPE_PASSWORD' => $TEXT['RETYPE_PASSWORD'],
149
									'TEXT_DISPLAY_NAME' => $TEXT['DISPLAY_NAME'],
150
									'TEXT_EMAIL' => $TEXT['EMAIL'],
151
									'TEXT_GROUP' => $TEXT['GROUP'],
152
									'TEXT_NONE' => $TEXT['NONE'],
153
									'TEXT_HOME_FOLDER' => $TEXT['HOME_FOLDER'],
154
									'USERNAME_FIELDNAME' => $username_fieldname,
155
									'CHANGING_PASSWORD' => $MESSAGE['USERS']['CHANGING_PASSWORD']
156
									)
157
							);
158
159
	// Parse template object
160
	$template->parse('main', 'main_block', false);
161
	$template->pparse('output', 'page');
162
} elseif($_POST['action'] == 'delete') {
163
	// Print header
164
	$admin = new admin('Access', 'users_delete');
165
	// Delete the user
166
	$database->query("DELETE FROM ".TABLE_PREFIX."users WHERE user_id = '".$_POST['user_id']."' LIMIT 1");
167
	if($database->is_error()) {
168
		$admin->print_error($database->get_error());
169
	} else {
170
		$admin->print_success($MESSAGE['USERS']['DELETED']);
171
	}
172
}
173
174
// Print admin footer
175
$admin->print_footer();
176
177
?>