Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * file index.php
19
 * index page to view notes.
20
 * if a course id is specified then the entries from that course are shown
21
 * if a user id is specified only notes related to that user are shown
22
 */
23
require_once('../config.php');
24
require_once('lib.php');
25
require_once($CFG->dirroot . '/course/lib.php');
26
 
27
$courseid     = optional_param('course', SITEID, PARAM_INT);
28
$userid       = optional_param('user', 0, PARAM_INT);
29
$filtertype   = optional_param('filtertype', '', PARAM_ALPHA);
30
$filterselect = optional_param('filterselect', 0, PARAM_INT);
31
 
32
if (empty($CFG->enablenotes)) {
33
    throw new \moodle_exception('notesdisabled', 'notes');
34
}
35
 
36
$url = new moodle_url('/notes/index.php');
37
if ($courseid != SITEID) {
38
    $url->param('course', $courseid);
39
}
40
if ($userid !== 0) {
41
    $url->param('user', $userid);
42
}
43
$PAGE->set_url($url);
44
 
45
// Tabs compatibility.
46
switch($filtertype) {
47
    case 'course':
48
        $courseid = $filterselect;
49
        break;
50
    case 'site':
51
        $courseid = SITEID;
52
        break;
53
}
54
 
55
if (empty($courseid)) {
56
    $courseid = SITEID;
57
}
58
 
59
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
60
 
61
if ($userid) {
62
    $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
63
    $filtertype = 'user';
64
    $filterselect = $user->id;
65
 
66
    if ($user->deleted) {
67
        echo $OUTPUT->header();
68
        echo $OUTPUT->heading(get_string('userdeleted'));
69
        echo $OUTPUT->footer();
70
        die;
71
    }
72
 
73
} else {
74
    $filtertype = 'course';
75
    $filterselect = $course->id;
76
    $user = $USER;
77
}
78
 
79
require_login($course);
80
 
81
// Output HTML.
82
if ($course->id == SITEID) {
83
    $coursecontext = context_system::instance();
84
} else {
85
    $coursecontext = context_course::instance($course->id);
86
}
87
 
88
require_capability('moodle/notes:view', $coursecontext);
89
$systemcontext = context_system::instance();
90
 
91
// Trigger event.
92
note_view($coursecontext, $userid);
93
 
94
$strnotes = get_string('notes', 'notes');
95
if ($userid && $course->id == SITEID) {
96
    $PAGE->set_context(context_user::instance($user->id));
97
    $PAGE->navigation->extend_for_user($user);
98
    // If we are looking at our own notes, then change focus to 'my notes'.
99
    if ($userid == $USER->id) {
100
        $notenode = $PAGE->navigation->find('notes', null)->make_inactive();
101
    }
102
 
103
    $notesurl = new moodle_url('/notes/index.php', array('user' => $userid));
104
    $PAGE->navbar->add(get_string('notes', 'notes'), $notesurl);
105
} else if ($course->id != SITEID) {
106
    $notenode = $PAGE->navigation->find('currentcoursenotes', null)->make_inactive();
107
 
108
    $notesurl = new moodle_url('/notes/index.php', array('user' => $userid, 'course' => $courseid));
109
    $PAGE->navbar->add(get_string('notes', 'notes'), $notesurl);
110
 
111
    $PAGE->set_context(context_course::instance($courseid));
112
} else {
113
    $link = null;
114
    if (course_can_view_participants($coursecontext) || course_can_view_participants($systemcontext)) {
115
        $link = new moodle_url('/user/index.php', array('id' => $course->id));
116
    }
117
}
118
 
119
$PAGE->set_pagelayout('incourse');
120
$PAGE->set_title($course->fullname);
121
if ($course->id == SITEID) {
122
    $PAGE->set_heading(fullname($user));
123
} else {
124
    $PAGE->set_heading($course->fullname);
125
}
126
 
127
echo $OUTPUT->header();
128
 
129
if ($course->id != SITEID) {
130
    $backurl = new moodle_url('/user/view.php', ['id' => $userid, 'course' => $courseid]);
131
    echo $OUTPUT->single_button($backurl, get_string('back'), 'get', ['class' => 'mb-3']);
132
 
133
    $headerinfo = array('heading' => fullname($user), 'user' => $user);
134
    echo $OUTPUT->context_header($headerinfo, 2);
135
}
136
 
137
echo $OUTPUT->heading($strnotes);
138
 
139
$strsitenotes = get_string('sitenotes', 'notes');
140
$strcoursenotes = get_string('coursenotes', 'notes');
141
$strpersonalnotes = get_string('personalnotes', 'notes');
142
$straddnewnote = get_string('addnewnote', 'notes');
143
 
144
echo $OUTPUT->box_start();
145
 
146
if ($courseid != SITEID) {
147
    $context = context_course::instance($courseid);
148
    $addid = has_capability('moodle/notes:manage', $context) ? $courseid : 0;
149
    $view = has_capability('moodle/notes:view', $context);
150
    $fullname = format_string($course->fullname, true, array('context' => $context));
151
    note_print_notes(
152
        '<a name="sitenotes"></a>' . $strsitenotes,
153
        $addid,
154
        $view,
155
        0,
156
        $userid,
157
        NOTES_STATE_SITE,
158
 
159
    );
160
    note_print_notes(
161
        '<a name="coursenotes"></a>' . $strcoursenotes. ' ('.$fullname.')',
162
        $addid,
163
        $view,
164
        $courseid,
165
        $userid,
166
        NOTES_STATE_PUBLIC,
167
 
168
    );
169
    note_print_notes(
170
        '<a name="personalnotes"></a>' . $strpersonalnotes,
171
        $addid,
172
        $view,
173
        $courseid,
174
        $userid,
175
        NOTES_STATE_DRAFT,
176
        $USER->id
177
    );
178
 
179
} else {  // Normal course.
180
    $view = has_capability('moodle/notes:view', context_system::instance());
181
    note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, 0, $view, 0, $userid, NOTES_STATE_SITE, 0);
182
    echo '<a name="coursenotes"></a>';
183
 
184
    if (!empty($userid)) {
185
        $courses = enrol_get_users_courses($userid);
186
        foreach ($courses as $c) {
187
            $ccontext = context_course::instance($c->id);
188
            $cfullname = format_string($c->fullname, true, array('context' => $ccontext));
189
            $header = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $c->id . '">' . $cfullname . '</a>';
190
            $viewcoursenotes = has_capability('moodle/notes:view', $ccontext);
191
            if (has_capability('moodle/notes:manage', $ccontext)) {
192
                $addid = $c->id;
193
            } else {
194
                $addid = 0;
195
            }
196
            note_print_notes($header, $addid, $viewcoursenotes, $c->id, $userid, NOTES_STATE_PUBLIC, 0);
197
        }
198
    }
199
}
200
 
201
echo $OUTPUT->box_end();
202
 
203
echo $OUTPUT->footer();