Update copyright date for 2020
[civicrm-core.git] / CRM / Contact / Page / Inline / Address.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2020 |
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-2020
32 */
33
34 /**
35 * Dummy page for details of address.
36 */
37 class CRM_Contact_Page_Inline_Address extends CRM_Core_Page {
38
39 /**
40 * Run the page.
41 *
42 * This method is called after the page is created.
43 */
44 public function run() {
45 // get the emails for this contact
46 $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
47 $locBlockNo = CRM_Utils_Request::retrieve('locno', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
48 $addressId = CRM_Utils_Request::retrieve('aid', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, NULL, $_REQUEST);
49
50 $address = [];
51 if ($addressId > 0) {
52 $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', ['labelColumn' => 'display_name']);
53
54 $entityBlock = ['id' => $addressId];
55 $address = CRM_Core_BAO_Address::getValues($entityBlock, FALSE, 'id');
56 if (!empty($address)) {
57 foreach ($address as $key => & $value) {
58 $value['location_type'] = $locationTypes[$value['location_type_id']];
59 }
60 }
61 }
62
63 // we just need current address block
64 $currentAddressBlock['address'][$locBlockNo] = array_pop($address);
65
66 if (!empty($currentAddressBlock['address'][$locBlockNo])) {
67 // get contact name of shared contact names
68 $sharedAddresses = [];
69 $shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($currentAddressBlock['address']);
70 foreach ($currentAddressBlock['address'] as $key => $addressValue) {
71 if (!empty($addressValue['master_id']) &&
72 !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']
73 ) {
74 $sharedAddresses[$key]['shared_address_display'] = [
75 'address' => $addressValue['display'],
76 'name' => $shareAddressContactNames[$addressValue['master_id']]['name'],
77 ];
78 }
79 }
80 $idValue = $currentAddressBlock['address'][$locBlockNo]['id'];
81 if (!empty($currentAddressBlock['address'][$locBlockNo]['master_id'])) {
82 $idValue = $currentAddressBlock['address'][$locBlockNo]['master_id'];
83 }
84
85 // add custom data of type address
86 $groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', NULL, $idValue);
87
88 // we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var.
89 $currentAddressBlock['address'][$locBlockNo]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, "dnc_");
90 $this->assign("dnc_viewCustomData", NULL);
91
92 $this->assign('add', $currentAddressBlock['address'][$locBlockNo]);
93 $this->assign('sharedAddresses', $sharedAddresses);
94 }
95 $contact = new CRM_Contact_BAO_Contact();
96 $contact->id = $contactId;
97 $contact->find(TRUE);
98 $privacy = [];
99 foreach (CRM_Contact_BAO_Contact::$_commPrefs as $name) {
100 if (isset($contact->$name)) {
101 $privacy[$name] = $contact->$name;
102 }
103 }
104
105 $this->assign('contactId', $contactId);
106 $this->assign('locationIndex', $locBlockNo);
107 $this->assign('addressId', $addressId);
108 $this->assign('privacy', $privacy);
109
110 // check logged in user permission
111 CRM_Contact_Page_View::checkUserPermission($this, $contactId);
112
113 // finally call parent
114 parent::run();
115 }
116
117 }