MDL-10984 more language strings
[moodle-pu.git] / notes / index.php
blob021be395dbbf1fafe8ad0944c896c8ff854a47ca
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');
11 // retrieve parameters
12 $courseid = optional_param('course', SITEID, PARAM_INT);
13 $userid = optional_param('user', 0, PARAM_INT);
14 $filtertype = optional_param('filtertype', '', PARAM_ALPHA);
15 $filterselect = optional_param('filterselect', 0, PARAM_INT);
17 // tabs compatibility
18 switch($filtertype) {
19 case 'course':
20 $courseid = $filterselect;
21 break;
22 case 'site':
23 $courseid = SITEID;
24 break;
27 // locate course information
28 if (!$course = get_record('course', 'id', $courseid)) {
29 error('Incorrect course id specified');
32 // locate user information
33 if ($userid) {
34 if(!$user = get_record('user', 'id', $userid)) {
35 error('Incorrect user id specified');
37 $filtertype = 'user';
38 $filterselect = $user->id;
39 } else {
40 $filtertype = 'course';
41 $filterselect = $course->id;
44 // require login to access notes
45 require_login($course->id);
46 $strnotes = get_string('notes', 'notes');
47 $crumbs = array(array('name' => $strnotes, 'link' => '', 'type' => 'activity'));
48 $currenttab = 'notes';
49 // output HTML
50 print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_navigation($crumbs));
52 require_once($CFG->dirroot .'/user/tabs.php');
54 $strsitenotes = get_string('sitenotes', 'notes');
55 $strcoursenotes = get_string('coursenotes', 'notes');
56 $strpersonalnotes = get_string('personalnotes', 'notes');
57 $straddnewnote = get_string('addnewnote', 'notes');
59 if($courseid != SITEID) {
60 echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a> | <a href="#personalnotes">' . $strpersonalnotes . '</a>';
61 $context = get_context_instance(CONTEXT_COURSE, $courseid);
62 $addid = has_capability('moodle/notes:manage', $context) ? $courseid : 0;
63 $view = has_capability('moodle/notes:view', $context);
64 note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, $addid, $view, 0, $userid, NOTES_STATE_SITE, 0);
65 note_print_notes('<a name="coursenotes"></a>' . $strcoursenotes, $addid, $view, $courseid, $userid, NOTES_STATE_PUBLIC, 0);
66 note_print_notes('<a name="personalnotes"></a>' . $strpersonalnotes, $addid, $view, $courseid, $userid, NOTES_STATE_DRAFT, $USER->id);
67 } else {
68 echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a>';
69 $view = has_capability('moodle/notes:view', get_context_instance(CONTEXT_SYSTEM));
70 note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, 0, $view, 0, $userid, NOTES_STATE_SITE, 0);
71 echo '<a name="coursenotes"></a>';
72 if($userid) {
73 $courses = get_my_courses($userid);
74 foreach($courses as $c) {
75 $header = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $c->id . '">' . $c->fullname . '</a>';
76 if (has_capability('moodle/notes:manage', get_context_instance(CONTEXT_COURSE, $c->id))) {
77 $addid = $c->id;
78 }else {
79 $addid = 0;
81 note_print_notes($header, $addid, $view, $c->id, $userid, NOTES_STATE_PUBLIC, 0);
86 add_to_log($courseid, 'notes', 'view', 'index.php?course='.$courseid.'&amp;user='.$userid, 'view notes');
88 print_footer($course);