1441 |
ariadna |
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 |
namespace core_sms\form;
|
|
|
18 |
|
|
|
19 |
use moodleform;
|
|
|
20 |
|
|
|
21 |
defined('MOODLE_INTERNAL') || die();
|
|
|
22 |
|
|
|
23 |
require_once($CFG->libdir . '/formslib.php');
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* SMS gateway instance form.
|
|
|
27 |
*
|
|
|
28 |
* @package core_sms
|
|
|
29 |
* @copyright 2024 Safat Shahin <safat.shahin@moodle.com>
|
|
|
30 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
31 |
*/
|
|
|
32 |
class sms_gateway_form extends moodleform {
|
|
|
33 |
|
|
|
34 |
protected function definition() {
|
|
|
35 |
global $PAGE;
|
|
|
36 |
$PAGE->requires->js_call_amd('core_sms/smsgatewaychooser', 'init');
|
|
|
37 |
|
|
|
38 |
$mform = $this->_form;
|
|
|
39 |
$gatewayconfigs = $this->_customdata['gatewayconfigs'] ?? [];
|
|
|
40 |
$returnurl = $this->_customdata['returnurl'] ?? null;
|
|
|
41 |
|
|
|
42 |
$smsplugins = [];
|
|
|
43 |
$smsgatewayplugins = \core\plugininfo\smsgateway::get_enabled_plugins();
|
|
|
44 |
foreach ($smsgatewayplugins as $pluginname => $notusing) {
|
|
|
45 |
$plugin = 'smsgateway_' . $pluginname;
|
|
|
46 |
$smsplugins[$plugin] = get_string('pluginname', $plugin);
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
$mform->addElement(
|
|
|
50 |
'select',
|
|
|
51 |
'smsgateway',
|
|
|
52 |
get_string('select_sms_gateways', 'sms'),
|
|
|
53 |
$smsplugins,
|
|
|
54 |
['data-smsgatewaychooser-field' => 'selector'],
|
|
|
55 |
);
|
|
|
56 |
$mform->setDefault('smsgateway', 'smsgateway_aws');
|
|
|
57 |
if (isset($gatewayconfigs->id)) {
|
|
|
58 |
$mform->hardFreeze('smsgateway');
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
$mform->addElement(
|
|
|
62 |
'text',
|
|
|
63 |
'name',
|
|
|
64 |
get_string('gateway_name', 'sms'),
|
|
|
65 |
'maxlength="255" size="20"',
|
|
|
66 |
);
|
|
|
67 |
$mform->setType('name', PARAM_TEXT);
|
|
|
68 |
$mform->addRule('name', get_string('required'), 'required', null, 'client');
|
|
|
69 |
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255);
|
|
|
70 |
|
|
|
71 |
$mform->addElement(
|
|
|
72 |
'text',
|
|
|
73 |
'countrycode',
|
|
|
74 |
get_string('countrycode', 'sms'),
|
|
|
75 |
'maxlength="255" size="20"',
|
|
|
76 |
);
|
|
|
77 |
$mform->setType('countrycode', PARAM_TEXT);
|
|
|
78 |
$mform->setDefault(
|
|
|
79 |
elementName: 'countrycode',
|
|
|
80 |
defaultValue: 0,
|
|
|
81 |
);
|
|
|
82 |
|
|
|
83 |
$mform->addElement('static', 'information', ' ', get_string('countrycode_help', 'core_sms'));
|
|
|
84 |
|
|
|
85 |
$mform->registerNoSubmitButton('updatesmsgateway');
|
|
|
86 |
$mform->addElement(
|
|
|
87 |
'submit',
|
|
|
88 |
'updatesmsgateway',
|
|
|
89 |
'update sms gateway',
|
|
|
90 |
['data-smsgatewaychooser-field' => 'updateButton', 'class' => 'd-none']
|
|
|
91 |
);
|
|
|
92 |
|
|
|
93 |
// Dispatch a hook for plugins to add their fields.
|
|
|
94 |
$hook = new \core_sms\hook\after_sms_gateway_form_hook(
|
|
|
95 |
mform: $mform,
|
|
|
96 |
plugin: $gatewayconfigs->smsgateway ?? 'smsgateway_aws',
|
|
|
97 |
);
|
|
|
98 |
\core\di::get(\core\hook\manager::class)->dispatch($hook);
|
|
|
99 |
|
|
|
100 |
// Form buttons.
|
|
|
101 |
$buttonarray = [];
|
|
|
102 |
$buttonarray[] = $mform->createElement('submit', 'saveandreturn', get_string('savechanges'));
|
|
|
103 |
$buttonarray[] = $mform->createElement('cancel');
|
|
|
104 |
$mform->addGroup($buttonarray, 'buttonar', '', [' '], false);
|
|
|
105 |
$mform->closeHeaderBefore('buttonar');
|
|
|
106 |
|
|
|
107 |
if ($returnurl) {
|
|
|
108 |
$mform->addElement('hidden', 'returnurl', $returnurl);
|
|
|
109 |
$mform->setType('returnurl', PARAM_LOCALURL);
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
if (isset($gatewayconfigs->id)) {
|
|
|
113 |
$mform->addElement('hidden', 'id', $gatewayconfigs->id);
|
|
|
114 |
$mform->setType('id', PARAM_INT);
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
$this->set_data($gatewayconfigs);
|
|
|
118 |
}
|
|
|
119 |
}
|