simplified-desktop theme
[atutor.git] / docs / mods / _core / users / instructor_requests.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 = '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->addError('SENDING_ERROR');
68                         }
69
70                         unset($mail);
71                 }
72         }
73
74         $msg->addFeedback('PROFILE_UPDATED_ADMIN');
75 } else if (!empty($_GET) && !$_GET['submit']) {
76         $msg->addError('NO_ITEM_SELECTED');
77 }
78
79 require(AT_INCLUDE_PATH.'header.inc.php'); 
80
81 $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";
82 $result = mysql_query($sql, $db);
83 $num_pending = mysql_num_rows($result);
84
85 $savant->assign('result', $result);
86 $savant->assign('num_pending', $num_pending);
87 $savant->display('admin/users/instructor_requests.tmpl.php');
88 require(AT_INCLUDE_PATH.'footer.inc.php'); ?>