Project

General

Profile

1 1189 Luisehahne
<?php
2 1246 Luisehahne
/**
3
 *
4 1271 Luisehahne
 * @category        admin
5
 * @package         users
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2010, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 4.3.4 and higher
13
 * @version         $Id$
14
 * @filesource		$HeadURL$
15
 * @lastmodified    $Date$
16
 *
17
*/
18 1189 Luisehahne
19 1246 Luisehahne
 // Include config file and admin class file
20 1189 Luisehahne
require('../../config.php');
21
require_once(WB_PATH.'/framework/class.admin.php');
22
23
// Create new database object
24
$database = new database();
25
26
if(!isset($_POST['action']) OR ($_POST['action'] != "modify" AND $_POST['action'] != "delete")) {
27
	header("Location: index.php");
28
	exit(0);
29
}
30
31 1213 MaGnaL
// Set parameter 'action' as alternative to javascript mechanism
32
if(isset($_POST['modify']))
33
	$_POST['action'] = "modify";
34
if(isset($_POST['delete']))
35
	$_POST['action'] = "delete";
36
37 1189 Luisehahne
// 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
	exit(0);
41
}
42
43
if($_POST['action'] == 'modify') {
44
	// Print header
45
	$admin = new admin('Access', 'users_modify');
46
	// Get existing values
47
	$results = $database->query("SELECT * FROM ".TABLE_PREFIX."users WHERE user_id = '".$_POST['user_id']."'");
48
	$user = $results->fetchRow();
49
50
	// Setup template object
51
	$template = new Template(THEME_PATH.'/templates');
52
	$template->set_file('page', 'users_form.htt');
53
	$template->set_block('page', 'main_block', 'main');
54
	$template->set_var(	array(
55
										'ACTION_URL' => ADMIN_URL.'/users/save.php',
56
										'SUBMIT_TITLE' => $TEXT['SAVE'],
57
										'USER_ID' => $user['user_id'],
58
										'USERNAME' => $user['username'],
59
										'DISPLAY_NAME' => $user['display_name'],
60
										'EMAIL' => $user['email'],
61
										'ADMIN_URL' => ADMIN_URL,
62
										'WB_URL' => WB_URL,
63
										'WB_PATH' => WB_PATH,
64
										'THEME_URL' => THEME_URL
65
										)
66
								);
67
	if($user['active'] == 1) {
68
		$template->set_var('ACTIVE_CHECKED', ' checked="checked"');
69
	} else {
70
		$template->set_var('DISABLED_CHECKED', ' checked="checked"');
71
	}
72
	// Add groups to list
73
	$template->set_block('main_block', 'group_list_block', 'group_list');
74
	$results = $database->query("SELECT group_id, name FROM ".TABLE_PREFIX."groups WHERE group_id != '1'");
75
	if($results->numRows() > 0) {
76
		$template->set_var('ID', '');
77
		$template->set_var('NAME', $TEXT['PLEASE_SELECT'].'...');
78
		$template->set_var('SELECTED', '');
79
		$template->parse('group_list', 'group_list_block', true);
80
		while($group = $results->fetchRow()) {
81
			$template->set_var('ID', $group['group_id']);
82
			$template->set_var('NAME', $group['name']);
83
			if(in_array($group['group_id'], explode(",",$user['groups_id']))) {
84
				$template->set_var('SELECTED', ' selected="selected"');
85
			} else {
86
				$template->set_var('SELECTED', '');
87
			}
88
			$template->parse('group_list', 'group_list_block', true);
89
		}
90
	}
91
	// Only allow the user to add a user to the Administrators group if they belong to it
92
	if(in_array(1, $admin->get_groups_id())) {
93
		$template->set_var('ID', '1');
94
		$users_groups = $admin->get_groups_name();
95
		$template->set_var('NAME', $users_groups[1]);
96
97
		$in_group = FALSE;
98
		foreach($admin->get_groups_id() as $cur_gid){
99
		    if (in_array($cur_gid, explode(",", $user['groups_id']))) {
100
		        $in_group = TRUE;
101
		    }
102
		}
103
104
		if($in_group) {
105
			$template->set_var('SELECTED', ' selected="selected"');
106
		} else {
107
			$template->set_var('SELECTED', '');
108
		}
109
		$template->parse('group_list', 'group_list_block', true);
110
	} else {
111
		if($results->numRows() == 0) {
112
			$template->set_var('ID', '');
113
			$template->set_var('NAME', $TEXT['NONE_FOUND']);
114
			$template->set_var('SELECTED', ' selected="selected"');
115
			$template->parse('group_list', 'group_list_block', true);
116
		}
117
	}
118
119
	// Generate username field name
120
	$username_fieldname = 'username_';
121
	$salt = "abchefghjkmnpqrstuvwxyz0123456789";
122
	srand((double)microtime()*1000000);
123
	$i = 0;
124
	while ($i <= 7) {
125
		$num = rand() % 33;
126
		$tmp = substr($salt, $num, 1);
127
		$username_fieldname = $username_fieldname . $tmp;
128
		$i++;
129
	}
130
131
	// Work-out if home folder should be shown
132
	if(!HOME_FOLDERS) {
133 1246 Luisehahne
		$template->set_var('DISPLAY_HOME_FOLDERS', 'display:none;');
134 1189 Luisehahne
	}
135
136
	// Include the WB functions file
137
	require_once(WB_PATH.'/framework/functions.php');
138
139
	// Add media folders to home folder list
140
	$template->set_block('main_block', 'folder_list_block', 'folder_list');
141 1246 Luisehahne
	foreach(directory_list(WB_PATH.MEDIA_DIRECTORY) AS $name)
142
    {
143 1189 Luisehahne
		$template->set_var('NAME', str_replace(WB_PATH, '', $name));
144
		$template->set_var('FOLDER', str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name));
145
		if($user['home_folder'] == str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name)) {
146
			$template->set_var('SELECTED', ' selected="selected"');
147
		} else {
148
			$template->set_var('SELECTED', ' ');
149
		}
150
		$template->parse('folder_list', 'folder_list_block', true);
151
	}
152
153
	// Insert language text and messages
154
	$template->set_var(array(
155
									'TEXT_RESET' => $TEXT['RESET'],
156
									'TEXT_ACTIVE' => $TEXT['ACTIVE'],
157
									'TEXT_DISABLED' => $TEXT['DISABLED'],
158
									'TEXT_PLEASE_SELECT' => $TEXT['PLEASE_SELECT'],
159
									'TEXT_USERNAME' => $TEXT['USERNAME'],
160
									'TEXT_PASSWORD' => $TEXT['PASSWORD'],
161
									'TEXT_RETYPE_PASSWORD' => $TEXT['RETYPE_PASSWORD'],
162
									'TEXT_DISPLAY_NAME' => $TEXT['DISPLAY_NAME'],
163
									'TEXT_EMAIL' => $TEXT['EMAIL'],
164
									'TEXT_GROUP' => $TEXT['GROUP'],
165
									'TEXT_NONE' => $TEXT['NONE'],
166
									'TEXT_HOME_FOLDER' => $TEXT['HOME_FOLDER'],
167
									'USERNAME_FIELDNAME' => $username_fieldname,
168
									'CHANGING_PASSWORD' => $MESSAGE['USERS']['CHANGING_PASSWORD'],
169
									'HEADING_MODIFY_USER' => $HEADING['MODIFY_USER']
170
									)
171
							);
172
173
	// Parse template object
174
	$template->parse('main', 'main_block', false);
175
	$template->pparse('output', 'page');
176
} elseif($_POST['action'] == 'delete') {
177
	// Print header
178
	$admin = new admin('Access', 'users_delete');
179
	// Delete the user
180
	$database->query("DELETE FROM ".TABLE_PREFIX."users WHERE user_id = '".$_POST['user_id']."' LIMIT 1");
181
	if($database->is_error()) {
182
		$admin->print_error($database->get_error());
183
	} else {
184
		$admin->print_success($MESSAGE['USERS']['DELETED']);
185
	}
186
}
187
188
// Print admin footer
189
$admin->print_footer();
190
191 4 ryan
?>