Introduce new `communication_style` field for Contacts
[civicrm-core.git] / CRM / Contact / Form / Inline.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 * Parent class for inline contact forms
38 */
39abstract 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
56 /**
57 * Common preprocess: fetch contact ID and contact type
58 */
59 public function preProcess() {
60 $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE, NULL, $_REQUEST);
61 $this->assign('contactId', $this->_contactId);
62
63 // get contact type and subtype
64 if (empty($this->_contactType)) {
65 $contactTypeInfo = CRM_Contact_BAO_Contact::getContactTypes($this->_contactId);
66 $this->_contactType = $contactTypeInfo[0];
67
68 // check if subtype is set
69 if (isset($contactTypeInfo[1])) {
70 // unset contact type which is 0th element
71 unset($contactTypeInfo[0]);
72 $this->_contactSubType = $contactTypeInfo;
73 }
74 }
75
76 $this->assign('contactType', $this->_contactType);
77 }
78
79 /**
80 * Common form elements
81 *
82 * @return void
83 * @access public
84 */
85 public function buildQuickForm() {
86 CRM_Contact_Form_Inline_Lock::buildQuickForm($this, $this->_contactId);
87
88 $buttons = array(
89 array(
90 'type' => 'upload',
91 'name' => ts('Save'),
92 'isDefault' => TRUE,
93 ),
94 array(
95 'type' => 'cancel',
96 'name' => ts('Cancel'),
97 ),
98 );
99 $this->addButtons($buttons);
100 }
101
102 /**
103 * Override default cancel action
104 *
105 * @return void
106 * @access public
107 */
108 public function cancelAction() {
109 $response = array('status' => 'cancel');
110 echo json_encode($response);
111 CRM_Utils_System::civiExit();
112 }
113
114 /**
115 * Set defaults for the form
116 *
117 * @return array
118 * @access public
119 */
120 public function setDefaultValues() {
121 $defaults = $params = array();
122 $params['id'] = $this->_contactId;
123
124 CRM_Contact_BAO_Contact::getValues($params, $defaults);
125
126 return $defaults;
127 }
128
129 /**
130 * Add entry to log table
131 *
132 * @return void
133 * @protected
134 */
135 protected function log() {
136 CRM_Core_BAO_Log::register($this->_contactId,
137 'civicrm_contact',
138 $this->_contactId
139 );
140 }
141
142 /**
143 * Final response from successful form submit
144 *
145 * @param response: array - data to send to the client
146 *
147 * @return void
148 * @protected
149 */
150 protected function response($response = array()) {
151 // Load changelog footer from template
152 $smarty = CRM_Core_Smarty::singleton();
153 $smarty->assign('contactId', $this->_contactId);
154 $smarty->assign('external_identifier', CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'external_identifier'));
155 $smarty->assign('lastModified', CRM_Core_BAO_Log::lastModified($this->_contactId, 'civicrm_contact'));
156 $viewOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
157 'contact_view_options', TRUE
158 );
159 $smarty->assign('changeLog', $viewOptions['log']);
160 $response = array_merge(
161 array(
162 'status' => 'save',
163 'changeLog' => array(
164 'count' => CRM_Contact_BAO_Contact::getCountComponent('log', $this->_contactId),
165 'markup' => $smarty->fetch('CRM/common/contactFooter.tpl'),
166 ),
167 ),
168 $response,
169 CRM_Contact_Form_Inline_Lock::getResponse($this->_contactId)
170 );
171 $this->postProcessHook();
172 // CRM-11831 @see http://www.malsup.com/jquery/form/#file-upload
173 $xhr = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
174 if (!$xhr) {
175 echo '<textarea>';
176 }
177 echo json_encode($response);
178 if (!$xhr) {
179 echo '</textarea>';
180 }
181 CRM_Utils_System::civiExit();
182 }
183}