forked from open-lms-open-source/moodle-mod_lightboxgallery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
comment.php
98 lines (80 loc) · 3.66 KB
/
comment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(__FILE__).'/locallib.php');
require_once(dirname(__FILE__).'/comment_form.php');
$id = required_param('id', PARAM_INT);
$delete = optional_param('delete', 0, PARAM_INT);
$confirm = optional_param('confirm', 0, PARAM_INT);
if (! $gallery = $DB->get_record('lightboxgallery', array('id' => $id))) {
print_error('invalidlightboxgalleryid', 'lightboxgallery');
}
if (! $course = $DB->get_record('course', array('id' => $gallery->course))) {
print_error('invalidcourseid');
}
if (! $cm = get_coursemodule_from_instance('lightboxgallery', $gallery->id, $course->id)) {
print_error('invalidcoursemodule');
}
if ($delete && ! $comment = $DB->get_record('lightboxgallery_comments', array('gallery' => $gallery->id, 'id' => $delete))) {
print_error('Invalid comment ID');
}
require_login($course->id);
$PAGE->set_url('/mod/lightboxgallery/view.php', array('id' => $id));
$PAGE->set_title($gallery->name);
$PAGE->set_heading($course->shortname);
$PAGE->set_button(update_module_button($cm->id, $course->id, get_string('modulename', 'lightboxgallery')));
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$galleryurl = $CFG->wwwroot.'/mod/lightboxgallery/view.php?id='.$cm->id;
if ($delete && has_capability('mod/lightboxgallery:edit', $context)) {
if ($confirm && confirm_sesskey()) {
$DB->delete_records('lightboxgallery_comments', array('id' => $comment->id));
redirect($galleryurl);
} else {
echo $OUTPUT->header();
lightboxgallery_print_comment($comment, $context);
echo('<br />');
$paramsyes = array('id' => $gallery->id, 'delete' => $comment->id, 'sesskey' => sesskey(), 'confirm' => 1);
$paramsno = array('id' => $cm->id);
echo $OUTPUT->confirm(get_string('commentdelete', 'lightboxgallery'),
new moodle_url('/mod/lightboxgallery/comment.php', $paramsyes),
new moodle_url('/mod/lightboxgallery/view.php', $paramsno));
echo $OUTPUT->footer();
die();
}
}
require_capability('mod/lightboxgallery:addcomment', $context);
if (! $gallery->comments) {
print_error('Comments disabled', $galleryurl);
}
$mform = new mod_lightboxgallery_comment_form(null, $gallery);
if ($mform->is_cancelled()) {
redirect($galleryurl);
} else if ($formadata = $mform->get_data()) {
$newcomment = new object;
$newcomment->gallery = $gallery->id;
$newcomment->userid = $USER->id;
$newcomment->comment = $formadata->comment['text'];
$newcomment->timemodified = time();
if ($DB->insert_record('lightboxgallery_comments', $newcomment)) {
add_to_log($course->id, 'lightboxgallery', 'comment', 'view.php?id='.$cm->id, $gallery->id, $cm->id, $USER->id);
redirect($galleryurl, get_string('commentadded', 'lightboxgallery'));
} else {
print_error('Comment creation failed');
}
}
echo $OUTPUT->header();
$mform->display();
echo $OUTPUT->footer();