3 ///////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
10 // Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
12 // This program is free software; you can redistribute it and/or modify //
13 // it under the terms of the GNU General Public License as published by //
14 // the Free Software Foundation; either version 2 of the License, or //
15 // (at your option) any later version. //
17 // This program is distributed in the hope that it will be useful, //
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20 // GNU General Public License for more details: //
22 // http://www.gnu.org/copyleft/gpl.html //
24 ///////////////////////////////////////////////////////////////////////////
26 require_once '../../../config.php';
27 require_once $CFG->dirroot
.'/grade/lib.php';
28 require_once $CFG->dirroot
.'/grade/report/lib.php'; // for preferences
30 $courseid = required_param('id', PARAM_INT
);
31 $action = optional_param('action', 0, PARAM_ALPHA
);
32 $eid = optional_param('eid', 0, PARAM_ALPHANUM
);
35 /// Make sure they can even access this course
37 if (!$course = get_record('course', 'id', $courseid)) {
38 print_error('nocourseid');
41 require_login($course);
42 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
43 require_capability('moodle/grade:manage', $context);
45 /// return tracking object
46 $gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'tree', 'courseid'=>$courseid));
47 $returnurl = $gpr->get_return_url(null);
49 //first make sure we have proper final grades - we need it for locking changes
50 grade_regrade_final_grades($courseid);
52 // get the grading tree object
53 // note: total must be first for moving to work correctly, if you want it last moving code must be rewritten!
54 $gtree = new grade_tree($courseid, false, false);
61 if (!$element = $gtree->locate_element($eid)) {
62 error('Incorrect element id!', $returnurl);
64 $object = $element['object'];
67 $switch = grade_report
::get_pref('aggregationposition');
69 $strgrades = get_string('grades');
70 $strgraderreport = get_string('graderreport', 'grades');
71 $strcategoriesedit = get_string('categoriesedit', 'grades');
72 $strcategoriesanditems = get_string('categoriesanditems', 'grades');
74 $navigation = grade_build_nav(__FILE__
, $strcategoriesanditems, array('courseid' => $courseid));
80 $confirm = optional_param('confirm', 0, PARAM_BOOL
);
82 if ($confirm and confirm_sesskey()) {
83 $object->delete('grade/report/grader/category');
87 print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strcategoriesedit, $navigation, '', '', true, '', navmenu($course));
88 $strdeletecheckfull = get_string('deletecheck', '', $object->get_name());
89 $optionsyes = array('eid'=>$eid, 'confirm'=>1, 'sesskey'=>sesskey(), 'id'=>$course->id
, 'action'=>'delete');
90 $optionsno = array('id'=>$course->id
);
91 notice_yesno($strdeletecheckfull, 'index.php', 'index.php', $optionsyes, $optionsno, 'post', 'get');
92 print_footer($course);
99 //TODO: implement autosorting based on order of mods on course page, categories first, manual items last
103 grade_grab_legacy_grades($course->id
);
104 redirect($returnurl);
107 if ($eid and confirm_sesskey()) {
108 $moveafter = required_param('moveafter', PARAM_ALPHANUM
);
109 if(!$after_el = $gtree->locate_element($moveafter)) {
110 error('Incorect element id in moveafter', $returnurl);
112 $after = $after_el['object'];
113 $parent = $after->get_parent_category();
114 $sortorder = $after->get_sortorder();
116 $object->set_parent($parent->id
);
117 $object->move_after_sortorder($sortorder);
119 redirect($returnurl);
124 if ($eid and confirm_sesskey()) {
133 print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strcategoriesedit, $navigation, '', '', true, '', navmenu($course));
135 /// Print the plugin selector at the top
136 print_grade_plugin_selector($courseid, 'edit', 'tree');
138 print_heading(get_string('categoriesedit', 'grades'));
141 print_box_start('gradetreebox generalbox');
142 echo '<ul id="grade_tree">';
143 print_grade_tree($gtree, $gtree->top_element
, $moving, $gpr, $switch);
147 echo '<div class="buttons">';
149 print_single_button('index.php', array('id'=>$course->id
), get_string('cancel'), 'get');
151 print_single_button('category.php', array('courseid'=>$course->id
), get_string('addcategory', 'grades'), 'get');
152 print_single_button('item.php', array('courseid'=>$course->id
), get_string('additem', 'grades'), 'get');
153 if (!empty($CFG->enableoutcomes
)) {
154 print_single_button('outcomeitem.php', array('courseid'=>$course->id
), get_string('addoutcomeitem', 'grades'), 'get');
156 //print_single_button('index.php', array('id'=>$course->id, 'action'=>'autosort'), get_string('autosort', 'grades'), 'get');
157 print_single_button('index.php', array('id'=>$course->id
, 'action'=>'synclegacy'), get_string('synclegacygrades', 'grades'), 'get');
160 print_footer($course);
163 function print_grade_tree(&$gtree, $element, $moving, &$gpr, $switch, $switchedlast=false) {
164 global $CFG, $COURSE;
166 /// fetch needed strings
167 $strmove = get_string('move');
168 $strmovehere = get_string('movehere');
169 $strdelete = get_string('delete');
171 $object = $element['object'];
172 $eid = $element['eid'];
175 $actions = $gtree->get_edit_icon($element, $gpr);
177 if ($element['type'] == 'item' or ($element['type'] == 'category' and $element['depth'] > 1)) {
178 $actions .= '<a href="index.php?id='.$COURSE->id
.'&action=delete&eid='
179 . $eid.'&sesskey='.sesskey().'"><img src="'.$CFG->pixpath
.'/t/delete.gif" class="iconsmall" alt="'
180 . $strdelete.'" title="'.$strdelete.'"/></a>';
181 $actions .= '<a href="index.php?id='.$COURSE->id
.'&action=moveselect&eid='
182 . $eid.'&sesskey='.sesskey().'"><img src="'.$CFG->pixpath
.'/t/move.gif" class="iconsmall" alt="'
183 . $strmove.'" title="'.$strmove.'"/></a>';
186 $actions .= $gtree->get_locking_icon($element, $gpr);
188 $name = $object->get_name();
190 //TODO: improve outcome visualisation
191 if ($element['type'] == 'item' and !empty($object->outcomeid
)) {
192 $name = $name.' ('.get_string('outcome', 'grades').')';
195 if ($object->is_hidden()) {
196 $name = '<span class="dimmed_text">'.$name.'</span>';
198 $actions .= $gtree->get_hiding_icon($element, $gpr);
201 $icon = '<img src="'.$CFG->wwwroot
.'/pix/spacer.gif" class="icon" alt=""/>';
203 $catcourseitem = false;
204 switch ($element['type']) {
206 if ($object->itemtype
== 'mod') {
207 $icon = '<img src="'.$CFG->modpixpath
.'/'.$object->itemmodule
.'/icon.gif" class="icon" alt="'
208 . get_string('modulename', $object->itemmodule
).'"/>';
209 } else if ($object->itemtype
== 'manual') {
210 //TODO: add manual grading icon
211 if (empty($object->outcomeid
)) {
212 $icon = '<img src="'.$CFG->pixpath
.'/t/edit.gif" class="icon" alt="'
213 . get_string('manualgrade', 'grades').'"/>'; // TODO: localize
215 $icon = '<img src="'.$CFG->pixpath
.'/i/outcomes.gif" class="icon" alt="'
216 . get_string('outcome', 'grades').'"/>';
223 $icon = '<img src="'.$CFG->pixpath
.'/i/category_grade.gif" class="icon" alt="'.get_string('categorygrade').'"/>'; // TODO: localize
224 $catcourseitem = true;
227 $icon = '<img src="'.$CFG->pixpath
.'/f/folder.gif" class="icon" alt="'.get_string('category').'"/>';
231 /// prepare move target if needed
234 $actions = ''; // no action icons when moving
235 $moveto = '<li><a href="index.php?id='.$COURSE->id
.'&action=move&eid='.$moving.'&moveafter='
236 . $eid.'&sesskey='.sesskey().'"><img class="movetarget" src="'.$CFG->wwwroot
.'/pix/movehere.gif" alt="'
237 . $strmovehere.'" title="'.$strmovehere.'" /></a></li>';
240 /// print the list items now
241 if ($moving == $eid) {
242 // do not diplay children
243 echo '<li class="'.$element['type'].' moving">'.$icon.$name.'('.get_string('move').')</li>';
245 } else if ($element['type'] != 'category') {
246 if ($catcourseitem and $switch) {
248 echo '<li class="'.$element['type'].'">'.$icon.$name.$actions.'</li>';
253 echo '<li class="'.$element['type'].'">'.$icon.$name.$actions.'</li>'.$moveto;
257 echo '<li class="'.$element['type'].'">'.$icon.$name.$actions;
258 echo '<ul class="catlevel'.$element['depth'].'">';
260 foreach($element['children'] as $child_el) {
261 if ($switch and empty($last)) {
264 print_grade_tree($gtree, $child_el, $moving, $gpr, $switch);
267 print_grade_tree($gtree, $last, $moving, $gpr, $switch, true);
270 if ($element['depth'] > 1) {
271 echo $moveto; // can not move after the top category