PageRenderTime 62ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/registration/index.php

https://github.com/mspall/moodle
PHP | 128 lines | 76 code | 21 blank | 31 comment | 24 complexity | 844661d6981fb4efd5c623cd7c0f4759 MD5 | raw file
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * @package moodle
  18. * @subpackage registration
  19. * @author Jerome Mouneyrac <jerome@mouneyrac.com>
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL
  21. * @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
  22. *
  23. * This page displays the site registration form.
  24. * It handles redirection to the hub to continue the registration workflow process.
  25. * It also handles update operation by web service.
  26. */
  27. require_once('../../config.php');
  28. require_once($CFG->libdir . '/adminlib.php');
  29. admin_externalpage_setup('registrationmoodleorg');
  30. $unregistration = optional_param('unregistration', false, PARAM_BOOL);
  31. $confirm = optional_param('confirm', false, PARAM_BOOL);
  32. if ($unregistration && \core\hub\registration::is_registered()) {
  33. if ($confirm) {
  34. require_sesskey();
  35. \core\hub\registration::unregister(false, false);
  36. if (!\core\hub\registration::is_registered()) {
  37. redirect(new moodle_url('/admin/registration/index.php'));
  38. }
  39. }
  40. echo $OUTPUT->header();
  41. echo $OUTPUT->confirm(
  42. get_string('registerwithmoodleorgremove', 'core_hub'),
  43. new moodle_url(new moodle_url('/admin/registration/index.php', ['unregistration' => 1, 'confirm' => 1])),
  44. new moodle_url(new moodle_url('/admin/registration/index.php'))
  45. );
  46. echo $OUTPUT->footer();
  47. exit;
  48. }
  49. $isinitialregistration = \core\hub\registration::show_after_install(true);
  50. if (!$returnurl = optional_param('returnurl', null, PARAM_LOCALURL)) {
  51. $returnurl = $isinitialregistration ? '/admin/index.php' : '/admin/registration/index.php';
  52. }
  53. $siteregistrationform = new \core\hub\site_registration_form();
  54. $siteregistrationform->set_data(['returnurl' => $returnurl]);
  55. if ($fromform = $siteregistrationform->get_data()) {
  56. // Save the settings.
  57. \core\hub\registration::save_site_info($fromform);
  58. if (\core\hub\registration::is_registered()) {
  59. if (\core\hub\registration::update_manual()) {
  60. redirect(new moodle_url($returnurl));
  61. }
  62. redirect(new moodle_url('/admin/registration/index.php', ['returnurl' => $returnurl]));
  63. } else {
  64. \core\hub\registration::register($returnurl);
  65. // This method will redirect away.
  66. }
  67. }
  68. // OUTPUT SECTION.
  69. echo $OUTPUT->header();
  70. // Current status of registration.
  71. $notificationtype = \core\output\notification::NOTIFY_ERROR;
  72. if (\core\hub\registration::is_registered()) {
  73. $lastupdated = \core\hub\registration::get_last_updated();
  74. if ($lastupdated == 0) {
  75. $registrationmessage = get_string('pleaserefreshregistrationunknown', 'admin');
  76. } else if (\core\hub\registration::get_new_registration_fields()) {
  77. $registrationmessage = get_string('pleaserefreshregistrationnewdata', 'admin');
  78. } else {
  79. $lastupdated = userdate($lastupdated, get_string('strftimedate', 'langconfig'));
  80. $registrationmessage = get_string('pleaserefreshregistration', 'admin', $lastupdated);
  81. $notificationtype = \core\output\notification::NOTIFY_INFO;
  82. }
  83. echo $OUTPUT->notification($registrationmessage, $notificationtype);
  84. } else if (!$isinitialregistration) {
  85. $registrationmessage = get_string('registrationwarning', 'admin');
  86. echo $OUTPUT->notification($registrationmessage, $notificationtype);
  87. }
  88. // Heading.
  89. if (\core\hub\registration::is_registered()) {
  90. echo $OUTPUT->heading(get_string('registerwithmoodleorgupdate', 'core_hub'));
  91. } else if ($isinitialregistration) {
  92. echo $OUTPUT->heading(get_string('registerwithmoodleorgcomplete', 'core_hub'));
  93. } else {
  94. echo $OUTPUT->heading(get_string('registerwithmoodleorg', 'core_hub'));
  95. }
  96. $renderer = $PAGE->get_renderer('core', 'admin');
  97. echo $renderer->moodleorg_registration_message();
  98. $siteregistrationform->display();
  99. if (\core\hub\registration::is_registered()) {
  100. // Unregister link.
  101. $unregisterhuburl = new moodle_url("/admin/registration/index.php", ['unregistration' => 1]);
  102. echo html_writer::div(html_writer::link($unregisterhuburl, get_string('unregister', 'hub')), 'unregister mt-2');
  103. } else if ($isinitialregistration) {
  104. echo html_writer::div(html_writer::link(new moodle_url($returnurl), get_string('skipregistration', 'hub')),
  105. 'skipregistration mt-2');
  106. }
  107. echo $OUTPUT->footer();