campusconnect /local/campusconnect/admin/ecs_form.php

Language PHP Lines 180
MD5 Hash aeed074daf387a15bbe45c39f4314a61 Estimated Cost $2,941 (why?)
Repository https://bitbucket.org/synergylearning/campusconnect.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * ECS settings page for campus connect
 *
 * @package    admin_campusconnect
 * @copyright  2012 Synergy Learning
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

defined('MOODLE_INTERNAL') || die();

global $CFG;

require_once($CFG->libdir."/formslib.php");
require_once($CFG->dirroot.'/local/campusconnect/ecssettings.php'); // For AUTH_xx definitions

class campusconnect_ecs_form extends moodleform {

    public function definition() {

        $roles = role_fix_names(get_all_roles(), context_system::instance(), ROLENAME_ORIGINAL);
        $allowedroleids = get_roles_for_contextlevels(CONTEXT_COURSE);
        $optroles = array();
        foreach ($roles as $role) {
            if (in_array($role->id, $allowedroleids)) {
                $optroles[$role->shortname] = $role->localname;
            }
        }

        $strrequired = get_string('required');

        $mform = $this->_form;

        $mform->addElement('hidden', 'id', null);
        $mform->setType('id', PARAM_INT);

        $mform->addElement('header', 'connectionsettings', get_string('connectionsettings', 'local_campusconnect'));

        $mform->addElement('selectyesno', 'enabled', get_string('ecsenabled', 'local_campusconnect'));
        $mform->addElement('text', 'name', get_string('name', 'local_campusconnect'));
        $mform->addRule('name', $strrequired, 'required', null, 'client');
        $mform->setType('name', PARAM_TEXT);

        $mform->addElement('text', 'url', get_string('url', 'local_campusconnect'), array('size' => 50));
        $mform->addRule('url', $strrequired, 'required', null, 'client');
        $mform->setType('url', PARAM_TEXT);
        $mform->addElement('static', 'urldesc', '', get_string('urldesc', 'local_campusconnect'));

        $mform->addElement('select', 'protocol', get_string('protocol', 'local_campusconnect'), array('http'=>'HTTP', 'https'=>'HTTPS'));
        $mform->addRule('protocol', $strrequired, 'required', null, 'client');

        $mform->addElement('text', 'port', get_string('port', 'local_campusconnect'));
        $mform->setType('port', PARAM_INT);

        $auth = array(
            campusconnect_ecssettings::AUTH_NONE => get_string('directconnection', 'local_campusconnect'),
            campusconnect_ecssettings::AUTH_CERTIFICATE => get_string('certificatebase', 'local_campusconnect'),
            campusconnect_ecssettings::AUTH_HTTP => get_string('usernamepassword', 'local_campusconnect')
        );
        $mform->addElement('select', 'auth', get_string('authenticationtype', 'local_campusconnect'),  $auth);

        $mform->addElement('text', 'certpath', get_string('clientcertificate', 'local_campusconnect'), array('size' => 70));
        $mform->disabledIf('certpath', 'auth', 'neq', campusconnect_ecssettings::AUTH_CERTIFICATE);
        $mform->setType('certpath', PARAM_PATH);

        $mform->addElement('text', 'keypath', get_string('certificatekey', 'local_campusconnect'), array('size' => 70));
        $mform->disabledIf('keypath', 'auth', 'neq', campusconnect_ecssettings::AUTH_CERTIFICATE);
        $mform->setType('keypath', PARAM_PATH);

        $mform->addElement('password', 'keypass', get_string('keypassword', 'local_campusconnect'));
        $mform->disabledIf('keypass', 'auth', 'neq', campusconnect_ecssettings::AUTH_CERTIFICATE);
        $mform->setType('keypass', PARAM_RAW);

        $mform->addElement('text', 'cacertpath', get_string('cacertificate', 'local_campusconnect'), array('size' => 70));
        $mform->disabledIf('cacertpath', 'auth', 'neq', campusconnect_ecssettings::AUTH_CERTIFICATE);
        $mform->setType('cacertpath', PARAM_PATH);

        $mform->addElement('text', 'httpuser', get_string('username', 'local_campusconnect'));
        $mform->disabledIf('httpuser', 'auth', 'neq', campusconnect_ecssettings::AUTH_HTTP);
        $mform->setType('httpuser', PARAM_TEXT);

        $mform->addElement('text', 'httppass', get_string('password', 'local_campusconnect'));
        $mform->disabledIf('httppass', 'auth', 'neq', campusconnect_ecssettings::AUTH_HTTP);
        $mform->setType('httppass', PARAM_RAW);

        $mform->addElement('text', 'ecsauth', get_string('ecsauth', 'local_campusconnect'));
        $mform->disabledIf('ecsauth', 'auth', 'neq', campusconnect_ecssettings::AUTH_NONE);
        $mform->setType('ecsauth', PARAM_TEXT);

        $mform->addElement('header', 'localsettings', get_string('localsettings', 'local_campusconnect'));

        $selectarray=array();
        $selectarray[] = $mform->createElement('select', 'pollingtimemin', '', range(0, 59));
        $selectarray[] = $mform->createElement('static', 'pollingmins', '', get_string('minutes', 'local_campusconnect'));
        $selectarray[] = $mform->createElement('select', 'pollingtimesec', '', range(0, 59));
        $selectarray[] = $mform->createElement('static', 'pollingsecs', '', get_string('seconds', 'local_campusconnect'));
        $mform->addGroup($selectarray, 'pollingtime', get_string('pollingtime', 'local_campusconnect'), array(' '), false);
        $mform->addHelpButton('pollingtime', 'pollingtime', 'local_campusconnect');

        $mform->addElement('text', 'importcategory', get_string('categoryid', 'local_campusconnect'));
        $mform->addElement('static', 'categoryiddesc', '', get_string('categoryiddesc', 'local_campusconnect'));
        $mform->addRule('importcategory', $strrequired, 'required', null, 'client');
        $mform->setType('importcategory', PARAM_INT);

        $mform->addElement('header', 'useraccountsettings', get_string('useraccountsettings', 'local_campusconnect'));

        $mform->addElement('select', 'importrole', get_string('roleassignments', 'local_campusconnect'), $optroles);
        $mform->setDefault('importrole', 'student');
        $mform->addElement('select', 'importperiod', get_string('activationperiod', 'local_campusconnect'), range(0, 36));
        $mform->addElement('static', 'activationmonths', '', get_string('months', 'local_campusconnect'));
        $mform->setDefault('importperiod', '10');

        $mform->addElement('header', 'notifications', get_string('notifications', 'local_campusconnect'));

        $mform->addElement('text', 'notifyusers', get_string('notifcationaboutecsusers', 'local_campusconnect'),
                           array('size' => 50));
        $mform->addElement('static', 'usernotdesc', '', get_string('usernotificationdesc', 'local_campusconnect'));
        $mform->setType('notifyusers', PARAM_RAW);

        $mform->addElement('text', 'notifycontent', get_string('notificationaboutnewecontent', 'local_campusconnect'),
                           array('size' => 50));
        $mform->addElement('static', 'contentnotdesc', '', get_string('contentnotificationdesc', 'local_campusconnect'));
        $mform->setType('notifycontent', PARAM_RAW);

        $mform->addElement('text', 'notifycourses', get_string('notificationaboutapprovedcourses', 'local_campusconnect'),
                           array('size' => 50));
        $mform->addElement('static', 'coursenotdesc', '', get_string('coursenotificationdesc', 'local_campusconnect'));
        $mform->setType('notifycourses', PARAM_RAW);

        $this->add_action_buttons();
    }

    public function validation($data, $files) {
        $errors = parent::validation($data, $files);
        if ($data['auth'] == campusconnect_ecssettings::AUTH_CERTIFICATE) {
            if (empty($data['certpath'])) {
                $errors['certpath'] = get_string('required');
            }
            if (empty($data['keypath'])) {
                $errors['keypath'] = get_string('required');
            }
            if (empty($data['keypass'])) {
                $errors['keypass'] = get_string('required');
            }
            if (empty($data['cacertpath'])) {
                $errors['cacertpath'] = get_string('required');
            }
        }
        if ($data['auth'] == campusconnect_ecssettings::AUTH_HTTP) {
            if (empty($data['httpuser'])) {
                $errors['httpuser'] = get_string('required');
            }
            if (empty($data['httppass'])) {
                $errors['httppass'] = get_string('required');
            }
        }

        if (!is_numeric($data['importcategory'])) {
            $errors['importcategory'] = get_string('mustbevalidcategory', 'local_campusconnect');
        }

        return $errors;
    }
}
Back to Top