[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 print_error('nocourseid'); 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 } 47 48 /// return tracking object 49 $gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'scale', 'courseid'=>$courseid)); 50 51 $strscale = get_string('scale'); 52 $strstandardscale = get_string('scalesstandard'); 53 $strcustomscales = get_string('scalescustom'); 54 $strname = get_string('name'); 55 $strdelete = get_string('delete'); 56 $stredit = get_string('edit'); 57 $srtcreatenewscale = get_string('scalescustomcreate'); 58 $strused = get_string('used'); 59 $stredit = get_string('edit'); 60 61 switch ($action) { 62 case 'delete': 63 if (!confirm_sesskey()) { 64 break; 65 } 66 $scaleid = required_param('scaleid', PARAM_INT); 67 if (!$scale = grade_scale::fetch(array('id'=>$scaleid))) { 68 break; 69 } 70 71 if (empty($scale->courseid)) { 72 require_capability('moodle/course:managescales', context_system::instance()); 73 } else if ($scale->courseid != $courseid) { 74 print_error('invalidcourseid'); 75 } 76 77 if (!$scale->can_delete()) { 78 break; 79 } 80 81 $deleteconfirmed = optional_param('deleteconfirmed', 0, PARAM_BOOL); 82 83 if (!$deleteconfirmed) { 84 $strdeletescale = get_string('delete'). ' '. get_string('scale'); 85 $PAGE->navbar->add($strdeletescale); 86 $PAGE->set_title($strdeletescale); 87 $PAGE->set_heading($COURSE->fullname); 88 echo $OUTPUT->header(); 89 $confirmurl = new moodle_url('index.php', array( 90 'id' => $courseid, 'scaleid' => $scale->id, 91 'action'=> 'delete', 92 'sesskey' => sesskey(), 93 'deleteconfirmed'=> 1)); 94 95 echo $OUTPUT->confirm(get_string('scaleconfirmdelete', 'grades', $scale->name), $confirmurl, "index.php?id={$courseid}"); 96 echo $OUTPUT->footer(); 97 die; 98 } else { 99 $scale->delete(); 100 } 101 break; 102 } 103 104 if (!$courseid) { 105 echo $OUTPUT->header(); 106 } 107 108 $table = new html_table(); 109 $table2 = new html_table(); 110 $heading = ''; 111 112 if ($courseid and $scales = grade_scale::fetch_all_local($courseid)) { 113 $heading = $strcustomscales; 114 115 $data = array(); 116 foreach($scales as $scale) { 117 $line = array(); 118 $line[] = format_string($scale->name).'<div class="scale_options">'.str_replace(",",", ",$scale->scale).'</div>'; 119 120 $used = $scale->is_used(); 121 $line[] = $used ? get_string('yes') : get_string('no'); 122 123 $buttons = ""; 124 $buttons .= grade_button('edit', $courseid, $scale); 125 if (!$used) { 126 $buttons .= grade_button('delete', $courseid, $scale); 127 } 128 $line[] = $buttons; 129 $data[] = $line; 130 } 131 $table->head = array($strscale, $strused, $stredit); 132 $table->size = array('70%', '20%', '10%'); 133 $table->align = array('left', 'center', 'center'); 134 $table->attributes['class'] = 'scaletable localscales generaltable'; 135 $table->data = $data; 136 } 137 138 if ($scales = grade_scale::fetch_all_global()) { 139 $heading = $strstandardscale; 140 141 $data = array(); 142 foreach($scales as $scale) { 143 $line = array(); 144 $line[] = format_string($scale->name).'<div class="scale_options">'.str_replace(",",", ",$scale->scale).'</div>'; 145 146 $used = $scale->is_used(); 147 $line[] = $used ? get_string('yes') : get_string('no'); 148 149 $buttons = ""; 150 if (has_capability('moodle/course:managescales', context_system::instance())) { 151 $buttons .= grade_button('edit', $courseid, $scale); 152 } 153 if (!$used and has_capability('moodle/course:managescales', context_system::instance())) { 154 $buttons .= grade_button('delete', $courseid, $scale); 155 } 156 $line[] = $buttons; 157 $data[] = $line; 158 } 159 $table2->head = array($strscale, $strused, $stredit); 160 $table->attributes['class'] = 'scaletable globalscales generaltable'; 161 $table2->size = array('70%', '20%', '10%'); 162 $table2->align = array('left', 'center', 'center'); 163 $table2->data = $data; 164 } 165 166 167 if ($courseid) { 168 print_grade_page_head($courseid, 'scale', 'scale', get_string('coursescales', 'grades')); 169 } 170 171 echo $OUTPUT->heading($strcustomscales, 3, 'main'); 172 echo html_writer::table($table); 173 echo $OUTPUT->heading($strstandardscale, 3, 'main'); 174 echo html_writer::table($table2); 175 echo $OUTPUT->container_start('buttons'); 176 echo $OUTPUT->single_button(new moodle_url('edit.php', array('courseid'=>$courseid)), $srtcreatenewscale); 177 echo $OUTPUT->container_end(); 178 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |