Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @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: users.php 1304 2010-03-16 23:10:17Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/users/users.php $
15
 * @lastmodified    $Date: 2010-03-17 00:10:17 +0100 (Wed, 17 Mar 2010) $
16
 *
17
*/
18

    
19
 // Include config file and admin class file
20
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
// 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
// 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
{
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
										'ADMIN_URL' => ADMIN_URL,
63
										'WB_URL' => WB_URL,
64
										'WB_PATH' => WB_PATH,
65
										'THEME_URL' => THEME_URL
66
										)
67
								);
68
	if($user['active'] == 1) {
69
		$template->set_var('ACTIVE_CHECKED', ' checked="checked"');
70
	} else {
71
		$template->set_var('DISABLED_CHECKED', ' checked="checked"');
72
	}
73
	// Add groups to list
74
	$template->set_block('main_block', 'group_list_block', 'group_list');
75
	$results = $database->query("SELECT group_id, name FROM ".TABLE_PREFIX."groups WHERE group_id != '1' ORDER BY name");
76
	if($results->numRows() > 0) {
77
		$template->set_var('ID', '');
78
		$template->set_var('NAME', $TEXT['PLEASE_SELECT'].'...');
79
		$template->set_var('SELECTED', '');
80
		$template->parse('group_list', 'group_list_block', true);
81
		while($group = $results->fetchRow()) {
82
			$template->set_var('ID', $group['group_id']);
83
			$template->set_var('NAME', $group['name']);
84
			if(in_array($group['group_id'], explode(",",$user['groups_id']))) {
85
				$template->set_var('SELECTED', ' selected="selected"');
86
			} else {
87
				$template->set_var('SELECTED', '');
88
			}
89
			$template->parse('group_list', 'group_list_block', true);
90
		}
91
	}
92

    
93
	// Only allow the user to add a user to the Administrators group if they belong to it
94
	if(in_array(1, $admin->get_groups_id()))
95
    {
96
		$template->set_var('ID', '1');
97
		$users_groups = $admin->get_groups_name();
98
		$template->set_var('NAME', $users_groups[1]);
99

    
100
		$in_group = FALSE;
101
		foreach($admin->get_groups_id() as $cur_gid){
102
		    if (in_array($cur_gid, explode(",", $user['groups_id']))) {
103
		        $in_group = TRUE;
104
		    }
105
		}
106

    
107
		if($in_group) {
108
			$template->set_var('SELECTED', ' selected="selected"');
109
		} else {
110
			$template->set_var('SELECTED', '');
111
		}
112
		$template->parse('group_list', 'group_list_block', true);
113
	} else {
114
		if($results->numRows() == 0) {
115
			$template->set_var('ID', '');
116
			$template->set_var('NAME', $TEXT['NONE_FOUND']);
117
			$template->set_var('SELECTED', ' selected="selected"');
118
			$template->parse('group_list', 'group_list_block', true);
119
		}
120
	}
121

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

    
191
// Print admin footer
192
$admin->print_footer();
193

    
194
?>
(4-4/4)