3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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-2016
37 class CRM_SMS_Form_Provider
extends CRM_Core_Form
{
38 protected $_id = NULL;
40 public function preProcess() {
42 $this->_id
= $this->get('id');
44 $this->setPageTitle(ts('SMS Provider'));
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 * Build the form object.
65 public function buildQuickForm() {
66 parent
::buildQuickForm();
68 $this->addButtons(array(
71 'name' => $this->_action
& CRM_Core_Action
::DELETE ?
ts('Delete') : ts('Save'),
76 'name' => ts('Cancel'),
80 if ($this->_action
& CRM_Core_Action
::DELETE
) {
84 $attributes = CRM_Core_DAO
::getAttribute('CRM_SMS_DAO_Provider');
86 $providerNames = CRM_Core_OptionGroup
::values('sms_provider_name', FALSE, FALSE, FALSE, NULL, 'label');
87 $apiTypes = CRM_Core_OptionGroup
::values('sms_api_type', FALSE, FALSE, FALSE, NULL, 'label');
89 $this->add('select', 'name', ts('Name'), array('' => '- select -') +
$providerNames, TRUE);
91 $this->add('text', 'title', ts('Title'),
92 $attributes['title'], TRUE
95 $this->addRule('title', ts('This Title already exists in Database.'), 'objectExists', array(
96 'CRM_SMS_DAO_Provider',
100 $this->add('text', 'username', ts('Username'),
101 $attributes['username'], TRUE
104 $this->add('password', 'password', ts('Password'),
105 $attributes['password'], TRUE
108 $this->add('select', 'api_type', ts('API Type'), $apiTypes, TRUE);
110 $this->add('text', 'api_url', ts('API Url'), $attributes['api_url'], TRUE);
112 $this->add('textarea', 'api_params', ts('API Parameters'),
113 "cols=50 rows=6", TRUE
116 $this->add('checkbox', 'is_active', ts('Is this provider active?'));
118 $this->add('checkbox', 'is_default', ts('Is this a default provider?'));
122 * Set the default values of various form elements.
126 public function setDefaultValues() {
129 $name = CRM_Utils_Request
::retrieve('key', 'String', $this, FALSE, NULL);
131 $defaults['name'] = $name;
132 $provider = CRM_SMS_Provider
::singleton(array('provider' => $name));
133 $defaults['api_url'] = $provider->_apiURL
;
137 $defaults['is_active'] = $defaults['is_default'] = 1;
141 $dao = new CRM_SMS_DAO_Provider();
142 $dao->id
= $this->_id
;
148 if (!$dao->find(TRUE)) {
152 CRM_Core_DAO
::storeValues($dao, $defaults);
158 * Process the form submission.
160 public function postProcess() {
162 CRM_Utils_System
::flushCache('CRM_SMS_DAO_Provider');
164 if ($this->_action
& CRM_Core_Action
::DELETE
) {
165 CRM_SMS_BAO_Provider
::del($this->_id
);
166 CRM_Core_Session
::setStatus(ts('Selected Provider has been deleted.'), ts('Deleted'), 'success');
170 $recData = $values = $this->controller
->exportValues($this->_name
);
171 $recData['is_active'] = CRM_Utils_Array
::value('is_active', $recData, 0);
172 $recData['is_default'] = CRM_Utils_Array
::value('is_default', $recData, 0);
174 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
175 CRM_SMS_BAO_Provider
::updateRecord($recData, $this->_id
);
177 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
178 CRM_SMS_BAO_Provider
::saveRecord($recData);