hub MDL-19309 new site registration form + course publication + community block

This commit is contained in:
jerome mouneyrac 2010-05-01 05:05:55 +00:00
parent 7b4c6d34b8
commit 07ab0c80ec
36 changed files with 3208 additions and 21 deletions

View file

@ -0,0 +1,64 @@
<?php
///////////////////////////////////////////////////////////////////////////
// //
// This file is part of Moodle - http://moodle.org/ //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// //
// Moodle is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// Moodle is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. //
// //
///////////////////////////////////////////////////////////////////////////
/*
* @package moodle
* @subpackage registration
* @author Jerome Mouneyrac <jerome@mouneyrac.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
*
* The administrator is redirect to this page from the hub to confirm that the
* site has been registered. It is an administration page. The administrator
* should be using the same browser during all the registration process.
* This page save the token that the hub gave us, in order to call the hub
* directory later by web service.
*/
require('../../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->dirroot.'/lib/hublib.php');
admin_externalpage_setup('siteregistrationconfirmed');
$newtoken = optional_param('newtoken', '', PARAM_ALPHANUM);
$url = optional_param('url', '', PARAM_URL);
$token = optional_param('token', '', PARAM_ALPHANUM);
$hub = new hub();
//check that the token/url couple exist and is not confirmed
$registeredhub = $hub->get_registeredhub($url);
if (!empty($registeredhub) and $registeredhub->confirmed == 0
and $registeredhub->token == $token) {
$registeredhub->token = $newtoken;
$registeredhub->confirmed = 1;
$hub->update_registeredhub($registeredhub);
echo $OUTPUT->header();
echo $OUTPUT->notification(get_string('registrationconfirmed', 'hub'), 'notifysuccess');
echo $OUTPUT->footer();
} else {
throw new moodle_exception('wrongtoken');
}

View file

@ -0,0 +1,360 @@
<?php
///////////////////////////////////////////////////////////////////////////
// //
// This file is part of Moodle - http://moodle.org/ //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// //
// Moodle is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// Moodle is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. //
// //
///////////////////////////////////////////////////////////////////////////
/*
* @package moodle
* @subpackage registration
* @author Jerome Mouneyrac <jerome@mouneyrac.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
*
* The forms needed by registration pages.
*/
require_once($CFG->dirroot.'/lib/formslib.php');
require_once($CFG->dirroot.'/lib/hublib.php');
/**
* This form display a hub selector.
* The hub list is retrieved from Moodle.org hub directory.
* Also displayed, a text field to enter private hub url + its password
*/
class hub_selector_form extends moodleform {
public function definition() {
global $CFG;
$mform =& $this->_form;
$mform->addElement('header', 'site', get_string('selecthub', 'hub'));
//retrieve the hub list on the hub directory by web service
$function = 'hubdirectory_get_hubs';
$params = array();
$serverurl = HUBDIRECTORYURL."/local/hubdirectory/webservice/webservices.php";
require_once($CFG->dirroot."/webservice/xmlrpc/lib.php");
$xmlrpcclient = new webservice_xmlrpc_client();
$hubs = $xmlrpcclient->call($serverurl, 'publichubdirectory', $function, $params);
//Public hub list
$options = array();
foreach ($hubs as $hub) {
//to not display a name longer than 100 character (too big)
if (strlen($hub['name'])>100) {
$hubname = substr($hub['name'],0, 100);
$hubname = $hubname."...";
} else {
$hubname = $hub['name'];
}
$options[$hub['url']] = $hubname;
$mform->addElement('hidden', clean_param($hub['url'], PARAM_ALPHANUMEXT), $hubname);
}
$mform->addElement('select', 'publichub', get_string('publichub','hub'),
$options, array("size" => 15));
$mform->addElement('static','or' , '', get_string('orenterprivatehub', 'hub'));
//Private hub
$mform->addElement('text','unlistedurl' , get_string('privatehuburl', 'hub'));
$mform->addElement('text','password' , get_string('password'));
$this->add_action_buttons(false, get_string('selecthub', 'hub'));
}
/**
* Check the unlisted URL is a URL
*/
function validation($data, $files) {
global $CFG;
$errors = parent::validation($data, $files);
$unlistedurl = $this->_form->_submitValues['unlistedurl'];
if (!empty($unlistedurl)) {
$unlistedurltotest = clean_param($unlistedurl, PARAM_URL);
if (empty($unlistedurltotest)) {
$errors['unlistedurl'] = get_string('badurlformat', 'hub');
}
}
return $errors;
}
}
/**
* The site registration form. Information will be sent to a given hub.
*/
class site_registration_form extends moodleform {
public function definition() {
global $CFG, $DB;
$strrequired = get_string('required');
$mform =& $this->_form;
$huburl = $this->_customdata['huburl'];
$hubname = $this->_customdata['hubname'];
$admin = get_admin();
$site = get_site();
//retrieve config for this hub and set default if they don't exist
$cleanhuburl = clean_param($huburl, PARAM_ALPHANUMEXT);
$sitename = get_config('hub', 'site_name_'.$cleanhuburl);
if ($sitename === false) {
$sitename = $site->fullname;
}
$sitedescription = get_config('hub', 'site_description_'.$cleanhuburl);
if ($sitedescription === false) {
$sitedescription = $site->summary;
}
$contactname = get_config('hub', 'site_contactname_'.$cleanhuburl);
if ($contactname === false) {
$contactname = fullname($admin, true);
}
$contactemail = get_config('hub', 'site_contactemail_'.$cleanhuburl);
if ($contactemail === false) {
$contactemail = $admin->email;
}
$contactphone = get_config('hub', 'site_contactphone_'.$cleanhuburl);
if ($contactphone === false) {
$contactphone = $admin->phone1;
}
$imageurl = get_config('hub', 'site_imageurl_'.$cleanhuburl);
$privacy = get_config('hub', 'site_privacy_'.$cleanhuburl);
$address = get_config('hub', 'site_address_'.$cleanhuburl);
$region = get_config('hub', 'site_region_'.$cleanhuburl);
$country = get_config('hub', 'site_country_'.$cleanhuburl);
if ($country === false) {
$country = $admin->country;
}
$geolocation = get_config('hub', 'site_geolocation_'.$cleanhuburl);
$contactable = get_config('hub', 'site_contactable_'.$cleanhuburl);
$emailalert = get_config('hub', 'site_emailalert_'.$cleanhuburl);
$coursesnumber = get_config('hub', 'site_coursesnumber_'.$cleanhuburl);
$usersnumber = get_config('hub', 'site_usersnumber_'.$cleanhuburl);
$roleassignmentsnumber = get_config('hub', 'site_roleassignmentsnumber_'.$cleanhuburl);
$postsnumber = get_config('hub', 'site_postsnumber_'.$cleanhuburl);
$questionsnumber = get_config('hub', 'site_questionsnumber_'.$cleanhuburl);
$resourcesnumber = get_config('hub', 'site_resourcesnumber_'.$cleanhuburl);
$mediancoursesize = get_config('hub', 'site_mediancoursesize_'.$cleanhuburl);
//hidden parameters
$mform->addElement('hidden', 'huburl', $huburl);
$mform->addElement('hidden', 'hubname', $hubname);
//the input parameters
$mform->addElement('header', 'moodle', get_string('registrationinfo', 'hub'));
$mform->addElement('text','name' , get_string('fullsitename'));
$mform->addRule('name', $strrequired, 'required', null, 'client');
$mform->setType('name', PARAM_TEXT);
$mform->setDefault('name', $sitename);
$options = array();
$hub = new hub();
$options[SITENOTPUBLISHED] = $hub->get_site_privacy_string(SITENOTPUBLISHED);
$options[SITENAMEPUBLISHED] = $hub->get_site_privacy_string(SITENAMEPUBLISHED);
$options[SITELINKPUBLISHED] = $hub->get_site_privacy_string(SITELINKPUBLISHED);
$mform->addElement('select', 'privacy', get_string('siteprivacy', 'hub'), $options);
$mform->setDefault('privacy', $privacy);
unset($options);
$mform->addElement('textarea', 'description', get_string('description'), array('rows'=>10));
$mform->addRule('description', $strrequired, 'required', null, 'client');
$mform->setDefault('description', $sitedescription);
$mform->setType('description', PARAM_TEXT);
$mform->addElement('static', 'urlstring',get_string('siteurl', 'hub'), $CFG->wwwroot);
$languages = get_string_manager()->get_list_of_languages();
$mform->addElement('static', 'langstring',get_string('language'), $languages[current_language()]);
$mform->addElement('hidden', 'language', current_language());
$mform->addElement('static', 'versionstring',get_string('moodleversion'), $CFG->version);
$mform->addElement('hidden', 'moodleversion', $CFG->version);
$mform->addElement('static', 'releasestring',get_string('moodlerelease'), $CFG->release);
$mform->addElement('hidden', 'moodlerelease', $CFG->release);
$mform->addElement('textarea','address' , get_string('postaladdress', 'hub'));
$mform->setType('address', PARAM_TEXT);
$mform->setDefault('address', $address);
//TODO: use the region array I generated
$mform->addElement('select', 'region', get_string('selectaregion'), array('-' => '-'));
$mform->setDefault('region', $region);
$countries = get_string_manager()->get_list_of_countries();
$mform->addElement('select', 'country', get_string('selectacountry'), $countries);
$mform->setDefault('country', $country);
$mform->addElement('text','geolocation' , get_string('geolocation'));
$mform->setDefault('geolocation', $geolocation);
$mform->addElement('text', 'contactname', get_string('administrator'));
$mform->addRule('contactname', $strrequired, 'required', null, 'client');
$mform->setType('contactname', PARAM_TEXT);
$mform->setDefault('contactname', $contactname);
$mform->addElement('text','contactphone' , get_string('phone'));
$mform->setType('contactphone', PARAM_TEXT);
$mform->addElement('text', 'contactemail', get_string('email'));
$mform->addRule('contactemail', $strrequired, 'required', null, 'client');
$mform->setType('contactemail', PARAM_TEXT);
$mform->setDefault('contactemail', $contactemail);
$options = array();
$options[0] = get_string("registrationcontactno");
$options[1] = get_string("registrationcontactyes");
$mform->addElement('select', 'contactable', get_string('registrationcontact'), $options);
$mform->setDefault('contactable', $contactable);
unset($options);
$options = array();
$options[0] = get_string("registrationno");
$options[1] = get_string("registrationyes");
$mform->addElement('select', 'emailalert', get_string('registrationemail'), $options);
$mform->setDefault('emailalert', $emailalert);
unset($options);
$mform->addElement('text','imageurl' , get_string('logourl', 'hub'));
$mform->setType('imageurl', PARAM_URL);
$mform->setDefault('imageurl', $imageurl);
/// Display statistic that are going to be retrieve by the hub
$coursecount = $DB->count_records('course')-1;
$usercount = $DB->count_records('user', array('deleted'=>0));
$roleassigncount = $DB->count_records('role_assignments');
$postcount = $DB->count_records('forum_posts');
$questioncount = $DB->count_records('question');
$resourcecount = $DB->count_records('resource');
require_once($CFG->dirroot."/course/lib.php");
$participantnumberaverage= average_number_of_participants();
$modulenumberaverage= average_number_of_courses_modules();
if (MOODLEORGHUBURL != $huburl) {
$mform->addElement('checkbox', 'courses', get_string('sendfollowinginfo', 'hub'),
" ".get_string('coursesnumber', 'hub', $coursecount));
$mform->setDefault('courses', true);
$mform->addElement('checkbox', 'users', '',
" ".get_string('usersnumber', 'hub', $usercount));
$mform->setDefault('users', true);
$mform->addElement('checkbox', 'roleassignments', '',
" ".get_string('roleassignmentsnumber', 'hub', $roleassigncount));
$mform->setDefault('roleassignments', true);
$mform->addElement('checkbox', 'posts', '',
" ".get_string('postsnumber', 'hub', $postcount));
$mform->setDefault('posts', true);
$mform->addElement('checkbox', 'questions', '',
" ".get_string('questionsnumber', 'hub', $questioncount));
$mform->setDefault('questions', true);
$mform->addElement('checkbox', 'resources', '',
" ".get_string('resourcesnumber', 'hub', $resourcecount));
$mform->setDefault('resources', true);
$mform->addElement('checkbox', 'participantnumberaverage', '',
" ".get_string('participantnumberaverage', 'hub', $participantnumberaverage));
$mform->setDefault('participantnumberaverage', true);
$mform->addElement('checkbox', 'modulenumberaverage', '',
" ".get_string('modulenumberaverage', 'hub', $modulenumberaverage));
$mform->setDefault('modulenumberaverage', true);
} else {
$mform->addElement('static', 'courseslabel',get_string('sendfollowinginfo', 'hub'),
" ".get_string('coursesnumber', 'hub', $coursecount));
$mform->addElement('hidden', 'courses', true);
$mform->addElement('static', 'userslabel', '',
" ".get_string('usersnumber', 'hub', $usercount));
$mform->addElement('hidden', 'users', true);
$mform->addElement('static', 'roleassignmentslabel', '',
" ".get_string('roleassignmentsnumber', 'hub', $roleassigncount));
$mform->addElement('hidden', 'roleassignments', true);
$mform->addElement('static', 'postslabel', '',
" ".get_string('postsnumber', 'hub', $postcount));
$mform->addElement('hidden', 'posts', true);
$mform->addElement('static', 'questionslabel', '',
" ".get_string('questionsnumber', 'hub', $questioncount));
$mform->addElement('hidden', 'questions', true);
$mform->addElement('static', 'resourceslabel', '',
" ".get_string('resourcesnumber', 'hub', $resourcecount));
$mform->addElement('hidden', 'resources', true);
$mform->addElement('static', 'participantnumberaveragelabel', '',
" ".get_string('participantnumberaverage', 'hub', $participantnumberaverage));
$mform->addElement('hidden', 'participantnumberaverage', true);
$mform->addElement('static', 'modulenumberaveragelabel', '',
" ".get_string('modulenumberaverage', 'hub', $modulenumberaverage));
$mform->addElement('hidden', 'modulenumberaverage', true);
}
//check if it's a first registration or update
$hubregistered = $hub->get_registeredhub($huburl);
if (!empty($hubregistered)) {
$buttonlabel = get_string('updatesite', 'hub',
!empty($hubname)?$hubname:$huburl);
$mform->addElement('hidden', 'update', true);
} else {
$buttonlabel = get_string('registersite', 'hub',
!empty($hubname)?$hubname:$huburl);
}
$this->add_action_buttons(false, $buttonlabel);
}
/**
* Check that the image size is correct
*/
function validation($data, $files) {
global $CFG;
$errors = array();
//check if the image (imageurl) has a correct size
$imageurl = $this->_form->_submitValues['imageurl'];
if (!empty($imageurl)) {
list($imagewidth, $imageheight, $imagetype, $imageattr) = getimagesize($imageurl); //getimagesize is a GD function
if ($imagewidth > SITEIMAGEWIDTH or $imageheight > SITEIMAGEHEIGHT) {
$sizestrings = new stdClass();
$sizestrings->width = SITEIMAGEWIDTH;
$sizestrings->height = SITEIMAGEHEIGHT;
$errors['imageurl'] = get_string('errorbadimageheightwidth', 'hub', $sizestrings);
}
}
return $errors;
}
}
?>

View file

@ -0,0 +1,68 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/*
* @package moodle
* @subpackage registration
* @author Jerome Mouneyrac <jerome@mouneyrac.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
*
* Thsi page displays a hub selector or a hub URL + password. Then it will redirect to
* the site registration form (with the selected hub as parameter)
*/
require('../../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->dirroot.'/admin/registration/forms.php');
admin_externalpage_setup('registrationselector');
$hubselectorform = new hub_selector_form();
$fromform = $hubselectorform->get_data();
//// Redirect to the registration form if an URL has been choosen ////
$selectedhuburl = optional_param('publichub', false, PARAM_URL);
$unlistedhuburl = optional_param('unlistedurl', false, PARAM_TEXT);
$password = optional_param('password', '', PARAM_RAW);
if (!empty($unlistedhuburl)) {
if (clean_param($unlistedhuburl, PARAM_URL) !== '') {
$huburl = $unlistedhuburl;
}
} else if (!empty($selectedhuburl)) {
$huburl = $selectedhuburl;
}
//redirect
if (!empty($huburl) and confirm_sesskey()) {
$hubname = optional_param(clean_param($huburl, PARAM_ALPHANUMEXT), '', PARAM_TEXT);
$params = array('sesskey' => sesskey(), 'huburl' => $huburl,
'password' => $password, 'hubname' => $hubname);
redirect(new moodle_url($CFG->wwwroot."/admin/registration/register.php",
$params));
}
//// OUTPUT ////
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('registeron', 'hub'), 3, 'main');
$hubselectorform->display();
echo $OUTPUT->footer();

View file

@ -0,0 +1,40 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/*
* @package moodle
* @subpackage registration
* @author Jerome Mouneyrac <jerome@mouneyrac.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
*
* On this page the administrator select if he wants to register on Moodle.org or
* a specific hub
*/
require('../../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/hublib.php');
admin_externalpage_setup('registrationindex');
$renderer = $PAGE->get_renderer('core', 'register');
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('registeron', 'hub'), 3, 'main');
echo $renderer->registrationselector();
echo $OUTPUT->footer();

View file

@ -0,0 +1,158 @@
<?php
///////////////////////////////////////////////////////////////////////////
// //
// This file is part of Moodle - http://moodle.org/ //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// //
// Moodle is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// Moodle is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. //
// //
///////////////////////////////////////////////////////////////////////////
/*
* @package moodle
* @subpackage registration
* @author Jerome Mouneyrac <jerome@mouneyrac.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
*
* This page displays the site registration form.
* It handles redirection to the hub to continue the registration workflow process.
* It also handles update operation by web service.
*/
require_once('../../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->dirroot.'/admin/registration/forms.php');
require_once($CFG->dirroot.'/webservice/lib.php');
require_once($CFG->dirroot.'/lib/hublib.php');
admin_externalpage_setup('registration');
$huburl = optional_param('huburl', '', PARAM_URL);
$hubname = optional_param('hubname', '', PARAM_TEXT);
if (empty($huburl) or !confirm_sesskey()) {
throw new moodle_exception('cannotaccessthispage');
}
/* TO DO
if DB config plugin table is not good for dealing with token reference and token confirmation
=> create other DB table
-----------------------------------------------------------------------------
Local Type | Token | Local WS | Remote Type | Remote URL | Confirmed
-----------------------------------------------------------------------------
HUB 4er4e server HUB-DIRECTORY http...moodle.org Yes
HUB 73j53 client HUB-DIRECTORY http...moodle.org Yes
SITE dfsd7 server HUB http...hub Yes
SITE fd8fd client HUB http...hub Yes
HUB ds78s server SITE http...site.com Yes
HUB-DIR. d7d8s server HUB http...hub Yes
-----------------------------------------------------------------------------
*/
$hub = new hub();
$registeredhub = $hub->get_registeredhub($huburl);
$siteregistrationform = new site_registration_form('',
array('alreadyregistered' => !empty($registeredhub->token),
'huburl' => $huburl, 'hubname' => $hubname));
$fromform = $siteregistrationform->get_data();
if (!empty($fromform) and confirm_sesskey()) {
//save the settings
$cleanhuburl = clean_param($huburl, PARAM_ALPHANUMEXT);
set_config('site_name_'.$cleanhuburl, $fromform->name, 'hub');
set_config('site_description_'.$cleanhuburl, $fromform->description, 'hub');
set_config('site_contactname_'.$cleanhuburl, $fromform->contactname, 'hub');
set_config('site_contactemail_'.$cleanhuburl, $fromform->contactemail, 'hub');
set_config('site_contactphone_'.$cleanhuburl, $fromform->contactphone, 'hub');
set_config('site_imageurl_'.$cleanhuburl, $fromform->imageurl, 'hub');
set_config('site_privacy_'.$cleanhuburl, $fromform->privacy, 'hub');
set_config('site_address_'.$cleanhuburl, $fromform->address, 'hub');
set_config('site_region_'.$cleanhuburl, $fromform->region, 'hub');
set_config('site_country_'.$cleanhuburl, $fromform->country, 'hub');
set_config('site_geolocation_'.$cleanhuburl, $fromform->geolocation, 'hub');
set_config('site_contactable_'.$cleanhuburl, $fromform->contactable, 'hub');
set_config('site_emailalert_'.$cleanhuburl, $fromform->emailalert, 'hub');
set_config('site_coursesnumber_'.$cleanhuburl, $fromform->courses, 'hub');
set_config('site_usersnumber_'.$cleanhuburl, $fromform->users, 'hub');
set_config('site_roleassignmentsnumber_'.$cleanhuburl, $fromform->roleassignments, 'hub');
set_config('site_postsnumber_'.$cleanhuburl, $fromform->posts, 'hub');
set_config('site_questionsnumber_'.$cleanhuburl, $fromform->questions, 'hub');
set_config('site_resourcesnumber_'.$cleanhuburl, $fromform->resources, 'hub');
set_config('site_modulenumberaverage_'.$cleanhuburl, $fromform->modulenumberaverage, 'hub');
set_config('site_participantnumberaverage_'.$cleanhuburl, $fromform->participantnumberaverage, 'hub');
}
/////// UNREGISTER ACTION //////
// TODO
/////// UPDATE ACTION ////////
// update the hub registration
$update = optional_param('update', 0, PARAM_INT);
if ($update and confirm_sesskey()) {
//update the registration
$function = 'hub_update_site_info';
$siteinfo = $hub->get_site_info($huburl);
$params = array($siteinfo);
$serverurl = $huburl."/local/hub/webservice/webservices.php";
require_once($CFG->dirroot."/webservice/xmlrpc/lib.php");
$xmlrpcclient = new webservice_xmlrpc_client();
$result = $xmlrpcclient->call($serverurl, $registeredhub->token, $function, $params);
}
/////// FORM REGISTRATION ACTION //////
if (!empty($fromform) and empty($update) and confirm_sesskey()) {
if (!empty($fromform) and confirm_sesskey()) { // if the register button has been clicked
$params = (array) $fromform; //we are using the form input as the redirection parameters (token, url and name)
if (empty($registeredhub)) {
//we save the token into the communication table in order to have a reference
$registeredhub = new stdClass();
$registeredhub->token = md5(uniqid(rand(),1));
$registeredhub->huburl = $huburl;
$registeredhub->hubname = $hubname;
$registeredhub->confirmed = 0;
$registeredhub->id = $hub->add_registeredhub($registeredhub);
}
$params['token'] = $registeredhub->token;
$params['url'] = $CFG->wwwroot;
redirect(new moodle_url(MOODLEORGHUBURL.'/local/hub/siteregistration.php', $params));
}
}
/////// OUTPUT SECTION /////////////
echo $OUTPUT->header();
//Display update notification result
if (!empty($registeredhub->confirmed)) {
if (!empty($result)) {
echo $OUTPUT->notification(get_string('siteregistrationupdated', 'hub'), 'notifysuccess');
}
}
$siteregistrationform->display();
echo $OUTPUT->footer();

View file

@ -0,0 +1,97 @@
<?php
///////////////////////////////////////////////////////////////////////////
// //
// This file is part of Moodle - http://moodle.org/ //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// //
// Moodle is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// Moodle is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. //
// //
///////////////////////////////////////////////////////////////////////////
/**
* Registration renderer.
* @package moodle
* @subpackage registration
* @copyright 2010 Moodle Pty Ltd (http://moodle.com)
* @author Jerome Mouneyrac
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_register_renderer extends plugin_renderer_base {
/**
* Display a box message confirming a site registration (add or update)
* @param string $confirmationmessage
* @return string
*/
public function registration_confirmation($confirmationmessage) {
global $OUTPUT;
$linktositelist = html_writer::tag('a', get_string('sitelist','hub'), array('href' => new moodle_url('/local/hub/index.php')));
$message = $confirmationmessage.html_writer::empty_tag('br').$linktositelist;
return $OUTPUT->box($message);
}
/**
* Display the page to register on Moodle.org or on a specific hub
*/
public function registrationselector() {
global $OUTPUT;
$table = new html_table();
$table->head = array(get_string('moodleorg', 'hub'), get_string('specifichub', 'hub'));
$table->size = array('50%', '50%');
//$table->attributes['class'] = 'registerindextable';
//Moodle.org information cell
$moodleorgcell = get_string('moodleorgregistrationdetail', 'hub');
$moodleorgcell .= html_writer::empty_tag('br').html_writer::empty_tag('br');
$moodleorgcell = html_writer::tag('div', $moodleorgcell, array('class' => 'justifytext'));
//Specific hub information cell
$specifichubcell = get_string('specifichubregistrationdetail', 'hub');
$specifichubcell .= html_writer::empty_tag('br').html_writer::empty_tag('br');
$specifichubcell = html_writer::tag('div', $specifichubcell, array('class' => 'justifytext'));
//add information cells
$cells = array($moodleorgcell, $specifichubcell);
$row = new html_table_row($cells);
$table->data[] = $row;
//Moodle.org button cell
$registeronmoodleorgurl = new moodle_url("/admin/registration/register.php",
array('sesskey' => sesskey(), 'huburl' => MOODLEORGHUBURL
, 'hubname' => 'Moodle.org'));
$registeronmoodleorgbutton = new single_button($registeronmoodleorgurl, get_string('registeronmoodleorg', 'hub'));
$registeronmoodleorgbutton->class = 'centeredbutton';
$registeronmoodleorgbuttonhtml = $OUTPUT->render($registeronmoodleorgbutton);
$moodleorgcell = $registeronmoodleorgbuttonhtml;
//Specific hub button cell
$registeronspecifichuburl = new moodle_url("/admin/registration/hubselector.php",
array('sesskey' => sesskey()));
$registeronspecifichubbutton = new single_button($registeronspecifichuburl, get_string('registeronspecifichub', 'hub'));
$registeronspecifichubbutton->class = 'centeredbutton';
$registeronspecifichubbuttonhtml = $OUTPUT->render($registeronspecifichubbutton);
$specifichubcell = $registeronspecifichubbuttonhtml;
//add button cells
$cells = array($moodleorgcell, $specifichubcell);
$row = new html_table_row($cells);
$table->data[] = $row;
return html_writer::table($table);
}
}

View file

@ -10,11 +10,15 @@ $hassiteconfig = has_capability('moodle/site:config', $systemcontext);
$ADMIN->add('root', new admin_externalpage('adminnotifications', get_string('notifications'), "$CFG->wwwroot/$CFG->admin/index.php"));
// Show the annoying registration button if registration hasn't been done or is 6 months old (15552000 seconds) MDL-17429
if (empty($CFG->registered) || ($CFG->registered < (time() - 15552000))) {
$ADMIN->add('root', new admin_externalpage('adminregistration', get_string('registration','admin'), "$CFG->wwwroot/$CFG->admin/register.php"));
}
$ADMIN->add('root', new admin_externalpage('registrationindex', get_string('registration','admin'),
"$CFG->wwwroot/$CFG->admin/registration/index.php"));
$ADMIN->add('root', new admin_externalpage('registration', get_string('registeron','hub'),
"$CFG->wwwroot/$CFG->admin/registration/register.php", 'moodle/site:config', true));
$ADMIN->add('root', new admin_externalpage('registrationselector', get_string('registeron','hub'),
"$CFG->wwwroot/$CFG->admin/registration/hubselector.php", 'moodle/site:config', true));
$ADMIN->add('root', new admin_externalpage('siteregistrationconfirmed',
get_string('registrationconfirmed', 'hub'),
$CFG->wwwroot."/".$CFG->admin."/registration/confirmregistration.php", 'moodle/site:config', true));
// hidden upgrade script
$ADMIN->add('root', new admin_externalpage('upgradesettings', get_string('upgradesettings', 'admin'), "$CFG->wwwroot/$CFG->admin/upgradesettings.php", 'moodle/site:config', true));