forked from mdjnelson/moodle-mod_certificate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod_form.php
186 lines (148 loc) · 9.32 KB
/
mod_form.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
// This file is part of the Certificate module for Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Instance add/edit form
*
* @package mod
* @subpackage certificate
* @copyright Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
}
require_once ($CFG->dirroot.'/course/moodleform_mod.php');
require_once($CFG->dirroot.'/mod/certificate/lib.php');
class mod_certificate_mod_form extends moodleform_mod {
function definition() {
global $CFG;
$mform =& $this->_form;
$mform->addElement('header', 'general', get_string('general', 'form'));
$mform->addElement('text', 'name', get_string('certificatename', 'certificate'), array('size'=>'64'));
if (!empty($CFG->formatstringstriptags)) {
$mform->setType('name', PARAM_TEXT);
} else {
$mform->setType('name', PARAM_CLEAN);
}
$mform->addRule('name', null, 'required', null, 'client');
$this->add_intro_editor(false, get_string('intro', 'certificate'));
// Issue options
$mform->addElement('header', 'issueoptions', get_string('issueoptions', 'certificate'));
$ynoptions = array( 0 => get_string('no'), 1 => get_string('yes'));
$mform->addElement('select', 'emailteachers', get_string('emailteachers', 'certificate'), $ynoptions);
$mform->setDefault('emailteachers', 0);
$mform->addHelpButton('emailteachers', 'emailteachers', 'certificate');
$mform->addElement('text', 'emailothers', get_string('emailothers', 'certificate'), array('size'=>'40', 'maxsize'=>'200'));
$mform->setType('emailothers', PARAM_TEXT);
$mform->addHelpButton('emailothers', 'emailothers', 'certificate');
$deliveryoptions = array( 0 => get_string('openbrowser', 'certificate'), 1 => get_string('download', 'certificate'), 2 => get_string('emailcertificate', 'certificate'));
$mform->addElement('select', 'delivery', get_string('delivery', 'certificate'), $deliveryoptions);
$mform->setDefault('delivery', 0);
$mform->addHelpButton('delivery', 'delivery', 'certificate');
$mform->addElement('select', 'savecert', get_string('savecert', 'certificate'), $ynoptions);
$mform->setDefault('savecert', 0);
$mform->addHelpButton('savecert', 'savecert', 'certificate');
$reportfile = "$CFG->dirroot/certificates/index.php";
if (file_exists($reportfile)) {
$mform->addElement('select', 'reportcert', get_string('reportcert', 'certificate'), $ynoptions);
$mform->setDefault('reportcert', 0);
$mform->addHelpButton('reportcert', 'reportcert', 'certificate');
}
$mform->addElement('text', 'requiredtime', get_string('coursetimereq', 'certificate'), array('size'=>'3'));
$mform->setType('requiredtime', PARAM_INT);
$mform->addHelpButton('requiredtime', 'coursetimereq', 'certificate');
// Text Options
$mform->addElement('header', 'textoptions', get_string('textoptions', 'certificate'));
$modules = certificate_get_mods();
$dateoptions = certificate_get_date_options() + $modules;
$mform->addElement('select', 'printdate', get_string('printdate', 'certificate'), $dateoptions);
$mform->setDefault('printdate', 'N');
$mform->addHelpButton('printdate', 'printdate', 'certificate');
$dateformatoptions = array( 1 => 'January 1, 2000', 2 => 'January 1st, 2000', 3 => '1 January 2000',
4 => 'January 2000', 5 => get_string('userdateformat', 'certificate'));
$mform->addElement('select', 'datefmt', get_string('datefmt', 'certificate'), $dateformatoptions);
$mform->setDefault('datefmt', 0);
$mform->addHelpButton('datefmt', 'datefmt', 'certificate');
$mform->addElement('select', 'printnumber', get_string('printnumber', 'certificate'), $ynoptions);
$mform->setDefault('printnumber', 0);
$mform->addHelpButton('printnumber', 'printnumber', 'certificate');
$gradeoptions = certificate_get_grade_options() + certificate_get_grade_categories($this->current->course) + $modules;
$mform->addElement('select', 'printgrade', get_string('printgrade', 'certificate'),$gradeoptions);
$mform->setDefault('printgrade', 0);
$mform->addHelpButton('printgrade', 'printgrade', 'certificate');
$gradeformatoptions = array( 1 => get_string('gradepercent', 'certificate'), 2 => get_string('gradepoints', 'certificate'),
3 => get_string('gradeletter', 'certificate'));
$mform->addElement('select', 'gradefmt', get_string('gradefmt', 'certificate'), $gradeformatoptions);
$mform->setDefault('gradefmt', 0);
$mform->addHelpButton('gradefmt', 'gradefmt', 'certificate');
$outcomeoptions = certificate_get_outcomes();
$mform->addElement('select', 'printoutcome', get_string('printoutcome', 'certificate'),$outcomeoptions);
$mform->setDefault('printoutcome', 0);
$mform->addHelpButton('printoutcome', 'printoutcome', 'certificate');
$mform->addElement('text', 'printhours', get_string('printhours', 'certificate'), array('size'=>'5', 'maxlength' => '255'));
$mform->setType('printhours', PARAM_TEXT);
$mform->addHelpButton('printhours', 'printhours', 'certificate');
$mform->addElement('select', 'printteacher', get_string('printteacher', 'certificate'), $ynoptions);
$mform->setDefault('printteacher', 0);
$mform->addHelpButton('printteacher', 'printteacher', 'certificate');
$mform->addElement('textarea', 'customtext', get_string('customtext', 'certificate'), array('cols'=>'40', 'rows'=>'4', 'wrap'=>'virtual'));
$mform->setType('customtext', PARAM_RAW);
$mform->addHelpButton('customtext', 'customtext', 'certificate');
// Design Options
$mform->addElement('header', 'designoptions', get_string('designoptions', 'certificate'));
$mform->addElement('select', 'certificatetype', get_string('certificatetype', 'certificate'), certificate_types());
$mform->setDefault('certificatetype', 'A4_non_embedded');
$mform->addHelpButton('certificatetype', 'certificatetype', 'certificate');
$orientation = array( 'L' => get_string('landscape', 'certificate'), 'P' => get_string('portrait', 'certificate'));
$mform->addElement('select', 'orientation', get_string('orientation', 'certificate'), $orientation);
$mform->setDefault('orientation', 'landscape');
$mform->addHelpButton('orientation', 'orientation', 'certificate');
$mform->addElement('select', 'borderstyle', get_string('borderstyle', 'certificate'), certificate_get_images(CERT_IMAGE_BORDER));
$mform->setDefault('borderstyle', '0');
$mform->addHelpButton('borderstyle', 'borderstyle', 'certificate');
$printframe = array( 0 => get_string('no'), 1 => get_string('borderblack', 'certificate'), 2 => get_string('borderbrown', 'certificate'),
3 => get_string('borderblue', 'certificate'), 4 => get_string('bordergreen', 'certificate'));
$mform->addElement('select', 'bordercolor', get_string('bordercolor', 'certificate'), $printframe);
$mform->setDefault('bordercolor', '0');
$mform->addHelpButton('bordercolor', 'bordercolor', 'certificate');
$mform->addElement('select', 'printwmark', get_string('printwmark', 'certificate'), certificate_get_images(CERT_IMAGE_WATERMARK));
$mform->setDefault('printwmark', '0');
$mform->addHelpButton('printwmark', 'printwmark', 'certificate');
$mform->addElement('select', 'printsignature', get_string('printsignature', 'certificate'), certificate_get_images(CERT_IMAGE_SIGNATURE));
$mform->setDefault('printsignature', '0');
$mform->addHelpButton('printsignature', 'printsignature', 'certificate');
$mform->addElement('select', 'printseal', get_string('printseal', 'certificate'), certificate_get_images(CERT_IMAGE_SEAL));
$mform->setDefault('printseal', '0');
$mform->addHelpButton('printseal', 'printseal', 'certificate');
$this->standard_coursemodule_elements();
$this->add_action_buttons();
}
/**
* Some basic validation
*
* @param $data
* @param $files
* @return array
*/
public function validation($data, $files) {
$errors = parent::validation($data, $files);
// Check that the required time entered is valid
if ((!is_number($data['requiredtime']) || $data['requiredtime'] < 0)) {
$errors['requiredtime'] = get_string('requiredtimenotvalid', 'certificate');
}
return $errors;
}
}