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