MDL-16221
[moodle-linuxchix.git] / grade / edit / scale / index.php
blob2968220a155cec71d37175694550a5aad7810cbd
1 <?php // $Id$
2 // Allows a creator to edit custom scales, and also display help about scales
4 ///////////////////////////////////////////////////////////////////////////
5 // //
6 // NOTICE OF COPYRIGHT //
7 // //
8 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
9 // http://moodle.com //
10 // //
11 // Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
12 // //
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. //
17 // //
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: //
22 // //
23 // http://www.gnu.org/copyleft/gpl.html //
24 // //
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
35 if ($courseid) {
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);
42 } else {
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');
66 switch ($action) {
67 case 'delete':
68 if (!confirm_sesskey()) {
69 break;
71 $scaleid = required_param('scaleid', PARAM_INT);
72 if (!$scale = grade_scale::fetch(array('id'=>$scaleid))) {
73 break;
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()) {
83 break;
86 //TODO: add confirmation
87 $scale->delete();
88 break;
91 if ($courseid) {
92 /// Print header
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');
97 } else {
98 admin_externalpage_print_header();
101 if ($courseid and $scales = grade_scale::fetch_all_local($courseid)) {
102 print_heading($strcustomscales);
103 $data = array();
104 foreach($scales as $scale) {
105 $line = array();
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');
111 $buttons = "";
112 $buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$courseid&amp;id=$scale->id\"><img".
113 " src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
114 if (!$used) {
115 $buttons .= "<a title=\"$strdelete\" href=\"index.php?id=$courseid&amp;scaleid=$scale->id&amp;action=delete&amp;sesskey=$USER->sesskey\"><img".
116 " src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
118 $line[] = $buttons;
119 $data[] = $line;
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;
126 print_table($table);
129 if ($scales = grade_scale::fetch_all_global()) {
130 print_heading($strstandardscale);
131 $data = array();
132 foreach($scales as $scale) {
133 $line = array();
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');
139 $buttons = "";
140 if (has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
141 $buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$courseid&amp;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&amp;scaleid=$scale->id&amp;action=delete&amp;sesskey=$USER->sesskey\"><img".
146 " src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
148 $line[] = $buttons;
149 $data[] = $line;
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;
156 print_table($table);
159 echo '<div class="buttons">';
160 print_single_button('edit.php', array('courseid'=>$courseid), $srtcreatenewscale);
161 echo '</div>';
163 if ($courseid) {
164 print_footer($course);
165 } else {
166 admin_externalpage_print_footer();