Revision 1347
Added by Dietmar about 14 years ago
save.php | ||
---|---|---|
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.4.9 and higher
|
|
13 |
* @version $Id$
|
|
14 |
* @filesource $HeadURL$
|
|
15 |
* @lastmodified $Date$
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
// Print admin header
|
|
20 |
require('../../config.php');
|
|
21 |
require_once(WB_PATH.'/framework/class.admin.php');
|
|
22 |
$admin = new admin('Access', 'users_modify');
|
|
23 |
|
|
24 |
// Create new database object
|
|
25 |
$database = new database();
|
|
26 |
|
|
27 |
// Check if user id is a valid number and doesnt equal 1
|
|
28 |
if(!isset($_POST['user_id']) OR !is_numeric($_POST['user_id']) OR $_POST['user_id'] == 1) {
|
|
29 |
header("Location: index.php");
|
|
30 |
exit(0);
|
|
31 |
} else {
|
|
32 |
$user_id = $_POST['user_id'];
|
|
33 |
}
|
|
34 |
|
|
35 |
// Gather details entered
|
|
36 |
$groups_id = (isset($_POST['groups'])) ? implode(",", $admin->add_slashes($_POST['groups'])) : '';
|
|
37 |
$active = $admin->add_slashes($_POST['active'][0]);
|
|
38 |
$username_fieldname = $admin->get_post_escaped('username_fieldname');
|
|
39 |
$username = strtolower($admin->get_post_escaped($username_fieldname));
|
|
40 |
$password = $admin->get_post('password');
|
|
41 |
$password2 = $admin->get_post('password2');
|
|
42 |
$display_name = $admin->get_post_escaped('display_name');
|
|
43 |
$email = $admin->get_post_escaped('email');
|
|
44 |
$home_folder = $admin->get_post_escaped('home_folder');
|
|
45 |
|
|
46 |
// Create a javascript back link
|
|
47 |
$js_back = "javascript: history.go(-1);";
|
|
48 |
|
|
49 |
// Check values
|
|
50 |
if($groups_id == "") {
|
|
51 |
$admin->print_error($MESSAGE['USERS']['NO_GROUP'], $js_back);
|
|
52 |
}
|
|
53 |
if(strlen($username) < 2) {
|
|
54 |
$admin->print_error($MESSAGE['USERS']['USERNAME_TOO_SHORT'], $js_back);
|
|
55 |
}
|
|
56 |
if($password != "") {
|
|
57 |
if(strlen($password) < 2) {
|
|
58 |
$admin->print_error($MESSAGE['USERS']['PASSWORD_TOO_SHORT'], $js_back);
|
|
59 |
}
|
|
60 |
if($password != $password2) {
|
|
61 |
$admin->print_error($MESSAGE['USERS']['PASSWORD_MISMATCH'], $js_back);
|
|
62 |
}
|
|
63 |
}
|
|
64 |
|
|
65 |
if($email != "")
|
|
66 |
{
|
|
67 |
if($admin->validate_email($email) == false)
|
|
68 |
{
|
|
69 |
$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
|
|
70 |
}
|
|
71 |
} else { // e-mail must be present
|
|
72 |
$admin->print_error($MESSAGE['SIGNUP']['NO_EMAIL'], $js_back);
|
|
73 |
}
|
|
74 |
|
|
75 |
// Check if the email already exists
|
|
76 |
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE email = '".$admin->add_slashes($_POST['email'])."'");
|
|
77 |
if($results->numRows() > 0)
|
|
78 |
{
|
|
79 |
if(isset($MESSAGE['USERS']['EMAIL_TAKEN']))
|
|
80 |
{
|
|
81 |
$admin->print_error($MESSAGE['USERS']['EMAIL_TAKEN'], $js_back);
|
|
82 |
} else {
|
|
83 |
$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
|
|
84 |
}
|
|
85 |
}
|
|
86 |
|
|
87 |
// Prevent from renaming user to "admin"
|
|
88 |
if($username != 'admin') {
|
|
89 |
$username_code = ", username = '$username'";
|
|
90 |
} else {
|
|
91 |
$username_code = '';
|
|
92 |
}
|
|
93 |
|
|
94 |
// Update the database
|
|
95 |
if($password == "") {
|
|
96 |
$query = "UPDATE ".TABLE_PREFIX."users SET groups_id = '$groups_id', active = '$active'$username_code, display_name = '$display_name', home_folder = '$home_folder', email = '$email' WHERE user_id = '$user_id'";
|
|
97 |
} else {
|
|
98 |
// MD5 supplied password
|
|
99 |
$md5_password = md5($password);
|
|
100 |
$query = "UPDATE ".TABLE_PREFIX."users SET groups_id = '$groups_id', active = '$active'$username_code, display_name = '$display_name', home_folder = '$home_folder', email = '$email', password = '$md5_password' WHERE user_id = '$user_id'";
|
|
101 |
}
|
|
102 |
$database->query($query);
|
|
103 |
if($database->is_error()) {
|
|
104 |
$admin->print_error($database->get_error());
|
|
105 |
} else {
|
|
106 |
$admin->print_success($MESSAGE['USERS']['SAVED']);
|
|
107 |
}
|
|
108 |
|
|
109 |
// Print admin footer
|
|
110 |
$admin->print_footer();
|
|
111 |
|
|
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.4.9 and higher |
|
13 |
* @version $Id$ |
|
14 |
* @filesource $HeadURL$ |
|
15 |
* @lastmodified $Date$ |
|
16 |
* |
|
17 |
*/ |
|
18 |
|
|
19 |
// Print admin header |
|
20 |
require('../../config.php'); |
|
21 |
require_once(WB_PATH.'/framework/class.admin.php'); |
|
22 |
$admin = new admin('Access', 'users_modify'); |
|
23 |
|
|
24 |
// Create new database object |
|
25 |
$database = new database(); |
|
26 |
|
|
27 |
// Check if user id is a valid number and doesnt equal 1 |
|
28 |
if(!isset($_POST['user_id']) OR !is_numeric($_POST['user_id']) OR $_POST['user_id'] == 1) { |
|
29 |
header("Location: index.php"); |
|
30 |
exit(0); |
|
31 |
} else { |
|
32 |
$user_id = $_POST['user_id']; |
|
33 |
} |
|
34 |
|
|
35 |
// Gather details entered |
|
36 |
$groups_id = (isset($_POST['groups'])) ? implode(",", $admin->add_slashes($_POST['groups'])) : ''; |
|
37 |
$active = $admin->add_slashes($_POST['active'][0]); |
|
38 |
$username_fieldname = $admin->get_post_escaped('username_fieldname'); |
|
39 |
$username = strtolower($admin->get_post_escaped($username_fieldname)); |
|
40 |
$password = $admin->get_post('password'); |
|
41 |
$password2 = $admin->get_post('password2'); |
|
42 |
$display_name = $admin->get_post_escaped('display_name'); |
|
43 |
$email = $admin->get_post_escaped('email'); |
|
44 |
$home_folder = $admin->get_post_escaped('home_folder'); |
|
45 |
|
|
46 |
// Create a javascript back link |
|
47 |
$js_back = "javascript: history.go(-1);"; |
|
48 |
|
|
49 |
// Check values |
|
50 |
if($groups_id == "") { |
|
51 |
$admin->print_error($MESSAGE['USERS']['NO_GROUP'], $js_back); |
|
52 |
} |
|
53 |
if(strlen($username) < 2) { |
|
54 |
$admin->print_error($MESSAGE['USERS']['USERNAME_TOO_SHORT'], $js_back); |
|
55 |
} |
|
56 |
if($password != "") { |
|
57 |
if(strlen($password) < 2) { |
|
58 |
$admin->print_error($MESSAGE['USERS']['PASSWORD_TOO_SHORT'], $js_back); |
|
59 |
} |
|
60 |
if($password != $password2) { |
|
61 |
$admin->print_error($MESSAGE['USERS']['PASSWORD_MISMATCH'], $js_back); |
|
62 |
} |
|
63 |
} |
|
64 |
|
|
65 |
if($email != "") |
|
66 |
{ |
|
67 |
if($admin->validate_email($email) == false) |
|
68 |
{ |
|
69 |
$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back); |
|
70 |
} |
|
71 |
} else { // e-mail must be present |
|
72 |
$admin->print_error($MESSAGE['SIGNUP']['NO_EMAIL'], $js_back); |
|
73 |
} |
|
74 |
|
|
75 |
// Check if the email already exists |
|
76 |
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE email = '".$admin->add_slashes($_POST['email'])."' AND user_id <> '".$user_id."' ");
|
|
77 |
if($results->numRows() > 0) |
|
78 |
{ |
|
79 |
if(isset($MESSAGE['USERS']['EMAIL_TAKEN'])) |
|
80 |
{ |
|
81 |
$admin->print_error($MESSAGE['USERS']['EMAIL_TAKEN'], $js_back); |
|
82 |
} else { |
|
83 |
$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back); |
|
84 |
} |
|
85 |
} |
|
86 |
|
|
87 |
// Prevent from renaming user to "admin" |
|
88 |
if($username != 'admin') { |
|
89 |
$username_code = ", username = '$username'"; |
|
90 |
} else { |
|
91 |
$username_code = ''; |
|
92 |
} |
|
93 |
|
|
94 |
// Update the database |
|
95 |
if($password == "") { |
|
96 |
$query = "UPDATE ".TABLE_PREFIX."users SET groups_id = '$groups_id', active = '$active'$username_code, display_name = '$display_name', home_folder = '$home_folder', email = '$email' WHERE user_id = '$user_id'"; |
|
97 |
} else { |
|
98 |
// MD5 supplied password |
|
99 |
$md5_password = md5($password); |
|
100 |
$query = "UPDATE ".TABLE_PREFIX."users SET groups_id = '$groups_id', active = '$active'$username_code, display_name = '$display_name', home_folder = '$home_folder', email = '$email', password = '$md5_password' WHERE user_id = '$user_id'"; |
|
101 |
} |
|
102 |
$database->query($query); |
|
103 |
if($database->is_error()) { |
|
104 |
$admin->print_error($database->get_error()); |
|
105 |
} else { |
|
106 |
$admin->print_success($MESSAGE['USERS']['SAVED']); |
|
107 |
} |
|
108 |
|
|
109 |
// Print admin footer |
|
110 |
$admin->print_footer(); |
|
111 |
|
|
112 | 112 |
?> |
Also available in: Unified diff
fix Droplet LoginBox fronend_signup (tks to Maverik)
fix save user e-mail,