Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / grade / edit / tree.php
blob68eaaae89a9c33519cf4a468bd3e9ae55c7d5ad6
1 <?php // $Id$
3 ///////////////////////////////////////////////////////////////////////////
4 // //
5 // NOTICE OF COPYRIGHT //
6 // //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
9 // //
10 // Copyright (C) 2001-2007 Martin Dougiamas http://dougiamas.com //
11 // //
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. //
16 // //
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: //
21 // //
22 // http://www.gnu.org/copyleft/gpl.html //
23 // //
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);
55 if (empty($eid)) {
56 $element = null;
57 $object = null;
59 } else {
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);
75 $moving = false;
77 switch ($action) {
78 case 'delete':
79 if ($eid) {
80 $confirm = optional_param('confirm', 0, PARAM_BOOL);
82 if ($confirm and confirm_sesskey()) {
83 $object->delete('grade/report/grader/category');
84 redirect($returnurl);
86 } else {
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);
93 die;
96 break;
98 case 'autosort':
99 //TODO: implement autosorting based on order of mods on course page, categories first, manual items last
100 break;
102 case 'synclegacy':
103 grade_grab_legacy_grades($course->id);
104 redirect($returnurl);
106 case 'move':
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);
121 break;
123 case 'moveselect':
124 if ($eid and confirm_sesskey()) {
125 $moving = $eid;
127 break;
129 default:
130 break;
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);
144 echo '</ul>';
145 print_box_end();
147 echo '<div class="buttons">';
148 if ($moving) {
149 print_single_button('tree.php', array('id'=>$course->id), get_string('cancel'), 'get');
150 } else {
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');
157 echo '</div>';
158 print_footer($course);
159 die;
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'];
175 /// prepare actions
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.'&amp;action=delete&amp;eid='.$eid.'&amp;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.'&amp;action=moveselect&amp;eid='.$eid.'&amp;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);
197 /// prepare icon
198 $icon = '<img src="'.$CFG->wwwroot.'/pix/spacer.gif" class="icon" alt=""/>';
199 switch ($element['type']) {
200 case 'item':
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
207 break;
208 case 'courseitem':
209 case 'categoryitem':
210 $icon = '<img src="'.$CFG->pixpath.'/i/category_grade.gif" class="icon" alt="'.get_string('categorygrade').'"/>'; // TODO: localize
211 break;
212 case 'category':
213 $icon = '<img src="'.$CFG->pixpath.'/f/folder.gif" class="icon" alt="'.get_string('category').'"/>';
214 break;
217 /// prepare move target if needed
218 $moveto = '';
219 if ($moving) {
220 $actions = ''; // no action icons when moving
221 $moveto = '<li><a href="tree.php?id='.$COURSE->id.'&amp;action=move&amp;eid='.$moving.'&amp;moveafter='.$eid.'&amp;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;
232 } else {
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);
238 echo '</ul></li>';
239 if ($element['depth'] > 1) {
240 echo $moveto; // can not move after the top category