3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
39 class CRM_SMS_Form_Provider
extends CRM_Core_Form
{
40 protected $_id = NULL; function preProcess() {
42 $this->_id
= $this->get('id');
44 CRM_Utils_System
::setTitle(ts('Manage - SMS Providers'));
47 $refreshURL = CRM_Utils_System
::url('civicrm/admin/sms/provider',
48 "reset=1&action=update&id={$this->_id}",
53 $refreshURL = CRM_Utils_System
::url('civicrm/admin/sms/provider',
59 $this->assign('refreshURL', $refreshURL);
63 * Function to build the form
68 public function buildQuickForm() {
69 parent
::buildQuickForm();
71 if ($this->_action
& CRM_Core_Action
::DELETE
) {
72 $this->addButtons(array(
75 'name' => ts('Delete'),
80 'name' => ts('Cancel'),
87 $this->addButtons(array(
95 'name' => ts('Cancel'),
101 $attributes = CRM_Core_DAO
::getAttribute('CRM_SMS_DAO_Provider');
103 $providerNames = CRM_Core_OptionGroup
::values('sms_provider_name', FALSE, FALSE, FALSE, NULL, 'label');
104 $apiTypes = CRM_Core_OptionGroup
::values('sms_api_type', FALSE, FALSE, FALSE, NULL, 'label');
106 $this->add('select', 'name', ts('Name'), array('' => '- select -') +
$providerNames, TRUE, array('onchange' => "reload(true)"));
108 $this->add('text', 'title', ts('Title'),
109 $attributes['title'], TRUE
112 $this->addRule('title', ts('This Title already exists in Database.'), 'objectExists', array('CRM_SMS_DAO_Provider', $this->_id
));
114 $this->add('text', 'username', ts('Username'),
115 $attributes['username'], TRUE
118 $this->add('password', 'password', ts('Password'),
119 $attributes['password'], TRUE
122 $this->add('select', 'api_type', ts('API Type'), $apiTypes, TRUE);
124 $this->add('text', 'api_url', ts('API Url'), $attributes['api_url'], TRUE);
126 $this->add('textarea', 'api_params', ts('API Parameters'),
127 "cols=50 rows=6", TRUE
130 $this->add('checkbox', 'is_active', ts('Is this provider active?'));
132 $this->add('checkbox', 'is_default', ts('Is this a default provider?'));
135 function setDefaultValues() {
138 $name = CRM_Utils_Request
::retrieve('key', 'String', $this, FALSE, NULL);
140 $defaults['name'] = $name;
141 $provider = CRM_SMS_Provider
::singleton(array('provider' => $name));
142 $defaults['api_url'] = $provider->_apiURL
;
146 $defaults['is_active'] = $defaults['is_default'] = 1;
150 $dao = new CRM_SMS_DAO_Provider();
151 $dao->id
= $this->_id
;
156 if (!$dao->find(TRUE)) {
160 CRM_Core_DAO
::storeValues($dao, $defaults);
166 * Function to process the form
172 public function postProcess() {
174 CRM_Utils_System
::flushCache('CRM_SMS_DAO_Provider');
176 if ($this->_action
& CRM_Core_Action
::DELETE
) {
177 CRM_SMS_BAO_Provider
::del($this->_id
);
178 CRM_Core_Session
::setStatus(ts('Selected Provider has been deleted.'), ts('Deleted'), 'success');
182 $recData = $values = $this->controller
->exportValues($this->_name
);
183 $recData['is_active'] = CRM_Utils_Array
::value('is_active', $recData, 0);
184 $recData['is_default'] = CRM_Utils_Array
::value('is_default', $recData, 0);
186 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
187 CRM_SMS_BAO_Provider
::updateRecord($recData, $this->_id
);
189 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
190 CRM_SMS_BAO_Provider
::saveRecord($recData);