MDL-36209 Allow teachers to assess submissions during the grading evaluation phase
[moodle.git] / course / modedit.php
blob56bf28a567d32149f4c8299e839686736182b45d
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 * Adds or updates modules in a course using new formslib
21 * @package moodlecore
22 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require_once("../config.php");
27 require_once("lib.php");
28 require_once($CFG->libdir.'/filelib.php');
29 require_once($CFG->libdir.'/gradelib.php');
30 require_once($CFG->libdir.'/completionlib.php');
31 require_once($CFG->libdir.'/conditionlib.php');
32 require_once($CFG->libdir.'/plagiarismlib.php');
34 $add = optional_param('add', '', PARAM_ALPHA); // module name
35 $update = optional_param('update', 0, PARAM_INT);
36 $return = optional_param('return', 0, PARAM_BOOL); //return to course/view.php if false or mod/modname/view.php if true
37 $type = optional_param('type', '', PARAM_ALPHANUM); //TODO: hopefully will be removed in 2.0
38 $sectionreturn = optional_param('sr', null, PARAM_INT);
40 $url = new moodle_url('/course/modedit.php');
41 $url->param('sr', $sectionreturn);
42 if (!empty($return)) {
43 $url->param('return', $return);
46 if (!empty($add)) {
47 $section = required_param('section', PARAM_INT);
48 $course = required_param('course', PARAM_INT);
50 $url->param('add', $add);
51 $url->param('section', $section);
52 $url->param('course', $course);
53 $PAGE->set_url($url);
55 $course = $DB->get_record('course', array('id'=>$course), '*', MUST_EXIST);
56 $module = $DB->get_record('modules', array('name'=>$add), '*', MUST_EXIST);
58 require_login($course);
59 $context = context_course::instance($course->id);
60 require_capability('moodle/course:manageactivities', $context);
62 course_create_sections_if_missing($course, $section);
63 $cw = get_fast_modinfo($course)->get_section_info($section);
65 if (!course_allowed_module($course, $module->name)) {
66 print_error('moduledisable');
69 $cm = null;
71 $data = new stdClass();
72 $data->section = $section; // The section number itself - relative!!! (section column in course_sections)
73 $data->visible = $cw->visible;
74 $data->course = $course->id;
75 $data->module = $module->id;
76 $data->modulename = $module->name;
77 $data->groupmode = $course->groupmode;
78 $data->groupingid = $course->defaultgroupingid;
79 $data->groupmembersonly = 0;
80 $data->id = '';
81 $data->instance = '';
82 $data->coursemodule = '';
83 $data->add = $add;
84 $data->return = 0; //must be false if this is an add, go back to course view on cancel
85 $data->sr = $sectionreturn;
87 if (plugin_supports('mod', $data->modulename, FEATURE_MOD_INTRO, true)) {
88 $draftid_editor = file_get_submitted_draft_itemid('introeditor');
89 file_prepare_draft_area($draftid_editor, null, null, null, null);
90 $data->introeditor = array('text'=>'', 'format'=>FORMAT_HTML, 'itemid'=>$draftid_editor); // TODO: add better default
93 if (plugin_supports('mod', $data->modulename, FEATURE_ADVANCED_GRADING, false)
94 and has_capability('moodle/grade:managegradingforms', $context)) {
95 require_once($CFG->dirroot.'/grade/grading/lib.php');
97 $data->_advancedgradingdata['methods'] = grading_manager::available_methods();
98 $areas = grading_manager::available_areas('mod_'.$module->name);
100 foreach ($areas as $areaname => $areatitle) {
101 $data->_advancedgradingdata['areas'][$areaname] = array(
102 'title' => $areatitle,
103 'method' => '',
105 $formfield = 'advancedgradingmethod_'.$areaname;
106 $data->{$formfield} = '';
110 if (!empty($type)) { //TODO: hopefully will be removed in 2.0
111 $data->type = $type;
114 $sectionname = get_section_name($course, $cw);
115 $fullmodulename = get_string('modulename', $module->name);
117 if ($data->section && $course->format != 'site') {
118 $heading = new stdClass();
119 $heading->what = $fullmodulename;
120 $heading->to = $sectionname;
121 $pageheading = get_string('addinganewto', 'moodle', $heading);
122 } else {
123 $pageheading = get_string('addinganew', 'moodle', $fullmodulename);
126 } else if (!empty($update)) {
128 $url->param('update', $update);
129 $PAGE->set_url($url);
131 $cm = get_coursemodule_from_id('', $update, 0, false, MUST_EXIST);
132 $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
134 require_login($course, false, $cm); // needed to setup proper $COURSE
135 $context = context_module::instance($cm->id);
136 require_capability('moodle/course:manageactivities', $context);
138 $module = $DB->get_record('modules', array('id'=>$cm->module), '*', MUST_EXIST);
139 $data = $data = $DB->get_record($module->name, array('id'=>$cm->instance), '*', MUST_EXIST);
140 $cw = $DB->get_record('course_sections', array('id'=>$cm->section), '*', MUST_EXIST);
142 $data->coursemodule = $cm->id;
143 $data->section = $cw->section; // The section number itself - relative!!! (section column in course_sections)
144 $data->visible = $cm->visible; //?? $cw->visible ? $cm->visible : 0; // section hiding overrides
145 $data->cmidnumber = $cm->idnumber; // The cm IDnumber
146 $data->groupmode = groups_get_activity_groupmode($cm); // locked later if forced
147 $data->groupingid = $cm->groupingid;
148 $data->groupmembersonly = $cm->groupmembersonly;
149 $data->course = $course->id;
150 $data->module = $module->id;
151 $data->modulename = $module->name;
152 $data->instance = $cm->instance;
153 $data->return = $return;
154 $data->sr = $sectionreturn;
155 $data->update = $update;
156 $data->completion = $cm->completion;
157 $data->completionview = $cm->completionview;
158 $data->completionexpected = $cm->completionexpected;
159 $data->completionusegrade = is_null($cm->completiongradeitemnumber) ? 0 : 1;
160 $data->showdescription = $cm->showdescription;
161 if (!empty($CFG->enableavailability)) {
162 $data->availablefrom = $cm->availablefrom;
163 $data->availableuntil = $cm->availableuntil;
164 $data->showavailability = $cm->showavailability;
167 if (plugin_supports('mod', $data->modulename, FEATURE_MOD_INTRO, true)) {
168 $draftid_editor = file_get_submitted_draft_itemid('introeditor');
169 $currentintro = file_prepare_draft_area($draftid_editor, $context->id, 'mod_'.$data->modulename, 'intro', 0, array('subdirs'=>true), $data->intro);
170 $data->introeditor = array('text'=>$currentintro, 'format'=>$data->introformat, 'itemid'=>$draftid_editor);
173 if (plugin_supports('mod', $data->modulename, FEATURE_ADVANCED_GRADING, false)
174 and has_capability('moodle/grade:managegradingforms', $context)) {
175 require_once($CFG->dirroot.'/grade/grading/lib.php');
176 $gradingman = get_grading_manager($context, 'mod_'.$data->modulename);
177 $data->_advancedgradingdata['methods'] = $gradingman->get_available_methods();
178 $areas = $gradingman->get_available_areas();
180 foreach ($areas as $areaname => $areatitle) {
181 $gradingman->set_area($areaname);
182 $method = $gradingman->get_active_method();
183 $data->_advancedgradingdata['areas'][$areaname] = array(
184 'title' => $areatitle,
185 'method' => $method,
187 $formfield = 'advancedgradingmethod_'.$areaname;
188 $data->{$formfield} = $method;
192 if ($items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$data->modulename,
193 'iteminstance'=>$data->instance, 'courseid'=>$course->id))) {
194 // add existing outcomes
195 foreach ($items as $item) {
196 if (!empty($item->outcomeid)) {
197 $data->{'outcome_'.$item->outcomeid} = 1;
201 // set category if present
202 $gradecat = false;
203 foreach ($items as $item) {
204 if ($gradecat === false) {
205 $gradecat = $item->categoryid;
206 continue;
208 if ($gradecat != $item->categoryid) {
209 //mixed categories
210 $gradecat = false;
211 break;
214 if ($gradecat !== false) {
215 // do not set if mixed categories present
216 $data->gradecat = $gradecat;
220 $sectionname = get_section_name($course, $cw);
221 $fullmodulename = get_string('modulename', $module->name);
223 if ($data->section && $course->format != 'site') {
224 $heading = new stdClass();
225 $heading->what = $fullmodulename;
226 $heading->in = $sectionname;
227 $pageheading = get_string('updatingain', 'moodle', $heading);
228 } else {
229 $pageheading = get_string('updatinga', 'moodle', $fullmodulename);
232 } else {
233 require_login();
234 print_error('invalidaction');
237 $pagepath = 'mod-' . $module->name . '-';
238 if (!empty($type)) { //TODO: hopefully will be removed in 2.0
239 $pagepath .= $type;
240 } else {
241 $pagepath .= 'mod';
243 $PAGE->set_pagetype($pagepath);
244 $PAGE->set_pagelayout('admin');
246 $modmoodleform = "$CFG->dirroot/mod/$module->name/mod_form.php";
247 if (file_exists($modmoodleform)) {
248 require_once($modmoodleform);
249 } else {
250 print_error('noformdesc');
253 $modlib = "$CFG->dirroot/mod/$module->name/lib.php";
254 if (file_exists($modlib)) {
255 include_once($modlib);
256 } else {
257 print_error('modulemissingcode', '', '', $modlib);
260 $mformclassname = 'mod_'.$module->name.'_mod_form';
261 $mform = new $mformclassname($data, $cw->section, $cm, $course);
262 $mform->set_data($data);
264 if ($mform->is_cancelled()) {
265 if ($return && !empty($cm->id)) {
266 redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id");
267 } else {
268 redirect(course_get_url($course, $cw->section, array('sr' => $sectionreturn)));
270 } else if ($fromform = $mform->get_data()) {
271 if (empty($fromform->coursemodule)) {
272 // Add
273 $cm = null;
274 $course = $DB->get_record('course', array('id'=>$fromform->course), '*', MUST_EXIST);
275 $fromform->instance = '';
276 $fromform->coursemodule = '';
277 } else {
278 // Update
279 $cm = get_coursemodule_from_id('', $fromform->coursemodule, 0, false, MUST_EXIST);
280 $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
281 $fromform->instance = $cm->instance;
282 $fromform->coursemodule = $cm->id;
285 if (!empty($fromform->coursemodule)) {
286 $context = context_module::instance($fromform->coursemodule);
287 } else {
288 $context = context_course::instance($course->id);
291 $fromform->course = $course->id;
292 $fromform->modulename = clean_param($fromform->modulename, PARAM_PLUGIN); // For safety
294 $addinstancefunction = $fromform->modulename."_add_instance";
295 $updateinstancefunction = $fromform->modulename."_update_instance";
297 if (!isset($fromform->groupingid)) {
298 $fromform->groupingid = 0;
301 if (!isset($fromform->groupmembersonly)) {
302 $fromform->groupmembersonly = 0;
305 if (!isset($fromform->name)) { //label
306 $fromform->name = $fromform->modulename;
309 if (!isset($fromform->completion)) {
310 $fromform->completion = COMPLETION_DISABLED;
312 if (!isset($fromform->completionview)) {
313 $fromform->completionview = COMPLETION_VIEW_NOT_REQUIRED;
316 // Convert the 'use grade' checkbox into a grade-item number: 0 if
317 // checked, null if not
318 if (isset($fromform->completionusegrade) && $fromform->completionusegrade) {
319 $fromform->completiongradeitemnumber = 0;
320 } else {
321 $fromform->completiongradeitemnumber = null;
324 // the type of event to trigger (mod_created/mod_updated)
325 $eventname = '';
327 if (!empty($fromform->update)) {
329 if (!empty($course->groupmodeforce) or !isset($fromform->groupmode)) {
330 $fromform->groupmode = $cm->groupmode; // keep original
333 // update course module first
334 $cm->groupmode = $fromform->groupmode;
335 $cm->groupingid = $fromform->groupingid;
336 $cm->groupmembersonly = $fromform->groupmembersonly;
338 $completion = new completion_info($course);
339 if ($completion->is_enabled()) {
340 // Update completion settings
341 $cm->completion = $fromform->completion;
342 $cm->completiongradeitemnumber = $fromform->completiongradeitemnumber;
343 $cm->completionview = $fromform->completionview;
344 $cm->completionexpected = $fromform->completionexpected;
346 if (!empty($CFG->enableavailability)) {
347 $cm->availablefrom = $fromform->availablefrom;
348 $cm->availableuntil = $fromform->availableuntil;
349 $cm->showavailability = $fromform->showavailability;
350 condition_info::update_cm_from_form($cm,$fromform,true);
352 if (isset($fromform->showdescription)) {
353 $cm->showdescription = $fromform->showdescription;
354 } else {
355 $cm->showdescription = 0;
358 $DB->update_record('course_modules', $cm);
360 $modcontext = context_module::instance($fromform->coursemodule);
362 // update embedded links and save files
363 if (plugin_supports('mod', $fromform->modulename, FEATURE_MOD_INTRO, true)) {
364 $fromform->intro = file_save_draft_area_files($fromform->introeditor['itemid'], $modcontext->id,
365 'mod_'.$fromform->modulename, 'intro', 0,
366 array('subdirs'=>true), $fromform->introeditor['text']);
367 $fromform->introformat = $fromform->introeditor['format'];
368 unset($fromform->introeditor);
371 if (!$updateinstancefunction($fromform, $mform)) {
372 print_error('cannotupdatemod', '', course_get_url($course, $cw->section), $fromform->modulename);
375 // make sure visibility is set correctly (in particular in calendar)
376 if (has_capability('moodle/course:activityvisibility', $modcontext)) {
377 set_coursemodule_visible($fromform->coursemodule, $fromform->visible);
380 if (isset($fromform->cmidnumber)) { //label
381 // set cm idnumber - uniqueness is already verified by form validation
382 set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber);
385 // Now that module is fully updated, also update completion data if
386 // required (this will wipe all user completion data and recalculate it)
387 if ($completion->is_enabled() && !empty($fromform->completionunlocked)) {
388 $completion->reset_all_state($cm);
391 $eventname = 'mod_updated';
393 add_to_log($course->id, "course", "update mod",
394 "../mod/$fromform->modulename/view.php?id=$fromform->coursemodule",
395 "$fromform->modulename $fromform->instance");
396 add_to_log($course->id, $fromform->modulename, "update",
397 "view.php?id=$fromform->coursemodule",
398 "$fromform->instance", $fromform->coursemodule);
400 } else if (!empty($fromform->add)) {
402 if (!empty($course->groupmodeforce) or !isset($fromform->groupmode)) {
403 $fromform->groupmode = 0; // do not set groupmode
406 if (!course_allowed_module($course, $fromform->modulename)) {
407 print_error('moduledisable', '', '', $fromform->modulename);
410 // first add course_module record because we need the context
411 $newcm = new stdClass();
412 $newcm->course = $course->id;
413 $newcm->module = $fromform->module;
414 $newcm->instance = 0; // not known yet, will be updated later (this is similar to restore code)
415 $newcm->visible = $fromform->visible;
416 $newcm->groupmode = $fromform->groupmode;
417 $newcm->groupingid = $fromform->groupingid;
418 $newcm->groupmembersonly = $fromform->groupmembersonly;
419 $completion = new completion_info($course);
420 if ($completion->is_enabled()) {
421 $newcm->completion = $fromform->completion;
422 $newcm->completiongradeitemnumber = $fromform->completiongradeitemnumber;
423 $newcm->completionview = $fromform->completionview;
424 $newcm->completionexpected = $fromform->completionexpected;
426 if(!empty($CFG->enableavailability)) {
427 $newcm->availablefrom = $fromform->availablefrom;
428 $newcm->availableuntil = $fromform->availableuntil;
429 $newcm->showavailability = $fromform->showavailability;
431 if (isset($fromform->showdescription)) {
432 $newcm->showdescription = $fromform->showdescription;
433 } else {
434 $newcm->showdescription = 0;
437 if (!$fromform->coursemodule = add_course_module($newcm)) {
438 print_error('cannotaddcoursemodule');
441 if (plugin_supports('mod', $fromform->modulename, FEATURE_MOD_INTRO, true)) {
442 $introeditor = $fromform->introeditor;
443 unset($fromform->introeditor);
444 $fromform->intro = $introeditor['text'];
445 $fromform->introformat = $introeditor['format'];
448 $returnfromfunc = $addinstancefunction($fromform, $mform);
450 if (!$returnfromfunc or !is_number($returnfromfunc)) {
451 // undo everything we can
452 $modcontext = context_module::instance($fromform->coursemodule);
453 delete_context(CONTEXT_MODULE, $fromform->coursemodule);
454 $DB->delete_records('course_modules', array('id'=>$fromform->coursemodule));
456 if (!is_number($returnfromfunc)) {
457 print_error('invalidfunction', '', course_get_url($course, $cw->section));
458 } else {
459 print_error('cannotaddnewmodule', '', course_get_url($course, $cw->section), $fromform->modulename);
463 $fromform->instance = $returnfromfunc;
465 $DB->set_field('course_modules', 'instance', $returnfromfunc, array('id'=>$fromform->coursemodule));
467 // update embedded links and save files
468 $modcontext = context_module::instance($fromform->coursemodule);
469 if (!empty($introeditor)) {
470 $fromform->intro = file_save_draft_area_files($introeditor['itemid'], $modcontext->id,
471 'mod_'.$fromform->modulename, 'intro', 0,
472 array('subdirs'=>true), $introeditor['text']);
473 $DB->set_field($fromform->modulename, 'intro', $fromform->intro, array('id'=>$fromform->instance));
476 // course_modules and course_sections each contain a reference
477 // to each other, so we have to update one of them twice.
478 $sectionid = course_add_cm_to_section($course, $fromform->coursemodule, $fromform->section);
480 // make sure visibility is set correctly (in particular in calendar)
481 // note: allow them to set it even without moodle/course:activityvisibility
482 set_coursemodule_visible($fromform->coursemodule, $fromform->visible);
484 if (isset($fromform->cmidnumber)) { //label
485 // set cm idnumber - uniqueness is already verified by form validation
486 set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber);
489 // Set up conditions
490 if ($CFG->enableavailability) {
491 condition_info::update_cm_from_form((object)array('id'=>$fromform->coursemodule), $fromform, false);
494 $eventname = 'mod_created';
496 add_to_log($course->id, "course", "add mod",
497 "../mod/$fromform->modulename/view.php?id=$fromform->coursemodule",
498 "$fromform->modulename $fromform->instance");
499 add_to_log($course->id, $fromform->modulename, "add",
500 "view.php?id=$fromform->coursemodule",
501 "$fromform->instance", $fromform->coursemodule);
502 } else {
503 print_error('invaliddata');
506 // Trigger mod_created/mod_updated event with information about this module.
507 $eventdata = new stdClass();
508 $eventdata->modulename = $fromform->modulename;
509 $eventdata->name = $fromform->name;
510 $eventdata->cmid = $fromform->coursemodule;
511 $eventdata->courseid = $course->id;
512 $eventdata->userid = $USER->id;
513 events_trigger($eventname, $eventdata);
515 // sync idnumber with grade_item
516 if ($grade_item = grade_item::fetch(array('itemtype'=>'mod', 'itemmodule'=>$fromform->modulename,
517 'iteminstance'=>$fromform->instance, 'itemnumber'=>0, 'courseid'=>$course->id))) {
518 if ($grade_item->idnumber != $fromform->cmidnumber) {
519 $grade_item->idnumber = $fromform->cmidnumber;
520 $grade_item->update();
524 $items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$fromform->modulename,
525 'iteminstance'=>$fromform->instance, 'courseid'=>$course->id));
527 // create parent category if requested and move to correct parent category
528 if ($items and isset($fromform->gradecat)) {
529 if ($fromform->gradecat == -1) {
530 $grade_category = new grade_category();
531 $grade_category->courseid = $course->id;
532 $grade_category->fullname = $fromform->name;
533 $grade_category->insert();
534 if ($grade_item) {
535 $parent = $grade_item->get_parent_category();
536 $grade_category->set_parent($parent->id);
538 $fromform->gradecat = $grade_category->id;
540 foreach ($items as $itemid=>$unused) {
541 $items[$itemid]->set_parent($fromform->gradecat);
542 if ($itemid == $grade_item->id) {
543 // use updated grade_item
544 $grade_item = $items[$itemid];
549 // add outcomes if requested
550 if ($outcomes = grade_outcome::fetch_all_available($course->id)) {
551 $grade_items = array();
553 // Outcome grade_item.itemnumber start at 1000, there is nothing above outcomes
554 $max_itemnumber = 999;
555 if ($items) {
556 foreach($items as $item) {
557 if ($item->itemnumber > $max_itemnumber) {
558 $max_itemnumber = $item->itemnumber;
563 foreach($outcomes as $outcome) {
564 $elname = 'outcome_'.$outcome->id;
566 if (property_exists($fromform, $elname) and $fromform->$elname) {
567 // so we have a request for new outcome grade item?
568 if ($items) {
569 foreach($items as $item) {
570 if ($item->outcomeid == $outcome->id) {
571 //outcome aready exists
572 continue 2;
577 $max_itemnumber++;
579 $outcome_item = new grade_item();
580 $outcome_item->courseid = $course->id;
581 $outcome_item->itemtype = 'mod';
582 $outcome_item->itemmodule = $fromform->modulename;
583 $outcome_item->iteminstance = $fromform->instance;
584 $outcome_item->itemnumber = $max_itemnumber;
585 $outcome_item->itemname = $outcome->fullname;
586 $outcome_item->outcomeid = $outcome->id;
587 $outcome_item->gradetype = GRADE_TYPE_SCALE;
588 $outcome_item->scaleid = $outcome->scaleid;
589 $outcome_item->insert();
591 // move the new outcome into correct category and fix sortorder if needed
592 if ($grade_item) {
593 $outcome_item->set_parent($grade_item->categoryid);
594 $outcome_item->move_after_sortorder($grade_item->sortorder);
596 } else if (isset($fromform->gradecat)) {
597 $outcome_item->set_parent($fromform->gradecat);
603 if (plugin_supports('mod', $fromform->modulename, FEATURE_ADVANCED_GRADING, false)
604 and has_capability('moodle/grade:managegradingforms', $modcontext)) {
605 require_once($CFG->dirroot.'/grade/grading/lib.php');
606 $gradingman = get_grading_manager($modcontext, 'mod_'.$fromform->modulename);
607 $showgradingmanagement = false;
608 foreach ($gradingman->get_available_areas() as $areaname => $aretitle) {
609 $formfield = 'advancedgradingmethod_'.$areaname;
610 if (isset($fromform->{$formfield})) {
611 $gradingman->set_area($areaname);
612 $methodchanged = $gradingman->set_active_method($fromform->{$formfield});
613 if (empty($fromform->{$formfield})) {
614 // going back to the simple direct grading is not a reason
615 // to open the management screen
616 $methodchanged = false;
618 $showgradingmanagement = $showgradingmanagement || $methodchanged;
623 rebuild_course_cache($course->id);
624 grade_regrade_final_grades($course->id);
625 plagiarism_save_form_elements($fromform); //save plagiarism settings
627 if (isset($fromform->submitbutton)) {
628 if (empty($showgradingmanagement)) {
629 redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$fromform->coursemodule");
630 } else {
631 $returnurl = new moodle_url("/mod/$module->name/view.php", array('id' => $fromform->coursemodule));
632 redirect($gradingman->get_management_url($returnurl));
634 } else {
635 redirect(course_get_url($course, $cw->section, array('sr' => $sectionreturn)));
637 exit;
639 } else {
641 $streditinga = get_string('editinga', 'moodle', $fullmodulename);
642 $strmodulenameplural = get_string('modulenameplural', $module->name);
644 if (!empty($cm->id)) {
645 $context = context_module::instance($cm->id);
646 } else {
647 $context = context_course::instance($course->id);
650 $PAGE->set_heading($course->fullname);
651 $PAGE->set_title($streditinga);
652 $PAGE->set_cacheable(false);
653 echo $OUTPUT->header();
655 if (get_string_manager()->string_exists('modulename_help', $module->name)) {
656 echo $OUTPUT->heading_with_help($pageheading, 'modulename', $module->name, 'icon');
657 } else {
658 echo $OUTPUT->heading_with_help($pageheading, '', $module->name, 'icon');
661 $mform->display();
663 echo $OUTPUT->footer();