made a copy
[atutor.git] / users / password_change.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
6 /* Adaptive Technology Resource Centre / University of Toronto                  */
7 /* http://atutor.ca                                                                                                             */
8 /*                                                                                                                                              */
9 /* This program is free software. You can redistribute it and/or                */
10 /* modify it under the terms of the GNU General Public License                  */
11 /* as published by the Free Software Foundation.                                                */
12 /************************************************************************/
13 // $Id: profile.php 6025 2006-03-28 20:13:55Z joel $
14
15 $page = 'profile';
16 $_user_location = 'users';
17
18 define('AT_INCLUDE_PATH', '../include/');
19 require(AT_INCLUDE_PATH.'vitals.inc.php');
20
21 if ($_SESSION['valid_user'] !== true) {
22         require(AT_INCLUDE_PATH.'header.inc.php');
23         $info = array('INVALID_USER', $_SESSION['course_id']);
24         $msg->printInfos($info);
25         require(AT_INCLUDE_PATH.'footer.inc.php');
26         exit;
27 }
28
29 if (isset($_POST['cancel'])) {
30         $msg->addFeedback('CANCELLED');
31         Header('Location: profile.php');
32         exit;
33 }
34
35 if (isset($_POST['submit'])) {
36         if (!empty($_POST['form_old_password_hidden'])) {
37                 //check if old password entered is correct
38                 $sql    = "SELECT password FROM ".TABLE_PREFIX."members WHERE member_id=$_SESSION[member_id]";
39                 $result = mysql_query($sql,$db);
40                 if ($row = mysql_fetch_assoc($result)) {
41                         if ($row['password'] != $_POST['form_old_password_hidden']) {
42                                 $msg->addError('WRONG_PASSWORD');
43                                 Header('Location: password_change.php');
44                                 exit;
45                         }
46                 }
47         } else {
48                 $msg->addError(array('EMPTY_FIELDS', _AT('password')));
49                 header('Location: password_change.php');
50                 exit;
51         }
52
53         /* password check: password is verified front end by javascript. here is to handle the errors from javascript */
54         if ($_POST['password_error'] <> "")
55         {
56                 $pwd_errors = explode(",", $_POST['password_error']);
57
58                 foreach ($pwd_errors as $pwd_error)
59                 {
60                         if ($pwd_error == "missing_password")
61                                 $missing_fields[] = _AT('password');
62                         else
63                                 $msg->addError($pwd_error);
64                 }
65         }
66
67         if (!$msg->containsErrors()) {                  
68                 // insert into the db.
69                 $password   = $addslashes($_POST['form_password_hidden']);
70
71                 $sql = "UPDATE ".TABLE_PREFIX."members SET password='$password', creation_date=creation_date, last_login=last_login WHERE member_id=$_SESSION[member_id]";
72                 $result = mysql_query($sql,$db);
73                 if (!$result) {
74                         require(AT_INCLUDE_PATH.'header.inc.php');
75                         $msg->printErrors('DB_NOT_UPDATED');
76                         require(AT_INCLUDE_PATH.'footer.inc.php');
77                         exit;
78                 }
79
80                 $msg->addFeedback('PASSWORD_CHANGED');
81                 header('Location: ./profile.php');
82                 exit;
83         }
84 }
85
86 /* template starts here */
87 $savant->display('users/password_change.tmpl.php');
88
89 ?>