calendar MDL-19793 Upgrade deprecated calls and added set_url calls
[moodle.git] / notes / index.php
CommitLineData
83e70cc2 1<?php // $Id$
2
3 /**
4 * file index.php
2f6c662f 5 * index page to view notes.
83e70cc2 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
b3829d0a 29 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
38eac4d5 30 print_error('invalidcourseid');
83e70cc2 31 }
32
33/// locate user information
34 if ($userid) {
b3829d0a 35 if (!$user = $DB->get_record('user', array('id'=>$userid))) {
38eac4d5 36 print_error('invaliduserid');
83e70cc2 37 }
38 $filtertype = 'user';
39 $filterselect = $user->id;
f5fc83e8 40
41 if ($user->deleted) {
fb676024 42 echo $OUTPUT->header();
587a4eb0 43 echo $OUTPUT->heading(get_string('userdeleted'));
3c1d69dd 44 echo $OUTPUT->footer();
f5fc83e8 45 die;
46 }
47
83e70cc2 48 } else {
49 $filtertype = 'course';
50 $filterselect = $course->id;
51 }
52
53/// require login to access notes
241bcec5 54 require_login($course);
83e70cc2 55 add_to_log($courseid, 'notes', 'view', 'index.php?course='.$courseid.'&amp;user='.$userid, 'view notes');
56
90658eef 57 if (empty($CFG->enablenotes)) {
58 print_error('notesdisabled', 'notes');
59 }
83e70cc2 60
61/// output HTML
b26adbef 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
66 }
67 $systemcontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
c7a2fd97 68
83e70cc2 69 $strnotes = get_string('notes', 'notes');
fb676024 70 $link = null;
b26adbef 71 if (has_capability('moodle/course:viewparticipants', $coursecontext) || has_capability('moodle/site:viewparticipants', $systemcontext)) {
fb676024 72 $link = new moodle_url($CFG->wwwroot.'/user/index.php',array('id'=>$course->id));
b26adbef 73 }
fb676024 74 $PAGE->navbar->add(get_string('participants'), $link);
9f26cce6 75 if ($userid) {
fb676024 76 $PAGE->navbar->add(fullname($user), new moodle_url($CFG->wwwroot.'/user/view.php', array('id'=>$user->id,'course'=>$course->id)));
9f26cce6 77 }
fb676024 78 $PAGE->navbar->add($strnotes);
79 $PAGE->set_title($course->shortname . ': ' . $strnotes);
80 $PAGE->set_heading($course->fullname);
81
82 echo $OUTPUT->header();
83 echo $OUTPUT->heading(fullname($user));
83e70cc2 84
2f6c662f 85 $showroles = 1;
83e70cc2 86 $currenttab = 'notes';
241bcec5 87 require($CFG->dirroot .'/user/tabs.php');
83e70cc2 88
89 $strsitenotes = get_string('sitenotes', 'notes');
90 $strcoursenotes = get_string('coursenotes', 'notes');
91 $strpersonalnotes = get_string('personalnotes', 'notes');
92 $straddnewnote = get_string('addnewnote', 'notes');
93
c7a2fd97 94 echo $OUTPUT->box_start();
83e70cc2 95
96 if ($courseid != SITEID) {
97 //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a> | <a href="#personalnotes">' . $strpersonalnotes . '</a>';
98 $context = get_context_instance(CONTEXT_COURSE, $courseid);
99 $addid = has_capability('moodle/notes:manage', $context) ? $courseid : 0;
100 $view = has_capability('moodle/notes:view', $context);
101 note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, $addid, $view, 0, $userid, NOTES_STATE_SITE, 0);
9f26cce6 102 note_print_notes('<a name="coursenotes"></a>' . $strcoursenotes. ' ('.$course->fullname.')', $addid, $view, $courseid, $userid, NOTES_STATE_PUBLIC, 0);
83e70cc2 103 note_print_notes('<a name="personalnotes"></a>' . $strpersonalnotes, $addid, $view, $courseid, $userid, NOTES_STATE_DRAFT, $USER->id);
104
105 } else { // Normal course
106 //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a>';
107 $view = has_capability('moodle/notes:view', get_context_instance(CONTEXT_SYSTEM));
108 note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, 0, $view, 0, $userid, NOTES_STATE_SITE, 0);
109 echo '<a name="coursenotes"></a>';
110
111 if (!empty($userid)) {
112 $courses = get_my_courses($userid);
113 foreach($courses as $c) {
114 $header = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $c->id . '">' . $c->fullname . '</a>';
115 if (has_capability('moodle/notes:manage', get_context_instance(CONTEXT_COURSE, $c->id))) {
116 $addid = $c->id;
117 } else {
118 $addid = 0;
119 }
120 note_print_notes($header, $addid, $view, $c->id, $userid, NOTES_STATE_PUBLIC, 0);
121 }
122 }
2f6c662f 123 }
83e70cc2 124
c7a2fd97 125 echo $OUTPUT->box_end();
83e70cc2 126
3c1d69dd 127 echo $OUTPUT->footer();
83e70cc2 128?>