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

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

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

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

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

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

    
195
?>
(4-4/4)