179020330cad5c8c495c300be12e438736de6288
[moodle.git] / mod / feedback / mod_form.php
1 <?php
2 /**
3 * print the form to add or edit a feedback-instance
4 *
5 * @author Andreas Grabs
6 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
7 * @package feedback
8 */
10 require_once ($CFG->dirroot.'/course/moodleform_mod.php');
12 class mod_feedback_mod_form extends moodleform_mod {
14     function definition() {
15         global $CFG, $DB;
17         $mform    =& $this->_form;
19         //-------------------------------------------------------------------------------
20         $mform->addElement('header', 'general', get_string('general', 'form'));
22         $mform->addElement('text', 'name', get_string('name', 'feedback'), array('size'=>'64'));
23         $mform->setType('name', PARAM_TEXT);
24         $mform->addRule('name', null, 'required', null, 'client');
26         $this->add_intro_editor(true, get_string('description', 'feedback'));
28         //-------------------------------------------------------------------------------
29         $mform->addElement('header', 'timinghdr', get_string('timing', 'form'));
31         $enableopengroup = array();
32         $enableopengroup[] =& $mform->createElement('checkbox', 'openenable', get_string('feedbackopen', 'feedback'));
33         $enableopengroup[] =& $mform->createElement('date_time_selector', 'timeopen', '');
34         $mform->addGroup($enableopengroup, 'enableopengroup', get_string('feedbackopen', 'feedback'), ' ', false);
35         $mform->setHelpButton('enableopengroup', array('timeopen', get_string('feedbackopens', 'feedback'), 'feedback'));
36         $mform->disabledIf('enableopengroup', 'openenable', 'notchecked');
38         $enableclosegroup = array();
39         $enableclosegroup[] =& $mform->createElement('checkbox', 'closeenable', get_string('feedbackclose', 'feedback'));
40         $enableclosegroup[] =& $mform->createElement('date_time_selector', 'timeclose', '');
41         $mform->addGroup($enableclosegroup, 'enableclosegroup', get_string('feedbackclose', 'feedback'), ' ', false);
42         $mform->setHelpButton('enableclosegroup', array('timeclose', get_string('feedbackcloses', 'feedback'), 'feedback'));
43         $mform->disabledIf('enableclosegroup', 'closeenable', 'notchecked');
45         //-------------------------------------------------------------------------------
46         $mform->addElement('header', 'feedbackhdr', get_string('feedback_options', 'feedback'));
48         $options=array();
49         $options[1]  = get_string('anonymous', 'feedback');
50         $options[2]  = get_string('non_anonymous', 'feedback');
51         $mform->addElement('select', 'anonymous', get_string('anonymous_edit', 'feedback'), $options);
53         $mform->addElement('selectyesno', 'publish_stats', get_string('show_analysepage_after_submit', 'feedback'));
54         $mform->addElement('selectyesno', 'email_notification', get_string('email_notification', 'feedback'));
55         $mform->setHelpButton('email_notification', array('emailnotification', get_string('email_notification', 'feedback'), 'feedback'));
57         // check if there is existing responses to this feedback
58         if (is_numeric($this->_instance) AND $this->_instance and $feedback = $DB->get_record("feedback", array("id"=>$this->_instance))) {
59             $completedFeedbackCount = feedback_get_completeds_group_count($feedback);
60         } else {
61             $completedFeedbackCount = false;
62         }
64         if($completedFeedbackCount) {
65             $multiple_submit_value = $feedback->multiple_submit ? get_string('yes') : get_string('no');
66             $mform->addElement('text', 'multiple_submit_static', get_string('multiple_submit', 'feedback'), array('size'=>'4','disabled'=>'disabled', 'value'=>$multiple_submit_value));
67             $mform->addElement('hidden', 'multiple_submit', '');
68             $mform->setType('', PARAM_INT);
69             $mform->setHelpButton('multiple_submit_static', array('multiplesubmit', get_string('multiple_submit', 'feedback'), 'feedback'));
70         }else {
71             $mform->addElement('selectyesno', 'multiple_submit', get_string('multiple_submit', 'feedback'));
72             $mform->setHelpButton('multiple_submit', array('multiplesubmit', get_string('multiple_submit', 'feedback'), 'feedback'));
73         }
74         $mform->addElement('selectyesno', 'autonumbering', get_string('autonumbering', 'feedback'));
75         $mform->setHelpButton('autonumbering', array('autonumbering', get_string('autonumbering', 'feedback'), 'feedback'));
77         //-------------------------------------------------------------------------------
78         $mform->addElement('header', 'aftersubmithdr', get_string('after_submit', 'feedback'));
80         $mform->addElement('editor', 'page_after_submit', get_string("page_after_submit", "feedback"), null, null);
81         $mform->setType('page_after_submit', PARAM_RAW);
83         $mform->addElement('text', 'site_after_submit', get_string('url_for_continue_button', 'feedback'), array('size'=>'64','maxlength'=>'255'));
84         $mform->setType('site_after_submit', PARAM_TEXT);
85         $mform->setHelpButton('site_after_submit', array('url_for_continue', get_string('url_for_continue_button', 'feedback'), 'feedback'));
86         //-------------------------------------------------------------------------------
87         $this->standard_coursemodule_elements();
88         //-------------------------------------------------------------------------------
89         // buttons
90         $this->add_action_buttons();
91     }
93     function data_preprocessing(&$default_values){
94         if (empty($default_values['timeopen'])) {
95             $default_values['openenable'] = 0;
96         } else {
97             $default_values['openenable'] = 1;
98         }
99         if (empty($default_values['timeclose'])) {
100             $default_values['closeenable'] = 0;
101         } else {
102             $default_values['closeenable'] = 1;
103         }
104         if (!isset($default_values['page_after_submitformat'])) {
105             $default_values['page_after_submitformat'] = FORMAT_HTML;
106         }
107         if (!isset($default_values['page_after_submit'])) {
108             $default_values['page_after_submit'] = '';
109         }
110         $default_values['page_after_submit'] = array('text'=>$default_values['page_after_submit'],'format'=>$default_values['page_after_submitformat']);
111     }
113     function get_data() {
114         $data = parent::get_data();
115         if ($data) {
116             $data->page_after_submitformat = $data->page_after_submit['format'];
117             $data->page_after_submit = $data->page_after_submit['text'];
118         }
119         return $data;
120     }
122     function validation($data, $files){
123         $errors = parent::validation($data, $files);
124         return $errors;
125     }