MDL-18910 moving modedit features to modname_supports()
[moodle.git] / mod / feedback / mod_form.php
CommitLineData
c70ad9f7 1<?php // $Id$
2/**
3* print the form to add or edit a feedback-instance
4*
5* @version $Id$
6* @author Andreas Grabs
7* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8* @package feedback
9*/
10
11require_once ($CFG->dirroot.'/course/moodleform_mod.php');
12
13class mod_feedback_mod_form extends moodleform_mod {
14
15 function definition() {
c18269c7 16 global $CFG, $DB;
c70ad9f7 17
18 $mform =& $this->_form;
19
20 //-------------------------------------------------------------------------------
21 $mform->addElement('header', 'general', get_string('general', 'form'));
22
23 $mform->addElement('text', 'name', get_string('name', 'feedback'), array('size'=>'64'));
24 $mform->setType('name', PARAM_TEXT);
25 $mform->addRule('name', null, 'required', null, 'client');
26
63b02567 27 $mform->addElement('htmleditor', 'intro', get_string("description", "feedback"), array('rows' => 20));
28 $mform->setType('intro', PARAM_RAW);
29 $mform->addRule('intro', null, 'required', null, 'client');
c70ad9f7 30
31 //-------------------------------------------------------------------------------
32 $mform->addElement('header', 'timinghdr', get_string('timing', 'form'));
33
34 $enableopengroup = array();
35 $enableopengroup[] =& $mform->createElement('checkbox', 'openenable', get_string('feedbackopen', 'feedback'));
36 $enableopengroup[] =& $mform->createElement('date_time_selector', 'timeopen', '');
37 $mform->addGroup($enableopengroup, 'enableopengroup', get_string('feedbackopen', 'feedback'), ' ', false);
38 $mform->setHelpButton('enableopengroup', array('timeopen', get_string('feedbackopens', 'feedback'), 'feedback'));
39 $mform->disabledIf('enableopengroup', 'openenable', 'notchecked');
40
41 $enableclosegroup = array();
42 $enableclosegroup[] =& $mform->createElement('checkbox', 'closeenable', get_string('feedbackclose', 'feedback'));
43 $enableclosegroup[] =& $mform->createElement('date_time_selector', 'timeclose', '');
44 $mform->addGroup($enableclosegroup, 'enableclosegroup', get_string('feedbackclose', 'feedback'), ' ', false);
45 $mform->setHelpButton('enableclosegroup', array('timeclose', get_string('feedbackcloses', 'feedback'), 'feedback'));
46 $mform->disabledIf('enableclosegroup', 'closeenable', 'notchecked');
47
48 //-------------------------------------------------------------------------------
49 $mform->addElement('header', 'feedbackhdr', get_string('feedback_options', 'feedback'));
50
51 $options=array();
52 $options[1] = get_string('anonymous', 'feedback');
53 $options[2] = get_string('non_anonymous', 'feedback');
54 $mform->addElement('select', 'anonymous', get_string('anonymous_edit', 'feedback'), $options);
55
7ac32c70 56 $mform->addElement('selectyesno', 'publish_stats', get_string('show_analysepage_after_submit', 'feedback'));
c70ad9f7 57 $mform->addElement('selectyesno', 'email_notification', get_string('email_notification', 'feedback'));
58 $mform->setHelpButton('email_notification', array('emailnotification', get_string('email_notification', 'feedback'), 'feedback'));
59
60 // check if there is existing responses to this feedback
c18269c7 61 if (is_numeric($this->_instance) AND $this->_instance and $feedback = $DB->get_record("feedback", array("id"=>$this->_instance))) {
c70ad9f7 62 $completedFeedbackCount = feedback_get_completeds_group_count($feedback);
63 } else {
64 $completedFeedbackCount = false;
65 }
66
67 if($completedFeedbackCount) {
68 $multiple_submit_value = $feedback->multiple_submit ? get_string('yes') : get_string('no');
69 $mform->addElement('text', 'multiple_submit_static', get_string('multiple_submit', 'feedback'), array('size'=>'4','disabled'=>'disabled', 'value'=>$multiple_submit_value));
70 $mform->addElement('hidden', 'multiple_submit', '');
efc59167 71 $mform->setHelpButton('multiple_submit_static', array('multiplesubmit', get_string('multiple_submit', 'feedback'), 'feedback'));
c70ad9f7 72 }else {
73 $mform->addElement('selectyesno', 'multiple_submit', get_string('multiple_submit', 'feedback'));
efc59167 74 $mform->setHelpButton('multiple_submit', array('multiplesubmit', get_string('multiple_submit', 'feedback'), 'feedback'));
c70ad9f7 75 }
efc59167 76 $mform->addElement('selectyesno', 'autonumbering', get_string('autonumbering', 'feedback'));
77 $mform->setHelpButton('autonumbering', array('autonumbering', get_string('autonumbering', 'feedback'), 'feedback'));
c70ad9f7 78
79 //-------------------------------------------------------------------------------
80 $mform->addElement('header', 'aftersubmithdr', get_string('after_submit', 'feedback'));
81
c184660d 82 $mform->addElement('text', 'site_after_submit', get_string('site_after_submit', 'feedback'), array('size'=>'64','maxlength'=>'255'));
83 $mform->setType('site_after_submit', PARAM_TEXT);
84
c70ad9f7 85 $mform->addElement('htmleditor', 'page_after_submit', get_string("page_after_submit", "feedback"), array('rows' => 20));
86 $mform->setType('page_after_submit', PARAM_RAW);
c70ad9f7 87 //-------------------------------------------------------------------------------
42f103be 88 $this->standard_coursemodule_elements();
c70ad9f7 89 //-------------------------------------------------------------------------------
90 // buttons
91 $this->add_action_buttons();
92 }
93
94 function data_preprocessing(&$default_values){
95 if (empty($default_values['timeopen'])) {
96 $default_values['openenable'] = 0;
97 } else {
98 $default_values['openenable'] = 1;
99 }
100 if (empty($default_values['timeclose'])) {
101 $default_values['closeenable'] = 0;
102 } else {
103 $default_values['closeenable'] = 1;
104 }
105
106 }
107
32648682 108 function validation($data, $files){
109 $errors = parent::validation($data, $files);
110 return $errors;
c70ad9f7 111 }
112
113}
114?>