MDL-43987 core: Remove port numbers in cleanremoteaddr
[moodle.git] / mod / workshop / editform.php
blob96417e3a686571dcd1b9e88834fd73cde25f5d17
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * Edit grading form in for a particular instance of workshop
21 * @package mod_workshop
22 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
27 require_once(dirname(__FILE__).'/locallib.php');
29 $cmid = required_param('cmid', PARAM_INT);
31 $cm = get_coursemodule_from_id('workshop', $cmid, 0, false, MUST_EXIST);
32 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
34 require_login($course, false, $cm);
35 require_capability('mod/workshop:editdimensions', $PAGE->context);
37 $workshop = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
38 $workshop = new workshop($workshop, $cm, $course);
40 // todo: check if there already is some assessment done and do not allowed the change of the form
41 // once somebody already used it to assess
43 $PAGE->set_url($workshop->editform_url());
44 $PAGE->set_title($workshop->name);
45 $PAGE->set_heading($course->fullname);
46 $PAGE->navbar->add(get_string('editingassessmentform', 'workshop'));
48 // load the grading strategy logic
49 $strategy = $workshop->grading_strategy_instance();
51 // load the form to edit the grading strategy dimensions
52 $mform = $strategy->get_edit_strategy_form($PAGE->url);
54 if ($mform->is_cancelled()) {
55 redirect($workshop->view_url());
56 } elseif ($data = $mform->get_data()) {
57 if (($data->workshopid != $workshop->id) or ($data->strategy != $workshop->strategy)) {
58 // this may happen if someone changes the workshop setting while the user had the
59 // editing form opened
60 throw new invalid_parameter_exception('Invalid workshop ID or the grading strategy has changed.');
62 $strategy->save_edit_strategy_form($data);
63 if (isset($data->saveandclose)) {
64 redirect($workshop->view_url());
65 } elseif (isset($data->saveandpreview)) {
66 redirect($workshop->previewform_url());
67 } else {
68 // save and continue - redirect to self to prevent data being re-posted by pressing "Reload"
69 redirect($PAGE->url);
73 // Output starts here
75 echo $OUTPUT->header();
76 echo $OUTPUT->heading(format_string($workshop->name));
77 echo $OUTPUT->heading(get_string('pluginname', 'workshopform_' . $workshop->strategy), 3);
79 $mform->display();
81 echo $OUTPUT->footer();