Project

General

Profile

1 1189 Luisehahne
<?php
2 1246 Luisehahne
/****************************************************************************
3
* SVN Version information:
4
*
5
* $Id$
6
*
7
*****************************************************************************
8
*                          WebsiteBaker
9
*
10
* WebsiteBaker Project <http://www.websitebaker2.org/>
11
* Copyright (C) 2009, Website Baker Org. e.V.
12
*         http://start.websitebaker2.org/impressum-datenschutz.php
13
* Copyright (C) 2004-2009, Ryan Djurovich
14
*
15
*                        About WebsiteBaker
16
*
17
* Website Baker is a PHP-based Content Management System (CMS)
18
* designed with one goal in mind: to enable its users to produce websites
19
* with ease.
20
*
21
*****************************************************************************
22
*
23
*****************************************************************************
24
*                        LICENSE INFORMATION
25
*
26
* WebsiteBaker is free software; you can redistribute it and/or
27
* modify it under the terms of the GNU General Public License
28
* as published by the Free Software Foundation; either version 2
29
* of the License, or (at your option) any later version.
30
*
31
* WebsiteBaker is distributed in the hope that it will be useful,
32
* but WITHOUT ANY WARRANTY; without even the implied warranty of
33
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
34
* See the GNU General Public License for more details.
35
*
36
* You should have received a copy of the GNU General Public License
37
* along with this program; if not, write to the Free Software
38
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
39
****************************************************************************
40
*
41
*****************************************************************************
42
*                   WebsiteBaker Extra Information
43
*
44
*
45
*
46
*
47
*****************************************************************************/
48
/**
49
 * @category    admin
50
 * @package     users
51
 * @author      Ryan Djurovich
52
 * @copyright   2004-2009, Ryan Djurovich
53
 * @copyright   2009-2010, Website Baker Org. e.V.
54
 * @version     $Id$
55
 * @platform    WebsiteBaker 2.8.x
56
 * @requirements >= PHP 4.3.4
57
 * @license     http://www.gnu.org/licenses/gpl.html
58
 *
59
 */
60 1189 Luisehahne
61 1246 Luisehahne
 // Include config file and admin class file
62 1189 Luisehahne
require('../../config.php');
63
require_once(WB_PATH.'/framework/class.admin.php');
64
65
// Create new database object
66
$database = new database();
67
68
if(!isset($_POST['action']) OR ($_POST['action'] != "modify" AND $_POST['action'] != "delete")) {
69
	header("Location: index.php");
70
	exit(0);
71
}
72
73 1213 MaGnaL
// Set parameter 'action' as alternative to javascript mechanism
74
if(isset($_POST['modify']))
75
	$_POST['action'] = "modify";
76
if(isset($_POST['delete']))
77
	$_POST['action'] = "delete";
78
79 1189 Luisehahne
// Check if user id is a valid number and doesnt equal 1
80
if(!isset($_POST['user_id']) OR !is_numeric($_POST['user_id']) OR $_POST['user_id'] == 1) {
81
	header("Location: index.php");
82
	exit(0);
83
}
84
85
if($_POST['action'] == 'modify') {
86
	// Print header
87
	$admin = new admin('Access', 'users_modify');
88
	// Get existing values
89
	$results = $database->query("SELECT * FROM ".TABLE_PREFIX."users WHERE user_id = '".$_POST['user_id']."'");
90
	$user = $results->fetchRow();
91
92
	// Setup template object
93
	$template = new Template(THEME_PATH.'/templates');
94
	$template->set_file('page', 'users_form.htt');
95
	$template->set_block('page', 'main_block', 'main');
96
	$template->set_var(	array(
97
										'ACTION_URL' => ADMIN_URL.'/users/save.php',
98
										'SUBMIT_TITLE' => $TEXT['SAVE'],
99
										'USER_ID' => $user['user_id'],
100
										'USERNAME' => $user['username'],
101
										'DISPLAY_NAME' => $user['display_name'],
102
										'EMAIL' => $user['email'],
103
										'ADMIN_URL' => ADMIN_URL,
104
										'WB_URL' => WB_URL,
105
										'WB_PATH' => WB_PATH,
106
										'THEME_URL' => THEME_URL
107
										)
108
								);
109
	if($user['active'] == 1) {
110
		$template->set_var('ACTIVE_CHECKED', ' checked="checked"');
111
	} else {
112
		$template->set_var('DISABLED_CHECKED', ' checked="checked"');
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', '');
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
			if(in_array($group['group_id'], explode(",",$user['groups_id']))) {
126
				$template->set_var('SELECTED', ' selected="selected"');
127
			} else {
128
				$template->set_var('SELECTED', '');
129
			}
130
			$template->parse('group_list', 'group_list_block', true);
131
		}
132
	}
133
	// Only allow the user to add a user to the Administrators group if they belong to it
134
	if(in_array(1, $admin->get_groups_id())) {
135
		$template->set_var('ID', '1');
136
		$users_groups = $admin->get_groups_name();
137
		$template->set_var('NAME', $users_groups[1]);
138
139
		$in_group = FALSE;
140
		foreach($admin->get_groups_id() as $cur_gid){
141
		    if (in_array($cur_gid, explode(",", $user['groups_id']))) {
142
		        $in_group = TRUE;
143
		    }
144
		}
145
146
		if($in_group) {
147
			$template->set_var('SELECTED', ' selected="selected"');
148
		} else {
149
			$template->set_var('SELECTED', '');
150
		}
151
		$template->parse('group_list', 'group_list_block', true);
152
	} else {
153
		if($results->numRows() == 0) {
154
			$template->set_var('ID', '');
155
			$template->set_var('NAME', $TEXT['NONE_FOUND']);
156
			$template->set_var('SELECTED', ' selected="selected"');
157
			$template->parse('group_list', 'group_list_block', true);
158
		}
159
	}
160
161
	// Generate username field name
162
	$username_fieldname = 'username_';
163
	$salt = "abchefghjkmnpqrstuvwxyz0123456789";
164
	srand((double)microtime()*1000000);
165
	$i = 0;
166
	while ($i <= 7) {
167
		$num = rand() % 33;
168
		$tmp = substr($salt, $num, 1);
169
		$username_fieldname = $username_fieldname . $tmp;
170
		$i++;
171
	}
172
173
	// Work-out if home folder should be shown
174
	if(!HOME_FOLDERS) {
175 1246 Luisehahne
		$template->set_var('DISPLAY_HOME_FOLDERS', 'display:none;');
176 1189 Luisehahne
	}
177
178
	// Include the WB functions file
179
	require_once(WB_PATH.'/framework/functions.php');
180
181
	// Add media folders to home folder list
182
	$template->set_block('main_block', 'folder_list_block', 'folder_list');
183 1246 Luisehahne
	foreach(directory_list(WB_PATH.MEDIA_DIRECTORY) AS $name)
184
    {
185 1189 Luisehahne
		$template->set_var('NAME', str_replace(WB_PATH, '', $name));
186
		$template->set_var('FOLDER', str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name));
187
		if($user['home_folder'] == str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name)) {
188
			$template->set_var('SELECTED', ' selected="selected"');
189
		} else {
190
			$template->set_var('SELECTED', ' ');
191
		}
192
		$template->parse('folder_list', 'folder_list_block', true);
193
	}
194
195
	// Insert language text and messages
196
	$template->set_var(array(
197
									'TEXT_RESET' => $TEXT['RESET'],
198
									'TEXT_ACTIVE' => $TEXT['ACTIVE'],
199
									'TEXT_DISABLED' => $TEXT['DISABLED'],
200
									'TEXT_PLEASE_SELECT' => $TEXT['PLEASE_SELECT'],
201
									'TEXT_USERNAME' => $TEXT['USERNAME'],
202
									'TEXT_PASSWORD' => $TEXT['PASSWORD'],
203
									'TEXT_RETYPE_PASSWORD' => $TEXT['RETYPE_PASSWORD'],
204
									'TEXT_DISPLAY_NAME' => $TEXT['DISPLAY_NAME'],
205
									'TEXT_EMAIL' => $TEXT['EMAIL'],
206
									'TEXT_GROUP' => $TEXT['GROUP'],
207
									'TEXT_NONE' => $TEXT['NONE'],
208
									'TEXT_HOME_FOLDER' => $TEXT['HOME_FOLDER'],
209
									'USERNAME_FIELDNAME' => $username_fieldname,
210
									'CHANGING_PASSWORD' => $MESSAGE['USERS']['CHANGING_PASSWORD'],
211
									'HEADING_MODIFY_USER' => $HEADING['MODIFY_USER']
212
									)
213
							);
214
215
	// Parse template object
216
	$template->parse('main', 'main_block', false);
217
	$template->pparse('output', 'page');
218
} elseif($_POST['action'] == 'delete') {
219
	// Print header
220
	$admin = new admin('Access', 'users_delete');
221
	// Delete the user
222
	$database->query("DELETE FROM ".TABLE_PREFIX."users WHERE user_id = '".$_POST['user_id']."' LIMIT 1");
223
	if($database->is_error()) {
224
		$admin->print_error($database->get_error());
225
	} else {
226
		$admin->print_success($MESSAGE['USERS']['DELETED']);
227
	}
228
}
229
230
// Print admin footer
231
$admin->print_footer();
232
233 4 ryan
?>