dataid)) { error('Data ID is incorrect'); } if (! $course = get_record('course', 'id', $data->course)) { error('Course is misconfigured'); } if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) { error('Course Module ID was incorrect'); } require_login($course->id, false, $cm); $context = get_context_instance(CONTEXT_MODULE, $cm->id); if ($commentid) { if (! $comment = get_record('data_comments', 'id', $commentid)) { error('Comment ID is misconfigured'); } if ($comment->recordid != $record->id) { error('Comment ID is misconfigured'); } if (!has_capability('mod/data:managecomments', $context) && $comment->userid != $USER->id) { error('Comment is not yours to edit!'); } } switch ($mode) { case 'add': if (empty($commentcontent)) { redirect('view.php?rid='.$record->id.'&page='.$page, get_string('commentempty', 'data')); } $newcomment = new object; $newcomment->userid = $USER->id; $newcomment->created = time(); $newcomment->modified = time(); if (($newcomment->content = $commentcontent) && ($newcomment->recordid = $record->id)) { insert_record('data_comments',$newcomment); } redirect('view.php?rid='.$record->id.'&page='.$page, get_string('commentsaved', 'data')); break; case 'edit': //print edit form print_header(); print_heading(get_string('edit')); echo '