Project

General

Profile

1 4 ryan
<?php
2
3 275 stefan
// $Id$
4 4 ryan
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
if(!defined('WB_URL')) {
27
	header('Location: ../index.php');
28
}
29
30
// Get the values entered
31 275 stefan
$current_password = $wb->get_post('current_password');
32
$email = $wb->get_post('email');
33 4 ryan
34
// Create a javascript back link
35
$js_back = "javascript: history.go(-1);";
36
37
// Get existing password
38
$database = new database();
39 275 stefan
$query = "SELECT user_id FROM ".TABLE_PREFIX."users WHERE user_id = '".$wb->get_user_id()."' AND password = '".md5($current_password)."'";
40 4 ryan
$results = $database->query($query);
41
42
// Validate values
43
if($results->numRows() == 0) {
44 275 stefan
	$wb->print_error($MESSAGE['PREFERENCES']['OLD_PASSWORD_INCORRECT'], $js_back, false);
45 4 ryan
}
46
// Validate values
47 275 stefan
if(!$wb->validate_email($email)) {
48
	$wb->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back, false);
49 4 ryan
}
50
51
// Update the database
52
$database = new database();
53 275 stefan
$query = "UPDATE ".TABLE_PREFIX."users SET email = '$email' WHERE user_id = '".$wb->get_user_id()."' AND password = '".md5($current_password)."'";
54 4 ryan
$database->query($query);
55
if($database->is_error()) {
56 275 stefan
	$wb->print_error($database->get_error,'index.php', false);
57 4 ryan
} else {
58 275 stefan
	$wb->print_success($MESSAGE['PREFERENCES']['EMAIL_UPDATED'], WB_URL.'/account/preferences'.PAGE_EXTENSION);
59 4 ryan
	$_SESSION['EMAIL'] = $email;
60
}
61
62
?>