[ Index ]

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

title

Body

[close]

/notes/ -> edit.php (source)

   1  <?php // $Id: edit.php,v 1.6.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      require_capability('moodle/notes:manage', $context);
  32  
  33  /// build-up form
  34      require_once ('edit_form.php');
  35  
  36  /// get option values for the user select
  37  
  38  /// create form
  39      $noteform = new note_edit_form();
  40  
  41  /// if form was cancelled then return to the notes list of the note
  42      if ($noteform->is_cancelled()) {
  43          redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&amp;user=' . $note->userid);
  44      }
  45  
  46  /// if data was submitted and validated, then save it to database
  47      if ($formdata = $noteform->get_data()){
  48          $note->courseid = $formdata->course;
  49          $note->userid = $formdata->user;
  50          $note->content = $formdata->content;
  51          $note->format = FORMAT_PLAIN;
  52          $note->publishstate = $formdata->publishstate;
  53          if (note_save($note)) {
  54              add_to_log($note->courseid, 'notes', 'update', 'index.php?course='.$note->courseid.'&amp;user='.$note->userid . '#note-' . $note->id, 'update note');
  55          }
  56          // redirect to notes list that contains this note
  57          redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&amp;user=' . $note->userid);
  58      }
  59  
  60  
  61      if ($noteform->is_submitted()) {
  62          // if data was submitted with errors, then use it as default for new form
  63          $note = $noteform->get_submitted_data(false);
  64      } else {
  65          // if data was not submitted yet, then used values retrieved from the database
  66          $note->user = $note->userid;
  67          $note->course = $note->courseid;
  68          $note->note = $note->id;
  69      }
  70      $noteform->set_data($note);
  71      $strnotes = get_string('editnote', 'notes');
  72  
  73  /// output HTML
  74      $nav = array();
  75      if (has_capability('moodle/course:viewparticipants', $context) || has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM))) {
  76          $nav[] = array('name' => get_string('participants'), 'link' => $CFG->wwwroot . '/user/index.php?id=' . $course->id, 'type' => 'misc');
  77      }
  78      $nav[] = array('name' => fullname($user), 'link' => $CFG->wwwroot . '/user/view.php?id=' . $user->id. '&amp;course=' . $course->id, 'type' => 'misc');
  79      $nav[] = array('name' => get_string('notes', 'notes'), 'link' => $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&amp;user=' . $user->id, 'type' => 'misc');
  80      $nav[] = array('name' => $strnotes, 'link' => '', 'type' => 'activity');
  81  
  82      print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_navigation($nav));
  83  
  84      print_heading(fullname($user));
  85  
  86      $noteform->display();
  87      print_footer();
  88  ?>


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