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