Merge pull request #2225 from lcdservices/CRM-13994
[civicrm-core.git] / CRM / Admin / Form.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
32 * $Id$
33 *
34 */
35
36 /**
37 * Base class for admin forms
38 */
39 class CRM_Admin_Form extends CRM_Core_Form {
40
41 /**
42 * The id of the object being edited / created
43 *
44 * @var int
45 */
46 protected $_id;
47
48 /**
49 * The default values for form fields
50 *
51 * @var int
52 */
53 protected $_values;
54
55 /**
56 * The name of the BAO object for this form
57 *
58 * @var string
59 */
60 protected $_BAOName;
61
62 function preProcess() {
63 $this->_id = $this->get('id');
64 $this->_BAOName = $this->get('BAOName');
65 $this->_values = array();
66 if (isset($this->_id)) {
67 $params = array('id' => $this->_id);
68 // this is needed if the form is outside the CRM name space
69 $baoName = $this->_BAOName;
70 $baoName::retrieve($params, $this->_values );
71 }
72 }
73
74 /**
75 * This function sets the default values for the form. MobileProvider that in edit/view mode
76 * the default values are retrieved from the database
77 *
78 * @access public
79 *
80 * @return None
81 */
82 function setDefaultValues() {
83 if (isset($this->_id) && empty($this->_values)) {
84 $this->_values = array();
85 $params = array('id' => $this->_id);
86 $baoName = $this->_BAOName;
87 $baoName::retrieve($params, $this->_values );
88 }
89 $defaults = $this->_values;
90
91 if ($this->_action == CRM_Core_Action::DELETE &&
92 isset($defaults['name'])
93 ) {
94 $this->assign('delName', $defaults['name']);
95 }
96
97 // its ok if there is no element called is_active
98 $defaults['is_active'] = ($this->_id) ? CRM_Utils_Array::value('is_active', $defaults) : 1;
99 if (CRM_Utils_Array::value('parent_id', $defaults)) {
100 $this->assign('is_parent', TRUE);
101 }
102 return $defaults;
103 }
104
105 /**
106 * Function to actually build the form
107 *
108 * @return None
109 * @access public
110 */
111 public function buildQuickForm() {
112 if ($this->_action & CRM_Core_Action::DELETE) {
113 $this->addButtons(array(
114 array(
115 'type' => 'next',
116 'name' => ts('Delete'),
117 'isDefault' => TRUE,
118 ),
119 array(
120 'type' => 'cancel',
121 'name' => ts('Cancel'),
122 ),
123 )
124 );
125 }
126 else {
127 $this->addButtons(array(
128 array(
129 'type' => 'next',
130 'name' => ts('Save'),
131 'isDefault' => TRUE,
132 ),
133 array(
134 'type' => 'cancel',
135 'name' => ts('Cancel'),
136 ),
137 )
138 );
139 }
140 }
141 }
142