Merge branch 'MDL-59169-master' of https://github.com/nwp90/moodle
[moodle.git] / grade / export / keymanager.php
blob303a7a66af90297a470df64ced76cfbf4631f17b
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * Grade export key management page.
21 * @package moodlecore
22 * @copyright 2008 Petr Skoda
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require_once '../../config.php';
27 require_once $CFG->dirroot.'/grade/export/lib.php';
29 $id = required_param('id', PARAM_INT); // course id
31 $PAGE->set_url('/grade/export/keymanager.php', array('id' => $id));
33 if (!$course = $DB->get_record('course', array('id'=>$id))) {
34 print_error('invalidcourseid');
37 require_login($course);
38 $context = context_course::instance($id);
40 require_capability('moodle/grade:export', $context);
42 // Check if the user has at least one grade publishing capability.
43 $plugins = grade_helper::get_plugins_export($course->id);
44 if (!isset($plugins['keymanager'])) {
45 print_error('nopermissions');
48 print_grade_page_head($course->id, 'export', 'keymanager', get_string('keymanager', 'grades'));
50 $stredit = get_string('edit');
51 $strdelete = get_string('delete');
53 $data = array();
54 $keys = $DB->get_records_select('user_private_key', "script='grade/export' AND instance=? AND userid=?", array($course->id, $USER->id));
55 if ($keys) {
56 foreach($keys as $key) {
57 $line = array();
58 $line[0] = format_string($key->value);
59 $line[1] = $key->iprestriction;
60 $line[2] = empty($key->validuntil) ? get_string('always') : userdate($key->validuntil);
62 $url = new moodle_url('key.php');
63 if (!empty($key->id)) {
64 $url->param('id', $key->id);
67 $buttons = $OUTPUT->action_icon($url, new pix_icon('t/edit', $stredit));
69 $url->param('delete', 1);
70 $url->param('sesskey', sesskey());
71 $buttons .= $OUTPUT->action_icon($url, new pix_icon('t/delete', $strdelete));
73 $line[3] = $buttons;
74 $data[] = $line;
77 $table = new html_table();
78 $table->head = array(get_string('keyvalue', 'userkey'), get_string('keyiprestriction', 'userkey'), get_string('keyvaliduntil', 'userkey'), $stredit);
79 $table->size = array('50%', '30%', '10%', '10%');
80 $table->align = array('left', 'left', 'left', 'center');
81 $table->width = '90%';
82 $table->data = $data;
83 echo html_writer::table($table);
85 echo $OUTPUT->container_start('buttons mdl-align');
86 echo $OUTPUT->single_button(new moodle_url('key.php', array('courseid'=>$course->id)), get_string('newuserkey', 'userkey'));
87 echo $OUTPUT->container_end();
89 echo $OUTPUT->footer();