Beispiel #1
0
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/data:comment', $context);
if ($commentid) {
    if (!($comment = $DB->get_record('data_comments', array('id' => $commentid)))) {
        print_error('commentmisconf');
    }
    if ($comment->recordid != $record->id) {
        print_error('commentmisconf');
    }
    if (!has_capability('mod/data:managecomments', $context) && $comment->userid != $USER->id) {
        print_error('cannoteditcomment');
    }
} else {
    $comment = false;
}
$mform = new mod_data_comment_form();
$mform->set_data(array('mode' => $mode, 'page' => $page, 'rid' => $record->id, 'commentid' => $commentid));
if ($comment) {
    $format = $comment->format;
    $content = $comment->content;
    if (can_use_html_editor()) {
        $options = new object();
        $options->smiley = false;
        $options->filter = false;
        $content = format_text($content, $format, $options);
        $format = FORMAT_HTML;
    }
    $mform->set_data(array('content' => $content, 'format' => $format));
}
if ($mform->is_cancelled()) {
    redirect('view.php?rid=' . $record->id . '&page=' . $page);
Beispiel #2
0
function data_print_comments($data, $record, $page = 0, $mform = false)
{
    global $CFG;
    $cm = get_coursemodule_from_instance('data', $data->id);
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
    $cancomment = has_capability('mod/data:comment', $context);
    echo '<a name="comments"></a>';
    if ($comments = get_records('data_comments', 'recordid', $record->id)) {
        foreach ($comments as $comment) {
            data_print_comment($data, $comment, $page);
        }
        echo '<br />';
    }
    if (!isloggedin() or isguest() or !$cancomment) {
        return;
    }
    $editor = optional_param('addcomment', 0, PARAM_BOOL);
    if (!$mform and !$editor) {
        echo '<div class="newcomment" style="text-align:center">';
        echo '<a href="view.php?d=' . $data->id . '&amp;rid=' . $record->id . '&amp;mode=single&amp;addcomment=1">' . get_string('addcomment', 'data') . '</a>';
        echo '</div>';
    } else {
        if (!$mform) {
            require_once 'comment_form.php';
            $mform = new mod_data_comment_form('comment.php');
            $mform->set_data(array('mode' => 'add', 'page' => $page, 'rid' => $record->id));
        }
        echo '<div class="newcomment" style="text-align:center">';
        $mform->display();
        echo '</div>';
    }
}