|
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 00018 require_once '../../../config.php'; 00019 require_once $CFG->dirroot.'/grade/lib.php'; 00020 00021 $courseid = required_param('id', PARAM_INT); 00022 $action = required_param('action', PARAM_ALPHA); 00023 $eid = required_param('eid', PARAM_ALPHANUM); 00024 00025 $PAGE->set_url('/grade/edit/tree/action.php', array('id'=>$courseid, 'action'=>$action, 'eid'=>$eid)); 00026 00028 if (!$course = $DB->get_record('course', array('id' => $courseid))) { 00029 print_error('nocourseid'); 00030 } 00031 require_login($course); 00032 $context = get_context_instance(CONTEXT_COURSE, $course->id); 00033 00034 // default return url 00035 $gpr = new grade_plugin_return(); 00036 $returnurl = $gpr->get_return_url($CFG->wwwroot.'/grade/edit/tree/index.php?id='.$course->id); 00037 00038 // get the grading tree object 00039 $gtree = new grade_tree($courseid, false, false); 00040 00041 // what are we working with? 00042 if (!$element = $gtree->locate_element($eid)) { 00043 print_error('invalidelementid', '', $returnurl); 00044 } 00045 $object = $element['object']; 00046 $type = $element['type']; 00047 00048 00049 switch ($action) { 00050 case 'hide': 00051 if ($eid and confirm_sesskey()) { 00052 if (!has_capability('moodle/grade:manage', $context) and !has_capability('moodle/grade:hide', $context)) { 00053 print_error('nopermissiontohide', '', $returnurl); 00054 } 00055 if ($type == 'grade' and empty($object->id)) { 00056 $object->insert(); 00057 } 00058 $object->set_hidden(1, true); 00059 } 00060 break; 00061 00062 case 'show': 00063 if ($eid and confirm_sesskey()) { 00064 if (!has_capability('moodle/grade:manage', $context) and !has_capability('moodle/grade:hide', $context)) { 00065 print_error('nopermissiontoshow', '', $returnurl); 00066 } 00067 if ($type == 'grade' and empty($object->id)) { 00068 $object->insert(); 00069 } 00070 $object->set_hidden(0, true); 00071 } 00072 break; 00073 00074 case 'lock': 00075 if ($eid and confirm_sesskey()) { 00076 if (!has_capability('moodle/grade:manage', $context) and !has_capability('moodle/grade:lock', $context)) { 00077 print_error('nopermissiontolock', '', $returnurl); 00078 } 00079 if ($type == 'grade' and empty($object->id)) { 00080 $object->insert(); 00081 } 00082 $object->set_locked(1, true, true); 00083 } 00084 break; 00085 00086 case 'unlock': 00087 if ($eid and confirm_sesskey()) { 00088 if (!has_capability('moodle/grade:manage', $context) and !has_capability('moodle/grade:unlock', $context)) { 00089 print_error('nopermissiontounlock', '', $returnurl); 00090 } 00091 if ($type == 'grade' and empty($object->id)) { 00092 $object->insert(); 00093 } 00094 $object->set_locked(0, true, true); 00095 } 00096 break; 00097 } 00098 00099 redirect($returnurl); 00100 //redirect($returnurl, 'debug delay', 5); 00101 00102