2 // Allows a creator to edit custom scales, and also display help about scales
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
.'/grade/lib.php';
29 require_once $CFG->libdir
.'/gradelib.php';
31 $courseid = optional_param('id', 0, PARAM_INT
);
32 $action = optional_param('action', '', PARAM_ALPHA
);
34 /// Make sure they can even access this course
36 if (!$course = get_record('course', 'id', $courseid)) {
37 print_error('nocourseid');
39 require_login($course);
40 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
41 require_capability('moodle/course:managescales', $context);
43 require_once $CFG->libdir
.'/adminlib.php';
44 admin_externalpage_setup('scales');
47 /// return tracking object
48 $gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'scale', 'courseid'=>$courseid));
51 $strgrades = get_string('grades');
52 $pagename = get_string('scales');
54 $navigation = grade_build_nav(__FILE__
, $pagename, array('courseid' => $courseid));
56 $strscale = get_string('scale');
57 $strstandardscale = get_string('scalesstandard');
58 $strcustomscales = get_string('scalescustom');
59 $strname = get_string('name');
60 $strdelete = get_string('delete');
61 $stredit = get_string('edit');
62 $srtcreatenewscale = get_string('scalescustomcreate');
63 $strused = get_string('used');
64 $stredit = get_string('edit');
68 if (!confirm_sesskey()) {
71 $scaleid = required_param('scaleid', PARAM_INT
);
72 if (!$scale = grade_scale
::fetch(array('id'=>$scaleid))) {
76 if (empty($scale->courseid
)) {
77 require_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM
));
78 } else if ($scale->courseid
!= $courseid) {
79 error('Incorrect courseid!');
82 if (!$scale->can_delete()) {
86 //TODO: add confirmation
93 print_header_simple($strgrades.': '.$pagename, ': '.$strgrades, $navigation, '', '', true, '', navmenu($course));
94 /// Print the plugin selector at the top
95 print_grade_plugin_selector($courseid, 'edit', 'scale');
98 admin_externalpage_print_header();
101 if ($courseid and $scales = grade_scale
::fetch_all_local($courseid)) {
102 print_heading($strcustomscales);
104 foreach($scales as $scale) {
106 $line[] = format_string($scale->name
).'<div class="scale_options">'.str_replace(",",", ",$scale->scale
).'</div>';
108 $used = $scale->is_used();
109 $line[] = $used ?
get_string('yes') : get_string('no');
112 $buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$courseid&id=$scale->id\"><img".
113 " src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
115 $buttons .= "<a title=\"$strdelete\" href=\"index.php?id=$courseid&scaleid=$scale->id&action=delete&sesskey=$USER->sesskey\"><img".
116 " src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
121 $table->head
= array($strscale, $strused, $stredit);
122 $table->size
= array('70%', '20%', '10%');
123 $table->align
= array('left', 'center', 'center');
124 $table->width
= '90%';
125 $table->data
= $data;
129 if ($scales = grade_scale
::fetch_all_global()) {
130 print_heading($strstandardscale);
132 foreach($scales as $scale) {
134 $line[] = format_string($scale->name
).'<div class="scale_options">'.str_replace(",",", ",$scale->scale
).'</div>';
136 $used = $scale->is_used();
137 $line[] = $used ?
get_string('yes') : get_string('no');
140 if (has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM
))) {
141 $buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$courseid&id=$scale->id\"><img".
142 " src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
144 if (!$used and has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM
))) {
145 $buttons .= "<a title=\"$strdelete\" href=\"index.php?id=$courseid&scaleid=$scale->id&action=delete&sesskey=$USER->sesskey\"><img".
146 " src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
151 $table->head
= array($strscale, $strused, $stredit);
152 $table->size
= array('70%', '20%', '10%');
153 $table->align
= array('left', 'center', 'center');
154 $table->width
= '90%';
155 $table->data
= $data;
159 echo '<div class="buttons">';
160 print_single_button('edit.php', array('courseid'=>$courseid), $srtcreatenewscale);
164 print_footer($course);
166 admin_externalpage_print_footer();