MDL-21695 adding support for module help
[moodle.git] / course / modedit.php
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.
14 //
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
20  *
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
24  */
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');
33     $add    = optional_param('add', '', PARAM_ALPHA);     // module name
34     $update = optional_param('update', 0, PARAM_INT);
35     $return = optional_param('return', 0, PARAM_BOOL);    //return to course/view.php if false or mod/modname/view.php if true
36     $type   = optional_param('type', '', PARAM_ALPHANUM); //TODO: hopefully will be removed in 2.0
38     $url = new moodle_url('/course/modedit.php');
39     if (!empty($add)) {
40         $url->param('add', $add);
41     } else if (!empty($update)) {
42         $url->param('update', $update);
43     } else {
44         debugging('Neither add nor update arguments were provided, PAGE->set_url needs to be checked', DEBUG_DEVELOPER);
45     }
46     if (!empty($return)) {
47         $url->param('return', $return);
48     }
49     if (!empty($type)) {
50         $url->param('type', $type);
51     }
52     $PAGE->set_url($url);
54     if (!empty($add)) {
55         $section = required_param('section', PARAM_INT);
56         $course  = required_param('course', PARAM_INT);
58         if (!$course = $DB->get_record('course', array('id'=>$course))) {
59             print_error('invalidcourseid');
60         }
62         require_login($course);
63         $context = get_context_instance(CONTEXT_COURSE, $course->id);
64         require_capability('moodle/course:manageactivities', $context);
66         if (!$module = $DB->get_record('modules', array('name'=>$add))) {
67             print_error('moduledoesnotexist');
68         }
70         $cw = get_course_section($section, $course->id);
72         if (!course_allowed_module($course, $module->id)) {
73             print_error('moduledisable');
74         }
76         $cm = null;
78         $data = new object();
79         $data->section          = $section;  // The section number itself - relative!!! (section column in course_sections)
80         $data->visible          = $cw->visible;
81         $data->course           = $course->id;
82         $data->module           = $module->id;
83         $data->modulename       = $module->name;
84         $data->groupmode        = $course->groupmode;
85         $data->groupingid       = $course->defaultgroupingid;
86         $data->groupmembersonly = 0;
87         $data->id               = '';
88         $data->instance         = '';
89         $data->coursemodule     = '';
90         $data->add              = $add;
91         $data->return           = 0; //must be false if this is an add, go back to course view on cancel
93         if (plugin_supports('mod', $data->modulename, FEATURE_MOD_INTRO, true)) {
94             $draftid_editor = file_get_submitted_draft_itemid('introeditor');
95             file_prepare_draft_area($draftid_editor, null, null, null);
96             $data->introeditor = array('text'=>'', 'format'=>FORMAT_HTML, 'itemid'=>$draftid_editor); // TODO: add better default
97         }
99         if (!empty($type)) { //TODO: hopefully will be removed in 2.0
100             $data->type = $type;
101         }
103         $sectionname = get_section_name($course->format);
104         $fullmodulename = get_string('modulename', $module->name);
106         if ($data->section && $course->format != 'site') {
107             $heading = new object();
108             $heading->what = $fullmodulename;
109             $heading->to   = "$sectionname $data->section";
110             $pageheading = get_string('addinganewto', 'moodle', $heading);
111         } else {
112             $pageheading = get_string('addinganew', 'moodle', $fullmodulename);
113         }
115         $pagepath = 'mod-' . $module->name . '-';
116         if (!empty($type)) { //TODO: hopefully will be removed in 2.0
117             $pagepath .= $type;
118         } else {
119             $pagepath .= 'mod';
120         }
121         $PAGE->set_pagetype($pagepath);
123         $navlinksinstancename = '';
125     } else if (!empty($update)) {
126         if (!$cm = get_coursemodule_from_id('', $update, 0)) {
127             print_error('invalidcoursemodule');
128         }
130         if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
131             print_error('invalidcourseid');
132         }
134         require_login($course, false, $cm); // needed to setup proper $COURSE
135         $context = get_context_instance(CONTEXT_MODULE, $cm->id);
136         require_capability('moodle/course:manageactivities', $context);
138         if (!$module = $DB->get_record('modules', array('id'=>$cm->module))) {
139             print_error('moduledoesnotexist');
140         }
142         if (!$data = $DB->get_record($module->name, array('id'=>$cm->instance))) {
143             print_error('moduleinstancedoesnotexist');
144         }
146         if (!$cw = $DB->get_record('course_sections', array('id'=>$cm->section))) {
147             print_error('sectionnotexist');
148         }
150         $data->coursemodule       = $cm->id;
151         $data->section            = $cw->section;  // The section number itself - relative!!! (section column in course_sections)
152         $data->visible            = $cm->visible; //??  $cw->visible ? $cm->visible : 0; // section hiding overrides
153         $data->cmidnumber         = $cm->idnumber;          // The cm IDnumber
154         $data->groupmode          = groups_get_activity_groupmode($cm); // locked later if forced
155         $data->groupingid         = $cm->groupingid;
156         $data->groupmembersonly   = $cm->groupmembersonly;
157         $data->course             = $course->id;
158         $data->module             = $module->id;
159         $data->modulename         = $module->name;
160         $data->instance           = $cm->instance;
161         $data->return             = $return;
162         $data->update             = $update;
163         $data->completion         = $cm->completion;
164         $data->completionview     = $cm->completionview;
165         $data->completionexpected = $cm->completionexpected;
166         $data->completionusegrade = is_null($cm->completiongradeitemnumber) ? 0 : 1;
167         if (!empty($CFG->enableavailability)) {
168             $data->availablefrom      = $cm->availablefrom;
169             $data->availableuntil     = $cm->availableuntil;
170             $data->showavailability   = $cm->showavailability;
171         }
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, $data->modulename.'_intro', 0, array('subdirs'=>true), $data->intro);
176             $data->introeditor = array('text'=>$currentintro, 'format'=>$data->introformat, 'itemid'=>$draftid_editor);
177         }
179         if ($items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$data->modulename,
180                                                  'iteminstance'=>$data->instance, 'courseid'=>$course->id))) {
181             // add existing outcomes
182             foreach ($items as $item) {
183                 if (!empty($item->outcomeid)) {
184                     $data->{'outcome_'.$item->outcomeid} = 1;
185                 }
186             }
188             // set category if present
189             $gradecat = false;
190             foreach ($items as $item) {
191                 if ($gradecat === false) {
192                     $gradecat = $item->categoryid;
193                     continue;
194                 }
195                 if ($gradecat != $item->categoryid) {
196                     //mixed categories
197                     $gradecat = false;
198                     break;
199                 }
200             }
201             if ($gradecat !== false) {
202                 // do not set if mixed categories present
203                 $data->gradecat = $gradecat;
204             }
205         }
207         $sectionname = get_section_name($course->format);
208         $fullmodulename = get_string('modulename', $module->name);
210         if ($data->section && $course->format != 'site') {
211             $heading = new object();
212             $heading->what = $fullmodulename;
213             $heading->in   = "$sectionname $cw->section";
214             $pageheading = get_string('updatingain', 'moodle', $heading);
215         } else {
216             $pageheading = get_string('updatinga', 'moodle', $fullmodulename);
217         }
219         $navlinksinstancename = array('name' => format_string($data->name, true), 'link' => "$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id", 'type' => 'activityinstance');
221         $pagetype = 'mod-' . $module->name . '-';
222         if (!empty($type)) {
223             $pagetype .= $type;
224         } else {
225             $pagetype .= 'mod';
226         }
227         $PAGE->set_pagetype($pagetype);
228     } else {
229         require_login();
230         print_error('invalidaction');
231     }
233     $modmoodleform = "$CFG->dirroot/mod/$module->name/mod_form.php";
234     if (file_exists($modmoodleform)) {
235         require_once($modmoodleform);
237     } else {
238         print_error('noformdesc');
239     }
241     $modlib = "$CFG->dirroot/mod/$module->name/lib.php";
242     if (file_exists($modlib)) {
243         include_once($modlib);
244     } else {
245         print_error('modulemissingcode', '', '', $modlib);
246     }
248     $mformclassname = 'mod_'.$module->name.'_mod_form';
249     $mform = new $mformclassname($data, $cw->section, $cm, $course);
250     $mform->set_data($data);
252     if ($mform->is_cancelled()) {
253         if ($return && !empty($cm->id)) {
254             redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id");
255         } else {
256             redirect("$CFG->wwwroot/course/view.php?id=$course->id#section-".$cw->section);
257         }
259     } else if ($fromform = $mform->get_data()) {
260         if (empty($fromform->coursemodule)) { //add
261             $cm = null;
262             if (!$course = $DB->get_record('course', array('id'=>$fromform->course))) {
263                 print_error('invalidcourseid');
264             }
265             $fromform->instance     = '';
266             $fromform->coursemodule = '';
267         } else { //update
268             if (!$cm = get_coursemodule_from_id('', $fromform->coursemodule, 0)) {
269                 print_error('invalidcoursemodule');
270             }
272             if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
273                 print_error('invalidcourseid');
274             }
275             $fromform->instance     = $cm->instance;
276             $fromform->coursemodule = $cm->id;
277         }
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);
284         }
286         $fromform->course = $course->id;
287         $fromform->modulename = clean_param($fromform->modulename, PARAM_SAFEDIR);  // For safety
289         $addinstancefunction    = $fromform->modulename."_add_instance";
290         $updateinstancefunction = $fromform->modulename."_update_instance";
292         if (!isset($fromform->groupingid)) {
293             $fromform->groupingid = 0;
294         }
296         if (!isset($fromform->groupmembersonly)) {
297             $fromform->groupmembersonly = 0;
298         }
300         if (!isset($fromform->name)) { //label
301             $fromform->name = $fromform->modulename;
302         }
304         if (!isset($fromform->completion)) {
305             $fromform->completion = COMPLETION_DISABLED;
306         }
307         if (!isset($fromform->completionview)) {
308             $fromform->completionview = COMPLETION_VIEW_NOT_REQUIRED;
309         }
311         // Convert the 'use grade' checkbox into a grade-item number: 0 if
312         // checked, null if not
313         $fromform->completiongradeitemnumber =
314             isset($fromform->completionusegrade) && $fromform->completionusegrade
315             ? 0 : null;
317         if (!empty($fromform->update)) {
319             if (!empty($course->groupmodeforce) or !isset($fromform->groupmode)) {
320                 $fromform->groupmode = $cm->groupmode; // keep original
321             }
323             // update course module first
324             $cm->groupmode        = $fromform->groupmode;
325             $cm->groupingid       = $fromform->groupingid;
326             $cm->groupmembersonly = $fromform->groupmembersonly;
328             $completion = new completion_info($course);
329             if ($completion->is_enabled()) {
330                 // Handle completion settings. If necessary, wipe existing completion
331                 // data first.
332                 if (!empty($fromform->completionunlocked)) {
333                     $completion = new completion_info($course);
334                     $completion->reset_all_state($cm);
335                 }
337                 $cm->completion                = $fromform->completion;
338                 $cm->completiongradeitemnumber = $fromform->completiongradeitemnumber;
339                 $cm->completionview            = $fromform->completionview;
340                 $cm->completionexpected        = $fromform->completionexpected;
341             }
342             if (!empty($CFG->enableavailability)) {
343                 $cm->availablefrom             = $fromform->availablefrom;
344                 $cm->availableuntil            = $fromform->availableuntil;
345                 // The form time is midnight, but because we want it to be
346                 // inclusive, set it to 23:59:59 on that day.
347                 if ($cm->availableuntil) {
348                     $cm->availableuntil = strtotime('23:59:59',
349                         $cm->availableuntil);
350                 }
351                 $cm->showavailability          = $fromform->showavailability;
352                 condition_info::update_cm_from_form($cm,$fromform,true);
353             }
355             $DB->update_record('course_modules', $cm);
357             $modcontext = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule);
359             // update embedded links and save files
360             if (plugin_supports('mod', $fromform->modulename, FEATURE_MOD_INTRO, true)) {
361                 $fromform->intro = file_save_draft_area_files($fromform->introeditor['itemid'], $modcontext->id,
362                                                               $fromform->modulename.'_intro', 0,
363                                                               array('subdirs'=>true), $fromform->introeditor['text']);
364                 $fromform->introformat = $fromform->introeditor['format'];
365                 unset($fromform->introeditor);
366             }
368             if (!$updateinstancefunction($fromform, $mform)) {
369                 print_error('cannotupdatemod', '', 'view.php?id=$course->id', $fromform->modulename);
370             }
372             // make sure visibility is set correctly (in particular in calendar)
373             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);
378             }
379             //trigger event with information about this module.
380             $eventdata = new object();
381             $eventdata->component = 'mod/'.$fromform->modulename;
382             $eventdata->course    = $course->id;
383             $eventdata->cm        = $fromform->coursemodule;
384             events_trigger($fromform->modulename.'_mod_updated', $eventdata);
386             add_to_log($course->id, "course", "update mod",
387                        "../mod/$fromform->modulename/view.php?id=$fromform->coursemodule",
388                        "$fromform->modulename $fromform->instance");
389             add_to_log($course->id, $fromform->modulename, "update",
390                        "view.php?id=$fromform->coursemodule",
391                        "$fromform->instance", $fromform->coursemodule);
393         } else if (!empty($fromform->add)) {
395             if (!empty($course->groupmodeforce) or !isset($fromform->groupmode)) {
396                 $fromform->groupmode = 0; // do not set groupmode
397             }
399             if (!course_allowed_module($course, $fromform->modulename)) {
400                 print_error('moduledisable', '', '', $fromform->modulename);
401             }
403             // first add course_module record because we need the context
404             $newcm = new object();
405             $newcm->course           = $course->id;
406             $newcm->module           = $fromform->module;
407             $newcm->instance         = 0; // not known yet, will be updated later (this is similar to restore code)
408             $newcm->visible          = $fromform->visible;
409             $newcm->groupmode        = $fromform->groupmode;
410             $newcm->groupingid       = $fromform->groupingid;
411             $newcm->groupmembersonly = $fromform->groupmembersonly;
412             $completion = new completion_info($course);
413             if ($completion->is_enabled()) {
414                 $newcm->completion                = $fromform->completion;
415                 $newcm->completiongradeitemnumber = $fromform->completiongradeitemnumber;
416                 $newcm->completionview            = $fromform->completionview;
417                 $newcm->completionexpected        = $fromform->completionexpected;
418             }
419             if(!empty($CFG->enableavailability)) {
420                 $newcm->availablefrom             = $fromform->availablefrom;
421                 $newcm->availableuntil            = $fromform->availableuntil;
422                 // The form time is midnight, but because we want it to be
423                 // inclusive, set it to 23:59:59 on that day.
424                 if ($newcm->availableuntil) {
425                     $newcm->availableuntil = strtotime('23:59:59',
426                         $newcm->availableuntil);
427                 }
428                 $newcm->showavailability          = $fromform->showavailability;
429             }
431             if (!$fromform->coursemodule = add_course_module($newcm)) {
432                 print_error('cannotaddcoursemodule');
433             }
435             if (plugin_supports('mod', $fromform->modulename, FEATURE_MOD_INTRO, false)) {
436                 $introeditor = $fromform->introeditor;
437                 unset($fromform->introeditor);
438                 $fromform->intro       = $introeditor['text'];
439                 $fromform->introformat = $introeditor['format'];
440             }
442             $returnfromfunc = $addinstancefunction($fromform, $mform);
444             if (!$returnfromfunc or !is_number($returnfromfunc)) {
445                 // undo everything we can
446                 $modcontext = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule);
447                 delete_context(CONTEXT_MODULE, $fromform->coursemodule);
448                 $DB->delete_records('course_modules', array('id'=>$fromform->coursemodule));
450                 if (!is_number($returnfromfunc)) {
451                     print_error('invalidfunction', '', 'view.php?id=$course->id');
452                 } else {
453                     print_error('cannotaddnewmodule', '', "view.php?id=$course->id", $fromform->modulename);
454                 }
455             }
457             $fromform->instance = $returnfromfunc;
459             $DB->set_field('course_modules', 'instance', $returnfromfunc, array('id'=>$fromform->coursemodule));
461             // update embedded links and save files
462             $modcontext = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule);
463             if (plugin_supports('mod', $fromform->modulename, FEATURE_MOD_INTRO, true)) {
464                 $fromform->intro = file_save_draft_area_files($introeditor['itemid'], $modcontext->id,
465                                                               $fromform->modulename.'_intro', 0,
466                                                               array('subdirs'=>true), $introeditor['text']);
467                 $DB->set_field($fromform->modulename, 'intro', $fromform->intro, array('id'=>$fromform->instance));
468             }
470             // course_modules and course_sections each contain a reference
471             // to each other, so we have to update one of them twice.
472             $sectionid = add_mod_to_section($fromform);
474             $DB->set_field('course_modules', 'section', $sectionid, array('id'=>$fromform->coursemodule));
476             // make sure visibility is set correctly (in particular in calendar)
477             set_coursemodule_visible($fromform->coursemodule, $fromform->visible);
479             if (isset($fromform->cmidnumber)) { //label
480                 // set cm idnumber - uniqueness is already verified by form validation
481                 set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber);
482             }
484             // Set up conditions
485             if ($CFG->enableavailability) {
486                 condition_info::update_cm_from_form((object)array('id'=>$fromform->coursemodule), $fromform, false);
487             }
488             //trigger event with information about this module.
489             $eventdata = new object();
490             $eventdata->component = 'mod/'.$fromform->modulename;
491             $eventdata->course    = $course->id;
492             $eventdata->cm        = $fromform->coursemodule;
493             events_trigger($fromform->modulename.'_mod_created', $eventdata);
495             add_to_log($course->id, "course", "add mod",
496                        "../mod/$fromform->modulename/view.php?id=$fromform->coursemodule",
497                        "$fromform->modulename $fromform->instance");
498             add_to_log($course->id, $fromform->modulename, "add",
499                        "view.php?id=$fromform->coursemodule",
500                        "$fromform->instance", $fromform->coursemodule);
501         } else {
502             print_error('invaliddata');
503         }
505         // sync idnumber with grade_item
506         if ($grade_item = grade_item::fetch(array('itemtype'=>'mod', 'itemmodule'=>$fromform->modulename,
507                      'iteminstance'=>$fromform->instance, 'itemnumber'=>0, 'courseid'=>$course->id))) {
508             if ($grade_item->idnumber != $fromform->cmidnumber) {
509                 $grade_item->idnumber = $fromform->cmidnumber;
510                 $grade_item->update();
511             }
512         }
514         $items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$fromform->modulename,
515                                              'iteminstance'=>$fromform->instance, 'courseid'=>$course->id));
517         // create parent category if requested and move to correct parent category
518         if ($items and isset($fromform->gradecat)) {
519             if ($fromform->gradecat == -1) {
520                 $grade_category = new grade_category();
521                 $grade_category->courseid = $course->id;
522                 $grade_category->fullname = $fromform->name;
523                 $grade_category->insert();
524                 if ($grade_item) {
525                     $parent = $grade_item->get_parent_category();
526                     $grade_category->set_parent($parent->id);
527                 }
528                 $fromform->gradecat = $grade_category->id;
529             }
530             foreach ($items as $itemid=>$unused) {
531                 $items[$itemid]->set_parent($fromform->gradecat);
532                 if ($itemid == $grade_item->id) {
533                     // use updated grade_item
534                     $grade_item = $items[$itemid];
535                 }
536             }
537         }
539         // add outcomes if requested
540         if ($outcomes = grade_outcome::fetch_all_available($course->id)) {
541             $grade_items = array();
543             // Outcome grade_item.itemnumber start at 1000, there is nothing above outcomes
544             $max_itemnumber = 999;
545             if ($items) {
546                 foreach($items as $item) {
547                     if ($item->itemnumber > $max_itemnumber) {
548                         $max_itemnumber = $item->itemnumber;
549                     }
550                 }
551             }
553             foreach($outcomes as $outcome) {
554                 $elname = 'outcome_'.$outcome->id;
556                 if (array_key_exists($elname, $fromform) and $fromform->$elname) {
557                     // so we have a request for new outcome grade item?
558                     if ($items) {
559                         foreach($items as $item) {
560                             if ($item->outcomeid == $outcome->id) {
561                                 //outcome aready exists
562                                 continue 2;
563                             }
564                         }
565                     }
567                     $max_itemnumber++;
569                     $outcome_item = new grade_item();
570                     $outcome_item->courseid     = $course->id;
571                     $outcome_item->itemtype     = 'mod';
572                     $outcome_item->itemmodule   = $fromform->modulename;
573                     $outcome_item->iteminstance = $fromform->instance;
574                     $outcome_item->itemnumber   = $max_itemnumber;
575                     $outcome_item->itemname     = $outcome->fullname;
576                     $outcome_item->outcomeid    = $outcome->id;
577                     $outcome_item->gradetype    = GRADE_TYPE_SCALE;
578                     $outcome_item->scaleid      = $outcome->scaleid;
579                     $outcome_item->insert();
581                     // move the new outcome into correct category and fix sortorder if needed
582                     if ($grade_item) {
583                         $outcome_item->set_parent($grade_item->categoryid);
584                         $outcome_item->move_after_sortorder($grade_item->sortorder);
586                     } else if (isset($fromform->gradecat)) {
587                         $outcome_item->set_parent($fromform->gradecat);
588                     }
589                 }
590             }
591         }
593         rebuild_course_cache($course->id);
594         grade_regrade_final_grades($course->id);
596         if (isset($fromform->submitbutton)) {
597             redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$fromform->coursemodule");
598         } else {
599             redirect("$CFG->wwwroot/course/view.php?id=$course->id");
600         }
601         exit;
603     } else {
604         if (!empty($cm->id)) {
605             $context = get_context_instance(CONTEXT_MODULE, $cm->id);
606         } else {
607             $context = get_context_instance(CONTEXT_COURSE, $course->id);
608         }
610         $streditinga = get_string('editinga', 'moodle', $fullmodulename);
611         $strmodulenameplural = get_string('modulenameplural', $module->name);
613         $PAGE->navbar->add($streditinga);
614         $PAGE->set_heading($course->fullname);
615         $PAGE->set_title($streditinga);
616         $PAGE->set_focuscontrol($mform->focus());
617         $PAGE->set_cacheable(false);
618         $PAGE->set_pagelayout('admin');
619         echo $OUTPUT->header();
621         if (!empty($cm->id)) {
622             $context = get_context_instance(CONTEXT_MODULE, $cm->id);
623             $overridableroles = get_overridable_roles($context);
624             $assignableroles  = get_assignable_roles($context);
625             $currenttab = 'update';
626             require($CFG->dirroot.'/'.$CFG->admin.'/roles/tabs.php');
627         }
629         if (get_string_manager()->string_exists('modulename_hlp', $module->name)) {
630             echo $OUTPUT->heading_with_help($pageheading, 'modulename', $module->name, 'icon');
631         } else {
632             echo $OUTPUT->heading_with_help($pageheading, '', '', 'icon');
633         }
635         $mform->display();
637         echo $OUTPUT->footer();
638     }