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 | /** | |
37 | * Parent class for inline contact forms | |
38 | */ | |
39 | abstract class CRM_Contact_Form_Inline extends CRM_Core_Form { | |
40 | ||
41 | /** | |
42 | * Id of the contact that is being edited | |
43 | */ | |
44 | public $_contactId; | |
45 | ||
46 | /** | |
47 | * Type of contact being edited | |
48 | */ | |
49 | public $_contactType; | |
50 | ||
51 | /** | |
52 | * Sub type of contact being edited | |
53 | */ | |
54 | public $_contactSubType; | |
55 | ||
b4b53245 TM |
56 | /** |
57 | * Explicitly declare the form context. | |
58 | */ | |
59 | public function getDefaultContext() { | |
60 | return 'create'; | |
61 | } | |
62 | ||
63 | /** | |
64 | * Explicitly declare the entity api name. | |
65 | */ | |
66 | public function getDefaultEntity() { | |
67 | return 'Contact'; | |
68 | } | |
69 | ||
6a488035 TO |
70 | /** |
71 | * Common preprocess: fetch contact ID and contact type | |
72 | */ | |
73 | public function preProcess() { | |
74 | $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE, NULL, $_REQUEST); | |
75 | $this->assign('contactId', $this->_contactId); | |
76 | ||
77 | // get contact type and subtype | |
78 | if (empty($this->_contactType)) { | |
79 | $contactTypeInfo = CRM_Contact_BAO_Contact::getContactTypes($this->_contactId); | |
80 | $this->_contactType = $contactTypeInfo[0]; | |
81 | ||
82 | // check if subtype is set | |
83 | if (isset($contactTypeInfo[1])) { | |
84 | // unset contact type which is 0th element | |
85 | unset($contactTypeInfo[0]); | |
86 | $this->_contactSubType = $contactTypeInfo; | |
87 | } | |
88 | } | |
89 | ||
90 | $this->assign('contactType', $this->_contactType); | |
84276082 CW |
91 | |
92 | $this->setAction(CRM_Core_Action::UPDATE); | |
6a488035 TO |
93 | } |
94 | ||
95 | /** | |
fe482240 | 96 | * Common form elements. |
6a488035 TO |
97 | * |
98 | * @return void | |
6a488035 TO |
99 | */ |
100 | public function buildQuickForm() { | |
101 | CRM_Contact_Form_Inline_Lock::buildQuickForm($this, $this->_contactId); | |
102 | ||
103 | $buttons = array( | |
104 | array( | |
105 | 'type' => 'upload', | |
106 | 'name' => ts('Save'), | |
107 | 'isDefault' => TRUE, | |
108 | ), | |
109 | array( | |
110 | 'type' => 'cancel', | |
111 | 'name' => ts('Cancel'), | |
112 | ), | |
113 | ); | |
114 | $this->addButtons($buttons); | |
115 | } | |
116 | ||
117 | /** | |
fe482240 | 118 | * Override default cancel action. |
6a488035 TO |
119 | * |
120 | * @return void | |
6a488035 TO |
121 | */ |
122 | public function cancelAction() { | |
123 | $response = array('status' => 'cancel'); | |
ecdef330 | 124 | CRM_Utils_JSON::output($response); |
6a488035 TO |
125 | } |
126 | ||
127 | /** | |
fe482240 | 128 | * Set defaults for the form. |
6a488035 TO |
129 | * |
130 | * @return array | |
6a488035 TO |
131 | */ |
132 | public function setDefaultValues() { | |
133 | $defaults = $params = array(); | |
134 | $params['id'] = $this->_contactId; | |
135 | ||
136 | CRM_Contact_BAO_Contact::getValues($params, $defaults); | |
137 | ||
138 | return $defaults; | |
139 | } | |
140 | ||
141 | /** | |
fe482240 | 142 | * Add entry to log table. |
6a488035 TO |
143 | * |
144 | * @return void | |
6a488035 TO |
145 | */ |
146 | protected function log() { | |
147 | CRM_Core_BAO_Log::register($this->_contactId, | |
148 | 'civicrm_contact', | |
149 | $this->_contactId | |
150 | ); | |
151 | } | |
152 | ||
153 | /** | |
fe482240 | 154 | * Common function for all inline contact edit forms. |
03a7ec8f | 155 | * Prepares ajaxResponse |
6a488035 TO |
156 | * |
157 | * @return void | |
6a488035 | 158 | */ |
03a7ec8f | 159 | protected function response() { |
b4efde7a CW |
160 | $this->ajaxResponse = array_merge( |
161 | self::renderFooter($this->_contactId), | |
162 | $this->ajaxResponse, | |
163 | CRM_Contact_Form_Inline_Lock::getResponse($this->_contactId) | |
164 | ); | |
165 | // Note: Post hooks will be called by CRM_Core_Form::mainProcess | |
166 | } | |
167 | ||
168 | /** | |
fe482240 EM |
169 | * Render change log footer markup for a contact and supply count. |
170 | * | |
b4efde7a CW |
171 | * Needed for refreshing the contact summary screen |
172 | * | |
173 | * @param int $cid | |
174 | * @param bool $includeCount | |
175 | * @return array | |
176 | */ | |
fe482240 EM |
177 | public static function renderFooter($cid, $includeCount = TRUE) { |
178 | // Load change log footer from template. | |
6a488035 | 179 | $smarty = CRM_Core_Smarty::singleton(); |
b4efde7a CW |
180 | $smarty->assign('contactId', $cid); |
181 | $smarty->assign('external_identifier', CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'external_identifier')); | |
182 | $smarty->assign('lastModified', CRM_Core_BAO_Log::lastModified($cid, 'civicrm_contact')); | |
6a488035 TO |
183 | $viewOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, |
184 | 'contact_view_options', TRUE | |
185 | ); | |
186 | $smarty->assign('changeLog', $viewOptions['log']); | |
b4efde7a CW |
187 | $ret = array('markup' => $smarty->fetch('CRM/common/contactFooter.tpl')); |
188 | if ($includeCount) { | |
189 | $ret['count'] = CRM_Contact_BAO_Contact::getCountComponent('log', $cid); | |
190 | } | |
191 | return array('changeLog' => $ret); | |
6a488035 | 192 | } |
96025800 | 193 | |
6a488035 | 194 | } |