Search moodle.org's
Developer Documentation


/notes/ -> index.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  /**
  18   * file index.php
  19   * index page to view notes.
  20   * if a course id is specified then the entries from that course are shown
  21   * if a user id is specified only notes related to that user are shown
  22   */
  23  require_once('../config.php');
  24  require_once ('lib.php');
  25  
  26  $courseid     = optional_param('course', SITEID, PARAM_INT);
  27  $userid       = optional_param('user', 0, PARAM_INT);
  28  $filtertype   = optional_param('filtertype', '', PARAM_ALPHA);
  29  $filterselect = optional_param('filterselect', 0, PARAM_INT);
  30  
  31  if (empty($CFG->enablenotes)) {
  32      print_error('notesdisabled', 'notes');
  33  }
  34  
  35  $url = new moodle_url('/notes/index.php');
  36  if ($courseid != SITEID) {
  37      $url->param('course', $courseid);
  38  }
  39  if ($userid !== 0) {
  40      $url->param('user', $userid);
  41  }
  42  $PAGE->set_url($url);
  43  
  44  // Tabs compatibility.
  45  switch($filtertype) {
  46      case 'course':
  47          $courseid = $filterselect;
  48          break;
  49      case 'site':
  50          $courseid = SITEID;
  51          break;
  52  }
  53  
  54  if (empty($courseid)) {
  55      $courseid = SITEID;
  56  }
  57  
  58  $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
  59  
  60  if ($userid) {
  61      $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
  62      $filtertype = 'user';
  63      $filterselect = $user->id;
  64  
  65      if ($user->deleted) {
  66          echo $OUTPUT->header();
  67          echo $OUTPUT->heading(get_string('userdeleted'));
  68          echo $OUTPUT->footer();
  69          die;
  70      }
  71  
  72  } else {
  73      $filtertype = 'course';
  74      $filterselect = $course->id;
  75  }
  76  
  77  require_login($course);
  78  
  79  // Output HTML.
  80  if ($course->id == SITEID) {
  81      $coursecontext = context_system::instance();
  82  } else {
  83      $coursecontext = context_course::instance($course->id);
  84  }
  85  
  86  require_capability('moodle/notes:view', $coursecontext);
  87  $systemcontext = context_system::instance();
  88  
  89  // Trigger event.
  90  $event = \core\event\notes_viewed::create(array(
  91      'relateduserid' => $userid,
  92      'context' => $coursecontext
  93  ));
  94  $event->trigger();
  95  
  96  $strnotes = get_string('notes', 'notes');
  97  if ($userid) {
  98      $PAGE->set_context(context_user::instance($user->id));
  99      $PAGE->navigation->extend_for_user($user);
 100  } else {
 101      $link = null;
 102      if (has_capability('moodle/course:viewparticipants', $coursecontext)
 103          || has_capability('moodle/site:viewparticipants', $systemcontext)) {
 104  
 105          $link = new moodle_url('/user/index.php', array('id' => $course->id));
 106      }
 107  }
 108  
 109  $PAGE->set_pagelayout('incourse');
 110  $PAGE->set_title($course->shortname . ': ' . $strnotes);
 111  $PAGE->set_heading($course->fullname);
 112  
 113  echo $OUTPUT->header();
 114  if ($userid) {
 115      echo $OUTPUT->heading(fullname($user).': '.$strnotes);
 116  } else {
 117      echo $OUTPUT->heading(format_string($course->shortname, true, array('context' => $coursecontext)).': '.$strnotes);
 118  }
 119  
 120  $strsitenotes = get_string('sitenotes', 'notes');
 121  $strcoursenotes = get_string('coursenotes', 'notes');
 122  $strpersonalnotes = get_string('personalnotes', 'notes');
 123  $straddnewnote = get_string('addnewnote', 'notes');
 124  
 125  echo $OUTPUT->box_start();
 126  
 127  if ($courseid != SITEID) {
 128      $context = context_course::instance($courseid);
 129      $addid = has_capability('moodle/notes:manage', $context) ? $courseid : 0;
 130      $view = has_capability('moodle/notes:view', $context);
 131      $fullname = format_string($course->fullname, true, array('context' => $context));
 132      note_print_notes(
 133          '<a name="sitenotes"></a>' . $strsitenotes,
 134          $addid,
 135          $view,
 136          0,
 137          $userid,
 138          NOTES_STATE_SITE,
 139          0
 140      );
 141      note_print_notes(
 142          '<a name="coursenotes"></a>' . $strcoursenotes. ' ('.$fullname.')',
 143          $addid,
 144          $view,
 145          $courseid,
 146          $userid,
 147          NOTES_STATE_PUBLIC,
 148          0
 149      );
 150      note_print_notes(
 151          '<a name="personalnotes"></a>' . $strpersonalnotes,
 152          $addid,
 153          $view,
 154          $courseid,
 155          $userid,
 156          NOTES_STATE_DRAFT,
 157          $USER->id
 158      );
 159  
 160  } else {  // Normal course.
 161      $view = has_capability('moodle/notes:view', context_system::instance());
 162      note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, 0, $view, 0, $userid, NOTES_STATE_SITE, 0);
 163      echo '<a name="coursenotes"></a>';
 164  
 165      if (!empty($userid)) {
 166          $courses = enrol_get_users_courses($userid);
 167          foreach ($courses as $c) {
 168              $ccontext = context_course::instance($c->id);
 169              $cfullname = format_string($c->fullname, true, array('context' => $ccontext));
 170              $header = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $c->id . '">' . $cfullname . '</a>';
 171              if (has_capability('moodle/notes:manage', context_course::instance($c->id))) {
 172                  $addid = $c->id;
 173              } else {
 174                  $addid = 0;
 175              }
 176              note_print_notes($header, $addid, $view, $c->id, $userid, NOTES_STATE_PUBLIC, 0);
 177          }
 178      }
 179  }
 180  
 181  echo $OUTPUT->box_end();
 182  
 183  echo $OUTPUT->footer();

Search This Site: