MDL-46148 qtype_calculated: validate formulas everywhere.
[moodle.git] / notes / index.php
CommitLineData
2f4a2f27 1<?php
83e70cc2 2
2f4a2f27 3/**
4 * file index.php
5 * index page to view notes.
6 * if a course id is specified then the entries from that course are shown
7 * if a user id is specified only notes related to that user are shown
8 */
9require_once('../config.php');
10require_once('lib.php');
83e70cc2 11
12/// retrieve parameters
2f4a2f27 13$courseid = optional_param('course', SITEID, PARAM_INT);
14$userid = optional_param('user', 0, PARAM_INT);
15$filtertype = optional_param('filtertype', '', PARAM_ALPHA);
16$filterselect = optional_param('filterselect', 0, PARAM_INT);
17
a6855934 18$url = new moodle_url('/notes/index.php');
7b2e259c 19if ($courseid != SITEID) {
2f4a2f27 20 $url->param('course', $courseid);
21}
22if ($userid !== 0) {
23 $url->param('user', $userid);
24}
2f4a2f27 25$PAGE->set_url($url);
83e70cc2 26
27/// tabs compatibility
2f4a2f27 28switch($filtertype) {
29 case 'course':
30 $courseid = $filterselect;
31 break;
32 case 'site':
33 $courseid = SITEID;
34 break;
35}
83e70cc2 36
7b5f1cd8
SH
37if (empty($courseid)) {
38 $courseid = SITEID;
39}
40
83e70cc2 41/// locate course information
74df2951 42$course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
83e70cc2 43
44/// locate user information
2f4a2f27 45if ($userid) {
3406acde 46 $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
2f4a2f27 47 $filtertype = 'user';
48 $filterselect = $user->id;
49
50 if ($user->deleted) {
51 echo $OUTPUT->header();
52 echo $OUTPUT->heading(get_string('userdeleted'));
53 echo $OUTPUT->footer();
54 die;
83e70cc2 55 }
56
2f4a2f27 57} else {
58 $filtertype = 'course';
59 $filterselect = $course->id;
60}
61
83e70cc2 62/// require login to access notes
2f4a2f27 63require_login($course);
83e70cc2 64/// output HTML
2f4a2f27 65if ($course->id == SITEID) {
bf0f06b1 66 $coursecontext = context_system::instance(); // SYSTEM context
2f4a2f27 67} else {
bf0f06b1 68 $coursecontext = context_course::instance($course->id); // Course context
2f4a2f27 69}
bf0f06b1 70$systemcontext = context_system::instance(); // SYSTEM context
2f4a2f27 71
c4f9401c
AA
72// Trigger event.
73$event = \core\event\notes_viewed::create(array(
c4f9401c 74 'relateduserid' => $userid,
e1b16f97 75 'context' => $coursecontext
c4f9401c
AA
76));
77$event->trigger();
78
79if (empty($CFG->enablenotes)) {
80 print_error('notesdisabled', 'notes');
81}
82
2f4a2f27 83$strnotes = get_string('notes', 'notes');
2f4a2f27 84if ($userid) {
bf0f06b1 85 $PAGE->set_context(context_user::instance($user->id));
7a7e209d
SH
86 $PAGE->navigation->extend_for_user($user);
87} else {
3406acde
SH
88 $link = null;
89 if (has_capability('moodle/course:viewparticipants', $coursecontext) || has_capability('moodle/site:viewparticipants', $systemcontext)) {
90 $link = new moodle_url('/user/index.php',array('id'=>$course->id));
91 }
2f4a2f27 92}
3406acde
SH
93
94$PAGE->set_pagelayout('course');
2f4a2f27 95$PAGE->set_title($course->shortname . ': ' . $strnotes);
96$PAGE->set_heading($course->fullname);
97
98echo $OUTPUT->header();
03d9401e
MD
99if ($userid) {
100 echo $OUTPUT->heading(fullname($user).': '.$strnotes);
101} else {
8ebbb06a 102 echo $OUTPUT->heading(format_string($course->shortname, true, array('context' => $coursecontext)).': '.$strnotes);
03d9401e 103}
2f4a2f27 104
105$strsitenotes = get_string('sitenotes', 'notes');
106$strcoursenotes = get_string('coursenotes', 'notes');
107$strpersonalnotes = get_string('personalnotes', 'notes');
108$straddnewnote = get_string('addnewnote', 'notes');
109
110echo $OUTPUT->box_start();
111
112if ($courseid != SITEID) {
113 //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a> | <a href="#personalnotes">' . $strpersonalnotes . '</a>';
bf0f06b1 114 $context = context_course::instance($courseid);
2f4a2f27 115 $addid = has_capability('moodle/notes:manage', $context) ? $courseid : 0;
116 $view = has_capability('moodle/notes:view', $context);
91d284c1 117 $fullname = format_string($course->fullname, true, array('context' => $context));
2f4a2f27 118 note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, $addid, $view, 0, $userid, NOTES_STATE_SITE, 0);
91d284c1 119 note_print_notes('<a name="coursenotes"></a>' . $strcoursenotes. ' ('.$fullname.')', $addid, $view, $courseid, $userid, NOTES_STATE_PUBLIC, 0);
2f4a2f27 120 note_print_notes('<a name="personalnotes"></a>' . $strpersonalnotes, $addid, $view, $courseid, $userid, NOTES_STATE_DRAFT, $USER->id);
121
122} else { // Normal course
123 //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a>';
bf0f06b1 124 $view = has_capability('moodle/notes:view', context_system::instance());
2f4a2f27 125 note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, 0, $view, 0, $userid, NOTES_STATE_SITE, 0);
126 echo '<a name="coursenotes"></a>';
127
128 if (!empty($userid)) {
df997f84 129 $courses = enrol_get_users_courses($userid);
2f4a2f27 130 foreach($courses as $c) {
bf0f06b1 131 $ccontext = context_course::instance($c->id);
91d284c1
SH
132 $cfullname = format_string($c->fullname, true, array('context' => $ccontext));
133 $header = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $c->id . '">' . $cfullname . '</a>';
bf0f06b1 134 if (has_capability('moodle/notes:manage', context_course::instance($c->id))) {
2f4a2f27 135 $addid = $c->id;
136 } else {
137 $addid = 0;
83e70cc2 138 }
2f4a2f27 139 note_print_notes($header, $addid, $view, $c->id, $userid, NOTES_STATE_PUBLIC, 0);
83e70cc2 140 }
2f6c662f 141 }
2f4a2f27 142}
83e70cc2 143
2f4a2f27 144echo $OUTPUT->box_end();
83e70cc2 145
1d422980 146echo $OUTPUT->footer();