"MDL-22335, make mainfile element as required"
[moodle.git] / admin / registration / register.php
CommitLineData
07ab0c80 1<?php
2///////////////////////////////////////////////////////////////////////////
3// //
4// This file is part of Moodle - http://moodle.org/ //
5// Moodle - Modular Object-Oriented Dynamic Learning Environment //
6// //
7// Moodle is free software: you can redistribute it and/or modify //
8// it under the terms of the GNU General Public License as published by //
9// the Free Software Foundation, either version 3 of the License, or //
10// (at your option) any later version. //
11// //
12// Moodle is distributed in the hope that it will be useful, //
13// but WITHOUT ANY WARRANTY; without even the implied warranty of //
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
15// GNU General Public License for more details. //
16// //
17// You should have received a copy of the GNU General Public License //
18// along with Moodle. If not, see <http://www.gnu.org/licenses/>. //
19// //
20///////////////////////////////////////////////////////////////////////////
21
22/*
23 * @package moodle
24 * @subpackage registration
25 * @author Jerome Mouneyrac <jerome@mouneyrac.com>
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL
27 * @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
28 *
29 * This page displays the site registration form.
30 * It handles redirection to the hub to continue the registration workflow process.
31 * It also handles update operation by web service.
32*/
33
34
35require_once('../../config.php');
36require_once($CFG->libdir.'/adminlib.php');
37require_once($CFG->dirroot.'/admin/registration/forms.php');
38require_once($CFG->dirroot.'/webservice/lib.php');
39require_once($CFG->dirroot.'/lib/hublib.php');
40
41admin_externalpage_setup('registration');
42
43
44$huburl = optional_param('huburl', '', PARAM_URL);
45$hubname = optional_param('hubname', '', PARAM_TEXT);
46if (empty($huburl) or !confirm_sesskey()) {
47 throw new moodle_exception('cannotaccessthispage');
48}
49
50/* TO DO
51if DB config plugin table is not good for dealing with token reference and token confirmation
52 => create other DB table
53-----------------------------------------------------------------------------
54Local Type | Token | Local WS | Remote Type | Remote URL | Confirmed
55-----------------------------------------------------------------------------
56 HUB 4er4e server HUB-DIRECTORY http...moodle.org Yes
57 HUB 73j53 client HUB-DIRECTORY http...moodle.org Yes
58 SITE dfsd7 server HUB http...hub Yes
59 SITE fd8fd client HUB http...hub Yes
60 HUB ds78s server SITE http...site.com Yes
61 HUB-DIR. d7d8s server HUB http...hub Yes
62-----------------------------------------------------------------------------
63*/
64
65$hub = new hub();
66
67$registeredhub = $hub->get_registeredhub($huburl);
68
69$siteregistrationform = new site_registration_form('',
70 array('alreadyregistered' => !empty($registeredhub->token),
71 'huburl' => $huburl, 'hubname' => $hubname));
72$fromform = $siteregistrationform->get_data();
73
74if (!empty($fromform) and confirm_sesskey()) {
75 //save the settings
76 $cleanhuburl = clean_param($huburl, PARAM_ALPHANUMEXT);
77 set_config('site_name_'.$cleanhuburl, $fromform->name, 'hub');
78 set_config('site_description_'.$cleanhuburl, $fromform->description, 'hub');
79 set_config('site_contactname_'.$cleanhuburl, $fromform->contactname, 'hub');
80 set_config('site_contactemail_'.$cleanhuburl, $fromform->contactemail, 'hub');
81 set_config('site_contactphone_'.$cleanhuburl, $fromform->contactphone, 'hub');
82 set_config('site_imageurl_'.$cleanhuburl, $fromform->imageurl, 'hub');
83 set_config('site_privacy_'.$cleanhuburl, $fromform->privacy, 'hub');
84 set_config('site_address_'.$cleanhuburl, $fromform->address, 'hub');
4032415e 85 set_config('site_region_'.$cleanhuburl, $fromform->regioncode, 'hub');
86 set_config('site_country_'.$cleanhuburl, $fromform->countrycode, 'hub');
07ab0c80 87 set_config('site_geolocation_'.$cleanhuburl, $fromform->geolocation, 'hub');
88 set_config('site_contactable_'.$cleanhuburl, $fromform->contactable, 'hub');
89 set_config('site_emailalert_'.$cleanhuburl, $fromform->emailalert, 'hub');
90 set_config('site_coursesnumber_'.$cleanhuburl, $fromform->courses, 'hub');
91 set_config('site_usersnumber_'.$cleanhuburl, $fromform->users, 'hub');
92 set_config('site_roleassignmentsnumber_'.$cleanhuburl, $fromform->roleassignments, 'hub');
93 set_config('site_postsnumber_'.$cleanhuburl, $fromform->posts, 'hub');
94 set_config('site_questionsnumber_'.$cleanhuburl, $fromform->questions, 'hub');
95 set_config('site_resourcesnumber_'.$cleanhuburl, $fromform->resources, 'hub');
96 set_config('site_modulenumberaverage_'.$cleanhuburl, $fromform->modulenumberaverage, 'hub');
97 set_config('site_participantnumberaverage_'.$cleanhuburl, $fromform->participantnumberaverage, 'hub');
98}
99
100/////// UNREGISTER ACTION //////
101// TODO
102
103
104/////// UPDATE ACTION ////////
105
106// update the hub registration
107$update = optional_param('update', 0, PARAM_INT);
108if ($update and confirm_sesskey()) {
109
110 //update the registration
111 $function = 'hub_update_site_info';
112 $siteinfo = $hub->get_site_info($huburl);
113 $params = array($siteinfo);
114 $serverurl = $huburl."/local/hub/webservice/webservices.php";
115 require_once($CFG->dirroot."/webservice/xmlrpc/lib.php");
116 $xmlrpcclient = new webservice_xmlrpc_client();
117 $result = $xmlrpcclient->call($serverurl, $registeredhub->token, $function, $params);
118
119}
120
121/////// FORM REGISTRATION ACTION //////
122
123if (!empty($fromform) and empty($update) and confirm_sesskey()) {
124
125 if (!empty($fromform) and confirm_sesskey()) { // if the register button has been clicked
126 $params = (array) $fromform; //we are using the form input as the redirection parameters (token, url and name)
127
128 if (empty($registeredhub)) {
129 //we save the token into the communication table in order to have a reference
130 $registeredhub = new stdClass();
131 $registeredhub->token = md5(uniqid(rand(),1));
132 $registeredhub->huburl = $huburl;
133 $registeredhub->hubname = $hubname;
134 $registeredhub->confirmed = 0;
135 $registeredhub->id = $hub->add_registeredhub($registeredhub);
136 }
137
138 $params['token'] = $registeredhub->token;
139 $params['url'] = $CFG->wwwroot;
140 redirect(new moodle_url(MOODLEORGHUBURL.'/local/hub/siteregistration.php', $params));
141
142 }
143}
144
145/////// OUTPUT SECTION /////////////
146
147echo $OUTPUT->header();
148//Display update notification result
149if (!empty($registeredhub->confirmed)) {
150 if (!empty($result)) {
151 echo $OUTPUT->notification(get_string('siteregistrationupdated', 'hub'), 'notifysuccess');
152 }
153}
154$siteregistrationform->display();
155
156
157
158echo $OUTPUT->footer();