Permalink
Browse files

MDL-31692 mod_lti - ensure that various mforms are used properly

* typesettings.php and instructor_edit_tool_type.php are tided
   up properly to ensure proper use for form data
* An incorrect PARAM type is corrected for typename
  • Loading branch information...
1 parent 848fc30 commit 9f6f18d2c24a8e191c13ab99425956c9759cfb2c @danpoltawski danpoltawski committed with Sam Hemelryk Jun 22, 2012
Showing with 34 additions and 108 deletions.
  1. +1 −1 mod/lti/edit_form.php
  2. +3 −6 mod/lti/instructor_edit_tool_type.php
  3. +30 −101 mod/lti/typessettings.php
@@ -62,7 +62,7 @@ public function definition() {
$mform->addElement('header', 'setup', get_string('tool_settings', 'lti'));
$mform->addElement('text', 'lti_typename', get_string('typename', 'lti'));
- $mform->setType('lti_typename', PARAM_INT);
+ $mform->setType('lti_typename', PARAM_TEXT);
$mform->addHelpButton('lti_typename', 'typename', 'lti');
$mform->addRule('lti_typename', null, 'required', null, 'client');
@@ -47,9 +47,8 @@
}
}
-$data = data_submitted();
-
-if (isset($data->submitbutton) && confirm_sesskey()) {
+$form = new mod_lti_edit_types_form();
+if ($data = $form->get_data()) {
$type = new stdClass();
if (!empty($typeid)) {
@@ -96,7 +95,7 @@
die;
}
-} else if (isset($data->cancel)) {
+} else if ($form->is_cancelled()) {
$script = "
<html>
<script type=\"text/javascript\">
@@ -120,10 +119,8 @@
echo $OUTPUT->heading(get_string('toolsetup', 'lti'));
if ($action == 'add') {
- $form = new mod_lti_edit_types_form();
$form->display();
} else if ($action == 'edit') {
- $form = new mod_lti_edit_types_form();
$type = lti_get_type_type_config($typeid);
$form->set_data($type);
$form->display();
@@ -53,41 +53,42 @@
require_once($CFG->dirroot.'/mod/lti/edit_form.php');
require_once($CFG->dirroot.'/mod/lti/locallib.php');
-$section = 'modsettinglti';
-$return = optional_param('return', '', PARAM_ALPHA);
-$adminediting = optional_param('adminedit', -1, PARAM_BOOL);
$action = optional_param('action', null, PARAM_ACTION);
$id = optional_param('id', null, PARAM_INT);
-$useexisting = optional_param('useexisting', null, PARAM_INT);
-$definenew = optional_param('definenew', null, PARAM_INT);
+$tab = optional_param('tab', '', PARAM_ALPHAEXT);
// no guest autologin
require_login(0, false);
+
$pageurl = new moodle_url('/mod/lti/typessettings.php');
+if (!empty($id)) {
+ $pageurl->param('id', $id);
+}
$PAGE->set_url($pageurl);
admin_externalpage_setup('managemodules'); // Hacky solution for printing the admin page
-$tab = optional_param('tab', '', PARAM_ALPHAEXT);
$redirect = "$CFG->wwwroot/$CFG->admin/settings.php?section=modsettinglti&tab={$tab}";
-// WRITING SUBMITTED DATA (IF ANY)
-
-$statusmsg = '';
-$errormsg = '';
-$focus = '';
+require_sesskey();
-$data = data_submitted();
-
-// Any posted data & any action
-if (!empty($data) || !empty($action)) {
- require_sesskey();
+if ($action == 'accept') {
+ lti_set_state_for_type($id, LTI_TOOL_STATE_CONFIGURED);
+ redirect($redirect);
+} else if ($action == 'reject') {
+ lti_set_state_for_type($id, LTI_TOOL_STATE_REJECTED);
+ redirect($redirect);
+} else if ($action == 'delete') {
+ lti_delete_type($id);
+ redirect($redirect);
}
-if (isset($data->submitbutton)) {
+$form = new mod_lti_edit_types_form($pageurl, (object)array('isadmin' => true));
+
+if ($data = $form->get_data()) {
$type = new stdClass();
- if (isset($id)) {
+ if (!empty($id)) {
$type->id = $id;
lti_update_type($type, $data);
@@ -100,94 +101,22 @@
redirect($redirect);
}
-
-} else if (isset($data->cancel)) {
- redirect($redirect);
-
-} else if ($action == 'accept') {
- lti_set_state_for_type($id, LTI_TOOL_STATE_CONFIGURED);
- redirect($redirect);
-
-} else if ($action == 'reject') {
- lti_set_state_for_type($id, LTI_TOOL_STATE_REJECTED);
- redirect($redirect);
-
-} else if ($action == 'delete') {
- lti_delete_type($id);
+} else if ($form->is_cancelled()) {
redirect($redirect);
}
-// print header stuff
-$PAGE->set_focuscontrol($focus);
-if (empty($SITE->fullname)) {
- $PAGE->set_title($settingspage->visiblename);
- $PAGE->set_heading($settingspage->visiblename);
-
- $PAGE->navbar->add(get_string('lti_administration', 'lti'), $CFG->wwwroot.'/admin/settings.php?section=modsettinglti');
-
- echo $OUTPUT->header();
-
- echo $OUTPUT->box(get_string('configintrosite', 'admin'));
-
- if ($errormsg !== '') {
- echo $OUTPUT->notification($errormsg);
-
- } else if ($statusmsg !== '') {
- echo $OUTPUT->notification($statusmsg, 'notifysuccess');
- }
-
- echo '<form action="typesettings.php" method="post" id="'.$id.'" >';
- echo '<div class="settingsform clearfix">';
- echo html_writer::input_hidden_params($PAGE->url);
- echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
- echo '<input type="hidden" name="return" value="'.$return.'" />';
-
- echo $settingspage->output_html();
-
- echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges', 'admin').'" /></div>';
-
- echo '</div>';
- echo '</form>';
-
-} else {
- if ($PAGE->user_allowed_editing()) {
- $url = clone($PAGE->url);
- if ($PAGE->user_is_editing()) {
- $caption = get_string('blockseditoff');
- $url->param('adminedit', 'off');
- } else {
- $caption = get_string('blocksediton');
- $url->param('adminedit', 'on');
- }
- $buttons = $OUTPUT->single_button($url, $caption, 'get');
- }
-
- $PAGE->set_title("$SITE->shortname: " . get_string('toolsetup', 'lti'));
-
- $PAGE->navbar->add(get_string('lti_administration', 'lti'), $CFG->wwwroot.'/admin/settings.php?section=modsettinglti');
+$PAGE->set_title("$SITE->shortname: " . get_string('toolsetup', 'lti'));
+$PAGE->navbar->add(get_string('lti_administration', 'lti'), $CFG->wwwroot.'/admin/settings.php?section=modsettinglti');
- echo $OUTPUT->header();
-
- if ($errormsg !== '') {
- echo $OUTPUT->notification($errormsg);
-
- } else if ($statusmsg !== '') {
- echo $OUTPUT->notification($statusmsg, 'notifysuccess');
- }
-
- echo $OUTPUT->heading(get_string('toolsetup', 'lti'));
- echo $OUTPUT->box_start('generalbox');
- if ($action == 'add') {
- $form = new mod_lti_edit_types_form($pageurl, (object)array('isadmin' => true));
- $form->display();
- } else if ($action == 'update') {
- $form = new mod_lti_edit_types_form('typessettings.php?id='.$id, (object)array('isadmin' => true));
- $type = lti_get_type_type_config($id);
- $form->set_data($type);
- $form->display();
- }
+echo $OUTPUT->header();
+echo $OUTPUT->heading(get_string('toolsetup', 'lti'));
+echo $OUTPUT->box_start('generalbox');
- echo $OUTPUT->box_end();
+if ($action == 'update') {
+ $type = lti_get_type_type_config($id);
+ $form->set_data($type);
}
+$form->display();
+echo $OUTPUT->box_end();
echo $OUTPUT->footer();

0 comments on commit 9f6f18d

Please sign in to comment.