forked from atutor/ATutor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enroll.php
175 lines (137 loc) · 5.36 KB
/
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
/***********************************************************************/
/* ATutor */
/***********************************************************************/
/* Copyright (c) 2002-2013 */
/* 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($_POST['cancel']){
header("Location:users/browse.php");
exit;
}
$course = intval($_GET['course']);
if ($course == 0) {
$course = intval($_POST['form_course_id']);
}
if ($course == 0) {
exit;
}
$sql = "SELECT access, member_id FROM ".TABLE_PREFIX."courses WHERE course_id=$course";
$course_info = queryDB($sql, array(TABLE_PREFIX, $course), TRUE);
if ($_POST['submit']) {
$_SESSION['enroll'] = AT_ENROLL_YES;
$_POST['form_course_id'] = intval($_POST['form_course_id']);
if ($course_info['access'] == 'private') {
$sql = "INSERT INTO %scourse_enrollment VALUES (%d, %d, 'n', 0, '"._AT('student')."', 0)";
$result = queryDB($sql, array(TABLE_PREFIX,$_SESSION['member_id'], $_POST['form_course_id']));
// send the email thing. if needed
$sql = "SELECT notify, member_id FROM %scourses WHERE course_id=%d AND notify=1";
$row = queryDB($sql, array(TABLE_PREFIX, $_POST['form_course_id']), TRUE);
if (isset($row['member_id']) && $row['member_id'] !='') {
// notify is enabled. get the email
$sql = "SELECT email, first_name, last_name FROM %smembers WHERE member_id=%d";
$row = queryDB($sql, array(TABLE_PREFIX, $row['member_id']), TRUE);
$to_email = $row['email'];
$tmp_message = $row['first_name'].' '.$row['last_name'].",\n\n";
$tmp_message .= _AT('enrol_msg', $system_courses[$_POST['form_course_id']]['title']);
$tmp_message .= _AT('enrol_login');
if ($to_email != '') {
require(AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php');
$mail = new ATutorMailer;
$mail->From = $_config['contact_email'];
$mail->AddAddress($to_email);
$mail->Subject = _AT('course_enrolment');
$mail->Body = $tmp_message;
if(!$mail->Send()) {
//echo 'There was an error sending the message';
$msg->printErrors('SENDING_ERROR');
exit;
}
unset($mail);
}
}
} else {
// public or protected
$sql = "INSERT INTO %scourse_enrollment VALUES ('%d', '%d', 'y', 0, '"._AT('student')."', 0)";
$result = queryDB($sql, array(TABLE_PREFIX, $_SESSION['member_id'], $_POST['form_course_id']));
}
}
if ($_SESSION['valid_user'] === true) {
$sql = "SELECT * FROM %scourse_enrollment WHERE member_id=%d AND course_id=%d";
$row = queryDB($sql, array(TABLE_PREFIX,$_SESSION['member_id'], $course ), TRUE);
if (($course_info['access'] == 'public') || ($course_info['access'] == 'protected')) {
if ($row['member_id'] != '') {
$feedback = array('NOW_ENROLLED', $system_courses[$course]['title']);
$msg->addFeedback($feedback);
header("Location:index.php");
} else if ($course_info['member_id'] != $_SESSION['member_id']) {
require(AT_INCLUDE_PATH.'header.inc.php'); ?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="form_course_id" value="<?php echo $course; ?>">
<div class="input-form">
<div class="row">
<p><?php echo _AT('use_enrol_button'); ?></p>
</div>
<div class="row buttons">
<input type="submit" name="submit" value="<?php echo _AT('enroll_me'); ?>" />
<input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
</div>
</div>
</form>
<?php
} else {
// we own this course!
$msg->printErrors('ALREADY_OWNED');
}
} else { // private
require(AT_INCLUDE_PATH.'header.inc.php');
if ((!$_POST['submit']) && ($row == '')) {
$msg->printInfos('PRIVATE_ENROL'); ?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="form_course_id" value="<?php echo $course; ?>">
<input type="submit" name="submit" class="button" value="<?php echo _AT('request_enrollment'); ?>">
</form>
<?php
} else if ($_POST['submit']) {
$msg->printFeedbacks('APPROVAL_PENDING');
} else if ($course_info['member_id'] != $_SESSION['member_id'] ){
// request has already been made
$msg->printErrors('ALREADY_ENROLED');
} else {
$msg->printErrors('ALREADY_OWNED');
}
}
} else {
require(AT_INCLUDE_PATH.'header.inc.php');
$msg->printInfos('LOGIN_ENROL');
?>
<div class="input-form">
<div class="row">
<h3><?php echo _AT('login'); ?></h3>
<p><a href="login.php?course=<?php echo $_SESSION[course_id]; ?>"><?php echo _AT('login_into_atutor'); ?></a></p>
</div>
</div>
<form action="registration.php" method="get">
<div class="input-form">
<div class="row">
<h3><?php echo _AT('new_user');?></h3>
<p><?php echo _AT('registration_text'); ?></p>
</div>
<div class="row buttons">
<input type="submit" name="register" value="<?php echo _AT('register'); ?>" class="button" />
</div>
</div>
</form>
<?php
}
require(AT_INCLUDE_PATH.'footer.inc.php');
?>