Fixed some notices on some custom pages
[moodle.git] / notes / index.php
CommitLineData
eca3af25 1<?php // $Id$\r
2\r
3/**\r
4 * file index.php\r
5 * index page to view notes. \r
6 * if a course id is specified then the entries from that course are shown\r
7 * if a user id is specified only notes related to that user are shown\r
8 */\r
9require_once('../config.php');\r
10require_once('lib.php');\r
11// retrieve parameters\r
12$courseid = optional_param('course', SITEID, PARAM_INT);\r
13$userid = optional_param('user', 0, PARAM_INT);\r
14$filtertype = optional_param('filtertype', '', PARAM_ALPHA);\r
15$filterselect = optional_param('filterselect', 0, PARAM_INT);\r
16\r
17// tabs compatibility\r
18switch($filtertype) {\r
19 case 'course':\r
20 $courseid = $filterselect;\r
21 break;\r
22 case 'site':\r
23 $courseid = SITEID;\r
24 break;\r
25}\r
26\r
27// locate course information\r
28if (!$course = get_record('course', 'id', $courseid)) {\r
29 error('Incorrect course id specified');\r
30}\r
31\r
32// locate user information\r
33if ($userid) {\r
34 if(!$user = get_record('user', 'id', $userid)) {\r
35 error('Incorrect user id specified');\r
36 }\r
37 $filtertype = 'user';\r
38 $filterselect = $user->id;\r
39} else {\r
40 $filtertype = 'course';\r
41 $filterselect = $course->id;\r
42}\r
43\r
44// require login to access notes\r
45require_login($course->id);\r
46$strnotes = get_string('notes', 'notes');\r
47$crumbs = array(array('name' => $strnotes, 'link' => '', 'type' => 'activity'));\r
48$currenttab = 'notes';\r
49// output HTML\r
50print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_navigation($crumbs));\r
51\r
52require_once($CFG->dirroot .'/user/tabs.php');\r
53\r
c55dee3f 54$strsitenotes = get_string('sitenotes', 'notes');\r
55$strcoursenotes = get_string('coursenotes', 'notes');\r
56$strpersonalnotes = get_string('personalnotes', 'notes');\r
57$straddnewnote = get_string('addnewnote', 'notes');\r
58\r
eca3af25 59if($courseid != SITEID) {\r
c55dee3f 60 echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a> | <a href="#personalnotes">' . $strpersonalnotes . '</a>';\r
eca3af25 61 $context = get_context_instance(CONTEXT_COURSE, $courseid);\r
c55dee3f 62 $addid = has_capability('moodle/notes:manage', $context) ? $courseid : 0;\r
63 $view = has_capability('moodle/notes:view', $context);\r
64 note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, $addid, $view, 0, $userid, NOTES_STATE_SITE, 0);\r
65 note_print_notes('<a name="coursenotes"></a>' . $strcoursenotes, $addid, $view, $courseid, $userid, NOTES_STATE_PUBLIC, 0);\r
66 note_print_notes('<a name="personalnotes"></a>' . $strpersonalnotes, $addid, $view, $courseid, $userid, NOTES_STATE_DRAFT, $USER->id);\r
eca3af25 67} else {\r
c55dee3f 68 echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a>';\r
69 $view = has_capability('moodle/notes:view', get_context_instance(CONTEXT_SYSTEM));\r
70 note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, 0, $view, 0, $userid, NOTES_STATE_SITE, 0);\r
71 echo '<a name="coursenotes"></a>';\r
eca3af25 72 if($userid) {\r
73 $courses = get_my_courses($userid);\r
74 foreach($courses as $c) {\r
75 $header = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $c->id . '">' . $c->fullname . '</a>';\r
c55dee3f 76 if (has_capability('moodle/notes:manage', get_context_instance(CONTEXT_COURSE, $c->id))) {\r
77 $addid = $c->id;\r
78 }else {\r
79 $addid = 0;\r
80 }\r
81 note_print_notes($header, $addid, $view, $c->id, $userid, NOTES_STATE_PUBLIC, 0);\r
eca3af25 82 }\r
83 }\r
84} \r
85\r
86add_to_log($courseid, 'notes', 'view', 'index.php?course='.$courseid.'&amp;user='.$userid, 'view notes');\r
87\r
c55dee3f 88print_footer($course);