made a copy
[atutor.git] / users / contact_instructor.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay & Joel Kronenberg        */
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$
14
15 if ($_REQUEST['from_browse']) {
16         $page = 'browse_courses';
17 } else {
18         $page = 'my_courses';
19 }
20
21 $_user_location = 'users';
22 define('AT_INCLUDE_PATH', '../include/');
23 require(AT_INCLUDE_PATH.'vitals.inc.php');
24
25 if ($_POST['cancel']) {
26         if ($_POST['from_browse']) {
27                 header('Location: browse.php');
28         } else {
29                 header('Location: index.php');
30         }
31         exit;
32 }
33
34         require(AT_INCLUDE_PATH.'header.inc.php');
35
36         echo '<h2>'._AT('contact_instructor').'</h2>';
37
38         $sql    = "SELECT first_name, last_name, email FROM ".TABLE_PREFIX."members WHERE member_id=$_SESSION[member_id]";
39         $result = mysql_query($sql, $db);
40         if ($row = mysql_fetch_array($result)) {
41                 $student_name = $row['last_name'];
42                 $student_name .= ($row['first_name'] ? ', '.$row['first_name'] : '');
43
44                 $student_email = $row['email'];
45         } else {
46                 $msg->printErrors('STUD_INFO_NOT_FOUND');
47                 require(AT_INCLUDE_PATH.'footer.inc.php');
48                 exit;
49         }
50
51         if ($_GET['course']) {
52                 $course = intval($_GET['course']);
53         } else {
54                 $course = intval($_POST['course']);
55         }
56
57         $sql    = "SELECT M.first_name, M.last_name, M.email, C.title FROM ".TABLE_PREFIX."members M, ".TABLE_PREFIX."courses C WHERE M.member_id=C.member_id AND C.course_id=$course";
58         $result = mysql_query($sql, $db);
59
60         if ($row = mysql_fetch_array($result)) {
61                 $instructor_name = $row['last_name'];
62                 $instructor_name .= ($row['first_name'] ? ', '.$row['first_name'] : '');
63
64                 $instructor_email = $row['email'];
65         } else {
66                 $msg->printErrors('INST_INFO_NOT_FOUND');
67                 require(AT_INCLUDE_PATH.'footer.inc.php');
68                 exit;
69         }
70
71         if ($_POST['submit']) {
72                 $missing_fields = array();
73
74                 $to_email = $instructor_email;
75                 $_POST['subject'] = trim($_POST['subject']);
76                 $_POST['body']    = trim($_POST['body']);
77
78                 if ($_POST['subject'] == '') {
79                         $missing_fields[] = _AT('subject');
80                 }
81                 if ($_POST['body'] == '') {
82                         $missing_fields[] = _AT('body');
83                 }
84                 
85                 if ($missing_fields) {
86                         $missing_fields = implode(', ', $missing_fields);
87                         $msg->addError(array('EMPTY_FIELDS', $missing_fields));
88                 }
89                 if (!$msg->containsErrors()) {
90                         $tmp_message = _AT('from_atutor', $row['title'])."\n\n";
91                         $tmp_message .= $_POST['body']."\n\n";
92
93                         if ($to_email != '') {
94                                 require(AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php');
95
96                                 $mail = new ATutorMailer;
97
98                                 $mail->From     = $_POST['from_email'];
99                                 $mail->FromName = $_POST['from'];
100                                 $mail->AddAddress($to_email);
101                                 $mail->Subject = $_POST['subject'];
102                                 $mail->Body    = $tmp_message;
103
104                                 if(!$mail->Send()) {
105                                    //echo 'There was an error sending the message';
106                                    $msg->printErrors('SENDING_ERROR');
107                                    exit;
108                                 }
109
110                                 unset($mail);
111
112                                 $msg->printFeedbacks('ACTION_COMPLETED_SUCCESSFULLY');
113                                 require(AT_INCLUDE_PATH.'footer.inc.php');
114                                 exit;
115                         }
116                 }
117         }
118
119 $msg->printErrors();
120
121 ?>
122 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
123 <input type="hidden" name="course" value="<?php echo $course; ?>" />
124 <input type="hidden" name="from_browse" value="<?php echo $_REQUEST['from_browse']; ?>" />
125 <table cellspacing="1" cellpadding="0" border="0" summary="" width="85%" class="bodyline" align="center">
126 <tr>
127         <th colspan="2" align="left" class="cyan"><?php echo _AT('instructor_contact_form'); ?></th>
128 </tr>
129 <tr>
130         <td class="row1" align="right"><b><?php echo _AT('contact_name'); ?>:</b></td>
131         <td class="row1"><?php echo $row[title]; ?></td>
132 </tr>
133 <tr><td height="1" class="row2" colspan="2"></td></tr>
134 <tr>
135         <td class="row1" align="right"><b><?php echo _AT('to_name'); ?>:</b></td>
136         <td class="row1"><?php echo $instructor_name; ?> (<?php echo _AT('course_instructor'); ?>)</td>
137 </tr>
138 <tr><td height="1" class="row2" colspan="2"></td></tr>
139 <tr>
140         <td class="row1" align="right"><b><?php echo _AT('to_email'); ?>:</b></td>
141         <td class="row1"><i><?php echo _AT('hidden'); ?></i></td>
142 </tr>
143 <tr><td height="1" class="row2" colspan="2"></td></tr>
144 <tr>
145         <td class="row1" align="right"><label for="from"><b><?php echo _AT('from_name'); ?>:</b></label></td>
146         <td class="row1"><input type="text" class="formfield" name="from" id="from" size="40" value="<?php echo $student_name;?>" /></td>
147 </tr>
148 <tr><td height="1" class="row2" colspan="2"></td></tr>
149 <tr>
150         <td class="row1" align="right"><label for="from_email"><b><?php echo _AT('from_email'); ?>:</b></label></td>
151         <td class="row1"><input type="text" class="formfield" name="from_email" id="from_email" size="40" value="<?php echo $student_email;?>" /></td>
152 </tr>
153 <tr><td height="1" class="row2" colspan="2"></td></tr>
154 <tr>
155         <td class="row1" align="right"><label for="subject"><b><?php echo _AT('subject'); ?>:</b></label></td>
156         <td class="row1"><input type="text"  class="formfield" name="subject" id="subject" size="40" value="<?php echo $_POST['subject']; ?>" /></td>
157 </tr>
158 <tr><td height="1" class="row2" colspan="2"></td></tr>
159 <tr>
160         <td class="row1" align="right" valign="top"><label for="body"><b><?php echo _AT('body'); ?>:</b></label></td>
161         <td class="row1"><textarea class="formfield" cols="55" rows="15" id="body" name="body"><?php echo $_POST['body']; ?></textarea><br /><br /></td>
162 </tr>
163 <tr><td height="1" class="row2" colspan="2"></td></tr>
164 <tr><td height="1" class="row2" colspan="2"></td></tr>
165 <tr>
166         <td class="row1" align="center" colspan="2"><input type="submit" name="submit" class="button" value="<?php echo _AT('send'); ?> [Alt-s]" accesskey="s" /> <input type="submit" name="cancel" class="button" value="<?php echo _AT('cancel'); ?>" /></td>
167 </tr>
168 </table>
169 </form>
170 <br />
171
172 <?php
173         require(AT_INCLUDE_PATH.'footer.inc.php');
174 ?>