Project

General

Profile

1 4 ryan
<?php
2
3
// $Id: save.php,v 1.4 2005/04/02 06:25:53 rdjurovich Exp $
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
} else {
38
	$user_id = $_POST['user_id'];
39
}
40
41
// Gather details entered
42
$group_id = $admin->get_post('group');
43
$active = $_POST['active'][0];
44
$username_fieldname = $admin->get_post('username_fieldname');
45
$username = strtolower($admin->get_post($username_fieldname));
46
$password = $admin->get_post('password');
47
$password2 = $admin->get_post('password2');
48
$display_name = $admin->get_post('display_name');
49
$email = $admin->get_post('email');
50
$home_folder = $admin->get_post('home_folder');
51
52
// Create a javascript back link
53
$js_back = "javascript: history.go(-1);";
54
55
// Check values
56
if($group_id == "") {
57
	$admin->print_error($MESSAGE['USERS']['NO_GROUP'], $js_back);
58
}
59
if(strlen($username) < 2) {
60
	$admin->print_error($MESSAGE['USERS']['USERNAME_TOO_SHORT'], $js_back);
61
}
62
if($password != "") {
63
	if(strlen($password) < 2) {
64
		$admin->print_error($MESSAGE['USERS']['PASSWORD_TOO_SHORT'], $js_back);
65
	}
66
	if($password != $password2) {
67
		$admin->print_error($MESSAGE['USERS']['PASSWORD_MISMATCH'], $js_back);
68
	}
69
}
70
if($email != "") {
71
	if($admin->validate_email($email) == false) {
72
		$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
73
	}
74
}
75
76
// Prevent from renaming user to "admin"
77
if($username != 'admin') {
78
	$username_code = ", username = '$username'";
79
} else {
80
	$username_code = '';
81
}
82
83
// Update the database
84
if($password == "") {
85
	$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'";
86
} else {
87
	// MD5 supplied password
88
	$md5_password = md5($password);
89
	$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'";
90
}
91
$database->query($query);
92
if($database->is_error()) {
93
	$admin->print_error($database->get_error());
94
} else {
95
	$admin->print_success($MESSAGE['USERS']['SAVED']);
96
}
97
98
// Print admin footer
99
$admin->print_footer();
100
101
?>