4 ///////////////////////////////////////////////////////////////////////////
6 // NOTICE OF COPYRIGHT //
8 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
9 // http://moodle.com //
11 // Copyright (C) 2001-2007 Martin Dougiamas http://dougiamas.com //
13 // This program is free software; you can redistribute it and/or modify //
14 // it under the terms of the GNU General Public License as published by //
15 // the Free Software Foundation; either version 2 of the License, or //
16 // (at your option) any later version. //
18 // This program is distributed in the hope that it will be useful, //
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
21 // GNU General Public License for more details: //
23 // http://www.gnu.org/copyleft/gpl.html //
25 ///////////////////////////////////////////////////////////////////////////
27 require_once '../../config.php';
28 require_once $CFG->libdir
.'/gradelib.php';
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);
43 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
44 //require_capability() here!!
47 $returnurl = 'edit_tree.php?id='.$course->id
;
49 // get the grading tree object
50 // note: total must be first for moving to work correctly, if you want it last moving code must be rewritten!
51 $gtree = new grade_tree($courseid, false, false, false);
58 if (!$element = $gtree->locate_element($eid)) {
59 error('Incorrect element id!', $returnurl);
61 $object = $element['object'];
65 $strgrades = get_string('grades');
66 $strgraderreport = get_string('graderreport', 'grades');
67 $strcategoriesedit = get_string('categoriesedit', 'grades');
69 $nav = array(array('name'=>$strgrades,'link'=>$CFG->wwwroot
.'/grade/index.php?id='.$courseid, 'type'=>'misc'),
70 array('name'=>$strcategoriesedit, 'link'=>'', 'type'=>'misc'));
72 $navigation = build_navigation($nav);
77 if ($eid and confirm_sesskey()) {
78 if ($element['type'] == 'category') {
79 redirect('edit_category.php?courseid='.$course->id
.'&id='.$object->id
);
81 redirect('edit_item.php?courseid='.$course->id
.'&id='.$object->id
);
88 $confirm = optional_param('confirm', 0, PARAM_BOOL
);
90 if ($confirm and confirm_sesskey()) {
91 $object->delete('grade/report/grader/category');
95 print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strcategoriesedit, $navigation, '', '', true, '', navmenu($course));
96 $strdeletecheckfull = get_string('deletecheck', '', $object->get_name());
97 $optionsyes = array('eid'=>$eid, 'confirm'=>1, 'sesskey'=>sesskey(), 'id'=>$course->id
, 'action'=>'delete');
98 $optionsno = array('id'=>$course->id
);
99 notice_yesno($strdeletecheckfull, 'edit_tree.php', 'edit_tree.php', $optionsyes, $optionsno, 'post', 'get');
100 print_footer($course);
107 //TODO: implement autosorting based on order of mods on course page, categories first, manual items last
111 grade_grab_legacy_grades($course->id
);
112 redirect($returnurl);
115 if ($eid and confirm_sesskey()) {
116 $moveafter = required_param('moveafter', PARAM_ALPHANUM
);
117 if(!$after_el = $gtree->locate_element($moveafter)) {
118 error('Incorect element id in moveafter', $returnurl);
120 $after = $after_el['object'];
121 $parent = $after->get_parent_category();
122 $sortorder = $after->get_sortorder();
124 $object->set_parent($parent->id
);
125 $object->move_after_sortorder($sortorder);
127 redirect($returnurl);
132 if ($eid and confirm_sesskey()) {
138 if ($eid and confirm_sesskey()) {
139 $object->set_hidden(1);
140 redirect($returnurl);
145 if ($eid and confirm_sesskey()) {
146 $object->set_hidden(0);
147 redirect($returnurl);
152 if ($eid and confirm_sesskey()) {
153 //TODO: add error handling in redirect
154 $object->set_locked(1);
155 redirect($returnurl);
160 if ($eid and confirm_sesskey()) {
161 $object->set_locked(0);
162 redirect($returnurl);
170 print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strcategoriesedit, $navigation, '', '', true, '', navmenu($course));
172 print_heading(get_string('categoriesedit', 'grades'));
175 // TODO: implement return support - use tabs from the report plugin
176 /*$currenttab = 'editcategory';
177 include('tabs.php');*/
179 print_box_start('gradetreebox generalbox');
180 echo '<ul id="grade_tree">';
181 print_grade_tree($gtree->top_element
, $moving);
185 echo '<div class="buttons">';
187 print_single_button('edit_tree.php', array('id'=>$course->id
), get_string('cancel'), 'get');
189 print_single_button('edit_category.php', array('courseid'=>$course->id
), get_string('addcategory', 'grades'), 'get');
190 print_single_button('edit_item.php', array('courseid'=>$course->id
), get_string('additem', 'grades'), 'get');
191 print_single_button('edit_tree.php', array('id'=>$course->id
, 'action'=>'autosort'), get_string('autosort', 'grades'), 'get');
192 print_single_button('edit_tree.php', array('id'=>$course->id
, 'action'=>'synclegacy'), get_string('synclegacygrades', 'grades'), 'get');
195 print_footer($course);
201 function print_grade_tree($element, $moving) {
202 global $CFG, $COURSE;
204 /// fetch needed strings
205 $strmove = get_string('move');
206 $strmovehere = get_string('movehere');
207 $stredit = get_string('edit');
208 $strdelete = get_string('delete');
209 $strhide = get_string('hide');
210 $strshow = get_string('show');
211 $strlock = get_string('lock', 'grades');
212 $strunlock = get_string('unlock', 'grades');
214 $object = $element['object'];
215 $eid = $element['eid'];
218 $actions = '<a href="edit_tree.php?id='.$COURSE->id
.'&action=edit&eid='.$eid.'&sesskey='.sesskey().'"><img src="'.$CFG->pixpath
.'/t/edit.gif" class="iconsmall" alt="'.$stredit.'" title="'.$stredit.'"/></a>';
220 if ($element['type'] == 'item' or ($element['type'] == 'category' and $element['depth'] > 1)) {
221 $actions .= '<a href="edit_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>';
222 $actions .= '<a href="edit_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>';
225 if ($object->is_locked()) {
226 $actions .= '<a href="edit_tree.php?id='.$COURSE->id
.'&action=unlock&eid='.$eid.'&sesskey='.sesskey().'"><img src="'.$CFG->pixpath
.'/t/unlock.gif" class="iconsmall" alt="'.$strunlock.'" title="'.$strunlock.'"/></a>';
228 $actions .= '<a href="edit_tree.php?id='.$COURSE->id
.'&action=lock&eid='.$eid.'&sesskey='.sesskey().'"><img src="'.$CFG->pixpath
.'/t/lock.gif" class="iconsmall" alt="'.$strlock.'" title="'.$strlock.'"/></a>';
231 if ($object->is_hidden()) {
232 $name = '<span class="dimmed_text">'.$object->get_name().'</span>';
233 $actions .= '<a href="edit_tree.php?id='.$COURSE->id
.'&action=show&eid='.$eid.'&sesskey='.sesskey().'"><img src="'.$CFG->pixpath
.'/t/show.gif" class="iconsmall" alt="'.$strshow.'" title="'.$strshow.'"/></a>';
235 $name = $object->get_name();
236 $actions .= '<a href="edit_tree.php?id='.$COURSE->id
.'&action=hide&eid='.$eid.'&sesskey='.sesskey().'"><img src="'.$CFG->pixpath
.'/t/hide.gif" class="iconsmall" alt="'.$strhide.'" title="'.$strhide.'"/></a>';
240 $icon = '<img src="'.$CFG->wwwroot
.'/pix/spacer.gif" class="icon" alt=""/>';
241 switch ($element['type']) {
243 if ($object->itemtype
== 'mod') {
244 $icon = '<img src="'.$CFG->modpixpath
.'/'.$object->itemmodule
.'/icon.gif" class="icon" alt="'.get_string('modulename', $object->itemmodule
).'"/>';
245 } else if ($object->itemtype
== 'manual') {
246 //TODO: add manual grading icon
247 $icon = '<img src="'.$CFG->pixpath
.'/t/edit.gif" class="icon" alt="'.get_string('manualgrade', 'grades').'"/>'; // TODO: localize
252 $icon = '<img src="'.$CFG->pixpath
.'/i/category_grade.gif" class="icon" alt="'.get_string('categorygrade').'"/>'; // TODO: localize
255 $icon = '<img src="'.$CFG->pixpath
.'/f/folder.gif" class="icon" alt="'.get_string('category').'"/>';
259 /// prepare move target if needed
262 $actions = ''; // no action icons when moving
263 $moveto = '<li><a href="edit_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>';
266 /// print the list items now
267 if ($moving == $eid) {
268 // do not diplay children
269 echo '<li class="'.$element['type'].' moving">'.$icon.$name.'('.get_string('move').')</li>';
271 } else if ($element['type'] != 'category') {
272 echo '<li class="'.$element['type'].'">'.$icon.$name.$actions.'</li>'.$moveto;
275 echo '<li class="'.$element['type'].'">'.$icon.$name.$actions;
276 echo '<ul class="catlevel'.$element['depth'].'">';
277 foreach($element['children'] as $child_el) {
278 print_grade_tree($child_el, $moving);
281 if ($element['depth'] > 1) {
282 echo $moveto; // can not move after the top category