Merge branch 'MDL-31429_paypal_messages' of git://github.com/andyjdavis/moodle
[moodle.git] / course / modedit.php
blob63ea832c4875f5f5064e5ea4e48040ca2b4638d7
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
39 $url = new moodle_url('/course/modedit.php');
40 if (!empty($return)) {
41 $url->param('return', $return);
44 if (!empty($add)) {
45 $section = required_param('section', PARAM_INT);
46 $course = required_param('course', PARAM_INT);
48 $url->param('add', $add);
49 $url->param('section', $section);
50 $url->param('course', $course);
51 $PAGE->set_url($url);
53 $course = $DB->get_record('course', array('id'=>$course), '*', MUST_EXIST);
54 $module = $DB->get_record('modules', array('name'=>$add), '*', MUST_EXIST);
56 require_login($course);
57 $context = get_context_instance(CONTEXT_COURSE, $course->id);
58 require_capability('moodle/course:manageactivities', $context);
60 $cw = get_course_section($section, $course->id);
62 if (!course_allowed_module($course, $module->name)) {
63 print_error('moduledisable');
66 $cm = null;
68 $data = new stdClass();
69 $data->section = $section; // The section number itself - relative!!! (section column in course_sections)
70 $data->visible = $cw->visible;
71 $data->course = $course->id;
72 $data->module = $module->id;
73 $data->modulename = $module->name;
74 $data->groupmode = $course->groupmode;
75 $data->groupingid = $course->defaultgroupingid;
76 $data->groupmembersonly = 0;
77 $data->id = '';
78 $data->instance = '';
79 $data->coursemodule = '';
80 $data->add = $add;
81 $data->return = 0; //must be false if this is an add, go back to course view on cancel
83 if (plugin_supports('mod', $data->modulename, FEATURE_MOD_INTRO, true)) {
84 $draftid_editor = file_get_submitted_draft_itemid('introeditor');
85 file_prepare_draft_area($draftid_editor, null, null, null, null);
86 $data->introeditor = array('text'=>'', 'format'=>FORMAT_HTML, 'itemid'=>$draftid_editor); // TODO: add better default
89 if (plugin_supports('mod', $data->modulename, FEATURE_ADVANCED_GRADING, false)
90 and has_capability('moodle/grade:managegradingforms', $context)) {
91 require_once($CFG->dirroot.'/grade/grading/lib.php');
93 $data->_advancedgradingdata['methods'] = grading_manager::available_methods();
94 $areas = grading_manager::available_areas('mod_'.$module->name);
96 foreach ($areas as $areaname => $areatitle) {
97 $data->_advancedgradingdata['areas'][$areaname] = array(
98 'title' => $areatitle,
99 'method' => '',
101 $formfield = 'advancedgradingmethod_'.$areaname;
102 $data->{$formfield} = '';
106 if (!empty($type)) { //TODO: hopefully will be removed in 2.0
107 $data->type = $type;
110 $sectionname = get_section_name($course, $cw);
111 $fullmodulename = get_string('modulename', $module->name);
113 if ($data->section && $course->format != 'site') {
114 $heading = new stdClass();
115 $heading->what = $fullmodulename;
116 $heading->to = $sectionname;
117 $pageheading = get_string('addinganewto', 'moodle', $heading);
118 } else {
119 $pageheading = get_string('addinganew', 'moodle', $fullmodulename);
122 } else if (!empty($update)) {
124 $url->param('update', $update);
125 $PAGE->set_url($url);
127 $cm = get_coursemodule_from_id('', $update, 0, false, MUST_EXIST);
128 $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
130 require_login($course, false, $cm); // needed to setup proper $COURSE
131 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
132 require_capability('moodle/course:manageactivities', $context);
134 $module = $DB->get_record('modules', array('id'=>$cm->module), '*', MUST_EXIST);
135 $data = $data = $DB->get_record($module->name, array('id'=>$cm->instance), '*', MUST_EXIST);
136 $cw = $DB->get_record('course_sections', array('id'=>$cm->section), '*', MUST_EXIST);
138 $data->coursemodule = $cm->id;
139 $data->section = $cw->section; // The section number itself - relative!!! (section column in course_sections)
140 $data->visible = $cm->visible; //?? $cw->visible ? $cm->visible : 0; // section hiding overrides
141 $data->cmidnumber = $cm->idnumber; // The cm IDnumber
142 $data->groupmode = groups_get_activity_groupmode($cm); // locked later if forced
143 $data->groupingid = $cm->groupingid;
144 $data->groupmembersonly = $cm->groupmembersonly;
145 $data->course = $course->id;
146 $data->module = $module->id;
147 $data->modulename = $module->name;
148 $data->instance = $cm->instance;
149 $data->return = $return;
150 $data->update = $update;
151 $data->completion = $cm->completion;
152 $data->completionview = $cm->completionview;
153 $data->completionexpected = $cm->completionexpected;
154 $data->completionusegrade = is_null($cm->completiongradeitemnumber) ? 0 : 1;
155 $data->showdescription = $cm->showdescription;
156 if (!empty($CFG->enableavailability)) {
157 $data->availablefrom = $cm->availablefrom;
158 $data->availableuntil = $cm->availableuntil;
159 $data->showavailability = $cm->showavailability;
162 if (plugin_supports('mod', $data->modulename, FEATURE_MOD_INTRO, true)) {
163 $draftid_editor = file_get_submitted_draft_itemid('introeditor');
164 $currentintro = file_prepare_draft_area($draftid_editor, $context->id, 'mod_'.$data->modulename, 'intro', 0, array('subdirs'=>true), $data->intro);
165 $data->introeditor = array('text'=>$currentintro, 'format'=>$data->introformat, 'itemid'=>$draftid_editor);
168 if (plugin_supports('mod', $data->modulename, FEATURE_ADVANCED_GRADING, false)
169 and has_capability('moodle/grade:managegradingforms', $context)) {
170 require_once($CFG->dirroot.'/grade/grading/lib.php');
171 $gradingman = get_grading_manager($context, 'mod_'.$data->modulename);
172 $data->_advancedgradingdata['methods'] = $gradingman->get_available_methods();
173 $areas = $gradingman->get_available_areas();
175 foreach ($areas as $areaname => $areatitle) {
176 $gradingman->set_area($areaname);
177 $method = $gradingman->get_active_method();
178 $data->_advancedgradingdata['areas'][$areaname] = array(
179 'title' => $areatitle,
180 'method' => $method,
182 $formfield = 'advancedgradingmethod_'.$areaname;
183 $data->{$formfield} = $method;
187 if ($items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$data->modulename,
188 'iteminstance'=>$data->instance, 'courseid'=>$course->id))) {
189 // add existing outcomes
190 foreach ($items as $item) {
191 if (!empty($item->outcomeid)) {
192 $data->{'outcome_'.$item->outcomeid} = 1;
196 // set category if present
197 $gradecat = false;
198 foreach ($items as $item) {
199 if ($gradecat === false) {
200 $gradecat = $item->categoryid;
201 continue;
203 if ($gradecat != $item->categoryid) {
204 //mixed categories
205 $gradecat = false;
206 break;
209 if ($gradecat !== false) {
210 // do not set if mixed categories present
211 $data->gradecat = $gradecat;
215 $sectionname = get_section_name($course, $cw);
216 $fullmodulename = get_string('modulename', $module->name);
218 if ($data->section && $course->format != 'site') {
219 $heading = new stdClass();
220 $heading->what = $fullmodulename;
221 $heading->in = $sectionname;
222 $pageheading = get_string('updatingain', 'moodle', $heading);
223 } else {
224 $pageheading = get_string('updatinga', 'moodle', $fullmodulename);
227 } else {
228 require_login();
229 print_error('invalidaction');
232 $pagepath = 'mod-' . $module->name . '-';
233 if (!empty($type)) { //TODO: hopefully will be removed in 2.0
234 $pagepath .= $type;
235 } else {
236 $pagepath .= 'mod';
238 $PAGE->set_pagetype($pagepath);
239 $PAGE->set_pagelayout('admin');
241 $modmoodleform = "$CFG->dirroot/mod/$module->name/mod_form.php";
242 if (file_exists($modmoodleform)) {
243 require_once($modmoodleform);
244 } else {
245 print_error('noformdesc');
248 $modlib = "$CFG->dirroot/mod/$module->name/lib.php";
249 if (file_exists($modlib)) {
250 include_once($modlib);
251 } else {
252 print_error('modulemissingcode', '', '', $modlib);
255 $mformclassname = 'mod_'.$module->name.'_mod_form';
256 $mform = new $mformclassname($data, $cw->section, $cm, $course);
257 $mform->set_data($data);
259 if ($mform->is_cancelled()) {
260 if ($return && !empty($cm->id)) {
261 redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id");
262 } else {
263 redirect("$CFG->wwwroot/course/view.php?id=$course->id#section-".$cw->section);
265 } else if ($fromform = $mform->get_data()) {
266 if (empty($fromform->coursemodule)) {
267 // Add
268 $cm = null;
269 $course = $DB->get_record('course', array('id'=>$fromform->course), '*', MUST_EXIST);
270 $fromform->instance = '';
271 $fromform->coursemodule = '';
272 } else {
273 // Update
274 $cm = get_coursemodule_from_id('', $fromform->coursemodule, 0, false, MUST_EXIST);
275 $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
276 $fromform->instance = $cm->instance;
277 $fromform->coursemodule = $cm->id;
280 if (!empty($fromform->coursemodule)) {
281 $context = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule);
282 } else {
283 $context = get_context_instance(CONTEXT_COURSE, $course->id);
286 $fromform->course = $course->id;
287 $fromform->modulename = clean_param($fromform->modulename, PARAM_PLUGIN); // For safety
289 $addinstancefunction = $fromform->modulename."_add_instance";
290 $updateinstancefunction = $fromform->modulename."_update_instance";
292 if (!isset($fromform->groupingid)) {
293 $fromform->groupingid = 0;
296 if (!isset($fromform->groupmembersonly)) {
297 $fromform->groupmembersonly = 0;
300 if (!isset($fromform->name)) { //label
301 $fromform->name = $fromform->modulename;
304 if (!isset($fromform->completion)) {
305 $fromform->completion = COMPLETION_DISABLED;
307 if (!isset($fromform->completionview)) {
308 $fromform->completionview = COMPLETION_VIEW_NOT_REQUIRED;
311 // Convert the 'use grade' checkbox into a grade-item number: 0 if
312 // checked, null if not
313 if (isset($fromform->completionusegrade) && $fromform->completionusegrade) {
314 $fromform->completiongradeitemnumber = 0;
315 } else {
316 $fromform->completiongradeitemnumber = null;
319 // the type of event to trigger (mod_created/mod_updated)
320 $eventname = '';
322 if (!empty($fromform->update)) {
324 if (!empty($course->groupmodeforce) or !isset($fromform->groupmode)) {
325 $fromform->groupmode = $cm->groupmode; // keep original
328 // update course module first
329 $cm->groupmode = $fromform->groupmode;
330 $cm->groupingid = $fromform->groupingid;
331 $cm->groupmembersonly = $fromform->groupmembersonly;
333 $completion = new completion_info($course);
334 if ($completion->is_enabled()) {
335 // Update completion settings
336 $cm->completion = $fromform->completion;
337 $cm->completiongradeitemnumber = $fromform->completiongradeitemnumber;
338 $cm->completionview = $fromform->completionview;
339 $cm->completionexpected = $fromform->completionexpected;
341 if (!empty($CFG->enableavailability)) {
342 $cm->availablefrom = $fromform->availablefrom;
343 $cm->availableuntil = $fromform->availableuntil;
344 $cm->showavailability = $fromform->showavailability;
345 condition_info::update_cm_from_form($cm,$fromform,true);
347 if (isset($fromform->showdescription)) {
348 $cm->showdescription = $fromform->showdescription;
349 } else {
350 $cm->showdescription = 0;
353 $DB->update_record('course_modules', $cm);
355 $modcontext = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule);
357 // update embedded links and save files
358 if (plugin_supports('mod', $fromform->modulename, FEATURE_MOD_INTRO, true)) {
359 $fromform->intro = file_save_draft_area_files($fromform->introeditor['itemid'], $modcontext->id,
360 'mod_'.$fromform->modulename, 'intro', 0,
361 array('subdirs'=>true), $fromform->introeditor['text']);
362 $fromform->introformat = $fromform->introeditor['format'];
363 unset($fromform->introeditor);
366 if (!$updateinstancefunction($fromform, $mform)) {
367 print_error('cannotupdatemod', '', "view.php?id={$course->id}#section-{$cw->section}", $fromform->modulename);
370 // make sure visibility is set correctly (in particular in calendar)
371 if (has_capability('moodle/course:activityvisibility', $modcontext)) {
372 set_coursemodule_visible($fromform->coursemodule, $fromform->visible);
375 if (isset($fromform->cmidnumber)) { //label
376 // set cm idnumber - uniqueness is already verified by form validation
377 set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber);
380 // Now that module is fully updated, also update completion data if
381 // required (this will wipe all user completion data and recalculate it)
382 if ($completion->is_enabled() && !empty($fromform->completionunlocked)) {
383 $completion->reset_all_state($cm);
386 $eventname = 'mod_updated';
388 add_to_log($course->id, "course", "update mod",
389 "../mod/$fromform->modulename/view.php?id=$fromform->coursemodule",
390 "$fromform->modulename $fromform->instance");
391 add_to_log($course->id, $fromform->modulename, "update",
392 "view.php?id=$fromform->coursemodule",
393 "$fromform->instance", $fromform->coursemodule);
395 } else if (!empty($fromform->add)) {
397 if (!empty($course->groupmodeforce) or !isset($fromform->groupmode)) {
398 $fromform->groupmode = 0; // do not set groupmode
401 if (!course_allowed_module($course, $fromform->modulename)) {
402 print_error('moduledisable', '', '', $fromform->modulename);
405 // first add course_module record because we need the context
406 $newcm = new stdClass();
407 $newcm->course = $course->id;
408 $newcm->module = $fromform->module;
409 $newcm->instance = 0; // not known yet, will be updated later (this is similar to restore code)
410 $newcm->visible = $fromform->visible;
411 $newcm->groupmode = $fromform->groupmode;
412 $newcm->groupingid = $fromform->groupingid;
413 $newcm->groupmembersonly = $fromform->groupmembersonly;
414 $completion = new completion_info($course);
415 if ($completion->is_enabled()) {
416 $newcm->completion = $fromform->completion;
417 $newcm->completiongradeitemnumber = $fromform->completiongradeitemnumber;
418 $newcm->completionview = $fromform->completionview;
419 $newcm->completionexpected = $fromform->completionexpected;
421 if(!empty($CFG->enableavailability)) {
422 $newcm->availablefrom = $fromform->availablefrom;
423 $newcm->availableuntil = $fromform->availableuntil;
424 $newcm->showavailability = $fromform->showavailability;
426 if (isset($fromform->showdescription)) {
427 $newcm->showdescription = $fromform->showdescription;
428 } else {
429 $newcm->showdescription = 0;
432 if (!$fromform->coursemodule = add_course_module($newcm)) {
433 print_error('cannotaddcoursemodule');
436 if (plugin_supports('mod', $fromform->modulename, FEATURE_MOD_INTRO, true)) {
437 $introeditor = $fromform->introeditor;
438 unset($fromform->introeditor);
439 $fromform->intro = $introeditor['text'];
440 $fromform->introformat = $introeditor['format'];
443 $returnfromfunc = $addinstancefunction($fromform, $mform);
445 if (!$returnfromfunc or !is_number($returnfromfunc)) {
446 // undo everything we can
447 $modcontext = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule);
448 delete_context(CONTEXT_MODULE, $fromform->coursemodule);
449 $DB->delete_records('course_modules', array('id'=>$fromform->coursemodule));
451 if (!is_number($returnfromfunc)) {
452 print_error('invalidfunction', '', "view.php?id={$course->id}#section-{$cw->section}");
453 } else {
454 print_error('cannotaddnewmodule', '', "view.php?id={$course->id}#section-{$cw->section}", $fromform->modulename);
458 $fromform->instance = $returnfromfunc;
460 $DB->set_field('course_modules', 'instance', $returnfromfunc, array('id'=>$fromform->coursemodule));
462 // update embedded links and save files
463 $modcontext = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule);
464 if (!empty($introeditor)) {
465 $fromform->intro = file_save_draft_area_files($introeditor['itemid'], $modcontext->id,
466 'mod_'.$fromform->modulename, 'intro', 0,
467 array('subdirs'=>true), $introeditor['text']);
468 $DB->set_field($fromform->modulename, 'intro', $fromform->intro, array('id'=>$fromform->instance));
471 // course_modules and course_sections each contain a reference
472 // to each other, so we have to update one of them twice.
473 $sectionid = add_mod_to_section($fromform);
475 $DB->set_field('course_modules', 'section', $sectionid, array('id'=>$fromform->coursemodule));
477 // make sure visibility is set correctly (in particular in calendar)
478 // note: allow them to set it even without moodle/course:activityvisibility
479 set_coursemodule_visible($fromform->coursemodule, $fromform->visible);
481 if (isset($fromform->cmidnumber)) { //label
482 // set cm idnumber - uniqueness is already verified by form validation
483 set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber);
486 // Set up conditions
487 if ($CFG->enableavailability) {
488 condition_info::update_cm_from_form((object)array('id'=>$fromform->coursemodule), $fromform, false);
491 $eventname = 'mod_created';
493 add_to_log($course->id, "course", "add mod",
494 "../mod/$fromform->modulename/view.php?id=$fromform->coursemodule",
495 "$fromform->modulename $fromform->instance");
496 add_to_log($course->id, $fromform->modulename, "add",
497 "view.php?id=$fromform->coursemodule",
498 "$fromform->instance", $fromform->coursemodule);
499 } else {
500 print_error('invaliddata');
503 // Trigger mod_created/mod_updated event with information about this module.
504 $eventdata = new stdClass();
505 $eventdata->modulename = $fromform->modulename;
506 $eventdata->name = $fromform->name;
507 $eventdata->cmid = $fromform->coursemodule;
508 $eventdata->courseid = $course->id;
509 $eventdata->userid = $USER->id;
510 events_trigger($eventname, $eventdata);
512 // sync idnumber with grade_item
513 if ($grade_item = grade_item::fetch(array('itemtype'=>'mod', 'itemmodule'=>$fromform->modulename,
514 'iteminstance'=>$fromform->instance, 'itemnumber'=>0, 'courseid'=>$course->id))) {
515 if ($grade_item->idnumber != $fromform->cmidnumber) {
516 $grade_item->idnumber = $fromform->cmidnumber;
517 $grade_item->update();
521 $items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$fromform->modulename,
522 'iteminstance'=>$fromform->instance, 'courseid'=>$course->id));
524 // create parent category if requested and move to correct parent category
525 if ($items and isset($fromform->gradecat)) {
526 if ($fromform->gradecat == -1) {
527 $grade_category = new grade_category();
528 $grade_category->courseid = $course->id;
529 $grade_category->fullname = $fromform->name;
530 $grade_category->insert();
531 if ($grade_item) {
532 $parent = $grade_item->get_parent_category();
533 $grade_category->set_parent($parent->id);
535 $fromform->gradecat = $grade_category->id;
537 foreach ($items as $itemid=>$unused) {
538 $items[$itemid]->set_parent($fromform->gradecat);
539 if ($itemid == $grade_item->id) {
540 // use updated grade_item
541 $grade_item = $items[$itemid];
546 // add outcomes if requested
547 if ($outcomes = grade_outcome::fetch_all_available($course->id)) {
548 $grade_items = array();
550 // Outcome grade_item.itemnumber start at 1000, there is nothing above outcomes
551 $max_itemnumber = 999;
552 if ($items) {
553 foreach($items as $item) {
554 if ($item->itemnumber > $max_itemnumber) {
555 $max_itemnumber = $item->itemnumber;
560 foreach($outcomes as $outcome) {
561 $elname = 'outcome_'.$outcome->id;
563 if (property_exists($fromform, $elname) and $fromform->$elname) {
564 // so we have a request for new outcome grade item?
565 if ($items) {
566 foreach($items as $item) {
567 if ($item->outcomeid == $outcome->id) {
568 //outcome aready exists
569 continue 2;
574 $max_itemnumber++;
576 $outcome_item = new grade_item();
577 $outcome_item->courseid = $course->id;
578 $outcome_item->itemtype = 'mod';
579 $outcome_item->itemmodule = $fromform->modulename;
580 $outcome_item->iteminstance = $fromform->instance;
581 $outcome_item->itemnumber = $max_itemnumber;
582 $outcome_item->itemname = $outcome->fullname;
583 $outcome_item->outcomeid = $outcome->id;
584 $outcome_item->gradetype = GRADE_TYPE_SCALE;
585 $outcome_item->scaleid = $outcome->scaleid;
586 $outcome_item->insert();
588 // move the new outcome into correct category and fix sortorder if needed
589 if ($grade_item) {
590 $outcome_item->set_parent($grade_item->categoryid);
591 $outcome_item->move_after_sortorder($grade_item->sortorder);
593 } else if (isset($fromform->gradecat)) {
594 $outcome_item->set_parent($fromform->gradecat);
600 if (plugin_supports('mod', $fromform->modulename, FEATURE_ADVANCED_GRADING, false)
601 and has_capability('moodle/grade:managegradingforms', $modcontext)) {
602 require_once($CFG->dirroot.'/grade/grading/lib.php');
603 $gradingman = get_grading_manager($modcontext, 'mod_'.$fromform->modulename);
604 $showgradingmanagement = false;
605 foreach ($gradingman->get_available_areas() as $areaname => $aretitle) {
606 $formfield = 'advancedgradingmethod_'.$areaname;
607 if (isset($fromform->{$formfield})) {
608 $gradingman->set_area($areaname);
609 $methodchanged = $gradingman->set_active_method($fromform->{$formfield});
610 if (empty($fromform->{$formfield})) {
611 // going back to the simple direct grading is not a reason
612 // to open the management screen
613 $methodchanged = false;
615 $showgradingmanagement = $showgradingmanagement || $methodchanged;
620 rebuild_course_cache($course->id);
621 grade_regrade_final_grades($course->id);
622 plagiarism_save_form_elements($fromform); //save plagiarism settings
624 if (isset($fromform->submitbutton)) {
625 if (empty($showgradingmanagement)) {
626 redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$fromform->coursemodule");
627 } else {
628 $returnurl = new moodle_url("/mod/$module->name/view.php", array('id' => $fromform->coursemodule));
629 redirect($gradingman->get_management_url($returnurl));
631 } else {
632 redirect("$CFG->wwwroot/course/view.php?id={$course->id}#section-{$cw->section}");
634 exit;
636 } else {
638 $streditinga = get_string('editinga', 'moodle', $fullmodulename);
639 $strmodulenameplural = get_string('modulenameplural', $module->name);
641 if (!empty($cm->id)) {
642 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
643 } else {
644 $context = get_context_instance(CONTEXT_COURSE, $course->id);
647 $PAGE->set_heading($course->fullname);
648 $PAGE->set_title($streditinga);
649 $PAGE->set_cacheable(false);
650 echo $OUTPUT->header();
652 if (get_string_manager()->string_exists('modulename_help', $module->name)) {
653 echo $OUTPUT->heading_with_help($pageheading, 'modulename', $module->name, 'icon');
654 } else {
655 echo $OUTPUT->heading_with_help($pageheading, '', $module->name, 'icon');
658 $mform->display();
660 echo $OUTPUT->footer();