2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * A page for managing custom and standard scales
20 * @package core_grades
21 * @copyright 2007 Petr Skoda
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once '../../../config.php';
26 require_once $CFG->dirroot
.'/grade/lib.php';
27 require_once $CFG->libdir
.'/gradelib.php';
29 $courseid = optional_param('id', 0, PARAM_INT
);
30 $action = optional_param('action', '', PARAM_ALPHA
);
32 $PAGE->set_url('/grade/edit/scale/index.php', array('id' => $courseid));
34 /// Make sure they can even access this course
36 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
37 print_error('nocourseid');
39 require_login($course);
40 $context = context_course
::instance($course->id
);
41 require_capability('moodle/course:managescales', $context);
42 $PAGE->set_pagelayout('admin');
44 require_once $CFG->libdir
.'/adminlib.php';
45 admin_externalpage_setup('scales');
48 /// return tracking object
49 $gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'scale', 'courseid'=>$courseid));
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');
63 if (!confirm_sesskey()) {
66 $scaleid = required_param('scaleid', PARAM_INT
);
67 if (!$scale = grade_scale
::fetch(array('id'=>$scaleid))) {
71 if (empty($scale->courseid
)) {
72 require_capability('moodle/course:managescales', context_system
::instance());
73 } else if ($scale->courseid
!= $courseid) {
74 print_error('invalidcourseid');
77 if (!$scale->can_delete()) {
81 $deleteconfirmed = optional_param('deleteconfirmed', 0, PARAM_BOOL
);
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
,
92 'sesskey' => sesskey(),
93 'deleteconfirmed'=> 1));
95 echo $OUTPUT->confirm(get_string('scaleconfirmdelete', 'grades', $scale->name
), $confirmurl, "index.php?id={$courseid}");
96 echo $OUTPUT->footer();
105 echo $OUTPUT->header();
108 $table = new html_table();
109 $table2 = new html_table();
112 if ($courseid and $scales = grade_scale
::fetch_all_local($courseid)) {
113 $heading = $strcustomscales;
116 foreach($scales as $scale) {
118 $line[] = format_string($scale->name
).'<div class="scale_options">'.str_replace(",",", ",$scale->scale
).'</div>';
120 $used = $scale->is_used();
121 $line[] = $used ?
get_string('yes') : get_string('no');
124 $buttons .= grade_button('edit', $courseid, $scale);
126 $buttons .= grade_button('delete', $courseid, $scale);
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;
138 if ($scales = grade_scale
::fetch_all_global()) {
139 $heading = $strstandardscale;
142 foreach($scales as $scale) {
144 $line[] = format_string($scale->name
).'<div class="scale_options">'.str_replace(",",", ",$scale->scale
).'</div>';
146 $used = $scale->is_used();
147 $line[] = $used ?
get_string('yes') : get_string('no');
150 if (has_capability('moodle/course:managescales', context_system
::instance())) {
151 $buttons .= grade_button('edit', $courseid, $scale);
153 if (!$used and has_capability('moodle/course:managescales', context_system
::instance())) {
154 $buttons .= grade_button('delete', $courseid, $scale);
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;
168 print_grade_page_head($courseid, 'scale', 'scale', get_string('coursescales', 'grades'));
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();