Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-02-18-07-54-54
[civicrm-core.git] / CRM / Admin / Form.php
... / ...
CommitLineData
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 */
39class 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 /**
63 * Basic setup
64 */
65 function preProcess() {
66 $this->_id = $this->get('id');
67 $this->_BAOName = $this->get('BAOName');
68 $this->_values = array();
69 if (isset($this->_id)) {
70 $params = array('id' => $this->_id);
71 // this is needed if the form is outside the CRM name space
72 $baoName = $this->_BAOName;
73 $baoName::retrieve($params, $this->_values );
74 }
75 }
76
77 /**
78 * This function sets the default values for the form. MobileProvider that in edit/view mode
79 * the default values are retrieved from the database
80 *
81 * @access public
82 *
83 * @return array
84 */
85 function setDefaultValues() {
86 if (isset($this->_id) && empty($this->_values)) {
87 $this->_values = array();
88 $params = array('id' => $this->_id);
89 $baoName = $this->_BAOName;
90 $baoName::retrieve($params, $this->_values );
91 }
92 $defaults = $this->_values;
93
94 if ($this->_action == CRM_Core_Action::DELETE &&
95 isset($defaults['name'])
96 ) {
97 $this->assign('delName', $defaults['name']);
98 }
99
100 // its ok if there is no element called is_active
101 $defaults['is_active'] = ($this->_id) ? CRM_Utils_Array::value('is_active', $defaults) : 1;
102 if (!empty($defaults['parent_id'])) {
103 $this->assign('is_parent', TRUE);
104 }
105 return $defaults;
106 }
107
108 /**
109 * Function to actually build the form
110 *
111 * @return void
112 * @access public
113 */
114 public function buildQuickForm() {
115 if ($this->_action & CRM_Core_Action::DELETE) {
116 $this->addButtons(array(
117 array(
118 'type' => 'next',
119 'name' => ts('Delete'),
120 'isDefault' => TRUE,
121 ),
122 array(
123 'type' => 'cancel',
124 'name' => ts('Cancel'),
125 ),
126 )
127 );
128 }
129 elseif ($this->_action & CRM_Core_Action::VIEW) {
130 $this->addButtons(array(
131 array(
132 'type' => 'cancel',
133 'name' => ts('Done'),
134 'isDefault' => TRUE,
135 ),
136 )
137 );
138 }
139 else {
140 $this->addButtons(array(
141 array(
142 'type' => 'next',
143 'name' => ts('Save'),
144 'isDefault' => TRUE,
145 ),
146 array(
147 'type' => 'cancel',
148 'name' => ts('Cancel'),
149 ),
150 )
151 );
152 }
153 }
154}
155