[ Index ]

PHP Cross Reference of moodle-2.8

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      if (!note_delete($note)) {
  52          print_error('cannotdeletepost', 'notes', $returnurl);
  53      }
  54      redirect($returnurl);
  55  
  56  } else {
  57      // If data was not submitted yet, then show note data with a delete confirmation form.
  58      $strnotes = get_string('notes', 'notes');
  59      $optionsyes = array('id' => $noteid, 'sesskey' => sesskey());
  60      $optionsno  = array('course' => $course->id, 'user' => $note->userid);
  61  
  62      // Output HTML.
  63      $link = null;
  64      if (has_capability('moodle/course:viewparticipants', $context)
  65          || has_capability('moodle/site:viewparticipants', context_system::instance())) {
  66  
  67          $link = new moodle_url('/user/index.php', array('id' => $course->id));
  68      }
  69      $PAGE->navbar->add(get_string('participants'), $link);
  70      $PAGE->navbar->add(fullname($user), new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id)));
  71      $PAGE->navbar->add(get_string('notes', 'notes'),
  72                         new moodle_url('/notes/index.php', array('user' => $user->id, 'course' => $course->id)));
  73      $PAGE->navbar->add(get_string('delete'));
  74      $PAGE->set_title($course->shortname . ': ' . $strnotes);
  75      $PAGE->set_heading($course->fullname);
  76      echo $OUTPUT->header();
  77      echo $OUTPUT->confirm(get_string('deleteconfirm', 'notes'),
  78                            new moodle_url('delete.php', $optionsyes),
  79                            new moodle_url('index.php', $optionsno));
  80      echo '<br />';
  81      note_print($note, NOTES_SHOW_BODY | NOTES_SHOW_HEAD);
  82      echo $OUTPUT->footer();
  83  }


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