Merge branch 'MDL-70476_310' of https://github.com/timhunt/moodle into MOODLE_310_STABLE
[moodle.git] / grade / export / keymanager.php
CommitLineData
e060e33d 1<?php
2
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.
14//
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/>.
17
eef00ade 18/**
19 * Grade export key management page.
20 *
21 * @package moodlecore
22 * @copyright 2008 Petr Skoda
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
6c3ef410 24 */
eed8e305 25
26require_once '../../config.php';
27require_once $CFG->dirroot.'/grade/export/lib.php';
28
eef00ade 29$id = required_param('id', PARAM_INT); // course id
30
a6855934 31$PAGE->set_url('/grade/export/keymanager.php', array('id' => $id));
eed8e305 32
f400841b 33if (!$course = $DB->get_record('course', array('id'=>$id))) {
d9ce6a4f 34 print_error('invalidcourseid');
eed8e305 35}
36
37require_login($course);
d4060472 38$context = context_course::instance($id);
eed8e305 39
40require_capability('moodle/grade:export', $context);
41
ead4d41e
SL
42// Check if the user has at least one grade publishing capability.
43$plugins = grade_helper::get_plugins_export($course->id);
44if (!isset($plugins['keymanager'])) {
45 print_error('nopermissions');
46}
47
27eef3bb 48print_grade_page_head($course->id, 'export', 'keymanager', get_string('keymanager', 'grades'));
eed8e305 49
eef00ade 50$stredit = get_string('edit');
51$strdelete = get_string('delete');
eed8e305 52
53$data = array();
5c75a0a3 54$keys = $DB->get_records_select('user_private_key', "script='grade/export' AND instance=? AND userid=?", array($course->id, $USER->id));
55if ($keys) {
eed8e305 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);
61
8ae8bf8a 62 $url = new moodle_url('key.php');
eef00ade 63 if (!empty($key->id)) {
8ae8bf8a 64 $url->param('id', $key->id);
eef00ade 65 }
8ae8bf8a 66
c63923bd 67 $buttons = $OUTPUT->action_icon($url, new pix_icon('t/edit', $stredit));
8ae8bf8a
PS
68
69 $url->param('delete', 1);
70 $url->param('sesskey', sesskey());
c63923bd 71 $buttons .= $OUTPUT->action_icon($url, new pix_icon('t/delete', $strdelete));
eed8e305 72
73 $line[3] = $buttons;
74 $data[] = $line;
75 }
76}
03fcc729 77$table = new html_table();
0f78c4de 78$table->head = array(get_string('keyvalue', 'userkey'), get_string('keyiprestriction', 'userkey'), get_string('keyvaliduntil', 'userkey'), $stredit);
eed8e305 79$table->size = array('50%', '30%', '10%', '10%');
80$table->align = array('left', 'left', 'left', 'center');
81$table->width = '90%';
82$table->data = $data;
16be8974 83echo html_writer::table($table);
eed8e305 84
eef00ade 85echo $OUTPUT->container_start('buttons mdl-align');
5c2ed7e2 86echo $OUTPUT->single_button(new moodle_url('key.php', array('courseid'=>$course->id)), get_string('newuserkey', 'userkey'));
03fcc729 87echo $OUTPUT->container_end();
eed8e305 88
5a931394 89echo $OUTPUT->footer();
6c3ef410 90