a4813c36 |
1 | <?php |
2 | require_once ('moodleform_mod.php'); |
3 | require_once($CFG->dirroot.'/mod/scorm/locallib.php'); |
4 | |
5 | class mod_scorm_mod_form extends moodleform_mod { |
6 | |
7 | function definition() { |
8 | |
9 | global $CFG, $COURSE, $SCORM_GRADE_METHOD, $SCORM_WHAT_GRADE; |
10 | $mform =& $this->_form; |
11 | |
12 | //------------------------------------------------------------------------------- |
13 | $mform->addElement('header', 'general', get_string('general', 'form')); |
14 | |
15 | // Name |
16 | $mform->addElement('text', 'name', get_string('name')); |
17 | $mform->setType('name', PARAM_TEXT); |
18 | $mform->addRule('name', null, 'required', null, 'client'); |
19 | |
20 | // Summary |
21 | $mform->addElement('htmleditor', 'summary', get_string('summary')); |
22 | $mform->setType('summary', PARAM_RAW); |
23 | $mform->addRule('summary', get_string('required'), 'required', null, 'client'); |
24 | $mform->setHelpButton('summary', array('writing', 'questions', 'richtext'), false, 'editorhelpbutton'); |
25 | |
26 | // Reference |
27 | $mform->addElement('choosecoursefile', 'reference', get_string('coursepacket','scorm')); |
28 | $mform->setType('reference', PARAM_RAW); // We need to find a better PARAM |
29 | $mform->addRule('reference', get_string('required'), 'required', null, 'client'); |
30 | $mform->setHelpButton('reference',array('package', get_string('coursepacket', 'scorm')), 'scorm'); |
31 | |
32 | //------------------------------------------------------------------------------- |
33 | // Other Settings |
34 | $mform->addElement('header', 'advanced', get_string('othersettings')); |
35 | |
36 | // Grading |
37 | $mform->addElement('static', 'grade', get_string('grades')); |
38 | // Grade Method |
39 | $mform->addElement('select', 'grademethod', get_string('grademethod', 'scorm'), $SCORM_GRADE_METHOD); |
40 | $mform->setHelpButton('grademethod', array('grademethod',get_string('grademethod', 'scorm')), 'scorm'); |
41 | $mform->setDefault('grademethod', 0); |
42 | |
43 | // Maximum Grade |
44 | for ($i=0; $i<=100; $i++) { |
45 | $grades[$i] = "$i"; |
46 | } |
47 | $mform->addElement('select', 'maxgrade', get_string('maximumgrade'), $grades); |
48 | $mform->setDefault('maxgrade', 0); |
49 | $mform->disabledIf('maxgrade', 'grademethod','eq',GRADESCOES); |
50 | |
51 | // Attempts |
52 | $mform->addElement('static', '', '' ,'<hr />'); |
53 | $mform->addElement('static', 'attempts', get_string('attempts','scorm')); |
54 | |
55 | // Max Attempts |
56 | for ($i=1; $i<=$CFG->scorm_maxattempts; $i++) { |
57 | if ($i == 1) { |
58 | $attempts[$i] = $i . ' ' . get_string('attempt','scorm'); |
59 | } else { |
60 | $attempts[$i] = $i . ' ' . get_string('attempts','scorm'); |
61 | } |
62 | } |
63 | $mform->addElement('select', 'maxattempt', get_string('maximumattempts', 'scorm'), $attempts); |
64 | $mform->setHelpButton('maxattempt', array('maxattempt',get_string('maximumattempts', 'scorm')), 'scorm'); |
65 | $mform->setDefault('maxattempt', 1); |
66 | |
67 | // What Grade |
68 | $mform->addElement('select', 'whatgrade', get_string('whatgrade', 'scorm'), $SCORM_WHAT_GRADE); |
69 | $mform->disabledIf('whatgrade', 'maxattempt','eq',1); |
70 | $mform->setHelpButton('whatgrade', array('whatgrade',get_string('whatgrade', 'scorm')), 'scorm'); |
71 | $mform->setDefault('whatgrade', 0); |
72 | $mform->setAdvanced('whatgrade'); |
73 | |
74 | // Activation period |
75 | $mform->addElement('static', '', '' ,'<hr />'); |
76 | $mform->addElement('static', 'activation', get_string('activation','scorm')); |
77 | $datestartgrp = array(); |
78 | $datestartgrp[] = &$mform->createElement('date_time_selector', 'startdate'); |
79 | $datestartgrp[] = &$mform->createElement('checkbox', 'startdisabled', null, get_string('disable')); |
80 | $mform->addGroup($datestartgrp, 'startdategrp', get_string('from'), ' ', false); |
81 | $mform->setDefault('startdate', 0); |
82 | $mform->setDefault('startdisabled', 1); |
83 | $mform->disabledIf('startdategrp', 'startdisabled', 'checked'); |
84 | |
85 | $dateendgrp = array(); |
86 | $dateendgrp[] = &$mform->createElement('date_time_selector', 'enddate'); |
87 | $dateendgrp[] = &$mform->createElement('checkbox', 'enddisabled', null, get_string('disable')); |
88 | $mform->addGroup($dateendgrp, 'dateendgrp', get_string('to'), ' ', false); |
89 | $mform->setDefault('enddate', 0); |
90 | $mform->setDefault('enddisabled', 1); |
91 | $mform->disabledIf('dateendgrp', 'enddisabled', 'checked'); |
92 | |
93 | // Stage Size |
94 | $mform->addElement('static', '', '' ,'<hr />'); |
95 | $mform->addElement('static', 'stagesize', get_string('stagesize','scorm')); |
96 | $mform->setHelpButton('stagesize', array('stagesize',get_string('stagesize', 'scorm')), 'scorm'); |
97 | // Width |
98 | $mform->addElement('text', 'width', get_string('width','scorm'),'maxlength="5" size="5"'); |
99 | $mform->setDefault('width', $CFG->scorm_framewidth); |
100 | $mform->setType('width', PARAM_INT); |
101 | |
102 | // Height |
103 | $mform->addElement('text', 'height', get_string('height','scorm'),'maxlength="5" size="5"'); |
104 | $mform->setDefault('height', $CFG->scorm_frameheight); |
105 | $mform->setType('height', PARAM_INT); |
106 | |
107 | // Framed / Popup Window |
108 | $options = array(); |
109 | $options[0] = get_string('iframe', 'scorm'); |
110 | $options[1] = get_string('popup', 'scorm'); |
111 | $mform->addElement('select', 'popup', get_string('display','scorm'), $options); |
112 | $mform->setDefault('popup', 0); |
113 | $mform->setAdvanced('popup'); |
114 | |
115 | // Window Options |
116 | $winoptgrp = array(); |
117 | $winoptgrp[] = &$mform->createElement('checkbox', 'resizable', '', get_string('resizable', 'scorm')); |
118 | $winoptgrp[] = &$mform->createElement('checkbox', 'scrollbars', '', get_string('scrollbars', 'scorm')); |
119 | $winoptgrp[] = &$mform->createElement('checkbox', 'directories', '', get_string('directories', 'scorm')); |
120 | $winoptgrp[] = &$mform->createElement('checkbox', 'location', '', get_string('location', 'scorm')); |
121 | $winoptgrp[] = &$mform->createElement('checkbox', 'menubar', '', get_string('menubar', 'scorm')); |
122 | $winoptgrp[] = &$mform->createElement('checkbox', 'toolbar', '', get_string('toolbar', 'scorm')); |
123 | $winoptgrp[] = &$mform->createElement('checkbox', 'status', '', get_string('status', 'scorm')); |
124 | $mform->addGroup($winoptgrp, 'winoptgrp', get_string('options'), '<br />', false); |
125 | $mform->setDefault('resizable', 1); |
126 | $mform->setDefault('scrollbars', 1); |
127 | $mform->setDefault('directories', 0); |
128 | $mform->setDefault('location', 0); |
129 | $mform->setDefault('menubar', 0); |
130 | $mform->setDefault('toolbar', 0); |
131 | $mform->setDefault('status', 0); |
132 | $mform->setAdvanced('winoptgrp'); |
133 | $mform->disabledIf('winoptgrp', 'popup', 'eq', 0); |
134 | |
135 | // Skip view page |
136 | $options = array(); |
137 | $options[0]=get_string('never'); |
138 | $options[1]=get_string('firstaccess','scorm'); |
139 | $options[2]=get_string('always'); |
140 | $mform->addElement('select', 'skipview', get_string('skipview', 'scorm'), $options); |
141 | $mform->setHelpButton('skipview', array('skipview',get_string('skipview', 'scorm')), 'scorm'); |
142 | $mform->setDefault('skipview', 1); |
143 | $mform->setAdvanced('skipview'); |
144 | |
145 | // Hide Browse |
146 | $mform->addElement('selectyesno', 'hidebrowse', get_string('hidebrowse', 'scorm')); |
147 | $mform->setHelpButton('hidebrowse', array('hidebrowse',get_string('hidebrowse', 'scorm')), 'scorm'); |
148 | $mform->setDefault('hidebrowse', 0); |
149 | $mform->setAdvanced('hidebrowse'); |
150 | |
151 | // Toc display |
152 | $options = array(); |
153 | $options[1]=get_string('hidden','scorm'); |
154 | $options[0]=get_string('sided','scorm'); |
155 | $options[2]=get_string('popupmenu','scorm'); |
156 | $mform->addElement('select', 'hidetoc', get_string('hidetoc', 'scorm'), $options); |
157 | $mform->setDefault('hidetoc', 0); |
158 | $mform->setAdvanced('hidetoc'); |
159 | |
160 | // Hide Navigation panel |
161 | $mform->addElement('selectyesno', 'hidenav', get_string('hidenav', 'scorm')); |
162 | $mform->setDefault('hidenav', 0); |
163 | $mform->setAdvanced('hidenav'); |
164 | |
165 | // Autocontinue |
166 | $mform->addElement('selectyesno', 'auto', get_string('autocontinue', 'scorm')); |
167 | $mform->setHelpButton('auto', array('autocontinue',get_string('autocontinue', 'scorm')), 'scorm'); |
168 | $mform->setDefault('auto', 0); |
169 | $mform->setAdvanced('auto'); |
170 | |
171 | // Update external packages timing |
172 | $options = array(); |
173 | $options[0]=get_string('onchanges','scorm'); |
174 | $options[1]=get_string('everyday','scorm'); |
175 | $options[2]=get_string('everytime','scorm'); |
176 | $mform->addElement('select', 'external', get_string('external', 'scorm'), $options); |
177 | $mform->setDefault('external', 0); |
178 | $mform->setAdvanced('external'); |
179 | |
180 | //------------------------------------------------------------------------------- |
181 | // Hidden Settings |
182 | $mform->addElement('hidden', 'datadir', null); |
183 | $mform->addElement('hidden', 'pkgtype', null); |
184 | $mform->addElement('hidden', 'launch', null); |
185 | $mform->addElement('hidden', 'redirect', null); |
186 | $mform->addElement('hidden', 'redirecturl', null); |
187 | |
188 | |
189 | //------------------------------------------------------------------------------- |
190 | $this->standard_coursemodule_elements(); |
191 | //------------------------------------------------------------------------------- |
192 | // buttons |
193 | $this->add_action_buttons(); |
194 | |
195 | } |
196 | |
197 | function defaults_preprocessing(&$default_values) { |
198 | global $COURSE; |
199 | |
200 | if (isset($default_values['popup']) && ($default_values['popup'] == 1) && isset($default_values['options'])) { |
201 | $options = explode(',',$default_values['options']); |
202 | foreach ($options as $option) { |
203 | list($element,$value) = explode('=',$option); |
204 | $element = trim($element); |
205 | $default_values[$element] = trim($value); |
206 | } |
207 | } |
208 | if (isset($default_values['grademethod'])) { |
209 | $default_values['whatgrade'] = intval($default_values['grademethod'] / 10); |
210 | $default_values['grademethod'] = $default_values['grademethod'] % 10; |
211 | } |
212 | if (isset($default_value['width']) && (strpos($default_value['width'],'%') === false) && ($default_value['width'] <= 100)) { |
213 | $default_value['width'] .= '%'; |
214 | } |
215 | if (isset($default_value['width']) && (strpos($default_value['height'],'%') === false) && ($default_value['height'] <= 100)) { |
216 | $default_value['height'] .= '%'; |
217 | } |
218 | $scorms = get_all_instances_in_course('scorm', $COURSE); |
219 | $coursescorm = current($scorms); |
220 | if (($COURSE->format == 'scorm') && ((count($scorms) == 0) || ($default_values['instance'] == $coursescorm->id))) { |
221 | $default_values['redirect'] = 'yes'; |
222 | $default_values['redirecturl'] = '../course/view.php?id='.$default_values['course']; |
223 | } else { |
224 | $default_values['redirect'] = 'no'; |
225 | $default_values['redirecturl'] = '../mod/scorm/view.php?id='.$default_values['coursemodule']; |
226 | } |
227 | if (isset($default_values['version'])) { |
228 | $default_values['pkgtype'] = (substr($default_values['version'],0,5) == 'SCORM') ? 'scorm':'aicc'; |
229 | } |
230 | if (isset($default_values['instance'])) { |
231 | $default_values['datadir'] = $default_values['instance']; |
232 | } |
233 | } |
234 | |
235 | } |
236 | ?> |