PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/local/campusconnect/fakecms_form.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 206 lines | 145 code | 24 blank | 37 comment | 10 complexity | ba5e48a80e55c6d1848bba58692cf1eb MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, Apache-2.0, BSD-3-Clause, AGPL-3.0
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Supports the creation of resources via fakecms.php
  18. *
  19. * @package local_campusconnect
  20. * @copyright 2012 Davo Smith, Synergy Learning
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. defined('MOODLE_INTERNAL') || die();
  24. global $CFG;
  25. require_once($CFG->libdir.'/formslib.php');
  26. /** Form for entering CMS data */
  27. class fakecms_form extends moodleform {
  28. public function definition() {
  29. $mform = $this->_form;
  30. $participants = $this->_customdata['participants'];
  31. $cmsparticipant = $this->_customdata['cmsparticipant'];
  32. $thisparticipant = $this->_customdata['thisparticipant'];
  33. $dirresources = $this->_customdata['dirresources'];
  34. if (!empty($dirresources)) {
  35. $dirresources = array_combine($dirresources, $dirresources);
  36. }
  37. $crsresources = $this->_customdata['crsresources'];
  38. if (!empty($crsresources)) {
  39. $crsresources = array_combine($crsresources, $crsresources);
  40. }
  41. $mbrresources = $this->_customdata['mbrresources'];
  42. if (!empty($mbrresources)) {
  43. $mbrresources = array_combine($mbrresources, $mbrresources);
  44. }
  45. $actions = array(
  46. 'create' => 'create',
  47. 'retrieve' => 'retrieve',
  48. 'update' => 'update',
  49. 'delete' => 'delete',
  50. );
  51. // General settings
  52. $mform->addElement('header', 'general', 'General');
  53. $mform->addElement('select', 'srcpart', 'Send from', $participants);
  54. $mform->setDefault('srcpart', $cmsparticipant);
  55. $mform->addElement('select', 'dstpart', 'Send to', $participants);
  56. $mform->setDefault('dstpart', $thisparticipant);
  57. // Directory trees
  58. $mform->addElement('header', 'dirtree', 'Directory tree');
  59. $mform->addElement('select', 'diraction', 'Action', $actions);
  60. $mform->addElement('select', 'dirresourceid', 'Existing resource', $dirresources);
  61. $mform->disabledIf('dirresourceid', 'diraction', 'eq', 'create');
  62. $mform->addElement('text', 'dirtreetitle', 'Directory tree name');
  63. $mform->setType('dirtreetitle', PARAM_TEXT);
  64. $mform->setDefault('dirtreetitle', 'Directory tree');
  65. $mform->addElement('text', 'dirrootid', 'Root directory id', array('size' => 10));
  66. $mform->setType('dirrootid', PARAM_TEXT);
  67. $mform->addElement('text', 'dirid', 'Directory id', array('size' => 10));
  68. $mform->setType('dirid', PARAM_TEXT);
  69. $mform->addElement('text', 'dirtitle', 'Directory title');
  70. $mform->setType('dirtitle', PARAM_TEXT);
  71. $mform->addElement('text', 'dirparentid', 'Parent directory id', array('size' => 10));
  72. $mform->setType('dirparentid', PARAM_TEXT);
  73. $mform->addElement('text', 'dirorder', 'Directory order (within parent)', array('size' => 10));
  74. $mform->setType('dirorder', PARAM_TEXT);
  75. $mform->addElement('submit', 'dirsubmit', 'Send directory request');
  76. // Courses
  77. $mform->addElement('header', 'course', 'Course');
  78. $mform->addElement('select', 'crsaction', 'Action', $actions);
  79. $mform->addElement('select', 'crsresourceid', 'Existing resource', $crsresources);
  80. $mform->disabledIf('crsresourceid', 'crsaction', 'eq', 'create');
  81. $mform->addElement('text', 'crsorganisation', 'Course organisation');
  82. $mform->setType('crsorganisation', PARAM_TEXT);
  83. $mform->addElement('text', 'crsid', 'Course id', array('size' => 10));
  84. $mform->setType('crsid', PARAM_TEXT);
  85. $mform->addElement('text', 'crsterm', 'Term', array('size' => 10));
  86. $mform->setType('crsterm', PARAM_TEXT);
  87. $mform->addElement('text', 'crstitle', 'Title');
  88. $mform->setType('crstitle', PARAM_TEXT);
  89. $mform->addElement('text', 'crstype', 'Course type');
  90. $mform->setType('crstype', PARAM_TEXT);
  91. $mform->addElement('text', 'crsmaxpart', 'Max participants', array('size' => 10));
  92. $mform->setType('crsmaxpart', PARAM_TEXT);
  93. /*
  94. for ($i=1; $i<=2; $i++) {
  95. $grp = array(
  96. $mform->createElement('text', "crslecturerfirst[$i]", ''),
  97. $mform->createElement('text', "crslecturerlast[$i]", ''),
  98. );
  99. $mform->setType("crslecturerfirst[$i]", PARAM_TEXT);
  100. $mform->setType("crslecturerlast[$i]", PARAM_TEXT);
  101. $mform->addGroup($grp, "crslecturer[$i]", "Lecturer $i (first, last)", ' ', false);
  102. }
  103. */
  104. for ($i=1; $i<=3; $i++) {
  105. $grp = array(
  106. $mform->createElement('text', "crsallparent[$i]", '', array('size' => 10)),
  107. $mform->createElement('text', "crsallorder[$i]", '', array('size' => 10)),
  108. );
  109. $mform->setType("crsallparent[$i]", PARAM_TEXT);
  110. $mform->setType("crsallorder[$i]", PARAM_TEXT);
  111. $mform->addGroup($grp, "crsallocation[$i]", "Allocation $i (parentdir, order)", ' ', false);
  112. }
  113. $mform->addElement('static', 'crsp', '', 'Parallel groups');
  114. $mform->setAdvanced('crsp');
  115. $mform->addElement('select', 'crsparallel', 'Parallel group scenario', array(-1 => 'none', 1 => 'One course', 2 => 'Separate groups', 3 => 'Separate courses', 4 => 'Separate lecturers'));
  116. $mform->setAdvanced("crsparallel");
  117. for ($i=1; $i<=3; $i++) {
  118. $mform->addElement('text', "crsptitle[$i]", "PGroup$i title");
  119. $mform->setAdvanced("crsptitle[$i]");
  120. $mform->setType("crsptitle[$i]", PARAM_TEXT);
  121. $mform->addElement('text', "crspid[$i]", "PGroup$i id", array('size' => 10));
  122. $mform->setType("crspid[$i]", PARAM_TEXT);
  123. $mform->setAdvanced("crspid[$i]");
  124. $mform->addElement('text', "crspcomment[$i]", "PGroup$i comment", array('size' => 40));
  125. $mform->setType("crspcomment[$i]", PARAM_TEXT);
  126. $mform->setAdvanced("crspcomment[$i]");
  127. for ($j=1; $j<=3; $j++) {
  128. $grp = array(
  129. $mform->createElement('text', "crsplecturerfirst[$i][$j]", ''),
  130. $mform->createElement('text', "crsplecturerlast[$i][$j]", ''),
  131. );
  132. $mform->setType("crsplecturerfirst[$i][$j]", PARAM_TEXT);
  133. $mform->setType("crsplecturerlast[$i][$j]", PARAM_TEXT);
  134. $mform->addGroup($grp, "crsplecturer[$i][$j]", "Lecturer $j (first, last)", ' ', false);
  135. $mform->setAdvanced("crsplecturer[$i][$j]");
  136. }
  137. $mform->addElement('static', "crsp$i", '', '');
  138. $mform->setAdvanced("crsp$i");
  139. }
  140. $mform->addElement('submit', 'crssubmit', 'Send course request');
  141. // Membership
  142. $mform->addElement('header', 'membership', 'Course membership');
  143. $mform->addElement('select', 'mbraction', 'Action', $actions);
  144. $mform->addElement('select', 'mbrresourceid', 'Existing resource', $mbrresources);
  145. $mform->disabledIf('mbrresourceid', 'mbraction', 'eq', 'create');
  146. $mform->addElement('text', 'mbrcourseid', 'Course id', array('size' => 10));
  147. $mform->setType('mbrcourseid', PARAM_TEXT);
  148. for ($i=1; $i<=5; $i++) {
  149. $mform->addElement('static', "mbr$i", '', '');
  150. $mform->addElement('text', "mbrid[$i]", "Person ID $i (username)");
  151. $mform->setType("mbrid[$i]", PARAM_TEXT);
  152. $mform->addElement('text', "mbrrole[$i]", "Role $i");
  153. $mform->setType("mbrrole[$i]", PARAM_TEXT);
  154. for ($j=1; $j<=3; $j++) {
  155. $mform->addElement('text', "mbrpgid[$i][$j]", "PGroup $i.$j ID", array('size' => 10));
  156. $mform->setType("mbrpgid[$i][$j]", PARAM_TEXT);
  157. $mform->setAdvanced("mbrpgid[$i][$j]");
  158. $mform->addElement('text', "mbrpgrole[$i][$j]", "PGroup $i.$j role");
  159. $mform->setType("mbrpgrole[$i][$j]", PARAM_TEXT);
  160. $mform->setAdvanced("mbrpgrole[$i][$j]");
  161. }
  162. }
  163. $mform->addElement('submit', 'mbrsubmit', 'Send membership request');
  164. $js = <<<END
  165. <script type="text/javascript">
  166. var elnames = ['dir', 'crs', 'mbr'], i, prefix, sel, fnchange;
  167. fnchange = function (e) {
  168. var name = e.currentTarget.id;
  169. var prefix = name.substr(3, 3);
  170. var action = document.getElementById('id_' + prefix + 'action');
  171. action.options[1].selected = true;
  172. };
  173. for (i = 0; i < elnames.length; i += 1) {
  174. prefix = elnames[i];
  175. sel = document.getElementById('id_' + prefix + 'resourceid');
  176. sel.onchange = fnchange;
  177. }
  178. </script>
  179. END;
  180. $mform->addElement('static', 'javascript', '', $js);
  181. }
  182. }