Fixing course protected by password see #5470

skala
Julio Montoya 12 years ago
parent d63a9ff1a8
commit e9a9a1a17e
  1. 16
      main/auth/courses.php
  2. 17
      main/auth/courses_controller.php
  3. 38
      main/inc/lib/auth.lib.php
  4. 11
      main/template/default/auth/courses_categories.php

@ -73,7 +73,7 @@ if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create
}
// filter actions
$actions = array('sortmycourses', 'createcoursecategory', 'subscribe', 'deletecoursecategory', 'display_courses','display_random_courses');
$actions = array('sortmycourses', 'createcoursecategory', 'subscribe', 'deletecoursecategory', 'display_courses', 'display_random_courses' , 'subscribe_user_with_password');
$action = 'display_random_courses';
$nameTools = get_lang('SortMyCourses');
@ -88,6 +88,10 @@ if ($action == 'subscribe') {
$nameTools = get_lang('CourseManagement');
}
if ($action == 'subscribe_user_with_password') {
$nameTools = get_lang('CourseManagement');
}
if ($action == 'display_random_courses' || $action == 'display_courses' ) {
$nameTools = get_lang('CourseManagement');
}
@ -164,9 +168,9 @@ if (isset($_REQUEST['search_course'])) {
}
}
// subscribe user to course
if (isset($_GET['subscribe_course'])) {
if ($ctok == $_GET['sec_token']) {
// Subscribe user to course
if (isset($_REQUEST['subscribe_course'])) {
if ($ctok == $_GET['sec_token']) {
$courses_controller->subscribe_user($_GET['subscribe_course'], $_GET['search_term'], $_GET['category_code']);
}
}
@ -185,6 +189,10 @@ if (isset($_POST['unsubscribe'])) {
}
}
switch ($action) {
case 'subscribe_user_with_password':
$courses_controller->subscribe_user($_POST['subscribe_user_with_password'], $_POST['search_term'], $_POST['category_code']);
exit;
break;
case 'createcoursecategory':
$courses_controller->categories_list($action);
break;

@ -79,7 +79,7 @@ class CoursesController { // extends Controller {
* @param string action
* @param string Category code (optional)
*/
public function courses_categories($action, $category_code = null, $message = '', $error = '') {
public function courses_categories($action, $category_code = null, $message = '', $error = '', $content = null) {
$data = array();
$browse_course_categories = $this->model->browse_course_categories();
@ -117,6 +117,7 @@ class CoursesController { // extends Controller {
$data['user_coursecodes'] = $user_coursecodes;
$data['action'] = $action;
$data['message'] = $message;
$data['content'] = $content;
$data['error'] = $error;
// render to the view
@ -170,23 +171,19 @@ class CoursesController { // extends Controller {
*/
public function subscribe_user($course_code, $search_term, $category_code) {
$data = array();
$result = $this->model->subscribe_user($course_code);
$result = $this->model->subscribe_user($course_code);
if (!$result) {
$error = get_lang('CourseRegistrationCodeIncorrect');
} else {
//Redirect directly to the course after subscription
/*
if ($result) {
$url = api_get_course_url($course_code);
header('Location: '.$url);
exit;
}*/
$message = $result;
$message = $result['message'];
$content = $result['content'];
}
if (!empty($search_term)) {
$this->search_courses($search_term, $message, $error);
} else {
$this->courses_categories('subcribe', $category_code, $message, $error);
$this->courses_categories('subcribe', $category_code, $message, $error, $content);
}
return $result;
}

@ -614,40 +614,42 @@ class Auth {
* @return string Message about results
*/
public function subscribe_user($course_code) {
global $_user;
$user_id = api_get_user_id();
$all_course_information = CourseManager::get_course_information($course_code);
if ($all_course_information['registration_code'] == '' || $_POST['course_registration_code'] == $all_course_information['registration_code']) {
if (api_is_platform_admin()) {
$status_user_in_new_course = COURSEMANAGER;
} else {
$status_user_in_new_course = null;
}
if (CourseManager::add_user_to_course($_user['user_id'], $course_code, $status_user_in_new_course)) {
if (CourseManager::add_user_to_course($user_id, $course_code, $status_user_in_new_course)) {
$send = api_get_course_setting('email_alert_to_teacher_on_new_user_in_course', $course_code);
if ($send == 1) {
CourseManager::email_to_tutor($_user['user_id'], $course_code, $send_to_tutor_also = false);
CourseManager::email_to_tutor($user_id, $course_code, $send_to_tutor_also = false);
} else if ($send == 2) {
CourseManager::email_to_tutor($_user['user_id'], $course_code, $send_to_tutor_also = true);
CourseManager::email_to_tutor($user_id, $course_code, $send_to_tutor_also = true);
}
return get_lang('EnrollToCourseSuccessful');
$message = get_lang('EnrollToCourseSuccessful');
} else {
return get_lang('ErrorContactPlatformAdmin');
}
$message = get_lang('ErrorContactPlatformAdmin');
}
return array('message' => $message);
} else {
$return = '';
if (isset($_POST['course_registration_code']) && $_POST['course_registration_code'] != $all_course_information['registration_code']) {
return false;
}
$return .= get_lang('CourseRequiresPassword') . '<br />';
$return .= $all_course_information['visual_code'] . ' - ' . $all_course_information['title'];
$return .= "<form action=\"" . api_get_path(WEB_CODE_PATH) . "auth/courses.php?action=subscribe_course&sec_token=" . $_SESSION['sec_token'] . "&subscribe_course=" . $all_course_information['code'] . "&category_code=" . $all_course_information['category_code'] . " \" method=\"post\">";
$return .= '<input type="hidden" name="token" value="' . $_SESSION['sec_token'] . '" />';
$return .= "<input type=\"text\" name=\"course_registration_code\" value=\"" . $_POST['course_registration_code'] . "\" />";
$return .= "<input type=\"submit\" name=\"submit_course_registration_code\" value=\"OK\" alt=\"" . get_lang('SubmitRegistrationCode') . "\" /></form>";
return $return;
$message = get_lang('CourseRequiresPassword') . '<br />';
$message .= $all_course_information['title'].' ('.$all_course_information['visual_code'].') ';
$action = api_get_path(WEB_CODE_PATH) . "auth/courses.php?action=subscribe_user_with_password&sec_token=" . $_SESSION['sec_token'];
$form = new FormValidator('subscribe_user_with_password', 'post', $action);
$form->addElement('hidden', 'sec_token', $_SESSION['sec_token']);
$form->addElement('hidden', 'subscribe_user_with_password', $all_course_information['code']);
$form->addElement('text', 'course_registration_code');
$form->addElement('button', 'submit', get_lang('SubmitRegistrationCode'));
$content = $form->return_form();
return array('message' => $message, 'content' => $content);
}
}
}

@ -8,7 +8,7 @@
*/
$stok = Security::get_token();
?>
<script type="text/javascript">
<script>
$(document).ready( function() {
$('.star-rating li a').live('click', function(event) {
var id = $(this).parents('ul').attr('id');
@ -111,6 +111,8 @@ $stok = Security::get_token();
<?php
if (!empty($message)) { Display::display_confirmation_message($message, false); }
if (!empty($error)) { Display::display_error_message($error, false); }
if (!empty($content)) { echo $content; }
if (!empty($search_term)) {
echo "<p><strong>".get_lang('SearchResultsFor')." ".Security::remove_XSS($_POST['search_term'])."</strong><br />";
@ -185,7 +187,7 @@ $stok = Security::get_token();
// If user is already subscribed to the course
if (!api_is_anonymous() && in_array($course['code'], $user_coursecodes)) {
if ($course['unsubscribe'] == UNSUBSCRIBE_ALLOWED) {
if ($course['unsubscribe'] == UNSUBSCRIBE_ALLOWED) {
echo ' <a class="btn btn-primary" href="'. api_get_self().'?action=unsubscribe&amp;sec_token='.$stok.'&amp;unsubscribe='.$course['code'].'&amp;search_term='.$search_term.'&amp;category_code='.$code.'">'.get_lang('Unsubscribe').'</a>';
}
echo '<br />';
@ -193,16 +195,15 @@ $stok = Security::get_token();
echo Display::label(get_lang("AlreadyRegisteredToCourse"), "info");
}
echo '</div>';
echo '</p>';
echo '</div>';
echo '<div class="span2">';
echo '<div class="course-block-popularity"><span>'.get_lang('ConnectionsLastMonth').'</span><div class="course-block-popularity-score">'.$count_connections.'</div></div>';
echo '</div>';
echo '</div></div>';
}
} else {
} else {
if (!isset($_POST['subscribe_user_with_password']))
echo Display::display_warning_message(get_lang('ThereAreNoCoursesInThisCategory'));
}
?>

Loading…
Cancel
Save