Updated the HEAD build version to 20100116
[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
18$url = new moodle_url($CFG->wwwroot.'/notes/index.php');
19if ($courseid !== SITEID) {
20 $url->param('course', $courseid);
21}
22if ($userid !== 0) {
23 $url->param('user', $userid);
24}
25if ($filtertype !== '') {
26 $url->param('filtertype', $filtertype);
27}
7a7e209d 28if ($filterselect !== 0) {
2f4a2f27 29 $url->param('filterselect', $filterselect);
30}
31$PAGE->set_url($url);
83e70cc2 32
33/// tabs compatibility
2f4a2f27 34switch($filtertype) {
35 case 'course':
36 $courseid = $filterselect;
37 break;
38 case 'site':
39 $courseid = SITEID;
40 break;
41}
83e70cc2 42
43/// locate course information
2f4a2f27 44if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
45 print_error('invalidcourseid');
46}
83e70cc2 47
48/// locate user information
2f4a2f27 49if ($userid) {
50 if (!$user = $DB->get_record('user', array('id'=>$userid))) {
51 print_error('invaliduserid');
52 }
53 $filtertype = 'user';
54 $filterselect = $user->id;
55
56 if ($user->deleted) {
57 echo $OUTPUT->header();
58 echo $OUTPUT->heading(get_string('userdeleted'));
59 echo $OUTPUT->footer();
60 die;
83e70cc2 61 }
62
2f4a2f27 63} else {
64 $filtertype = 'course';
65 $filterselect = $course->id;
66}
67
83e70cc2 68/// require login to access notes
2f4a2f27 69require_login($course);
70add_to_log($courseid, 'notes', 'view', 'index.php?course='.$courseid.'&amp;user='.$userid, 'view notes');
83e70cc2 71
2f4a2f27 72if (empty($CFG->enablenotes)) {
73 print_error('notesdisabled', 'notes');
74}
83e70cc2 75
76/// output HTML
2f4a2f27 77if ($course->id == SITEID) {
78 $coursecontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
79} else {
80 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context
81}
82$systemcontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
83
84$strnotes = get_string('notes', 'notes');
85$link = null;
86if (has_capability('moodle/course:viewparticipants', $coursecontext) || has_capability('moodle/site:viewparticipants', $systemcontext)) {
87 $link = new moodle_url($CFG->wwwroot.'/user/index.php',array('id'=>$course->id));
88}
2f4a2f27 89if ($userid) {
7a7e209d
SH
90 $PAGE->navigation->extend_for_user($user);
91} else {
92 $PAGE->navbar->add(get_string('participants'), $link);
93 $PAGE->navbar->add($strnotes);
2f4a2f27 94}
2f4a2f27 95$PAGE->set_title($course->shortname . ': ' . $strnotes);
96$PAGE->set_heading($course->fullname);
97
98echo $OUTPUT->header();
99echo $OUTPUT->heading(fullname($user));
100
101$showroles = 1;
102$currenttab = 'notes';
103require($CFG->dirroot .'/user/tabs.php');
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>';
114 $context = get_context_instance(CONTEXT_COURSE, $courseid);
115 $addid = has_capability('moodle/notes:manage', $context) ? $courseid : 0;
116 $view = has_capability('moodle/notes:view', $context);
117 note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, $addid, $view, 0, $userid, NOTES_STATE_SITE, 0);
118 note_print_notes('<a name="coursenotes"></a>' . $strcoursenotes. ' ('.$course->fullname.')', $addid, $view, $courseid, $userid, NOTES_STATE_PUBLIC, 0);
119 note_print_notes('<a name="personalnotes"></a>' . $strpersonalnotes, $addid, $view, $courseid, $userid, NOTES_STATE_DRAFT, $USER->id);
120
121} else { // Normal course
122 //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a>';
123 $view = has_capability('moodle/notes:view', get_context_instance(CONTEXT_SYSTEM));
124 note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, 0, $view, 0, $userid, NOTES_STATE_SITE, 0);
125 echo '<a name="coursenotes"></a>';
126
127 if (!empty($userid)) {
128 $courses = get_my_courses($userid);
129 foreach($courses as $c) {
130 $header = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $c->id . '">' . $c->fullname . '</a>';
131 if (has_capability('moodle/notes:manage', get_context_instance(CONTEXT_COURSE, $c->id))) {
132 $addid = $c->id;
133 } else {
134 $addid = 0;
83e70cc2 135 }
2f4a2f27 136 note_print_notes($header, $addid, $view, $c->id, $userid, NOTES_STATE_PUBLIC, 0);
83e70cc2 137 }
2f6c662f 138 }
2f4a2f27 139}
83e70cc2 140
2f4a2f27 141echo $OUTPUT->box_end();
83e70cc2 142
1d422980 143echo $OUTPUT->footer();