PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/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
Possible License(s): GPL-2.0, LGPL-2.1, BSD-3-Clause, LGPL-2.0
  1. <?php
  2. require_once ($CFG->dirroot.'/course/moodleform_mod.php');
  3. require_once($CFG->dirroot.'/mod/scorm/locallib.php');
  4. class mod_scorm_mod_form extends moodleform_mod {
  5. function definition() {
  6. global $CFG, $COURSE;
  7. $mform =& $this->_form;
  8. if (isset($CFG->slasharguments) && !$CFG->slasharguments) {
  9. $mform->addElement('static', '', '',notify(get_string('slashargs', 'scorm'), 'notifyproblem', 'center', true));
  10. }
  11. $zlib = ini_get('zlib.output_compression'); //check for zlib compression - if used, throw error because of IE bug. - SEE MDL-16185
  12. if (isset($zlib) && $zlib) {
  13. $mform->addElement('static', '', '',notify(get_string('zlibwarning', 'scorm'), 'notifyproblem', 'center', true));
  14. }
  15. //-------------------------------------------------------------------------------
  16. $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);
  23. }
  24. $mform->addRule('name', null, 'required', null, 'client');
  25. // Summary
  26. $mform->addElement('htmleditor', 'summary', get_string('summary'));
  27. $mform->setType('summary', PARAM_RAW);
  28. $mform->addRule('summary', get_string('required'), 'required', null, 'client');
  29. $mform->setHelpButton('summary', array('writing', 'questions', 'richtext'), false, 'editorhelpbutton');
  30. // Reference
  31. $mform->addElement('choosecoursefileorimsrepo', 'reference', get_string('package','scorm'));
  32. $mform->setType('reference', PARAM_RAW); // We need to find a better PARAM
  33. $mform->addRule('reference', get_string('required'), 'required');
  34. $mform->setHelpButton('reference',array('package', get_string('package', 'scorm'), 'scorm'));
  35. //-------------------------------------------------------------------------------
  36. // Other Settings
  37. $mform->addElement('header', 'advanced', get_string('othersettings', 'form'));
  38. // Grade Method
  39. $mform->addElement('select', 'grademethod', get_string('grademethod', 'scorm'), scorm_get_grade_method_array());
  40. $mform->setHelpButton('grademethod', array('grademethod',get_string('grademethod', 'scorm'),'scorm'));
  41. $mform->setDefault('grademethod', $CFG->scorm_grademethod);
  42. // Maximum Grade
  43. for ($i=0; $i<=100; $i++) {
  44. $grades[$i] = "$i";
  45. }
  46. $mform->addElement('select', 'maxgrade', get_string('maximumgrade'), $grades);
  47. $mform->setDefault('maxgrade', $CFG->scorm_maxgrade);
  48. $mform->disabledIf('maxgrade', 'grademethod','eq',GRADESCOES);
  49. // Attempts
  50. $mform->addElement('static', '', '' ,'<hr />');
  51. // Max Attempts
  52. $mform->addElement('select', 'maxattempt', get_string('maximumattempts', 'scorm'), scorm_get_attempts_array());
  53. $mform->setHelpButton('maxattempt', array('maxattempt',get_string('maximumattempts', 'scorm'), 'scorm'));
  54. $mform->setDefault('maxattempt', $CFG->scorm_maxattempts);
  55. // What Grade
  56. $mform->addElement('select', 'whatgrade', get_string('whatgrade', 'scorm'), scorm_get_what_grade_array());
  57. $mform->disabledIf('whatgrade', 'maxattempt','eq',1);
  58. $mform->setHelpButton('whatgrade', array('whatgrade',get_string('whatgrade', 'scorm'), 'scorm'));
  59. $mform->setDefault('whatgrade', $CFG->scorm_whatgrade);
  60. $mform->setAdvanced('whatgrade');
  61. // Activation period
  62. /* $mform->addElement('static', '', '' ,'<hr />');
  63. $mform->addElement('static', 'activation', get_string('activation','scorm'));
  64. $datestartgrp = array();
  65. $datestartgrp[] = &$mform->createElement('date_time_selector', 'startdate');
  66. $datestartgrp[] = &$mform->createElement('checkbox', 'startdisabled', null, get_string('disable'));
  67. $mform->addGroup($datestartgrp, 'startdategrp', get_string('from'), ' ', false);
  68. $mform->setDefault('startdate', 0);
  69. $mform->setDefault('startdisabled', 1);
  70. $mform->disabledIf('startdategrp', 'startdisabled', 'checked');
  71. $dateendgrp = array();
  72. $dateendgrp[] = &$mform->createElement('date_time_selector', 'enddate');
  73. $dateendgrp[] = &$mform->createElement('checkbox', 'enddisabled', null, get_string('disable'));
  74. $mform->addGroup($dateendgrp, 'dateendgrp', get_string('to'), ' ', false);
  75. $mform->setDefault('enddate', 0);
  76. $mform->setDefault('enddisabled', 1);
  77. $mform->disabledIf('dateendgrp', 'enddisabled', 'checked');
  78. */
  79. // Stage Size
  80. $mform->addElement('static', '', '' ,'<hr />');
  81. $mform->addElement('static', 'stagesize', get_string('stagesize','scorm'));
  82. $mform->setHelpButton('stagesize', array('stagesize',get_string('stagesize', 'scorm'), 'scorm'));
  83. // Width
  84. $mform->addElement('text', 'width', get_string('width','scorm'),'maxlength="5" size="5"');
  85. $mform->setDefault('width', $CFG->scorm_framewidth);
  86. $mform->setType('width', PARAM_INT);
  87. // Height
  88. $mform->addElement('text', 'height', get_string('height','scorm'),'maxlength="5" size="5"');
  89. $mform->setDefault('height', $CFG->scorm_frameheight);
  90. $mform->setType('height', PARAM_INT);
  91. // Framed / Popup Window
  92. $mform->addElement('select', 'popup', get_string('display','scorm'), scorm_get_popup_display_array());
  93. $mform->setDefault('popup', $CFG->scorm_popup);
  94. $mform->setAdvanced('popup');
  95. // Window Options
  96. $winoptgrp = array();
  97. foreach(scorm_get_popup_options_array() as $key => $value){
  98. $winoptgrp[] = &$mform->createElement('checkbox', $key, '', get_string($key, 'scorm'));
  99. $mform->setDefault($key, $value);
  100. }
  101. $mform->addGroup($winoptgrp, 'winoptgrp', get_string('options','scorm'), '<br />', false);
  102. $mform->setAdvanced('winoptgrp');
  103. $mform->disabledIf('winoptgrp', 'popup', 'eq', 0);
  104. // Skip view page
  105. $mform->addElement('select', 'skipview', get_string('skipview', 'scorm'), scorm_get_skip_view_array());
  106. $mform->setHelpButton('skipview', array('skipview',get_string('skipview', 'scorm'), 'scorm'));
  107. $mform->setDefault('skipview', $CFG->scorm_skipview);
  108. $mform->setAdvanced('skipview');
  109. // Hide Browse
  110. $mform->addElement('selectyesno', 'hidebrowse', get_string('hidebrowse', 'scorm'));
  111. $mform->setHelpButton('hidebrowse', array('hidebrowse',get_string('hidebrowse', 'scorm'), 'scorm'));
  112. $mform->setDefault('hidebrowse', $CFG->scorm_hidebrowse);
  113. $mform->setAdvanced('hidebrowse');
  114. // Toc display
  115. $mform->addElement('select', 'hidetoc', get_string('hidetoc', 'scorm'), scorm_get_hidetoc_array());
  116. $mform->setDefault('hidetoc', $CFG->scorm_hidetoc);
  117. $mform->setAdvanced('hidetoc');
  118. // Hide Navigation panel
  119. $mform->addElement('selectyesno', 'hidenav', get_string('hidenav', 'scorm'));
  120. $mform->setDefault('hidenav', $CFG->scorm_hidenav);
  121. $mform->setAdvanced('hidenav');
  122. // Autocontinue
  123. $mform->addElement('selectyesno', 'auto', get_string('autocontinue', 'scorm'));
  124. $mform->setHelpButton('auto', array('autocontinue',get_string('autocontinue', 'scorm'), 'scorm'));
  125. $mform->setDefault('auto', $CFG->scorm_auto);
  126. $mform->setAdvanced('auto');
  127. // Update packages timing
  128. $mform->addElement('select', 'updatefreq', get_string('updatefreq', 'scorm'), scorm_get_updatefreq_array());
  129. $mform->setDefault('updatefreq', $CFG->scorm_updatefreq);
  130. $mform->setAdvanced('updatefreq');
  131. //-------------------------------------------------------------------------------
  132. // Hidden Settings
  133. $mform->addElement('hidden', 'datadir', null);
  134. $mform->setType('datadir', PARAM_RAW);
  135. $mform->addElement('hidden', 'pkgtype', null);
  136. $mform->setType('pkgtype', PARAM_RAW);
  137. $mform->addElement('hidden', 'launch', null);
  138. $mform->setType('launch', PARAM_RAW);
  139. $mform->addElement('hidden', 'redirect', null);
  140. $mform->setType('redirect', PARAM_RAW);
  141. $mform->addElement('hidden', 'redirecturl', null);
  142. $mform->setType('redirecturl', PARAM_RAW);
  143. //-------------------------------------------------------------------------------
  144. $features = new stdClass;
  145. $features->groups = false;
  146. $features->groupings = true;
  147. $features->groupmembersonly = true;
  148. $this->standard_coursemodule_elements($features);
  149. //-------------------------------------------------------------------------------
  150. // buttons
  151. $this->add_action_buttons();
  152. }
  153. function data_preprocessing(&$default_values) {
  154. global $COURSE;
  155. if (isset($default_values['popup']) && ($default_values['popup'] == 1) && isset($default_values['options'])) {
  156. if (!empty($default_values['options'])) {
  157. $options = explode(',',$default_values['options']);
  158. foreach ($options as $option) {
  159. list($element,$value) = explode('=',$option);
  160. $element = trim($element);
  161. $default_values[$element] = trim($value);
  162. }
  163. }
  164. }
  165. if (isset($default_values['grademethod'])) {
  166. $default_values['whatgrade'] = intval($default_values['grademethod'] / 10);
  167. $default_values['grademethod'] = $default_values['grademethod'] % 10;
  168. }
  169. if (isset($default_value['width']) && (strpos($default_value['width'],'%') === false) && ($default_value['width'] <= 100)) {
  170. $default_value['width'] .= '%';
  171. }
  172. if (isset($default_value['width']) && (strpos($default_value['height'],'%') === false) && ($default_value['height'] <= 100)) {
  173. $default_value['height'] .= '%';
  174. }
  175. $scorms = get_all_instances_in_course('scorm', $COURSE);
  176. $coursescorm = current($scorms);
  177. if (($COURSE->format == 'scorm') && ((count($scorms) == 0) || ($default_values['instance'] == $coursescorm->id))) {
  178. $default_values['redirect'] = 'yes';
  179. $default_values['redirecturl'] = '../course/view.php?id='.$default_values['course'];
  180. } else {
  181. $default_values['redirect'] = 'no';
  182. $default_values['redirecturl'] = '../mod/scorm/view.php?id='.$default_values['coursemodule'];
  183. }
  184. if (isset($default_values['version'])) {
  185. $default_values['pkgtype'] = (substr($default_values['version'],0,5) == 'SCORM') ? 'scorm':'aicc';
  186. }
  187. if (isset($default_values['instance'])) {
  188. $default_values['datadir'] = $default_values['instance'];
  189. }
  190. }
  191. function validation($data, $files) {
  192. $errors = parent::validation($data, $files);
  193. $validate = scorm_validate($data);
  194. if (!$validate->result) {
  195. $errors = $errors + $validate->errors;
  196. }
  197. return $errors;
  198. }
  199. //need to translate the "options" field.
  200. function set_data($default_values) {
  201. if (is_object($default_values)) {
  202. if (!empty($default_values->options)) {
  203. $options = explode(',', $default_values->options);
  204. foreach ($options as $option) {
  205. $opt = explode('=', $option);
  206. if (isset($opt[1])) {
  207. $default_values->$opt[0] = $opt[1];
  208. }
  209. }
  210. }
  211. $default_values = (array)$default_values;
  212. }
  213. $this->data_preprocessing($default_values);
  214. parent::set_data($default_values); //never slashed for moodleform_mod
  215. }
  216. }
  217. ?>