2 require_once ('moodleform_mod.php');
3 require_once($CFG->dirroot
.'/mod/scorm/locallib.php');
5 class mod_scorm_mod_form
extends moodleform_mod
{
7 function definition() {
9 global $CFG, $COURSE, $SCORM_GRADE_METHOD, $SCORM_WHAT_GRADE;
10 $mform =& $this->_form
;
12 //-------------------------------------------------------------------------------
13 $mform->addElement('header', 'general', get_string('general', 'form'));
16 $mform->addElement('text', 'name', get_string('name'));
17 $mform->setType('name', PARAM_TEXT
);
18 $mform->addRule('name', null, 'required', null, 'client');
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');
27 $mform->addElement('choosecoursefile', 'reference', get_string('package','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('package', 'scorm')), 'scorm');
32 //-------------------------------------------------------------------------------
34 $mform->addElement('header', 'advanced', get_string('othersettings','scorm'));
37 $mform->addElement('static', 'grade', get_string('grades'));
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);
44 for ($i=0; $i<=100; $i++
) {
47 $mform->addElement('select', 'maxgrade', get_string('maximumgrade'), $grades);
48 $mform->setDefault('maxgrade', 0);
49 $mform->disabledIf('maxgrade', 'grademethod','eq',GRADESCOES
);
52 $mform->addElement('static', '', '' ,'<hr />');
53 $mform->addElement('static', 'attempts', get_string('attempts','scorm'));
56 for ($i=1; $i<=$CFG->scorm_maxattempts
; $i++
) {
58 $attempts[$i] = $i . ' ' . get_string('attempt','scorm');
60 $attempts[$i] = $i . ' ' . get_string('attempts','scorm');
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);
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');
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');
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');
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');
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
);
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
);
107 // Framed / Popup Window
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');
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);
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');
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');
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');
160 // Hide Navigation panel
161 $mform->addElement('selectyesno', 'hidenav', get_string('hidenav', 'scorm'));
162 $mform->setDefault('hidenav', 0);
163 $mform->setAdvanced('hidenav');
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');
171 // Update packages timing
173 $options[0]=get_string('never','scorm');
174 $options[1]=get_string('onchanges','scorm');
175 $options[2]=get_string('everyday','scorm');
176 $options[3]=get_string('everytime','scorm');
177 $mform->addElement('select', 'updatefreq', get_string('updatefreq', 'scorm'), $options);
178 $mform->setDefault('updatefreq', 0);
179 $mform->setAdvanced('updatefreq');
181 //-------------------------------------------------------------------------------
183 $mform->addElement('hidden', 'datadir', null);
184 $mform->addElement('hidden', 'pkgtype', null);
185 $mform->addElement('hidden', 'launch', null);
186 $mform->addElement('hidden', 'redirect', null);
187 $mform->addElement('hidden', 'redirecturl', null);
190 //-------------------------------------------------------------------------------
191 $this->standard_coursemodule_elements();
192 //-------------------------------------------------------------------------------
194 $this->add_action_buttons();
198 function defaults_preprocessing(&$default_values) {
201 if (isset($default_values['popup']) && ($default_values['popup'] == 1) && isset($default_values['options'])) {
202 $options = explode(',',$default_values['options']);
203 foreach ($options as $option) {
204 list($element,$value) = explode('=',$option);
205 $element = trim($element);
206 $default_values[$element] = trim($value);
209 if (isset($default_values['grademethod'])) {
210 $default_values['whatgrade'] = intval($default_values['grademethod'] / 10);
211 $default_values['grademethod'] = $default_values['grademethod'] %
10;
213 if (isset($default_value['width']) && (strpos($default_value['width'],'%') === false) && ($default_value['width'] <= 100)) {
214 $default_value['width'] .= '%';
216 if (isset($default_value['width']) && (strpos($default_value['height'],'%') === false) && ($default_value['height'] <= 100)) {
217 $default_value['height'] .= '%';
219 $scorms = get_all_instances_in_course('scorm', $COURSE);
220 $coursescorm = current($scorms);
221 if (($COURSE->format
== 'scorm') && ((count($scorms) == 0) ||
($default_values['instance'] == $coursescorm->id
))) {
222 $default_values['redirect'] = 'yes';
223 $default_values['redirecturl'] = '../course/view.php?id='.$default_values['course'];
225 $default_values['redirect'] = 'no';
226 $default_values['redirecturl'] = '../mod/scorm/view.php?id='.$default_values['coursemodule'];
228 if (isset($default_values['version'])) {
229 $default_values['pkgtype'] = (substr($default_values['version'],0,5) == 'SCORM') ?
'scorm':'aicc';
231 if (isset($default_values['instance'])) {
232 $default_values['datadir'] = $default_values['instance'];
236 function validation($data) {
237 $validate = scorm_validate($data);
239 if ($validate->result
) {
242 return $validate->errors
;