MDL-22764, added capability check on view.php, edit.php requires managefiles capabili...
[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');
94788de2 39require_once($CFG->dirroot.'/admin/registration/lib.php');
07ab0c80 40
41admin_externalpage_setup('registration');
42
43
44$huburl = optional_param('huburl', '', PARAM_URL);
4b1acb3a 45$password = optional_param('password', '', PARAM_TEXT);
07ab0c80 46$hubname = optional_param('hubname', '', PARAM_TEXT);
47if (empty($huburl) or !confirm_sesskey()) {
15ac57cb 48 throw new moodle_exception('missingparameter');
07ab0c80 49}
50
51/* TO DO
52if DB config plugin table is not good for dealing with token reference and token confirmation
53 => create other DB table
54-----------------------------------------------------------------------------
55Local Type | Token | Local WS | Remote Type | Remote URL | Confirmed
56-----------------------------------------------------------------------------
57 HUB 4er4e server HUB-DIRECTORY http...moodle.org Yes
58 HUB 73j53 client HUB-DIRECTORY http...moodle.org Yes
59 SITE dfsd7 server HUB http...hub Yes
60 SITE fd8fd client HUB http...hub Yes
61 HUB ds78s server SITE http...site.com Yes
62 HUB-DIR. d7d8s server HUB http...hub Yes
63-----------------------------------------------------------------------------
64*/
65
94788de2 66$registrationmanager = new registration_manager();
07ab0c80 67
94788de2 68$registeredhub = $registrationmanager->get_registeredhub($huburl);
07ab0c80 69
70$siteregistrationform = new site_registration_form('',
71 array('alreadyregistered' => !empty($registeredhub->token),
4b1acb3a 72 'huburl' => $huburl, 'hubname' => $hubname,
73 'password' => $password));
07ab0c80 74$fromform = $siteregistrationform->get_data();
75
76if (!empty($fromform) and confirm_sesskey()) {
77 //save the settings
78 $cleanhuburl = clean_param($huburl, PARAM_ALPHANUMEXT);
79 set_config('site_name_'.$cleanhuburl, $fromform->name, 'hub');
80 set_config('site_description_'.$cleanhuburl, $fromform->description, 'hub');
81 set_config('site_contactname_'.$cleanhuburl, $fromform->contactname, 'hub');
82 set_config('site_contactemail_'.$cleanhuburl, $fromform->contactemail, 'hub');
83 set_config('site_contactphone_'.$cleanhuburl, $fromform->contactphone, 'hub');
84 set_config('site_imageurl_'.$cleanhuburl, $fromform->imageurl, 'hub');
85 set_config('site_privacy_'.$cleanhuburl, $fromform->privacy, 'hub');
86 set_config('site_address_'.$cleanhuburl, $fromform->address, 'hub');
4032415e 87 set_config('site_region_'.$cleanhuburl, $fromform->regioncode, 'hub');
88 set_config('site_country_'.$cleanhuburl, $fromform->countrycode, 'hub');
07ab0c80 89 set_config('site_geolocation_'.$cleanhuburl, $fromform->geolocation, 'hub');
90 set_config('site_contactable_'.$cleanhuburl, $fromform->contactable, 'hub');
91 set_config('site_emailalert_'.$cleanhuburl, $fromform->emailalert, 'hub');
92 set_config('site_coursesnumber_'.$cleanhuburl, $fromform->courses, 'hub');
93 set_config('site_usersnumber_'.$cleanhuburl, $fromform->users, 'hub');
94 set_config('site_roleassignmentsnumber_'.$cleanhuburl, $fromform->roleassignments, 'hub');
95 set_config('site_postsnumber_'.$cleanhuburl, $fromform->posts, 'hub');
96 set_config('site_questionsnumber_'.$cleanhuburl, $fromform->questions, 'hub');
97 set_config('site_resourcesnumber_'.$cleanhuburl, $fromform->resources, 'hub');
98 set_config('site_modulenumberaverage_'.$cleanhuburl, $fromform->modulenumberaverage, 'hub');
99 set_config('site_participantnumberaverage_'.$cleanhuburl, $fromform->participantnumberaverage, 'hub');
100}
101
102/////// UNREGISTER ACTION //////
103// TODO
104
105
106/////// UPDATE ACTION ////////
107
108// update the hub registration
109$update = optional_param('update', 0, PARAM_INT);
110if ($update and confirm_sesskey()) {
111
112 //update the registration
113 $function = 'hub_update_site_info';
94788de2 114 $siteinfo = $registrationmanager->get_site_info($huburl);
07ab0c80 115 $params = array($siteinfo);
116 $serverurl = $huburl."/local/hub/webservice/webservices.php";
117 require_once($CFG->dirroot."/webservice/xmlrpc/lib.php");
118 $xmlrpcclient = new webservice_xmlrpc_client();
119 $result = $xmlrpcclient->call($serverurl, $registeredhub->token, $function, $params);
120
121}
122
123/////// FORM REGISTRATION ACTION //////
124
125if (!empty($fromform) and empty($update) and confirm_sesskey()) {
126
127 if (!empty($fromform) and confirm_sesskey()) { // if the register button has been clicked
128 $params = (array) $fromform; //we are using the form input as the redirection parameters (token, url and name)
129
94788de2 130 $unconfirmedhub = $registrationmanager->get_unconfirmedhub($huburl);
4b1acb3a 131 if (empty($unconfirmedhub)) {
07ab0c80 132 //we save the token into the communication table in order to have a reference
4b1acb3a 133 $unconfirmedhub = new stdClass();
134 $unconfirmedhub->token = md5(uniqid(rand(),1));
135 $unconfirmedhub->huburl = $huburl;
136 $unconfirmedhub->hubname = $hubname;
137 $unconfirmedhub->confirmed = 0;
94788de2 138 $unconfirmedhub->id = $registrationmanager->add_registeredhub($unconfirmedhub);
07ab0c80 139 }
140
4b1acb3a 141 $params['token'] = $unconfirmedhub->token;
07ab0c80 142 $params['url'] = $CFG->wwwroot;
06d4578c 143 redirect(new moodle_url(HUB_MOODLEORGHUBURL.'/local/hub/siteregistration.php', $params));
07ab0c80 144
145 }
146}
147
148/////// OUTPUT SECTION /////////////
149
150echo $OUTPUT->header();
151//Display update notification result
152if (!empty($registeredhub->confirmed)) {
153 if (!empty($result)) {
154 echo $OUTPUT->notification(get_string('siteregistrationupdated', 'hub'), 'notifysuccess');
155 }
156}
157$siteregistrationform->display();
158
159
160
15ac57cb 161echo $OUTPUT->footer();