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