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;
27 public $submitOnce = TRUE;
29 public function preProcess() {
31 $this->_id
= $this->get('id');
33 $this->setPageTitle(ts('SMS Provider'));
36 $refreshURL = CRM_Utils_System
::url('civicrm/admin/sms/provider',
37 "reset=1&action=update&id={$this->_id}",
42 $refreshURL = CRM_Utils_System
::url('civicrm/admin/sms/provider',
48 $this->assign('refreshURL', $refreshURL);
52 * Build the form object.
54 public function buildQuickForm() {
55 parent
::buildQuickForm();
60 'name' => $this->_action
& CRM_Core_Action
::DELETE ?
ts('Delete') : ts('Save'),
65 'name' => ts('Cancel'),
69 if ($this->_action
& CRM_Core_Action
::DELETE
) {
73 $attributes = CRM_Core_DAO
::getAttribute('CRM_SMS_DAO_Provider');
75 $providerNames = CRM_Core_OptionGroup
::values('sms_provider_name', FALSE, FALSE, FALSE, NULL, 'label');
76 $apiTypes = CRM_Core_OptionGroup
::values('sms_api_type', FALSE, FALSE, FALSE, NULL, 'label');
78 $this->add('select', 'name', ts('Name'), $providerNames, TRUE, ['placeholder' => TRUE]);
80 $this->add('text', 'title', ts('Title'),
81 $attributes['title'], TRUE
84 $this->addRule('title', ts('This Title already exists in Database.'), 'objectExists', [
85 'CRM_SMS_DAO_Provider',
89 $this->add('text', 'username', ts('Username'),
90 $attributes['username'], TRUE
93 $this->add('password', 'password', ts('Password'),
94 $attributes['password'], TRUE
97 $this->add('select', 'api_type', ts('API Type'), $apiTypes, TRUE);
99 $this->add('text', 'api_url', ts('API Url'), $attributes['api_url'], TRUE);
101 $this->add('textarea', 'api_params', ts('API Parameters'),
102 ['cols' => 50, 'rows' => 6], TRUE
105 $this->add('checkbox', 'is_active', ts('Is this provider active?'));
107 $this->add('checkbox', 'is_default', ts('Is this a default provider?'));
111 * Set the default values of various form elements.
115 public function setDefaultValues() {
118 $name = CRM_Utils_Request
::retrieve('key', 'String', $this, FALSE, NULL);
120 $defaults['name'] = $name;
121 $provider = CRM_SMS_Provider
::singleton(['provider' => $name]);
122 $defaults['api_url'] = $provider->_apiURL ??
'';
126 $defaults['is_active'] = $defaults['is_default'] = 1;
130 $dao = new CRM_SMS_DAO_Provider();
131 $dao->id
= $this->_id
;
137 if (!$dao->find(TRUE)) {
141 CRM_Core_DAO
::storeValues($dao, $defaults);
147 * Process the form submission.
149 public function postProcess() {
151 CRM_Utils_System
::flushCache();
153 if ($this->_action
& CRM_Core_Action
::DELETE
) {
154 CRM_SMS_BAO_Provider
::del($this->_id
);
155 CRM_Core_Session
::setStatus(ts('Selected Provider has been deleted.'), ts('Deleted'), 'success');
159 $recData = $values = $this->controller
->exportValues($this->_name
);
160 $recData['is_active'] = CRM_Utils_Array
::value('is_active', $recData, 0);
161 $recData['is_default'] = CRM_Utils_Array
::value('is_default', $recData, 0);
163 if ($this->_action
&& (CRM_Core_Action
::UPDATE || CRM_Core_Action
::ADD
)) {
165 $recData['id'] = $this->_id
;
167 civicrm_api3('SmsProvider', 'create', $recData);