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
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);
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');
45 if (!confirm_sesskey()) {
48 $scaleid = required_param('scaleid', PARAM_INT
);
49 if (!$scale = grade_scale
::fetch(array('id'=>$scaleid))) {
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()) {
63 //TODO: add confirmation
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');
75 admin_externalpage_print_header();
78 if ($courseid and $scales = grade_scale
::fetch_all_local($courseid)) {
79 print_heading($strcustomscales);
81 foreach($scales as $scale) {
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');
89 $buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$courseid&id=$scale->id\"><img".
90 " src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
92 $buttons .= "<a title=\"$strdelete\" href=\"index.php?id=$courseid&scaleid=$scale->id&action=delete&sesskey=$USER->sesskey\"><img".
93 " src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
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;
106 if ($scales = grade_scale
::fetch_all_global()) {
107 print_heading($strstandardscale);
109 foreach($scales as $scale) {
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');
117 if (has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM
))) {
118 $buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$courseid&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&scaleid=$scale->id&action=delete&sesskey=$USER->sesskey\"><img".
123 " src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
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;
136 echo '<div class="buttons">';
137 print_single_button('edit.php', array('courseid'=>$courseid), $srtcreatenewscale);
141 print_footer($course);
143 admin_externalpage_print_footer();