3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
21 class CRM_SMS_Form_Provider
extends CRM_Core_Form
{
22 protected $_id = NULL;
24 public function preProcess() {
26 $this->_id
= $this->get('id');
28 $this->setPageTitle(ts('SMS Provider'));
31 $refreshURL = CRM_Utils_System
::url('civicrm/admin/sms/provider',
32 "reset=1&action=update&id={$this->_id}",
37 $refreshURL = CRM_Utils_System
::url('civicrm/admin/sms/provider',
43 $this->assign('refreshURL', $refreshURL);
47 * Build the form object.
49 public function buildQuickForm() {
50 parent
::buildQuickForm();
55 'name' => $this->_action
& CRM_Core_Action
::DELETE ?
ts('Delete') : ts('Save'),
60 'name' => ts('Cancel'),
64 if ($this->_action
& CRM_Core_Action
::DELETE
) {
68 $attributes = CRM_Core_DAO
::getAttribute('CRM_SMS_DAO_Provider');
70 $providerNames = CRM_Core_OptionGroup
::values('sms_provider_name', FALSE, FALSE, FALSE, NULL, 'label');
71 $apiTypes = CRM_Core_OptionGroup
::values('sms_api_type', FALSE, FALSE, FALSE, NULL, 'label');
73 $this->add('select', 'name', ts('Name'), $providerNames, TRUE, ['placeholder' => TRUE]);
75 $this->add('text', 'title', ts('Title'),
76 $attributes['title'], TRUE
79 $this->addRule('title', ts('This Title already exists in Database.'), 'objectExists', [
80 'CRM_SMS_DAO_Provider',
84 $this->add('text', 'username', ts('Username'),
85 $attributes['username'], TRUE
88 $this->add('password', 'password', ts('Password'),
89 $attributes['password'], TRUE
92 $this->add('select', 'api_type', ts('API Type'), $apiTypes, TRUE);
94 $this->add('text', 'api_url', ts('API Url'), $attributes['api_url'], TRUE);
96 $this->add('textarea', 'api_params', ts('API Parameters'),
97 ['cols' => 50, 'rows' => 6], TRUE
100 $this->add('checkbox', 'is_active', ts('Is this provider active?'));
102 $this->add('checkbox', 'is_default', ts('Is this a default provider?'));
106 * Set the default values of various form elements.
110 public function setDefaultValues() {
113 $name = CRM_Utils_Request
::retrieve('key', 'String', $this, FALSE, NULL);
115 $defaults['name'] = $name;
116 $provider = CRM_SMS_Provider
::singleton(['provider' => $name]);
117 $defaults['api_url'] = $provider->_apiURL ??
'';
121 $defaults['is_active'] = $defaults['is_default'] = 1;
125 $dao = new CRM_SMS_DAO_Provider();
126 $dao->id
= $this->_id
;
132 if (!$dao->find(TRUE)) {
136 CRM_Core_DAO
::storeValues($dao, $defaults);
142 * Process the form submission.
144 public function postProcess() {
146 CRM_Utils_System
::flushCache();
148 if ($this->_action
& CRM_Core_Action
::DELETE
) {
149 CRM_SMS_BAO_Provider
::del($this->_id
);
150 CRM_Core_Session
::setStatus(ts('Selected Provider has been deleted.'), ts('Deleted'), 'success');
154 $recData = $values = $this->controller
->exportValues($this->_name
);
155 $recData['is_active'] = CRM_Utils_Array
::value('is_active', $recData, 0);
156 $recData['is_default'] = CRM_Utils_Array
::value('is_default', $recData, 0);
158 if ($this->_action
&& (CRM_Core_Action
::UPDATE || CRM_Core_Action
::ADD
)) {
160 $recData['id'] = $this->_id
;
162 civicrm_api3('SmsProvider', 'create', $recData);