made a copy
[atutor.git] / admin / admin_deny.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$
14
15 define('AT_INCLUDE_PATH', '../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
17 admin_authenticate(AT_ADMIN_PRIV_USERS);
18
19 //check valid requester id
20 $request_id = intval($_REQUEST['id']);
21 $sql    = "SELECT * FROM ".TABLE_PREFIX."members WHERE member_id=".$request_id;
22 $result = mysql_query($sql, $db);
23 if (!($row = mysql_fetch_array($result))) {
24         require(AT_INCLUDE_PATH.'header.inc.php'); 
25         echo _AT('no_user_found');
26         require(AT_INCLUDE_PATH.'footer.inc.php'); 
27         exit;
28 }
29
30 // message options
31 $msg_options = array (_AT('leave_blank'),
32                         _AT('instructor_request_denymsg1'),
33                         _AT('instructor_request_denymsg2'),
34                         _AT('instructor_request_denymsg3'),
35                         _AT('instructor_request_denymsg4'),
36                         _AT('other'));
37 $other_option = count($msg_options)-1;
38
39 if (isset($_POST['submit'])) {
40         $sql = 'DELETE FROM '.TABLE_PREFIX.'instructor_approvals WHERE member_id='.$request_id;
41         $result = mysql_query($sql, $db);
42         write_to_log(AT_ADMIN_LOG_DELETE, 'instructor_approvals', mysql_affected_rows($db), $sql);
43
44         $msg->addFeedback('PROFILE_UPDATED_ADMIN');
45
46         /* notify the users that they have been denied: */
47         $sql   = "SELECT email, first_name, last_name FROM ".TABLE_PREFIX."members WHERE member_id=".$_POST['id'];
48         $result = mysql_query($sql, $db);
49         if ($row = mysql_fetch_array($result)) {
50                 $to_email = $row['email'];
51
52                 $message = _AT('instructor_request_deny', AT_BASE_HREF)." \n";
53                 if ($_POST['msg_option'] == $other_option) {
54                         $message.=addslashes($_POST['other_msg']);
55                 } else if ($_POST['msg_option']) {
56                         $message.= "\n".$msg_options[$_POST['msg_option']];
57                 }
58
59                 if ($to_email != '') {
60                         
61                         require(AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php');
62
63                         $mail = new ATutorMailer;
64
65                         $mail->From     = $_config['contact_email'];
66                         $mail->AddAddress($to_email);
67                         $mail->Subject = _AT('instructor_request');
68                         $mail->Body    = $message;
69
70                         if(!$mail->Send()) {
71                            //echo 'There was an error sending the message';
72                            $msg->printErrors('SENDING_ERROR');
73                            exit;
74                         }
75
76                         unset($mail);
77                 }
78         }
79         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
80         Header('Location: index.php');
81         exit;
82 } else if ($_POST['cancel']) {
83         $msg->addFeedback('CANCELLED');
84         header('Location: index.php');
85         exit;
86 }
87
88 require(AT_INCLUDE_PATH.'header.inc.php'); 
89
90 $sql   = "SELECT email, first_name, last_name FROM ".TABLE_PREFIX."members WHERE member_id=".$request_id;
91 $result = mysql_query($sql, $db);
92
93 if ($row = mysql_fetch_array($result)) {
94         $username = '';
95         if ($row['first_name']!="") {
96                 $username .= $row['first_name'].' ';
97         }
98
99         if ($row['last_name']!="") {
100                 $username .= $row['last_name'].' ';
101         }
102         $username .= $row['email'];
103 } else {
104         require(AT_INCLUDE_PATH.'header.inc.php'); 
105         echo _AT('no_user_found');
106         require(AT_INCLUDE_PATH.'footer.inc.php'); 
107         exit;
108 }
109 ?>
110
111 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="form">
112 <input type="hidden" name="action" value="process" />
113 <input type="hidden" name="id" value="<?php echo $request_id; ?>" />
114
115 <div class="input-form">
116         <div class="row">
117                 <label for="confirm">
118                 <?php 
119                 echo _AT('confirm_deny_instructor');
120                 echo "<ul><li>$username</li></ul>"; 
121                 ?>
122                 </label>
123         </div>
124
125         <div class="row">
126                 <?php echo _AT('instructor_request_enterdenymsg'); ?><br />
127
128                 <?php 
129                         $radio_buttons = '';
130                         $i = 0;
131                         echo '<input type="radio" name="msg_option" id="c'.$i.'" value="'.$i.'" checked="checked" /><label for="c'.$i.'">'.$msg_options[$i].'</label><br />';
132
133                         $num_msgs = count($msg_options) - 1;
134                         for ($i = 1; $i<$num_msgs; $i++) {
135                                 echo '<input type="radio" name="msg_option" id="c'.$i.'" value="'.$i.'" /><label for="c'.$i.'">'.$msg_options[$i].'</label><br />';
136                         }
137
138                         echo '<input type="radio" name="msg_option" id="c'.$i.'" value="'.$i.'" /><label for="c'.$i.'">'.$msg_options[$i].'</label>';
139                 ?>
140                 <input type="text" class="formfield" name="other_msg" id="other_msg" size="30" onmousedown="document.form['c<?php echo $other_option; ?>'].checked = true;">
141                 <br />
142         </div>
143
144         <div class="row buttons">
145                 <input type="submit" name="submit" value="<?php echo _AT('deny'); ?>" accesskey="s" />
146                 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
147         </div>
148 </div>
149 </form>
150
151 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>