[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/notes/ -> delete.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  require_once('../config.php');
  18  require_once ('lib.php');
  19  
  20  $noteid = required_param('id', PARAM_INT);
  21  
  22  $PAGE->set_url('/notes/delete.php', array('id' => $noteid));
  23  
  24  if (!$note = note_load($noteid)) {
  25      print_error('invalidid');
  26  }
  27  
  28  if (!$course = $DB->get_record('course', array('id' => $note->courseid))) {
  29      print_error('invalidcourseid');
  30  }
  31  
  32  require_login($course);
  33  
  34  if (empty($CFG->enablenotes)) {
  35      print_error('notesdisabled', 'notes');
  36  }
  37  
  38  if (!$user = $DB->get_record('user', array('id' => $note->userid))) {
  39      print_error('invaliduserid');
  40  }
  41  
  42  $context = context_course::instance($course->id);
  43  
  44  if (!has_capability('moodle/notes:manage', $context)) {
  45      print_error('nopermissiontodelete', 'notes');
  46  }
  47  
  48  if (data_submitted() && confirm_sesskey()) {
  49      // If data was submitted and is valid, then delete note.
  50      $returnurl = $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&amp;user=' . $note->userid;
  51      note_delete($note);
  52      redirect($returnurl);
  53  
  54  } else {
  55      // If data was not submitted yet, then show note data with a delete confirmation form.
  56      $strnotes = get_string('notes', 'notes');
  57      $optionsyes = array('id' => $noteid, 'sesskey' => sesskey());
  58      $optionsno  = array('course' => $course->id, 'user' => $note->userid);
  59  
  60      // Output HTML.
  61      $link = null;
  62      if (has_capability('moodle/course:viewparticipants', $context)
  63          || has_capability('moodle/site:viewparticipants', context_system::instance())) {
  64  
  65          $link = new moodle_url('/user/index.php', array('id' => $course->id));
  66      }
  67      $PAGE->navbar->add(get_string('participants'), $link);
  68      $PAGE->navbar->add(fullname($user), new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id)));
  69      $PAGE->navbar->add(get_string('notes', 'notes'),
  70                         new moodle_url('/notes/index.php', array('user' => $user->id, 'course' => $course->id)));
  71      $PAGE->navbar->add(get_string('delete'));
  72      $PAGE->set_title($course->shortname . ': ' . $strnotes);
  73      $PAGE->set_heading($course->fullname);
  74      echo $OUTPUT->header();
  75      echo $OUTPUT->confirm(get_string('deleteconfirm', 'notes'),
  76                            new moodle_url('delete.php', $optionsyes),
  77                            new moodle_url('index.php', $optionsno));
  78      echo '<br />';
  79      note_print($note, NOTES_SHOW_BODY | NOTES_SHOW_HEAD);
  80      echo $OUTPUT->footer();
  81  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1