gotocourse.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Allow the user to login to a course after reaching a course URL
  5. * (e.g. http://chamilo.chamilo.org/courses/MYCOURSE/?id_session=0 )
  6. * See https://support.chamilo.org/issues/6768.
  7. *
  8. * Author : hubert.borderiou@grenet.fr
  9. */
  10. require_once __DIR__.'/../inc/global.inc.php';
  11. require_once api_get_path(SYS_PATH).'main/auth/cas/authcas.php';
  12. $msg = null;
  13. if (isset($_GET['firstpage'])) {
  14. $firstpage = $_GET['firstpage'];
  15. // if course is public, go to course without auth
  16. $tab_course_info = api_get_course_info($firstpage);
  17. api_set_firstpage_parameter($firstpage);
  18. $tpl = new Template(null, 1, 1);
  19. $action = api_get_self().'?'.Security::remove_XSS($_SERVER['QUERY_STRING']);
  20. $action = str_replace('&amp;', '&', $action);
  21. $form = new FormValidator('formLogin', 'post', $action, null, ['class' => 'form-stacked']);
  22. $params = [
  23. 'placeholder' => get_lang('UserName'),
  24. ];
  25. // Avoid showing the autocapitalize option if the browser doesn't
  26. // support it: this attribute is against the HTML5 standard
  27. if (api_browser_support('autocapitalize')) {
  28. $params['autocapitalize'] = 'none';
  29. }
  30. $form->addElement(
  31. 'text',
  32. 'login',
  33. null,
  34. $params
  35. );
  36. $params = [
  37. 'placeholder' => get_lang('Password'),
  38. ];
  39. if (api_browser_support('autocapitalize')) {
  40. $params['autocapitalize'] = 'none';
  41. }
  42. $form->addElement(
  43. 'password',
  44. 'password',
  45. null,
  46. $params
  47. );
  48. $form->addButtonNext(get_lang('LoginEnter'), 'submitAuth');
  49. // see same text in main_api.lib.php function api_not_allowed
  50. if (api_is_cas_activated()) {
  51. $msg .= Display::return_message(sprintf(get_lang('YouHaveAnInstitutionalAccount'), api_get_setting("Institution")), '', false);
  52. $msg .= Display::div("<br/><a href='".get_cas_direct_URL(api_get_course_id())."'>".getCASLogoHTML()." ".sprintf(get_lang('LoginWithYourAccount'), api_get_setting("Institution"))."</a><br/><br/>", ['align' => 'center']);
  53. $msg .= Display::return_message(get_lang('YouDontHaveAnInstitutionAccount'));
  54. $msg .= "<p style='text-align:center'><a href='#' onclick='$(this).parent().next().toggle()'>".get_lang('LoginWithExternalAccount')."</a></p>";
  55. $msg .= "<div style='display:none;'>";
  56. }
  57. $msg .= '<div class="well_login">';
  58. $msg .= $form->returnForm();
  59. $msg .= '</div>';
  60. if (api_is_cas_activated()) {
  61. $msg .= "</div>";
  62. }
  63. $msg .= '<hr/><p style="text-align:center"><a href="'.api_get_path(WEB_PATH).'">'.get_lang('ReturnToCourseHomepage').'</a></p>';
  64. $tpl->assign('content', '<h4>'.get_lang('LoginToGoToThisCourse').'</h4>'.$msg);
  65. $tpl->display_one_col_template();
  66. } else {
  67. api_delete_firstpage_parameter();
  68. header('Location: '.api_get_path(WEB_PATH).'index.php');
  69. exit;
  70. }