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