From: skodak Date: Wed, 13 Dec 2006 23:09:34 +0000 (+0000) Subject: MDL-5964 need html editor for comments in database mod + added format sql table field X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=40b6dd0116eedc05bab6bce8aa949cc44bba5b81;p=moodle.git MDL-5964 need html editor for comments in database mod + added format sql table field MDL-7813 accessiblity fixes in comments --- diff --git a/lang/en_utf8/data.php b/lang/en_utf8/data.php index 89c2f22ac1..be397ac236 100644 --- a/lang/en_utf8/data.php +++ b/lang/en_utf8/data.php @@ -28,6 +28,7 @@ $string['chooseorupload'] = 'Choose file'; $string['columns'] = 'columns'; $string['commentdeleted'] = 'Comment deleted'; $string['commentempty'] = 'Comment was empty'; +$string['comment'] = 'Comment'; $string['comments'] = 'Comments'; $string['commentsaved'] = 'Comment saved'; $string['commentsn'] = '$a comment(s)'; diff --git a/mod/data/comment.php b/mod/data/comment.php index bc2cea1f6a..191f120dc8 100755 --- a/mod/data/comment.php +++ b/mod/data/comment.php @@ -2,17 +2,16 @@ require_once('../../config.php'); require_once('lib.php'); + require_once('comment_form.php'); //param needed to go back to view.php - $rid = required_param('rid', PARAM_INT); // Record ID - $page = optional_param('page', 0, PARAM_INT); // Page ID + $rid = required_param('rid', PARAM_INT); // Record ID + $page = optional_param('page', 0, PARAM_INT); // Page ID //param needed for comment operations - $mode = optional_param('mode','',PARAM_ALPHA); + $mode = optional_param('mode','add',PARAM_ALPHA); $commentid = optional_param('commentid','',PARAM_INT); $confirm = optional_param('confirm','',PARAM_INT); - $commentcontent = trim(optional_param('commentcontent','',PARAM_NOTAGS)); - $template = optional_param('template','',PARAM_ALPHA); if (! $record = get_record('data_records', 'id', $rid)) { @@ -42,55 +41,67 @@ if (!has_capability('mod/data:managecomments', $context) && $comment->userid != $USER->id) { error('Comment is not yours to edit!'); } + } else { + $comment = false; + } + + + $mform = new data_comment_form('comment.php'); + $mform->set_defaults(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_defaults(array('content'=>$content, 'format'=>$format)); + } + + + if ($mform->is_cancelled()) { + redirect('view.php?rid='.$record->id.'&page='.$page); } switch ($mode) { case 'add': - if (empty($commentcontent)) { - redirect('view.php?rid='.$record->id.'&page='.$page, get_string('commentempty', 'data')); + if (!$formadata = $mform->data_submitted()) { + break; // something is wrong here, try again } - $newcomment = new object; - $newcomment->userid = $USER->id; - $newcomment->created = time(); + $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); + $newcomment->content = $formadata->content; + $newcomment->recordid = $formadata->rid; + if (insert_record('data_comments',$newcomment)) { + redirect('view.php?rid='.$record->id.'&page='.$page); + } else { + error('Error while saving comment.'); } - 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 '
'; - echo '
'; - echo ''; - echo ''; - echo ''; - - echo ''; - echo ''; - echo ''; - echo '
'; - echo ''; - echo '
'; - print_footer(); break; - case 'editcommit': //update db - if (empty($commentcontent)) { - redirect('view.php?rid='.$record->id.'&page='.$page, get_string('commentempty', 'data')); + case 'edit': //print edit form + if (!$formadata = $mform->data_submitted()) { + break; // something is wrong here, try again } - if ($comment) { - $newcomment = new object; - $newcomment->id = $comment->id; - $newcomment->content = $commentcontent; - $newcomment->modified = time(); - update_record('data_comments',$newcomment); + $updatedcomment = new object(); + $updatedcomment->id = $formadata->commentid; + $updatedcomment->content = $formadata->content; + $updatedcomment->format = $formadata->format; + $updatedcomment->modified = time(); + + if (update_record('data_comments',$updatedcomment)) { + redirect('view.php?rid='.$record->id.'&page='.$page); + } else { + error('Error while saving comment.'); } - redirect('view.php?rid='.$record->id.'&page='.$page, get_string('commentsaved', 'data')); break; case 'delete': //deletes single comment from db @@ -108,16 +119,14 @@ 'view.php?rid='.$record->id.'&page='.$page); print_footer(); } - - break; - - default: //print all listing, and add comment form - print_header(); - data_print_comments($data, $record, $page); - print_footer(); + die; break; } + print_header(); + data_print_comments($data, $record, $page, $mform); + print_footer(); + ?> diff --git a/mod/data/comment_form.php b/mod/data/comment_form.php new file mode 100644 index 0000000000..b6a5754e43 --- /dev/null +++ b/mod/data/comment_form.php @@ -0,0 +1,39 @@ +libdir.'/formslib.php'; + +class data_comment_form extends moodleform { + function definition() { + $mform =& $this->_form; + + // visible elements + $mform->addElement('htmleditor', 'content', get_string('comment', 'data'), array('cols'=>85, 'rows'=>18)); + $mform->addRule('content', get_string('required'), 'required', null, 'client'); + $mform->setType('content', PARAM_RAW); // cleaned before the display + + $mform->addElement('format', 'format', get_string('format')); + $mform->setHelpButton('format', array('textformat', get_string('helpformatting'))); + + // hidden optional params + $mform->addElement('hidden', 'mode', 'add'); + $mform->setType('mode', PARAM_ALPHA); + + $mform->addElement('hidden', 'page', 0); + $mform->setType('page', PARAM_INT); + + $mform->addElement('hidden', 'rid', 0); + $mform->setType('rid', PARAM_INT); + + $mform->addElement('hidden', 'commentid', 0); + $mform->setType('commentid', PARAM_INT); + + // buttons + $buttonarray = array(); + $buttonarray[] =& $mform->createElement('submit', 'submitbutton', get_string('savechanges')); + $buttonarray[] =& $mform->createElement('reset', 'reset', get_string('revert')); + $buttonarray[] =& $mform->createElement('cancel'); + + $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false); + } +} +?> \ No newline at end of file diff --git a/mod/data/db/install.xml b/mod/data/db/install.xml index ba49e9f8db..d71f92eafd 100644 --- a/mod/data/db/install.xml +++ b/mod/data/db/install.xml @@ -99,8 +99,9 @@ - - + + + diff --git a/mod/data/db/upgrade.php b/mod/data/db/upgrade.php index 954fbdd281..94c9754c9f 100644 --- a/mod/data/db/upgrade.php +++ b/mod/data/db/upgrade.php @@ -32,6 +32,18 @@ function xmldb_data_upgrade($oldversion=0) { /// $result = result of "/lib/ddllib.php" function calls /// } + if ($result && $oldversion < 2006121300) { + + /// Define field format to be added to data_comments + $table = new XMLDBTable('data_comments'); + $field = new XMLDBField('format'); + $field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'content'); + + /// Launch add field format + $result = $result && add_field($table, $field); + + } + return $result; } diff --git a/mod/data/lib.php b/mod/data/lib.php index 105d601960..4658352f93 100755 --- a/mod/data/lib.php +++ b/mod/data/lib.php @@ -890,6 +890,7 @@ function data_print_template($template, $records, $data, $search='',$page=0, $re * Printing Ratings Form * *********************************/ if (($template == 'singletemplate') && ($data->comments)) { //prints ratings options + data_print_comments($data, $record, $page); } @@ -1081,7 +1082,7 @@ function data_get_ratings($recordid, $sort="u.firstname ASC") { //prints all comments + a text box for adding additional comment -function data_print_comments($data, $record, $page=0) { +function data_print_comments($data, $record, $page=0, $mform=false) { global $CFG; @@ -1091,18 +1092,28 @@ function data_print_comments($data, $record, $page=0) { foreach ($comments as $comment) { data_print_comment($data, $comment, $page); } + echo '
'; + } + + if (!isloggedin() or isguest()) { + return; } - if (isloggedin() and !isguest()) { - echo '
'; - echo ''; - echo ''; - echo ''; - echo ''; + $editor = optional_param('addcomment', 0, PARAM_BOOL); - echo ''; - echo '
'; - echo '
'; + if (!$mform and !$editor) { + echo ''; + } else { + if (!$mform) { + require_once('comment_form.php'); + $mform = new data_comment_form('comment.php'); + $mform->set_defaults(array('mode'=>'add', 'page'=>$page, 'rid'=>$record->id)); + } + echo '
'; + $mform->display(); + echo '
'; } } @@ -1146,8 +1157,7 @@ function data_print_comment($data, $comment, $page=0) { echo ''."\n"; // Print whole message - $options->para = false; - echo format_text($comment->content, FORMAT_MOODLE, $options); + echo format_text($comment->content, $comment->format); /// Commands diff --git a/mod/data/tabs.php b/mod/data/tabs.php index f17d53a8df..037abeabb4 100755 --- a/mod/data/tabs.php +++ b/mod/data/tabs.php @@ -37,7 +37,7 @@ $row[] = new tabobject('list', $CFG->wwwroot.'/mod/data/view.php?d='.$data->id, get_string('list','data'), '', true); if (isset($record)) { - $row[] = new tabobject('single', $CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&rid='.$record->id, get_string('single','data'), '', true); + $row[] = new tabobject('single', $CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&rid='.$record->id, get_string('single','data'), '', true); } else { $row[] = new tabobject('single', $CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&mode=single', get_string('single','data'), '', true); } diff --git a/mod/data/templates.php b/mod/data/templates.php index 37bccb3b6c..3b9fe44a86 100755 --- a/mod/data/templates.php +++ b/mod/data/templates.php @@ -224,7 +224,7 @@ echo ''; echo ''; if ($mode != 'singletemplate') { - // more points to single template - not useable there + // more points to single template - not useable there echo ''; echo ''; echo ''; diff --git a/mod/data/version.php b/mod/data/version.php index d4eb8b2d41..626454a94c 100644 --- a/mod/data/version.php +++ b/mod/data/version.php @@ -5,8 +5,8 @@ // This fragment is called by /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2006100201; -$module->requires = 2006080900; // Requires this Moodle version +$module->version = 2006121300; +$module->requires = 2006120700; // Requires this Moodle version $module->cron = 60; ?>