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