See Release Notes
Long Term Support Release
Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 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 * A page for managing custom and standard scales 19 * 20 * @package core_grades 21 * @copyright 2007 Petr Skoda 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 require_once '../../../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/scale/index.php', array('id' => $courseid)); 33 34 /// Make sure they can even access this course 35 if ($courseid) { 36 if (!$course = $DB->get_record('course', array('id' => $courseid))) { 37 throw new \moodle_exception('invalidcourseid'); 38 } 39 require_login($course); 40 $context = context_course::instance($course->id); 41 require_capability('moodle/course:managescales', $context); 42 $PAGE->set_pagelayout('admin'); 43 } else { 44 require_once $CFG->libdir.'/adminlib.php'; 45 admin_externalpage_setup('scales'); 46 $context = context_system::instance(); 47 $PAGE->set_primary_active_tab('siteadminnode'); 48 } 49 50 /// return tracking object 51 $gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'scale', 'courseid'=>$courseid)); 52 53 $strscale = get_string('scale'); 54 $strstandardscale = get_string('scalesstandard'); 55 $strcustomscales = get_string('scalescustom'); 56 $strname = get_string('name'); 57 $strdelete = get_string('delete'); 58 $stredit = get_string('edit'); 59 $strused = get_string('used'); 60 $stredit = get_string('edit'); 61 62 switch ($action) { 63 case 'delete': 64 if (!confirm_sesskey()) { 65 break; 66 } 67 $scaleid = required_param('scaleid', PARAM_INT); 68 if (!$scale = grade_scale::fetch(array('id'=>$scaleid))) { 69 break; 70 } 71 72 if (empty($scale->courseid)) { 73 require_capability('moodle/course:managescales', context_system::instance()); 74 } else if ($scale->courseid != $courseid) { 75 throw new \moodle_exception('invalidcourseid'); 76 } 77 78 if (!$scale->can_delete()) { 79 break; 80 } 81 82 $deleteconfirmed = optional_param('deleteconfirmed', 0, PARAM_BOOL); 83 84 if (!$deleteconfirmed) { 85 if ($courseid) { 86 $PAGE->navbar->add(get_string('scales'), new moodle_url('/grade/edit/scale/index.php', 87 ['id' => $courseid])); 88 } 89 $strdeletescale = get_string('deletescale', 'grades'); 90 $PAGE->navbar->add($strdeletescale); 91 $PAGE->set_title($strdeletescale); 92 $PAGE->set_heading($COURSE->fullname); 93 echo $OUTPUT->header(); 94 $confirmurl = new moodle_url('index.php', array( 95 'id' => $courseid, 'scaleid' => $scale->id, 96 'action'=> 'delete', 97 'sesskey' => sesskey(), 98 'deleteconfirmed'=> 1)); 99 100 echo $OUTPUT->confirm(get_string('scaleconfirmdelete', 'grades', $scale->get_name()), $confirmurl, 101 "index.php?id={$courseid}"); 102 echo $OUTPUT->footer(); 103 die; 104 } else { 105 $scale->delete(); 106 } 107 break; 108 } 109 110 if (!$courseid) { 111 echo $OUTPUT->header(); 112 } 113 114 $table = new html_table(); 115 $table2 = new html_table(); 116 $heading = ''; 117 118 if ($courseid and $scales = grade_scale::fetch_all_local($courseid)) { 119 $heading = $strcustomscales; 120 121 $data = array(); 122 foreach($scales as $scale) { 123 $line = array(); 124 $line[] = $scale->get_name() .'<div class="scale_options">'.str_replace(",", ", ", $scale->scale).'</div>'; 125 126 $used = $scale->is_used(); 127 $line[] = $used ? get_string('yes') : get_string('no'); 128 129 $buttons = ""; 130 $buttons .= grade_button('edit', $courseid, $scale); 131 if (!$used) { 132 $buttons .= grade_button('delete', $courseid, $scale); 133 } 134 $line[] = $buttons; 135 $data[] = $line; 136 } 137 $table->head = array($strscale, $strused, $stredit); 138 $table->size = array('70%', '20%', '10%'); 139 $table->align = array('left', 'center', 'center'); 140 $table->attributes['class'] = 'scaletable localscales generaltable'; 141 $table->data = $data; 142 } 143 144 if ($scales = grade_scale::fetch_all_global()) { 145 $heading = $strstandardscale; 146 147 $data = array(); 148 foreach($scales as $scale) { 149 $line = array(); 150 $line[] = $scale->get_name().'<div class="scale_options">'.str_replace(",", ", ", $scale->scale).'</div>'; 151 152 $used = $scale->is_used(); 153 $line[] = $used ? get_string('yes') : get_string('no'); 154 155 $buttons = ""; 156 if (has_capability('moodle/course:managescales', context_system::instance())) { 157 $buttons .= grade_button('edit', $courseid, $scale); 158 } 159 if (!$used and has_capability('moodle/course:managescales', context_system::instance())) { 160 $buttons .= grade_button('delete', $courseid, $scale); 161 } 162 $line[] = $buttons; 163 $data[] = $line; 164 } 165 $table2->head = array($strscale, $strused, $stredit); 166 $table->attributes['class'] = 'scaletable globalscales generaltable'; 167 $table2->size = array('70%', '20%', '10%'); 168 $table2->align = array('left', 'center', 'center'); 169 $table2->data = $data; 170 } 171 172 $actionbar = new \core_grades\output\scales_action_bar($context); 173 174 if ($courseid) { 175 print_grade_page_head($courseid, 'scale', 'scale', get_string('coursescales', 'grades'), 176 false, false, true, null, null, null, $actionbar); 177 } else { 178 $renderer = $PAGE->get_renderer('core_grades'); 179 echo $renderer->render_action_bar($actionbar); 180 echo $OUTPUT->heading(get_string('scales', 'core')); 181 } 182 183 $hascustomscales = !empty($table->data); 184 $hasstandardscales = !empty($table2->data); 185 186 // If there are custom scales available in this context, output the custom scales table and a heading. 187 if ($hascustomscales) { 188 echo $OUTPUT->heading($strcustomscales, 3, 'main mt-3'); 189 echo html_writer::table($table); 190 } 191 // If there are standard scales available in this context, output the standard scales table and a heading. 192 if ($hasstandardscales) { 193 echo $OUTPUT->heading($strstandardscale, 3, 'main mt-3'); 194 echo html_writer::table($table2); 195 } 196 // If the are no available scales, display a notification. 197 if (!$hascustomscales && !$hasstandardscales) { 198 echo $OUTPUT->notification(get_string('noexistingscales', 'grades'), 'info', false); 199 } 200 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body