MDL-11517 reserved word MOD used in table alias in questions backup code
[moodle-pu.git] / grade / edit / scale / index.php
blobfd1eb272bd13792dee95f05989c32cf5147f3fe9
1 <?php // $Id$
2 // Allows a creator to edit custom scales, and also display help about scales
4 require_once '../../../config.php';
5 require_once $CFG->dirroot.'/grade/lib.php';
6 require_once $CFG->libdir.'/gradelib.php';
8 $courseid = optional_param('id', 0, PARAM_INT);
9 $action = optional_param('action', '', PARAM_ALPHA);
11 /// Make sure they can even access this course
12 if ($courseid) {
13 if (!$course = get_record('course', 'id', $courseid)) {
14 print_error('nocourseid');
16 require_login($course);
17 $context = get_context_instance(CONTEXT_COURSE, $course->id);
18 require_capability('moodle/course:managescales', $context);
19 } else {
20 require_once $CFG->libdir.'/adminlib.php';
21 admin_externalpage_setup('scales');
24 /// return tracking object
25 $gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'scale', 'courseid'=>$courseid));
28 $strgrades = get_string('grades');
29 $pagename = get_string('scales');
31 $navigation = grade_build_nav(__FILE__, $pagename, array('courseid' => $courseid));
33 $strscale = get_string('scale');
34 $strstandardscale = get_string('scalesstandard');
35 $strcustomscales = get_string('scalescustom');
36 $strname = get_string('name');
37 $strdelete = get_string('delete');
38 $stredit = get_string('edit');
39 $srtcreatenewscale = get_string('scalescustomcreate');
40 $strused = get_string('used');
41 $stredit = get_string('edit');
43 switch ($action) {
44 case 'delete':
45 if (!confirm_sesskey()) {
46 break;
48 $scaleid = required_param('scaleid', PARAM_INT);
49 if (!$scale = grade_scale::fetch(array('id'=>$scaleid))) {
50 break;
53 if (empty($scale->courseid)) {
54 require_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM));
55 } else if ($scale->courseid != $courseid) {
56 error('Incorrect courseid!');
59 if (!$scale->can_delete()) {
60 break;
63 //TODO: add confirmation
64 $scale->delete();
65 break;
68 if ($courseid) {
69 /// Print header
70 print_header_simple($strgrades.': '.$pagename, ': '.$strgrades, $navigation, '', '', true, '', navmenu($course));
71 /// Print the plugin selector at the top
72 print_grade_plugin_selector($courseid, 'edit', 'scale');
74 } else {
75 admin_externalpage_print_header();
78 if ($courseid and $scales = grade_scale::fetch_all_local($courseid)) {
79 print_heading($strcustomscales);
80 $data = array();
81 foreach($scales as $scale) {
82 $line = array();
83 $line[] = format_string($scale->name).'<div class="scale_options">'.str_replace(",",", ",$scale->scale).'</div>';
85 $used = $scale->is_used();
86 $line[] = $used ? get_string('yes') : get_string('no');
88 $buttons = "";
89 $buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$courseid&amp;id=$scale->id\"><img".
90 " src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
91 if (!$used) {
92 $buttons .= "<a title=\"$strdelete\" href=\"index.php?id=$courseid&amp;scaleid=$scale->id&amp;action=delete&amp;sesskey=$USER->sesskey\"><img".
93 " src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
95 $line[] = $buttons;
96 $data[] = $line;
98 $table->head = array($strscale, $strused, $stredit);
99 $table->size = array('70%', '20%', '10%');
100 $table->align = array('left', 'center', 'center');
101 $table->width = '90%';
102 $table->data = $data;
103 print_table($table);
106 if ($scales = grade_scale::fetch_all_global()) {
107 print_heading($strstandardscale);
108 $data = array();
109 foreach($scales as $scale) {
110 $line = array();
111 $line[] = format_string($scale->name).'<div class="scale_options">'.str_replace(",",", ",$scale->scale).'</div>';
113 $used = $scale->is_used();
114 $line[] = $used ? get_string('yes') : get_string('no');
116 $buttons = "";
117 if (has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
118 $buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$courseid&amp;id=$scale->id\"><img".
119 " src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
121 if (!$used and has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
122 $buttons .= "<a title=\"$strdelete\" href=\"index.php?id=$courseid&amp;scaleid=$scale->id&amp;action=delete&amp;sesskey=$USER->sesskey\"><img".
123 " src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
125 $line[] = $buttons;
126 $data[] = $line;
128 $table->head = array($strscale, $strused, $stredit);
129 $table->size = array('70%', '20%', '10%');
130 $table->align = array('left', 'center', 'center');
131 $table->width = '90%';
132 $table->data = $data;
133 print_table($table);
136 echo '<div class="buttons">';
137 print_single_button('edit.php', array('courseid'=>$courseid), $srtcreatenewscale);
138 echo '</div>';
140 if ($courseid) {
141 print_footer($course);
142 } else {
143 admin_externalpage_print_footer();