PageRenderTime 36ms CodeModel.GetById 17ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 1ms

/moodle/mod/scorm/mod_form.php

https://bitbucket.org/geek745/moodle-db2
PHP | 250 lines | 171 code | 32 blank | 47 comment | 33 complexity | 314224c5f129d35e22b164e254e5c381 MD5 | raw file
  1<?php
  2require_once ($CFG->dirroot.'/course/moodleform_mod.php');
  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;
 10        $mform    =& $this->_form;
 11        if (isset($CFG->slasharguments) && !$CFG->slasharguments) {
 12            $mform->addElement('static', '', '',notify(get_string('slashargs', 'scorm'), 'notifyproblem', 'center', true));
 13        }
 14        $zlib = ini_get('zlib.output_compression'); //check for zlib compression - if used, throw error because of IE bug. - SEE MDL-16185
 15        if (isset($zlib) && $zlib) {
 16            $mform->addElement('static', '', '',notify(get_string('zlibwarning', 'scorm'), 'notifyproblem', 'center', true));
 17        }
 18//-------------------------------------------------------------------------------
 19        $mform->addElement('header', 'general', get_string('general', 'form'));
 20
 21// Name
 22        $mform->addElement('text', 'name', get_string('name'));
 23        if (!empty($CFG->formatstringstriptags)) {
 24            $mform->setType('name', PARAM_TEXT);
 25        } else {
 26            $mform->setType('name', PARAM_CLEAN);
 27        }
 28        $mform->addRule('name', null, 'required', null, 'client');
 29
 30// Summary
 31        $mform->addElement('htmleditor', 'summary', get_string('summary'));
 32        $mform->setType('summary', PARAM_RAW);
 33        $mform->addRule('summary', get_string('required'), 'required', null, 'client');
 34        $mform->setHelpButton('summary', array('writing', 'questions', 'richtext'), false, 'editorhelpbutton');
 35
 36// Reference
 37        $mform->addElement('choosecoursefileorimsrepo', 'reference', get_string('package','scorm'));
 38        $mform->setType('reference', PARAM_RAW);  // We need to find a better PARAM
 39        $mform->addRule('reference', get_string('required'), 'required');
 40        $mform->setHelpButton('reference',array('package', get_string('package', 'scorm'), 'scorm'));
 41
 42//-------------------------------------------------------------------------------
 43// Other Settings
 44        $mform->addElement('header', 'advanced', get_string('othersettings', 'form'));
 45
 46// Grade Method
 47        $mform->addElement('select', 'grademethod', get_string('grademethod', 'scorm'), scorm_get_grade_method_array());
 48        $mform->setHelpButton('grademethod', array('grademethod',get_string('grademethod', 'scorm'),'scorm'));
 49        $mform->setDefault('grademethod', $CFG->scorm_grademethod);
 50
 51// Maximum Grade
 52        for ($i=0; $i<=100; $i++) {
 53          $grades[$i] = "$i";
 54        }
 55        $mform->addElement('select', 'maxgrade', get_string('maximumgrade'), $grades);
 56        $mform->setDefault('maxgrade', $CFG->scorm_maxgrade);
 57        $mform->disabledIf('maxgrade', 'grademethod','eq',GRADESCOES);
 58
 59// Attempts
 60        $mform->addElement('static', '', '' ,'<hr />');
 61
 62// Max Attempts
 63        $mform->addElement('select', 'maxattempt', get_string('maximumattempts', 'scorm'), scorm_get_attempts_array());
 64        $mform->setHelpButton('maxattempt', array('maxattempt',get_string('maximumattempts', 'scorm'), 'scorm'));
 65        $mform->setDefault('maxattempt', $CFG->scorm_maxattempts);
 66
 67// What Grade
 68        $mform->addElement('select', 'whatgrade', get_string('whatgrade', 'scorm'), scorm_get_what_grade_array());
 69        $mform->disabledIf('whatgrade', 'maxattempt','eq',1);
 70        $mform->setHelpButton('whatgrade', array('whatgrade',get_string('whatgrade', 'scorm'), 'scorm'));
 71        $mform->setDefault('whatgrade', $CFG->scorm_whatgrade);
 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        $mform->addElement('select', 'popup', get_string('display','scorm'), scorm_get_popup_display_array());
109        $mform->setDefault('popup', $CFG->scorm_popup);
110        $mform->setAdvanced('popup');
111
112// Window Options
113        $winoptgrp = array();
114        foreach(scorm_get_popup_options_array() as $key => $value){
115            $winoptgrp[] = &$mform->createElement('checkbox', $key, '', get_string($key, 'scorm'));
116            $mform->setDefault($key, $value);
117        }
118        $mform->addGroup($winoptgrp, 'winoptgrp', get_string('options','scorm'), '<br />', false);
119        $mform->setAdvanced('winoptgrp');
120        $mform->disabledIf('winoptgrp', 'popup', 'eq', 0);
121
122// Skip view page
123        $mform->addElement('select', 'skipview', get_string('skipview', 'scorm'), scorm_get_skip_view_array());
124        $mform->setHelpButton('skipview', array('skipview',get_string('skipview', 'scorm'), 'scorm'));
125        $mform->setDefault('skipview', $CFG->scorm_skipview);
126        $mform->setAdvanced('skipview');
127
128// Hide Browse
129        $mform->addElement('selectyesno', 'hidebrowse', get_string('hidebrowse', 'scorm'));
130        $mform->setHelpButton('hidebrowse', array('hidebrowse',get_string('hidebrowse', 'scorm'), 'scorm'));
131        $mform->setDefault('hidebrowse', $CFG->scorm_hidebrowse);
132        $mform->setAdvanced('hidebrowse');
133
134// Toc display
135        $mform->addElement('select', 'hidetoc', get_string('hidetoc', 'scorm'), scorm_get_hidetoc_array());
136        $mform->setDefault('hidetoc', $CFG->scorm_hidetoc);
137        $mform->setAdvanced('hidetoc');
138
139// Hide Navigation panel
140        $mform->addElement('selectyesno', 'hidenav', get_string('hidenav', 'scorm'));
141        $mform->setDefault('hidenav', $CFG->scorm_hidenav);
142        $mform->setAdvanced('hidenav');
143
144// Autocontinue
145        $mform->addElement('selectyesno', 'auto', get_string('autocontinue', 'scorm'));
146        $mform->setHelpButton('auto', array('autocontinue',get_string('autocontinue', 'scorm'), 'scorm'));
147        $mform->setDefault('auto', $CFG->scorm_auto);
148        $mform->setAdvanced('auto');
149
150// Update packages timing
151        $mform->addElement('select', 'updatefreq', get_string('updatefreq', 'scorm'), scorm_get_updatefreq_array());
152        $mform->setDefault('updatefreq', $CFG->scorm_updatefreq);
153        $mform->setAdvanced('updatefreq');
154
155//-------------------------------------------------------------------------------
156// Hidden Settings
157        $mform->addElement('hidden', 'datadir', null);
158        $mform->setType('datadir', PARAM_RAW);
159        $mform->addElement('hidden', 'pkgtype', null);
160        $mform->setType('pkgtype', PARAM_RAW);
161        $mform->addElement('hidden', 'launch', null);
162        $mform->setType('launch', PARAM_RAW);
163        $mform->addElement('hidden', 'redirect', null);
164        $mform->setType('redirect', PARAM_RAW);
165        $mform->addElement('hidden', 'redirecturl', null);
166        $mform->setType('redirecturl', PARAM_RAW);
167
168
169//-------------------------------------------------------------------------------
170        $features = new stdClass;
171        $features->groups = false;
172        $features->groupings = true;
173        $features->groupmembersonly = true;
174        $this->standard_coursemodule_elements($features);
175//-------------------------------------------------------------------------------
176        // buttons
177        $this->add_action_buttons();
178
179    }
180
181    function data_preprocessing(&$default_values) {
182        global $COURSE;
183
184        if (isset($default_values['popup']) && ($default_values['popup'] == 1) && isset($default_values['options'])) {
185            if (!empty($default_values['options'])) {
186                $options = explode(',',$default_values['options']);
187                foreach ($options as $option) {
188                    list($element,$value) = explode('=',$option);
189                    $element = trim($element);
190                    $default_values[$element] = trim($value); 
191                }
192            }
193        }
194        if (isset($default_values['grademethod'])) {
195            $default_values['whatgrade'] = intval($default_values['grademethod'] / 10);
196            $default_values['grademethod'] = $default_values['grademethod'] % 10;
197        }
198        if (isset($default_value['width']) && (strpos($default_value['width'],'%') === false) && ($default_value['width'] <= 100)) {
199            $default_value['width'] .= '%';
200        }
201        if (isset($default_value['width']) && (strpos($default_value['height'],'%') === false) && ($default_value['height'] <= 100)) {
202            $default_value['height'] .= '%';
203        }
204        $scorms = get_all_instances_in_course('scorm', $COURSE);
205        $coursescorm = current($scorms);
206        if (($COURSE->format == 'scorm') && ((count($scorms) == 0) || ($default_values['instance'] == $coursescorm->id))) {
207            $default_values['redirect'] = 'yes';
208            $default_values['redirecturl'] = '../course/view.php?id='.$default_values['course'];    
209        } else {
210            $default_values['redirect'] = 'no';
211            $default_values['redirecturl'] = '../mod/scorm/view.php?id='.$default_values['coursemodule'];
212        }
213        if (isset($default_values['version'])) {
214            $default_values['pkgtype'] = (substr($default_values['version'],0,5) == 'SCORM') ? 'scorm':'aicc';
215        }
216        if (isset($default_values['instance'])) {
217            $default_values['datadir'] = $default_values['instance'];
218        }
219    }
220
221    function validation($data, $files) {
222        $errors = parent::validation($data, $files);
223
224        $validate = scorm_validate($data);
225
226        if (!$validate->result) {
227            $errors = $errors + $validate->errors;
228        }
229
230        return $errors;
231    }
232    //need to translate the "options" field.
233    function set_data($default_values) {
234        if (is_object($default_values)) {
235            if (!empty($default_values->options)) {
236                $options = explode(',', $default_values->options);
237                foreach ($options as $option) {
238                    $opt = explode('=', $option);
239                    if (isset($opt[1])) {
240                        $default_values->$opt[0] = $opt[1];
241                    }
242                }
243            }
244            $default_values = (array)$default_values;
245        }
246        $this->data_preprocessing($default_values);
247        parent::set_data($default_values); //never slashed for moodleform_mod
248    }
249}
250?>