dirroot.'/grade/lib.php'; require_once $CFG->dirroot.'/grade/report/lib.php'; // for preferences $courseid = required_param('id', PARAM_INT); $action = optional_param('action', 0, PARAM_ALPHA); $eid = optional_param('eid', 0, PARAM_ALPHANUM); /// Make sure they can even access this course if (!$course = get_record('course', 'id', $courseid)) { print_error('nocourseid'); } require_login($course); $context = get_context_instance(CONTEXT_COURSE, $course->id); require_capability('moodle/grade:manage', $context); /// return tracking object $gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'tree', 'courseid'=>$courseid)); $returnurl = $gpr->get_return_url(null); //first make sure we have proper final grades - we need it for locking changes grade_regrade_final_grades($courseid); // get the grading tree object // note: total must be first for moving to work correctly, if you want it last moving code must be rewritten! $gtree = new grade_tree($courseid, false, false); if (empty($eid)) { $element = null; $object = null; } else { if (!$element = $gtree->locate_element($eid)) { error('Incorrect element id!', $returnurl); } $object = $element['object']; } $switch = grade_get_setting($course->id, 'aggregationposition', $CFG->grade_aggregationposition); $strgrades = get_string('grades'); $strgraderreport = get_string('graderreport', 'grades'); $strcategoriesedit = get_string('categoriesedit', 'grades'); $strcategoriesanditems = get_string('categoriesanditems', 'grades'); $navigation = grade_build_nav(__FILE__, $strcategoriesanditems, array('courseid' => $courseid)); $moving = false; switch ($action) { case 'delete': if ($eid) { if (!element_deletable($element)) { // no deleting of external activities - they would be recreated anyway! // exception is activity without grading or misconfigured activities break; } $confirm = optional_param('confirm', 0, PARAM_BOOL); if ($confirm and confirm_sesskey()) { $object->delete('grade/report/grader/category'); redirect($returnurl); } else { print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strcategoriesedit, $navigation, '', '', true, '', navmenu($course)); $strdeletecheckfull = get_string('deletecheck', '', $object->get_name()); $optionsyes = array('eid'=>$eid, 'confirm'=>1, 'sesskey'=>sesskey(), 'id'=>$course->id, 'action'=>'delete'); $optionsno = array('id'=>$course->id); notice_yesno($strdeletecheckfull, 'index.php', 'index.php', $optionsyes, $optionsno, 'post', 'get'); print_footer($course); die; } } break; case 'autosort': //TODO: implement autosorting based on order of mods on course page, categories first, manual items last break; case 'synclegacy': grade_grab_legacy_grades($course->id); redirect($returnurl); case 'move': if ($eid and confirm_sesskey()) { $moveafter = required_param('moveafter', PARAM_ALPHANUM); if(!$after_el = $gtree->locate_element($moveafter)) { error('Incorect element id in moveafter', $returnurl); } $after = $after_el['object']; $parent = $after->get_parent_category(); $sortorder = $after->get_sortorder(); $object->set_parent($parent->id); $object->move_after_sortorder($sortorder); redirect($returnurl); } break; case 'moveselect': if ($eid and confirm_sesskey()) { $moving = $eid; } break; default: break; } print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strcategoriesedit, $navigation, '', '', true, '', navmenu($course)); /// Print the plugin selector at the top print_grade_plugin_selector($courseid, 'edit', 'tree'); print_heading(get_string('categoriesedit', 'grades')); print_box_start('gradetreebox generalbox'); echo '