2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * prints the forms to choose an item-typ to create items and to choose a template to use
20 * @author Andreas Grabs
21 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
22 * @package mod_feedback
25 //It must be included from a Moodle page
26 if (!defined('MOODLE_INTERNAL')) {
27 die('Direct access to this script is forbidden.');
30 require_once($CFG->libdir
.'/formslib.php');
32 class feedback_edit_use_template_form
extends moodleform
{
37 public function definition() {
38 $mform =& $this->_form
;
40 $course = $this->_customdata
['course'];
42 $elementgroup = array();
44 $mform->addElement('header', 'using_templates', get_string('using_templates', 'feedback'));
46 $mform->addElement('hidden', 'id');
47 $mform->setType('id', PARAM_INT
);
50 $templates_options = array();
51 $owntemplates = feedback_get_template_list($course, 'own');
52 $publictemplates = feedback_get_template_list($course, 'public');
55 if ($owntemplates or $publictemplates) {
56 $options[''] = array('' => get_string('choosedots'));
59 $courseoptions = array();
60 foreach ($owntemplates as $template) {
61 $courseoptions[$template->id
] = format_string($template->name
);
63 $options[get_string('course')] = $courseoptions;
66 if ($publictemplates) {
67 $publicoptions = array();
68 foreach ($publictemplates as $template) {
69 $publicoptions[$template->id
] = format_string($template->name
);
71 $options[get_string('public', 'feedback')] = $publicoptions;
74 $attributes = 'onChange="M.core_formchangechecker.set_form_submitted(); this.form.submit()"';
75 $elementgroup[] = $mform->createElement('selectgroups',
77 get_string('using_templates', 'feedback'),
81 $elementgroup[] = $mform->createElement('submit',
83 get_string('use_this_template', 'feedback'),
84 array('class' => 'hiddenifjs'));
86 $mform->addGroup($elementgroup, 'elementgroup', '', array(' '), false);
88 $mform->addElement('static', 'info', get_string('no_templates_available_yet', 'feedback'));
91 $this->set_data(array('id' => $this->_customdata
['id']));
95 class feedback_edit_create_template_form
extends moodleform
{
100 public function definition() {
101 $mform =& $this->_form
;
104 $mform->addElement('hidden', 'id');
105 $mform->setType('id', PARAM_INT
);
106 $mform->addElement('hidden', 'do_show');
107 $mform->setType('do_show', PARAM_ALPHANUMEXT
);
108 $mform->setConstant('do_show', 'templates');
111 $mform->addElement('header', 'creating_templates', get_string('creating_templates', 'feedback'));
114 $elementgroup = array();
116 $elementgroup[] = $mform->createElement('text',
118 get_string('name', 'feedback'),
119 array('size'=>'40', 'maxlength'=>'200'));
121 if (has_capability('mod/feedback:createpublictemplate', context_system
::instance())) {
122 $elementgroup[] = $mform->createElement('checkbox',
124 get_string('public', 'feedback'));
128 $mform->addGroup($elementgroup,
130 get_string('name', 'feedback'),
135 $mform->addElement('submit', 'create_template', get_string('save_as_new_template', 'feedback'));
137 $mform->setType('templatename', PARAM_TEXT
);
139 $this->set_data(array('id' => $this->_customdata
['id']));
145 * @param array $data array of ("fieldname"=>value) of submitted data
146 * @param array $files array of uploaded files "element_name"=>tmp_file_path
147 * @return array of "element_name"=>"error_description" if there are errors,
148 * or an empty array if everything is OK (true allowed for backwards compatibility too).
150 public function validation($data, $files) {
151 $errors = parent
::validation($data, $files);
152 if (!isset($data['templatename']) ||
trim(strval($data['templatename'])) === '') {
153 $errors['elementgroup'] = get_string('name_required', 'feedback');