Project

General

Profile

« Previous | Next » 

Revision 1289

Added by kweitzel almost 15 years ago

Branch 2.8.1 merged back into Trunk

View differences:

users.php
1
<?php
2

  
3
// $Id$
4

  
5
/*
6

  
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2009, Ryan Djurovich
9

  
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14

  
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19

  
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23

  
24
*/
25

  
26
// Include config file and admin class file
27
require('../../config.php');
28
require_once(WB_PATH.'/framework/class.admin.php');
29

  
30
// Create new database object
31
$database = new database();
32

  
33
if(!isset($_POST['action']) OR ($_POST['action'] != "modify" AND $_POST['action'] != "delete")) {
34
	header("Location: index.php");
35
	exit(0);
36
}
37

  
38
// Check if user id is a valid number and doesnt equal 1
39
if(!isset($_POST['user_id']) OR !is_numeric($_POST['user_id']) OR $_POST['user_id'] == 1) {
40
	header("Location: index.php");
41
	exit(0);
42
}
43

  
44
if($_POST['action'] == 'modify') {
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'");
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'], split(",",$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
	// Only allow the user to add a user to the Administrators group if they belong to it
93
	if(in_array(1, $admin->get_groups_id())) {
94
		$template->set_var('ID', '1');
95
		$users_groups = $admin->get_groups_name();
96
		$template->set_var('NAME', $users_groups[1]);
97
		
98
		$in_group = FALSE;
99
		foreach($admin->get_groups_id() as $cur_gid){
100
		    if (in_array($cur_gid, split(",", $user['groups_id']))) {
101
		        $in_group = TRUE;
102
		    }
103
		}
104

  
105
		if($in_group) {
106
			$template->set_var('SELECTED', ' selected="selected"');
107
		} else {
108
			$template->set_var('SELECTED', '');
109
		}
110
		$template->parse('group_list', 'group_list_block', true);
111
	} else {
112
		if($results->numRows() == 0) {
113
			$template->set_var('ID', '');
114
			$template->set_var('NAME', $TEXT['NONE_FOUND']);
115
			$template->set_var('SELECTED', ' selected="selected"');
116
			$template->parse('group_list', 'group_list_block', true);
117
		}
118
	}
119
	
120
	// Generate username field name
121
	$username_fieldname = 'username_';
122
	$salt = "abchefghjkmnpqrstuvwxyz0123456789";
123
	srand((double)microtime()*1000000);
124
	$i = 0;
125
	while ($i <= 7) {
126
		$num = rand() % 33;
127
		$tmp = substr($salt, $num, 1);
128
		$username_fieldname = $username_fieldname . $tmp;
129
		$i++;
130
	}
131
	
132
	// Work-out if home folder should be shown
133
	if(!HOME_FOLDERS) {
134
		$template->set_var('DISPLAY_HOME_FOLDERS', 'none');
135
	}
136
	
137
	// Include the WB functions file
138
	require_once(WB_PATH.'/framework/functions.php');
139
	
140
	// Add media folders to home folder list
141
	$template->set_block('main_block', 'folder_list_block', 'folder_list');
142
	foreach(directory_list(WB_PATH.MEDIA_DIRECTORY) AS $name) {
143
		$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

  
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$

14
 * @filesource		$HeadURL$
15
 * @lastmodified    $Date$

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
	// 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
		$template->set_var('DISPLAY_HOME_FOLDERS', 'display:none;');

134
	}

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
	foreach(directory_list(WB_PATH.MEDIA_DIRECTORY) AS $name)

142
    {

143
		$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 191
?>
192 192

  

Also available in: Unified diff