Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
/notes/ -> edit.php (source)

Differences Between: [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

   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  require_once ('edit_form.php');
  20  require_once($CFG->dirroot . '/course/lib.php');
  21  
  22  $noteid = optional_param('id', 0, PARAM_INT);
  23  
  24  $url = new moodle_url('/notes/edit.php');
  25  
  26  if ($noteid) {
  27      // Existing note.
  28      $url->param('id', $noteid);
  29      if (!$note = note_load($noteid)) {
  30          print_error('invalidid', 'notes');
  31      }
  32  
  33  } else {
  34      // Adding new note.
  35      $courseid = required_param('courseid', PARAM_INT);
  36      $userid   = required_param('userid', PARAM_INT);
  37      $state    = optional_param('publishstate', NOTES_STATE_PUBLIC, PARAM_ALPHA);
  38  
  39      $note = new stdClass();
  40      $note->courseid     = $courseid;
  41      $note->userid       = $userid;
  42      $note->publishstate = $state;
  43  
  44      $url->param('courseid', $courseid);
  45      $url->param('userid', $userid);
  46      if ($state !== NOTES_STATE_PUBLIC) {
  47          $url->param('publishstate', $state);
  48      }
  49  }
  50  
  51  $PAGE->set_url($url);
  52  
  53  if (!$course = $DB->get_record('course', array('id' => $note->courseid))) {
  54      print_error('invalidcourseid');
  55  }
  56  
  57  require_login($course);
  58  
  59  if (empty($CFG->enablenotes)) {
  60      print_error('notesdisabled', 'notes');
  61  }
  62  
  63  $context = context_course::instance($course->id);
  64  require_capability('moodle/notes:manage', $context);
  65  
  66  if (!$user = $DB->get_record('user', array('id' => $note->userid))) {
  67      print_error('invaliduserid');
  68  }
  69  
  70  $noteform = new note_edit_form();
  71  $noteform->set_data($note);
  72  
  73  // If form was cancelled then return to the notes list of the note.
  74  if ($noteform->is_cancelled()) {
  75      redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&amp;user=' . $note->userid);
  76  }
  77  
  78  // If data was submitted and validated, then save it to database.
  79  if ($note = $noteform->get_data()) {
  80      if ($noteid) {
  81          // A noteid has been used, we don't allow editing of course or user so
  82          // lets unset them to be sure we never change that by accident.
  83          unset($note->courseid);
  84          unset($note->userid);
  85      }
  86      note_save($note);
  87      // Redirect to notes list that contains this note.
  88      redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&amp;user=' . $note->userid);
  89  }
  90  
  91  if ($noteid) {
  92      $strnotes = get_string('editnote', 'notes');
  93  } else {
  94      $strnotes = get_string('addnewnote', 'notes');
  95  }
  96  
  97  // Output HTML.
  98  $link = null;
  99  if (course_can_view_participants($context) || course_can_view_participants(context_system::instance())) {
 100      $link = new moodle_url('/user/index.php', array('id' => $course->id));
 101  }
 102  $PAGE->navbar->add(get_string('participants'), $link);
 103  $PAGE->navbar->add(fullname($user), new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id)));
 104  $PAGE->navbar->add(get_string('notes', 'notes'),
 105                     new moodle_url('/notes/index.php', array('user' => $user->id, 'course' => $course->id)));
 106  $PAGE->navbar->add($strnotes);
 107  $PAGE->set_title($course->shortname . ': ' . $strnotes);
 108  $PAGE->set_heading($course->fullname);
 109  
 110  echo $OUTPUT->header();
 111  echo $OUTPUT->heading(fullname($user));
 112  
 113  $noteform->display();
 114  echo $OUTPUT->footer();