From 6117edc7c1513dde957f8565ec7db3c466eb7e5c Mon Sep 17 00:00:00 2001 From: skodak Date: Wed, 29 Nov 2006 21:28:38 +0000 Subject: [PATCH] fix submission and notes edit to use new forms lib MDL-7740 --- .../type/online/assignment.class.php | 6 +- .../type/upload/assignment.class.php | 61 +++++++++++-------- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/mod/assignment/type/online/assignment.class.php b/mod/assignment/type/online/assignment.class.php index b68e9e71f5..205270d000 100644 --- a/mod/assignment/type/online/assignment.class.php +++ b/mod/assignment/type/online/assignment.class.php @@ -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); diff --git a/mod/assignment/type/upload/assignment.class.php b/mod/assignment/type/upload/assignment.class.php index 1e8670d450..4c5aef22a8 100644 --- a/mod/assignment/type/upload/assignment.class.php +++ b/mod/assignment/type/upload/assignment.class.php @@ -1,4 +1,5 @@ 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 '
'; - echo ''; - echo ''; - echo ''; - echo '
'; - helpbutton('reading', get_string('helpreading'), 'moodle', true, true); - echo '
'; - helpbutton('writing', get_string('helpwriting'), 'moodle', true, true); - echo '
'; - echo '
'; - print_textarea(can_use_html_editor(), 20, 60, 630, 400, 'text', $defaulttext); - echo '
'; - echo ''; - echo ''; - echo ''; - echo ''; - echo '
'; - echo '
'; - - 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); + } } ?> -- 2.39.5