Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
5dc2f3cc | 37 | * Base class for admin forms |
6a488035 TO |
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 | /** | |
eceb18cc | 49 | * The default values for form fields. |
6a488035 TO |
50 | * |
51 | * @var int | |
52 | */ | |
53 | protected $_values; | |
54 | ||
55 | /** | |
eceb18cc | 56 | * The name of the BAO object for this form. |
6a488035 TO |
57 | * |
58 | * @var string | |
59 | */ | |
60 | protected $_BAOName; | |
61 | ||
a4969aee TM |
62 | /** |
63 | * Explicitly declare the form context. | |
64 | */ | |
65 | public function getDefaultContext() { | |
66 | return 'create'; | |
67 | } | |
68 | ||
355ba699 | 69 | /** |
eceb18cc | 70 | * Basic setup. |
355ba699 | 71 | */ |
00be9182 | 72 | public function preProcess() { |
353ffa53 | 73 | $this->_id = $this->get('id'); |
6a488035 | 74 | $this->_BAOName = $this->get('BAOName'); |
353ffa53 | 75 | $this->_values = array(); |
6a488035 TO |
76 | if (isset($this->_id)) { |
77 | $params = array('id' => $this->_id); | |
78 | // this is needed if the form is outside the CRM name space | |
0e6e8724 | 79 | $baoName = $this->_BAOName; |
481a74f4 | 80 | $baoName::retrieve($params, $this->_values); |
6a488035 TO |
81 | } |
82 | } | |
83 | ||
84 | /** | |
c490a46a | 85 | * Set default values for the form. Note that in edit/view mode |
6a488035 TO |
86 | * the default values are retrieved from the database |
87 | * | |
6a488035 | 88 | * |
355ba699 | 89 | * @return array |
6a488035 | 90 | */ |
00be9182 | 91 | public function setDefaultValues() { |
6a488035 TO |
92 | if (isset($this->_id) && empty($this->_values)) { |
93 | $this->_values = array(); | |
94 | $params = array('id' => $this->_id); | |
0e6e8724 | 95 | $baoName = $this->_BAOName; |
481a74f4 | 96 | $baoName::retrieve($params, $this->_values); |
6a488035 TO |
97 | } |
98 | $defaults = $this->_values; | |
99 | ||
100 | if ($this->_action == CRM_Core_Action::DELETE && | |
101 | isset($defaults['name']) | |
102 | ) { | |
103 | $this->assign('delName', $defaults['name']); | |
104 | } | |
105 | ||
106 | // its ok if there is no element called is_active | |
107 | $defaults['is_active'] = ($this->_id) ? CRM_Utils_Array::value('is_active', $defaults) : 1; | |
a7488080 | 108 | if (!empty($defaults['parent_id'])) { |
6a488035 TO |
109 | $this->assign('is_parent', TRUE); |
110 | } | |
111 | return $defaults; | |
112 | } | |
113 | ||
114 | /** | |
eceb18cc | 115 | * Add standard buttons. |
6a488035 | 116 | * |
355ba699 | 117 | * @return void |
6a488035 TO |
118 | */ |
119 | public function buildQuickForm() { | |
e2046b33 | 120 | if ($this->_action & CRM_Core_Action::VIEW || $this->_action & CRM_Core_Action::PREVIEW) { |
52395565 CW |
121 | $this->addButtons(array( |
122 | array( | |
123 | 'type' => 'cancel', | |
124 | 'name' => ts('Done'), | |
125 | 'isDefault' => TRUE, | |
126 | ), | |
127 | ) | |
128 | ); | |
129 | } | |
6a488035 TO |
130 | else { |
131 | $this->addButtons(array( | |
132 | array( | |
133 | 'type' => 'next', | |
a1f552a9 | 134 | 'name' => $this->_action & CRM_Core_Action::DELETE ? ts('Delete') : ts('Save'), |
6a488035 TO |
135 | 'isDefault' => TRUE, |
136 | ), | |
137 | array( | |
138 | 'type' => 'cancel', | |
139 | 'name' => ts('Cancel'), | |
140 | ), | |
141 | ) | |
142 | ); | |
143 | } | |
144 | } | |
96025800 | 145 | |
6a488035 | 146 | } |