PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/local/campusconnect/admin/ecs_form.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 179 lines | 122 code | 36 blank | 21 comment | 13 complexity | aeed074daf387a15bbe45c39f4314a61 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. * ECS settings page for campus connect
  18. *
  19. * @package admin_campusconnect
  20. * @copyright 2012 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. require_once($CFG->dirroot.'/local/campusconnect/ecssettings.php'); // For AUTH_xx definitions
  27. class campusconnect_ecs_form extends moodleform {
  28. public function definition() {
  29. $roles = role_fix_names(get_all_roles(), context_system::instance(), ROLENAME_ORIGINAL);
  30. $allowedroleids = get_roles_for_contextlevels(CONTEXT_COURSE);
  31. $optroles = array();
  32. foreach ($roles as $role) {
  33. if (in_array($role->id, $allowedroleids)) {
  34. $optroles[$role->shortname] = $role->localname;
  35. }
  36. }
  37. $strrequired = get_string('required');
  38. $mform = $this->_form;
  39. $mform->addElement('hidden', 'id', null);
  40. $mform->setType('id', PARAM_INT);
  41. $mform->addElement('header', 'connectionsettings', get_string('connectionsettings', 'local_campusconnect'));
  42. $mform->addElement('selectyesno', 'enabled', get_string('ecsenabled', 'local_campusconnect'));
  43. $mform->addElement('text', 'name', get_string('name', 'local_campusconnect'));
  44. $mform->addRule('name', $strrequired, 'required', null, 'client');
  45. $mform->setType('name', PARAM_TEXT);
  46. $mform->addElement('text', 'url', get_string('url', 'local_campusconnect'), array('size' => 50));
  47. $mform->addRule('url', $strrequired, 'required', null, 'client');
  48. $mform->setType('url', PARAM_TEXT);
  49. $mform->addElement('static', 'urldesc', '', get_string('urldesc', 'local_campusconnect'));
  50. $mform->addElement('select', 'protocol', get_string('protocol', 'local_campusconnect'), array('http'=>'HTTP', 'https'=>'HTTPS'));
  51. $mform->addRule('protocol', $strrequired, 'required', null, 'client');
  52. $mform->addElement('text', 'port', get_string('port', 'local_campusconnect'));
  53. $mform->setType('port', PARAM_INT);
  54. $auth = array(
  55. campusconnect_ecssettings::AUTH_NONE => get_string('directconnection', 'local_campusconnect'),
  56. campusconnect_ecssettings::AUTH_CERTIFICATE => get_string('certificatebase', 'local_campusconnect'),
  57. campusconnect_ecssettings::AUTH_HTTP => get_string('usernamepassword', 'local_campusconnect')
  58. );
  59. $mform->addElement('select', 'auth', get_string('authenticationtype', 'local_campusconnect'), $auth);
  60. $mform->addElement('text', 'certpath', get_string('clientcertificate', 'local_campusconnect'), array('size' => 70));
  61. $mform->disabledIf('certpath', 'auth', 'neq', campusconnect_ecssettings::AUTH_CERTIFICATE);
  62. $mform->setType('certpath', PARAM_PATH);
  63. $mform->addElement('text', 'keypath', get_string('certificatekey', 'local_campusconnect'), array('size' => 70));
  64. $mform->disabledIf('keypath', 'auth', 'neq', campusconnect_ecssettings::AUTH_CERTIFICATE);
  65. $mform->setType('keypath', PARAM_PATH);
  66. $mform->addElement('password', 'keypass', get_string('keypassword', 'local_campusconnect'));
  67. $mform->disabledIf('keypass', 'auth', 'neq', campusconnect_ecssettings::AUTH_CERTIFICATE);
  68. $mform->setType('keypass', PARAM_RAW);
  69. $mform->addElement('text', 'cacertpath', get_string('cacertificate', 'local_campusconnect'), array('size' => 70));
  70. $mform->disabledIf('cacertpath', 'auth', 'neq', campusconnect_ecssettings::AUTH_CERTIFICATE);
  71. $mform->setType('cacertpath', PARAM_PATH);
  72. $mform->addElement('text', 'httpuser', get_string('username', 'local_campusconnect'));
  73. $mform->disabledIf('httpuser', 'auth', 'neq', campusconnect_ecssettings::AUTH_HTTP);
  74. $mform->setType('httpuser', PARAM_TEXT);
  75. $mform->addElement('text', 'httppass', get_string('password', 'local_campusconnect'));
  76. $mform->disabledIf('httppass', 'auth', 'neq', campusconnect_ecssettings::AUTH_HTTP);
  77. $mform->setType('httppass', PARAM_RAW);
  78. $mform->addElement('text', 'ecsauth', get_string('ecsauth', 'local_campusconnect'));
  79. $mform->disabledIf('ecsauth', 'auth', 'neq', campusconnect_ecssettings::AUTH_NONE);
  80. $mform->setType('ecsauth', PARAM_TEXT);
  81. $mform->addElement('header', 'localsettings', get_string('localsettings', 'local_campusconnect'));
  82. $selectarray=array();
  83. $selectarray[] = $mform->createElement('select', 'pollingtimemin', '', range(0, 59));
  84. $selectarray[] = $mform->createElement('static', 'pollingmins', '', get_string('minutes', 'local_campusconnect'));
  85. $selectarray[] = $mform->createElement('select', 'pollingtimesec', '', range(0, 59));
  86. $selectarray[] = $mform->createElement('static', 'pollingsecs', '', get_string('seconds', 'local_campusconnect'));
  87. $mform->addGroup($selectarray, 'pollingtime', get_string('pollingtime', 'local_campusconnect'), array(' '), false);
  88. $mform->addHelpButton('pollingtime', 'pollingtime', 'local_campusconnect');
  89. $mform->addElement('text', 'importcategory', get_string('categoryid', 'local_campusconnect'));
  90. $mform->addElement('static', 'categoryiddesc', '', get_string('categoryiddesc', 'local_campusconnect'));
  91. $mform->addRule('importcategory', $strrequired, 'required', null, 'client');
  92. $mform->setType('importcategory', PARAM_INT);
  93. $mform->addElement('header', 'useraccountsettings', get_string('useraccountsettings', 'local_campusconnect'));
  94. $mform->addElement('select', 'importrole', get_string('roleassignments', 'local_campusconnect'), $optroles);
  95. $mform->setDefault('importrole', 'student');
  96. $mform->addElement('select', 'importperiod', get_string('activationperiod', 'local_campusconnect'), range(0, 36));
  97. $mform->addElement('static', 'activationmonths', '', get_string('months', 'local_campusconnect'));
  98. $mform->setDefault('importperiod', '10');
  99. $mform->addElement('header', 'notifications', get_string('notifications', 'local_campusconnect'));
  100. $mform->addElement('text', 'notifyusers', get_string('notifcationaboutecsusers', 'local_campusconnect'),
  101. array('size' => 50));
  102. $mform->addElement('static', 'usernotdesc', '', get_string('usernotificationdesc', 'local_campusconnect'));
  103. $mform->setType('notifyusers', PARAM_RAW);
  104. $mform->addElement('text', 'notifycontent', get_string('notificationaboutnewecontent', 'local_campusconnect'),
  105. array('size' => 50));
  106. $mform->addElement('static', 'contentnotdesc', '', get_string('contentnotificationdesc', 'local_campusconnect'));
  107. $mform->setType('notifycontent', PARAM_RAW);
  108. $mform->addElement('text', 'notifycourses', get_string('notificationaboutapprovedcourses', 'local_campusconnect'),
  109. array('size' => 50));
  110. $mform->addElement('static', 'coursenotdesc', '', get_string('coursenotificationdesc', 'local_campusconnect'));
  111. $mform->setType('notifycourses', PARAM_RAW);
  112. $this->add_action_buttons();
  113. }
  114. public function validation($data, $files) {
  115. $errors = parent::validation($data, $files);
  116. if ($data['auth'] == campusconnect_ecssettings::AUTH_CERTIFICATE) {
  117. if (empty($data['certpath'])) {
  118. $errors['certpath'] = get_string('required');
  119. }
  120. if (empty($data['keypath'])) {
  121. $errors['keypath'] = get_string('required');
  122. }
  123. if (empty($data['keypass'])) {
  124. $errors['keypass'] = get_string('required');
  125. }
  126. if (empty($data['cacertpath'])) {
  127. $errors['cacertpath'] = get_string('required');
  128. }
  129. }
  130. if ($data['auth'] == campusconnect_ecssettings::AUTH_HTTP) {
  131. if (empty($data['httpuser'])) {
  132. $errors['httpuser'] = get_string('required');
  133. }
  134. if (empty($data['httppass'])) {
  135. $errors['httppass'] = get_string('required');
  136. }
  137. }
  138. if (!is_numeric($data['importcategory'])) {
  139. $errors['importcategory'] = get_string('mustbevalidcategory', 'local_campusconnect');
  140. }
  141. return $errors;
  142. }
  143. }