PageRenderTime 26ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/registration/index.php

https://github.com/adamann2/moodle
PHP | 125 lines | 73 code | 21 blank | 31 comment | 26 complexity | c2aa69e036a479f755491d442d58cb03 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 for Moodle.net.
  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', 0, PARAM_INT);
  31. if ($unregistration && \core\hub\registration::is_registered()) {
  32. $siteunregistrationform = new \core\hub\site_unregistration_form();
  33. if ($siteunregistrationform->is_cancelled()) {
  34. redirect(new moodle_url('/admin/registration/index.php'));
  35. } else if ($data = $siteunregistrationform->get_data()) {
  36. if (\core\hub\registration::unregister($data->unpublishalladvertisedcourses,
  37. $data->unpublishalluploadedcourses)) {
  38. redirect(new moodle_url('/admin/registration/index.php'));
  39. }
  40. }
  41. echo $OUTPUT->header();
  42. echo $OUTPUT->heading(get_string('unregisterfrom', 'hub', 'Moodle.net'), 3, 'main');
  43. $siteunregistrationform->display();
  44. echo $OUTPUT->footer();
  45. exit;
  46. }
  47. $isinitialregistration = \core\hub\registration::show_after_install(true);
  48. if (!$returnurl = optional_param('returnurl', null, PARAM_LOCALURL)) {
  49. $returnurl = $isinitialregistration ? '/admin/index.php' : '/admin/registration/index.php';
  50. }
  51. $siteregistrationform = new \core\hub\site_registration_form();
  52. $siteregistrationform->set_data(['returnurl' => $returnurl]);
  53. if ($fromform = $siteregistrationform->get_data()) {
  54. // Save the settings.
  55. \core\hub\registration::save_site_info($fromform);
  56. if (\core\hub\registration::is_registered()) {
  57. if (\core\hub\registration::update_manual()) {
  58. redirect(new moodle_url($returnurl));
  59. }
  60. redirect(new moodle_url('/admin/registration/index.php', ['returnurl' => $returnurl]));
  61. } else {
  62. \core\hub\registration::register($returnurl);
  63. // This method will redirect away.
  64. }
  65. }
  66. // OUTPUT SECTION.
  67. echo $OUTPUT->header();
  68. // Current status of registration on Moodle.net.
  69. $notificationtype = \core\output\notification::NOTIFY_ERROR;
  70. if (\core\hub\registration::is_registered()) {
  71. $lastupdated = \core\hub\registration::get_last_updated();
  72. if ($lastupdated == 0) {
  73. $registrationmessage = get_string('pleaserefreshregistrationunknown', 'admin');
  74. } else if (\core\hub\registration::get_new_registration_fields()) {
  75. $registrationmessage = get_string('pleaserefreshregistrationnewdata', 'admin');
  76. } else {
  77. $lastupdated = userdate($lastupdated, get_string('strftimedate', 'langconfig'));
  78. $registrationmessage = get_string('pleaserefreshregistration', 'admin', $lastupdated);
  79. $notificationtype = \core\output\notification::NOTIFY_INFO;
  80. }
  81. echo $OUTPUT->notification($registrationmessage, $notificationtype);
  82. } else if (!$isinitialregistration) {
  83. $registrationmessage = get_string('registrationwarning', 'admin');
  84. echo $OUTPUT->notification($registrationmessage, $notificationtype);
  85. }
  86. // Heading.
  87. if (\core\hub\registration::is_registered()) {
  88. echo $OUTPUT->heading(get_string('updatesite', 'hub', 'Moodle.net'));
  89. } else if ($isinitialregistration) {
  90. echo $OUTPUT->heading(get_string('completeregistration', 'hub'));
  91. } else {
  92. echo $OUTPUT->heading(get_string('registerwithmoodleorg', 'admin'));
  93. }
  94. $renderer = $PAGE->get_renderer('core', 'register');
  95. echo $renderer->moodleorg_registration_message();
  96. $siteregistrationform->display();
  97. if (\core\hub\registration::is_registered()) {
  98. // Unregister link.
  99. $unregisterhuburl = new moodle_url("/admin/registration/index.php", ['unregistration' => 1]);
  100. echo html_writer::div(html_writer::link($unregisterhuburl, get_string('unregister', 'hub')), 'unregister');
  101. } else if ($isinitialregistration) {
  102. echo html_writer::div(html_writer::link(new moodle_url($returnurl), get_string('skipregistration', 'hub')), 'skipregistration');
  103. }
  104. echo $OUTPUT->footer();