Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
namespace mod_questionnaire;
18
 
19
defined('MOODLE_INTERNAL') || die();
20
 
21
require_once($CFG->libdir . '/formslib.php');
22
 
23
/**
24
 * The questionnaire settings form.
25
 * @package mod_questionnaire
26
 * @copyright  2016 Mike Churchward (mike.churchward@poetgroup.org)
27
 * @author     Mike Churchward
28
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 */
30
class settings_form extends \moodleform {
31
 
32
    /**
33
     * Defines the form.
34
     */
35
    public function definition() {
36
        global $questionnaire, $questionnairerealms;
37
 
38
        $mform    =& $this->_form;
39
 
40
        $mform->addElement('header', 'contenthdr', get_string('contentoptions', 'questionnaire'));
41
 
42
        $capabilities = questionnaire_load_capabilities($questionnaire->cm->id);
43
        if (!$capabilities->createtemplates) {
44
            unset($questionnairerealms['template']);
45
        }
46
        if (!$capabilities->createpublic) {
47
            unset($questionnairerealms['public']);
48
        }
49
        if (isset($questionnairerealms['public']) || isset($questionnairerealms['template'])) {
50
            $mform->addElement('select', 'realm', get_string('realm', 'questionnaire'), $questionnairerealms);
51
            $mform->setDefault('realm', $questionnaire->survey->realm);
52
            $mform->addHelpButton('realm', 'realm', 'questionnaire');
53
        } else {
54
            $mform->addElement('hidden', 'realm', 'private');
55
        }
56
        $mform->setType('realm', PARAM_RAW);
57
 
58
        $mform->addElement('text', 'title', get_string('title', 'questionnaire'), array('size' => '60'));
59
        $mform->setDefault('title', $questionnaire->survey->title);
60
        $mform->setType('title', PARAM_TEXT);
61
        $mform->addRule('title', null, 'required', null, 'client');
62
        $mform->addHelpButton('title', 'title', 'questionnaire');
63
 
64
        $mform->addElement('text', 'subtitle', get_string('subtitle', 'questionnaire'), array('size' => '60'));
65
        $mform->setDefault('subtitle', $questionnaire->survey->subtitle);
66
        $mform->setType('subtitle', PARAM_TEXT);
67
        $mform->addHelpButton('subtitle', 'subtitle', 'questionnaire');
68
 
69
        $editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'trusttext' => true);
70
        $mform->addElement('editor', 'info', get_string('additionalinfo', 'questionnaire'), null, $editoroptions);
71
        $mform->setDefault('info', $questionnaire->survey->info);
72
        $mform->setType('info', PARAM_RAW);
73
        $mform->addHelpButton('info', 'additionalinfo', 'questionnaire');
74
 
75
        $mform->addElement('header', 'submithdr', get_string('submitoptions', 'questionnaire'));
76
 
77
        $mform->addElement('text', 'thanks_page', get_string('url', 'questionnaire'), array('size' => '60'));
78
        $mform->setType('thanks_page', PARAM_TEXT);
79
        $mform->setDefault('thanks_page', $questionnaire->survey->thanks_page);
80
        $mform->addHelpButton('thanks_page', 'url', 'questionnaire');
81
 
82
        $mform->addElement('static', 'confmes', get_string('confalts', 'questionnaire'));
83
        $mform->addHelpButton('confmes', 'confpage', 'questionnaire');
84
 
85
        $mform->addElement('text', 'thank_head', get_string('headingtext', 'questionnaire'), array('size' => '30'));
86
        $mform->setType('thank_head', PARAM_TEXT);
87
        $mform->setDefault('thank_head', $questionnaire->survey->thank_head);
88
 
89
        $editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'trusttext' => true);
90
        $mform->addElement('editor', 'thank_body', get_string('bodytext', 'questionnaire'), null, $editoroptions);
91
        $mform->setType('thank_body', PARAM_RAW);
92
        $mform->setDefault('thank_body', $questionnaire->survey->thank_body);
93
 
94
        $allowemailreporting = get_config('questionnaire', 'allowemailreporting');
95
        if (!$allowemailreporting) {
96
            $attributes = ['size' => '75', 'disabled' => 'disabled'];
97
        } else {
98
            $attributes = ['size' => '75'];
99
        }
100
        $mform->addElement('text', 'email', get_string('email', 'questionnaire'), $attributes);
101
        $mform->setType('email', PARAM_TEXT);
102
        $mform->setDefault('email', $questionnaire->survey->email);
103
        $mform->addHelpButton('email', 'sendemail', 'questionnaire');
104
 
105
        // Hidden fields.
106
        $mform->addElement('hidden', 'id', 0);
107
        $mform->setType('id', PARAM_INT);
108
        $mform->addElement('hidden', 'sid', 0);
109
        $mform->setType('sid', PARAM_INT);
110
        $mform->addElement('hidden', 'name', '');
111
        $mform->setType('name', PARAM_TEXT);
112
        $mform->addElement('hidden', 'courseid', '');
113
        $mform->setType('courseid', PARAM_RAW);
114
 
115
        // Buttons.
116
 
117
        $submitlabel = get_string('savechangesanddisplay');
118
        $submit2label = get_string('savechangesandreturntocourse');
119
        $mform = $this->_form;
120
 
121
        // Elements in a row need a group.
122
        $buttonarray = array();
123
        $buttonarray[] = &$mform->createElement('submit', 'submitbutton2', $submit2label);
124
        $buttonarray[] = &$mform->createElement('submit', 'submitbutton', $submitlabel);
125
        $buttonarray[] = &$mform->createElement('cancel');
126
 
127
        $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
128
        $mform->setType('buttonar', PARAM_RAW);
129
        $mform->closeHeaderBefore('buttonar');
130
 
131
    }
132
 
133
    /**
134
     * Validation rules for form.
135
     * @param array $data array of ("fieldname"=>value) of submitted data
136
     * @param array $files array of uploaded files "element_name"=>tmp_file_path
137
     * @return array of "element_name"=>"error_description" if there are errors,
138
     *         or an empty array if everything is OK (true allowed for backwards compatibility too).
139
     */
140
    public function validation($data, $files) {
141
        $errors = parent::validation($data, $files);
142
        return $errors;
143
    }
144
}