]> git.mjollnir.org Git - moodle.git/commitdiff
following on from last commit to post.php removing redundant post.html and adding...
authorjamiesensei <jamiesensei>
Tue, 7 Nov 2006 09:08:08 +0000 (09:08 +0000)
committerjamiesensei <jamiesensei>
Tue, 7 Nov 2006 09:08:08 +0000 (09:08 +0000)
mod/forum/post.html [deleted file]
mod/forum/post_form.php [new file with mode: 0644]

diff --git a/mod/forum/post.html b/mod/forum/post.html
deleted file mode 100644 (file)
index 8a5e687..0000000
+++ /dev/null
@@ -1,183 +0,0 @@
-<?php
-
-
-if (!isset($coursecontext)) {
-    // Has not yet been set by post.php.
-    $coursecontext = get_context_instance(CONTEXT_COURSE, $forum->course);
-}
-
-
-if (!isset($discussion->timestart)) {
-    $discussion->timestart = 0;
-}
-if (!isset($discussion->timeend)) {
-    $discussion->timeend = 0;
-}
-
-trusttext_prepare_edit($post->message, $post->format, $usehtmleditor, $modcontext);
-
-?>
-<form name="theform" method="post" action="post.php" enctype="multipart/form-data">
-<table border="0" cellpadding="5">
-<tr valign="top">
-    <td align="right"><b><?php print_string("subject", "forum"); ?>:</b></td>
-    <td>
-        <input type="text" name="subject" size="60" value="<?php p($post->subject) ?>" alt="<?php print_string("subject", "forum"); ?>" />
-    </td>
-</tr>
-<tr valign="top">
-    <td align="right"><b><?php print_string("message", "forum"); ?>:</b>
-    <br /><br />
-      <?php
-        helpbutton("reading", get_string("helpreading"), "moodle", true, true);
-        echo "<br />";
-        helpbutton("writing", get_string("helpwriting"), "moodle", true, true);
-        echo "<br />";
-        helpbutton("questions", get_string("helpquestions"), "moodle", true, true);
-        echo "<br />";
-        if ($usehtmleditor) {
-           helpbutton("richtext", get_string("helprichtext"), "moodle", true, true);
-        } else {
-           emoticonhelpbutton("theform", "message");
-        } 
-        echo "<br />";
-      ?>
-    </td>
-    <td align="left">
-    <?php print_textarea($usehtmleditor, 25, 65, 630, 400, "message", $post->message); ?>
-    </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", $post->format, "");
-        }
-        helpbutton("textformat", get_string("helpformatting"));
-     ?>
-    </td>
-</tr>
-
-
-<tr valign="top">
-    <td align="right"><b><?php print_string("subscription", "forum") ?>:</b></td>
-    <td>
-    <?php 
-       if (forum_is_forcesubscribed($forum->id)) {
-           print_string("everyoneissubscribed", "forum");
-       } else if ($forum->forcesubscribe != FORUM_DISALLOWSUBSCRIBE ||
-                    has_capability('moodle/course:manageactivities', $coursecontext)){
-           unset($options);
-           if (forum_is_subscribed($USER->id, $post->forum)) {
-               $options[0] = get_string("subscribestart", "forum");
-               $options[1] = get_string("subscribestop", "forum");
-               choose_from_menu($options, "unsubscribe", 0, "");
-           } else {
-               $default = 0;
-               if (!empty($USER->autosubscribe)) {
-                   $default = 1;
-               }
-               $options[0] = get_string("subscribestop", "forum");
-               $options[1] = get_string("subscribestart", "forum");
-               choose_from_menu($options, "subscribe", $default, "");
-           }
-       } else if ($forum->forcesubscribe == FORUM_DISALLOWSUBSCRIBE) {
-           print_string('disallowsubscribe','forum');
-       }
-       helpbutton("subscription", get_string("subscription", "forum"), "forum"); 
-    ?>
-    </td>
-</tr>
-
-
-<?php if ($forum->maxbytes != 1 && has_capability('mod/forum:createattachment', $modcontext))  {  //  1 = No attachments at all
-?>
-
-<tr valign="top">
-    <td align="right"><b><?php print_string("attachment", "forum") ?>:<br />(<?php print_string("optional") ?>)&nbsp;</b></td>
-    <td>
-    <?php $maxbytes = get_max_upload_file_size($CFG->maxbytes, $course->maxbytes, $forum->maxbytes); ?>
-    <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $maxbytes ?>" />
-    <input type="file" name="attachment" size="40" alt="<?php print_string("attachment", "forum") ?>" />
-    <?php
-    helpbutton("attachment", get_string("attachment", "forum"), "forum");
-    echo '&nbsp;';
-    print_string("maxsize", "", display_size($maxbytes)); 
-    ?>
-    </td>
-</tr>
-
-<?php } ?>
-
-
-<?php
-    if (has_capability('moodle/course:manageactivities', $coursecontext)
-            && empty($post->id)) {
-?>
-
-<tr valign="top">
-    <td align="right"><b><?php print_string("mailnow", "forum") ?>:</b></td>
-    <td><?php print_checkbox('mailnow', '1', !empty($post->mailnow)); ?>
-    </td>
-</tr>
-
-<?php } ?>
-
-
-<?php if (!empty($CFG->forum_enabletimedposts) && !$post->parent) {
-   // This is the first post of a discussion, and  timed posts are enabled.
- ?>
-<tr valign="top">
-    <td align="right"><b><?php print_string("displayperiod", "forum") ?>:<br />(<?php print_string("optional") ?>)&nbsp;</b></td>
-    <td>
-        <table cellpadding="0" cellspacing="0">
-            <tr>
-                <td align="right"><?php print_string('displaystart', "forum") ?>: </td>
-                <td><?php
-                    print_date_selector("timestartday", "timestartmonth", "timestartyear", $discussion->timestart);
-                    print_string('disable');
-                    echo ': ';
-                    print_checkbox('timestartdisabled', 1, empty($discussion->timestart));
-                    helpbutton("displayperiod", get_string("displayperiod", "forum"), "forum");
-                    ?></td>
-            </tr>
-            <tr>
-                <td height="18" colspan="2"> </td>
-            </tr>
-            <tr>
-                <td align="right"><?php print_string('displayend', "forum") ?>: </td>
-                <td><?php
-                    print_date_selector("timeendday", "timeendmonth", "timeendyear", $discussion->timeend);
-                    print_string('disable');
-                    echo ': ';
-                    print_checkbox('timeenddisabled', 1, empty($discussion->timeend));
-                    ?></td>
-            </tr>
-        </table>
-    </td>
-</tr>
-
-<?php } else { ?>
-<input type="hidden" name="timestartdisabled" value="1" />
-<input type="hidden" name="timeenddisabled" value="1" />
-<?php } ?>
-<tr>
-    <td align="center" colspan="2">
-    <input type="hidden" name="course"     value="<?php p($post->course) ?>" />
-    <input type="hidden" name="forum"      value="<?php p($post->forum) ?>" />
-    <input type="hidden" name="discussion" value="<?php p($post->discussion) ?>" />
-    <input type="hidden" name="parent"     value="<?php p($post->parent) ?>" />
-    <input type="hidden" name="userid"     value="<?php p($post->userid) ?>" />
-    <input type="hidden" name="groupid"    value="<?php p($post->groupid) ?>" />
-    <input type="hidden" name="edit"       value="<?php p($post->edit) ?>" />
-    <input type="submit" value="<?php p(($post->edit) ? get_string('savechanges') : get_string('posttoforum', 'forum')); ?>" />
-    </td>
-
-</tr>
-</table>
-</form>
diff --git a/mod/forum/post_form.php b/mod/forum/post_form.php
new file mode 100644 (file)
index 0000000..65f4efa
--- /dev/null
@@ -0,0 +1,122 @@
+<?php
+require_once ($CFG->libdir.'/formslib.php');
+class forum_post_form extends moodleform {
+
+       function definition() {
+
+               global $CFG;
+               $mform    =& $this->_form;
+               $renderer =& $mform->defaultRenderer();
+
+               extract($this->_customdata);
+
+
+        $mform->addElement('header', 'general', '');//fill in the data depending on page params
+                                                //later using set_defaults
+               $mform->addElement('text', 'subject', get_string("subject", "forum"), 'size="60"');
+               $mform->setType('subject', PARAM_TEXT);
+               $mform->addRule('subject', get_string('required'), 'required', null, 'client');
+
+               $mform->addElement('htmleditor', 'message', get_string("message", "forum"));
+               $mform->setType('message', PARAM_RAW);
+               $mform->addRule('message', get_string('required'), 'required', null, 'client');
+
+        $mform->addElement('format', 'format', get_string('format'));
+        $mform->setHelpButton('format', array("textformat", get_string("helpformatting")));
+
+
+               if (isset($forum->id)&& forum_is_forcesubscribed($forum->id)) {
+
+                       $mform->addElement('static', 'subscribemessage', get_string("subscription", "forum"), get_string("everyoneissubscribed", "forum"));
+            $mform->addElement('hidden', 'subscribe');
+            $mform->setHelpButton('subscribemessage', array("subscription", get_string("subscription", "forum"), "forum"));
+
+               } else if (isset($forum->forcesubscribe)&& $forum->forcesubscribe != FORUM_DISALLOWSUBSCRIBE ||
+                             has_capability('moodle/course:manageactivities', $coursecontext)){
+                       unset($options);
+                       $options[0] = get_string("subscribestop", "forum");
+                       $options[1] = get_string("subscribestart", "forum");
+
+                       $mform->addElement('select', 'subscribe', get_string("subscription", "forum"), $options);
+            $mform->setHelpButton('subscribe', array("subscription", get_string("subscription", "forum"), "forum"));
+               } else if ($forum->forcesubscribe == FORUM_DISALLOWSUBSCRIBE) {
+                       $mform->addElement('static', 'subscribemessage', get_string("subscription", "forum"), get_string('disallowsubscribe', 'forum'));
+            $mform->addElement('hidden', 'subscribe');
+            $mform->setHelpButton('subscribemessage', array("subscription", get_string("subscription", "forum"), "forum"));
+               }
+
+               if (empty($post->id)
+                     && has_capability('moodle/course:manageactivities', $coursecontext)) {
+            $mform->addElement('checkbox', 'mailnow', get_string("mailnow", "forum"));
+               }
+
+               if (!isset($discussion->timestart)) {
+                       $discussion->timestart = 0;
+               }
+               if (!isset($discussion->timeend)) {
+                       $discussion->timeend = 0;
+               }
+               if (!empty($CFG->forum_enabletimedposts) && !$post->parent) {
+            $mform->addElement('header','', get_string("displayperiod", "forum"));
+                   $timestartgroup=array();
+                   $timestartgroup[]=&MoodleQuickForm::createElement('date_selector', 'timestart', get_string('timestartday', 'forum'));
+                   $timestartgroup[]=&MoodleQuickForm::createElement('checkbox', 'timestartdisabled', '', get_string('disable'));
+            $mform->addGroup($timestartgroup, 'timestartgroup', get_string('displaystart', 'forum'), '&nbsp;', false);
+                       $mform->setHelpButton('timestartgroup', array("displayperiod", get_string("displayperiod", "forum"), "forum"));
+                       $timeendgroup=array();
+                   $timeendgroup[]=&MoodleQuickForm::createElement('date_selector', 'timeend', get_string('timeendday', 'forum'));
+                       $timeendgroup[]=&MoodleQuickForm::createElement('checkbox', 'timeenddisabled', '', get_string('disable'));
+            $mform->addGroup($timeendgroup, 'timeendgroup', get_string('displayend', 'forum'), '&nbsp;', false);
+                       $mform->setHelpButton('timeendgroup', array("displayperiod", get_string("displayperiod", "forum"), "forum"));
+               } else {
+                       $mform->addElement('hidden', 'timestartdisabled', '1');
+                       $mform->setType('timestartdisabled', PARAM_INT);
+                       $mform->addElement('hidden', 'timeenddisabled', '1');
+                       $mform->setType('timeenddisabled', PARAM_INT);
+
+               }
+               if(isset($post->edit)){
+                       $submit_string=get_string('savechanges');
+               }else{
+                       $submit_string=get_string('posttoforum', 'forum');
+               }
+               $mform->addElement('submit', 'submit', $submit_string);
+               $renderer->addStopFieldsetElements('submit');
+
+               $mform->addElement('hidden', 'course');
+               $mform->setType('course', PARAM_INT);
+
+               $mform->addElement('hidden', 'forum');
+               $mform->setType('forum', PARAM_INT);
+
+               $mform->addElement('hidden', 'discussion');
+               $mform->setType('discussion', PARAM_INT);
+
+               $mform->addElement('hidden', 'parent');
+               $mform->setType('parent', PARAM_INT);
+
+               $mform->addElement('hidden', 'userid');
+               $mform->setType('userid', PARAM_INT);
+
+               $mform->addElement('hidden', 'groupid');
+               $mform->setType('groupid', PARAM_INT);
+
+               $mform->addElement('hidden', 'edit');
+               $mform->setType('edit', PARAM_INT);
+
+               $mform->addElement('hidden', 'reply');
+               $mform->setType('reply', PARAM_INT);
+
+       }
+
+       function validation($data){
+           $error=array();
+        if (empty($data['timeenddisabled']) && empty($data['timestartdisabled'])
+                     && $data['timeend'] <= $data['timestart']) {
+             $error['timeendgroup'] = get_string('timestartenderror', 'forum');
+        }
+        return (count($error)==0)?true:$error;
+       }
+
+}
+?>