| 1 | 
           efrain | 
           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 | 
              | 
        
        
            | 
            | 
           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
  | 
        
        
            | 
            | 
           24 | 
            */
  | 
        
        
            | 
            | 
           25 | 
              | 
        
        
            | 
            | 
           26 | 
           require_once '../../config.php';
  | 
        
        
            | 
            | 
           27 | 
           require_once $CFG->dirroot.'/grade/export/lib.php';
  | 
        
        
            | 
            | 
           28 | 
              | 
        
        
            | 
            | 
           29 | 
           $id = required_param('id', PARAM_INT); // course id
  | 
        
        
            | 
            | 
           30 | 
              | 
        
        
            | 
            | 
           31 | 
           $PAGE->set_url('/grade/export/keymanager.php', array('id' => $id));
  | 
        
        
            | 
            | 
           32 | 
              | 
        
        
            | 
            | 
           33 | 
           if (!$course = $DB->get_record('course', array('id'=>$id))) {
  | 
        
        
            | 
            | 
           34 | 
               throw new \moodle_exception('invalidcourseid');
  | 
        
        
            | 
            | 
           35 | 
           }
  | 
        
        
            | 
            | 
           36 | 
              | 
        
        
            | 
            | 
           37 | 
           require_login($course);
  | 
        
        
            | 
            | 
           38 | 
           $context = context_course::instance($id);
  | 
        
        
            | 
            | 
           39 | 
              | 
        
        
            | 
            | 
           40 | 
           require_capability('moodle/grade:export', $context);
  | 
        
        
            | 
            | 
           41 | 
              | 
        
        
            | 
            | 
           42 | 
           // Check if the user has at least one grade publishing capability.
  | 
        
        
            | 
            | 
           43 | 
           $plugins = grade_helper::get_plugins_export($course->id);
  | 
        
        
            | 
            | 
           44 | 
           if (!isset($plugins['keymanager'])) {
  | 
        
        
            | 
            | 
           45 | 
               throw new \moodle_exception('nopermissions');
  | 
        
        
            | 
            | 
           46 | 
           }
  | 
        
        
            | 
            | 
           47 | 
              | 
        
        
            | 
            | 
           48 | 
           $actionbar = new \core_grades\output\export_key_manager_action_bar($context);
  | 
        
        
            | 
            | 
           49 | 
           print_grade_page_head($COURSE->id, 'export', 'keymanager',
  | 
        
        
            | 
            | 
           50 | 
               get_string('keymanager', 'grades'), false, false, true, null,
  | 
        
        
            | 
            | 
           51 | 
               null, null, $actionbar);
  | 
        
        
            | 
            | 
           52 | 
              | 
        
        
            | 
            | 
           53 | 
           $stredit   = get_string('edit');
  | 
        
        
            | 
            | 
           54 | 
           $strdelete = get_string('delete');
  | 
        
        
            | 
            | 
           55 | 
              | 
        
        
            | 
            | 
           56 | 
           $data = array();
  | 
        
        
            | 
            | 
           57 | 
           $keys = $DB->get_records_select('user_private_key', "script='grade/export' AND instance=? AND userid=?", array($course->id, $USER->id));
  | 
        
        
            | 
            | 
           58 | 
           if ($keys) {
  | 
        
        
            | 
            | 
           59 | 
               foreach($keys as $key) {
  | 
        
        
            | 
            | 
           60 | 
                   $line = array();
  | 
        
        
            | 
            | 
           61 | 
                   $line[0] = format_string($key->value);
  | 
        
        
            | 
            | 
           62 | 
                   $line[1] = $key->iprestriction;
  | 
        
        
            | 
            | 
           63 | 
                   $line[2] = empty($key->validuntil) ? get_string('always') : userdate($key->validuntil);
  | 
        
        
            | 
            | 
           64 | 
              | 
        
        
            | 
            | 
           65 | 
                   $url = new moodle_url('key.php');
  | 
        
        
            | 
            | 
           66 | 
                   if (!empty($key->id)) {
  | 
        
        
            | 
            | 
           67 | 
                       $url->param('id', $key->id);
  | 
        
        
            | 
            | 
           68 | 
                   }
  | 
        
        
            | 
            | 
           69 | 
              | 
        
        
            | 
            | 
           70 | 
                   $buttons = $OUTPUT->action_icon($url, new pix_icon('t/edit', $stredit));
  | 
        
        
            | 
            | 
           71 | 
              | 
        
        
            | 
            | 
           72 | 
                   $url->param('delete', 1);
  | 
        
        
            | 
            | 
           73 | 
                   $url->param('sesskey', sesskey());
  | 
        
        
            | 
            | 
           74 | 
                   $buttons .= $OUTPUT->action_icon($url, new pix_icon('t/delete', $strdelete));
  | 
        
        
            | 
            | 
           75 | 
              | 
        
        
            | 
            | 
           76 | 
                   $line[3] = $buttons;
  | 
        
        
            | 
            | 
           77 | 
                   $data[] = $line;
  | 
        
        
            | 
            | 
           78 | 
               }
  | 
        
        
            | 
            | 
           79 | 
           }
  | 
        
        
            | 
            | 
           80 | 
           $table = new html_table();
  | 
        
        
            | 
            | 
           81 | 
           $table->head  = array(get_string('keyvalue', 'userkey'), get_string('keyiprestriction', 'userkey'), get_string('keyvaliduntil', 'userkey'), $stredit);
  | 
        
        
            | 
            | 
           82 | 
           $table->size  = array('50%', '30%', '10%', '10%');
  | 
        
        
            | 
            | 
           83 | 
           $table->align = array('left', 'left', 'left', 'center');
  | 
        
        
            | 
            | 
           84 | 
           $table->width = '90%';
  | 
        
        
            | 
            | 
           85 | 
           $table->data  = $data;
  | 
        
        
            | 
            | 
           86 | 
           echo html_writer::table($table);
  | 
        
        
            | 
            | 
           87 | 
           echo $OUTPUT->footer();
  | 
        
        
            | 
            | 
           88 | 
              |