commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / CRM / Contact / Form / Inline.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
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
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 */
84 public function buildQuickForm() {
85 CRM_Contact_Form_Inline_Lock::buildQuickForm($this, $this->_contactId);
86
87 $buttons = array(
88 array(
89 'type' => 'upload',
90 'name' => ts('Save'),
91 'isDefault' => TRUE,
92 ),
93 array(
94 'type' => 'cancel',
95 'name' => ts('Cancel'),
96 ),
97 );
98 $this->addButtons($buttons);
99 }
100
101 /**
102 * Override default cancel action.
103 *
104 * @return void
105 */
106 public function cancelAction() {
107 $response = array('status' => 'cancel');
108 CRM_Utils_JSON::output($response);
109 }
110
111 /**
112 * Set defaults for the form.
113 *
114 * @return array
115 */
116 public function setDefaultValues() {
117 $defaults = $params = array();
118 $params['id'] = $this->_contactId;
119
120 CRM_Contact_BAO_Contact::getValues($params, $defaults);
121
122 return $defaults;
123 }
124
125 /**
126 * Add entry to log table.
127 *
128 * @return void
129 */
130 protected function log() {
131 CRM_Core_BAO_Log::register($this->_contactId,
132 'civicrm_contact',
133 $this->_contactId
134 );
135 }
136
137 /**
138 * Common function for all inline contact edit forms.
139 * Prepares ajaxResponse
140 *
141 * @return void
142 */
143 protected function response() {
144 $this->ajaxResponse = array_merge(
145 self::renderFooter($this->_contactId),
146 $this->ajaxResponse,
147 CRM_Contact_Form_Inline_Lock::getResponse($this->_contactId)
148 );
149 // Note: Post hooks will be called by CRM_Core_Form::mainProcess
150 }
151
152 /**
153 * Render change log footer markup for a contact and supply count.
154 *
155 * Needed for refreshing the contact summary screen
156 *
157 * @param int $cid
158 * @param bool $includeCount
159 * @return array
160 */
161 public static function renderFooter($cid, $includeCount = TRUE) {
162 // Load change log footer from template.
163 $smarty = CRM_Core_Smarty::singleton();
164 $smarty->assign('contactId', $cid);
165 $smarty->assign('external_identifier', CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'external_identifier'));
166 $smarty->assign('lastModified', CRM_Core_BAO_Log::lastModified($cid, 'civicrm_contact'));
167 $viewOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
168 'contact_view_options', TRUE
169 );
170 $smarty->assign('changeLog', $viewOptions['log']);
171 $ret = array('markup' => $smarty->fetch('CRM/common/contactFooter.tpl'));
172 if ($includeCount) {
173 $ret['count'] = CRM_Contact_BAO_Contact::getCountComponent('log', $cid);
174 }
175 return array('changeLog' => $ret);
176 }
177
178 }