Update for latest functions
[moodle.git] / notes / index.php
CommitLineData
83e70cc2 1<?php // $Id$
2
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 */
9 require_once('../config.php');
10 require_once('lib.php');
11
12/// retrieve parameters
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/// tabs compatibility
19 switch($filtertype) {
20 case 'course':
21 $courseid = $filterselect;
22 break;
23 case 'site':
24 $courseid = SITEID;
25 break;
26 }
27
28/// locate course information
29 if (!$course = get_record('course', 'id', $courseid)) {
30 error('Incorrect course id specified');
31 }
32
33/// locate user information
34 if ($userid) {
35 if (!$user = get_record('user', 'id', $userid)) {
36 error('Incorrect user id specified');
37 }
38 $filtertype = 'user';
39 $filterselect = $user->id;
40 } else {
41 $filtertype = 'course';
42 $filterselect = $course->id;
43 }
44
45/// require login to access notes
46 require_login($course->id);
47 add_to_log($courseid, 'notes', 'view', 'index.php?course='.$courseid.'&amp;user='.$userid, 'view notes');
48
49
50/// output HTML
51
52 $strnotes = get_string('notes', 'notes');
e0c9a62d 53 $nav = array();
9f26cce6 54 $nav[] = array('name' => get_string('participants'), 'link' => $CFG->wwwroot . '/user/index.php?id=' . $course->id, 'type' => 'misc');
55 if ($userid) {
56 $nav[] = array('name' => fullname($user), 'link' => $CFG->wwwroot . '/user/view.php?id=' . $user->id. '&amp;course=' . $course->id, 'type' => 'misc');
57 }
e0c9a62d 58 $nav[] = array('name' => $strnotes, 'link' => '', 'type' => 'misc');
83e70cc2 59
60 print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_navigation($nav));
61
62 $currenttab = 'notes';
63 require_once($CFG->dirroot .'/user/tabs.php');
64
65 $strsitenotes = get_string('sitenotes', 'notes');
66 $strcoursenotes = get_string('coursenotes', 'notes');
67 $strpersonalnotes = get_string('personalnotes', 'notes');
68 $straddnewnote = get_string('addnewnote', 'notes');
69
70 print_box_start();
71
72 if ($courseid != SITEID) {
73 //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a> | <a href="#personalnotes">' . $strpersonalnotes . '</a>';
74 $context = get_context_instance(CONTEXT_COURSE, $courseid);
75 $addid = has_capability('moodle/notes:manage', $context) ? $courseid : 0;
76 $view = has_capability('moodle/notes:view', $context);
77 note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, $addid, $view, 0, $userid, NOTES_STATE_SITE, 0);
9f26cce6 78 note_print_notes('<a name="coursenotes"></a>' . $strcoursenotes. ' ('.$course->fullname.')', $addid, $view, $courseid, $userid, NOTES_STATE_PUBLIC, 0);
83e70cc2 79 note_print_notes('<a name="personalnotes"></a>' . $strpersonalnotes, $addid, $view, $courseid, $userid, NOTES_STATE_DRAFT, $USER->id);
80
81 } else { // Normal course
82 //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a>';
83 $view = has_capability('moodle/notes:view', get_context_instance(CONTEXT_SYSTEM));
84 note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, 0, $view, 0, $userid, NOTES_STATE_SITE, 0);
85 echo '<a name="coursenotes"></a>';
86
87 if (!empty($userid)) {
88 $courses = get_my_courses($userid);
89 foreach($courses as $c) {
90 $header = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $c->id . '">' . $c->fullname . '</a>';
91 if (has_capability('moodle/notes:manage', get_context_instance(CONTEXT_COURSE, $c->id))) {
92 $addid = $c->id;
93 } else {
94 $addid = 0;
95 }
96 note_print_notes($header, $addid, $view, $c->id, $userid, NOTES_STATE_PUBLIC, 0);
97 }
98 }
99 }
100
101 print_box_end();
102
103 print_footer($course);
104?>