2 require_once ($CFG->dirroot
.'/course/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', 'form'));
37 $mform->addElement('select', 'grademethod', get_string('grademethod', 'scorm'), $SCORM_GRADE_METHOD);
38 $mform->setHelpButton('grademethod', array('grademethod',get_string('grademethod', 'scorm'),'scorm'));
39 $mform->setDefault('grademethod', 0);
42 for ($i=0; $i<=100; $i++
) {
45 $mform->addElement('select', 'maxgrade', get_string('maximumgrade'), $grades);
46 $mform->setDefault('maxgrade', 0);
47 $mform->disabledIf('maxgrade', 'grademethod','eq',GRADESCOES
);
50 $mform->addElement('static', '', '' ,'<hr />');
53 $attempts = array(0 => get_string('nolimit','scorm'));
54 for ($i=1; $i<=$CFG->scorm_maxattempts
; $i++
) {
56 $attempts[$i] = get_string('attempt1','scorm');
58 $attempts[$i] = get_string('attemptsx','scorm', $i);
61 $mform->addElement('select', 'maxattempt', get_string('maximumattempts', 'scorm'), $attempts);
62 $mform->setHelpButton('maxattempt', array('maxattempt',get_string('maximumattempts', 'scorm'), 'scorm'));
63 $mform->setDefault('maxattempt', 1);
66 $mform->addElement('select', 'whatgrade', get_string('whatgrade', 'scorm'), $SCORM_WHAT_GRADE);
67 $mform->disabledIf('whatgrade', 'maxattempt','eq',1);
68 $mform->setHelpButton('whatgrade', array('whatgrade',get_string('whatgrade', 'scorm'), 'scorm'));
69 $mform->setDefault('whatgrade', 0);
70 $mform->setAdvanced('whatgrade');
73 /* $mform->addElement('static', '', '' ,'<hr />');
74 $mform->addElement('static', 'activation', get_string('activation','scorm'));
75 $datestartgrp = array();
76 $datestartgrp[] = &$mform->createElement('date_time_selector', 'startdate');
77 $datestartgrp[] = &$mform->createElement('checkbox', 'startdisabled', null, get_string('disable'));
78 $mform->addGroup($datestartgrp, 'startdategrp', get_string('from'), ' ', false);
79 $mform->setDefault('startdate', 0);
80 $mform->setDefault('startdisabled', 1);
81 $mform->disabledIf('startdategrp', 'startdisabled', 'checked');
83 $dateendgrp = array();
84 $dateendgrp[] = &$mform->createElement('date_time_selector', 'enddate');
85 $dateendgrp[] = &$mform->createElement('checkbox', 'enddisabled', null, get_string('disable'));
86 $mform->addGroup($dateendgrp, 'dateendgrp', get_string('to'), ' ', false);
87 $mform->setDefault('enddate', 0);
88 $mform->setDefault('enddisabled', 1);
89 $mform->disabledIf('dateendgrp', 'enddisabled', 'checked');
92 $mform->addElement('static', '', '' ,'<hr />');
93 $mform->addElement('static', 'stagesize', get_string('stagesize','scorm'));
94 $mform->setHelpButton('stagesize', array('stagesize',get_string('stagesize', 'scorm'), 'scorm'));
96 $mform->addElement('text', 'width', get_string('width','scorm'),'maxlength="5" size="5"');
97 $mform->setDefault('width', $CFG->scorm_framewidth
);
98 $mform->setType('width', PARAM_INT
);
101 $mform->addElement('text', 'height', get_string('height','scorm'),'maxlength="5" size="5"');
102 $mform->setDefault('height', $CFG->scorm_frameheight
);
103 $mform->setType('height', PARAM_INT
);
105 // Framed / Popup Window
107 $options[0] = get_string('iframe', 'scorm');
108 $options[1] = get_string('popup', 'scorm');
109 $mform->addElement('select', 'popup', get_string('display','scorm'), $options);
110 $mform->setDefault('popup', 0);
111 $mform->setAdvanced('popup');
114 $winoptgrp = array();
115 $winoptgrp[] = &$mform->createElement('checkbox', 'resizable', '', get_string('resizable', 'scorm'));
116 $winoptgrp[] = &$mform->createElement('checkbox', 'scrollbars', '', get_string('scrollbars', 'scorm'));
117 $winoptgrp[] = &$mform->createElement('checkbox', 'directories', '', get_string('directories', 'scorm'));
118 $winoptgrp[] = &$mform->createElement('checkbox', 'location', '', get_string('location', 'scorm'));
119 $winoptgrp[] = &$mform->createElement('checkbox', 'menubar', '', get_string('menubar', 'scorm'));
120 $winoptgrp[] = &$mform->createElement('checkbox', 'toolbar', '', get_string('toolbar', 'scorm'));
121 $winoptgrp[] = &$mform->createElement('checkbox', 'status', '', get_string('status', 'scorm'));
122 $mform->addGroup($winoptgrp, 'winoptgrp', get_string('options','scorm'), '<br />', false);
123 $mform->setDefault('resizable', 1);
124 $mform->setDefault('scrollbars', 1);
125 $mform->setDefault('directories', 0);
126 $mform->setDefault('location', 0);
127 $mform->setDefault('menubar', 0);
128 $mform->setDefault('toolbar', 0);
129 $mform->setDefault('status', 0);
130 $mform->setAdvanced('winoptgrp');
131 $mform->disabledIf('winoptgrp', 'popup', 'eq', 0);
135 $options[0]=get_string('never');
136 $options[1]=get_string('firstaccess','scorm');
137 $options[2]=get_string('always');
138 $mform->addElement('select', 'skipview', get_string('skipview', 'scorm'), $options);
139 $mform->setHelpButton('skipview', array('skipview',get_string('skipview', 'scorm'), 'scorm'));
140 $mform->setDefault('skipview', 1);
141 $mform->setAdvanced('skipview');
144 $mform->addElement('selectyesno', 'hidebrowse', get_string('hidebrowse', 'scorm'));
145 $mform->setHelpButton('hidebrowse', array('hidebrowse',get_string('hidebrowse', 'scorm'), 'scorm'));
146 $mform->setDefault('hidebrowse', 0);
147 $mform->setAdvanced('hidebrowse');
151 $options[1]=get_string('hidden','scorm');
152 $options[0]=get_string('sided','scorm');
153 $options[2]=get_string('popupmenu','scorm');
154 $mform->addElement('select', 'hidetoc', get_string('hidetoc', 'scorm'), $options);
155 $mform->setDefault('hidetoc', 0);
156 $mform->setAdvanced('hidetoc');
158 // Hide Navigation panel
159 $mform->addElement('selectyesno', 'hidenav', get_string('hidenav', 'scorm'));
160 $mform->setDefault('hidenav', 0);
161 $mform->setAdvanced('hidenav');
164 $mform->addElement('selectyesno', 'auto', get_string('autocontinue', 'scorm'));
165 $mform->setHelpButton('auto', array('autocontinue',get_string('autocontinue', 'scorm'), 'scorm'));
166 $mform->setDefault('auto', 0);
167 $mform->setAdvanced('auto');
169 // Update packages timing
171 $options[0]=get_string('never');
172 $options[1]=get_string('onchanges','scorm');
173 $options[2]=get_string('everyday','scorm');
174 $options[3]=get_string('everytime','scorm');
175 $mform->addElement('select', 'updatefreq', get_string('updatefreq', 'scorm'), $options);
176 $mform->setDefault('updatefreq', 0);
177 $mform->setAdvanced('updatefreq');
179 //-------------------------------------------------------------------------------
181 $mform->addElement('hidden', 'datadir', null);
182 $mform->addElement('hidden', 'pkgtype', null);
183 $mform->addElement('hidden', 'launch', null);
184 $mform->addElement('hidden', 'redirect', null);
185 $mform->addElement('hidden', 'redirecturl', null);
188 //-------------------------------------------------------------------------------
189 $features = new stdClass
;
190 $features->groups
= false;
191 $features->groupings
= true;
192 $features->groupmembersonly
= true;
193 $this->standard_coursemodule_elements($features);
194 //-------------------------------------------------------------------------------
196 $this->add_action_buttons();
200 function defaults_preprocessing(&$default_values) {
203 if (isset($default_values['popup']) && ($default_values['popup'] == 1) && isset($default_values['options'])) {
204 $options = explode(',',$default_values['options']);
205 foreach ($options as $option) {
206 list($element,$value) = explode('=',$option);
207 $element = trim($element);
208 $default_values[$element] = trim($value);
211 if (isset($default_values['grademethod'])) {
212 $default_values['whatgrade'] = intval($default_values['grademethod'] / 10);
213 $default_values['grademethod'] = $default_values['grademethod'] %
10;
215 if (isset($default_value['width']) && (strpos($default_value['width'],'%') === false) && ($default_value['width'] <= 100)) {
216 $default_value['width'] .= '%';
218 if (isset($default_value['width']) && (strpos($default_value['height'],'%') === false) && ($default_value['height'] <= 100)) {
219 $default_value['height'] .= '%';
221 $scorms = get_all_instances_in_course('scorm', $COURSE);
222 $coursescorm = current($scorms);
223 if (($COURSE->format
== 'scorm') && ((count($scorms) == 0) ||
($default_values['instance'] == $coursescorm->id
))) {
224 $default_values['redirect'] = 'yes';
225 $default_values['redirecturl'] = '../course/view.php?id='.$default_values['course'];
227 $default_values['redirect'] = 'no';
228 $default_values['redirecturl'] = '../mod/scorm/view.php?id='.$default_values['coursemodule'];
230 if (isset($default_values['version'])) {
231 $default_values['pkgtype'] = (substr($default_values['version'],0,5) == 'SCORM') ?
'scorm':'aicc';
233 if (isset($default_values['instance'])) {
234 $default_values['datadir'] = $default_values['instance'];
238 function validation($data) {
239 $errors = parent
::validation($data);
240 if ($errors === true) {
244 $validate = scorm_validate($data);
246 if (!$validate->result
) {
247 $errors = $errors +
$validate->errors
;
250 if (count($errors) == 0) {