3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * Parent class for inline contact forms
39 abstract class CRM_Contact_Form_Inline
extends CRM_Core_Form
{
42 * Id of the contact that is being edited
47 * Type of contact being edited
52 * Sub type of contact being edited
54 public $_contactSubType;
57 * Explicitly declare the form context.
59 public function getDefaultContext() {
64 * Explicitly declare the entity api name.
66 public function getDefaultEntity() {
71 * Common preprocess: fetch contact ID and contact type
73 public function preProcess() {
74 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE, NULL, $_REQUEST);
75 $this->assign('contactId', $this->_contactId
);
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];
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;
90 $this->assign('contactType', $this->_contactType
);
94 * Common form elements.
98 public function buildQuickForm() {
99 CRM_Contact_Form_Inline_Lock
::buildQuickForm($this, $this->_contactId
);
104 'name' => ts('Save'),
109 'name' => ts('Cancel'),
112 $this->addButtons($buttons);
116 * Override default cancel action.
120 public function cancelAction() {
121 $response = array('status' => 'cancel');
122 CRM_Utils_JSON
::output($response);
126 * Set defaults for the form.
130 public function setDefaultValues() {
131 $defaults = $params = array();
132 $params['id'] = $this->_contactId
;
134 CRM_Contact_BAO_Contact
::getValues($params, $defaults);
140 * Add entry to log table.
144 protected function log() {
145 CRM_Core_BAO_Log
::register($this->_contactId
,
152 * Common function for all inline contact edit forms.
153 * Prepares ajaxResponse
157 protected function response() {
158 $this->ajaxResponse
= array_merge(
159 self
::renderFooter($this->_contactId
),
161 CRM_Contact_Form_Inline_Lock
::getResponse($this->_contactId
)
163 // Note: Post hooks will be called by CRM_Core_Form::mainProcess
167 * Render change log footer markup for a contact and supply count.
169 * Needed for refreshing the contact summary screen
172 * @param bool $includeCount
175 public static function renderFooter($cid, $includeCount = TRUE) {
176 // Load change log footer from template.
177 $smarty = CRM_Core_Smarty
::singleton();
178 $smarty->assign('contactId', $cid);
179 $smarty->assign('external_identifier', CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'external_identifier'));
180 $smarty->assign('lastModified', CRM_Core_BAO_Log
::lastModified($cid, 'civicrm_contact'));
181 $viewOptions = CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
182 'contact_view_options', TRUE
184 $smarty->assign('changeLog', $viewOptions['log']);
185 $ret = array('markup' => $smarty->fetch('CRM/common/contactFooter.tpl'));
187 $ret['count'] = CRM_Contact_BAO_Contact
::getCountComponent('log', $cid);
189 return array('changeLog' => $ret);