registration MDL-22662 display explicit error message when ws communication fail...
[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');
2f4a2f27 19if ($courseid !== SITEID) {
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
37/// locate course information
3406acde 38$course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
83e70cc2 39
40/// locate user information
2f4a2f27 41if ($userid) {
3406acde 42 $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
2f4a2f27 43 $filtertype = 'user';
44 $filterselect = $user->id;
45
46 if ($user->deleted) {
47 echo $OUTPUT->header();
48 echo $OUTPUT->heading(get_string('userdeleted'));
49 echo $OUTPUT->footer();
50 die;
83e70cc2 51 }
52
2f4a2f27 53} else {
54 $filtertype = 'course';
55 $filterselect = $course->id;
56}
57
83e70cc2 58/// require login to access notes
2f4a2f27 59require_login($course);
60add_to_log($courseid, 'notes', 'view', 'index.php?course='.$courseid.'&amp;user='.$userid, 'view notes');
83e70cc2 61
2f4a2f27 62if (empty($CFG->enablenotes)) {
63 print_error('notesdisabled', 'notes');
64}
83e70cc2 65
66/// output HTML
2f4a2f27 67if ($course->id == SITEID) {
68 $coursecontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
69} else {
70 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context
71}
72$systemcontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
73
74$strnotes = get_string('notes', 'notes');
2f4a2f27 75if ($userid) {
3406acde 76 $PAGE->set_context(get_context_instance(CONTEXT_USER, $user->id));
7a7e209d
SH
77 $PAGE->navigation->extend_for_user($user);
78} else {
3406acde
SH
79 $link = null;
80 if (has_capability('moodle/course:viewparticipants', $coursecontext) || has_capability('moodle/site:viewparticipants', $systemcontext)) {
81 $link = new moodle_url('/user/index.php',array('id'=>$course->id));
82 }
7a7e209d
SH
83 $PAGE->navbar->add(get_string('participants'), $link);
84 $PAGE->navbar->add($strnotes);
2f4a2f27 85}
3406acde
SH
86
87$PAGE->set_pagelayout('course');
2f4a2f27 88$PAGE->set_title($course->shortname . ': ' . $strnotes);
89$PAGE->set_heading($course->fullname);
90
91echo $OUTPUT->header();
03d9401e
MD
92if ($userid) {
93 echo $OUTPUT->heading(fullname($user).': '.$strnotes);
94} else {
95 echo $OUTPUT->heading($course->shortname.': '.$strnotes);
96}
2f4a2f27 97
98$strsitenotes = get_string('sitenotes', 'notes');
99$strcoursenotes = get_string('coursenotes', 'notes');
100$strpersonalnotes = get_string('personalnotes', 'notes');
101$straddnewnote = get_string('addnewnote', 'notes');
102
103echo $OUTPUT->box_start();
104
105if ($courseid != SITEID) {
106 //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a> | <a href="#personalnotes">' . $strpersonalnotes . '</a>';
107 $context = get_context_instance(CONTEXT_COURSE, $courseid);
108 $addid = has_capability('moodle/notes:manage', $context) ? $courseid : 0;
109 $view = has_capability('moodle/notes:view', $context);
110 note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, $addid, $view, 0, $userid, NOTES_STATE_SITE, 0);
111 note_print_notes('<a name="coursenotes"></a>' . $strcoursenotes. ' ('.$course->fullname.')', $addid, $view, $courseid, $userid, NOTES_STATE_PUBLIC, 0);
112 note_print_notes('<a name="personalnotes"></a>' . $strpersonalnotes, $addid, $view, $courseid, $userid, NOTES_STATE_DRAFT, $USER->id);
113
114} else { // Normal course
115 //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a>';
116 $view = has_capability('moodle/notes:view', get_context_instance(CONTEXT_SYSTEM));
117 note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, 0, $view, 0, $userid, NOTES_STATE_SITE, 0);
118 echo '<a name="coursenotes"></a>';
119
120 if (!empty($userid)) {
121 $courses = get_my_courses($userid);
122 foreach($courses as $c) {
123 $header = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $c->id . '">' . $c->fullname . '</a>';
124 if (has_capability('moodle/notes:manage', get_context_instance(CONTEXT_COURSE, $c->id))) {
125 $addid = $c->id;
126 } else {
127 $addid = 0;
83e70cc2 128 }
2f4a2f27 129 note_print_notes($header, $addid, $view, $c->id, $userid, NOTES_STATE_PUBLIC, 0);
83e70cc2 130 }
2f6c662f 131 }
2f4a2f27 132}
83e70cc2 133
2f4a2f27 134echo $OUTPUT->box_end();
83e70cc2 135
1d422980 136echo $OUTPUT->footer();