Merge branch 'wip-mdl-41843-m25' of git://github.com/rajeshtaneja/moodle into MOODLE_...
[moodle.git] / notes / index.php
blob62c01b9979d6f362625f4d5a711e1d580f0e6ccb
1 <?php
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 $url = new moodle_url('/notes/index.php');
19 if ($courseid != SITEID) {
20 $url->param('course', $courseid);
22 if ($userid !== 0) {
23 $url->param('user', $userid);
25 $PAGE->set_url($url);
27 /// tabs compatibility
28 switch($filtertype) {
29 case 'course':
30 $courseid = $filterselect;
31 break;
32 case 'site':
33 $courseid = SITEID;
34 break;
37 if (empty($courseid)) {
38 $courseid = SITEID;
41 /// locate course information
42 $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
44 /// locate user information
45 if ($userid) {
46 $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
47 $filtertype = 'user';
48 $filterselect = $user->id;
50 if ($user->deleted) {
51 echo $OUTPUT->header();
52 echo $OUTPUT->heading(get_string('userdeleted'));
53 echo $OUTPUT->footer();
54 die;
57 } else {
58 $filtertype = 'course';
59 $filterselect = $course->id;
62 /// require login to access notes
63 require_login($course);
64 add_to_log($courseid, 'notes', 'view', 'index.php?course='.$courseid.'&amp;user='.$userid, 'view notes');
66 if (empty($CFG->enablenotes)) {
67 print_error('notesdisabled', 'notes');
70 /// output HTML
71 if ($course->id == SITEID) {
72 $coursecontext = context_system::instance(); // SYSTEM context
73 } else {
74 $coursecontext = context_course::instance($course->id); // Course context
76 $systemcontext = context_system::instance(); // SYSTEM context
78 $strnotes = get_string('notes', 'notes');
79 if ($userid) {
80 $PAGE->set_context(context_user::instance($user->id));
81 $PAGE->navigation->extend_for_user($user);
82 } else {
83 $link = null;
84 if (has_capability('moodle/course:viewparticipants', $coursecontext) || has_capability('moodle/site:viewparticipants', $systemcontext)) {
85 $link = new moodle_url('/user/index.php',array('id'=>$course->id));
89 $PAGE->set_pagelayout('course');
90 $PAGE->set_title($course->shortname . ': ' . $strnotes);
91 $PAGE->set_heading($course->fullname);
93 echo $OUTPUT->header();
94 if ($userid) {
95 echo $OUTPUT->heading(fullname($user).': '.$strnotes);
96 } else {
97 echo $OUTPUT->heading(format_string($course->shortname, true, array('context' => $coursecontext)).': '.$strnotes);
100 $strsitenotes = get_string('sitenotes', 'notes');
101 $strcoursenotes = get_string('coursenotes', 'notes');
102 $strpersonalnotes = get_string('personalnotes', 'notes');
103 $straddnewnote = get_string('addnewnote', 'notes');
105 echo $OUTPUT->box_start();
107 if ($courseid != SITEID) {
108 //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a> | <a href="#personalnotes">' . $strpersonalnotes . '</a>';
109 $context = context_course::instance($courseid);
110 $addid = has_capability('moodle/notes:manage', $context) ? $courseid : 0;
111 $view = has_capability('moodle/notes:view', $context);
112 $fullname = format_string($course->fullname, true, array('context' => $context));
113 note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, $addid, $view, 0, $userid, NOTES_STATE_SITE, 0);
114 note_print_notes('<a name="coursenotes"></a>' . $strcoursenotes. ' ('.$fullname.')', $addid, $view, $courseid, $userid, NOTES_STATE_PUBLIC, 0);
115 note_print_notes('<a name="personalnotes"></a>' . $strpersonalnotes, $addid, $view, $courseid, $userid, NOTES_STATE_DRAFT, $USER->id);
117 } else { // Normal course
118 //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a>';
119 $view = has_capability('moodle/notes:view', context_system::instance());
120 note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, 0, $view, 0, $userid, NOTES_STATE_SITE, 0);
121 echo '<a name="coursenotes"></a>';
123 if (!empty($userid)) {
124 $courses = enrol_get_users_courses($userid);
125 foreach($courses as $c) {
126 $ccontext = context_course::instance($c->id);
127 $cfullname = format_string($c->fullname, true, array('context' => $ccontext));
128 $header = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $c->id . '">' . $cfullname . '</a>';
129 if (has_capability('moodle/notes:manage', context_course::instance($c->id))) {
130 $addid = $c->id;
131 } else {
132 $addid = 0;
134 note_print_notes($header, $addid, $view, $c->id, $userid, NOTES_STATE_PUBLIC, 0);
139 echo $OUTPUT->box_end();
141 echo $OUTPUT->footer();