ilm_manager_form.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * Form to manager ilm installed into iAssign.
  4. * This uses 'locallib.php:view_files_ilm($iassign_ilm_class, $extension)' to construct HTML/JavaScript to manage iLM content files.
  5. *
  6. * Release Notes:
  7. * - v 1.7 2013/10/24
  8. * + View extension when iassign view is active.
  9. * - v 1.6 2013/08/22
  10. * + Merge for import zip files and iassign files.
  11. * - v 1.5 2013/08/21
  12. * + Insert functions for import files.
  13. * - v 1.4 2013/07/23
  14. * + Fix filter iLM from select of iLMs only iassign mode and not block mode..
  15. * + Fix change form message with function 'disable_form_change_checker()'.
  16. * - v 1.3 2013/07/12
  17. * + Fix filter iLM from select of iLMs.
  18. * + Fix error messages of 'setType' in debug mode for hidden fields.
  19. * - v 1.1 2013/06/26
  20. * + Remove the button of choose iLM (ID of iLM send of parent page).
  21. *
  22. * @author Patricia Alves Rodrigues
  23. * @author Leo^nidas de Oliveira Branda~o
  24. * @version v 1.7 2013/10/24
  25. * @package mod_iassign_ilm
  26. * @since 2010/09/27
  27. * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
  28. *
  29. * <b>License</b>
  30. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  31. */
  32. if (!defined('MOODLE_INTERNAL')) {
  33. die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
  34. }
  35. require_once($CFG->libdir . '/formslib.php');
  36. /// This class create form based on moodleform.
  37. // @calledby ./mod/iassign/ilm_manager.php
  38. // @see moodleform
  39. class ilm_manager_form extends moodleform {
  40. function definition () {
  41. global $CFG, $USER, $DB, $PAGE, $OUTPUT;
  42. $id = optional_param('id', 0, PARAM_INT); // Course Module ID
  43. $from = optional_param('from', 0, PARAM_TEXT);
  44. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  45. $mform = & $this->_form;
  46. //TODO Javascript code: verify alternatives...
  47. $code_javascript_open_online_ilm = "
  48. <script type='text/javascript'>
  49. //<![CDATA[
  50. function clear_action (action) { // Auxiliary to identify correct iAssign form 'http://.../moodle/mod/iassign/ilm_manager.php'
  51. if (action) {
  52. var items = action.split('/');
  53. var sizeI = items.length;
  54. return items[sizeI-1];
  55. }
  56. return '';
  57. }
  58. function open_online_ilm (ilmid) {
  59. var dirid, ilmid;
  60. if (ilmid == null || ilmid == '')
  61. ilmid = document.getElementById('id_iassign_ilmid').value;
  62. var document_forms = document.getElementsByTagName('form'); // instead of document.forms
  63. //TOODO: Nowadays, there are lots of 'form' in view of Moodle! Use: id='mform1_k2DTt9FBTfCoWkC'
  64. console.log('ilm_manager_form.php: open_online_ilm(.): #document_forms = ' + document_forms.length);
  65. for (var i=0; i<document_forms.length; i++) {
  66. var strAction = clear_action(document_forms[i].action);
  67. if (strAction == 'ilm_manager.php') {
  68. dirid = document_forms[i].dirid.value;
  69. break;
  70. }
  71. }
  72. console.log('ilm_manager_form.php: open_online_ilm(.): dirid=' + dirid);
  73. // change window content with iLM online editor
  74. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $from . "&id=" . $id . "&action=new&ilmid='+ilmid+'&dirid='+dirid;
  75. }
  76. //]]>
  77. </script>\n";
  78. /// Adding new iLM
  79. $mform->addElement('header', 'new_ilm', get_string('new_ilm', 'iassign'));
  80. $extension_text = '';
  81. if ($from == 'block' || $from == 'tinymce') {
  82. // Search iMA registered in the database
  83. $ilms = $DB->get_records('iassign_ilm', array('enable' => 1));
  84. $applets = array();
  85. foreach ($ilms as $ilm)
  86. $applets[$ilm->id] = $ilm->name . ' ' . $ilm->version;
  87. $ia_array = array();
  88. $ia_array[] = & $mform->createElement('select', 'iassign_ilmid', get_string('choose_iLM', 'iassign'), $applets);
  89. $ia_array[] = & $mform->createElement('button', 'online_new_iassign', get_string('open_editor_ilm', 'iassign', ''), array('onClick' => 'open_online_ilm()'));
  90. $mform->addGroup($ia_array, 'select_iassign', get_string('choose_iLM', 'iassign'), array(' '), false);
  91. }
  92. else if ($from == 'iassign') {
  93. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  94. if ($iassign_ilm) {
  95. $extension_text = "(" . $iassign_ilm->extension . ") ";
  96. $ia_array[] = & $mform->createElement('button', 'online_new_iassign', get_string('open_editor_ilm', 'iassign', ' ' . $iassign_ilm->name), array('onClick' => 'open_online_ilm(' . $ilmid . ')'));
  97. $mform->addGroup($ia_array, 'select_iassign', '', array(' '), false);
  98. }
  99. }
  100. /// Upload file ilm
  101. $mform->addElement('html', $code_javascript_open_online_ilm);
  102. $mform->addElement('header', 'upload_ilm_file', get_string('upload_ilm_file', 'iassign'));
  103. $options = array('subdirs' => 0, 'maxbytes' => $CFG->userquota, 'maxfiles' => -1, 'accepted_types' => array('*'));
  104. $mform->addElement('filepicker', 'file', get_string('import_file', 'iassign', $extension_text), null, $options);
  105. $mform->addElement('submit', 'submitbutton', get_string('add_file', 'iassign'));
  106. // Hidden fields
  107. $mform->addElement('hidden', 'id');
  108. $mform->setType('id', PARAM_TEXT);
  109. $mform->addElement('hidden', 'from');
  110. $mform->setType('from', PARAM_TEXT);
  111. $mform->addElement('hidden', 'ilmid');
  112. $mform->setType('ilmid', PARAM_TEXT);
  113. $mform->addElement('hidden', 'dirid');
  114. $mform->setType('dirid', PARAM_TEXT);
  115. $mform->disable_form_change_checker();
  116. }
  117. } // class ilm_manager_form extends moodleform