2006-06-29 06:48:31 +00:00
|
|
|
<?php // $Id$
|
2006-02-14 03:17:21 +00:00
|
|
|
|
|
|
|
require_once('../../config.php');
|
|
|
|
require_once('lib.php');
|
|
|
|
|
|
|
|
//param needed to go back to view.php
|
2006-03-29 17:36:20 +00:00
|
|
|
$rid = required_param('rid', PARAM_INT); // Record ID
|
|
|
|
$page = optional_param('page', 0, PARAM_INT); // Page ID
|
2006-02-14 03:17:21 +00:00
|
|
|
|
|
|
|
//param needed for comment operations
|
|
|
|
$mode = optional_param('mode','',PARAM_ALPHA);
|
|
|
|
$commentid = optional_param('commentid','',PARAM_INT);
|
|
|
|
$confirm = optional_param('confirm','',PARAM_INT);
|
2006-06-29 06:48:31 +00:00
|
|
|
$commentcontent = trim(optional_param('commentcontent','',PARAM_NOTAGS));
|
2006-02-28 01:52:38 +00:00
|
|
|
$template = optional_param('template','',PARAM_ALPHA);
|
2006-02-24 08:20:13 +00:00
|
|
|
|
|
|
|
|
2006-03-29 17:36:20 +00:00
|
|
|
if (! $record = get_record('data_records', 'id', $rid)) {
|
|
|
|
error('Record ID is incorrect');
|
|
|
|
}
|
|
|
|
if (! $data = get_record('data', 'id', $record->dataid)) {
|
|
|
|
error('Data ID is incorrect');
|
2006-02-14 03:17:21 +00:00
|
|
|
}
|
2006-03-29 17:36:20 +00:00
|
|
|
if (! $course = get_record('course', 'id', $data->course)) {
|
|
|
|
error('Course is misconfigured');
|
|
|
|
}
|
2006-12-06 20:17:58 +00:00
|
|
|
if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
|
|
|
|
error('Course Module ID was incorrect');
|
|
|
|
}
|
2006-03-29 17:36:20 +00:00
|
|
|
|
2006-12-06 20:17:58 +00:00
|
|
|
require_login($course->id, false, $cm);
|
2006-08-08 05:13:06 +00:00
|
|
|
|
2006-08-09 13:45:49 +00:00
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
|
|
|
|
|
|
|
if ($commentid) {
|
2006-03-29 17:36:20 +00:00
|
|
|
if (! $comment = get_record('data_comments', 'id', $commentid)) {
|
|
|
|
error('Comment ID is misconfigured');
|
|
|
|
}
|
|
|
|
if ($comment->recordid != $record->id) {
|
|
|
|
error('Comment ID is misconfigured');
|
|
|
|
}
|
2006-08-14 05:55:40 +00:00
|
|
|
if (!has_capability('mod/data:managecomments', $context) && $comment->userid != $USER->id) {
|
2006-03-29 17:36:20 +00:00
|
|
|
error('Comment is not yours to edit!');
|
|
|
|
}
|
2006-02-14 03:17:21 +00:00
|
|
|
}
|
2006-03-29 17:36:20 +00:00
|
|
|
|
2006-02-14 03:17:21 +00:00
|
|
|
switch ($mode) {
|
|
|
|
case 'add':
|
2006-06-29 06:48:31 +00:00
|
|
|
if (empty($commentcontent)) {
|
|
|
|
redirect('view.php?rid='.$record->id.'&page='.$page, get_string('commentempty', 'data'));
|
|
|
|
}
|
|
|
|
|
2006-02-14 03:17:21 +00:00
|
|
|
$newcomment = new object;
|
|
|
|
$newcomment->userid = $USER->id;
|
2006-02-27 02:13:48 +00:00
|
|
|
$newcomment->created = time();
|
|
|
|
$newcomment->modified = time();
|
2006-03-29 17:36:20 +00:00
|
|
|
if (($newcomment->content = $commentcontent) && ($newcomment->recordid = $record->id)) {
|
2006-02-14 03:17:21 +00:00
|
|
|
insert_record('data_comments',$newcomment);
|
|
|
|
}
|
2006-03-29 17:36:20 +00:00
|
|
|
redirect('view.php?rid='.$record->id.'&page='.$page, get_string('commentsaved', 'data'));
|
2006-02-14 03:17:21 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'edit': //print edit form
|
|
|
|
print_header();
|
2006-03-29 17:36:20 +00:00
|
|
|
print_heading(get_string('edit'));
|
2006-02-14 03:17:21 +00:00
|
|
|
echo '<div align="center">';
|
|
|
|
echo '<form action="comment.php" method="post">';
|
2006-03-29 17:36:20 +00:00
|
|
|
echo '<input type="hidden" name="commentid" value="'.$comment->id.'" />';
|
|
|
|
echo '<input type="hidden" name="rid" value="'.$record->id.'" />';
|
2006-02-14 03:17:21 +00:00
|
|
|
echo '<input type="hidden" name="page" value="'.$page.'" />';
|
|
|
|
|
|
|
|
echo '<textarea name="commentcontent">'.s($comment->content).'</textarea>';
|
|
|
|
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
|
|
|
|
echo '<input type="hidden" name="mode" value="editcommit" />';
|
|
|
|
echo '<br /><input type="submit" value="'.get_string('ok').'" />';
|
|
|
|
echo '<input type="button" value="'.get_string('cancel').'" onclick="javascript:history.go(-1)" />';
|
|
|
|
echo '</form></div>';
|
|
|
|
print_footer();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'editcommit': //update db
|
2006-06-29 06:48:31 +00:00
|
|
|
if (empty($commentcontent)) {
|
|
|
|
redirect('view.php?rid='.$record->id.'&page='.$page, get_string('commentempty', 'data'));
|
|
|
|
}
|
|
|
|
|
2006-03-29 17:36:20 +00:00
|
|
|
if ($comment) {
|
|
|
|
$newcomment = new object;
|
|
|
|
$newcomment->id = $comment->id;
|
|
|
|
$newcomment->content = $commentcontent;
|
|
|
|
$newcomment->modified = time();
|
|
|
|
update_record('data_comments',$newcomment);
|
|
|
|
}
|
|
|
|
redirect('view.php?rid='.$record->id.'&page='.$page, get_string('commentsaved', 'data'));
|
2006-02-14 03:17:21 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'delete': //deletes single comment from db
|
2006-03-29 17:36:20 +00:00
|
|
|
if ($confirm and confirm_sesskey() and $comment) {
|
|
|
|
delete_records('data_comments','id',$comment->id);
|
|
|
|
redirect('view.php?rid='.$record->id.'&page='.$page, get_string('commentdeleted', 'data'));
|
|
|
|
|
2006-02-14 03:17:21 +00:00
|
|
|
} else { //print confirm delete form
|
|
|
|
print_header();
|
2006-03-29 17:36:20 +00:00
|
|
|
data_print_comment($data, $comment, $page);
|
|
|
|
|
|
|
|
notice_yesno(get_string('deletecomment','data'),
|
|
|
|
'comment.php?rid='.$record->id.'&commentid='.$comment->id.'&page='.$page.
|
|
|
|
'&sesskey='.sesskey().'&mode=delete&confirm=1',
|
|
|
|
'view.php?rid='.$record->id.'&page='.$page);
|
2006-02-14 03:17:21 +00:00
|
|
|
print_footer();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: //print all listing, and add comment form
|
|
|
|
print_header();
|
2006-12-06 20:17:58 +00:00
|
|
|
data_print_comments($data, $record, $page);
|
2006-02-14 03:17:21 +00:00
|
|
|
print_footer();
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|