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 CRM_Utils_System
::setTitle(ts('Manage - SMS Providers'));
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 if ($this->_action
& CRM_Core_Action
::DELETE
) {
74 $this->addButtons(array(
77 'name' => ts('Delete'),
82 'name' => ts('Cancel'),
89 $this->addButtons(array(
97 'name' => ts('Cancel'),
103 $attributes = CRM_Core_DAO
::getAttribute('CRM_SMS_DAO_Provider');
105 $providerNames = CRM_Core_OptionGroup
::values('sms_provider_name', FALSE, FALSE, FALSE, NULL, 'label');
106 $apiTypes = CRM_Core_OptionGroup
::values('sms_api_type', FALSE, FALSE, FALSE, NULL, 'label');
108 $this->add('select', 'name', ts('Name'), array('' => '- select -') +
$providerNames, TRUE, array('onchange' => "reload(true)"));
110 $this->add('text', 'title', ts('Title'),
111 $attributes['title'], TRUE
114 $this->addRule('title', ts('This Title already exists in Database.'), 'objectExists', array('CRM_SMS_DAO_Provider', $this->_id
));
116 $this->add('text', 'username', ts('Username'),
117 $attributes['username'], TRUE
120 $this->add('password', 'password', ts('Password'),
121 $attributes['password'], TRUE
124 $this->add('select', 'api_type', ts('API Type'), $apiTypes, TRUE);
126 $this->add('text', 'api_url', ts('API Url'), $attributes['api_url'], TRUE);
128 $this->add('textarea', 'api_params', ts('API Parameters'),
129 "cols=50 rows=6", TRUE
132 $this->add('checkbox', 'is_active', ts('Is this provider active?'));
134 $this->add('checkbox', 'is_default', ts('Is this a default provider?'));
138 * This virtual function is used to set the default values of
139 * various form elements
143 * @return array reference to the array of default values
149 function setDefaultValues() {
152 $name = CRM_Utils_Request
::retrieve('key', 'String', $this, FALSE, NULL);
154 $defaults['name'] = $name;
155 $provider = CRM_SMS_Provider
::singleton(array('provider' => $name));
156 $defaults['api_url'] = $provider->_apiURL
;
160 $defaults['is_active'] = $defaults['is_default'] = 1;
164 $dao = new CRM_SMS_DAO_Provider();
165 $dao->id
= $this->_id
;
170 if (!$dao->find(TRUE)) {
174 CRM_Core_DAO
::storeValues($dao, $defaults);
180 * Function to process the form
186 public function postProcess() {
188 CRM_Utils_System
::flushCache('CRM_SMS_DAO_Provider');
190 if ($this->_action
& CRM_Core_Action
::DELETE
) {
191 CRM_SMS_BAO_Provider
::del($this->_id
);
192 CRM_Core_Session
::setStatus(ts('Selected Provider has been deleted.'), ts('Deleted'), 'success');
196 $recData = $values = $this->controller
->exportValues($this->_name
);
197 $recData['is_active'] = CRM_Utils_Array
::value('is_active', $recData, 0);
198 $recData['is_default'] = CRM_Utils_Array
::value('is_default', $recData, 0);
200 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
201 CRM_SMS_BAO_Provider
::updateRecord($recData, $this->_id
);
203 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
204 CRM_SMS_BAO_Provider
::saveRecord($recData);