]> git.mjollnir.org Git - moodle.git/commitdiff
fix submission and notes edit to use new forms lib MDL-7740
authorskodak <skodak>
Wed, 29 Nov 2006 21:28:38 +0000 (21:28 +0000)
committerskodak <skodak>
Wed, 29 Nov 2006 21:28:38 +0000 (21:28 +0000)
mod/assignment/type/online/assignment.class.php
mod/assignment/type/upload/assignment.class.php

index b68e9e71f56f7a4b8e1c036bbd5a12a5500db8d8..205270d000ca806d40f7d6e5ae279b12a21a946d 100644 (file)
@@ -241,13 +241,13 @@ class assignment_online_edit_form extends moodleform {
         $mform =& $this->_form;
 
         // visible elements
-        $mform->addElement('htmleditor', 'text', get_string('submission', 'assignment'));
-        $mform->setType('text', PARAM_RAW);
+        $mform->addElement('htmleditor', 'text', get_string('submission', 'assignment'), array('cols'=>85, 'rows'=>30));
+        $mform->setType('text', PARAM_RAW); // to be cleaned before display
 
         $mform->addElement('format', 'format', get_string('format'));
         $mform->setHelpButton('format', array('textformat', get_string('helpformatting')));
 
-        // hidden optional params
+        // hidden params
         $mform->addElement('hidden', 'id', 0);
         $mform->setType('id', PARAM_INT);
 
index 1e8670d4505f01bc55067dba1d52187af8a9f0c9..4c5aef22a8c7f8c6b320f7372cf46770261cbac3 100644 (file)
@@ -1,4 +1,5 @@
 <?php // $Id$
+require_once($CFG->libdir.'/formslib.php');
 
 define('ASSIGNMENT_STATUS_SUBMITTED', 'submitted');
 
@@ -436,12 +437,19 @@ class assignment_upload extends assignment_base {
 
         $returnurl = 'view.php?id='.$this->cm->id;
 
+        $mform = new assignment_upload_notes_form('upload.php');
+
+        $defaults = new object();
+        $defaults->id = $this->cm->id;
+
         if ($submission = $this->get_submission($USER->id)) {
-            $defaulttext = $submission->data1;
+            $defaults->text = $submission->data1;
         } else {
-            $defaulttext = '';
+            $defaults->text = '';
         }
 
+        $mform->set_defaults($defaults);
+
         if (!$this->can_update_notes($submission)) {
             $this->view_header(get_string('upload'));
             notify(get_string('uploaderror', 'assignment'));
@@ -450,13 +458,12 @@ class assignment_upload extends assignment_base {
             die;
         }
 
-        if (data_submitted('nomatch') and $action == 'savenotes') {
-            $text = required_param('text', PARAM_RAW); // to be cleaned before display
+        if ($data = $mform->data_submitted() and $action == 'savenotes') {
             $submission = $this->get_submission($USER->id, true); // get or create submission
             $updated = new object();
             $updated->id           = $submission->id;
             $updated->timemodified = time();
-            $updated->data1        = $text;
+            $updated->data1        = $data->text;
 
             if (update_record('assignment_submissions', $updated)) {
                 add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id);
@@ -472,30 +479,10 @@ class assignment_upload extends assignment_base {
 
         /// show notes edit form
         $this->view_header(get_string('notes', 'assignment'));
+
         print_heading(get_string('notes', 'assignment'), 'center');
 
-        echo '<form name="theform" action="upload.php" method="post">';
-        echo '<table cellspacing="0" class="editbox" align="center">';
-        echo '<tr><td align="right">';
-        helpbutton('reading', get_string('helpreading'), 'moodle', true, true);
-        echo '<br />';
-        helpbutton('writing', get_string('helpwriting'), 'moodle', true, true);
-        echo '<br />';
-        echo '</td></tr>';
-        echo '<tr><td align="center">';
-        print_textarea(can_use_html_editor(), 20, 60, 630, 400, 'text', $defaulttext);
-        echo '</td></tr>';
-        echo '<tr><td align="center">';
-        echo '<input type="hidden" name="id" value="'.$this->cm->id.'" />';
-        echo '<input type="hidden" name="action" value="savenotes" />';
-        echo '<input type="submit" value="'.get_string('savechanges').'" />';
-        echo '<input type="reset" value="'.get_string('revert').'" />';
-        echo '</td></tr></table>';
-        echo '</form>';
-
-        if (can_use_html_editor()) {
-            use_html_editor();   // MUst be at the end of the page
-        }
+        $mform->display();
 
         $this->view_footer();
         die;
@@ -921,7 +908,27 @@ class assignment_upload extends assignment_base {
         return 0;
     }
 
+}
+
+class assignment_upload_notes_form extends moodleform {
+    function definition() {
+        $mform =& $this->_form;
+
+        // visible elements
+        $mform->addElement('htmleditor', 'text', get_string('notes', 'assignment'), array('cols'=>85, 'rows'=>30));
+        $mform->setType('text', PARAM_RAW); // to be cleaned before display
 
+        // hidden params
+        $mform->addElement('hidden', 'id', 0);
+        $mform->setType('id', PARAM_INT);
+        $mform->addElement('hidden', 'action', 'savenotes');
+        $mform->setType('id', PARAM_ALPHA);
+
+        // buttons
+        $buttonarray[] = &MoodleQuickForm::createElement('submit', 'submitbutton', get_string('savechanges'));
+        $buttonarray[] = &MoodleQuickForm::createElement('reset', 'reset', get_string('revert'));
+        $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
+    }
 }
 
 ?>