| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.5 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
| 7 | +--------------------------------------------------------------------+ |
| 8 | | This file is a part of CiviCRM. | |
| 9 | | | |
| 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. | |
| 13 | | | |
| 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. | |
| 18 | | | |
| 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 | +--------------------------------------------------------------------+ |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * |
| 30 | * @package CRM |
| 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
| 32 | * $Id$ |
| 33 | * |
| 34 | */ |
| 35 | |
| 36 | /** |
| 37 | * customize the output to meet our specific requirements |
| 38 | */ |
| 39 | class CRM_Admin_Form_Persistent extends CRM_Core_Form { |
| 40 | |
| 41 | public function preProcess() { |
| 42 | $this->_indexID = CRM_Utils_Request::retrieve('id', 'Integer', $this, FALSE); |
| 43 | $this->_config = CRM_Utils_Request::retrieve('config', 'Integer', $this, 0); |
| 44 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE); |
| 45 | |
| 46 | $session = CRM_Core_Session::singleton(); |
| 47 | $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/tplstrings', 'reset=1')); |
| 48 | CRM_Utils_System::setTitle(ts('DB Template Strings')); |
| 49 | parent::preProcess(); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @return array |
| 54 | */ |
| 55 | public function setDefaultValues() { |
| 56 | $defaults = array(); |
| 57 | |
| 58 | if ($this->_indexID && ($this->_action & (CRM_Core_Action::UPDATE))) { |
| 59 | $params = array('id' => $this->_indexID); |
| 60 | CRM_Core_BAO_Persistent::retrieve($params, $defaults); |
| 61 | if (CRM_Utils_Array::value('is_config', $defaults) == 1) { |
| 62 | $defaults['data'] = implode(',', $defaults['data']); |
| 63 | } |
| 64 | } |
| 65 | return $defaults; |
| 66 | } |
| 67 | |
| 68 | public function buildQuickForm() { |
| 69 | $this->add('text', 'context', ts('Context:'), NULL, TRUE); |
| 70 | $this->add('text', 'name', ts('Name:'), NULL, TRUE); |
| 71 | $this->add('textarea', 'data', ts('Data:'), array('rows' => 4, 'cols' => 50), TRUE); |
| 72 | $this->addButtons(array( |
| 73 | array( |
| 74 | 'type' => 'submit', |
| 75 | 'name' => ts('Save'), |
| 76 | 'isDefault' => TRUE, |
| 77 | ), |
| 78 | array( |
| 79 | 'type' => 'cancel', |
| 80 | 'name' => ts('Cancel'), |
| 81 | ), |
| 82 | ) |
| 83 | ); |
| 84 | } |
| 85 | |
| 86 | public function postProcess() { |
| 87 | $params = $ids = array(); |
| 88 | $params = $this->controller->exportValues($this->_name); |
| 89 | |
| 90 | $params['is_config'] = $this->_config; |
| 91 | |
| 92 | if ($this->_action & CRM_Core_Action::ADD) { |
| 93 | CRM_Core_Session::setStatus(ts('DB Template has been added successfully.'), ts("Saved"), "success"); |
| 94 | } |
| 95 | if ($this->_action & CRM_Core_Action::UPDATE) { |
| 96 | $ids['persistent'] = $this->_indexID; |
| 97 | CRM_Core_Session::setStatus(ts('DB Template has been updated successfully.'), ts("Saved"), "success"); |
| 98 | } |
| 99 | CRM_Core_BAO_Persistent::add($params, $ids); |
| 100 | |
| 101 | CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/tplstrings', "reset=1")); |
| 102 | } |
| 103 | } |
| 104 | |