-
Notifications
You must be signed in to change notification settings - Fork 1
/
comment.php
80 lines (63 loc) · 2.93 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
<?php
require_once('../../config.php');
require_once('lib.php');
require_once('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 = get_record('lightboxgallery', 'id', $id)) {
error('Course module is incorrect');
}
if (! $course = get_record('course', 'id', $gallery->course)) {
error('Course is misconfigured');
}
if (! $cm = get_coursemodule_from_instance('lightboxgallery', $gallery->id, $course->id)) {
error('Course Module ID was incorrect');
}
if ($delete && ! $comment = get_record('lightboxgallery_comments', 'gallery', $gallery->id, 'id', $delete)) {
error('Invalid comment ID');
}
require_login($course->id);
$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()) {
delete_records('lightboxgallery_comments', 'id', $comment->id);
redirect($galleryurl);
} else {
print_header();
lightboxgallery_print_comment($comment, $context);
echo('<br />');
notice_yesno(get_string('commentdelete', 'lightboxgallery'),
$CFG->wwwroot . '/mod/lightboxgallery/comment.php', $CFG->wwwroot . '/mod/lightboxgallery/view.php',
array('id' => $gallery->id, 'delete' => $comment->id, 'sesskey' => sesskey(), 'confirm' => 1), array('id' => $cm->id),
'post', 'get');
print_footer();
die();
}
}
require_capability('mod/lightboxgallery:addcomment', $context);
if (! $gallery->comments) {
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;
$newcomment->timemodified = time();
if (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 {
error('Comment creation failed');
}
}
$navigation = build_navigation(get_string('addcomment', 'lightboxgallery'), $cm);
print_header($course->shortname . ': ' . $gallery->name, $course->fullname, $navigation, '', '', true, ' ', navmenu($course, $cm));
$mform->display();
print_footer($course);
?>