NOMDL MNet admin/mnet trivial code cleanups spotted during development

This commit is contained in:
David Mudrak 2010-07-12 15:03:03 +00:00
parent 908ca82aaa
commit e7c1d0211e
2 changed files with 17 additions and 13 deletions

View file

@ -15,15 +15,17 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* This file contains two forms for adding/editing mnet hosts, used by peers.php * This file contains two forms for adding/editing mnet hosts, used by peers.php
* *
* @package moodlecore * @package core
* @subpackage mnet
* @copyright 2010 Penny Leach * @copyright 2010 Penny Leach
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php'); require_once($CFG->libdir . '/formslib.php');
/** /**
@ -33,12 +35,15 @@ require_once($CFG->libdir . '/formslib.php');
class mnet_simple_host_form extends moodleform { class mnet_simple_host_form extends moodleform {
function definition() { function definition() {
global $DB; global $DB;
$mform =& $this->_form;
$mform->addElement('text', 'wwwroot', get_string('hostname', 'mnet'));
$mform->addElement('select', 'applicationid', get_string('applicationtype', 'mnet'), $DB->get_records_menu('mnet_application', array(), 'id,display_name'));
$mform = $this->_form;
$mform->addElement('text', 'wwwroot', get_string('hostname', 'mnet'));
$mform->setType('wwwroot', PARAM_URL); $mform->setType('wwwroot', PARAM_URL);
$mform->addRule('wwwroot', null, 'required', null, 'client'); $mform->addRule('wwwroot', null, 'required', null, 'client');
$mform->addElement('select', 'applicationid', get_string('applicationtype', 'mnet'),
$DB->get_records_menu('mnet_application', array(), 'id,display_name'));
$mform->addRule('applicationid', null, 'required', null, 'client'); $mform->addRule('applicationid', null, 'required', null, 'client');
$this->add_action_buttons(false, get_string('addhost', 'mnet')); $this->add_action_buttons(false, get_string('addhost', 'mnet'));
@ -46,6 +51,7 @@ class mnet_simple_host_form extends moodleform {
function validation($data) { function validation($data) {
global $DB; global $DB;
$wwwroot = $data['wwwroot']; $wwwroot = $data['wwwroot'];
// ensure the wwwroot starts with a http or https prefix // ensure the wwwroot starts with a http or https prefix
if (strtolower(substr($wwwroot, 0, 4)) != 'http') { if (strtolower(substr($wwwroot, 0, 4)) != 'http') {
@ -66,7 +72,8 @@ class mnet_simple_host_form extends moodleform {
class mnet_review_host_form extends moodleform { class mnet_review_host_form extends moodleform {
function definition() { function definition() {
global $OUTPUT; global $OUTPUT;
$mform =& $this->_form;
$mform = $this->_form;
$mnet_peer = $this->_customdata['peer']; $mnet_peer = $this->_customdata['peer'];
$mform->addElement('hidden', 'last_connect_time'); $mform->addElement('hidden', 'last_connect_time');
@ -76,15 +83,16 @@ class mnet_review_host_form extends moodleform {
$mform->addElement('text', 'name', get_string('site')); $mform->addElement('text', 'name', get_string('site'));
$mform->setType('name', PARAM_NOTAGS); $mform->setType('name', PARAM_NOTAGS);
$mform->addElement('text', 'wwwroot', get_string('hostname', 'mnet')); $mform->addElement('text', 'wwwroot', get_string('hostname', 'mnet'));
$mform->setType('wwwroot', PARAM_URL); $mform->setType('wwwroot', PARAM_URL);
$mform->addElement('textarea', 'public_key', get_string('publickey', 'mnet'), array('rows' => 17, 'cols' => 100, 'class' => 'smalltext')); $mform->addElement('textarea', 'public_key', get_string('publickey', 'mnet'), array('rows' => 17, 'cols' => 100, 'class' => 'smalltext'));
$mform->setType('public_key', PARAM_PEM); $mform->setType('public_key', PARAM_PEM);
if ($mnet_peer && !empty($mnet_peer->deleted)) { if ($mnet_peer && !empty($mnet_peer->deleted)) {
$radioarray=array(); $radioarray = array();
$radioarray[] = &MoodleQuickForm::createElement('radio', 'deleted', '', get_string('yes'), 1); $radioarray[] = MoodleQuickForm::createElement('radio', 'deleted', '', get_string('yes'), 1);
$radioarray[] = &MoodleQuickForm::createElement('radio', 'deleted', '', get_string('no'), 0); $radioarray[] = MoodleQuickForm::createElement('radio', 'deleted', '', get_string('no'), 0);
$mform->addGroup($radioarray, 'radioar', get_string('deleted'), array(' '), false); $mform->addGroup($radioarray, 'radioar', get_string('deleted'), array(' '), false);
} else { } else {
$mform->addElement('hidden', 'deleted'); $mform->addElement('hidden', 'deleted');

View file

@ -36,7 +36,6 @@ require_login();
$context = get_context_instance(CONTEXT_SYSTEM); $context = get_context_instance(CONTEXT_SYSTEM);
require_capability('moodle/site:config', $context, $USER->id, true, 'nopermissions'); require_capability('moodle/site:config', $context, $USER->id, true, 'nopermissions');
/// Initialize variables. /// Initialize variables.
$hostid = optional_param('hostid', 0, PARAM_INT); $hostid = optional_param('hostid', 0, PARAM_INT);
$updra = optional_param('updateregisterall', 0, PARAM_INT); $updra = optional_param('updateregisterall', 0, PARAM_INT);
@ -71,12 +70,10 @@ if (!isset($CFG->mnet_dispatcher_mode)) {
set_config('mnet_dispatcher_mode', 'off'); set_config('mnet_dispatcher_mode', 'off');
} }
$mnet_peer = new mnet_peer(); $mnet_peer = new mnet_peer();
$simpleform = new mnet_simple_host_form(); // the one that goes on the bottom of the main page $simpleform = new mnet_simple_host_form(); // the one that goes on the bottom of the main page
$reviewform = null; // set up later in different code branches, so mnet_peer can be passed to the constructor $reviewform = null; // set up later in different code branches, so mnet_peer can be passed to the constructor
// if the first form has been submitted, bootstrap the peer and load up the review form // if the first form has been submitted, bootstrap the peer and load up the review form
if ($formdata = $simpleform->get_data()) { if ($formdata = $simpleform->get_data()) {
// ensure we remove trailing slashes // ensure we remove trailing slashes
@ -168,7 +165,6 @@ if ($formdata = $reviewform->get_data()) {
$mnet_peer->public_key_expires = $mnet_peer->check_common_name($formdata->public_key); $mnet_peer->public_key_expires = $mnet_peer->check_common_name($formdata->public_key);
$mnet_peer->updateparams->public_key_expires = $mnet_peer->check_common_name($formdata->public_key); $mnet_peer->updateparams->public_key_expires = $mnet_peer->check_common_name($formdata->public_key);
$credentials = $mnet_peer->check_credentials($mnet_peer->public_key); $credentials = $mnet_peer->check_credentials($mnet_peer->public_key);
$mnet_peer->public_key_expires = $credentials['validTo_time_t']; $mnet_peer->public_key_expires = $credentials['validTo_time_t'];