MDL-21437 data - checkbox and multimenu fields search working + require all too
[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
3406acde 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);
64add_to_log($courseid, 'notes', 'view', 'index.php?course='.$courseid.'&amp;user='.$userid, 'view notes');
83e70cc2 65
2f4a2f27 66if (empty($CFG->enablenotes)) {
67 print_error('notesdisabled', 'notes');
68}
83e70cc2 69
70/// output HTML
2f4a2f27 71if ($course->id == SITEID) {
72 $coursecontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
73} else {
74 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context
75}
76$systemcontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
77
78$strnotes = get_string('notes', 'notes');
2f4a2f27 79if ($userid) {
3406acde 80 $PAGE->set_context(get_context_instance(CONTEXT_USER, $user->id));
7a7e209d
SH
81 $PAGE->navigation->extend_for_user($user);
82} else {
3406acde
SH
83 $link = null;
84 if (has_capability('moodle/course:viewparticipants', $coursecontext) || has_capability('moodle/site:viewparticipants', $systemcontext)) {
85 $link = new moodle_url('/user/index.php',array('id'=>$course->id));
86 }
7a7e209d
SH
87 $PAGE->navbar->add(get_string('participants'), $link);
88 $PAGE->navbar->add($strnotes);
2f4a2f27 89}
3406acde
SH
90
91$PAGE->set_pagelayout('course');
2f4a2f27 92$PAGE->set_title($course->shortname . ': ' . $strnotes);
93$PAGE->set_heading($course->fullname);
94
95echo $OUTPUT->header();
03d9401e
MD
96if ($userid) {
97 echo $OUTPUT->heading(fullname($user).': '.$strnotes);
98} else {
99 echo $OUTPUT->heading($course->shortname.': '.$strnotes);
100}
2f4a2f27 101
102$strsitenotes = get_string('sitenotes', 'notes');
103$strcoursenotes = get_string('coursenotes', 'notes');
104$strpersonalnotes = get_string('personalnotes', 'notes');
105$straddnewnote = get_string('addnewnote', 'notes');
106
107echo $OUTPUT->box_start();
108
109if ($courseid != SITEID) {
110 //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a> | <a href="#personalnotes">' . $strpersonalnotes . '</a>';
111 $context = get_context_instance(CONTEXT_COURSE, $courseid);
112 $addid = has_capability('moodle/notes:manage', $context) ? $courseid : 0;
113 $view = has_capability('moodle/notes:view', $context);
114 note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, $addid, $view, 0, $userid, NOTES_STATE_SITE, 0);
115 note_print_notes('<a name="coursenotes"></a>' . $strcoursenotes. ' ('.$course->fullname.')', $addid, $view, $courseid, $userid, NOTES_STATE_PUBLIC, 0);
116 note_print_notes('<a name="personalnotes"></a>' . $strpersonalnotes, $addid, $view, $courseid, $userid, NOTES_STATE_DRAFT, $USER->id);
117
118} else { // Normal course
119 //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a>';
120 $view = has_capability('moodle/notes:view', get_context_instance(CONTEXT_SYSTEM));
121 note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, 0, $view, 0, $userid, NOTES_STATE_SITE, 0);
122 echo '<a name="coursenotes"></a>';
123
124 if (!empty($userid)) {
df997f84 125 $courses = enrol_get_users_courses($userid);
2f4a2f27 126 foreach($courses as $c) {
127 $header = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $c->id . '">' . $c->fullname . '</a>';
128 if (has_capability('moodle/notes:manage', get_context_instance(CONTEXT_COURSE, $c->id))) {
129 $addid = $c->id;
130 } else {
131 $addid = 0;
83e70cc2 132 }
2f4a2f27 133 note_print_notes($header, $addid, $view, $c->id, $userid, NOTES_STATE_PUBLIC, 0);
83e70cc2 134 }
2f6c662f 135 }
2f4a2f27 136}
83e70cc2 137
2f4a2f27 138echo $OUTPUT->box_end();
83e70cc2 139
1d422980 140echo $OUTPUT->footer();