PageRenderTime 65ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/moodle/enrol/users_forms.php

https://bitbucket.org/sebastianberm/moodle20
PHP | 200 lines | 121 code | 57 blank | 22 comment | 5 complexity | 8c0210eae3a799967ba114b4e63712f8 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, AGPL-3.0, MPL-2.0-no-copyleft-exception, GPL-3.0, Apache-2.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. * Various enrol UI forms
  18. *
  19. * @package core
  20. * @subpackage enrol
  21. * @copyright 2010 Petr Skoda {@link http://skodak.org}
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. defined('MOODLE_INTERNAL') || die();
  25. require_once("$CFG->libdir/formslib.php");
  26. class enrol_users_assign_form extends moodleform {
  27. function definition() {
  28. global $CFG, $DB;
  29. $mform = $this->_form;
  30. $user = $this->_customdata['user'];
  31. $course = $this->_customdata['course'];
  32. $context = get_context_instance(CONTEXT_COURSE, $course->id);
  33. $assignable = $this->_customdata['assignable'];
  34. $assignable = array_reverse($assignable, true); // students first
  35. $ras = get_user_roles($context, $user->id, true);
  36. foreach ($ras as $ra) {
  37. unset($assignable[$ra->roleid]);
  38. }
  39. $mform->addElement('header','general', fullname($user));
  40. $mform->addElement('select', 'roleid', get_string('addrole', 'role'), $assignable);
  41. $mform->addElement('hidden', 'id');
  42. $mform->setType('id', PARAM_INT);
  43. $mform->addElement('hidden', 'user');
  44. $mform->setType('user', PARAM_INT);
  45. $mform->addElement('hidden', 'action');
  46. $mform->setType('action', PARAM_ACTION);
  47. $mform->addElement('hidden', 'ifilter');
  48. $mform->setType('ifilter', PARAM_ALPHA);
  49. $mform->addElement('hidden', 'page');
  50. $mform->setType('page', PARAM_INT);
  51. $mform->addElement('hidden', 'perpage');
  52. $mform->setType('perpage', PARAM_INT);
  53. $mform->addElement('hidden', 'sort');
  54. $mform->setType('sort', PARAM_ALPHA);
  55. $mform->addElement('hidden', 'dir');
  56. $mform->setType('dir', PARAM_ALPHA);
  57. $this->add_action_buttons();
  58. $this->set_data(array('action'=>'assign', 'user'=>$user->id));
  59. }
  60. }
  61. class enrol_users_addmember_form extends moodleform {
  62. function definition() {
  63. global $CFG, $DB;
  64. $mform = $this->_form;
  65. $user = $this->_customdata['user'];
  66. $course = $this->_customdata['course'];
  67. $context = get_context_instance(CONTEXT_COURSE, $course->id);
  68. $allgroups = $this->_customdata['allgroups'];
  69. $usergroups = groups_get_all_groups($course->id, $user->id, 0, 'g.id');
  70. $options = array();
  71. foreach ($allgroups as $group) {
  72. if (isset($usergroups[$group->id])) {
  73. continue;
  74. }
  75. $options[$group->id] = $group->name;
  76. }
  77. $mform->addElement('header','general', fullname($user));
  78. $mform->addElement('select', 'groupid', get_string('addgroup', 'group'), $options);
  79. $mform->addElement('hidden', 'id');
  80. $mform->setType('id', PARAM_INT);
  81. $mform->addElement('hidden', 'user');
  82. $mform->setType('user', PARAM_INT);
  83. $mform->addElement('hidden', 'action');
  84. $mform->setType('action', PARAM_ACTION);
  85. $mform->addElement('hidden', 'ifilter');
  86. $mform->setType('ifilter', PARAM_ALPHA);
  87. $mform->addElement('hidden', 'page');
  88. $mform->setType('page', PARAM_INT);
  89. $mform->addElement('hidden', 'perpage');
  90. $mform->setType('perpage', PARAM_INT);
  91. $mform->addElement('hidden', 'sort');
  92. $mform->setType('sort', PARAM_ALPHA);
  93. $mform->addElement('hidden', 'dir');
  94. $mform->setType('dir', PARAM_ALPHA);
  95. $this->add_action_buttons();
  96. $this->set_data(array('action'=>'addmember', 'user'=>$user->id));
  97. }
  98. }
  99. class enrol_users_edit_form extends moodleform {
  100. function definition() {
  101. global $CFG, $DB;
  102. $mform = $this->_form;
  103. $user = $this->_customdata['user'];
  104. $course = $this->_customdata['course'];
  105. $ue = $this->_customdata['ue'];
  106. $mform->addElement('header','general', '');
  107. $options = array(ENROL_USER_ACTIVE => get_string('participationactive', 'enrol'),
  108. ENROL_USER_SUSPENDED => get_string('participationsuspended', 'enrol'));
  109. if (isset($options[$ue->status])) {
  110. $mform->addElement('select', 'status', get_string('participationstatus', 'enrol'), $options);
  111. }
  112. $mform->addElement('date_selector', 'timestart', get_string('enroltimestart', 'enrol'), array('optional' => true));
  113. $mform->addElement('date_selector', 'timeend', get_string('enroltimeend', 'enrol'), array('optional' => true));
  114. $mform->addElement('hidden', 'id');
  115. $mform->setType('id', PARAM_INT);
  116. $mform->addElement('hidden', 'ue');
  117. $mform->setType('ue', PARAM_INT);
  118. $mform->addElement('hidden', 'action');
  119. $mform->setType('action', PARAM_ACTION);
  120. $mform->addElement('hidden', 'ifilter');
  121. $mform->setType('ifilter', PARAM_ALPHA);
  122. $mform->addElement('hidden', 'page');
  123. $mform->setType('page', PARAM_INT);
  124. $mform->addElement('hidden', 'perpage');
  125. $mform->setType('perpage', PARAM_INT);
  126. $mform->addElement('hidden', 'sort');
  127. $mform->setType('sort', PARAM_ALPHA);
  128. $mform->addElement('hidden', 'dir');
  129. $mform->setType('dir', PARAM_ALPHA);
  130. $this->add_action_buttons();
  131. $this->set_data(array('action'=>'edit', 'ue'=>$ue->id, 'status'=>$ue->status, 'timestart'=>$ue->timestart, 'timeend'=>$ue->timeend));
  132. }
  133. function validation($data, $files) {
  134. $errors = parent::validation($data, $files);
  135. if (!empty($data['timestart']) and !empty($data['timeend'])) {
  136. if ($data['timestart'] >= $data['timeend']) {
  137. $errors['timestart'] = get_string('error');
  138. $errors['timeend'] = get_string('error');
  139. }
  140. }
  141. return $errors;
  142. }
  143. }