2009-07-07 02:26:36 +00:00
|
|
|
<?php
|
2007-07-29 23:02:03 +00:00
|
|
|
|
2009-07-07 02:26:36 +00:00
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-10 06:34:20 +00:00
|
|
|
|
2007-07-29 23:02:03 +00:00
|
|
|
require_once '../../../config.php';
|
|
|
|
require_once $CFG->dirroot.'/grade/lib.php';
|
|
|
|
require_once $CFG->libdir.'/gradelib.php';
|
|
|
|
|
2007-07-30 22:56:45 +00:00
|
|
|
$courseid = optional_param('id', 0, PARAM_INT);
|
2007-07-29 23:02:03 +00:00
|
|
|
$action = optional_param('action', '', PARAM_ALPHA);
|
|
|
|
|
2010-01-16 15:39:56 +00:00
|
|
|
$PAGE->set_url('/grade/edit/scale/index.php', array('id' => $courseid));
|
2009-08-27 09:39:50 +00:00
|
|
|
|
2007-07-29 23:02:03 +00:00
|
|
|
/// Make sure they can even access this course
|
2007-07-30 22:56:45 +00:00
|
|
|
if ($courseid) {
|
2008-06-02 16:06:33 +00:00
|
|
|
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
|
2007-07-30 22:56:45 +00:00
|
|
|
print_error('nocourseid');
|
|
|
|
}
|
|
|
|
require_login($course);
|
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
|
|
|
require_capability('moodle/course:managescales', $context);
|
|
|
|
} else {
|
|
|
|
require_once $CFG->libdir.'/adminlib.php';
|
|
|
|
admin_externalpage_setup('scales');
|
2007-07-29 23:02:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// return tracking object
|
|
|
|
$gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'scale', 'courseid'=>$courseid));
|
|
|
|
|
|
|
|
$strscale = get_string('scale');
|
|
|
|
$strstandardscale = get_string('scalesstandard');
|
2007-07-30 22:56:45 +00:00
|
|
|
$strcustomscales = get_string('scalescustom');
|
2007-07-29 23:02:03 +00:00
|
|
|
$strname = get_string('name');
|
|
|
|
$strdelete = get_string('delete');
|
|
|
|
$stredit = get_string('edit');
|
|
|
|
$srtcreatenewscale = get_string('scalescustomcreate');
|
2007-09-18 18:37:58 +00:00
|
|
|
$strused = get_string('used');
|
2007-07-30 22:56:45 +00:00
|
|
|
$stredit = get_string('edit');
|
2007-07-29 23:02:03 +00:00
|
|
|
|
|
|
|
switch ($action) {
|
|
|
|
case 'delete':
|
|
|
|
if (!confirm_sesskey()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$scaleid = required_param('scaleid', PARAM_INT);
|
|
|
|
if (!$scale = grade_scale::fetch(array('id'=>$scaleid))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($scale->courseid)) {
|
|
|
|
require_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM));
|
2007-07-30 22:56:45 +00:00
|
|
|
} else if ($scale->courseid != $courseid) {
|
2008-05-14 07:04:09 +00:00
|
|
|
print_error('invalidcourseid');
|
2007-07-29 23:02:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$scale->can_delete()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-08-27 09:39:50 +00:00
|
|
|
$deleteconfirmed = optional_param('deleteconfirmed', 0, PARAM_BOOL);
|
|
|
|
|
|
|
|
if (!$deleteconfirmed) {
|
2009-09-07 06:04:46 +00:00
|
|
|
$PAGE->set_title(get_string('scaledelete', 'grades'));
|
|
|
|
echo $OUTPUT->header();
|
2009-08-27 09:39:50 +00:00
|
|
|
$confirmurl = new moodle_url('index.php', array(
|
|
|
|
'id' => $courseid, 'scaleid' => $scale->id,
|
|
|
|
'action'=> 'delete',
|
|
|
|
'sesskey' => sesskey(),
|
|
|
|
'deleteconfirmed'=> 1));
|
|
|
|
|
|
|
|
echo $OUTPUT->confirm(get_string('scaleconfirmdelete', 'grades', $scale->name), $confirmurl, "index.php?id={$courseid}");
|
|
|
|
echo $OUTPUT->footer();
|
|
|
|
die;
|
|
|
|
} else {
|
|
|
|
$scale->delete();
|
|
|
|
}
|
2007-07-29 23:02:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-02-09 10:49:41 +00:00
|
|
|
if (!$courseid) {
|
2007-07-30 22:56:45 +00:00
|
|
|
admin_externalpage_print_header();
|
|
|
|
}
|
2007-07-29 23:02:03 +00:00
|
|
|
|
2009-08-20 08:40:49 +00:00
|
|
|
$table = new html_table();
|
|
|
|
$table2 = new html_table();
|
2009-02-09 10:49:41 +00:00
|
|
|
$heading = '';
|
|
|
|
|
2007-07-30 22:56:45 +00:00
|
|
|
if ($courseid and $scales = grade_scale::fetch_all_local($courseid)) {
|
2009-02-09 10:49:41 +00:00
|
|
|
$heading = $strcustomscales;
|
|
|
|
|
2007-07-29 23:02:03 +00:00
|
|
|
$data = array();
|
|
|
|
foreach($scales as $scale) {
|
|
|
|
$line = array();
|
|
|
|
$line[] = format_string($scale->name).'<div class="scale_options">'.str_replace(",",", ",$scale->scale).'</div>';
|
|
|
|
|
2007-09-18 18:37:58 +00:00
|
|
|
$used = $scale->is_used();
|
|
|
|
$line[] = $used ? get_string('yes') : get_string('no');
|
2007-07-29 23:02:03 +00:00
|
|
|
|
|
|
|
$buttons = "";
|
2009-08-27 09:39:50 +00:00
|
|
|
$buttons .= grade_button('edit', $courseid, $scale);
|
2007-09-18 18:37:58 +00:00
|
|
|
if (!$used) {
|
2009-08-27 09:39:50 +00:00
|
|
|
$buttons .= grade_button('delete', $courseid, $scale);
|
2007-07-29 23:02:03 +00:00
|
|
|
}
|
|
|
|
$line[] = $buttons;
|
|
|
|
$data[] = $line;
|
|
|
|
}
|
2007-09-18 18:37:58 +00:00
|
|
|
$table->head = array($strscale, $strused, $stredit);
|
2007-07-29 23:02:03 +00:00
|
|
|
$table->size = array('70%', '20%', '10%');
|
|
|
|
$table->align = array('left', 'center', 'center');
|
|
|
|
$table->width = '90%';
|
|
|
|
$table->data = $data;
|
|
|
|
}
|
|
|
|
|
2007-07-30 22:56:45 +00:00
|
|
|
if ($scales = grade_scale::fetch_all_global()) {
|
2009-02-09 10:49:41 +00:00
|
|
|
$heading = $strstandardscale;
|
|
|
|
|
2007-07-29 23:02:03 +00:00
|
|
|
$data = array();
|
|
|
|
foreach($scales as $scale) {
|
|
|
|
$line = array();
|
|
|
|
$line[] = format_string($scale->name).'<div class="scale_options">'.str_replace(",",", ",$scale->scale).'</div>';
|
|
|
|
|
2007-09-18 18:37:58 +00:00
|
|
|
$used = $scale->is_used();
|
|
|
|
$line[] = $used ? get_string('yes') : get_string('no');
|
2007-07-29 23:02:03 +00:00
|
|
|
|
|
|
|
$buttons = "";
|
2007-07-30 22:56:45 +00:00
|
|
|
if (has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
|
2009-08-27 09:39:50 +00:00
|
|
|
$buttons .= grade_button('edit', $courseid, $scale);
|
2007-07-30 22:56:45 +00:00
|
|
|
}
|
2007-09-18 18:37:58 +00:00
|
|
|
if (!$used and has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
|
2009-08-27 09:39:50 +00:00
|
|
|
$buttons .= grade_button('delete', $courseid, $scale);
|
2007-07-29 23:02:03 +00:00
|
|
|
}
|
|
|
|
$line[] = $buttons;
|
|
|
|
$data[] = $line;
|
|
|
|
}
|
2009-02-09 10:49:41 +00:00
|
|
|
$table2->head = array($strscale, $strused, $stredit);
|
|
|
|
$table2->size = array('70%', '20%', '10%');
|
|
|
|
$table2->align = array('left', 'center', 'center');
|
|
|
|
$table2->width = '90%';
|
|
|
|
$table2->data = $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($courseid) {
|
|
|
|
print_grade_page_head($courseid, 'scale', null, get_string('coursescales', 'grades'));
|
2007-07-29 23:02:03 +00:00
|
|
|
}
|
|
|
|
|
2009-08-06 08:16:46 +00:00
|
|
|
echo $OUTPUT->heading($strcustomscales, 3, 'main');
|
2010-03-20 22:15:54 +00:00
|
|
|
echo html_writer::table($table);
|
2009-08-06 08:16:46 +00:00
|
|
|
echo $OUTPUT->heading($strstandardscale, 3, 'main');
|
2010-03-20 22:15:54 +00:00
|
|
|
echo html_writer::table($table2);
|
2009-08-20 08:40:49 +00:00
|
|
|
echo $OUTPUT->container_start('buttons');
|
2010-01-03 15:46:14 +00:00
|
|
|
echo $OUTPUT->single_button(new moodle_url('edit.php', array('courseid'=>$courseid)), $srtcreatenewscale);
|
2009-08-27 09:39:50 +00:00
|
|
|
echo $OUTPUT->container_end();
|
|
|
|
echo $OUTPUT->footer();
|