3 require_once('../../config.php');
4 require_once('key_form.php');
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
);
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');
28 if (!$course = get_record('course', 'id', $courseid)) {
29 error('Course ID was incorrect');
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) {
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');
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()) {
69 } elseif ($data = $editform->get_data()) {
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);
78 create_user_key('grade/import', $USER->id
, $course->id
, $data->iprestriction
, $data->validuntil
);
84 $strkeys = get_string('userkeys', 'userkey');
85 $strgrades = get_string('grades');
88 $strheading = get_string('edituserkey', 'userkey');
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);
100 print_header_simple($strkeys, ': '.$strkeys, $navigation, '', '', true, '', navmenu($course));
102 $editform->display();
103 print_footer($course);