ilm_manager_form.php 4.4 KB

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