3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
39 class CRM_SMS_Form_Provider
extends CRM_Core_Form
{
40 protected $_id = NULL;
42 function preProcess() {
44 $this->_id
= $this->get('id');
46 $this->setPageTitle(ts('SMS Provider'));
49 $refreshURL = CRM_Utils_System
::url('civicrm/admin/sms/provider',
50 "reset=1&action=update&id={$this->_id}",
55 $refreshURL = CRM_Utils_System
::url('civicrm/admin/sms/provider',
61 $this->assign('refreshURL', $refreshURL);
65 * Function to build the form
70 public function buildQuickForm() {
71 parent
::buildQuickForm();
73 $this->addButtons(array(
76 'name' => $this->_action
& CRM_Core_Action
::DELETE ?
ts('Delete') : ts('Save'),
81 'name' => ts('Cancel'),
86 if ($this->_action
& CRM_Core_Action
::DELETE
) {
90 $attributes = CRM_Core_DAO
::getAttribute('CRM_SMS_DAO_Provider');
92 $providerNames = CRM_Core_OptionGroup
::values('sms_provider_name', FALSE, FALSE, FALSE, NULL, 'label');
93 $apiTypes = CRM_Core_OptionGroup
::values('sms_api_type', FALSE, FALSE, FALSE, NULL, 'label');
95 $this->add('select', 'name', ts('Name'), array('' => '- select -') +
$providerNames, TRUE);
97 $this->add('text', 'title', ts('Title'),
98 $attributes['title'], TRUE
101 $this->addRule('title', ts('This Title already exists in Database.'), 'objectExists', array('CRM_SMS_DAO_Provider', $this->_id
));
103 $this->add('text', 'username', ts('Username'),
104 $attributes['username'], TRUE
107 $this->add('password', 'password', ts('Password'),
108 $attributes['password'], TRUE
111 $this->add('select', 'api_type', ts('API Type'), $apiTypes, TRUE);
113 $this->add('text', 'api_url', ts('API Url'), $attributes['api_url'], TRUE);
115 $this->add('textarea', 'api_params', ts('API Parameters'),
116 "cols=50 rows=6", TRUE
119 $this->add('checkbox', 'is_active', ts('Is this provider active?'));
121 $this->add('checkbox', 'is_default', ts('Is this a default provider?'));
125 * This virtual function is used to set the default values of
126 * various form elements
130 * @return array reference to the array of default values
136 function setDefaultValues() {
139 $name = CRM_Utils_Request
::retrieve('key', 'String', $this, FALSE, NULL);
141 $defaults['name'] = $name;
142 $provider = CRM_SMS_Provider
::singleton(array('provider' => $name));
143 $defaults['api_url'] = $provider->_apiURL
;
147 $defaults['is_active'] = $defaults['is_default'] = 1;
151 $dao = new CRM_SMS_DAO_Provider();
152 $dao->id
= $this->_id
;
157 if (!$dao->find(TRUE)) {
161 CRM_Core_DAO
::storeValues($dao, $defaults);
167 * Function to process the form
173 public function postProcess() {
175 CRM_Utils_System
::flushCache('CRM_SMS_DAO_Provider');
177 if ($this->_action
& CRM_Core_Action
::DELETE
) {
178 CRM_SMS_BAO_Provider
::del($this->_id
);
179 CRM_Core_Session
::setStatus(ts('Selected Provider has been deleted.'), ts('Deleted'), 'success');
183 $recData = $values = $this->controller
->exportValues($this->_name
);
184 $recData['is_active'] = CRM_Utils_Array
::value('is_active', $recData, 0);
185 $recData['is_default'] = CRM_Utils_Array
::value('is_default', $recData, 0);
187 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
188 CRM_SMS_BAO_Provider
::updateRecord($recData, $this->_id
);
190 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
191 CRM_SMS_BAO_Provider
::saveRecord($recData);