Example #1
0
        $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();