settings_form.php 14 KB

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