2 /***********************************************************************/
4 /***********************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
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 /***********************************************************************/
15 $_user_location = 'users';
16 define('AT_INCLUDE_PATH', 'include/');
17 require (AT_INCLUDE_PATH.'vitals.inc.php');
19 $course = intval($_GET['course']);
21 $course = intval($_POST['form_course_id']);
28 $sql = "SELECT access, member_id FROM ".TABLE_PREFIX."courses WHERE course_id=$course";
29 $result = mysql_query($sql, $db);
30 $course_info = mysql_fetch_array($result);
32 if ($_POST['submit']) {
33 $_SESSION['enroll'] = AT_ENROLL_YES;
34 $_POST['form_course_id'] = intval($_POST['form_course_id']);
36 if ($course_info[0] == 'private') {
37 $sql = "INSERT INTO ".TABLE_PREFIX."course_enrollment VALUES ($_SESSION[member_id], $_POST[form_course_id], 'n', 0, '"._AT('student')."', 0)";
38 $result = mysql_query($sql, $db);
40 // send the email thing. if needed
42 $sql = "SELECT notify, member_id FROM ".TABLE_PREFIX."courses WHERE course_id=$_POST[form_course_id] AND notify=1";
43 $result = mysql_query($sql, $db);
44 if ($row = mysql_fetch_array($result)) {
45 // notify is enabled. get the email
46 $sql = "SELECT email, first_name, last_name FROM ".TABLE_PREFIX."members WHERE member_id=$row[member_id]";
47 $result = mysql_query($sql, $db);
48 $row = mysql_fetch_assoc($result);
50 $to_email = $row['email'];
52 $tmp_message = $row['first_name'].' '.$row['last_name'].",\n\n";
53 $tmp_message .= _AT('enrol_msg', $system_courses[$_POST['form_course_id']]['title']);
54 $tmp_message .= _AT('enrol_login');
55 if ($to_email != '') {
57 require(AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php');
59 $mail = new ATutorMailer;
61 $mail->From = $_config['contact_email'];
62 $mail->AddAddress($to_email);
63 $mail->Subject = _AT('course_enrolment');
64 $mail->Body = $tmp_message;
67 //echo 'There was an error sending the message';
68 $msg->printErrors('SENDING_ERROR');
75 // public or protected
76 $sql = "INSERT INTO ".TABLE_PREFIX."course_enrollment VALUES ($_SESSION[member_id], $_POST[form_course_id], 'y', 0, '"._AT('student')."', 0)";
77 $result = mysql_query($sql, $db);
81 if ($_SESSION['valid_user']) {
83 $sql = "SELECT * FROM ".TABLE_PREFIX."course_enrollment WHERE member_id=$_SESSION[member_id] AND course_id=$course";
84 $result = mysql_query($sql, $db);
85 $row = mysql_fetch_array($result);
87 if (($course_info[0] == 'public') || ($course_info[0] == 'protected')) {
90 $feedback = array('NOW_ENROLLED', $system_courses[$course]['title']);
91 $msg->addFeedback($feedback);
92 header("Location:index.php");
93 } else if ($course_info[1] != $_SESSION['member_id']) {
95 require(AT_INCLUDE_PATH.'header.inc.php'); ?>
97 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
98 <input type="hidden" name="form_course_id" value="<?php echo $course; ?>">
99 <div class="input-form">
101 <p><?php echo _AT('use_enrol_button'); ?></p>
104 <div class="row buttons">
105 <input type="submit" name="submit" value="<?php echo _AT('enroll_me'); ?>" />
111 // we own this course!
112 $msg->printErrors('ALREADY_OWNED');
116 require(AT_INCLUDE_PATH.'header.inc.php');
118 if ((!$_POST['submit']) && ($row == '')) {
120 $msg->printInfos('PRIVATE_ENROL'); ?>
122 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
123 <input type="hidden" name="form_course_id" value="<?php echo $course; ?>">
124 <input type="submit" name="submit" class="button" value="<?php echo _AT('request_enrollment'); ?>">
128 } else if ($_POST['submit']) {
129 $msg->printFeedbacks('APPROVAL_PENDING');
130 } else if ($course_info[1] != $_SESSION['member_id'] ){
131 // request has already been made
132 $msg->printErrors('ALREADY_ENROLED');
134 $msg->printErrors('ALREADY_OWNED');
139 require(AT_INCLUDE_PATH.'header.inc.php');
140 $msg->printErrors('LOGIN_ENROL');
142 <div class="input-form">
144 <h3><?php echo _AT('login'); ?></h3>
145 <p><a href="login.php?course=<?php echo $_SESSION[course_id]; ?>"><?php echo _AT('login_into_atutor'); ?></a></p>
149 <form action="registration.php" method="get">
150 <div class="input-form">
152 <h3><?php echo _AT('new_user');?></h3>
153 <p><?php echo _AT('registration_text'); ?></p>
155 <div class="row buttons">
156 <input type="submit" name="register" value="<?php echo _AT('register'); ?>" class="button" />
164 require(AT_INCLUDE_PATH.'footer.inc.php');