Automatic installer.php lang files by installer_builder (20100429)
[moodle.git] / notes / index.php
blob0a36c7707f7f8c25bf132d4a0060954c865d8b27
1 <?php // $Id$
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');
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);
18 /// tabs compatibility
19 switch($filtertype) {
20 case 'course':
21 $courseid = $filterselect;
22 break;
23 case 'site':
24 $courseid = SITEID;
25 break;
28 /// locate course information
29 if (!$course = get_record('course', 'id', $courseid)) {
30 error('Incorrect course id specified');
33 /// locate user information
34 if ($userid) {
35 if (!$user = get_record('user', 'id', $userid)) {
36 error('Incorrect user id specified');
38 $filtertype = 'user';
39 $filterselect = $user->id;
41 if ($user->deleted) {
42 print_header();
43 print_heading(get_string('userdeleted'));
44 print_footer();
45 die;
48 } else {
49 $filtertype = 'course';
50 $filterselect = $course->id;
53 /// require login to access notes
54 require_login($course);
55 add_to_log($courseid, 'notes', 'view', 'index.php?course='.$courseid.'&amp;user='.$userid, 'view notes');
57 if (empty($CFG->enablenotes)) {
58 print_error('notesdisabled', 'notes');
61 /// output HTML
62 if ($course->id == SITEID) {
63 $coursecontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
64 } else {
65 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context
67 $systemcontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
69 $strnotes = get_string('notes', 'notes');
70 $nav = array();
71 if (has_capability('moodle/course:viewparticipants', $coursecontext) || has_capability('moodle/site:viewparticipants', $systemcontext)) {
72 $nav[] = array('name' => get_string('participants'), 'link' => $CFG->wwwroot . '/user/index.php?id=' . $course->id, 'type' => 'misc');
74 if ($userid) {
75 $nav[] = array('name' => fullname($user), 'link' => $CFG->wwwroot . '/user/view.php?id=' . $user->id. '&amp;course=' . $course->id, 'type' => 'misc');
77 $nav[] = array('name' => $strnotes, 'link' => '', 'type' => 'misc');
79 print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_navigation($nav));
81 $showroles = 1;
82 $currenttab = 'notes';
83 require($CFG->dirroot .'/user/tabs.php');
85 $strsitenotes = get_string('sitenotes', 'notes');
86 $strcoursenotes = get_string('coursenotes', 'notes');
87 $strpersonalnotes = get_string('personalnotes', 'notes');
88 $straddnewnote = get_string('addnewnote', 'notes');
90 print_box_start();
92 if ($courseid != SITEID) {
93 //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a> | <a href="#personalnotes">' . $strpersonalnotes . '</a>';
94 $context = get_context_instance(CONTEXT_COURSE, $courseid);
95 $addid = has_capability('moodle/notes:manage', $context) ? $courseid : 0;
96 $view = has_capability('moodle/notes:view', $context);
97 note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, $addid, $view, 0, $userid, NOTES_STATE_SITE, 0);
98 note_print_notes('<a name="coursenotes"></a>' . $strcoursenotes. ' ('.$course->fullname.')', $addid, $view, $courseid, $userid, NOTES_STATE_PUBLIC, 0);
99 note_print_notes('<a name="personalnotes"></a>' . $strpersonalnotes, $addid, $view, $courseid, $userid, NOTES_STATE_DRAFT, $USER->id);
101 } else { // Normal course
102 //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a>';
103 $view = has_capability('moodle/notes:view', get_context_instance(CONTEXT_SYSTEM));
104 note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, 0, $view, 0, $userid, NOTES_STATE_SITE, 0);
105 echo '<a name="coursenotes"></a>';
107 if (!empty($userid)) {
108 $courses = get_my_courses($userid);
109 foreach($courses as $c) {
110 $header = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $c->id . '">' . $c->fullname . '</a>';
111 if (has_capability('moodle/notes:manage', get_context_instance(CONTEXT_COURSE, $c->id))) {
112 $addid = $c->id;
113 } else {
114 $addid = 0;
116 note_print_notes($header, $addid, $view, $c->id, $userid, NOTES_STATE_PUBLIC, 0);
121 print_box_end();
123 print_footer($course);