moved code up one level to eliminate the docs subdirectory
[acontent.git] / user / user_password.php
1 <?php
2 /************************************************************************/
3 /* AContent                                                             */
4 /************************************************************************/
5 /* Copyright (c) 2010                                                   */
6 /* Inclusive Design Institute                                           */
7 /*                                                                      */
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 /************************************************************************/
12
13 define('TR_INCLUDE_PATH', '../include/');
14 include_once(TR_INCLUDE_PATH.'vitals.inc.php');
15 include_once(TR_INCLUDE_PATH.'classes/DAO/UsersDAO.class.php');
16
17 if (isset($_POST['cancel'])) {
18         $msg->addFeedback('CANCELLED');
19         Header('Location: ../index.php');
20         exit;
21 }
22
23 if (isset($_POST['submit'])) {
24         /* password check: password is verified front end by javascript. here is to handle the errors from javascript */
25         if ($_POST['password_error'] <> "")
26         {
27                 $pwd_errors = explode(",", $_POST['password_error']);
28
29                 foreach ($pwd_errors as $pwd_error)
30                 {
31                         if ($pwd_error == "missing_password")
32                                 $missing_fields[] = _AT('password');
33                         else
34                                 $msg->addError($pwd_error);
35                 }
36         }
37
38         if (!$msg->containsErrors()) {
39                 // insert into the db.
40                 $password   = $addslashes($_POST['form_password_hidden']);
41                 
42                 $usersDAO = new UsersDAO();
43
44                 if (!$usersDAO->setPassword($_GET['id'], $password)) 
45                 {
46                         require(TR_INCLUDE_PATH.'header.inc.php');
47                         $msg->printErrors('DB_NOT_UPDATED');
48                         require(TR_INCLUDE_PATH.'footer.inc.php');
49                         exit;
50                 }
51
52                 // send email to user
53                 $user_row = $usersDAO->getUserByID($_GET['id']);
54
55                 $tmp_message  = _AT('password_change_msg')."\n\n";
56                 $tmp_message .= _AT('web_site').' : '.TR_BASE_HREF."\n";
57                 $tmp_message .= _AT('login_name').' : '.$user_row['login']."\n";
58                 
59                 require(TR_INCLUDE_PATH . 'classes/phpmailer/transformablemailer.class.php');
60                 $mail = new TransformableMailer;
61                 $mail->From     = $_config['contact_email'];
62                 $mail->AddAddress($user_row['email']);
63                 $mail->Subject = $_config['site_name'] . ': ' . _AT('password_changed');
64                 $mail->Body    = $tmp_message;
65
66                 if(!$mail->Send()) 
67                 {
68                    $msg->addError('SENDING_ERROR');
69                 }
70                 else
71                 {
72                         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
73                 }
74                 
75                 header('Location: index.php');
76                 exit;
77         }
78 }
79
80 /* template starts here */
81 $savant->display('user/user_password.tmpl.php');
82
83 ?>