MDL-31873 added mod_assign_get_grades web service function
[moodle.git] / grade / import / 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/>.
a700b5de 17
eef00ade 18/**
19 * Grade import 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
24 */
a700b5de 25
eef00ade 26require_once(dirname(__FILE__).'/../../config.php');
27require_once($CFG->dirroot.'/grade/lib.php');
28
29$id = required_param('id', PARAM_INT); // course id
30
a6855934 31$PAGE->set_url('/grade/import/keymanager.php', array('id' => $id));
a700b5de 32
f400841b 33if (!$course = $DB->get_record('course', array('id'=>$id))) {
a700b5de 34 print_error('nocourseid');
35}
36
37require_login($course);
d4060472 38$context = context_course::instance($id);
a700b5de 39
40require_capability('moodle/grade:import', $context);
41
27eef3bb 42print_grade_page_head($course->id, 'import', 'keymanager', get_string('keymanager', 'grades'));
a700b5de 43
eef00ade 44$stredit = get_string('edit');
45$strdelete = get_string('delete');
a700b5de 46
47$data = array();
5c75a0a3 48$params = array($course->id, $USER->id);
785720d6 49if ($keys = $DB->get_records_select('user_private_key', "script='grade/import' AND instance=? AND userid=?", $params)) {
a700b5de 50 foreach($keys as $key) {
51 $line = array();
52 $line[0] = format_string($key->value);
53 $line[1] = $key->iprestriction;
54 $line[2] = empty($key->validuntil) ? get_string('always') : userdate($key->validuntil);
6c3ef410 55
8ae8bf8a
PS
56 $url = new moodle_url('key.php', array('id' => $key->id));
57
c63923bd 58 $buttons = $OUTPUT->action_icon($url, new pix_icon('t/edit', $stredit));
8ae8bf8a
PS
59
60 $url->param('delete', 1);
61 $url->param('sesskey', sesskey());
c63923bd 62 $buttons .= $OUTPUT->action_icon($url, new pix_icon('t/delete', $strdelete));
a700b5de 63
64 $line[3] = $buttons;
65 $data[] = $line;
66 }
67}
03fcc729 68$table = new html_table();
a700b5de 69$table->head = array(get_string('keyvalue', 'userkey'), get_string('keyiprestriction', 'userkey'), get_string('keyvaliduntil', 'userkey'), $stredit);
70$table->size = array('50%', '30%', '10%', '10%');
71$table->align = array('left', 'left', 'left', 'center');
72$table->width = '90%';
73$table->data = $data;
16be8974 74echo html_writer::table($table);
a700b5de 75
eef00ade 76echo $OUTPUT->container_start('buttons mdl-align');
5c2ed7e2 77echo $OUTPUT->single_button(new moodle_url('key.php', array('courseid'=>$course->id)), get_string('newuserkey', 'userkey'));
03fcc729 78echo $OUTPUT->container_end();
a700b5de 79
5a931394 80echo $OUTPUT->footer();
6c3ef410 81