made a copy
[atutor.git] / admin / instructor_requests.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 $_user_location = 'admin';
16
17 define('AT_INCLUDE_PATH', '../include/');
18 require(AT_INCLUDE_PATH.'vitals.inc.php');
19 admin_authenticate(AT_ADMIN_PRIV_USERS);
20
21 if (isset($_GET['deny']) && isset($_GET['id'])) {
22         header('Location: admin_deny.php?id='.$_GET['id']);
23         exit;
24         /*
25         $sql = 'DELETE FROM '.TABLE_PREFIX.'instructor_approvals WHERE member_id='.intval($_GET['id']);
26         $result = mysql_query($sql, $db);
27
28         write_to_log(AT_ADMIN_LOG_DELETE, 'instructor_approvals', mysql_affected_rows($db), $sql);
29         */
30
31 } else if (isset($_GET['approve']) && isset($_GET['id'])) {
32         $id = intval($_GET['id']);
33
34         $sql = 'DELETE FROM '.TABLE_PREFIX.'instructor_approvals WHERE member_id='.$id;
35         $result = mysql_query($sql, $db);
36
37         write_to_log(AT_ADMIN_LOG_DELETE, 'instructor_approvals', mysql_affected_rows($db), $sql);
38
39         $sql = 'UPDATE '.TABLE_PREFIX.'members SET status='.AT_STATUS_INSTRUCTOR.', creation_date=creation_date, last_login=last_login WHERE member_id='.$id;
40         $result = mysql_query($sql, $db);
41
42         write_to_log(AT_ADMIN_LOG_UPDATE, 'members', mysql_affected_rows($db), $sql);
43
44         /* notify the users that they have been approved: */
45         $sql   = "SELECT email, first_name, last_name FROM ".TABLE_PREFIX."members WHERE member_id=$id";
46         $result = mysql_query($sql, $db);
47         if ($row = mysql_fetch_assoc($result)) {
48                 $to_email = $row['email'];
49
50                 if ($row['first_name']!="" || $row['last_name']!="") {
51                         $tmp_message  = $row['first_name'].' '.$row['last_name'].",\n\n";               
52                 }       
53                 $tmp_message .= _AT('instructor_request_reply', AT_BASE_HREF);
54
55                 if ($to_email != '') {
56                         require(AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php');
57
58                         $mail = new ATutorMailer;
59
60                         $mail->From     = $_config['contact_email'];
61                         $mail->AddAddress($to_email);
62                         $mail->Subject = _AT('instructor_request');
63                         $mail->Body    = $tmp_message;
64
65                         if(!$mail->Send()) {
66                            //echo 'There was an error sending the message';
67                            $msg->printErrors('SENDING_ERROR');
68                            exit;
69                         }
70
71                         unset($mail);
72                 }
73         }
74
75         $msg->addFeedback('PROFILE_UPDATED_ADMIN');
76 } else if (!empty($_GET) && !$_GET['submit']) {
77         $msg->addError('NO_ITEM_SELECTED');
78 }
79
80 require(AT_INCLUDE_PATH.'header.inc.php'); 
81
82 $sql    = "SELECT M.login, M.first_name, M.last_name, M.email, M.member_id, A.* FROM ".TABLE_PREFIX."members M, ".TABLE_PREFIX."instructor_approvals A WHERE A.member_id=M.member_id ORDER BY M.login";
83 $result = mysql_query($sql, $db);
84 $num_pending = mysql_num_rows($result);
85 ?>
86
87 <form name="form" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
88 <table class="data" summary="" rules="cols">
89 <thead>
90 <tr>
91         <th scope="col">&nbsp;</th>
92         <th scope="col"><?php echo _AT('login_name');     ?></th>
93         <th scope="col"><?php echo _AT('first_name');   ?></th>
94         <th scope="col"><?php echo _AT('last_name');    ?></th>
95         <th scope="col"><?php echo _AT('email');        ?></th>
96         <th scope="col"><?php echo _AT('notes');        ?></th>
97 </tr>
98 </thead>
99 <tfoot>
100 <tr>
101         <td colspan="6">
102         <input type="submit" name="deny" value="<?php echo _AT('deny'); ?>" /> 
103         <input type="submit" name="approve" value="<?php echo _AT('approve'); ?>" /></td>
104 </tr>
105 </tfoot>
106 <tbody>
107 <?php
108         if ($row = mysql_fetch_assoc($result)) {
109                 do {
110                         echo '<tr onmousedown="document.form[\'i'.$row['member_id'].'\'].checked = true;rowselect(this);" id="r_'.$row['member_id'].'">';
111                         echo '<td><input type="radio" name="id" value="'.$row['member_id'].'" id="i'.$row['member_id'].'" /></td>';
112                         echo '<td><label for="i'.$row['member_id'].'">'.AT_print($row['login'], 'members.login').'</label></td>';
113                         echo '<td>'.AT_print($row['first_name'], 'members.first_name').'</td>';
114                         echo '<td>'.AT_print($row['last_name'], 'members.last_name').'</td>';
115                         echo '<td>'.AT_print($row['email'], 'members.email').'</td>';
116                         
117                         echo '<td>'.AT_print($row['notes'], 'instructor_approvals.notes').'</td>';
118
119                         echo '</tr>';
120                 } while ($row = mysql_fetch_assoc($result));
121         } else {
122                 echo '<tr><td colspan="6">'._AT('none_found').'</td></tr>';
123         }
124 ?>
125 </tbody>
126 </table>
127 </form>
128
129 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>