|
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('key_form.php'); 00028 00030 $courseid = optional_param('courseid', 0, PARAM_INT); 00031 $id = optional_param('id', 0, PARAM_INT); // The key's id 00032 $delete = optional_param('delete', 0, PARAM_BOOL); 00033 $confirm = optional_param('confirm', 0, PARAM_BOOL); 00034 00035 $PAGE->set_url('/grade/export/key.php', array('id' => $id, 'courseid' => $courseid)); 00036 00037 if ($id) { 00038 if (!$key = $DB->get_record('user_private_key', array('id' => $id))) { 00039 print_error('invalidgroupid'); 00040 } 00041 if (empty($courseid)) { 00042 $courseid = $key->instance; 00043 00044 } else if ($courseid != $key->instance) { 00045 print_error('invalidcourseid'); 00046 } 00047 00048 if (!$course = $DB->get_record('course', array('id'=>$courseid))) { 00049 print_error('invalidcourseid'); 00050 } 00051 00052 } else { 00053 if (!$course = $DB->get_record('course', array('id'=>$courseid))) { 00054 print_error('invalidcourseid'); 00055 } 00056 $key = new stdClass(); 00057 } 00058 00059 $key->courseid = $course->id; 00060 00061 require_login($course); 00062 $context = get_context_instance(CONTEXT_COURSE, $course->id); 00063 require_capability('moodle/grade:export', $context); 00064 00065 // extra security check 00066 if (!empty($key->userid) and $USER->id != $key->userid) { 00067 print_error('notownerofkey'); 00068 } 00069 00070 $returnurl = $CFG->wwwroot.'/grade/export/keymanager.php?id='.$course->id; 00071 00072 if ($id and $delete) { 00073 if (!$confirm) { 00074 $PAGE->set_title(get_string('deleteselectedkey')); 00075 $PAGE->set_heading($course->fullname); 00076 echo $OUTPUT->header(); 00077 $optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1); 00078 $optionsno = array('id'=>$courseid); 00079 $formcontinue = new single_button(new moodle_url('key.php', $optionsyes), get_string('yes'), 'get'); 00080 $formcancel = new single_button(new moodle_url('keymanager.php', $optionsno), get_string('no'), 'get'); 00081 echo $OUTPUT->confirm(get_string('deletekeyconfirm', 'userkey', $key->value), $formcontinue, $formcancel); 00082 echo $OUTPUT->footer(); 00083 die; 00084 00085 } else if (confirm_sesskey()){ 00086 $DB->delete_records('user_private_key', array('id' => $id)); 00087 redirect('keymanager.php?id='.$course->id); 00088 } 00089 } 00090 00092 $editform = new key_form(); 00093 $editform->set_data($key); 00094 00095 if ($editform->is_cancelled()) { 00096 redirect($returnurl); 00097 00098 } elseif ($data = $editform->get_data()) { 00099 00100 if ($data->id) { 00101 $record = new stdClass(); 00102 $record->id = $data->id; 00103 $record->iprestriction = $data->iprestriction; 00104 $record->validuntil = $data->validuntil; 00105 $DB->update_record('user_private_key', $record); 00106 } else { 00107 create_user_key('grade/export', $USER->id, $course->id, $data->iprestriction, $data->validuntil); 00108 } 00109 00110 redirect($returnurl); 00111 } 00112 00113 $strkeys = get_string('userkeys', 'userkey'); 00114 $strgrades = get_string('grades'); 00115 00116 if ($id) { 00117 $strheading = get_string('edituserkey', 'userkey'); 00118 } else { 00119 $strheading = get_string('createuserkey', 'userkey'); 00120 } 00121 00122 $PAGE->navbar->add($strgrades, new moodle_url('/grade/index.php', array('id'=>$courseid))); 00123 $PAGE->navbar->add($strkeys, new moodle_url('/grade/export/keymanager.php', array('id'=>$courseid))); 00124 $PAGE->navbar->add($strheading); 00125 00127 $PAGE->set_title($strkeys); 00128 $PAGE->set_heading($course->fullname); 00129 echo $OUTPUT->header(); 00130 00131 $editform->display(); 00132 echo $OUTPUT->footer(); 00133