3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
38 class CRM_SMS_Form_Provider
extends CRM_Core_Form
{
39 protected $_id = NULL;
41 public function preProcess() {
43 $this->_id
= $this->get('id');
45 $this->setPageTitle(ts('SMS Provider'));
48 $refreshURL = CRM_Utils_System
::url('civicrm/admin/sms/provider',
49 "reset=1&action=update&id={$this->_id}",
54 $refreshURL = CRM_Utils_System
::url('civicrm/admin/sms/provider',
60 $this->assign('refreshURL', $refreshURL);
64 * Build the form object.
66 public function buildQuickForm() {
67 parent
::buildQuickForm();
69 $this->addButtons(array(
72 'name' => $this->_action
& CRM_Core_Action
::DELETE ?
ts('Delete') : ts('Save'),
77 'name' => ts('Cancel'),
82 if ($this->_action
& CRM_Core_Action
::DELETE
) {
86 $attributes = CRM_Core_DAO
::getAttribute('CRM_SMS_DAO_Provider');
88 $providerNames = CRM_Core_OptionGroup
::values('sms_provider_name', FALSE, FALSE, FALSE, NULL, 'label');
89 $apiTypes = CRM_Core_OptionGroup
::values('sms_api_type', FALSE, FALSE, FALSE, NULL, 'label');
91 $this->add('select', 'name', ts('Name'), array('' => '- select -') +
$providerNames, TRUE);
93 $this->add('text', 'title', ts('Title'),
94 $attributes['title'], TRUE
97 $this->addRule('title', ts('This Title already exists in Database.'), 'objectExists', array(
98 'CRM_SMS_DAO_Provider',
102 $this->add('text', 'username', ts('Username'),
103 $attributes['username'], TRUE
106 $this->add('password', 'password', ts('Password'),
107 $attributes['password'], TRUE
110 $this->add('select', 'api_type', ts('API Type'), $apiTypes, TRUE);
112 $this->add('text', 'api_url', ts('API Url'), $attributes['api_url'], TRUE);
114 $this->add('textarea', 'api_params', ts('API Parameters'),
115 "cols=50 rows=6", TRUE
118 $this->add('checkbox', 'is_active', ts('Is this provider active?'));
120 $this->add('checkbox', 'is_default', ts('Is this a default provider?'));
124 * Set the default values of various form elements.
128 public function setDefaultValues() {
131 $name = CRM_Utils_Request
::retrieve('key', 'String', $this, FALSE, NULL);
133 $defaults['name'] = $name;
134 $provider = CRM_SMS_Provider
::singleton(array('provider' => $name));
135 $defaults['api_url'] = $provider->_apiURL
;
139 $defaults['is_active'] = $defaults['is_default'] = 1;
143 $dao = new CRM_SMS_DAO_Provider();
144 $dao->id
= $this->_id
;
150 if (!$dao->find(TRUE)) {
154 CRM_Core_DAO
::storeValues($dao, $defaults);
160 * Process the form submission.
162 public function postProcess() {
164 CRM_Utils_System
::flushCache('CRM_SMS_DAO_Provider');
166 if ($this->_action
& CRM_Core_Action
::DELETE
) {
167 CRM_SMS_BAO_Provider
::del($this->_id
);
168 CRM_Core_Session
::setStatus(ts('Selected Provider has been deleted.'), ts('Deleted'), 'success');
172 $recData = $values = $this->controller
->exportValues($this->_name
);
173 $recData['is_active'] = CRM_Utils_Array
::value('is_active', $recData, 0);
174 $recData['is_default'] = CRM_Utils_Array
::value('is_default', $recData, 0);
176 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
177 CRM_SMS_BAO_Provider
::updateRecord($recData, $this->_id
);
179 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
180 CRM_SMS_BAO_Provider
::saveRecord($recData);