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
// 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
*
* @package moodlecore
* @package core
* @subpackage mnet
* @copyright 2010 Penny Leach
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');
/**
@ -33,12 +35,15 @@ require_once($CFG->libdir . '/formslib.php');
class mnet_simple_host_form extends moodleform {
function definition() {
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->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');
$this->add_action_buttons(false, get_string('addhost', 'mnet'));
@ -46,6 +51,7 @@ class mnet_simple_host_form extends moodleform {
function validation($data) {
global $DB;
$wwwroot = $data['wwwroot'];
// ensure the wwwroot starts with a http or https prefix
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 {
function definition() {
global $OUTPUT;
$mform =& $this->_form;
$mform = $this->_form;
$mnet_peer = $this->_customdata['peer'];
$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->setType('name', PARAM_NOTAGS);
$mform->addElement('text', 'wwwroot', get_string('hostname', 'mnet'));
$mform->setType('wwwroot', PARAM_URL);
$mform->addElement('textarea', 'public_key', get_string('publickey', 'mnet'), array('rows' => 17, 'cols' => 100, 'class' => 'smalltext'));
$mform->setType('public_key', PARAM_PEM);
if ($mnet_peer && !empty($mnet_peer->deleted)) {
$radioarray=array();
$radioarray[] = &MoodleQuickForm::createElement('radio', 'deleted', '', get_string('yes'), 1);
$radioarray[] = &MoodleQuickForm::createElement('radio', 'deleted', '', get_string('no'), 0);
$radioarray = array();
$radioarray[] = MoodleQuickForm::createElement('radio', 'deleted', '', get_string('yes'), 1);
$radioarray[] = MoodleQuickForm::createElement('radio', 'deleted', '', get_string('no'), 0);
$mform->addGroup($radioarray, 'radioar', get_string('deleted'), array(' '), false);
} else {
$mform->addElement('hidden', 'deleted');

View File

@ -36,7 +36,6 @@ require_login();
$context = get_context_instance(CONTEXT_SYSTEM);
require_capability('moodle/site:config', $context, $USER->id, true, 'nopermissions');
/// Initialize variables.
$hostid = optional_param('hostid', 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');
}
$mnet_peer = new mnet_peer();
$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
// if the first form has been submitted, bootstrap the peer and load up the review form
if ($formdata = $simpleform->get_data()) {
// 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->updateparams->public_key_expires = $mnet_peer->check_common_name($formdata->public_key);
$credentials = $mnet_peer->check_credentials($mnet_peer->public_key);
$mnet_peer->public_key_expires = $credentials['validTo_time_t'];