forked from atutor/ATutor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprivate_enroll.php
128 lines (104 loc) · 4.33 KB
/
private_enroll.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/****************************************************************/
/* ATutor */
/****************************************************************/
/* Copyright (c) 2002-2010 */
/* Inclusive Design Institute */
/* http://atutor.ca */
/* */
/* This program is free software. You can redistribute it and/or*/
/* modify it under the terms of the GNU General Public License */
/* as published by the Free Software Foundation. */
/****************************************************************/
// $Id$
$_user_location = 'users';
define('AT_INCLUDE_PATH', '../include/');
require(AT_INCLUDE_PATH.'vitals.inc.php');
if (!$_SESSION['valid_user']) {
require(AT_INCLUDE_PATH.'header.inc.php');
$msg->printErrors('LOGIN_ENROL');
require(AT_INCLUDE_PATH.'footer.inc.php');
exit;
}
$course = intval($_REQUEST['course']);
if ($course == 0) {
exit;
}
$sql = "SELECT access, member_id FROM %scourses WHERE course_id=%d";
$course_info = queryDB($sql, array(TABLE_PREFIX, $course), TRUE);
if ($_POST['submit']) {
$_SESSION['enroll'] = AT_ENROLL_YES;
if ($course_info['access'] == 'private') {
$sql = "INSERT INTO %scourse_enrollment VALUES (%d, %d, 'n', 0, '%s', 0)";
$result = queryDB($sql, array(TABLE_PREFIX, $_SESSION['member_id'], $course, _AT('student')));
// send the email - if needed
if ($system_courses[$course]['notify'] == 1) {
$mail_list = array(); //initialize an array to store all the pending emails
//Get the list of students with enrollment privilege
$module =& $moduleFactory->getModule('_core/enrolment');
$sql = "SELECT email, first_name, last_name, `privileges` FROM %smembers m INNER JOIN %scourse_enrollment ce ON m.member_id=ce.member_id WHERE ce.privileges > 0 AND ce.course_id=%d";
$rows_members = queryDB($sql, array(TABLE_PREFIX, TABLE_PREFIX, $course));
foreach($rows_members as $row){
if (query_bit($row['privileges'], $module->getPrivilege())){
unset($row['privileges']); //we don't need the privilege to flow around
$mail_list[] = $row;
}
}
//Get instructor information
$ins_id = $system_courses[$course]['member_id'];
$sql = "SELECT email, first_name, last_name FROM %smembers WHERE member_id=%d";
$row = queryDB($sql, array(TABLE_PREFIX, $ins_id), TRUE);
$mail_list[] = $row;
//Send email notification to both assistants with privileges & Instructor
foreach ($mail_list as $row){
$to_email = $row['email'];
$tmp_message = $row['first_name'] .' ' . $row['last_name']."\n\n";
$tmp_message .= _AT('enrol_messagenew', $system_courses[$course]['title'], AT_BASE_HREF );
if ($to_email != '') {
require(AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php');
$mail = new ATutorMailer;
$mail->From = $_config['contact_email'];
$mail->FromName = $_config['site_name'];
$mail->AddAddress($to_email);
$mail->Subject = _AT('enrol_message3');
$mail->Body = $tmp_message;
if (!$mail->Send()) {
require(AT_INCLUDE_PATH.'header.inc.php');
$msg->printErrors('SENDING_ERROR');
require(AT_INCLUDE_PATH.'footer.inc.php');
exit;
}
unset($mail);
}
}
}
$msg->addFeedback('APPROVAL_PENDING');
header('Location: index.php');
exit;
} else {
$sql = "INSERT INTO %scourse_enrollment VALUES (%d, %d, 'y', 0, '%s', 0)";
$result = queryDB($sql, array(TABLE_PREFIX, $_SESSION['member_id'], $course, _AT('student')));
}
}
$sql = "SELECT * FROM %scourse_enrollment WHERE member_id=%d AND course_id=%d";
$row_in = queryDB($sql, array(TABLE_PREFIX, $_SESSION['member_id'], $course), TRUE);
// request has already been made
if ($row_in['member_id'] == $_SESSION['member_id'] ) {
$msg->addFeedback('ALREADY_REQUESTED');
header('Location: ./index.php');
exit;
}
require(AT_INCLUDE_PATH.'header.inc.php');
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="course" value="<?php echo $course; ?>">
<div class="input-form">
<div class="row">
<?php echo _AT('private_enroll'); ?>
</div>
<div class="row buttons">
<input type="submit" name="submit" value="<?php echo _AT('request_enrollment'); ?>" />
</div>
</div>
</form>
<?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>