[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/notes/ -> delete.php (source)

   1  <?php // $Id: delete.php,v 1.4.2.1 2008/01/10 10:58:09 tjhunt Exp $
   2  
   3  require_once ('../config.php');
   4  require_once ('lib.php');
   5  
   6  // retrieve parameters
   7  $noteid       = required_param('note', PARAM_INT);
   8  
   9  // locate note information
  10  if (!$note = note_load($noteid)) {
  11      error('Incorrect note id specified');
  12  }
  13  
  14  // locate course information
  15  if (!$course = get_record('course', 'id', $note->courseid)) {
  16      error('Incorrect course id found');
  17  }
  18  
  19  // locate user information
  20      if (!$user = get_record('user', 'id', $note->userid)) {
  21          error('Incorrect user id found');
  22      }
  23  
  24  // require login to access notes
  25  require_login($course->id);
  26  
  27  // locate context information
  28  $context = get_context_instance(CONTEXT_COURSE, $course->id);
  29  
  30  // check capability
  31  if (!has_capability('moodle/notes:manage', $context)) {
  32      error('You may not delete this note');
  33  }
  34  
  35  if (data_submitted() && confirm_sesskey()) {
  36  //if data was submitted and is valid, then delete note
  37      $returnurl = $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&amp;user=' . $note->userid;
  38      if (note_delete($noteid)) {
  39          add_to_log($note->courseid, 'notes', 'delete', 'index.php?course='.$note->courseid.'&amp;user='.$note->userid . '#note-' . $note->id , 'delete note');
  40      } else {
  41          error('Error occured while deleting post', $returnurl);
  42      }
  43      redirect($returnurl);
  44  } else {
  45  // if data was not submitted yet, then show note data with a delete confirmation form
  46      $strnotes = get_string('notes', 'notes');
  47      $optionsyes = array('note'=>$noteid, 'sesskey'=>sesskey());
  48      $optionsno = array('course'=>$course->id, 'user'=>$note->userid);
  49  
  50  // output HTML
  51      if (has_capability('moodle/course:viewparticipants', $context) || has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM))) {
  52          $nav[] = array('name' => get_string('participants'), 'link' => $CFG->wwwroot . '/user/index.php?id=' . $course->id, 'type' => 'misc');
  53      }
  54      $nav[] = array('name' => fullname($user), 'link' => $CFG->wwwroot . '/user/view.php?id=' . $user->id. '&amp;course=' . $course->id, 'type' => 'misc');
  55      $nav[] = array('name' => get_string('notes', 'notes'), 'link' => $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&amp;user=' . $user->id, 'type' => 'misc');
  56      $nav[] = array('name' => get_string('delete'), 'link' => '', 'type' => 'activity');
  57      print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_navigation($nav));
  58      notice_yesno(get_string('deleteconfirm', 'notes'), 'delete.php', 'index.php', $optionsyes, $optionsno, 'post', 'get');
  59      echo '<br />';
  60      note_print($note, NOTES_SHOW_BODY | NOTES_SHOW_HEAD);
  61      print_footer();
  62  }
  63  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7