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 1492 2011-08-11 14:53:12Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/users/users.php $
15
 * @lastmodified    $Date: 2011-08-11 16:53:12 +0200 (Thu, 11 Aug 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
$action = 'cancel';
24
// Set parameter 'action' as alternative to javascript mechanism
25
$action = (isset($_POST['modify']) ? 'modify' : $action );
26
$action = (isset($_POST['delete']) ? 'delete' : $action );
27

    
28
switch ($action):
29
	case 'modify' :
30
			// Print header
31
			$admin = new admin('Access', 'users_modify');
32
			$user_id = intval($admin->checkIDKEY('user_id', 0, $_SERVER['REQUEST_METHOD']));
33
			// Check if user id is a valid number and doesnt equal 1
34
			if($user_id == 0){
35
			$admin->print_error($MESSAGE['GENERIC_FORGOT_OPTIONS'] );
36
            }
37
			if( ($user_id < 2 ) )
38
			{
39
				// if($admin_header) { $admin->print_header(); }
40
				$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'] );
41
			}
42
			// Get existing values
43
			$results = $database->query("SELECT * FROM `".TABLE_PREFIX."users` WHERE `user_id` = '".$user_id."'");
44
			$user = $results->fetchRow();
45

    
46
			// Setup template object
47
			$template = new Template(THEME_PATH.'/templates');
48
			$template->set_file('page', 'users_form.htt');
49
			$template->set_block('page', 'main_block', 'main');
50
			$template->set_var(	array(
51
								'ACTION_URL' => ADMIN_URL.'/users/save.php',
52
								'SUBMIT_TITLE' => $TEXT['SAVE'],
53
								'USER_ID' => $user['user_id'],
54
								'USERNAME' => $user['username'],
55
								'DISPLAY_NAME' => $user['display_name'],
56
								'EMAIL' => $user['email'],
57
								'ADMIN_URL' => ADMIN_URL,
58
								'WB_URL' => WB_URL,
59
								'THEME_URL' => THEME_URL
60
								)
61
						);
62

    
63
			$template->set_var('FTAN', $admin->getFTAN());
64
			if($user['active'] == 1) {
65
				$template->set_var('ACTIVE_CHECKED', ' checked="checked"');
66
			} else {
67
				$template->set_var('DISABLED_CHECKED', ' checked="checked"');
68
			}
69
			// Add groups to list
70
			$template->set_block('main_block', 'group_list_block', 'group_list');
71
			$results = $database->query("SELECT group_id, name FROM ".TABLE_PREFIX."groups WHERE group_id != '1' ORDER BY name");
72
			if($results->numRows() > 0) {
73
				$template->set_var('ID', '');
74
				$template->set_var('NAME', $TEXT['PLEASE_SELECT'].'...');
75
				$template->set_var('SELECTED', '');
76
				$template->parse('group_list', 'group_list_block', true);
77
				while($group = $results->fetchRow()) {
78
					$template->set_var('ID', $group['group_id']);
79
					$template->set_var('NAME', $group['name']);
80
					if(in_array($group['group_id'], explode(",",$user['groups_id']))) {
81
						$template->set_var('SELECTED', ' selected="selected"');
82
					} else {
83
						$template->set_var('SELECTED', '');
84
					}
85
					$template->parse('group_list', 'group_list_block', true);
86
				}
87
			}
88

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

    
96
				$in_group = FALSE;
97
				foreach($admin->get_groups_id() as $cur_gid){
98
				    if (in_array($cur_gid, explode(",", $user['groups_id']))) {
99
				        $in_group = TRUE;
100
				    }
101
				}
102

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

    
118
			// Generate username field name
119
			$username_fieldname = 'username_';
120
			$salt = "abchefghjkmnpqrstuvwxyz0123456789";
121
			srand((double)microtime()*1000000);
122
			$i = 0;
123
			while ($i <= 7) {
124
				$num = rand() % 33;
125
				$tmp = substr($salt, $num, 1);
126
				$username_fieldname = $username_fieldname . $tmp;
127
				$i++;
128
			}
129

    
130
			// Work-out if home folder should be shown
131
			if(!HOME_FOLDERS) {
132
				$template->set_var('DISPLAY_HOME_FOLDERS', 'display:none;');
133
			}
134

    
135
			// Include the WB functions file
136
			require_once(WB_PATH.'/framework/functions.php');
137

    
138
			// Add media folders to home folder list
139
			$template->set_block('main_block', 'folder_list_block', 'folder_list');
140
			foreach(directory_list(WB_PATH.MEDIA_DIRECTORY) AS $name)
141
		    {
142
				$template->set_var('NAME', str_replace(WB_PATH, '', $name));
143
				$template->set_var('FOLDER', str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name));
144
				if($user['home_folder'] == str_replace(WB_PATH.MEDIA_DIRECTORY, '', $name)) {
145
					$template->set_var('SELECTED', ' selected="selected"');
146
				} else {
147
					$template->set_var('SELECTED', ' ');
148
				}
149
				$template->parse('folder_list', 'folder_list_block', true);
150
			}
151

    
152
			// Insert language text and messages
153
			$template->set_var(array(
154
								'TEXT_RESET' => $TEXT['RESET'],
155
								'TEXT_CANCEL' => $TEXT['CANCEL'],
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
			// Print admin footer
177
			$admin->print_footer();
178
			break;
179
		case 'delete' :
180
			// Print header
181
			$admin = new admin('Access', 'users_delete');
182
			$user_id = intval($admin->checkIDKEY('user_id', 0, $_SERVER['REQUEST_METHOD']));
183
			// Check if user id is a valid number and doesnt equal 1
184
			if($user_id == 0){
185
			$admin->print_error($MESSAGE['GENERIC_FORGOT_OPTIONS'] );
186
            }
187
			if( ($user_id < 2 ) )
188
			{
189
				// if($admin_header) { $admin->print_header(); }
190
				$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'] );
191
			}
192
			$sql  = 'SELECT `active` FROM `'.TABLE_PREFIX.'users` ';
193
            $sql .= 'WHERE `user_id` = '.$user_id.'';
194
            if( ($iDeleteUser = $database->get_one($sql)) == 1 ) {
195
				// Delete the user
196
				$database->query("UPDATE `".TABLE_PREFIX."users` SET `active` = 0 WHERE `user_id` = '".$user_id."' ");
197
            } else {
198
				$database->query("DELETE FROM `".TABLE_PREFIX."users` WHERE `user_id` = ".$user_id);
199
            }
200

    
201
			if($database->is_error()) {
202
				$admin->print_error($database->get_error());
203
			} else {
204
				$admin->print_success($MESSAGE['USERS_DELETED']);
205
			}
206
			// Print admin footer
207
			$admin->print_footer();
208
			break;
209
	default:
210
			break;
211
endswitch;
(4-4/4)