2 // Allows a creator to edit custom outcomes, and also display help about outcomes
4 ///////////////////////////////////////////////////////////////////////////
6 // NOTICE OF COPYRIGHT //
8 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
9 // http://moodle.com //
11 // Copyright (C) 1999 onwards Martin Dougiamas http://moodle.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->dirroot
.'/lib/formslib.php');
29 require_once $CFG->dirroot
.'/grade/lib.php';
30 require_once $CFG->libdir
.'/gradelib.php';
32 $courseid = optional_param('id', 0, PARAM_INT
);
33 $action = optional_param('action', '', PARAM_ALPHA
);
35 /// Make sure they can even access this course
37 if (!$course = get_record('course', 'id', $courseid)) {
38 print_error('nocourseid');
40 require_login($course);
41 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
42 require_capability('moodle/grade:manageoutcomes', $context);
44 if (empty($CFG->enableoutcomes
)) {
45 redirect('../../index.php?id='.$courseid);
49 require_once $CFG->libdir
.'/adminlib.php';
50 admin_externalpage_setup('outcomes');
53 /// return tracking object
54 $gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'outcome', 'courseid'=>$courseid));
56 require_once('import_outcomes_form.php');
57 $upload_form = new import_outcomes_form();
59 if ($upload_form_data = $upload_form->get_data()) {
60 require_once('import.php');
65 $strgrades = get_string('grades');
66 $pagename = get_string('outcomes', 'grades');
68 $navigation = grade_build_nav(__FILE__
, $pagename, $courseid);
70 $strshortname = get_string('shortname');
71 $strfullname = get_string('fullname');
72 $strscale = get_string('scale');
73 $strstandardoutcome = get_string('outcomesstandard', 'grades');
74 $strcustomoutcomes = get_string('outcomescustom', 'grades');
75 $strdelete = get_string('delete');
76 $stredit = get_string('edit');
77 $strcreatenewoutcome = get_string('outcomecreate', 'grades');
78 $stritems = get_string('items', 'grades');
79 $strcourses = get_string('courses');
80 $stredit = get_string('edit');
84 if (!confirm_sesskey()) {
87 $outcomeid = required_param('outcomeid', PARAM_INT
);
88 if (!$outcome = grade_outcome
::fetch(array('id'=>$outcomeid))) {
92 if (empty($outcome->courseid
)) {
93 require_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM
));
94 } else if ($outcome->courseid
!= $courseid) {
95 error('Incorrect courseid!');
98 if (!$outcome->can_delete()) {
102 $deleteconfirmed = optional_param('deleteconfirmed', 0, PARAM_BOOL
);
104 if(!$deleteconfirmed){
105 print_header(get_string('outcomedelete', 'grades'));
106 notice_yesno(get_string('outcomeconfirmdelete', 'grades', $outcome->fullname
),
107 "index.php?id={$courseid}", "index.php?id={$courseid}",
108 array('outcomeid' => $outcome->id
,
110 'sesskey' => $USER->sesskey
,
111 'deleteconfirmed'=> 1)
121 $systemcontext = get_context_instance(CONTEXT_SYSTEM
);
122 $caneditsystemscales = has_capability('moodle/course:managescales', $systemcontext);
126 print_header_simple($strgrades.': '.$pagename, ': '.$strgrades, $navigation, '', '', true, '', navmenu($course));
127 /// Print the plugin selector at the top
128 print_grade_plugin_selector($courseid, 'edit', 'outcome');
130 $caneditcoursescales = has_capability('moodle/course:managescales', $context);
132 $currenttab = 'outcomes';
136 admin_externalpage_print_header();
137 $caneditcoursescales = $caneditsystemscales;
141 $outcomes_tables = array();
143 if ($courseid and $outcomes = grade_outcome
::fetch_all_local($courseid)) {
145 $return = print_heading($strcustomoutcomes, '', 2, 'main', true);
147 foreach($outcomes as $outcome) {
149 $line[] = $outcome->get_name();
150 $line[] = $outcome->get_shortname();
152 $scale = $outcome->load_scale();
153 if (empty($scale->id
)) { // hopefully never happens
154 $line[] = $scale->get_name();
156 if (empty($scale->courseid
)) {
157 $caneditthisscale = $caneditsystemscales;
158 } else if ($scale->courseid
== $courseid) {
159 $caneditthisscale = $caneditcoursescales;
161 $context = get_context_instance(CONTEXT_COURSE
, $scale->courseid
);
162 $caneditthisscale = has_capability('moodle/course:managescales', $context);
164 if ($caneditthisscale) {
165 $url = $CFG->wwwroot
.'/grade/edit/scale/edit.php?courseid='.$courseid.'&id='.$scale->id
;
166 $url = $gpr->add_url_params($url);
167 $line[] = '<a href="'.$url.'">'.$scale->get_name().'</a>';
169 $line[] = $scale->get_name();
173 $line[] = $outcome->get_item_uses_count();
176 $buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$courseid&id=$outcome->id\"><img".
177 " src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
178 if ($outcome->can_delete()) {
179 $buttons .= "<a title=\"$strdelete\" href=\"index.php?id=$courseid&outcomeid=$outcome->id&action=delete&sesskey=$USER->sesskey\"><img".
180 " src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
186 $table = new object();
187 $table->head
= array($strfullname, $strshortname, $strscale, $stritems, $stredit);
188 $table->size
= array('30%', '20%', '20%', '20%', '10%' );
189 $table->align
= array('left', 'left', 'left', 'center', 'center');
190 $table->width
= '90%';
191 $table->data
= $data;
192 $return .= print_table($table, true);
193 $outcomes_tables[] = $return;
197 if ($outcomes = grade_outcome
::fetch_all_global()) {
199 $return = print_heading($strstandardoutcome, '', 2, 'main', true);
201 foreach($outcomes as $outcome) {
203 $line[] = $outcome->get_name();
204 $line[] = $outcome->get_shortname();
206 $scale = $outcome->load_scale();
207 if (empty($scale->id
)) { // hopefully never happens
208 $line[] = $scale->get_name();
210 if (empty($scale->courseid
)) {
211 $caneditthisscale = $caneditsystemscales;
212 } else if ($scale->courseid
== $courseid) {
213 $caneditthisscale = $caneditcoursescales;
215 $context = get_context_instance(CONTEXT_COURSE
, $scale->courseid
);
216 $caneditthisscale = has_capability('moodle/course:managescales', $context);
218 if ($caneditthisscale) {
219 $url = $CFG->wwwroot
.'/grade/edit/scale/edit.php?courseid='.$courseid.'&id='.$scale->id
;
220 $url = $gpr->add_url_params($url);
221 $line[] = '<a href="'.$url.'">'.$scale->get_name().'</a>';
223 $line[] = $scale->get_name();
227 $line[] = $outcome->get_course_uses_count();
228 $line[] = $outcome->get_item_uses_count();
231 if (has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM
))) {
232 $buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$courseid&id=$outcome->id\"><img".
233 " src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
235 if (has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM
)) and $outcome->can_delete()) {
236 $buttons .= "<a title=\"$strdelete\" href=\"index.php?id=$courseid&outcomeid=$outcome->id&action=delete&sesskey=$USER->sesskey\"><img".
237 " src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
243 $table = new object();
244 $table->head
= array($strfullname, $strshortname, $strscale, $strcourses, $stritems, $stredit);
245 $table->size
= array('30%', '20%', '20%', '10%', '10%', '10%');
246 $table->align
= array('left', 'left', 'left', 'center', 'center', 'center');
247 $table->width
= '90%';
248 $table->data
= $data;
249 $return .= print_table($table, true);
250 $outcomes_tables[] = $return;
253 foreach($outcomes_tables as $table) {
257 echo '<div class="buttons">';
258 print_single_button('edit.php', array('courseid'=>$courseid), $strcreatenewoutcome);
259 if ( !empty($outcomes_tables) ) {
260 print_single_button('export.php', array('id'=>$courseid, 'sesskey'=>sesskey()), get_string('exportalloutcomes', 'grades'));
264 $upload_form->display();
267 print_footer($course);
269 admin_externalpage_print_footer();