Differences Between: [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Listing page for grade outcomes. 19 * 20 * @package core_grades 21 * @copyright 2008 Nicolas Connault 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 require_once(__DIR__.'/../../../config.php'); 26 require_once($CFG->dirroot.'/grade/lib.php'); 27 require_once($CFG->libdir.'/gradelib.php'); 28 29 $courseid = optional_param('id', 0, PARAM_INT); 30 $action = optional_param('action', '', PARAM_ALPHA); 31 32 $PAGE->set_url('/grade/edit/outcome/index.php', array('id' => $courseid)); 33 $PAGE->set_pagelayout('admin'); 34 35 /// Make sure they can even access this course 36 if ($courseid) { 37 $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); 38 require_login($course); 39 $context = context_course::instance($course->id); 40 require_capability('moodle/grade:manageoutcomes', $context); 41 42 if (empty($CFG->enableoutcomes)) { 43 redirect('../../index.php?id='.$courseid); 44 } 45 // This page doesn't exist on the navigation so map it to another 46 navigation_node::override_active_url(new moodle_url('/grade/edit/outcome/course.php', array('id'=>$courseid))); 47 } else { 48 if (empty($CFG->enableoutcomes)) { 49 redirect('../../../'); 50 } 51 require_once $CFG->libdir.'/adminlib.php'; 52 admin_externalpage_setup('outcomes'); 53 } 54 55 /// return tracking object 56 $gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'outcome', 'courseid'=>$courseid)); 57 58 $strshortname = get_string('outcomeshortname', 'grades'); 59 $strfullname = get_string('outcomefullname', 'grades'); 60 $strscale = get_string('scale'); 61 $strstandardoutcome = get_string('outcomesstandard', 'grades'); 62 $strcustomoutcomes = get_string('outcomescustom', 'grades'); 63 $strcreatenewoutcome = get_string('outcomecreate', 'grades'); 64 $stritems = get_string('items', 'grades'); 65 $strcourses = get_string('courses'); 66 $stredit = get_string('edit'); 67 68 switch ($action) { 69 case 'delete': 70 if (!confirm_sesskey()) { 71 break; 72 } 73 $outcomeid = required_param('outcomeid', PARAM_INT); 74 if (!$outcome = grade_outcome::fetch(array('id'=>$outcomeid))) { 75 break; 76 } 77 78 if (empty($outcome->courseid)) { 79 require_capability('moodle/grade:manage', context_system::instance()); 80 } else if ($outcome->courseid != $courseid) { 81 print_error('invalidcourseid'); 82 } 83 84 if (!$outcome->can_delete()) { 85 break; 86 } 87 88 $deleteconfirmed = optional_param('deleteconfirmed', 0, PARAM_BOOL); 89 90 if(!$deleteconfirmed){ 91 $PAGE->set_title(get_string('outcomedelete', 'grades')); 92 echo $OUTPUT->header(); 93 $confirmurl = new moodle_url('index.php', array( 94 'id' => $courseid, 'outcomeid' => $outcome->id, 95 'action'=> 'delete', 96 'sesskey' => sesskey(), 97 'deleteconfirmed'=> 1)); 98 99 echo $OUTPUT->confirm(get_string('outcomeconfirmdelete', 'grades', $outcome->fullname), $confirmurl, "index.php?id={$courseid}"); 100 echo $OUTPUT->footer(); 101 die; 102 }else{ 103 $outcome->delete(); 104 } 105 break; 106 } 107 108 $systemcontext = context_system::instance(); 109 $caneditsystemscales = has_capability('moodle/course:managescales', $systemcontext); 110 111 if ($courseid) { 112 113 $caneditcoursescales = has_capability('moodle/course:managescales', $context); 114 115 } else { 116 echo $OUTPUT->header(); 117 $caneditcoursescales = $caneditsystemscales; 118 } 119 120 121 $outcomes_tables = array(); 122 $heading = get_string('outcomes', 'grades'); 123 124 if ($courseid and $outcomes = grade_outcome::fetch_all_local($courseid)) { 125 $return = $OUTPUT->heading($strcustomoutcomes, 3, 'main'); 126 $data = array(); 127 foreach($outcomes as $outcome) { 128 $line = array(); 129 $line[] = $outcome->get_name(); 130 $line[] = $outcome->get_shortname(); 131 132 $scale = $outcome->load_scale(); 133 if (empty($scale->id)) { // hopefully never happens 134 $line[] = $scale->get_name(); 135 debugging("Found a scale with no ID ({$scale->get_name()}) while outputting course outcomes", DEBUG_DEVELOPER); 136 } else { 137 if (empty($scale->courseid)) { 138 $caneditthisscale = $caneditsystemscales; 139 } else if ($scale->courseid == $courseid) { 140 $caneditthisscale = $caneditcoursescales; 141 } else { 142 $context = context_course::instance($scale->courseid); 143 $caneditthisscale = has_capability('moodle/course:managescales', $context); 144 } 145 if ($caneditthisscale) { 146 $line[] = grade_print_scale_link($courseid, $scale, $gpr); 147 } else { 148 $line[] = $scale->get_name(); 149 } 150 } 151 152 $line[] = $outcome->get_item_uses_count(); 153 154 $buttons = grade_button('edit', $courseid, $outcome); 155 156 if ($outcome->can_delete()) { 157 $buttons .= grade_button('delete', $courseid, $outcome); 158 } 159 $line[] = $buttons; 160 161 $data[] = $line; 162 } 163 $table = new html_table(); 164 $table->head = array($strfullname, $strshortname, $strscale, $stritems, $stredit); 165 $table->size = array('30%', '20%', '20%', '20%', '10%' ); 166 $table->align = array('left', 'left', 'left', 'center', 'center'); 167 $table->width = '90%'; 168 $table->data = $data; 169 $return .= html_writer::table($table); 170 $outcomes_tables[] = $return; 171 } 172 173 174 if ($outcomes = grade_outcome::fetch_all_global()) { 175 $return = $OUTPUT->heading($strstandardoutcome, 3, 'main'); 176 $data = array(); 177 foreach($outcomes as $outcome) { 178 $line = array(); 179 $line[] = $outcome->get_name(); 180 $line[] = $outcome->get_shortname(); 181 182 $scale = $outcome->load_scale(); 183 if (empty($scale->id)) { // hopefully never happens 184 $line[] = $scale->get_name(); 185 debugging("Found a scale with no ID ({$scale->get_name()}) while outputting global outcomes", DEBUG_DEVELOPER); 186 } else { 187 if (empty($scale->courseid)) { 188 $caneditthisscale = $caneditsystemscales; 189 } else if ($scale->courseid == $courseid) { 190 $caneditthisscale = $caneditcoursescales; 191 } else { 192 $context = context_course::instance($scale->courseid); 193 $caneditthisscale = has_capability('moodle/course:managescales', $context); 194 } 195 if ($caneditthisscale) { 196 $line[] = grade_print_scale_link($courseid, $scale, $gpr); 197 } else { 198 $line[] = $scale->get_name(); 199 } 200 } 201 202 $line[] = $outcome->get_course_uses_count(); 203 $line[] = $outcome->get_item_uses_count(); 204 205 $buttons = ""; 206 if (has_capability('moodle/grade:manage', context_system::instance())) { 207 $buttons .= grade_button('edit', $courseid, $outcome); 208 } 209 if (has_capability('moodle/grade:manage', context_system::instance()) and $outcome->can_delete()) { 210 $buttons .= grade_button('delete', $courseid, $outcome); 211 } 212 $line[] = $buttons; 213 214 $data[] = $line; 215 } 216 $table = new html_table(); 217 $table->head = array($strfullname, $strshortname, $strscale, $strcourses, $stritems, $stredit); 218 $table->size = array('30%', '20%', '20%', '10%', '10%', '10%'); 219 $table->align = array('left', 'left', 'left', 'center', 'center', 'center'); 220 $table->width = '90%'; 221 $table->data = $data; 222 $return .= html_writer::table($table); 223 $outcomes_tables[] = $return; 224 } 225 226 if ($courseid) { 227 /// Print header 228 print_grade_page_head($courseid, 'outcome', 'edit', $heading); 229 } 230 231 foreach($outcomes_tables as $table) { 232 echo $table; 233 } 234 235 echo $OUTPUT->container_start('buttons'); 236 echo $OUTPUT->single_button(new moodle_url('edit.php', array('courseid'=>$courseid)), $strcreatenewoutcome); 237 if ( !empty($outcomes_tables) ) { 238 echo $OUTPUT->single_button(new moodle_url('export.php', array('id'=>$courseid, 'sesskey'=>sesskey())), get_string('exportalloutcomes', 'grades')); 239 } 240 echo $OUTPUT->container_end(); 241 242 echo $OUTPUT->footer(); 243 244 /** 245 * Local shortcut function for creating a link to a scale. 246 * @param int $courseid The Course ID 247 * @param grade_scale $scale The Scale to link to 248 * @param grade_plugin_return $gpr An object used to identify the page we just came from 249 * @return string html 250 */ 251 function grade_print_scale_link($courseid, $scale, $gpr) { 252 global $CFG, $OUTPUT; 253 $url = new moodle_url('/grade/edit/scale/edit.php', array('courseid' => $courseid, 'id' => $scale->id)); 254 $url = $gpr->add_url_params($url); 255 return html_writer::link($url, $scale->get_name()); 256 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body