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');
22 header("Location:users/browse.php");
26 $course = intval($_GET['course']);
28 $course = intval($_POST['form_course_id']);
35 $sql = "SELECT access, member_id FROM ".TABLE_PREFIX."courses WHERE course_id=$course";
36 $result = mysql_query($sql, $db);
37 $course_info = mysql_fetch_array($result);
39 if ($_POST['submit']) {
40 $_SESSION['enroll'] = AT_ENROLL_YES;
41 $_POST['form_course_id'] = intval($_POST['form_course_id']);
43 if ($course_info[0] == 'private') {
44 $sql = "INSERT INTO ".TABLE_PREFIX."course_enrollment VALUES ($_SESSION[member_id], $_POST[form_course_id], 'n', 0, '"._AT('student')."', 0)";
45 $result = mysql_query($sql, $db);
47 // send the email thing. if needed
49 $sql = "SELECT notify, member_id FROM ".TABLE_PREFIX."courses WHERE course_id=$_POST[form_course_id] AND notify=1";
50 $result = mysql_query($sql, $db);
51 if ($row = mysql_fetch_array($result)) {
52 // notify is enabled. get the email
53 $sql = "SELECT email, first_name, last_name FROM ".TABLE_PREFIX."members WHERE member_id=$row[member_id]";
54 $result = mysql_query($sql, $db);
55 $row = mysql_fetch_assoc($result);
57 $to_email = $row['email'];
59 $tmp_message = $row['first_name'].' '.$row['last_name'].",\n\n";
60 $tmp_message .= _AT('enrol_msg', $system_courses[$_POST['form_course_id']]['title']);
61 $tmp_message .= _AT('enrol_login');
62 if ($to_email != '') {
64 require(AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php');
66 $mail = new ATutorMailer;
68 $mail->From = $_config['contact_email'];
69 $mail->AddAddress($to_email);
70 $mail->Subject = _AT('course_enrolment');
71 $mail->Body = $tmp_message;
74 //echo 'There was an error sending the message';
75 $msg->printErrors('SENDING_ERROR');
82 // public or protected
83 $sql = "INSERT INTO ".TABLE_PREFIX."course_enrollment VALUES ($_SESSION[member_id], $_POST[form_course_id], 'y', 0, '"._AT('student')."', 0)";
84 $result = mysql_query($sql, $db);
88 if ($_SESSION['valid_user']) {
90 $sql = "SELECT * FROM ".TABLE_PREFIX."course_enrollment WHERE member_id=$_SESSION[member_id] AND course_id=$course";
91 $result = mysql_query($sql, $db);
92 $row = mysql_fetch_array($result);
94 if (($course_info[0] == 'public') || ($course_info[0] == 'protected')) {
97 $feedback = array('NOW_ENROLLED', $system_courses[$course]['title']);
98 $msg->addFeedback($feedback);
99 header("Location:index.php");
100 } else if ($course_info[1] != $_SESSION['member_id']) {
102 require(AT_INCLUDE_PATH.'header.inc.php'); ?>
104 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
105 <input type="hidden" name="form_course_id" value="<?php echo $course; ?>">
106 <div class="input-form">
108 <p><?php echo _AT('use_enrol_button'); ?></p>
111 <div class="row buttons">
112 <input type="submit" name="submit" value="<?php echo _AT('enroll_me'); ?>" />
113 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
119 // we own this course!
120 $msg->printErrors('ALREADY_OWNED');
124 require(AT_INCLUDE_PATH.'header.inc.php');
126 if ((!$_POST['submit']) && ($row == '')) {
128 $msg->printInfos('PRIVATE_ENROL'); ?>
130 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
131 <input type="hidden" name="form_course_id" value="<?php echo $course; ?>">
132 <input type="submit" name="submit" class="button" value="<?php echo _AT('request_enrollment'); ?>">
136 } else if ($_POST['submit']) {
137 $msg->printFeedbacks('APPROVAL_PENDING');
138 } else if ($course_info[1] != $_SESSION['member_id'] ){
139 // request has already been made
140 $msg->printErrors('ALREADY_ENROLED');
142 $msg->printErrors('ALREADY_OWNED');
147 require(AT_INCLUDE_PATH.'header.inc.php');
148 $msg->printErrors('LOGIN_ENROL');
150 <div class="input-form">
152 <h3><?php echo _AT('login'); ?></h3>
153 <p><a href="login.php?course=<?php echo $_SESSION[course_id]; ?>"><?php echo _AT('login_into_atutor'); ?></a></p>
157 <form action="registration.php" method="get">
158 <div class="input-form">
160 <h3><?php echo _AT('new_user');?></h3>
161 <p><?php echo _AT('registration_text'); ?></p>
163 <div class="row buttons">
164 <input type="submit" name="register" value="<?php echo _AT('register'); ?>" class="button" />
172 require(AT_INCLUDE_PATH.'footer.inc.php');