Moodle release 2.4.10
[moodle.git] / course / modedit.php
blobc8ca07121d1301ac648058d3abd7bbc69b843a94
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 // There is no page for this in the navigation. The closest we'll have is the course section.
63 // If the course section isn't displayed on the navigation this will fall back to the course which
64 // will be the closest match we have.
65 navigation_node::override_active_url(course_get_url($course, $section));
67 course_create_sections_if_missing($course, $section);
68 $cw = get_fast_modinfo($course)->get_section_info($section);
70 if (!course_allowed_module($course, $module->name)) {
71 print_error('moduledisable');
74 $cm = null;
76 $data = new stdClass();
77 $data->section = $section; // The section number itself - relative!!! (section column in course_sections)
78 $data->visible = $cw->visible;
79 $data->course = $course->id;
80 $data->module = $module->id;
81 $data->modulename = $module->name;
82 $data->groupmode = $course->groupmode;
83 $data->groupingid = $course->defaultgroupingid;
84 $data->groupmembersonly = 0;
85 $data->id = '';
86 $data->instance = '';
87 $data->coursemodule = '';
88 $data->add = $add;
89 $data->return = 0; //must be false if this is an add, go back to course view on cancel
90 $data->sr = $sectionreturn;
92 if (plugin_supports('mod', $data->modulename, FEATURE_MOD_INTRO, true)) {
93 $draftid_editor = file_get_submitted_draft_itemid('introeditor');
94 file_prepare_draft_area($draftid_editor, null, null, null, null);
95 $data->introeditor = array('text'=>'', 'format'=>FORMAT_HTML, 'itemid'=>$draftid_editor); // TODO: add better default
98 if (plugin_supports('mod', $data->modulename, FEATURE_ADVANCED_GRADING, false)
99 and has_capability('moodle/grade:managegradingforms', $context)) {
100 require_once($CFG->dirroot.'/grade/grading/lib.php');
102 $data->_advancedgradingdata['methods'] = grading_manager::available_methods();
103 $areas = grading_manager::available_areas('mod_'.$module->name);
105 foreach ($areas as $areaname => $areatitle) {
106 $data->_advancedgradingdata['areas'][$areaname] = array(
107 'title' => $areatitle,
108 'method' => '',
110 $formfield = 'advancedgradingmethod_'.$areaname;
111 $data->{$formfield} = '';
115 if (!empty($type)) { //TODO: hopefully will be removed in 2.0
116 $data->type = $type;
119 $sectionname = get_section_name($course, $cw);
120 $fullmodulename = get_string('modulename', $module->name);
122 if ($data->section && $course->format != 'site') {
123 $heading = new stdClass();
124 $heading->what = $fullmodulename;
125 $heading->to = $sectionname;
126 $pageheading = get_string('addinganewto', 'moodle', $heading);
127 } else {
128 $pageheading = get_string('addinganew', 'moodle', $fullmodulename);
130 $navbaraddition = $pageheading;
132 } else if (!empty($update)) {
134 $url->param('update', $update);
135 $PAGE->set_url($url);
137 $cm = get_coursemodule_from_id('', $update, 0, false, MUST_EXIST);
138 $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
140 require_login($course, false, $cm); // needed to setup proper $COURSE
141 $context = context_module::instance($cm->id);
142 require_capability('moodle/course:manageactivities', $context);
144 $module = $DB->get_record('modules', array('id'=>$cm->module), '*', MUST_EXIST);
145 $data = $data = $DB->get_record($module->name, array('id'=>$cm->instance), '*', MUST_EXIST);
146 $cw = $DB->get_record('course_sections', array('id'=>$cm->section), '*', MUST_EXIST);
148 $data->coursemodule = $cm->id;
149 $data->section = $cw->section; // The section number itself - relative!!! (section column in course_sections)
150 $data->visible = $cm->visible; //?? $cw->visible ? $cm->visible : 0; // section hiding overrides
151 $data->cmidnumber = $cm->idnumber; // The cm IDnumber
152 $data->groupmode = groups_get_activity_groupmode($cm); // locked later if forced
153 $data->groupingid = $cm->groupingid;
154 $data->groupmembersonly = $cm->groupmembersonly;
155 $data->course = $course->id;
156 $data->module = $module->id;
157 $data->modulename = $module->name;
158 $data->instance = $cm->instance;
159 $data->return = $return;
160 $data->sr = $sectionreturn;
161 $data->update = $update;
162 $data->completion = $cm->completion;
163 $data->completionview = $cm->completionview;
164 $data->completionexpected = $cm->completionexpected;
165 $data->completionusegrade = is_null($cm->completiongradeitemnumber) ? 0 : 1;
166 $data->showdescription = $cm->showdescription;
167 if (!empty($CFG->enableavailability)) {
168 $data->availablefrom = $cm->availablefrom;
169 $data->availableuntil = $cm->availableuntil;
170 $data->showavailability = $cm->showavailability;
173 if (plugin_supports('mod', $data->modulename, FEATURE_MOD_INTRO, true)) {
174 $draftid_editor = file_get_submitted_draft_itemid('introeditor');
175 $currentintro = file_prepare_draft_area($draftid_editor, $context->id, 'mod_'.$data->modulename, 'intro', 0, array('subdirs'=>true), $data->intro);
176 $data->introeditor = array('text'=>$currentintro, 'format'=>$data->introformat, 'itemid'=>$draftid_editor);
179 if (plugin_supports('mod', $data->modulename, FEATURE_ADVANCED_GRADING, false)
180 and has_capability('moodle/grade:managegradingforms', $context)) {
181 require_once($CFG->dirroot.'/grade/grading/lib.php');
182 $gradingman = get_grading_manager($context, 'mod_'.$data->modulename);
183 $data->_advancedgradingdata['methods'] = $gradingman->get_available_methods();
184 $areas = $gradingman->get_available_areas();
186 foreach ($areas as $areaname => $areatitle) {
187 $gradingman->set_area($areaname);
188 $method = $gradingman->get_active_method();
189 $data->_advancedgradingdata['areas'][$areaname] = array(
190 'title' => $areatitle,
191 'method' => $method,
193 $formfield = 'advancedgradingmethod_'.$areaname;
194 $data->{$formfield} = $method;
198 if ($items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$data->modulename,
199 'iteminstance'=>$data->instance, 'courseid'=>$course->id))) {
200 // add existing outcomes
201 foreach ($items as $item) {
202 if (!empty($item->outcomeid)) {
203 $data->{'outcome_'.$item->outcomeid} = 1;
207 // set category if present
208 $gradecat = false;
209 foreach ($items as $item) {
210 if ($gradecat === false) {
211 $gradecat = $item->categoryid;
212 continue;
214 if ($gradecat != $item->categoryid) {
215 //mixed categories
216 $gradecat = false;
217 break;
220 if ($gradecat !== false) {
221 // do not set if mixed categories present
222 $data->gradecat = $gradecat;
226 $sectionname = get_section_name($course, $cw);
227 $fullmodulename = get_string('modulename', $module->name);
229 if ($data->section && $course->format != 'site') {
230 $heading = new stdClass();
231 $heading->what = $fullmodulename;
232 $heading->in = $sectionname;
233 $pageheading = get_string('updatingain', 'moodle', $heading);
234 } else {
235 $pageheading = get_string('updatinga', 'moodle', $fullmodulename);
237 $navbaraddition = null;
239 } else {
240 require_login();
241 print_error('invalidaction');
244 $pagepath = 'mod-' . $module->name . '-';
245 if (!empty($type)) { //TODO: hopefully will be removed in 2.0
246 $pagepath .= $type;
247 } else {
248 $pagepath .= 'mod';
250 $PAGE->set_pagetype($pagepath);
251 $PAGE->set_pagelayout('admin');
253 $modmoodleform = "$CFG->dirroot/mod/$module->name/mod_form.php";
254 if (file_exists($modmoodleform)) {
255 require_once($modmoodleform);
256 } else {
257 print_error('noformdesc');
260 $modlib = "$CFG->dirroot/mod/$module->name/lib.php";
261 if (file_exists($modlib)) {
262 include_once($modlib);
263 } else {
264 print_error('modulemissingcode', '', '', $modlib);
267 $mformclassname = 'mod_'.$module->name.'_mod_form';
268 $mform = new $mformclassname($data, $cw->section, $cm, $course);
269 $mform->set_data($data);
271 if ($mform->is_cancelled()) {
272 if ($return && !empty($cm->id)) {
273 redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id");
274 } else {
275 redirect(course_get_url($course, $cw->section, array('sr' => $sectionreturn)));
277 } else if ($fromform = $mform->get_data()) {
278 if (empty($fromform->coursemodule)) {
279 // Add
280 $cm = null;
281 $course = $DB->get_record('course', array('id'=>$fromform->course), '*', MUST_EXIST);
282 $fromform->instance = '';
283 $fromform->coursemodule = '';
284 } else {
285 // Update
286 $cm = get_coursemodule_from_id('', $fromform->coursemodule, 0, false, MUST_EXIST);
287 $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
288 $fromform->instance = $cm->instance;
289 $fromform->coursemodule = $cm->id;
292 if (!empty($fromform->coursemodule)) {
293 $context = context_module::instance($fromform->coursemodule);
294 } else {
295 $context = context_course::instance($course->id);
298 $fromform->course = $course->id;
299 $fromform->modulename = clean_param($fromform->modulename, PARAM_PLUGIN); // For safety
301 $addinstancefunction = $fromform->modulename."_add_instance";
302 $updateinstancefunction = $fromform->modulename."_update_instance";
304 if (!isset($fromform->groupingid)) {
305 $fromform->groupingid = 0;
308 if (!isset($fromform->groupmembersonly)) {
309 $fromform->groupmembersonly = 0;
312 if (!isset($fromform->name)) { //label
313 $fromform->name = $fromform->modulename;
316 if (!isset($fromform->completion)) {
317 $fromform->completion = COMPLETION_DISABLED;
319 if (!isset($fromform->completionview)) {
320 $fromform->completionview = COMPLETION_VIEW_NOT_REQUIRED;
323 // Convert the 'use grade' checkbox into a grade-item number: 0 if
324 // checked, null if not
325 if (isset($fromform->completionusegrade) && $fromform->completionusegrade) {
326 $fromform->completiongradeitemnumber = 0;
327 } else {
328 $fromform->completiongradeitemnumber = null;
331 // the type of event to trigger (mod_created/mod_updated)
332 $eventname = '';
334 if (!empty($fromform->update)) {
336 if (!empty($course->groupmodeforce) or !isset($fromform->groupmode)) {
337 $fromform->groupmode = $cm->groupmode; // keep original
340 // update course module first
341 $cm->groupmode = $fromform->groupmode;
342 $cm->groupingid = $fromform->groupingid;
343 $cm->groupmembersonly = $fromform->groupmembersonly;
345 $completion = new completion_info($course);
346 if ($completion->is_enabled() && !empty($fromform->completionunlocked)) {
347 // Update completion settings
348 $cm->completion = $fromform->completion;
349 $cm->completiongradeitemnumber = $fromform->completiongradeitemnumber;
350 $cm->completionview = $fromform->completionview;
351 $cm->completionexpected = $fromform->completionexpected;
353 if (!empty($CFG->enableavailability)) {
354 $cm->availablefrom = $fromform->availablefrom;
355 $cm->availableuntil = $fromform->availableuntil;
356 $cm->showavailability = $fromform->showavailability;
357 condition_info::update_cm_from_form($cm,$fromform,true);
359 if (isset($fromform->showdescription)) {
360 $cm->showdescription = $fromform->showdescription;
361 } else {
362 $cm->showdescription = 0;
365 $DB->update_record('course_modules', $cm);
367 $modcontext = context_module::instance($fromform->coursemodule);
369 // update embedded links and save files
370 if (plugin_supports('mod', $fromform->modulename, FEATURE_MOD_INTRO, true)) {
371 $fromform->intro = file_save_draft_area_files($fromform->introeditor['itemid'], $modcontext->id,
372 'mod_'.$fromform->modulename, 'intro', 0,
373 array('subdirs'=>true), $fromform->introeditor['text']);
374 $fromform->introformat = $fromform->introeditor['format'];
375 unset($fromform->introeditor);
378 if (!$updateinstancefunction($fromform, $mform)) {
379 print_error('cannotupdatemod', '', course_get_url($course, $cw->section), $fromform->modulename);
382 // make sure visibility is set correctly (in particular in calendar)
383 if (has_capability('moodle/course:activityvisibility', $modcontext)) {
384 set_coursemodule_visible($fromform->coursemodule, $fromform->visible);
387 if (isset($fromform->cmidnumber)) { //label
388 // set cm idnumber - uniqueness is already verified by form validation
389 set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber);
392 // Now that module is fully updated, also update completion data if
393 // required (this will wipe all user completion data and recalculate it)
394 if ($completion->is_enabled() && !empty($fromform->completionunlocked)) {
395 $completion->reset_all_state($cm);
398 $eventname = 'mod_updated';
400 add_to_log($course->id, "course", "update mod",
401 "../mod/$fromform->modulename/view.php?id=$fromform->coursemodule",
402 "$fromform->modulename $fromform->instance");
403 add_to_log($course->id, $fromform->modulename, "update",
404 "view.php?id=$fromform->coursemodule",
405 "$fromform->instance", $fromform->coursemodule);
407 } else if (!empty($fromform->add)) {
409 if (!empty($course->groupmodeforce) or !isset($fromform->groupmode)) {
410 $fromform->groupmode = 0; // do not set groupmode
413 if (!course_allowed_module($course, $fromform->modulename)) {
414 print_error('moduledisable', '', '', $fromform->modulename);
417 // first add course_module record because we need the context
418 $newcm = new stdClass();
419 $newcm->course = $course->id;
420 $newcm->module = $fromform->module;
421 $newcm->instance = 0; // not known yet, will be updated later (this is similar to restore code)
422 $newcm->visible = $fromform->visible;
423 $newcm->visibleold = $fromform->visible;
424 $newcm->groupmode = $fromform->groupmode;
425 $newcm->groupingid = $fromform->groupingid;
426 $newcm->groupmembersonly = $fromform->groupmembersonly;
427 $completion = new completion_info($course);
428 if ($completion->is_enabled()) {
429 $newcm->completion = $fromform->completion;
430 $newcm->completiongradeitemnumber = $fromform->completiongradeitemnumber;
431 $newcm->completionview = $fromform->completionview;
432 $newcm->completionexpected = $fromform->completionexpected;
434 if(!empty($CFG->enableavailability)) {
435 $newcm->availablefrom = $fromform->availablefrom;
436 $newcm->availableuntil = $fromform->availableuntil;
437 $newcm->showavailability = $fromform->showavailability;
439 if (isset($fromform->showdescription)) {
440 $newcm->showdescription = $fromform->showdescription;
441 } else {
442 $newcm->showdescription = 0;
445 if (!$fromform->coursemodule = add_course_module($newcm)) {
446 print_error('cannotaddcoursemodule');
449 if (plugin_supports('mod', $fromform->modulename, FEATURE_MOD_INTRO, true)) {
450 $introeditor = $fromform->introeditor;
451 unset($fromform->introeditor);
452 $fromform->intro = $introeditor['text'];
453 $fromform->introformat = $introeditor['format'];
456 $returnfromfunc = $addinstancefunction($fromform, $mform);
458 if (!$returnfromfunc or !is_number($returnfromfunc)) {
459 // undo everything we can
460 $modcontext = context_module::instance($fromform->coursemodule);
461 delete_context(CONTEXT_MODULE, $fromform->coursemodule);
462 $DB->delete_records('course_modules', array('id'=>$fromform->coursemodule));
464 if (!is_number($returnfromfunc)) {
465 print_error('invalidfunction', '', course_get_url($course, $cw->section));
466 } else {
467 print_error('cannotaddnewmodule', '', course_get_url($course, $cw->section), $fromform->modulename);
471 $fromform->instance = $returnfromfunc;
473 $DB->set_field('course_modules', 'instance', $returnfromfunc, array('id'=>$fromform->coursemodule));
475 // update embedded links and save files
476 $modcontext = context_module::instance($fromform->coursemodule);
477 if (!empty($introeditor)) {
478 $fromform->intro = file_save_draft_area_files($introeditor['itemid'], $modcontext->id,
479 'mod_'.$fromform->modulename, 'intro', 0,
480 array('subdirs'=>true), $introeditor['text']);
481 $DB->set_field($fromform->modulename, 'intro', $fromform->intro, array('id'=>$fromform->instance));
484 // course_modules and course_sections each contain a reference
485 // to each other, so we have to update one of them twice.
486 $sectionid = course_add_cm_to_section($course, $fromform->coursemodule, $fromform->section);
488 // make sure visibility is set correctly (in particular in calendar)
489 // note: allow them to set it even without moodle/course:activityvisibility
490 set_coursemodule_visible($fromform->coursemodule, $fromform->visible);
492 if (isset($fromform->cmidnumber)) { //label
493 // set cm idnumber - uniqueness is already verified by form validation
494 set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber);
497 // Set up conditions
498 if ($CFG->enableavailability) {
499 condition_info::update_cm_from_form((object)array('id'=>$fromform->coursemodule), $fromform, false);
502 $eventname = 'mod_created';
504 add_to_log($course->id, "course", "add mod",
505 "../mod/$fromform->modulename/view.php?id=$fromform->coursemodule",
506 "$fromform->modulename $fromform->instance");
507 add_to_log($course->id, $fromform->modulename, "add",
508 "view.php?id=$fromform->coursemodule",
509 "$fromform->instance", $fromform->coursemodule);
510 } else {
511 print_error('invaliddata');
514 // Trigger mod_created/mod_updated event with information about this module.
515 $eventdata = new stdClass();
516 $eventdata->modulename = $fromform->modulename;
517 $eventdata->name = $fromform->name;
518 $eventdata->cmid = $fromform->coursemodule;
519 $eventdata->courseid = $course->id;
520 $eventdata->userid = $USER->id;
521 events_trigger($eventname, $eventdata);
523 // sync idnumber with grade_item
524 if ($grade_item = grade_item::fetch(array('itemtype'=>'mod', 'itemmodule'=>$fromform->modulename,
525 'iteminstance'=>$fromform->instance, 'itemnumber'=>0, 'courseid'=>$course->id))) {
526 if ($grade_item->idnumber != $fromform->cmidnumber) {
527 $grade_item->idnumber = $fromform->cmidnumber;
528 $grade_item->update();
532 $items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$fromform->modulename,
533 'iteminstance'=>$fromform->instance, 'courseid'=>$course->id));
535 // create parent category if requested and move to correct parent category
536 if ($items and isset($fromform->gradecat)) {
537 if ($fromform->gradecat == -1) {
538 $grade_category = new grade_category();
539 $grade_category->courseid = $course->id;
540 $grade_category->fullname = $fromform->name;
541 $grade_category->insert();
542 if ($grade_item) {
543 $parent = $grade_item->get_parent_category();
544 $grade_category->set_parent($parent->id);
546 $fromform->gradecat = $grade_category->id;
548 foreach ($items as $itemid=>$unused) {
549 $items[$itemid]->set_parent($fromform->gradecat);
550 if ($itemid == $grade_item->id) {
551 // use updated grade_item
552 $grade_item = $items[$itemid];
557 // add outcomes if requested
558 if ($outcomes = grade_outcome::fetch_all_available($course->id)) {
559 $grade_items = array();
561 // Outcome grade_item.itemnumber start at 1000, there is nothing above outcomes
562 $max_itemnumber = 999;
563 if ($items) {
564 foreach($items as $item) {
565 if ($item->itemnumber > $max_itemnumber) {
566 $max_itemnumber = $item->itemnumber;
571 foreach($outcomes as $outcome) {
572 $elname = 'outcome_'.$outcome->id;
574 if (property_exists($fromform, $elname) and $fromform->$elname) {
575 // so we have a request for new outcome grade item?
576 if ($items) {
577 foreach($items as $item) {
578 if ($item->outcomeid == $outcome->id) {
579 //outcome aready exists
580 continue 2;
585 $max_itemnumber++;
587 $outcome_item = new grade_item();
588 $outcome_item->courseid = $course->id;
589 $outcome_item->itemtype = 'mod';
590 $outcome_item->itemmodule = $fromform->modulename;
591 $outcome_item->iteminstance = $fromform->instance;
592 $outcome_item->itemnumber = $max_itemnumber;
593 $outcome_item->itemname = $outcome->fullname;
594 $outcome_item->outcomeid = $outcome->id;
595 $outcome_item->gradetype = GRADE_TYPE_SCALE;
596 $outcome_item->scaleid = $outcome->scaleid;
597 $outcome_item->insert();
599 // move the new outcome into correct category and fix sortorder if needed
600 if ($grade_item) {
601 $outcome_item->set_parent($grade_item->categoryid);
602 $outcome_item->move_after_sortorder($grade_item->sortorder);
604 } else if (isset($fromform->gradecat)) {
605 $outcome_item->set_parent($fromform->gradecat);
611 if (plugin_supports('mod', $fromform->modulename, FEATURE_ADVANCED_GRADING, false)
612 and has_capability('moodle/grade:managegradingforms', $modcontext)) {
613 require_once($CFG->dirroot.'/grade/grading/lib.php');
614 $gradingman = get_grading_manager($modcontext, 'mod_'.$fromform->modulename);
615 $showgradingmanagement = false;
616 foreach ($gradingman->get_available_areas() as $areaname => $aretitle) {
617 $formfield = 'advancedgradingmethod_'.$areaname;
618 if (isset($fromform->{$formfield})) {
619 $gradingman->set_area($areaname);
620 $methodchanged = $gradingman->set_active_method($fromform->{$formfield});
621 if (empty($fromform->{$formfield})) {
622 // going back to the simple direct grading is not a reason
623 // to open the management screen
624 $methodchanged = false;
626 $showgradingmanagement = $showgradingmanagement || $methodchanged;
631 rebuild_course_cache($course->id);
632 grade_regrade_final_grades($course->id);
633 plagiarism_save_form_elements($fromform); //save plagiarism settings
635 if (isset($fromform->submitbutton)) {
636 if (empty($showgradingmanagement)) {
637 redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$fromform->coursemodule");
638 } else {
639 $returnurl = new moodle_url("/mod/$module->name/view.php", array('id' => $fromform->coursemodule));
640 redirect($gradingman->get_management_url($returnurl));
642 } else {
643 redirect(course_get_url($course, $cw->section, array('sr' => $sectionreturn)));
645 exit;
647 } else {
649 $streditinga = get_string('editinga', 'moodle', $fullmodulename);
650 $strmodulenameplural = get_string('modulenameplural', $module->name);
652 if (!empty($cm->id)) {
653 $context = context_module::instance($cm->id);
654 } else {
655 $context = context_course::instance($course->id);
658 $PAGE->set_heading($course->fullname);
659 $PAGE->set_title($streditinga);
660 $PAGE->set_cacheable(false);
662 if (isset($navbaraddition)) {
663 $PAGE->navbar->add($navbaraddition);
666 echo $OUTPUT->header();
668 if (get_string_manager()->string_exists('modulename_help', $module->name)) {
669 echo $OUTPUT->heading_with_help($pageheading, 'modulename', $module->name, 'icon');
670 } else {
671 echo $OUTPUT->heading_with_help($pageheading, '', $module->name, 'icon');
674 $mform->display();
676 echo $OUTPUT->footer();