MDL-11517 reserved word MOD used in table alias in questions backup code
[moodle-pu.git] / grade / import / key.php
blob9d31d9e1f132cc9af7bc07e7b8ac80809495cb3f
1 <?php //$Id$
3 require_once('../../config.php');
4 require_once('key_form.php');
6 /// get url variables
7 $courseid = optional_param('courseid', 0, PARAM_INT);
8 $id = optional_param('id', 0, PARAM_INT);
9 $delete = optional_param('delete', 0, PARAM_BOOL);
10 $confirm = optional_param('confirm', 0, PARAM_BOOL);
12 if ($id) {
13 if (!$key = get_record('user_private_key', 'id', $id)) {
14 error('Group ID was incorrect');
16 if (empty($courseid)) {
17 $courseid = $key->instance;
19 } else if ($courseid != $key->instance) {
20 error('Course ID was incorrect');
23 if (!$course = get_record('course', 'id', $courseid)) {
24 error('Course ID was incorrect');
27 } else {
28 if (!$course = get_record('course', 'id', $courseid)) {
29 error('Course ID was incorrect');
31 $key = new object();
34 $key->courseid = $course->id;
36 require_login($course);
37 $context = get_context_instance(CONTEXT_COURSE, $course->id);
38 require_capability('moodle/grade:import', $context);
40 // extra security check
41 if (!empty($key->userid) and $USER->id != $key->userid) {
42 error('You are not owner of this key');
45 $returnurl = $CFG->wwwroot.'/grade/import/keymanager.php?id='.$course->id;
47 if ($id and $delete) {
48 if (!$confirm) {
49 print_header(get_string('deleteselectedkey'), get_string('deleteselectedkey'));
50 $optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
51 $optionsno = array('id'=>$courseid);
52 notice_yesno(get_string('deletekeyconfirm', 'userkey', $key->value), 'key.php', 'keymanager.php', $optionsyes, $optionsno, 'get', 'get');
53 print_footer();
54 die;
56 } else if (confirm_sesskey()){
57 delete_records('user_private_key', 'id', $id);
58 redirect('keymanager.php?id='.$course->id);
62 /// First create the form
63 $editform = new key_form();
64 $editform->set_data($key);
66 if ($editform->is_cancelled()) {
67 redirect($returnurl);
69 } elseif ($data = $editform->get_data()) {
71 if ($data->id) {
72 $record = new object();
73 $record->id = $data->id;
74 $record->iprestriction = $data->iprestriction;
75 $record->validuntil = $data->validuntil;
76 update_record('user_private_key', $record);
77 } else {
78 create_user_key('grade/import', $USER->id, $course->id, $data->iprestriction, $data->validuntil);
81 redirect($returnurl);
84 $strkeys = get_string('userkeys', 'userkey');
85 $strgrades = get_string('grades');
87 if ($id) {
88 $strheading = get_string('edituserkey', 'userkey');
89 } else {
90 $strheading = get_string('createuserkey', 'userkey');
94 $navlinks = array(array('name'=>$strgrades, 'link'=>$CFG->wwwroot.'/grade/index.php?id='.$courseid, 'type'=>'misc'),
95 array('name'=>$strkeys, 'link'=>$CFG->wwwroot.'/grade/import/keymanager.php?id='.$courseid, 'type'=>'misc'),
96 array('name'=>$strheading, 'link'=>'', 'type'=>'misc'));
97 $navigation = build_navigation($navlinks);
99 /// Print header
100 print_header_simple($strkeys, ': '.$strkeys, $navigation, '', '', true, '', navmenu($course));
102 $editform->display();
103 print_footer($course);