3 ///////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
10 // Copyright (C) 2001-2007 Martin Dougiamas http://dougiamas.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';
29 $courseid = required_param('id', PARAM_INT
);
30 $action = optional_param('action', 0, PARAM_ALPHA
);
31 $eid = optional_param('eid', 0, PARAM_ALPHANUM
);
34 /// Make sure they can even access this course
36 if (!$course = get_record('course', 'id', $courseid)) {
37 print_error('nocourseid');
40 require_login($course);
41 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
42 require_capability('moodle/grade:manage', $context);
44 /// return tracking object
45 $gpr = new grade_plugin_return(array('type'=>'edit', 'courseid'=>$courseid));
46 $returnurl = $gpr->get_return_url(null);
48 //first make sure we have proper final grades - we need it for locking changes
49 grade_regrade_final_grades($courseid);
51 // get the grading tree object
52 // note: total must be first for moving to work correctly, if you want it last moving code must be rewritten!
53 $gtree = new grade_tree($courseid, false, false);
60 if (!$element = $gtree->locate_element($eid)) {
61 error('Incorrect element id!', $returnurl);
63 $object = $element['object'];
67 $strgrades = get_string('grades');
68 $strgraderreport = get_string('graderreport', 'grades');
69 $strcategoriesedit = get_string('categoriesedit', 'grades');
71 $nav = array(array('name'=>$strgrades,'link'=>$CFG->wwwroot
.'/grade/index.php?id='.$courseid, 'type'=>'misc'),
72 array('name'=>$strcategoriesedit, 'link'=>'', 'type'=>'misc'));
74 $navigation = build_navigation($nav);
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, 'tree.php', 'tree.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);
147 echo '<div class="buttons">';
149 print_single_button('tree.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 print_single_button('outcomeitem.php', array('courseid'=>$course->id
), get_string('addoutcomeitem', 'grades'), 'get');
154 print_single_button('tree.php', array('id'=>$course->id
, 'action'=>'autosort'), get_string('autosort', 'grades'), 'get');
155 print_single_button('tree.php', array('id'=>$course->id
, 'action'=>'synclegacy'), get_string('synclegacygrades', 'grades'), 'get');
158 print_footer($course);
164 function print_grade_tree(&$gtree, $element, $moving, &$gpr) {
165 global $CFG, $COURSE;
167 /// fetch needed strings
168 $strmove = get_string('move');
169 $strmovehere = get_string('movehere');
170 $strdelete = get_string('delete');
172 $object = $element['object'];
173 $eid = $element['eid'];
176 $actions = $gtree->get_edit_icon($element, $gpr);
178 if ($element['type'] == 'item' or ($element['type'] == 'category' and $element['depth'] > 1)) {
179 $actions .= '<a href="tree.php?id='.$COURSE->id
.'&action=delete&eid='.$eid.'&sesskey='.sesskey().'"><img src="'.$CFG->pixpath
.'/t/delete.gif" class="iconsmall" alt="'.$strdelete.'" title="'.$strdelete.'"/></a>';
180 $actions .= '<a href="tree.php?id='.$COURSE->id
.'&action=moveselect&eid='.$eid.'&sesskey='.sesskey().'"><img src="'.$CFG->pixpath
.'/t/move.gif" class="iconsmall" alt="'.$strmove.'" title="'.$strmove.'"/></a>';
183 $actions .= $gtree->get_locking_icon($element, $gpr);
185 $name = $object->get_name();
187 //TODO: improve outcome visulisation
188 if ($element['type'] == 'item' and !empty($object->outcomeid
)) {
189 $name = $name.' ('.get_string('outcome', 'grades').')';
192 if ($object->is_hidden()) {
193 $name = '<span class="dimmed_text">'.$name.'</span>';
195 $actions .= $gtree->get_hiding_icon($element, $gpr);
198 $icon = '<img src="'.$CFG->wwwroot
.'/pix/spacer.gif" class="icon" alt=""/>';
199 switch ($element['type']) {
201 if ($object->itemtype
== 'mod') {
202 $icon = '<img src="'.$CFG->modpixpath
.'/'.$object->itemmodule
.'/icon.gif" class="icon" alt="'.get_string('modulename', $object->itemmodule
).'"/>';
203 } else if ($object->itemtype
== 'manual') {
204 //TODO: add manual grading icon
205 $icon = '<img src="'.$CFG->pixpath
.'/t/edit.gif" class="icon" alt="'.get_string('manualgrade', 'grades').'"/>'; // TODO: localize
210 $icon = '<img src="'.$CFG->pixpath
.'/i/category_grade.gif" class="icon" alt="'.get_string('categorygrade').'"/>'; // TODO: localize
213 $icon = '<img src="'.$CFG->pixpath
.'/f/folder.gif" class="icon" alt="'.get_string('category').'"/>';
217 /// prepare move target if needed
220 $actions = ''; // no action icons when moving
221 $moveto = '<li><a href="tree.php?id='.$COURSE->id
.'&action=move&eid='.$moving.'&moveafter='.$eid.'&sesskey='.sesskey().'"><img class="movetarget" src="'.$CFG->wwwroot
.'/pix/movehere.gif" alt="'.$strmovehere.'" title="'.$strmovehere.'" /></a></li>';
224 /// print the list items now
225 if ($moving == $eid) {
226 // do not diplay children
227 echo '<li class="'.$element['type'].' moving">'.$icon.$name.'('.get_string('move').')</li>';
229 } else if ($element['type'] != 'category') {
230 echo '<li class="'.$element['type'].'">'.$icon.$name.$actions.'</li>'.$moveto;
233 echo '<li class="'.$element['type'].'">'.$icon.$name.$actions;
234 echo '<ul class="catlevel'.$element['depth'].'">';
235 foreach($element['children'] as $child_el) {
236 print_grade_tree($gtree, $child_el, $moving, $gpr);
239 if ($element['depth'] > 1) {
240 echo $moveto; // can not move after the top category