2009-07-07 02:26:36 +00:00
|
|
|
<?php
|
2007-07-30 22:56:45 +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
|
|
|
|
2009-08-27 09:39:50 +00:00
|
|
|
/**
|
|
|
|
* Edit page for grade outcomes.
|
|
|
|
*
|
|
|
|
* @package moodlecore
|
|
|
|
* @copyright 2008 Nicolas Connault
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2007-07-30 22:56:45 +00:00
|
|
|
require_once '../../../config.php';
|
|
|
|
require_once $CFG->dirroot.'/grade/lib.php';
|
|
|
|
require_once $CFG->dirroot.'/grade/report/lib.php';
|
|
|
|
require_once 'edit_form.php';
|
|
|
|
|
|
|
|
$courseid = optional_param('courseid', 0, PARAM_INT);
|
|
|
|
$id = optional_param('id', 0, PARAM_INT);
|
|
|
|
|
|
|
|
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
2009-02-09 10:49:41 +00:00
|
|
|
$heading = null;
|
2007-07-30 22:56:45 +00:00
|
|
|
|
|
|
|
// a bit complex access control :-O
|
|
|
|
if ($id) {
|
2009-02-09 10:49:41 +00:00
|
|
|
$heading = get_string('editoutcome', 'grades');
|
|
|
|
|
2007-07-30 22:56:45 +00:00
|
|
|
/// editing existing outcome
|
2008-06-02 16:06:33 +00:00
|
|
|
if (!$outcome_rec = $DB->get_record('grade_outcomes', array('id' => $id))) {
|
2008-05-14 07:01:32 +00:00
|
|
|
print_error('invalidoutcome');
|
2007-07-30 22:56:45 +00:00
|
|
|
}
|
|
|
|
if ($outcome_rec->courseid) {
|
|
|
|
$outcome_rec->standard = 0;
|
2008-06-02 16:06:33 +00:00
|
|
|
if (!$course = $DB->get_record('course', array('id' => $outcome_rec->courseid))) {
|
2008-05-14 07:01:32 +00:00
|
|
|
print_error('invalidcourseid');
|
2007-07-30 22:56:45 +00:00
|
|
|
}
|
|
|
|
require_login($course);
|
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
|
|
|
require_capability('moodle/grade:manage', $context);
|
|
|
|
$courseid = $course->id;
|
|
|
|
} else {
|
|
|
|
if ($courseid) {
|
2008-06-02 16:06:33 +00:00
|
|
|
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
|
2008-05-14 07:01:32 +00:00
|
|
|
print_error('invalidcourseid');
|
2007-07-30 22:56:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$outcome_rec->standard = 1;
|
|
|
|
$outcome_rec->courseid = $courseid;
|
|
|
|
require_login();
|
|
|
|
require_capability('moodle/grade:manage', $systemcontext);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if ($courseid){
|
2009-02-09 10:49:41 +00:00
|
|
|
$heading = get_string('addoutcome', 'grades');
|
2007-07-30 22:56:45 +00:00
|
|
|
/// adding new outcome from course
|
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');
|
|
|
|
}
|
|
|
|
$outcome_rec = new object();
|
|
|
|
$outcome_rec->standard = 0;
|
|
|
|
$outcome_rec->courseid = $courseid;
|
|
|
|
require_login($course);
|
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
|
|
|
require_capability('moodle/grade:manage', $context);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/// adding new outcome from admin section
|
|
|
|
$outcome_rec = new object();
|
|
|
|
$outcome_rec->standard = 1;
|
|
|
|
$outcome_rec->courseid = 0;
|
|
|
|
require_login();
|
|
|
|
require_capability('moodle/grade:manage', $systemcontext);
|
|
|
|
}
|
|
|
|
|
|
|
|
// default return url
|
|
|
|
$gpr = new grade_plugin_return();
|
|
|
|
$returnurl = $gpr->get_return_url('index.php?id='.$courseid);
|
|
|
|
|
|
|
|
$mform = new edit_outcome_form(null, array('gpr'=>$gpr));
|
|
|
|
|
|
|
|
$mform->set_data($outcome_rec);
|
|
|
|
|
|
|
|
if ($mform->is_cancelled()) {
|
|
|
|
redirect($returnurl);
|
|
|
|
|
2008-06-09 16:53:30 +00:00
|
|
|
} else if ($data = $mform->get_data()) {
|
2007-07-30 22:56:45 +00:00
|
|
|
$outcome = new grade_outcome(array('id'=>$id));
|
|
|
|
$data->usermodified = $USER->id;
|
|
|
|
grade_outcome::set_properties($outcome, $data);
|
|
|
|
|
|
|
|
if (empty($outcome->id)) {
|
|
|
|
if (!has_capability('moodle/grade:manage', $systemcontext)) {
|
|
|
|
$data->standard = 0;
|
|
|
|
}
|
|
|
|
$outcome->courseid = !empty($data->standard) ? null : $courseid;
|
|
|
|
if (empty($outcome->courseid)) {
|
|
|
|
$outcome->courseid = null;
|
|
|
|
}
|
|
|
|
$outcome->insert();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (isset($data->standard)) {
|
|
|
|
$outcome->courseid = !empty($data->standard) ? null : $courseid;
|
|
|
|
} else {
|
2009-01-07 19:52:24 +00:00
|
|
|
unset($outcome->courseid); // keep previous
|
2007-07-30 22:56:45 +00:00
|
|
|
}
|
|
|
|
$outcome->update();
|
|
|
|
}
|
|
|
|
|
2007-07-31 12:03:45 +00:00
|
|
|
redirect($returnurl);
|
2007-07-30 22:56:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($courseid) {
|
2009-02-09 10:49:41 +00:00
|
|
|
print_grade_page_head($courseid, 'outcome', 'edit', $heading);
|
2007-07-30 22:56:45 +00:00
|
|
|
} else {
|
|
|
|
require_once $CFG->libdir.'/adminlib.php';
|
|
|
|
admin_externalpage_setup('outcomes');
|
|
|
|
admin_externalpage_print_header();
|
|
|
|
}
|
|
|
|
|
2008-10-17 14:33:05 +00:00
|
|
|
if (!grade_scale::fetch_all_local($courseid) && !grade_scale::fetch_all_global()) {
|
2009-08-20 08:40:49 +00:00
|
|
|
echo $OUTPUT->confirm(get_string('noscales', 'grades'), $CFG->wwwroot.'/grade/edit/scale/edit.php?courseid='.$courseid, $returnurl);
|
2009-08-06 14:21:57 +00:00
|
|
|
echo $OUTPUT->footer();
|
2008-10-17 14:33:05 +00:00
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
2007-07-30 22:56:45 +00:00
|
|
|
$mform->display();
|
2009-08-06 14:21:57 +00:00
|
|
|
echo $OUTPUT->footer();
|