moodle_database conversion error.
[moodle.git] / mod / scorm / mod_form.php
CommitLineData
a4813c36 1<?php
23a7718b 2require_once ($CFG->dirroot.'/course/moodleform_mod.php');
a4813c36 3require_once($CFG->dirroot.'/mod/scorm/locallib.php');
4
5class 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;
01e6c030 11 if (isset($CFG->slasharguments) && !$CFG->slasharguments) {
12 $mform->addElement('static', '', '',notify(get_string('slashargs', 'scorm'), 'notifyproblem', 'center', true));
13 }
a4813c36 14//-------------------------------------------------------------------------------
15 $mform->addElement('header', 'general', get_string('general', 'form'));
16
17// Name
18 $mform->addElement('text', 'name', get_string('name'));
8eb1d25f 19 if (!empty($CFG->formatstringstriptags)) {
20 $mform->setType('name', PARAM_TEXT);
21 } else {
22 $mform->setType('name', PARAM_CLEAN);
23 }
a4813c36 24 $mform->addRule('name', null, 'required', null, 'client');
25
26// Summary
27 $mform->addElement('htmleditor', 'summary', get_string('summary'));
28 $mform->setType('summary', PARAM_RAW);
29 $mform->addRule('summary', get_string('required'), 'required', null, 'client');
30 $mform->setHelpButton('summary', array('writing', 'questions', 'richtext'), false, 'editorhelpbutton');
31
32// Reference
d9397d51 33 $mform->addElement('choosecoursefileorimsrepo', 'reference', get_string('package','scorm'));
a4813c36 34 $mform->setType('reference', PARAM_RAW); // We need to find a better PARAM
878aaab9 35 $mform->addRule('reference', get_string('required'), 'required');
4b07d3a8 36 $mform->setHelpButton('reference',array('package', get_string('package', 'scorm'), 'scorm'));
a4813c36 37
38//-------------------------------------------------------------------------------
39// Other Settings
3b631eda 40 $mform->addElement('header', 'advanced', get_string('othersettings', 'form'));
a4813c36 41
a4813c36 42// Grade Method
43 $mform->addElement('select', 'grademethod', get_string('grademethod', 'scorm'), $SCORM_GRADE_METHOD);
4b07d3a8 44 $mform->setHelpButton('grademethod', array('grademethod',get_string('grademethod', 'scorm'),'scorm'));
a4813c36 45 $mform->setDefault('grademethod', 0);
46
47// Maximum Grade
48 for ($i=0; $i<=100; $i++) {
49 $grades[$i] = "$i";
50 }
51 $mform->addElement('select', 'maxgrade', get_string('maximumgrade'), $grades);
52 $mform->setDefault('maxgrade', 0);
53 $mform->disabledIf('maxgrade', 'grademethod','eq',GRADESCOES);
54
55// Attempts
56 $mform->addElement('static', '', '' ,'<hr />');
a4813c36 57
58// Max Attempts
9a71cd85 59 $attempts = array(0 => get_string('nolimit','scorm'));
a4813c36 60 for ($i=1; $i<=$CFG->scorm_maxattempts; $i++) {
61 if ($i == 1) {
3b631eda 62 $attempts[$i] = get_string('attempt1','scorm');
a4813c36 63 } else {
3b631eda 64 $attempts[$i] = get_string('attemptsx','scorm', $i);
a4813c36 65 }
66 }
67 $mform->addElement('select', 'maxattempt', get_string('maximumattempts', 'scorm'), $attempts);
4b07d3a8 68 $mform->setHelpButton('maxattempt', array('maxattempt',get_string('maximumattempts', 'scorm'), 'scorm'));
a4813c36 69 $mform->setDefault('maxattempt', 1);
70
71// What Grade
72 $mform->addElement('select', 'whatgrade', get_string('whatgrade', 'scorm'), $SCORM_WHAT_GRADE);
73 $mform->disabledIf('whatgrade', 'maxattempt','eq',1);
4b07d3a8 74 $mform->setHelpButton('whatgrade', array('whatgrade',get_string('whatgrade', 'scorm'), 'scorm'));
a4813c36 75 $mform->setDefault('whatgrade', 0);
76 $mform->setAdvanced('whatgrade');
77
78// Activation period
2b90f941 79/* $mform->addElement('static', '', '' ,'<hr />');
a4813c36 80 $mform->addElement('static', 'activation', get_string('activation','scorm'));
81 $datestartgrp = array();
82 $datestartgrp[] = &$mform->createElement('date_time_selector', 'startdate');
83 $datestartgrp[] = &$mform->createElement('checkbox', 'startdisabled', null, get_string('disable'));
84 $mform->addGroup($datestartgrp, 'startdategrp', get_string('from'), ' ', false);
85 $mform->setDefault('startdate', 0);
86 $mform->setDefault('startdisabled', 1);
87 $mform->disabledIf('startdategrp', 'startdisabled', 'checked');
88
89 $dateendgrp = array();
90 $dateendgrp[] = &$mform->createElement('date_time_selector', 'enddate');
91 $dateendgrp[] = &$mform->createElement('checkbox', 'enddisabled', null, get_string('disable'));
92 $mform->addGroup($dateendgrp, 'dateendgrp', get_string('to'), ' ', false);
93 $mform->setDefault('enddate', 0);
94 $mform->setDefault('enddisabled', 1);
95 $mform->disabledIf('dateendgrp', 'enddisabled', 'checked');
2b90f941 96*/
a4813c36 97// Stage Size
98 $mform->addElement('static', '', '' ,'<hr />');
99 $mform->addElement('static', 'stagesize', get_string('stagesize','scorm'));
4b07d3a8 100 $mform->setHelpButton('stagesize', array('stagesize',get_string('stagesize', 'scorm'), 'scorm'));
a4813c36 101// Width
102 $mform->addElement('text', 'width', get_string('width','scorm'),'maxlength="5" size="5"');
103 $mform->setDefault('width', $CFG->scorm_framewidth);
104 $mform->setType('width', PARAM_INT);
105
106// Height
107 $mform->addElement('text', 'height', get_string('height','scorm'),'maxlength="5" size="5"');
108 $mform->setDefault('height', $CFG->scorm_frameheight);
109 $mform->setType('height', PARAM_INT);
110
111// Framed / Popup Window
112 $options = array();
113 $options[0] = get_string('iframe', 'scorm');
114 $options[1] = get_string('popup', 'scorm');
115 $mform->addElement('select', 'popup', get_string('display','scorm'), $options);
116 $mform->setDefault('popup', 0);
117 $mform->setAdvanced('popup');
118
119// Window Options
120 $winoptgrp = array();
121 $winoptgrp[] = &$mform->createElement('checkbox', 'resizable', '', get_string('resizable', 'scorm'));
122 $winoptgrp[] = &$mform->createElement('checkbox', 'scrollbars', '', get_string('scrollbars', 'scorm'));
123 $winoptgrp[] = &$mform->createElement('checkbox', 'directories', '', get_string('directories', 'scorm'));
124 $winoptgrp[] = &$mform->createElement('checkbox', 'location', '', get_string('location', 'scorm'));
125 $winoptgrp[] = &$mform->createElement('checkbox', 'menubar', '', get_string('menubar', 'scorm'));
126 $winoptgrp[] = &$mform->createElement('checkbox', 'toolbar', '', get_string('toolbar', 'scorm'));
127 $winoptgrp[] = &$mform->createElement('checkbox', 'status', '', get_string('status', 'scorm'));
4b07d3a8 128 $mform->addGroup($winoptgrp, 'winoptgrp', get_string('options','scorm'), '<br />', false);
a4813c36 129 $mform->setDefault('resizable', 1);
130 $mform->setDefault('scrollbars', 1);
131 $mform->setDefault('directories', 0);
132 $mform->setDefault('location', 0);
133 $mform->setDefault('menubar', 0);
134 $mform->setDefault('toolbar', 0);
135 $mform->setDefault('status', 0);
136 $mform->setAdvanced('winoptgrp');
137 $mform->disabledIf('winoptgrp', 'popup', 'eq', 0);
138
139// Skip view page
140 $options = array();
141 $options[0]=get_string('never');
142 $options[1]=get_string('firstaccess','scorm');
143 $options[2]=get_string('always');
144 $mform->addElement('select', 'skipview', get_string('skipview', 'scorm'), $options);
4b07d3a8 145 $mform->setHelpButton('skipview', array('skipview',get_string('skipview', 'scorm'), 'scorm'));
a4813c36 146 $mform->setDefault('skipview', 1);
147 $mform->setAdvanced('skipview');
148
149// Hide Browse
150 $mform->addElement('selectyesno', 'hidebrowse', get_string('hidebrowse', 'scorm'));
4b07d3a8 151 $mform->setHelpButton('hidebrowse', array('hidebrowse',get_string('hidebrowse', 'scorm'), 'scorm'));
a4813c36 152 $mform->setDefault('hidebrowse', 0);
153 $mform->setAdvanced('hidebrowse');
154
155// Toc display
156 $options = array();
157 $options[1]=get_string('hidden','scorm');
158 $options[0]=get_string('sided','scorm');
159 $options[2]=get_string('popupmenu','scorm');
160 $mform->addElement('select', 'hidetoc', get_string('hidetoc', 'scorm'), $options);
161 $mform->setDefault('hidetoc', 0);
162 $mform->setAdvanced('hidetoc');
163
164// Hide Navigation panel
165 $mform->addElement('selectyesno', 'hidenav', get_string('hidenav', 'scorm'));
166 $mform->setDefault('hidenav', 0);
167 $mform->setAdvanced('hidenav');
168
169// Autocontinue
170 $mform->addElement('selectyesno', 'auto', get_string('autocontinue', 'scorm'));
4b07d3a8 171 $mform->setHelpButton('auto', array('autocontinue',get_string('autocontinue', 'scorm'), 'scorm'));
a4813c36 172 $mform->setDefault('auto', 0);
173 $mform->setAdvanced('auto');
174
a679d64d 175// Update packages timing
a4813c36 176 $options = array();
4b07d3a8 177 $options[0]=get_string('never');
4eaaf0a6 178 // $options[1]=get_string('onchanges','scorm'); - nolonger required, but dont change the sequence
a679d64d 179 $options[2]=get_string('everyday','scorm');
180 $options[3]=get_string('everytime','scorm');
181 $mform->addElement('select', 'updatefreq', get_string('updatefreq', 'scorm'), $options);
182 $mform->setDefault('updatefreq', 0);
183 $mform->setAdvanced('updatefreq');
a4813c36 184
185//-------------------------------------------------------------------------------
186// Hidden Settings
187 $mform->addElement('hidden', 'datadir', null);
188 $mform->addElement('hidden', 'pkgtype', null);
189 $mform->addElement('hidden', 'launch', null);
190 $mform->addElement('hidden', 'redirect', null);
191 $mform->addElement('hidden', 'redirecturl', null);
192
193
194//-------------------------------------------------------------------------------
d8c9d8a1 195 $features = new stdClass;
196 $features->groups = false;
197 $features->groupings = true;
198 $features->groupmembersonly = true;
199 $this->standard_coursemodule_elements($features);
a4813c36 200//-------------------------------------------------------------------------------
201 // buttons
202 $this->add_action_buttons();
203
204 }
205
206 function defaults_preprocessing(&$default_values) {
207 global $COURSE;
208
209 if (isset($default_values['popup']) && ($default_values['popup'] == 1) && isset($default_values['options'])) {
210 $options = explode(',',$default_values['options']);
211 foreach ($options as $option) {
212 list($element,$value) = explode('=',$option);
213 $element = trim($element);
214 $default_values[$element] = trim($value);
215 }
216 }
217 if (isset($default_values['grademethod'])) {
218 $default_values['whatgrade'] = intval($default_values['grademethod'] / 10);
219 $default_values['grademethod'] = $default_values['grademethod'] % 10;
220 }
221 if (isset($default_value['width']) && (strpos($default_value['width'],'%') === false) && ($default_value['width'] <= 100)) {
222 $default_value['width'] .= '%';
223 }
224 if (isset($default_value['width']) && (strpos($default_value['height'],'%') === false) && ($default_value['height'] <= 100)) {
225 $default_value['height'] .= '%';
226 }
227 $scorms = get_all_instances_in_course('scorm', $COURSE);
228 $coursescorm = current($scorms);
229 if (($COURSE->format == 'scorm') && ((count($scorms) == 0) || ($default_values['instance'] == $coursescorm->id))) {
230 $default_values['redirect'] = 'yes';
231 $default_values['redirecturl'] = '../course/view.php?id='.$default_values['course'];
232 } else {
233 $default_values['redirect'] = 'no';
234 $default_values['redirecturl'] = '../mod/scorm/view.php?id='.$default_values['coursemodule'];
235 }
236 if (isset($default_values['version'])) {
237 $default_values['pkgtype'] = (substr($default_values['version'],0,5) == 'SCORM') ? 'scorm':'aicc';
238 }
239 if (isset($default_values['instance'])) {
240 $default_values['datadir'] = $default_values['instance'];
241 }
242 }
243
a78890d5 244 function validation($data, $files) {
245 $errors = parent::validation($data, $files);
60243313 246
a679d64d 247 $validate = scorm_validate($data);
248
60243313 249 if (!$validate->result) {
250 $errors = $errors + $validate->errors;
251 }
252
a78890d5 253 return $errors;
a679d64d 254 }
ea38a6b9 255 //need to translate the "options" field.
256 function set_data($default_values) {
257 if (is_object($default_values)) {
258 if (!empty($default_values->options)) {
259 $options = explode(',', $default_values->options);
260 foreach ($options as $option) {
261 $opt = explode('=', $option);
262 if (isset($opt[1])) {
263 $default_values->$opt[0] = $opt[1];
264 }
265 }
266 }
267 $default_values = (array)$default_values;
268 }
269 $this->data_preprocessing($default_values);
270 parent::set_data($default_values); //never slashed for moodleform_mod
271 }
a4813c36 272}
d9397d51 273?>