Merge pull request #1620 from jloguercio/1.11.x

Redirect To Session feature after inscription - BT#12220
remotes/angel/1.11.x
José Loguercio 8 years ago committed by GitHub
commit b5113d3c32
  1. 28
      main/auth/inscription.php
  2. 29
      main/inc/lib/sessionmanager.lib.php
  3. 3
      main/install/configuration.dist.php
  4. 8
      main/session/about.php
  5. 2
      main/template/default/session/about.tpl

@ -61,6 +61,17 @@ $user_already_registered_show_terms = false;
if (api_get_setting('allow_terms_conditions') == 'true') {
$user_already_registered_show_terms = isset($_SESSION['term_and_condition']['user_id']);
}
// Direct Link Session Subscription feature #12220
$sessionRedirect = isset($_REQUEST['s']) && !empty($_REQUEST['s']) ? $_REQUEST['s'] : null;
$onlyOneCourseSessionRedirect = isset($_REQUEST['cr']) && !empty($_REQUEST['cr']) ? $_REQUEST['cr'] : null;
if (api_get_configuration_value('allow_redirect_to_session_after_inscription_about')) {
if (!empty($sessionRedirect)) {
Session::write('session_redirect', $sessionRedirect);
Session::write('only_one_course_session_redirect', $onlyOneCourseSessionRedirect);
}
}
// Direct Link Subscription feature #5299
$course_code_redirect = isset($_REQUEST['c']) && !empty($_REQUEST['c']) ? $_REQUEST['c'] : null;
@ -478,6 +489,7 @@ if (api_get_setting('allow_terms_conditions') == 'true') {
$form->addButtonCreate(get_lang('RegisterUser'));
$course_code_redirect = Session::read('course_redirect');
$sessionToRedirect = Session::read('session_redirect');
if ($form->validate()) {
$values = $form->getSubmitValues(1);
@ -617,6 +629,19 @@ if ($form->validate()) {
Database::query($sql);
}
// Saving user to Session if it was set
if (!empty($sessionToRedirect)) {
$sessionInfo = api_get_session_info($sessionToRedirect);
if (!empty($sessionInfo)) {
SessionManager::subscribe_users_to_session(
$sessionToRedirect,
[$user_id],
SESSION_VISIBLE_READ_ONLY,
false
);
}
}
// Saving user to course if it was set.
if (!empty($course_code_redirect)) {
$course_info = api_get_course_info($course_code_redirect);
@ -828,6 +853,7 @@ if ($form->validate()) {
}
}
SessionManager::redirectToSession();
$form_data = CourseManager::redirectToCourse($form_data);
$form_register = new FormValidator('form_register', 'post', $form_data['action']);
@ -846,6 +872,8 @@ if ($form->validate()) {
// Just in case
Session::erase('course_redirect');
Session::erase('exercise_redirect');
Session::erase('session_redirect');
Session::erase('only_one_course_session_redirect');
if (CustomPages::enabled()) {
CustomPages::display(

@ -8171,4 +8171,33 @@ class SessionManager
return Database::store_result($result, 'ASSOC');
}
/**
* subsscribe and redirect to session after inscription
*/
public static function redirectToSession()
{
$sessionId = isset($_SESSION['session_redirect']) ? $_SESSION['session_redirect'] : null;
$onlyOneCourseSessionToRedirect = isset($_SESSION['only_one_course_session_redirect']) ? $_SESSION['only_one_course_session_redirect'] : null;
$userId = api_get_user_id();
$sessionInfo = api_get_session_info($sessionId);
if (!empty($sessionInfo)) {
$response = self::isUserSubscribedAsStudent($sessionId, $userId);
if ($response) {
$urlToRedirect = api_get_path(WEB_CODE_PATH) . 'session/index.php?session_id=' . $sessionId;
if (!empty($onlyOneCourseSessionToRedirect)) {
$urlToRedirect = api_get_path(WEB_PATH) . 'courses/' . $onlyOneCourseSessionToRedirect . '/index.php?id_session=' . $sessionId;
}
header('Location: ' . $urlToRedirect);
exit;
}
}
}
}

@ -269,4 +269,5 @@ $_configuration['system_stable'] = NEW_VERSION_STABLE;
//$_configuration['mail_header_style'] = '';
// Show all agenda events in personal agenda from all session no matter the visibility.
//$_configuration['personal_agenda_show_all_session_events'] = false;
// Allows to redirect to the session after the inscription in session about
// $_configuration['allow_redirect_to_session_after_inscription_about'] = false;

@ -180,6 +180,14 @@ $template->assign(
)
);
$redirectToSession = api_get_configuration_value('allow_redirect_to_session_after_inscription_about');
$redirectToSession = $redirectToSession ? '?s=' . $sessionId : false;
$coursesInThisSession = SessionManager::get_course_list_by_session_id($sessionId);
$coursesCount = count($coursesInThisSession);
$redirectToSession = $coursesCount == 1 ? $redirectToSession . '&cr=' . array_values($coursesInThisSession)[0]['directory'] : $redirectToSession;
$template->assign('redirect_to_session', $redirectToSession);
$template->assign('courses', $courses);
$essence = Essence\Essence::instance();
$template->assign('essence', $essence);

@ -228,7 +228,7 @@
</div>
{% elseif not _u.logged %}
{% if 'allow_registration'|get_setting == 'true' %}
<a href="{{ _p.web_main ~ 'auth/inscription.php' }}" class="btn btn-info btn-lg">
<a href="{{ _p.web_main ~ 'auth/inscription.php' ~ redirect_to_session }}" class="btn btn-info btn-lg">
<em class="fa fa-sign-in fa-fw"></em> {{ 'SignUp'|get_lang }}
</a>
{% endif %}

Loading…
Cancel
Save