Project

General

Profile

1
<?php
2

    
3
// $Id: save.php 286 2006-01-23 21:15:10Z stefan $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2005, 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
// Print admin header
27
require('../../config.php');
28
require_once(WB_PATH.'/framework/class.admin.php');
29
$admin = new admin('Access', 'users_modify');
30

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

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

    
42
// Gather details entered
43
$group_id = $admin->get_post('group');
44
$active = $_POST['active'][0];
45
$username_fieldname = $admin->get_post('username_fieldname');
46
$username = strtolower($admin->get_post($username_fieldname));
47
$password = $admin->get_post('password');
48
$password2 = $admin->get_post('password2');
49
$display_name = $admin->get_post('display_name');
50
$email = $admin->get_post('email');
51
$home_folder = $admin->get_post('home_folder');
52

    
53
// Create a javascript back link
54
$js_back = "javascript: history.go(-1);";
55

    
56
// Check values
57
if($group_id == "") {
58
	$admin->print_error($MESSAGE['USERS']['NO_GROUP'], $js_back);
59
}
60
if(strlen($username) < 2) {
61
	$admin->print_error($MESSAGE['USERS']['USERNAME_TOO_SHORT'], $js_back);
62
}
63
if($password != "") {
64
	if(strlen($password) < 2) {
65
		$admin->print_error($MESSAGE['USERS']['PASSWORD_TOO_SHORT'], $js_back);
66
	}
67
	if($password != $password2) {
68
		$admin->print_error($MESSAGE['USERS']['PASSWORD_MISMATCH'], $js_back);
69
	}
70
}
71
if($email != "") {
72
	if($admin->validate_email($email) == false) {
73
		$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
74
	}
75
}
76

    
77
// Prevent from renaming user to "admin"
78
if($username != 'admin') {
79
	$username_code = ", username = '$username'";
80
} else {
81
	$username_code = '';
82
}
83

    
84
// Update the database
85
if($password == "") {
86
	$query = "UPDATE ".TABLE_PREFIX."users SET group_id = '$group_id', active = '$active'$username_code, display_name = '$display_name', home_folder = '$home_folder', email = '$email' WHERE user_id = '$user_id'";
87
} else {
88
	// MD5 supplied password
89
	$md5_password = md5($password);
90
	$query = "UPDATE ".TABLE_PREFIX."users SET group_id = '$group_id', active = '$active'$username_code, display_name = '$display_name', home_folder = '$home_folder', email = '$email', password = '$md5_password' WHERE user_id = '$user_id'";
91
}
92
$database->query($query);
93
if($database->is_error()) {
94
	$admin->print_error($database->get_error());
95
} else {
96
	$admin->print_success($MESSAGE['USERS']['SAVED']);
97
}
98

    
99
// Print admin footer
100
$admin->print_footer();
101

    
102
?>
(3-3/6)