settings_form.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <?php
  2. /**
  3. * Form to add and edit interactive Learning Module (iLM).
  4. *
  5. * Release Notes:
  6. * - v 1.6 2013/12/12
  7. * + Insert support of import iLM from zip packages.
  8. * - v 1.5 2013/10/31
  9. * + Insert support of import iLM from zip packages.
  10. * - v 1.4 2013/10/24
  11. * + Fix required upload an file for new iLM.
  12. * - v 1.3 2013/07/12
  13. * + Fix error messages of 'setType' in debug mode for hidden fields.
  14. * + Form now accept actions: add, edit, copy (new version from an iLM), and new version (empty new version).
  15. *
  16. * @author Patricia Alves Rodrigues
  17. * @author Leônidas O. Brandão
  18. * @author Luciano Oliveira Borges
  19. * @version v 1.6 2013/12/12
  20. * @package mod_iassign_settings
  21. * @since 2010/09/27
  22. * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
  23. *
  24. * <b>License</b>
  25. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  26. */
  27. /**
  28. * Moodle core defines constant MOODLE_INTERNAL which shall be used to make sure that the script is included and not called directly.
  29. */
  30. if (!defined('MOODLE_INTERNAL')) {
  31. die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
  32. }
  33. require_once ($CFG->libdir . '/formslib.php');
  34. require_once ($CFG->dirroot . '/course/moodleform_mod.php');
  35. require_once ($CFG->dirroot . '/mod/iassign/lib.php');
  36. /**
  37. * This class create form based moodleform.
  38. * @see moodleform
  39. */
  40. class mod_ilm_form extends moodleform {
  41. /**
  42. * Add elements to form
  43. */
  44. function definition() {
  45. global $CFG, $COURSE, $USER, $DB;
  46. $mform = & $this->_form;
  47. if ($CFG->action_ilm != 'import') {
  48. if ($CFG->action_ilm == 'add') {
  49. /* $params = array('parent' => '0');
  50. $tmps = $DB->get_records_sql("SELECT s.id, s.name, s.extension, s.file_jar
  51. FROM {iassign_ilm} s
  52. WHERE s.parent = :parent", $params); // " - jed/emacs */
  53. $tmps = $DB->get_records('iassign_ilm', array('parent' => 0));
  54. } else {
  55. /* $params = array('id' => $CFG->ilm_id);
  56. $tmps = $DB->get_records_sql("SELECT s.id, s.name, s.extension, s.file_jar
  57. FROM {iassign_ilm} s
  58. WHERE s.id != :id AND s.parent = 0", $params); // " - jed/emacs */
  59. $tmps = $DB->get_records('iassign_ilm', array('id' => $CFG->ilm_id));
  60. }
  61. $extensions = "";
  62. $names = "";
  63. $versions = "";
  64. $filejars = "";
  65. foreach ($tmps as $tmp) {
  66. $exts = explode(",", $tmp->extension);
  67. foreach ($exts as $ext) {
  68. $extensions .="'" . $ext . "',";
  69. }
  70. $names .="'" . $tmp->name . "',";
  71. $filejars .="'" . $tmp->file_jar . "',";
  72. }
  73. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $CFG->ilm_id));
  74. if (!$iassign_ilm) {
  75. $iassign_ilm = new stdClass();
  76. $iassign_ilm->parent = 0;
  77. }
  78. /// @todo Código Javascript, verificar alternativa.
  79. $code_javascript = "
  80. <script type='text/javascript'>
  81. //<![CDATA[
  82. document.getElementById('id_data_file_html').style.display = 'none'
  83. document.getElementById('id_data_file_jar').classList.remove('collapsed');
  84. document.getElementById('id_data_ilm').classList.remove('collapsed');
  85. function search_name(name){
  86. var i;
  87. var names = new Array(";
  88. $code_javascript .=$names . "'');" . chr(13);
  89. $code_javascript .="
  90. for (i=0;i<names.length;i++){
  91. if(names[i].toLowerCase()==name.toLowerCase()){
  92. document.forms['mform1'].name.value='';
  93. confirm('" . get_string('invalid_name_ilm', 'iassign') . " '+names[i]+'!');
  94. }
  95. }";
  96. $code_javascript .= "}
  97. function search_extension(extensions){
  98. var i;
  99. var ext_inserteds = extensions.split(',');
  100. var ext_exists = new Array(";
  101. $code_javascript .=$extensions . "'');" . chr(13);
  102. $code_javascript .="
  103. for (k=0;k<ext_inserteds.length;k++){
  104. for (i=0;i<ext_exists.length;i++){
  105. if(ext_exists[i].toLowerCase()==ext_inserteds[k].toLowerCase()){
  106. document.forms['mform1'].extension.value='';
  107. confirm('" . get_string('invalid_extension_ilm', 'iassign') . " '+ext_exists[i]+'!');
  108. }
  109. }
  110. }";
  111. $code_javascript .= "}
  112. function search_filejar(fullfilejar){
  113. var i;
  114. var tmp=fullfilejar.split('/');
  115. var filejar=tmp[tmp.length-1];
  116. var filejars = new Array(";
  117. $code_javascript .=$filejars . "'');" . chr(13);
  118. $code_javascript .="
  119. for (i=0;i<filejars.length;i++){
  120. if(filejars[i].toLowerCase()==filejar.toLowerCase()){
  121. document.forms['mform1'].file_jar[0].value='';
  122. confirm('" . get_string('invalid_filejar_ilm', 'iassign') . " '+filejars[i]+'!');
  123. }
  124. }";
  125. $code_javascript .= "}
  126. function change_language(lang){
  127. if(document.forms['mform1'].description_lang.value != '') {
  128. descriptions = eval('(' + document.forms['mform1'].description_lang.value + ')');
  129. descriptions[document.forms['mform1'].set_lang.value] = tinyMCE.activeEditor.getContent();
  130. document.forms['mform1'].description_lang.value = JSON.stringify(descriptions);
  131. if(descriptions[lang] != undefined)
  132. tinyMCE.activeEditor.setContent(descriptions[lang]);
  133. else
  134. tinyMCE.activeEditor.setContent('');
  135. } else {
  136. document.forms['mform1'].description_lang.value = '{ \"' + document.forms['mform1'].set_lang.value + '\" : \"' + tinyMCE.activeEditor.getContent() + '\" }';
  137. tinyMCE.activeEditor.setContent('');
  138. }
  139. document.forms['mform1'].set_lang.value = lang;
  140. }
  141. //]]>
  142. </script>";
  143. //-------------------------------------------------------------------------------
  144. /// Adding the "data_ilm" fieldset, where all the common settings are showed
  145. if ($CFG->action_ilm != 'add') {
  146. /*$mform->addElement('header', 'type_ilm', get_string('type_ilm', 'iassign'));
  147. /// Adding the select option for HTML5 or Java
  148. $options = array(
  149. 'Java' => 'Java',
  150. 'HTML5' => 'HTML5'
  151. );
  152. $mform->addElement('select', 'ilm_type', get_string('ilm_type', 'iassign'), $options);
  153. $mform->setDefault('ilm_type', PARAM_TEXT);
  154. $mform->addHelpButton('ilm_type', 'ilm_type', 'iassign');
  155. $mform->addElement('header', 'data_ilm', get_string('data_ilm', 'iassign'));
  156. *
  157. */
  158. /// Adding the standard "name" field
  159. if ($CFG->action_ilm != 'add') {
  160. $mform->addElement('static', 'name_ilm', get_string('name_ilm', 'iassign'));
  161. $mform->addElement('hidden', 'name');
  162. $mform->setType('name', PARAM_TEXT);
  163. } else {
  164. $mform->addElement('text', 'name', get_string('name_ilm', 'iassign'), array('size' => '55', 'onchange' => 'search_name(this.value);'));
  165. $mform->setType('name', PARAM_TEXT);
  166. }
  167. /// Adding the standard "version" field
  168. $mform->addElement('text', 'version', get_string('version_ilm', 'iassign'), array('size' => '55'));
  169. $mform->setType('version', PARAM_TEXT);
  170. $mform->addHelpButton('version', 'version_ilm', 'iassign');
  171. // Adding the type of iLM
  172. $mform->addElement('static', 'ilm_type', get_string('type_ilm', 'iassign'));
  173. $mform->addElement('hidden', 'type');
  174. $mform->setType('type', PARAM_TEXT);
  175. /// Adding the standard "url" field
  176. $mform->addElement('text', 'url', get_string('url_ilm', 'iassign'), array('size' => '55'));
  177. $mform->setType('url', PARAM_TEXT);
  178. $mform->addElement('select', 'lang', get_string('language_label', 'iassign'), get_string_manager()->get_list_of_translations(), array('onChange' => 'change_language(this.value);'));
  179. $mform->setDefault('lang', current_language());
  180. /// Adding the standard "description" field
  181. $mform->addElement('htmleditor', 'description', get_string('description', 'iassign'));
  182. $mform->setType('description', PARAM_RAW);
  183. /// Adding the "data_file_jar" fieldset, where all the common settings are showed
  184. $mform->addElement('header', 'data_file_jar', get_string('data_file_jar', 'iassign'));
  185. $mform->addElement('static', 'file_jar_static', get_string('file_jar', 'iassign'));
  186. /// Adding the standard "file_class" field
  187. $mform->addElement('text', 'file_class', get_string('file_class', 'iassign'), array('size' => '55'));
  188. $mform->setType('file_class', PARAM_TEXT);
  189. //$mform->addRule('file_class', get_string('required', 'iassign'), 'required');
  190. /// Adding the standard "extension" field
  191. $mform->addElement('text', 'extension', get_string('extension', 'iassign'), array('size' => '30', 'onchange' => 'search_extension(this.value);'));
  192. $mform->setType('extension', PARAM_TEXT);
  193. //$mform->addRule('extension', get_string('required', 'iassign'), 'required');
  194. $mform->addHelpButton('extension', 'extension', 'iassign');
  195. /// Adding the standard "width" field
  196. $mform->addElement('text', 'width', get_string('width', 'iassign'), array('size' => '10'));
  197. $mform->setType('width', PARAM_TEXT);
  198. //$mform->addRule('width', get_string('required', 'iassign'), 'required');
  199. /// Adding the standard "height" field
  200. $mform->addElement('text', 'height', get_string('height', 'iassign'), array('size' => '10'));
  201. $mform->setType('height', PARAM_TEXT);
  202. //$mform->addRule('height', get_string('required', 'iassign'), 'required');
  203. /// Adding the standard "evaluate" field
  204. $mform->addElement('selectyesno', 'evaluate', get_string('auto_evaluate', 'iassign'));
  205. $mform->setDefault('evaluate', 1);
  206. //$mform->addRule('evaluate', get_string('required', 'iassign'), 'required');
  207. $mform->addHelpButton('evaluate', 'auto_evaluate', 'iassign');
  208. /// Adding the "data_file_jar" fieldset, where all the common settings are showed
  209. $mform->addElement('header', 'data_file_html', get_string('data_file_html', 'iassign'));
  210. /// Adding static text
  211. $mform->addElement('static', 'data_file_html_static', get_string('data_file_html_static', 'iassign'));
  212. }
  213. /// Upload file ilm
  214. /*
  215. $mform->addElement('header', 'upload_jar', get_string('upload_jar', 'iassign'));
  216. //$mform->setExpanded('upload_jar');
  217. $options = array('subdirs' => 0, 'maxbytes' => $CFG->userquota, 'maxfiles' => -1, 'accepted_types' => '*');
  218. $mform->addElement('filemanager', 'file', null, null, $options);
  219. *
  220. */
  221. $mform->addElement('header', 'upload_jar', get_string('upload_jar', 'iassign'));
  222. $options = array('subdirs' => 0, 'maxbytes' => $CFG->userquota, 'maxfiles' => 1, 'accepted_types' => array('*'));
  223. $mform->addElement('filepicker', 'file', null, null, $options);
  224. $mform->addRule('file', get_string('required', 'iassign'), 'required');
  225. if ($CFG->action_ilm == 'add' || $CFG->action_ilm == 'copy' || $CFG->action_ilm == 'new_version')
  226. $mform->addRule('file', get_string('required', 'iassign'), 'required');
  227. /// Adding the standard "hidden" field
  228. if ($CFG->action_ilm == 'edit') {
  229. $mform->addElement('hidden', 'id');
  230. $mform->setType('id', PARAM_INT);
  231. }
  232. $mform->addElement('hidden', 'set_lang');
  233. $mform->setType('set_lang', PARAM_TEXT);
  234. $mform->setDefault('set_lang', current_language());
  235. $mform->addElement('hidden', 'description_lang');
  236. $mform->setType('description_lang', PARAM_TEXT);
  237. $mform->addElement('hidden', 'file_jar');
  238. $mform->setType('file_jar', PARAM_TEXT);
  239. $mform->addElement('hidden', 'author');
  240. $mform->setType('author', PARAM_TEXT);
  241. $mform->addElement('hidden', 'action');
  242. $mform->setType('action', PARAM_TEXT);
  243. $mform->addElement('hidden', 'timecreated');
  244. $mform->setType('timecreated', PARAM_TEXT);
  245. $mform->addElement('hidden', 'timemodified');
  246. $mform->setType('timemodified', PARAM_TEXT);
  247. $mform->addElement('hidden', 'parent');
  248. $mform->setType('parent', PARAM_INT);
  249. $mform->addElement('hidden', 'enable');
  250. $mform->setType('enable', PARAM_INT);
  251. $mform->addElement('html', $code_javascript);
  252. } else {
  253. $mform->addElement('header', 'upload_ilm', get_string('upload_ilm', 'iassign'));
  254. //$mform->setExpanded('upload_ilm');
  255. $options = array('subdirs' => 0, 'maxbytes' => $CFG->userquota, 'maxfiles' => 1, 'accepted_types' => array('*'));
  256. $mform->addElement('filepicker', 'file', null, null, $options);
  257. $mform->addRule('file', get_string('required', 'iassign'), 'required');
  258. $mform->addElement('hidden', 'action');
  259. $mform->setType('action', PARAM_TEXT);
  260. }
  261. $this->add_action_buttons();
  262. }
  263. }