Merge branch 'MDL-39444_24' of git://github.com/timhunt/moodle into MOODLE_24_STABLE
[moodle.git] / course / modedit.php
blob20b71b413c54ee1d13fa3d40101c01c1ff47564f
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->visibleold = $fromform->visible;
417 $newcm->groupmode = $fromform->groupmode;
418 $newcm->groupingid = $fromform->groupingid;
419 $newcm->groupmembersonly = $fromform->groupmembersonly;
420 $completion = new completion_info($course);
421 if ($completion->is_enabled()) {
422 $newcm->completion = $fromform->completion;
423 $newcm->completiongradeitemnumber = $fromform->completiongradeitemnumber;
424 $newcm->completionview = $fromform->completionview;
425 $newcm->completionexpected = $fromform->completionexpected;
427 if(!empty($CFG->enableavailability)) {
428 $newcm->availablefrom = $fromform->availablefrom;
429 $newcm->availableuntil = $fromform->availableuntil;
430 $newcm->showavailability = $fromform->showavailability;
432 if (isset($fromform->showdescription)) {
433 $newcm->showdescription = $fromform->showdescription;
434 } else {
435 $newcm->showdescription = 0;
438 if (!$fromform->coursemodule = add_course_module($newcm)) {
439 print_error('cannotaddcoursemodule');
442 if (plugin_supports('mod', $fromform->modulename, FEATURE_MOD_INTRO, true)) {
443 $introeditor = $fromform->introeditor;
444 unset($fromform->introeditor);
445 $fromform->intro = $introeditor['text'];
446 $fromform->introformat = $introeditor['format'];
449 $returnfromfunc = $addinstancefunction($fromform, $mform);
451 if (!$returnfromfunc or !is_number($returnfromfunc)) {
452 // undo everything we can
453 $modcontext = context_module::instance($fromform->coursemodule);
454 delete_context(CONTEXT_MODULE, $fromform->coursemodule);
455 $DB->delete_records('course_modules', array('id'=>$fromform->coursemodule));
457 if (!is_number($returnfromfunc)) {
458 print_error('invalidfunction', '', course_get_url($course, $cw->section));
459 } else {
460 print_error('cannotaddnewmodule', '', course_get_url($course, $cw->section), $fromform->modulename);
464 $fromform->instance = $returnfromfunc;
466 $DB->set_field('course_modules', 'instance', $returnfromfunc, array('id'=>$fromform->coursemodule));
468 // update embedded links and save files
469 $modcontext = context_module::instance($fromform->coursemodule);
470 if (!empty($introeditor)) {
471 $fromform->intro = file_save_draft_area_files($introeditor['itemid'], $modcontext->id,
472 'mod_'.$fromform->modulename, 'intro', 0,
473 array('subdirs'=>true), $introeditor['text']);
474 $DB->set_field($fromform->modulename, 'intro', $fromform->intro, array('id'=>$fromform->instance));
477 // course_modules and course_sections each contain a reference
478 // to each other, so we have to update one of them twice.
479 $sectionid = course_add_cm_to_section($course, $fromform->coursemodule, $fromform->section);
481 // make sure visibility is set correctly (in particular in calendar)
482 // note: allow them to set it even without moodle/course:activityvisibility
483 set_coursemodule_visible($fromform->coursemodule, $fromform->visible);
485 if (isset($fromform->cmidnumber)) { //label
486 // set cm idnumber - uniqueness is already verified by form validation
487 set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber);
490 // Set up conditions
491 if ($CFG->enableavailability) {
492 condition_info::update_cm_from_form((object)array('id'=>$fromform->coursemodule), $fromform, false);
495 $eventname = 'mod_created';
497 add_to_log($course->id, "course", "add mod",
498 "../mod/$fromform->modulename/view.php?id=$fromform->coursemodule",
499 "$fromform->modulename $fromform->instance");
500 add_to_log($course->id, $fromform->modulename, "add",
501 "view.php?id=$fromform->coursemodule",
502 "$fromform->instance", $fromform->coursemodule);
503 } else {
504 print_error('invaliddata');
507 // Trigger mod_created/mod_updated event with information about this module.
508 $eventdata = new stdClass();
509 $eventdata->modulename = $fromform->modulename;
510 $eventdata->name = $fromform->name;
511 $eventdata->cmid = $fromform->coursemodule;
512 $eventdata->courseid = $course->id;
513 $eventdata->userid = $USER->id;
514 events_trigger($eventname, $eventdata);
516 // sync idnumber with grade_item
517 if ($grade_item = grade_item::fetch(array('itemtype'=>'mod', 'itemmodule'=>$fromform->modulename,
518 'iteminstance'=>$fromform->instance, 'itemnumber'=>0, 'courseid'=>$course->id))) {
519 if ($grade_item->idnumber != $fromform->cmidnumber) {
520 $grade_item->idnumber = $fromform->cmidnumber;
521 $grade_item->update();
525 $items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$fromform->modulename,
526 'iteminstance'=>$fromform->instance, 'courseid'=>$course->id));
528 // create parent category if requested and move to correct parent category
529 if ($items and isset($fromform->gradecat)) {
530 if ($fromform->gradecat == -1) {
531 $grade_category = new grade_category();
532 $grade_category->courseid = $course->id;
533 $grade_category->fullname = $fromform->name;
534 $grade_category->insert();
535 if ($grade_item) {
536 $parent = $grade_item->get_parent_category();
537 $grade_category->set_parent($parent->id);
539 $fromform->gradecat = $grade_category->id;
541 foreach ($items as $itemid=>$unused) {
542 $items[$itemid]->set_parent($fromform->gradecat);
543 if ($itemid == $grade_item->id) {
544 // use updated grade_item
545 $grade_item = $items[$itemid];
550 // add outcomes if requested
551 if ($outcomes = grade_outcome::fetch_all_available($course->id)) {
552 $grade_items = array();
554 // Outcome grade_item.itemnumber start at 1000, there is nothing above outcomes
555 $max_itemnumber = 999;
556 if ($items) {
557 foreach($items as $item) {
558 if ($item->itemnumber > $max_itemnumber) {
559 $max_itemnumber = $item->itemnumber;
564 foreach($outcomes as $outcome) {
565 $elname = 'outcome_'.$outcome->id;
567 if (property_exists($fromform, $elname) and $fromform->$elname) {
568 // so we have a request for new outcome grade item?
569 if ($items) {
570 foreach($items as $item) {
571 if ($item->outcomeid == $outcome->id) {
572 //outcome aready exists
573 continue 2;
578 $max_itemnumber++;
580 $outcome_item = new grade_item();
581 $outcome_item->courseid = $course->id;
582 $outcome_item->itemtype = 'mod';
583 $outcome_item->itemmodule = $fromform->modulename;
584 $outcome_item->iteminstance = $fromform->instance;
585 $outcome_item->itemnumber = $max_itemnumber;
586 $outcome_item->itemname = $outcome->fullname;
587 $outcome_item->outcomeid = $outcome->id;
588 $outcome_item->gradetype = GRADE_TYPE_SCALE;
589 $outcome_item->scaleid = $outcome->scaleid;
590 $outcome_item->insert();
592 // move the new outcome into correct category and fix sortorder if needed
593 if ($grade_item) {
594 $outcome_item->set_parent($grade_item->categoryid);
595 $outcome_item->move_after_sortorder($grade_item->sortorder);
597 } else if (isset($fromform->gradecat)) {
598 $outcome_item->set_parent($fromform->gradecat);
604 if (plugin_supports('mod', $fromform->modulename, FEATURE_ADVANCED_GRADING, false)
605 and has_capability('moodle/grade:managegradingforms', $modcontext)) {
606 require_once($CFG->dirroot.'/grade/grading/lib.php');
607 $gradingman = get_grading_manager($modcontext, 'mod_'.$fromform->modulename);
608 $showgradingmanagement = false;
609 foreach ($gradingman->get_available_areas() as $areaname => $aretitle) {
610 $formfield = 'advancedgradingmethod_'.$areaname;
611 if (isset($fromform->{$formfield})) {
612 $gradingman->set_area($areaname);
613 $methodchanged = $gradingman->set_active_method($fromform->{$formfield});
614 if (empty($fromform->{$formfield})) {
615 // going back to the simple direct grading is not a reason
616 // to open the management screen
617 $methodchanged = false;
619 $showgradingmanagement = $showgradingmanagement || $methodchanged;
624 rebuild_course_cache($course->id);
625 grade_regrade_final_grades($course->id);
626 plagiarism_save_form_elements($fromform); //save plagiarism settings
628 if (isset($fromform->submitbutton)) {
629 if (empty($showgradingmanagement)) {
630 redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$fromform->coursemodule");
631 } else {
632 $returnurl = new moodle_url("/mod/$module->name/view.php", array('id' => $fromform->coursemodule));
633 redirect($gradingman->get_management_url($returnurl));
635 } else {
636 redirect(course_get_url($course, $cw->section, array('sr' => $sectionreturn)));
638 exit;
640 } else {
642 $streditinga = get_string('editinga', 'moodle', $fullmodulename);
643 $strmodulenameplural = get_string('modulenameplural', $module->name);
645 if (!empty($cm->id)) {
646 $context = context_module::instance($cm->id);
647 } else {
648 $context = context_course::instance($course->id);
651 $PAGE->set_heading($course->fullname);
652 $PAGE->set_title($streditinga);
653 $PAGE->set_cacheable(false);
654 echo $OUTPUT->header();
656 if (get_string_manager()->string_exists('modulename_help', $module->name)) {
657 echo $OUTPUT->heading_with_help($pageheading, 'modulename', $module->name, 'icon');
658 } else {
659 echo $OUTPUT->heading_with_help($pageheading, '', $module->name, 'icon');
662 $mform->display();
664 echo $OUTPUT->footer();