|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00026 require_once("../config.php"); 00027 require_once("lib.php"); 00028 require_once($CFG->libdir.'/filelib.php'); 00029 require_once($CFG->libdir.'/gradelib.php'); 00030 require_once($CFG->libdir.'/completionlib.php'); 00031 require_once($CFG->libdir.'/conditionlib.php'); 00032 require_once($CFG->libdir.'/plagiarismlib.php'); 00033 00034 $add = optional_param('add', '', PARAM_ALPHA); // module name 00035 $update = optional_param('update', 0, PARAM_INT); 00036 $return = optional_param('return', 0, PARAM_BOOL); //return to course/view.php if false or mod/modname/view.php if true 00037 $type = optional_param('type', '', PARAM_ALPHANUM); //TODO: hopefully will be removed in 2.0 00038 00039 $url = new moodle_url('/course/modedit.php'); 00040 if (!empty($return)) { 00041 $url->param('return', $return); 00042 } 00043 00044 if (!empty($add)) { 00045 $section = required_param('section', PARAM_INT); 00046 $course = required_param('course', PARAM_INT); 00047 00048 $url->param('add', $add); 00049 $url->param('section', $section); 00050 $url->param('course', $course); 00051 $PAGE->set_url($url); 00052 00053 $course = $DB->get_record('course', array('id'=>$course), '*', MUST_EXIST); 00054 $module = $DB->get_record('modules', array('name'=>$add), '*', MUST_EXIST); 00055 00056 require_login($course); 00057 $context = get_context_instance(CONTEXT_COURSE, $course->id); 00058 require_capability('moodle/course:manageactivities', $context); 00059 00060 $cw = get_course_section($section, $course->id); 00061 00062 if (!course_allowed_module($course, $module->id)) { 00063 print_error('moduledisable'); 00064 } 00065 00066 $cm = null; 00067 00068 $data = new stdClass(); 00069 $data->section = $section; // The section number itself - relative!!! (section column in course_sections) 00070 $data->visible = $cw->visible; 00071 $data->course = $course->id; 00072 $data->module = $module->id; 00073 $data->modulename = $module->name; 00074 $data->groupmode = $course->groupmode; 00075 $data->groupingid = $course->defaultgroupingid; 00076 $data->groupmembersonly = 0; 00077 $data->id = ''; 00078 $data->instance = ''; 00079 $data->coursemodule = ''; 00080 $data->add = $add; 00081 $data->return = 0; //must be false if this is an add, go back to course view on cancel 00082 00083 if (plugin_supports('mod', $data->modulename, FEATURE_MOD_INTRO, true)) { 00084 $draftid_editor = file_get_submitted_draft_itemid('introeditor'); 00085 file_prepare_draft_area($draftid_editor, null, null, null, null); 00086 $data->introeditor = array('text'=>'', 'format'=>FORMAT_HTML, 'itemid'=>$draftid_editor); // TODO: add better default 00087 } 00088 00089 if (plugin_supports('mod', $data->modulename, FEATURE_ADVANCED_GRADING, false) 00090 and has_capability('moodle/grade:managegradingforms', $context)) { 00091 require_once($CFG->dirroot.'/grade/grading/lib.php'); 00092 00093 $data->_advancedgradingdata['methods'] = grading_manager::available_methods(); 00094 $areas = grading_manager::available_areas('mod_'.$module->name); 00095 00096 foreach ($areas as $areaname => $areatitle) { 00097 $data->_advancedgradingdata['areas'][$areaname] = array( 00098 'title' => $areatitle, 00099 'method' => '', 00100 ); 00101 $formfield = 'advancedgradingmethod_'.$areaname; 00102 $data->{$formfield} = ''; 00103 } 00104 } 00105 00106 if (!empty($type)) { //TODO: hopefully will be removed in 2.0 00107 $data->type = $type; 00108 } 00109 00110 $sectionname = get_section_name($course, $cw); 00111 $fullmodulename = get_string('modulename', $module->name); 00112 00113 if ($data->section && $course->format != 'site') { 00114 $heading = new stdClass(); 00115 $heading->what = $fullmodulename; 00116 $heading->to = $sectionname; 00117 $pageheading = get_string('addinganewto', 'moodle', $heading); 00118 } else { 00119 $pageheading = get_string('addinganew', 'moodle', $fullmodulename); 00120 } 00121 00122 } else if (!empty($update)) { 00123 00124 $url->param('update', $update); 00125 $PAGE->set_url($url); 00126 00127 $cm = get_coursemodule_from_id('', $update, 0, false, MUST_EXIST); 00128 $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST); 00129 00130 require_login($course, false, $cm); // needed to setup proper $COURSE 00131 $context = get_context_instance(CONTEXT_MODULE, $cm->id); 00132 require_capability('moodle/course:manageactivities', $context); 00133 00134 $module = $DB->get_record('modules', array('id'=>$cm->module), '*', MUST_EXIST); 00135 $data = $data = $DB->get_record($module->name, array('id'=>$cm->instance), '*', MUST_EXIST); 00136 $cw = $DB->get_record('course_sections', array('id'=>$cm->section), '*', MUST_EXIST); 00137 00138 $data->coursemodule = $cm->id; 00139 $data->section = $cw->section; // The section number itself - relative!!! (section column in course_sections) 00140 $data->visible = $cm->visible; //?? $cw->visible ? $cm->visible : 0; // section hiding overrides 00141 $data->cmidnumber = $cm->idnumber; // The cm IDnumber 00142 $data->groupmode = groups_get_activity_groupmode($cm); // locked later if forced 00143 $data->groupingid = $cm->groupingid; 00144 $data->groupmembersonly = $cm->groupmembersonly; 00145 $data->course = $course->id; 00146 $data->module = $module->id; 00147 $data->modulename = $module->name; 00148 $data->instance = $cm->instance; 00149 $data->return = $return; 00150 $data->update = $update; 00151 $data->completion = $cm->completion; 00152 $data->completionview = $cm->completionview; 00153 $data->completionexpected = $cm->completionexpected; 00154 $data->completionusegrade = is_null($cm->completiongradeitemnumber) ? 0 : 1; 00155 $data->showdescription = $cm->showdescription; 00156 if (!empty($CFG->enableavailability)) { 00157 $data->availablefrom = $cm->availablefrom; 00158 $data->availableuntil = $cm->availableuntil; 00159 $data->showavailability = $cm->showavailability; 00160 } 00161 00162 if (plugin_supports('mod', $data->modulename, FEATURE_MOD_INTRO, true)) { 00163 $draftid_editor = file_get_submitted_draft_itemid('introeditor'); 00164 $currentintro = file_prepare_draft_area($draftid_editor, $context->id, 'mod_'.$data->modulename, 'intro', 0, array('subdirs'=>true), $data->intro); 00165 $data->introeditor = array('text'=>$currentintro, 'format'=>$data->introformat, 'itemid'=>$draftid_editor); 00166 } 00167 00168 if (plugin_supports('mod', $data->modulename, FEATURE_ADVANCED_GRADING, false) 00169 and has_capability('moodle/grade:managegradingforms', $context)) { 00170 require_once($CFG->dirroot.'/grade/grading/lib.php'); 00171 $gradingman = get_grading_manager($context, 'mod_'.$data->modulename); 00172 $data->_advancedgradingdata['methods'] = $gradingman->get_available_methods(); 00173 $areas = $gradingman->get_available_areas(); 00174 00175 foreach ($areas as $areaname => $areatitle) { 00176 $gradingman->set_area($areaname); 00177 $method = $gradingman->get_active_method(); 00178 $data->_advancedgradingdata['areas'][$areaname] = array( 00179 'title' => $areatitle, 00180 'method' => $method, 00181 ); 00182 $formfield = 'advancedgradingmethod_'.$areaname; 00183 $data->{$formfield} = $method; 00184 } 00185 } 00186 00187 if ($items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$data->modulename, 00188 'iteminstance'=>$data->instance, 'courseid'=>$course->id))) { 00189 // add existing outcomes 00190 foreach ($items as $item) { 00191 if (!empty($item->outcomeid)) { 00192 $data->{'outcome_'.$item->outcomeid} = 1; 00193 } 00194 } 00195 00196 // set category if present 00197 $gradecat = false; 00198 foreach ($items as $item) { 00199 if ($gradecat === false) { 00200 $gradecat = $item->categoryid; 00201 continue; 00202 } 00203 if ($gradecat != $item->categoryid) { 00204 //mixed categories 00205 $gradecat = false; 00206 break; 00207 } 00208 } 00209 if ($gradecat !== false) { 00210 // do not set if mixed categories present 00211 $data->gradecat = $gradecat; 00212 } 00213 } 00214 00215 $sectionname = get_section_name($course, $cw); 00216 $fullmodulename = get_string('modulename', $module->name); 00217 00218 if ($data->section && $course->format != 'site') { 00219 $heading = new stdClass(); 00220 $heading->what = $fullmodulename; 00221 $heading->in = $sectionname; 00222 $pageheading = get_string('updatingain', 'moodle', $heading); 00223 } else { 00224 $pageheading = get_string('updatinga', 'moodle', $fullmodulename); 00225 } 00226 00227 } else { 00228 require_login(); 00229 print_error('invalidaction'); 00230 } 00231 00232 $pagepath = 'mod-' . $module->name . '-'; 00233 if (!empty($type)) { //TODO: hopefully will be removed in 2.0 00234 $pagepath .= $type; 00235 } else { 00236 $pagepath .= 'mod'; 00237 } 00238 $PAGE->set_pagetype($pagepath); 00239 $PAGE->set_pagelayout('admin'); 00240 00241 $modmoodleform = "$CFG->dirroot/mod/$module->name/mod_form.php"; 00242 if (file_exists($modmoodleform)) { 00243 require_once($modmoodleform); 00244 } else { 00245 print_error('noformdesc'); 00246 } 00247 00248 $modlib = "$CFG->dirroot/mod/$module->name/lib.php"; 00249 if (file_exists($modlib)) { 00250 include_once($modlib); 00251 } else { 00252 print_error('modulemissingcode', '', '', $modlib); 00253 } 00254 00255 $mformclassname = 'mod_'.$module->name.'_mod_form'; 00256 $mform = new $mformclassname($data, $cw->section, $cm, $course); 00257 $mform->set_data($data); 00258 00259 if ($mform->is_cancelled()) { 00260 if ($return && !empty($cm->id)) { 00261 redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id"); 00262 } else { 00263 redirect("$CFG->wwwroot/course/view.php?id=$course->id#section-".$cw->section); 00264 } 00265 } else if ($fromform = $mform->get_data()) { 00266 if (empty($fromform->coursemodule)) { 00267 // Add 00268 $cm = null; 00269 $course = $DB->get_record('course', array('id'=>$fromform->course), '*', MUST_EXIST); 00270 $fromform->instance = ''; 00271 $fromform->coursemodule = ''; 00272 } else { 00273 // Update 00274 $cm = get_coursemodule_from_id('', $fromform->coursemodule, 0, false, MUST_EXIST); 00275 $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST); 00276 $fromform->instance = $cm->instance; 00277 $fromform->coursemodule = $cm->id; 00278 } 00279 00280 if (!empty($fromform->coursemodule)) { 00281 $context = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule); 00282 } else { 00283 $context = get_context_instance(CONTEXT_COURSE, $course->id); 00284 } 00285 00286 $fromform->course = $course->id; 00287 $fromform->modulename = clean_param($fromform->modulename, PARAM_PLUGIN); // For safety 00288 00289 $addinstancefunction = $fromform->modulename."_add_instance"; 00290 $updateinstancefunction = $fromform->modulename."_update_instance"; 00291 00292 if (!isset($fromform->groupingid)) { 00293 $fromform->groupingid = 0; 00294 } 00295 00296 if (!isset($fromform->groupmembersonly)) { 00297 $fromform->groupmembersonly = 0; 00298 } 00299 00300 if (!isset($fromform->name)) { //label 00301 $fromform->name = $fromform->modulename; 00302 } 00303 00304 if (!isset($fromform->completion)) { 00305 $fromform->completion = COMPLETION_DISABLED; 00306 } 00307 if (!isset($fromform->completionview)) { 00308 $fromform->completionview = COMPLETION_VIEW_NOT_REQUIRED; 00309 } 00310 00311 // Convert the 'use grade' checkbox into a grade-item number: 0 if 00312 // checked, null if not 00313 if (isset($fromform->completionusegrade) && $fromform->completionusegrade) { 00314 $fromform->completiongradeitemnumber = 0; 00315 } else { 00316 $fromform->completiongradeitemnumber = null; 00317 } 00318 00319 // the type of event to trigger (mod_created/mod_updated) 00320 $eventname = ''; 00321 00322 if (!empty($fromform->update)) { 00323 00324 if (!empty($course->groupmodeforce) or !isset($fromform->groupmode)) { 00325 $fromform->groupmode = $cm->groupmode; // keep original 00326 } 00327 00328 // update course module first 00329 $cm->groupmode = $fromform->groupmode; 00330 $cm->groupingid = $fromform->groupingid; 00331 $cm->groupmembersonly = $fromform->groupmembersonly; 00332 00333 $completion = new completion_info($course); 00334 if ($completion->is_enabled()) { 00335 // Update completion settings 00336 $cm->completion = $fromform->completion; 00337 $cm->completiongradeitemnumber = $fromform->completiongradeitemnumber; 00338 $cm->completionview = $fromform->completionview; 00339 $cm->completionexpected = $fromform->completionexpected; 00340 } 00341 if (!empty($CFG->enableavailability)) { 00342 $cm->availablefrom = $fromform->availablefrom; 00343 $cm->availableuntil = $fromform->availableuntil; 00344 $cm->showavailability = $fromform->showavailability; 00345 condition_info::update_cm_from_form($cm,$fromform,true); 00346 } 00347 if (isset($fromform->showdescription)) { 00348 $cm->showdescription = $fromform->showdescription; 00349 } else { 00350 $cm->showdescription = 0; 00351 } 00352 00353 $DB->update_record('course_modules', $cm); 00354 00355 $modcontext = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule); 00356 00357 // update embedded links and save files 00358 if (plugin_supports('mod', $fromform->modulename, FEATURE_MOD_INTRO, true)) { 00359 $fromform->intro = file_save_draft_area_files($fromform->introeditor['itemid'], $modcontext->id, 00360 'mod_'.$fromform->modulename, 'intro', 0, 00361 array('subdirs'=>true), $fromform->introeditor['text']); 00362 $fromform->introformat = $fromform->introeditor['format']; 00363 unset($fromform->introeditor); 00364 } 00365 00366 if (!$updateinstancefunction($fromform, $mform)) { 00367 print_error('cannotupdatemod', '', "view.php?id={$course->id}#section-{$cw->section}", $fromform->modulename); 00368 } 00369 00370 // make sure visibility is set correctly (in particular in calendar) 00371 if (has_capability('moodle/course:activityvisibility', $modcontext)) { 00372 set_coursemodule_visible($fromform->coursemodule, $fromform->visible); 00373 } 00374 00375 if (isset($fromform->cmidnumber)) { //label 00376 // set cm idnumber - uniqueness is already verified by form validation 00377 set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber); 00378 } 00379 00380 // Now that module is fully updated, also update completion data if 00381 // required (this will wipe all user completion data and recalculate it) 00382 if ($completion->is_enabled() && !empty($fromform->completionunlocked)) { 00383 $completion->reset_all_state($cm); 00384 } 00385 00386 $eventname = 'mod_updated'; 00387 00388 add_to_log($course->id, "course", "update mod", 00389 "../mod/$fromform->modulename/view.php?id=$fromform->coursemodule", 00390 "$fromform->modulename $fromform->instance"); 00391 add_to_log($course->id, $fromform->modulename, "update", 00392 "view.php?id=$fromform->coursemodule", 00393 "$fromform->instance", $fromform->coursemodule); 00394 00395 } else if (!empty($fromform->add)) { 00396 00397 if (!empty($course->groupmodeforce) or !isset($fromform->groupmode)) { 00398 $fromform->groupmode = 0; // do not set groupmode 00399 } 00400 00401 if (!course_allowed_module($course, $fromform->modulename)) { 00402 print_error('moduledisable', '', '', $fromform->modulename); 00403 } 00404 00405 // first add course_module record because we need the context 00406 $newcm = new stdClass(); 00407 $newcm->course = $course->id; 00408 $newcm->module = $fromform->module; 00409 $newcm->instance = 0; // not known yet, will be updated later (this is similar to restore code) 00410 $newcm->visible = $fromform->visible; 00411 $newcm->groupmode = $fromform->groupmode; 00412 $newcm->groupingid = $fromform->groupingid; 00413 $newcm->groupmembersonly = $fromform->groupmembersonly; 00414 $completion = new completion_info($course); 00415 if ($completion->is_enabled()) { 00416 $newcm->completion = $fromform->completion; 00417 $newcm->completiongradeitemnumber = $fromform->completiongradeitemnumber; 00418 $newcm->completionview = $fromform->completionview; 00419 $newcm->completionexpected = $fromform->completionexpected; 00420 } 00421 if(!empty($CFG->enableavailability)) { 00422 $newcm->availablefrom = $fromform->availablefrom; 00423 $newcm->availableuntil = $fromform->availableuntil; 00424 $newcm->showavailability = $fromform->showavailability; 00425 } 00426 if (isset($fromform->showdescription)) { 00427 $newcm->showdescription = $fromform->showdescription; 00428 } else { 00429 $newcm->showdescription = 0; 00430 } 00431 00432 if (!$fromform->coursemodule = add_course_module($newcm)) { 00433 print_error('cannotaddcoursemodule'); 00434 } 00435 00436 if (plugin_supports('mod', $fromform->modulename, FEATURE_MOD_INTRO, true)) { 00437 $introeditor = $fromform->introeditor; 00438 unset($fromform->introeditor); 00439 $fromform->intro = $introeditor['text']; 00440 $fromform->introformat = $introeditor['format']; 00441 } 00442 00443 $returnfromfunc = $addinstancefunction($fromform, $mform); 00444 00445 if (!$returnfromfunc or !is_number($returnfromfunc)) { 00446 // undo everything we can 00447 $modcontext = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule); 00448 delete_context(CONTEXT_MODULE, $fromform->coursemodule); 00449 $DB->delete_records('course_modules', array('id'=>$fromform->coursemodule)); 00450 00451 if (!is_number($returnfromfunc)) { 00452 print_error('invalidfunction', '', "view.php?id={$course->id}#section-{$cw->section}"); 00453 } else { 00454 print_error('cannotaddnewmodule', '', "view.php?id={$course->id}#section-{$cw->section}", $fromform->modulename); 00455 } 00456 } 00457 00458 $fromform->instance = $returnfromfunc; 00459 00460 $DB->set_field('course_modules', 'instance', $returnfromfunc, array('id'=>$fromform->coursemodule)); 00461 00462 // update embedded links and save files 00463 $modcontext = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule); 00464 if (!empty($introeditor)) { 00465 $fromform->intro = file_save_draft_area_files($introeditor['itemid'], $modcontext->id, 00466 'mod_'.$fromform->modulename, 'intro', 0, 00467 array('subdirs'=>true), $introeditor['text']); 00468 $DB->set_field($fromform->modulename, 'intro', $fromform->intro, array('id'=>$fromform->instance)); 00469 } 00470 00471 // course_modules and course_sections each contain a reference 00472 // to each other, so we have to update one of them twice. 00473 $sectionid = add_mod_to_section($fromform); 00474 00475 $DB->set_field('course_modules', 'section', $sectionid, array('id'=>$fromform->coursemodule)); 00476 00477 // make sure visibility is set correctly (in particular in calendar) 00478 // note: allow them to set it even without moodle/course:activityvisibility 00479 set_coursemodule_visible($fromform->coursemodule, $fromform->visible); 00480 00481 if (isset($fromform->cmidnumber)) { //label 00482 // set cm idnumber - uniqueness is already verified by form validation 00483 set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber); 00484 } 00485 00486 // Set up conditions 00487 if ($CFG->enableavailability) { 00488 condition_info::update_cm_from_form((object)array('id'=>$fromform->coursemodule), $fromform, false); 00489 } 00490 00491 $eventname = 'mod_created'; 00492 00493 add_to_log($course->id, "course", "add mod", 00494 "../mod/$fromform->modulename/view.php?id=$fromform->coursemodule", 00495 "$fromform->modulename $fromform->instance"); 00496 add_to_log($course->id, $fromform->modulename, "add", 00497 "view.php?id=$fromform->coursemodule", 00498 "$fromform->instance", $fromform->coursemodule); 00499 } else { 00500 print_error('invaliddata'); 00501 } 00502 00503 // Trigger mod_created/mod_updated event with information about this module. 00504 $eventdata = new stdClass(); 00505 $eventdata->modulename = $fromform->modulename; 00506 $eventdata->name = $fromform->name; 00507 $eventdata->cmid = $fromform->coursemodule; 00508 $eventdata->courseid = $course->id; 00509 $eventdata->userid = $USER->id; 00510 events_trigger($eventname, $eventdata); 00511 00512 // sync idnumber with grade_item 00513 if ($grade_item = grade_item::fetch(array('itemtype'=>'mod', 'itemmodule'=>$fromform->modulename, 00514 'iteminstance'=>$fromform->instance, 'itemnumber'=>0, 'courseid'=>$course->id))) { 00515 if ($grade_item->idnumber != $fromform->cmidnumber) { 00516 $grade_item->idnumber = $fromform->cmidnumber; 00517 $grade_item->update(); 00518 } 00519 } 00520 00521 $items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$fromform->modulename, 00522 'iteminstance'=>$fromform->instance, 'courseid'=>$course->id)); 00523 00524 // create parent category if requested and move to correct parent category 00525 if ($items and isset($fromform->gradecat)) { 00526 if ($fromform->gradecat == -1) { 00527 $grade_category = new grade_category(); 00528 $grade_category->courseid = $course->id; 00529 $grade_category->fullname = $fromform->name; 00530 $grade_category->insert(); 00531 if ($grade_item) { 00532 $parent = $grade_item->get_parent_category(); 00533 $grade_category->set_parent($parent->id); 00534 } 00535 $fromform->gradecat = $grade_category->id; 00536 } 00537 foreach ($items as $itemid=>$unused) { 00538 $items[$itemid]->set_parent($fromform->gradecat); 00539 if ($itemid == $grade_item->id) { 00540 // use updated grade_item 00541 $grade_item = $items[$itemid]; 00542 } 00543 } 00544 } 00545 00546 // add outcomes if requested 00547 if ($outcomes = grade_outcome::fetch_all_available($course->id)) { 00548 $grade_items = array(); 00549 00550 // Outcome grade_item.itemnumber start at 1000, there is nothing above outcomes 00551 $max_itemnumber = 999; 00552 if ($items) { 00553 foreach($items as $item) { 00554 if ($item->itemnumber > $max_itemnumber) { 00555 $max_itemnumber = $item->itemnumber; 00556 } 00557 } 00558 } 00559 00560 foreach($outcomes as $outcome) { 00561 $elname = 'outcome_'.$outcome->id; 00562 00563 if (property_exists($fromform, $elname) and $fromform->$elname) { 00564 // so we have a request for new outcome grade item? 00565 if ($items) { 00566 foreach($items as $item) { 00567 if ($item->outcomeid == $outcome->id) { 00568 //outcome aready exists 00569 continue 2; 00570 } 00571 } 00572 } 00573 00574 $max_itemnumber++; 00575 00576 $outcome_item = new grade_item(); 00577 $outcome_item->courseid = $course->id; 00578 $outcome_item->itemtype = 'mod'; 00579 $outcome_item->itemmodule = $fromform->modulename; 00580 $outcome_item->iteminstance = $fromform->instance; 00581 $outcome_item->itemnumber = $max_itemnumber; 00582 $outcome_item->itemname = $outcome->fullname; 00583 $outcome_item->outcomeid = $outcome->id; 00584 $outcome_item->gradetype = GRADE_TYPE_SCALE; 00585 $outcome_item->scaleid = $outcome->scaleid; 00586 $outcome_item->insert(); 00587 00588 // move the new outcome into correct category and fix sortorder if needed 00589 if ($grade_item) { 00590 $outcome_item->set_parent($grade_item->categoryid); 00591 $outcome_item->move_after_sortorder($grade_item->sortorder); 00592 00593 } else if (isset($fromform->gradecat)) { 00594 $outcome_item->set_parent($fromform->gradecat); 00595 } 00596 } 00597 } 00598 } 00599 00600 if (plugin_supports('mod', $fromform->modulename, FEATURE_ADVANCED_GRADING, false) 00601 and has_capability('moodle/grade:managegradingforms', $modcontext)) { 00602 require_once($CFG->dirroot.'/grade/grading/lib.php'); 00603 $gradingman = get_grading_manager($modcontext, 'mod_'.$fromform->modulename); 00604 $showgradingmanagement = false; 00605 foreach ($gradingman->get_available_areas() as $areaname => $aretitle) { 00606 $formfield = 'advancedgradingmethod_'.$areaname; 00607 if (isset($fromform->{$formfield})) { 00608 $gradingman->set_area($areaname); 00609 $methodchanged = $gradingman->set_active_method($fromform->{$formfield}); 00610 if (empty($fromform->{$formfield})) { 00611 // going back to the simple direct grading is not a reason 00612 // to open the management screen 00613 $methodchanged = false; 00614 } 00615 $showgradingmanagement = $showgradingmanagement || $methodchanged; 00616 } 00617 } 00618 } 00619 00620 rebuild_course_cache($course->id); 00621 grade_regrade_final_grades($course->id); 00622 plagiarism_save_form_elements($fromform); //save plagiarism settings 00623 00624 if (isset($fromform->submitbutton)) { 00625 if (empty($showgradingmanagement)) { 00626 redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$fromform->coursemodule"); 00627 } else { 00628 $returnurl = new moodle_url("/mod/$module->name/view.php", array('id' => $fromform->coursemodule)); 00629 redirect($gradingman->get_management_url($returnurl)); 00630 } 00631 } else { 00632 redirect("$CFG->wwwroot/course/view.php?id={$course->id}#section-{$cw->section}"); 00633 } 00634 exit; 00635 00636 } else { 00637 00638 $streditinga = get_string('editinga', 'moodle', $fullmodulename); 00639 $strmodulenameplural = get_string('modulenameplural', $module->name); 00640 00641 if (!empty($cm->id)) { 00642 $context = get_context_instance(CONTEXT_MODULE, $cm->id); 00643 } else { 00644 $context = get_context_instance(CONTEXT_COURSE, $course->id); 00645 } 00646 00647 $PAGE->set_heading($course->fullname); 00648 $PAGE->set_title($streditinga); 00649 $PAGE->set_cacheable(false); 00650 echo $OUTPUT->header(); 00651 00652 if (get_string_manager()->string_exists('modulename_help', $module->name)) { 00653 echo $OUTPUT->heading_with_help($pageheading, 'modulename', $module->name, 'icon'); 00654 } else { 00655 echo $OUTPUT->heading_with_help($pageheading, '', $module->name, 'icon'); 00656 } 00657 00658 $mform->display(); 00659 00660 echo $OUTPUT->footer(); 00661 }