]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-11027 user key manager for grade exports
authorskodak <skodak>
Tue, 28 Aug 2007 21:54:18 +0000 (21:54 +0000)
committerskodak <skodak>
Tue, 28 Aug 2007 21:54:18 +0000 (21:54 +0000)
grade/export/grade_export_form.php
grade/export/key.php [new file with mode: 0644]
grade/export/key_form.php [new file with mode: 0644]
grade/export/keymanager.php [new file with mode: 0644]

index f71dbc62d9692e47f44c7e32fd6491af8e7bed88..10c05630c062b46021dc7fab7fa4d1b8d50d09ef 100755 (executable)
@@ -26,7 +26,7 @@ class grade_export_form extends moodleform {
             }
         }
         $mform->addElement('select', 'key', get_string('userkey', 'grades'), $options);
-        $mform->addElement('static', 'justalink', get_string('key_manager'), '<a href="hmm_create_me">some link to key manager</a>');
+        $mform->addElement('static', 'keymanagerlink', get_string('key_manager'), '<a href="'.$CFG->wwwroot.'/grade/export/keymanager.php?id='.$COURSE->id.'">'.get_string('keymanager').'</a>');
 
         $mform->addElement('header', 'general', get_string('gradeitemsinc', 'grades')); // TODO: localize
 
diff --git a/grade/export/key.php b/grade/export/key.php
new file mode 100644 (file)
index 0000000..659f88a
--- /dev/null
@@ -0,0 +1,99 @@
+<?php  //$Id$
+
+require_once('../../config.php');
+require_once('key_form.php');
+
+/// get url variables
+$courseid = optional_param('courseid', 0, PARAM_INT);
+$id       = optional_param('id', 0, PARAM_INT);
+$delete   = optional_param('delete', 0, PARAM_BOOL);
+$confirm  = optional_param('confirm', 0, PARAM_BOOL);
+
+if ($id) {
+    if (!$key = get_record('user_private_key', 'id', $id)) {
+        error('Group ID was incorrect');
+    }
+    if (empty($courseid)) {
+        $courseid = $key->instance;
+
+    } else if ($courseid != $key->instance) {
+        error('Course ID was incorrect');
+    }
+
+    if (!$course = get_record('course', 'id', $courseid)) {
+        error('Course ID was incorrect');
+    }
+
+} else {
+    if (!$course = get_record('course', 'id', $courseid)) {
+        error('Course ID was incorrect');
+    }
+    $key = new object();
+}
+
+$key->courseid = $course->id;
+
+require_login($course);
+$context = get_context_instance(CONTEXT_COURSE, $course->id);
+require_capability('moodle/grade:export', $context);
+
+$returnurl = $CFG->wwwroot.'/grade/export/keymanager.php?id='.$course->id;
+
+if ($id and $delete) {
+    if (!$confirm) {
+        print_header(get_string('deleteselectedkey'), get_string('deleteselectedkey'));
+        $optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
+        $optionsno  = array('id'=>$courseid);
+        notice_yesno(get_string('deletekeyconfirm', 'key', $key->value), 'key.php', 'keymanager.php', $optionsyes, $optionsno, 'get', 'get');
+        print_footer();
+        die;
+
+    } else if (confirm_sesskey()){
+        delete_records('user_private_key', 'id', $id);
+        redirect('keymanager.php?id='.$course->id);
+    }
+}
+
+/// First create the form
+$editform = new key_form();
+$editform->set_data($key);
+
+if ($editform->is_cancelled()) {
+    redirect($returnurl);
+
+} elseif ($data = $editform->get_data()) {
+
+    if ($data->id) {
+        $record = new object();
+        $record->id            = $data->id;
+        $record->iprestriction = $data->iprestriction;
+        $record->validuntil    = $data->validuntil;
+        update_record('user_private_key', $record);
+    } else {
+        create_user_key('grade/export', $USER->id, $course->id, $data->iprestriction, $data->validuntil);
+    }
+
+    redirect($returnurl);
+}
+
+$strkeys   = get_string('userkeys');
+$strgrades = get_string('grades');
+
+if ($id) {
+    $strheading = get_string('edituserkey', 'key');
+} else {
+    $strheading = get_string('createuserkey', 'key');
+}
+
+
+$navlinks = array(array('name'=>$strgrades, 'link'=>$CFG->wwwroot.'/grade/index.php?id='.$courseid, 'type'=>'misc'),
+                  array('name'=>$strkeys, 'link'=>$CFG->wwwroot.'/grade/export/keymanager.php?id='.$courseid, 'type'=>'misc'),
+                  array('name'=>$strheading, 'link'=>'', 'type'=>'misc'));
+$navigation = build_navigation($navlinks);
+
+/// Print header
+print_header_simple($strkeys, ': '.$strkeys, $navigation, '', '', true, '', navmenu($course));
+
+$editform->display();
+print_footer($course);
+?>
diff --git a/grade/export/key_form.php b/grade/export/key_form.php
new file mode 100644 (file)
index 0000000..3a326d0
--- /dev/null
@@ -0,0 +1,28 @@
+<?php //$Id$
+
+require_once($CFG->dirroot.'/lib/formslib.php');
+
+class key_form extends moodleform {
+
+    // Define the form
+    function definition () {
+        global $USER, $CFG, $COURSE;
+
+        $mform =& $this->_form;
+
+        $mform->addElement('static', 'value', get_string('keyvalue'));
+        $mform->addElement('text', 'iprestriction', get_string('keyiprestriction'), array('size'=>80));
+        $mform->addElement('date_time_selector', 'validuntil', get_string('keyvaliduntil'), array('optional'=>true));
+
+
+        $mform->addElement('hidden','id');
+        $mform->setType('id', PARAM_INT);
+
+        $mform->addElement('hidden','courseid');
+        $mform->setType('courseid', PARAM_INT);
+
+        $this->add_action_buttons();
+    }
+}
+
+?>
diff --git a/grade/export/keymanager.php b/grade/export/keymanager.php
new file mode 100644 (file)
index 0000000..782e2b0
--- /dev/null
@@ -0,0 +1,78 @@
+<?php  //$Id$
+
+///////////////////////////////////////////////////////////////////////////
+//                                                                       //
+// NOTICE OF COPYRIGHT                                                   //
+//                                                                       //
+// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
+//          http://moodle.com                                            //
+//                                                                       //
+// Copyright (C) 1999 onwards  Martin Dougiamas  http://moodle.com       //
+//                                                                       //
+// This program is free software; you can redistribute it and/or modify  //
+// it under the terms of the GNU General Public License as published by  //
+// the Free Software Foundation; either version 2 of the License, or     //
+// (at your option) any later version.                                   //
+//                                                                       //
+// This program is distributed in the hope that it will be useful,       //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
+// GNU General Public License for more details:                          //
+//                                                                       //
+//          http://www.gnu.org/copyleft/gpl.html                         //
+//                                                                       //
+///////////////////////////////////////////////////////////////////////////
+
+require_once '../../config.php';
+require_once $CFG->dirroot.'/grade/export/lib.php';
+
+$id     = required_param('id', PARAM_INT); // course id
+
+if (!$course = get_record('course', 'id', $id)) {
+    print_error('nocourseid');
+}
+
+require_login($course);
+$context = get_context_instance(CONTEXT_COURSE, $id);
+
+require_capability('moodle/grade:export', $context);
+
+$strgrades = get_string('grades', 'grades');
+$navigation = grade_build_nav(__FILE__, null, array('courseid' => $course->id));
+
+print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
+print_grade_plugin_selector($id, '', '');
+
+$stredit         = get_string('edit');
+$strdelete       = get_string('delete');
+
+$data = array();
+if ($keys = get_records_select('user_private_key', "script='grade/export' AND instance={$course->id} AND userid={$USER->id}")) {
+    foreach($keys as $key) {
+        $line = array();
+        $line[0] = format_string($key->value);
+        $line[1] = $key->iprestriction;
+        $line[2] = empty($key->validuntil) ? get_string('always') : userdate($key->validuntil);
+
+        $buttons  = "<a title=\"$stredit\" href=\"key.php?id=$key->id\"><img".
+                    " src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
+        $buttons .= "<a title=\"$strdelete\" href=\"key.php?id=$key->id&amp;delete=1\"><img".
+                    " src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
+
+        $line[3] = $buttons;
+        $data[] = $line;
+    }
+}
+$table->head  = array(get_string('keyvalue'), get_string('keyiprestriction'), get_string('keyvaliduntil'), $stredit);
+$table->size  = array('50%', '30%', '10%', '10%');
+$table->align = array('left', 'left', 'left', 'center');
+$table->width = '90%';
+$table->data  = $data;
+print_table($table);
+
+echo '<div class="buttons">';
+print_single_button('key.php', array('courseid'=>$course->id), get_string('newuserkey'));
+echo '</div>';
+
+print_footer();
+?>