2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2010 */
6 /* Inclusive Design Institute */
8 /* This program is free software. You can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation. */
11 /************************************************************************/
13 define('TR_INCLUDE_PATH', '../include/');
14 require(TR_INCLUDE_PATH.'vitals.inc.php');
15 require_once(TR_INCLUDE_PATH.'classes/DAO/UsersDAO.class.php');
17 global $_current_user;
19 if (!isset($_current_user))
21 require(TR_INCLUDE_PATH.'header.inc.php');
22 $msg->printInfos('INVALID_USER');
23 require(TR_INCLUDE_PATH.'footer.inc.php');
27 if (isset($_POST['cancel']))
29 $msg->addFeedback('CANCELLED');
30 Header('Location: ../index.php');
34 if (isset($_POST['submit']))
36 $this_password = $_POST['form_password_hidden'];
39 if (!empty($this_password))
41 //check if old password entered is correct
42 if ($row = $_current_user->getInfo())
44 if ($row['password'] != $this_password)
46 $msg->addError('WRONG_PASSWORD');
47 Header('Location: change_email.php');
54 $msg->addError(array('EMPTY_FIELDS', _AT('password')));
55 header('Location: change_email.php');
60 if ($_POST['email'] == '')
62 $msg->addError(array('EMPTY_FIELDS', _AT('email')));
66 if(!preg_match("/^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,6}$/i", $_POST['email']))
68 $msg->addError('EMAIL_INVALID');
71 $usersDAO = new UsersDAO();
72 $row = $usersDAO->getUserByEmail($_POST['email']);
73 if ($row['user_id'] > 0 && $row['user_id'] <> $_SESSION['user_id'])
75 $msg->addError('EMAIL_EXISTS');
79 if (!$msg->containsErrors())
81 if (defined('TR_EMAIL_CONFIRMATION') && TR_EMAIL_CONFIRMATION)
83 //send confirmation email
84 $row = $_current_user->getInfo();
86 if ($row['email'] != $_POST['email']) {
87 $code = substr(md5($_POST['email'] . $row['creation_date'] . $_SESSION['user_id']), 0, 10);
88 $confirmation_link = TR_BASE_HREF . 'confirm.php?id='.$_SESSION['user_id'].SEP .'e='.urlencode($_POST['email']).SEP.'m='.$code;
90 /* send the email confirmation message: */
91 require(TR_INCLUDE_PATH . 'classes/phpmailer/transformablemailer.class.php');
92 $mail = new TransformableMailer();
94 $mail->From = $_config['contact_email'];
95 $mail->AddAddress($_POST['email']);
96 $mail->Subject = SITE_NAME . ' - ' . _AT('email_confirmation_subject');
97 $mail->Body = _AT('email_confirmation_message2', $_config['site_name'], $confirmation_link);
101 $msg->addFeedback('CONFIRM_EMAIL');
103 $msg->addFeedback('CHANGE_TO_SAME_EMAIL');
107 //insert into database
108 $_current_user->setEmail($addslashes($_POST[email]));
110 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
115 $row = $_current_user->getInfo();
117 if (!isset($_POST['submit'])) {
121 /* template starts here */
122 $savant->assign('row', $row);
123 $savant->display('profile/change_email.tmpl.php');