gotocourse.php 2.9 KB

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