migrated comment.php over to using new formslib.

This commit is contained in:
jamiesensei
2006-10-26 07:59:22 +00:00
parent 92309430b8
commit c3c5f0bd86
3 changed files with 119 additions and 142 deletions
-67
View File
@@ -1,67 +0,0 @@
<?php //$Id$
if (!isset($form->format)) {
$form->format = $defaultformat;
}
trusttext_prepare_edit($form->text, $form->format, $usehtmleditor, $context);
?>
<form name="form" method="post" action="comment.php">
<table class="generalbox">
<tr valign="top">
<td align="right"><b>
<?php echo get_string("comment","glossary") ?>:
</b></td>
<td rowspan="2">
<?php print_textarea($usehtmleditor, 25, 65, 630, 400, "text", $form->text); ?>
</td>
</tr>
<tr valign="top">
<td align="right" nowrap="nowrap">
<?php
helpbutton("writing", get_string("helpwriting"), "moodle", true, true);
echo "<br />";
if ($usehtmleditor) {
helpbutton("richtext", get_string("helprichtext"), "moodle", true, true);
} else {
emoticonhelpbutton("form", "text");
}
echo "<br />";
?>
</td>
</tr>
<tr valign="top">
<td align="right"><b><?php print_string("formattexttype"); ?>:</b></td>
<td>
<?php
if ($usehtmleditor) { /// Trying this out for a while
print_string('formathtml');
echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
} else {
choose_from_menu(format_text_menu(), "format", $form->format, "");
}
helpbutton("textformat", get_string("helpformatting"));
?>
</td>
</tr>
<tr>
<td colspan="2">
<center>
<?php
if (isset($comment->id)) {
echo "<input type=\"hidden\" name=\"cid\" value=\"$comment->id\" />";
}
?>
<input type="hidden" name="id" value="<?php p($cm->id) ?>" />
<input type="hidden" name="eid" value="<?php p($entry->id) ?>" />
<input type="hidden" name="action" value="<?php p($action) ?>" />
<input type="hidden" name="confirm" value="1" />
<input type="submit" value="<?php print_string("savechanges") ?>" />
<input type="reset" value="<?php print_string("revert") ?>" />
</center>
</td>
</tr>
</table>
</form>
+49 -75
View File
@@ -3,43 +3,44 @@
/// This page prints a particular instance of glossary
require_once('../../config.php');
require_once('lib.php');
include('comment_form.php');
$id = required_param('id', PARAM_INT); // Course Module ID
$eid = required_param('eid', PARAM_INT); // Entry ID
$cid = optional_param('cid', 0, PARAM_INT); // Comment ID
$confirm = optional_param('confirm',0, PARAM_INT); // Confirm the action
$action = optional_param('action','add', PARAM_ALPHA);
$action = optional_param('action','add', PARAM_ACTION);
$action = strtolower($action);
global $USER, $CFG;
if (! $cm = get_coursemodule_from_id('glossary', $id)) {
if (!$cm = get_coursemodule_from_id('glossary', $id)) {
error('Course Module ID was incorrect');
}
if (! $course = get_record('course', 'id', $cm->course)) {
if (!$course = get_record('course', 'id', $cm->course)) {
error('Course is misconfigured');
}
if (! $glossary = get_record('glossary', 'id', $cm->instance)) {
if (!$glossary = get_record('glossary', 'id', $cm->instance)) {
error('Course module is incorrect');
}
if (! $entry = get_record('glossary_entries', 'id', $eid)) {
if (!$entry = get_record('glossary_entries', 'id', $eid)) {
error('Entry is incorrect');
}
if ( $cid ) {
if (! $comment = get_record('glossary_comments', 'id', $cid)) {
if ($cid ) {
if (!$comment = get_record('glossary_comments', 'id', $cid)) {
error('Comment is incorrect');
}
}
require_login($course->id, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (isguest()) {
error('Guests are not allowed to post comments', $_SERVER['HTTP_REFERER']);
}
@@ -64,59 +65,50 @@
$strglossary = get_string('modulename', 'glossary');
$strcomments = get_string('comments', 'glossary');
print_header_simple(format_string($glossary->name), '',
"<a href=\"index.php?id=$course->id\">$strglossaries</a> -> <a href=\"view.php?id=$cm->id\">".format_string($glossary->name,true)."</a> -> <a href=\"comments.php?id=$cm->id&amp;eid=$entry->id\">$strcomments</a> -> " . $straction,
'', '', true, update_module_button($cm->id, $course->id, $strglossary),
navmenu($course, $cm));
echo '<center>';
/// Input section
/// Input section
if ( $action == 'delete' ) {
if (($comment->userid <> $USER->id) and !has_capability('mod/glossary:managecomments', $context)) {
error('You can\'t delete other people\'s comments!');
}
if (!$glossary->allowcomments && !has_capability('mod/glossary:managecomments', $context)) {
error('You can\'t delete comments in this glossary!');
}
error('You can\'t delete comments in this glossary!');
}
if ( data_submitted() and $confirm ) {
delete_records('glossary_comments','id', $cid);
print_simple_box_start('center','40%', '#FFBBBB');
echo '<center>'.get_string('commentdeleted','glossary').'</center>';
print_simple_box_end();
print_footer($course);
add_to_log($course->id, 'glossary', 'delete comment', "comments.php?id=$cm->id&amp;eid=$entry->id", "$comment->id",$cm->id);
redirect("comments.php?id=$cm->id&amp;eid=$entry->id");
} else {
print_header_simple(format_string($glossary->name), '',
"<a href=\"index.php?id=$course->id\">$strglossaries</a> -> <a href=\"view.php?id=$cm->id\">".format_string($glossary->name,true)."</a> -> <a href=\"comments.php?id=$cm->id&amp;eid=$entry->id\">$strcomments</a> -> " . $straction,
'', '', true, update_module_button($cm->id, $course->id, $strglossary),
navmenu($course, $cm));
glossary_print_comment($course, $cm, $glossary, $entry, $comment);
print_simple_box_start('center','40%', '#FFBBBB');
echo '<center><br />'.get_string('areyousuredeletecomment','glossary');
?>
<form name="form" method="post" action="comment.php">
<input type="hidden" name="id" value="<?php p($id) ?>" />
<input type="hidden" name="eid" value="<?php p($eid) ?>" />
<input type="hidden" name="cid" value="<?php p($cid) ?>" />
<input type="hidden" name="action" value="delete" />
<input type="hidden" name="confirm" value="1" />
<input type="submit" value="<?php print_string('yes')?>" />
<input type="button" value="<?php print_string('no')?>" onclick="javascript:history.go(-1);" />
?>
<form name="form" method="post" action="comment.php">
<input type="hidden" name="id" value="<?php p($id) ?>" />
<input type="hidden" name="eid" value="<?php p($eid) ?>" />
<input type="hidden" name="cid" value="<?php p($cid) ?>" />
<input type="hidden" name="action" value="delete" />
<input type="hidden" name="confirm" value="1" />
<input type="submit" value="<?php print_string('yes')?>" />
<input type="button" value="<?php print_string('no')?>" onclick="javascript:history.go(-1);" />
</form>
</center>
<?php
</form>
</center>
<?php
print_simple_box_end();
}
} else {
if (!$glossary->allowcomments && !has_capability('mod/glossary:comment', $context)) {
error('You can\'t add/edit comments to this glossary!');
}
if ( $action == 'edit' ) {
if (!isset($comment->timemodified)) {
$timetocheck = 0;
} else {
@@ -133,15 +125,17 @@
}
}
if ( $confirm and $form = data_submitted() ) {
trusttext_after_edit($form->text, $context);
$mform = new glossary_comment_form('comment.php',
compact('comment', 'cm', 'entry', 'action', 'context'));
if ($fromform = $mform->data_submitted()) {
trusttext_after_edit($fromform->comment, $context);
$newentry->entryid = $entry->id;
$newentry->entrycomment = $form->text;
$newentry->format = $form->format;
$newentry->entrycomment = $fromform->comment;
$newentry->format = $fromform->format;
$newentry->timemodified = time();
if ( $action == 'add' ) {
if ($action == 'add') {
$newentry->userid = $USER->id;
if (! $newentry->id = insert_record('glossary_comments', $newentry)) {
@@ -150,7 +144,7 @@
add_to_log($course->id, 'glossary', 'add comment', "comments.php?id=$cm->id&amp;eid=$entry->id", "$newentry->id", $cm->id);
}
} else {
$newentry->id = $form->cid;
$newentry->id = $fromform->cid;
$newentry->userid = $comment->userid;
if (! update_record('glossary_comments', $newentry)) {
@@ -159,41 +153,21 @@
add_to_log($course->id, 'glossary', 'update comment', "comments.php?id=$cm->id&amp;eid=$entry->id", "$newentry->id",$cm->id);
}
}
print_simple_box_start('center','40%', '#FFBBBB');
echo '<center>'.get_string('commentupdated','glossary').'</center>';
print_simple_box_end();
print_footer($course);
redirect("comments.php?id=$cm->id&amp;eid=$entry->id");
} else {
print_header_simple(format_string($glossary->name), '',
"<a href=\"index.php?id=$course->id\">$strglossaries</a> -> <a href=\"view.php?id=$cm->id\">".
format_string($glossary->name,true)."</a> -> <a href=\"comments.php?id=$cm->id&amp;eid=$entry->id\">$strcomments</a> -> " . $straction,
'', '', true, update_module_button($cm->id, $course->id, $strglossary), navmenu($course, $cm));
/// original glossary entry
glossary_print_entry($course, $cm, $glossary, $entry, 'approval', '', false);
echo '<br />';
// TODO add buttons
//helpbutton("writing", get_string("helpwriting"), "moodle", true, true);
if ($usehtmleditor = can_use_html_editor()) {
$defaultformat = FORMAT_HTML;
} else {
$defaultformat = FORMAT_MOODLE;
}
if (isset($comment) ) {
$form->text = $comment->entrycomment;
$form->format = $comment->format;
} else {
$form->text = '';
$form->format = $defaultformat;
}
include('comment.html');
if ($usehtmleditor) {
use_html_editor('text');
}
$mform->display();
}
}
echo '</center>';
/// Finish the page
print_footer($course);
?>
?>
+70
View File
@@ -0,0 +1,70 @@
<?php //$Id$
// TODO - THE HELP BUTTON FOR FORMATTING TO BE Included and formatting drop down box.
include_once $CFG->libdir.'/formslib.php';
class glossary_comment_form extends moodleform {
function definition() {
$mform =& $this->_form;
if(isset($this->_customdata['comment'])) {
$comment = $this->_customdata['comment'];
$commentid=$comment->id;
$commenttext = $comment->entrycomment;
$defaultformat=$comment->format;
}else{
$commentid=0;
$commenttext ='';
$defaultformat=null;
}
$entry = $this->_customdata['entry'];
$cm = $this->_customdata['cm'];
$action = $this->_customdata['action'];
$mform =& $this->_form;
//two pronged attack for trusttext
//submitted value
if (!empty($_POST)){
trusttext_prepare_edit($_POST['comment'], $_POST['format'], can_use_html_editor(),
$this->_customdata['context']);
}
$mform->addElement('htmleditor','comment',get_string("comment", "glossary"));
$mform->setType('comment', PARAM_RAW);
$mform->addElement('format', 'format', get_string("format"));
$mform->setDefault('format',$defaultformat);
//second prong : defaults
// format element works it's default out for itself
$format=$mform->exportValue('format');
trusttext_prepare_edit($commenttext, $format, can_use_html_editor(),
$this->_customdata['context']);
$mform->setDefault('format',$format);
$mform->setDefault('comment',$commenttext);
//hidden elements, in this case setType may not be needed as these
//are all processed by optional_param in comment.php but just in case
//someone later gets data from form->data_submitted() we'll add them.
$mform->addElement('hidden','cid',$comment->id);
$mform->setType('cid', PARAM_INT);
$mform->addElement('hidden','id',$cm->id);
$mform->setType('cid', PARAM_INT);
$mform->addElement('hidden','eid',$entry->id);
$mform->setType('eid', PARAM_INT);
$mform->addElement('hidden','action',$action);
$mform->setType('action', PARAM_ACTION);
$buttonarray[] = &MoodleQuickForm::createElement('submit','submit',get_string("savechanges"));
$buttonarray[] = &MoodleQuickForm::createElement('reset','reset',get_string("revert"));
$mform->addGroup($buttonarray,'buttonar','', array(" "), false);
}
}
?>