Project

General

Profile

1
<?php
2

    
3
// $Id: users.php 1012 2009-06-25 18:21:41Z Ruebenwurzel $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2009, 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
	exit(0);
36
}
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
	exit(0);
42
}
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(THEME_PATH.'/templates');
53
	$template->set_file('page', 'users_form.htt');
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="checked"');
66
	} else {
67
		$template->set_var('DISABLED_CHECKED', ' 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(in_array($group['group_id'], split(",",$user['groups_id']))) {
81
				$template->set_var('SELECTED', ' 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(in_array(1, $admin->get_groups_id())) {
90
		$template->set_var('ID', '1');
91
		$users_groups = $admin->get_groups_name();
92
		$template->set_var('NAME', $users_groups[1]);
93
		
94
		$in_group = FALSE;
95
		foreach($admin->get_groups_id() as $cur_gid){
96
		    if (in_array($cur_gid, split(",", $user['groups_id']))) {
97
		        $in_group = TRUE;
98
		    }
99
		}
100

    
101
		if($in_group) {
102
			$template->set_var('SELECTED', ' selected="selected"');
103
		} else {
104
			$template->set_var('SELECTED', '');
105
		}
106
		$template->parse('group_list', 'group_list_block', true);
107
	} else {
108
		if($results->numRows() == 0) {
109
			$template->set_var('ID', '');
110
			$template->set_var('NAME', $TEXT['NONE_FOUND']);
111
			$template->set_var('SELECTED', ' selected="selected"');
112
			$template->parse('group_list', 'group_list_block', true);
113
		}
114
	}
115
	
116
	// Generate username field name
117
	$username_fieldname = 'username_';
118
	$salt = "abchefghjkmnpqrstuvwxyz0123456789";
119
	srand((double)microtime()*1000000);
120
	$i = 0;
121
	while ($i <= 7) {
122
		$num = rand() % 33;
123
		$tmp = substr($salt, $num, 1);
124
		$username_fieldname = $username_fieldname . $tmp;
125
		$i++;
126
	}
127
	
128
	// Work-out if home folder should be shown
129
	if(!HOME_FOLDERS) {
130
		$template->set_var('DISPLAY_HOME_FOLDERS', 'none');
131
	}
132
	
133
	// Include the WB functions file
134
	require_once(WB_PATH.'/framework/functions.php');
135
	
136
	// Add media folders to home folder list
137
	$template->set_block('main_block', 'folder_list_block', 'folder_list');
138
	foreach(directory_list(WB_PATH.MEDIA_DIRECTORY) AS $name) {
139
		$template->set_var('NAME', str_replace(WB_PATH, '', $name));
140
		$template->set_var('FOLDER', str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name));
141
		if($user['home_folder'] == str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name)) {
142
			$template->set_var('SELECTED', ' selected="selected"');
143
		} else {
144
			$template->set_var('SELECTED', ' ');
145
		}
146
		$template->parse('folder_list', 'folder_list_block', true);
147
	}
148
	
149
	// Insert language text and messages
150
	$template->set_var(array(
151
									'TEXT_RESET' => $TEXT['RESET'],
152
									'TEXT_ACTIVE' => $TEXT['ACTIVE'],
153
									'TEXT_DISABLED' => $TEXT['DISABLED'],
154
									'TEXT_PLEASE_SELECT' => $TEXT['PLEASE_SELECT'],
155
									'TEXT_USERNAME' => $TEXT['USERNAME'],
156
									'TEXT_PASSWORD' => $TEXT['PASSWORD'],
157
									'TEXT_RETYPE_PASSWORD' => $TEXT['RETYPE_PASSWORD'],
158
									'TEXT_DISPLAY_NAME' => $TEXT['DISPLAY_NAME'],
159
									'TEXT_EMAIL' => $TEXT['EMAIL'],
160
									'TEXT_GROUP' => $TEXT['GROUP'],
161
									'TEXT_NONE' => $TEXT['NONE'],
162
									'TEXT_HOME_FOLDER' => $TEXT['HOME_FOLDER'],
163
									'USERNAME_FIELDNAME' => $username_fieldname,
164
									'CHANGING_PASSWORD' => $MESSAGE['USERS']['CHANGING_PASSWORD'],
165
									'HEADING_MODIFY_USER' => $HEADING['MODIFY_USER']
166
									)
167
							);
168
	
169
	// Parse template object
170
	$template->parse('main', 'main_block', false);
171
	$template->pparse('output', 'page');
172
} elseif($_POST['action'] == 'delete') {
173
	// Print header
174
	$admin = new admin('Access', 'users_delete');
175
	// Delete the user
176
	$database->query("DELETE FROM ".TABLE_PREFIX."users WHERE user_id = '".$_POST['user_id']."' LIMIT 1");
177
	if($database->is_error()) {
178
		$admin->print_error($database->get_error());
179
	} else {
180
		$admin->print_success($MESSAGE['USERS']['DELETED']);
181
	}
182
}
183

    
184
// Print admin footer
185
$admin->print_footer();
186

    
187
?>
(4-4/4)