[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/grade/export/ -> key.php (source)

   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 edit 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 ('key_form.php');
  28  
  29  /// get url variables
  30  $courseid = optional_param('courseid', 0, PARAM_INT);
  31  $id       = optional_param('id', 0, PARAM_INT); // The key's id
  32  $delete   = optional_param('delete', 0, PARAM_BOOL);
  33  $confirm  = optional_param('confirm', 0, PARAM_BOOL);
  34  
  35  $PAGE->set_url('/grade/export/key.php', array('id' => $id, 'courseid' => $courseid));
  36  
  37  if ($id) {
  38      if (!$key = $DB->get_record('user_private_key', array('id' => $id))) {
  39          print_error('invalidgroupid');
  40      }
  41      if (empty($courseid)) {
  42          $courseid = $key->instance;
  43  
  44      } else if ($courseid != $key->instance) {
  45          print_error('invalidcourseid');
  46      }
  47  
  48      if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
  49          print_error('invalidcourseid');
  50      }
  51  
  52  } else {
  53      if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
  54          print_error('invalidcourseid');
  55      }
  56      $key = new stdClass();
  57  }
  58  
  59  $key->courseid = $course->id;
  60  
  61  require_login($course);
  62  $context = context_course::instance($course->id);
  63  require_capability('moodle/grade:export', $context);
  64  
  65  // extra security check
  66  if (!empty($key->userid) and $USER->id != $key->userid) {
  67      print_error('notownerofkey');
  68  }
  69  
  70  $returnurl = $CFG->wwwroot.'/grade/export/keymanager.php?id='.$course->id;
  71  
  72  if ($id and $delete) {
  73      if (!$confirm) {
  74          $PAGE->set_title(get_string('deleteselectedkey'));
  75          $PAGE->set_heading($course->fullname);
  76          echo $OUTPUT->header();
  77          $optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
  78          $optionsno  = array('id'=>$courseid);
  79          $formcontinue = new single_button(new moodle_url('key.php', $optionsyes), get_string('yes'), 'get');
  80          $formcancel = new single_button(new moodle_url('keymanager.php', $optionsno), get_string('no'), 'get');
  81          echo $OUTPUT->confirm(get_string('deletekeyconfirm', 'userkey', $key->value), $formcontinue, $formcancel);
  82          echo $OUTPUT->footer();
  83          die;
  84  
  85      } else if (confirm_sesskey()){
  86          $DB->delete_records('user_private_key', array('id' => $id));
  87          redirect('keymanager.php?id='.$course->id);
  88      }
  89  }
  90  
  91  /// First create the form
  92  $editform = new key_form();
  93  $editform->set_data($key);
  94  
  95  if ($editform->is_cancelled()) {
  96      redirect($returnurl);
  97  
  98  } elseif ($data = $editform->get_data()) {
  99  
 100      if ($data->id) {
 101          $record = new stdClass();
 102          $record->id            = $data->id;
 103          $record->iprestriction = $data->iprestriction;
 104          $record->validuntil    = $data->validuntil;
 105          $DB->update_record('user_private_key', $record);
 106      } else {
 107          create_user_key('grade/export', $USER->id, $course->id, $data->iprestriction, $data->validuntil);
 108      }
 109  
 110      redirect($returnurl);
 111  }
 112  
 113  $strkeys   = get_string('userkeys', 'userkey');
 114  $strgrades = get_string('grades');
 115  
 116  if ($id) {
 117      $strheading = get_string('edituserkey', 'userkey');
 118  } else {
 119      $strheading = get_string('createuserkey', 'userkey');
 120  }
 121  
 122  $PAGE->navbar->add($strgrades, new moodle_url('/grade/index.php', array('id'=>$courseid)));
 123  $PAGE->navbar->add($strkeys, new moodle_url('/grade/export/keymanager.php', array('id'=>$courseid)));
 124  $PAGE->navbar->add($strheading);
 125  
 126  /// Print header
 127  $PAGE->set_title($strkeys);
 128  $PAGE->set_heading($course->fullname);
 129  echo $OUTPUT->header();
 130  
 131  $editform->display();
 132  echo $OUTPUT->footer();
 133  


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1