Project

General

Profile

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