2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay & Joel Kronenberg */
6 /* Adaptive Technology Resource Centre / University of Toronto */
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 /****************************************************************/
14 define('AT_INCLUDE_PATH', 'include/');
15 require (AT_INCLUDE_PATH.'vitals.inc.php');
17 $course = intval($_GET['course']);
19 $course = intval($_POST['form_course_id']);
26 $sql = "SELECT access, member_id FROM ".TABLE_PREFIX."courses WHERE course_id=$course";
27 $result = mysql_query($sql, $db);
28 $course_info = mysql_fetch_array($result);
30 if ($_POST['submit']) {
31 $_SESSION['enroll'] = AT_ENROLL_YES;
32 $_POST['form_course_id'] = intval($_POST['form_course_id']);
34 if ($course_info[0] == 'private') {
35 $sql = "INSERT INTO ".TABLE_PREFIX."course_enrollment VALUES ($_SESSION[member_id], $_POST[form_course_id], 'n', 0, '"._AT('student')."', 0)";
36 $result = mysql_query($sql, $db);
38 // send the email thing. if needed
40 $sql = "SELECT notify, member_id FROM ".TABLE_PREFIX."courses WHERE course_id=$_POST[form_course_id] AND notify=1";
41 $result = mysql_query($sql, $db);
42 if ($row = mysql_fetch_array($result)) {
43 // notify is enabled. get the email
44 $sql = "SELECT email, first_name, last_name FROM ".TABLE_PREFIX."members WHERE member_id=$row[member_id]";
45 $result = mysql_query($sql, $db);
46 $row = mysql_fetch_assoc($result);
48 $to_email = $row['email'];
50 $tmp_message = $row['first_name'].' '.$row['last_name'].",\n\n";
51 $tmp_message .= _AT('enrol_msg', $system_courses[$_POST['form_course_id']]['title']);
52 $tmp_message .= _AT('enrol_login');
53 if ($to_email != '') {
55 require(AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php');
57 $mail = new ATutorMailer;
59 $mail->From = $_config['contact_email'];
60 $mail->AddAddress($to_email);
61 $mail->Subject = _AT('course_enrolment');
62 $mail->Body = $tmp_message;
65 //echo 'There was an error sending the message';
66 $msg->printErrors('SENDING_ERROR');
73 // public or protected
74 $sql = "INSERT INTO ".TABLE_PREFIX."course_enrollment VALUES ($_SESSION[member_id], $_POST[form_course_id], 'y', 0, '"._AT('student')."', 0)";
75 $result = mysql_query($sql, $db);
79 if ($_SESSION['valid_user']) {
81 $sql = "SELECT * FROM ".TABLE_PREFIX."course_enrollment WHERE member_id=$_SESSION[member_id] AND course_id=$course";
82 $result = mysql_query($sql, $db);
83 $row = mysql_fetch_array($result);
85 if (($course_info[0] == 'public') || ($course_info[0] == 'protected')) {
88 $feedback = array('NOW_ENROLLED', $system_courses[$course]['title']);
89 $msg->addFeedback($feedback);
90 header("Location:index.php");
91 } else if ($course_info[1] != $_SESSION['member_id']) {
93 require(AT_INCLUDE_PATH.'header.inc.php'); ?>
95 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
96 <input type="hidden" name="form_course_id" value="<?php echo $course; ?>">
97 <div class="input-form">
99 <p><?php echo _AT('use_enrol_button'); ?></p>
102 <div class="row buttons">
103 <input type="submit" name="submit" value="<?php echo _AT('enroll_me'); ?>" />
109 // we own this course!
110 $msg->printErrors('ALREADY_OWNED');
114 require(AT_INCLUDE_PATH.'header.inc.php');
116 if ((!$_POST['submit']) && ($row == '')) {
118 $msg->printInfos('PRIVATE_ENROL'); ?>
120 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
121 <input type="hidden" name="form_course_id" value="<?php echo $course; ?>">
122 <input type="submit" name="submit" class="button" value="<?php echo _AT('request_enrollment'); ?>">
126 } else if ($_POST['submit']) {
127 $msg->printFeedbacks('APPROVAL_PENDING');
128 } else if ($course_info[1] != $_SESSION['member_id'] ){
129 // request has already been made
130 $msg->printErrors('ALREADY_ENROLED');
132 $msg->printErrors('ALREADY_OWNED');
137 require(AT_INCLUDE_PATH.'header.inc.php');
138 $msg->printErrors('LOGIN_ENROL');
140 <div class="input-form">
142 <h3><?php echo _AT('login'); ?></h3>
143 <p><a href="login.php?course=<?php echo $_SESSION[course_id]; ?>"><?php echo _AT('login_into_atutor'); ?></a></p>
147 <form action="registration.php" method="get">
148 <div class="input-form">
150 <h3><?php echo _AT('new_user');?></h3>
151 <p><?php echo _AT('registration_text'); ?></p>
153 <div class="row buttons">
154 <input type="submit" name="register" value="<?php echo _AT('register'); ?>" class="button" />
162 require(AT_INCLUDE_PATH.'footer.inc.php');