Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / mod / scorm / mod_form.php
blob229427588ae2a87ebf0614fdcb787180a48c4039
1 <?php
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;
11 if (isset($CFG->slasharguments) && !$CFG->slasharguments) {
12 $mform->addElement('static', '', '',notify(get_string('slashargs', 'scorm'), 'notifyproblem', 'center', true));
14 //-------------------------------------------------------------------------------
15 $mform->addElement('header', 'general', get_string('general', 'form'));
17 // Name
18 $mform->addElement('text', 'name', get_string('name'));
19 if (!empty($CFG->formatstringstriptags)) {
20 $mform->setType('name', PARAM_TEXT);
21 } else {
22 $mform->setType('name', PARAM_CLEAN);
24 $mform->addRule('name', null, 'required', null, 'client');
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');
32 // Reference
33 $mform->addElement('choosecoursefileorimsrepo', 'reference', get_string('package','scorm'));
34 $mform->setType('reference', PARAM_RAW); // We need to find a better PARAM
35 $mform->addRule('reference', get_string('required'), 'required');
36 $mform->setHelpButton('reference',array('package', get_string('package', 'scorm'), 'scorm'));
38 //-------------------------------------------------------------------------------
39 // Other Settings
40 $mform->addElement('header', 'advanced', get_string('othersettings', 'form'));
42 // Grade Method
43 $mform->addElement('select', 'grademethod', get_string('grademethod', 'scorm'), $SCORM_GRADE_METHOD);
44 $mform->setHelpButton('grademethod', array('grademethod',get_string('grademethod', 'scorm'),'scorm'));
45 $mform->setDefault('grademethod', 0);
47 // Maximum Grade
48 for ($i=0; $i<=100; $i++) {
49 $grades[$i] = "$i";
51 $mform->addElement('select', 'maxgrade', get_string('maximumgrade'), $grades);
52 $mform->setDefault('maxgrade', 0);
53 $mform->disabledIf('maxgrade', 'grademethod','eq',GRADESCOES);
55 // Attempts
56 $mform->addElement('static', '', '' ,'<hr />');
58 // Max Attempts
59 $attempts = array(0 => get_string('nolimit','scorm'));
60 for ($i=1; $i<=$CFG->scorm_maxattempts; $i++) {
61 if ($i == 1) {
62 $attempts[$i] = get_string('attempt1','scorm');
63 } else {
64 $attempts[$i] = get_string('attemptsx','scorm', $i);
67 $mform->addElement('select', 'maxattempt', get_string('maximumattempts', 'scorm'), $attempts);
68 $mform->setHelpButton('maxattempt', array('maxattempt',get_string('maximumattempts', 'scorm'), 'scorm'));
69 $mform->setDefault('maxattempt', 1);
71 // What Grade
72 $mform->addElement('select', 'whatgrade', get_string('whatgrade', 'scorm'), $SCORM_WHAT_GRADE);
73 $mform->disabledIf('whatgrade', 'maxattempt','eq',1);
74 $mform->setHelpButton('whatgrade', array('whatgrade',get_string('whatgrade', 'scorm'), 'scorm'));
75 $mform->setDefault('whatgrade', 0);
76 $mform->setAdvanced('whatgrade');
78 // Activation period
79 /* $mform->addElement('static', '', '' ,'<hr />');
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');
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');
97 // Stage Size
98 $mform->addElement('static', '', '' ,'<hr />');
99 $mform->addElement('static', 'stagesize', get_string('stagesize','scorm'));
100 $mform->setHelpButton('stagesize', array('stagesize',get_string('stagesize', 'scorm'), 'scorm'));
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);
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);
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');
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'));
128 $mform->addGroup($winoptgrp, 'winoptgrp', get_string('options','scorm'), '<br />', false);
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);
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);
145 $mform->setHelpButton('skipview', array('skipview',get_string('skipview', 'scorm'), 'scorm'));
146 $mform->setDefault('skipview', 1);
147 $mform->setAdvanced('skipview');
149 // Hide Browse
150 $mform->addElement('selectyesno', 'hidebrowse', get_string('hidebrowse', 'scorm'));
151 $mform->setHelpButton('hidebrowse', array('hidebrowse',get_string('hidebrowse', 'scorm'), 'scorm'));
152 $mform->setDefault('hidebrowse', 0);
153 $mform->setAdvanced('hidebrowse');
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');
164 // Hide Navigation panel
165 $mform->addElement('selectyesno', 'hidenav', get_string('hidenav', 'scorm'));
166 $mform->setDefault('hidenav', 0);
167 $mform->setAdvanced('hidenav');
169 // Autocontinue
170 $mform->addElement('selectyesno', 'auto', get_string('autocontinue', 'scorm'));
171 $mform->setHelpButton('auto', array('autocontinue',get_string('autocontinue', 'scorm'), 'scorm'));
172 $mform->setDefault('auto', 0);
173 $mform->setAdvanced('auto');
175 // Update packages timing
176 $options = array();
177 $options[0]=get_string('never');
178 // $options[1]=get_string('onchanges','scorm'); - nolonger required, but dont change the sequence
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');
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);
194 //-------------------------------------------------------------------------------
195 $features = new stdClass;
196 $features->groups = false;
197 $features->groupings = true;
198 $features->groupmembersonly = true;
199 $this->standard_coursemodule_elements($features);
200 //-------------------------------------------------------------------------------
201 // buttons
202 $this->add_action_buttons();
206 function defaults_preprocessing(&$default_values) {
207 global $COURSE;
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);
217 if (isset($default_values['grademethod'])) {
218 $default_values['whatgrade'] = intval($default_values['grademethod'] / 10);
219 $default_values['grademethod'] = $default_values['grademethod'] % 10;
221 if (isset($default_value['width']) && (strpos($default_value['width'],'%') === false) && ($default_value['width'] <= 100)) {
222 $default_value['width'] .= '%';
224 if (isset($default_value['width']) && (strpos($default_value['height'],'%') === false) && ($default_value['height'] <= 100)) {
225 $default_value['height'] .= '%';
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'];
236 if (isset($default_values['version'])) {
237 $default_values['pkgtype'] = (substr($default_values['version'],0,5) == 'SCORM') ? 'scorm':'aicc';
239 if (isset($default_values['instance'])) {
240 $default_values['datadir'] = $default_values['instance'];
244 function validation($data, $files) {
245 $errors = parent::validation($data, $files);
247 $validate = scorm_validate($data);
249 if (!$validate->result) {
250 $errors = $errors + $validate->errors;
253 return $errors;