index.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * @package chamilo.plugin.before_login
  4. */
  5. if (api_is_anonymous()) {
  6. // Only available in the index.php page
  7. $loginAccepted = isset($_SESSION['before_login_accepted']) ? $_SESSION['before_login_accepted'] : null;
  8. $parsedUrl = parse_url($_SERVER['REQUEST_URI']);
  9. $currentPage = str_replace('index.php', '', $parsedUrl['path']);
  10. if (api_get_path(REL_PATH) !== $currentPage) {
  11. return null;
  12. }
  13. // Hide only if the before_login_accepted session was set to ON.
  14. if ($loginAccepted) {
  15. return null;
  16. }
  17. // Only available for the selected language.
  18. $languageToActivate = api_get_plugin_setting('before_login', 'language');
  19. if (api_get_interface_language() != $languageToActivate) {
  20. return null;
  21. }
  22. $option1 = api_get_plugin_setting('before_login', 'option1');
  23. $urlOption1 = api_get_plugin_setting('before_login', 'option1_url');
  24. $option2 = api_get_plugin_setting('before_login', 'option2');
  25. $urlOption2 = api_get_plugin_setting('before_login', 'option2_url');
  26. $form = new FormValidator('form');
  27. $renderer = & $form->defaultRenderer();
  28. $renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
  29. $renderersetCustomElementTemplate->setCustomElementTemplate('<tr><td>{element}</td></tr>');
  30. $form->addElement('html', $option1);
  31. $form->addElement('checkbox', 'left', null, get_lang('Yes'));
  32. $form->addElement('button', 'submit', get_lang('Confirm'), array('class' => 'btn btn-primary'));
  33. $formHtml = $form->return_form();
  34. if ($form->validate()) {
  35. $result = $form->getSubmitValues();
  36. if (isset($result['left']) && $result['left']) {
  37. $_SESSION['before_login_accepted'] = 1;
  38. header('Location: '.$urlOption1);
  39. exit;
  40. }
  41. }
  42. $form2 = new FormValidator('form');
  43. if (!empty($option2) && !empty($urlOption2)) {
  44. $renderer = & $form2->defaultRenderer();
  45. $renderer->setHeaderTemplate('');
  46. $renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
  47. $renderer->setCustomElementTemplate('<tr><td>{element}</td></tr>');
  48. $form2->addElement('html', $option2);
  49. $form2->addElement('checkbox', 'right', null, get_lang('Yes'));
  50. $form2->addElement('button', 'submit', get_lang('Send'));
  51. $formHtml2 = $form2->return_form();
  52. if ($form2->validate()) {
  53. $result = $form2->getSubmitValues();
  54. if (isset($result['right']) && $result['right']) {
  55. header('Location: '.$urlOption2);
  56. exit;
  57. }
  58. }
  59. }
  60. $_template['form_option1'] = $formHtml;
  61. $_template['form_option2'] = $formHtml2;
  62. }