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-2011, 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 5.2.2 and higher
13
 * @version         $Id: users.php 1373 2011-01-10 12:14:10Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/users/users.php $
15
 * @lastmodified    $Date: 2011-01-10 13:14:10 +0100 (Mon, 10 Jan 2011) $
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
	
69
	$template->set_var('FTAN', $admin->getFTAN());
70
	if($user['active'] == 1) {
71
		$template->set_var('ACTIVE_CHECKED', ' checked="checked"');
72
	} else {
73
		$template->set_var('DISABLED_CHECKED', ' checked="checked"');
74
	}
75
	// Add groups to list
76
	$template->set_block('main_block', 'group_list_block', 'group_list');
77
	$results = $database->query("SELECT group_id, name FROM ".TABLE_PREFIX."groups WHERE group_id != '1' ORDER BY name");
78
	if($results->numRows() > 0) {
79
		$template->set_var('ID', '');
80
		$template->set_var('NAME', $TEXT['PLEASE_SELECT'].'...');
81
		$template->set_var('SELECTED', '');
82
		$template->parse('group_list', 'group_list_block', true);
83
		while($group = $results->fetchRow()) {
84
			$template->set_var('ID', $group['group_id']);
85
			$template->set_var('NAME', $group['name']);
86
			if(in_array($group['group_id'], explode(",",$user['groups_id']))) {
87
				$template->set_var('SELECTED', ' selected="selected"');
88
			} else {
89
				$template->set_var('SELECTED', '');
90
			}
91
			$template->parse('group_list', 'group_list_block', true);
92
		}
93
	}
94

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

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

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

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

    
193
// Print admin footer
194
$admin->print_footer();
195

    
196
?>
(4-4/4)