Merge pull request #8 from radiocontrolled/0004872
[atutor.git] / contact_instructor.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2010                                      */
6 /* Inclusive Design Institute                                   */
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$
14
15 $_user_location = 'public';
16
17 define('AT_INCLUDE_PATH', 'include/');
18 require(AT_INCLUDE_PATH.'vitals.inc.php');
19
20 if (isset($_SESSION['member_id']) && $_SESSION['member_id']) {
21         $to = $_base_href . 'users/browse.php';
22 } else {
23         $to = $_base_href . 'browse.php';
24 }
25
26
27 if (isset($_POST['cancel'])) {
28         $msg->addFeedback('CANCELLED');
29         header('Location: ' . $to);
30         exit;
31 }
32
33 $row = array();
34
35 $id = intval($_REQUEST['id']);
36 if (isset($system_courses[$id], $system_courses[$id]['member_id'])) {
37         $sql    = "SELECT M.member_id, M.first_name, M.last_name, M.email FROM ".TABLE_PREFIX."members M WHERE M.member_id={$system_courses[$id][member_id]}";
38         $result = mysql_query($sql, $db);
39         $row = mysql_fetch_assoc($result);
40 }
41
42 if ($row) {
43         $instructor_name = get_display_name($row['member_id']);
44         $instructor_email = AT_print($row['email'], 'members.email');
45 } else {
46         $msg->addError('INST_INFO_NOT_FOUND');
47         header('Location: ' . $to);
48         exit;
49 }
50
51 if (isset($_POST['submit'])) {
52         $missing_fields = array();
53
54         $to_email = $_POST['email'];
55         $_POST['subject'] = trim($_POST['subject']);
56         $_POST['body']    = trim($_POST['body']);
57
58         if ($_POST['subject'] == '') {
59                 $missing_fields[] = _AT('subject');
60         }
61                 
62         if ($_POST['body'] == '') {
63                 $missing_fields[] = _AT('body');
64         }
65
66         if ($missing_fields) {
67                 $missing_fields = implode(', ', $missing_fields);
68                 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
69         }
70
71         if (!$msg->containsErrors()) {
72
73                 require(AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php');
74
75                 if (empty($_POST['from_email'])) {
76                         $_POST['from_email'] = $instructor_email;
77                 }
78                 if (empty($_POST['from'])) {
79                         $_POST['from'] = '';
80                 }
81
82                 $mail = new ATutorMailer;
83
84                 $mail->From     = $_POST['from_email'];
85                 $mail->FromName = $_POST['from'];
86                 $mail->AddAddress($instructor_email, $instructor_name);
87                 $mail->Subject = stripslashes($addslashes($_POST['subject']));
88                 $mail->Body    = stripslashes($addslashes($_POST['body']));
89
90                 if(!$mail->Send()) {
91                    $msg->addError('SENDING_ERROR');
92                    header('Location: ' . $to);
93                    exit;
94                 }
95                 unset($mail);
96                 
97                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
98                 header('Location: ' . $to);
99                 exit;
100         }
101
102 }
103
104 require (AT_INCLUDE_PATH.'header.inc.php');
105 ?>
106 <?php 
107 $savant->display('contact_instructor.tmpl.php');
108 require(AT_INCLUDE_PATH.'footer.inc.php'); ?>