|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00026 require_once '../../../config.php'; 00027 require_once $CFG->dirroot.'/grade/lib.php'; 00028 require_once $CFG->dirroot.'/grade/report/lib.php'; 00029 require_once 'edit_form.php'; 00030 00031 $courseid = optional_param('courseid', 0, PARAM_INT); 00032 $id = optional_param('id', 0, PARAM_INT); 00033 00034 $url = new moodle_url('/grade/edit/outcome/edit.php'); 00035 if ($courseid !== 0) { 00036 $url->param('courseid', $courseid); 00037 } 00038 if ($id !== 0) { 00039 $url->param('id', $id); 00040 } 00041 $PAGE->set_url($url); 00042 $PAGE->set_pagelayout('admin'); 00043 00044 $systemcontext = get_context_instance(CONTEXT_SYSTEM); 00045 $heading = null; 00046 00047 // a bit complex access control :-O 00048 if ($id) { 00049 $heading = get_string('editoutcome', 'grades'); 00050 00052 if (!$outcome_rec = $DB->get_record('grade_outcomes', array('id' => $id))) { 00053 print_error('invalidoutcome'); 00054 } 00055 if ($outcome_rec->courseid) { 00056 $outcome_rec->standard = 0; 00057 if (!$course = $DB->get_record('course', array('id' => $outcome_rec->courseid))) { 00058 print_error('invalidcourseid'); 00059 } 00060 require_login($course); 00061 $context = get_context_instance(CONTEXT_COURSE, $course->id); 00062 require_capability('moodle/grade:manage', $context); 00063 $courseid = $course->id; 00064 } else { 00065 if ($courseid) { 00066 if (!$course = $DB->get_record('course', array('id' => $courseid))) { 00067 print_error('invalidcourseid'); 00068 } 00069 } 00070 $outcome_rec->standard = 1; 00071 $outcome_rec->courseid = $courseid; 00072 require_login(); 00073 require_capability('moodle/grade:manage', $systemcontext); 00074 } 00075 00076 } else if ($courseid){ 00077 $heading = get_string('addoutcome', 'grades'); 00079 $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); 00080 require_login($course); 00081 $context = get_context_instance(CONTEXT_COURSE, $course->id); 00082 require_capability('moodle/grade:manage', $context); 00083 navigation_node::override_active_url(new moodle_url('/grade/edit/outcome/course.php', array('id'=>$courseid))); 00084 00085 $outcome_rec = new stdClass(); 00086 $outcome_rec->standard = 0; 00087 $outcome_rec->courseid = $courseid; 00088 } else { 00089 require_login(); 00090 require_capability('moodle/grade:manage', $systemcontext); 00091 00093 $outcome_rec = new stdClass(); 00094 $outcome_rec->standard = 1; 00095 $outcome_rec->courseid = 0; 00096 } 00097 00098 if (!$courseid) { 00099 require_once $CFG->libdir.'/adminlib.php'; 00100 admin_externalpage_setup('scales'); 00101 } 00102 00103 // default return url 00104 $gpr = new grade_plugin_return(); 00105 $returnurl = $gpr->get_return_url('index.php?id='.$courseid); 00106 $editoroptions = array( 00107 'maxfiles' => EDITOR_UNLIMITED_FILES, 00108 'maxbytes' => $CFG->maxbytes, 00109 'trusttext' => false, 00110 'noclean' => true, 00111 'context' => $systemcontext 00112 ); 00113 00114 if (!empty($outcome_rec->id)) { 00115 $outcome_rec = file_prepare_standard_editor($outcome_rec, 'description', $editoroptions, $systemcontext, 'grade', 'outcome', $outcome_rec->id); 00116 } else { 00117 $outcome_rec = file_prepare_standard_editor($outcome_rec, 'description', $editoroptions, $systemcontext, 'grade', 'outcome', null); 00118 } 00119 00120 $mform = new edit_outcome_form(null, compact('gpr', 'editoroptions')); 00121 00122 $mform->set_data($outcome_rec); 00123 00124 if ($mform->is_cancelled()) { 00125 redirect($returnurl); 00126 00127 } else if ($data = $mform->get_data()) { 00128 $outcome = new grade_outcome(array('id'=>$id)); 00129 $data->usermodified = $USER->id; 00130 00131 if (empty($outcome->id)) { 00132 $data->description = $data->description_editor['text']; 00133 grade_outcome::set_properties($outcome, $data); 00134 if (!has_capability('moodle/grade:manage', $systemcontext)) { 00135 $data->standard = 0; 00136 } 00137 $outcome->courseid = !empty($data->standard) ? null : $courseid; 00138 if (empty($outcome->courseid)) { 00139 $outcome->courseid = null; 00140 } 00141 $outcome->insert(); 00142 00143 $data = file_postupdate_standard_editor($data, 'description', $editoroptions, $systemcontext, 'grade', 'outcome', $outcome->id); 00144 $DB->set_field($outcome->table, 'description', $data->description, array('id'=>$outcome->id)); 00145 } else { 00146 $data = file_postupdate_standard_editor($data, 'description', $editoroptions, $systemcontext, 'grade', 'outcome', $id); 00147 grade_outcome::set_properties($outcome, $data); 00148 if (isset($data->standard)) { 00149 $outcome->courseid = !empty($data->standard) ? null : $courseid; 00150 } else { 00151 unset($outcome->courseid); // keep previous 00152 } 00153 $outcome->update(); 00154 } 00155 00156 redirect($returnurl); 00157 } 00158 00159 if ($courseid) { 00160 print_grade_page_head($courseid, 'outcome', 'edit', $heading); 00161 } else { 00162 echo $OUTPUT->header(); 00163 } 00164 00165 if (!grade_scale::fetch_all_local($courseid) && !grade_scale::fetch_all_global()) { 00166 echo $OUTPUT->confirm(get_string('noscales', 'grades'), $CFG->wwwroot.'/grade/edit/scale/edit.php?courseid='.$courseid, $returnurl); 00167 echo $OUTPUT->footer(); 00168 die(); 00169 } 00170 00171 $mform->display(); 00172 echo $OUTPUT->footer();