comments
[civicrm-core.git] / CRM / Contact / Page / Inline / Address.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 * Dummy page for details of address
38 *
39 */
40 class 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
48 */
49 public function run() {
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();
56 if ($addressId > 0) {
57 $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name'));
58
59 $entityBlock = array('id' => $addressId);
60 $address = CRM_Core_BAO_Address::getValues($entityBlock, FALSE, 'id');
61 if (!empty($address)) {
62 foreach ($address as $key => & $value) {
63 $value['location_type'] = $locationTypes[$value['location_type_id']];
64 }
65 }
66 }
67
68 // we just need current address block
69 $currentAddressBlock['address'][$locBlockNo] = array_pop($address);
70
71 if (!empty($currentAddressBlock['address'][$locBlockNo])) {
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) {
76 if (!empty($addressValue['master_id']) &&
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
87 $groupTree = CRM_Core_BAO_CustomGroup::getTree('Address',
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.
92 $currentAddressBlock['address'][$locBlockNo]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, "dnc_");
93 $this->assign("dnc_viewCustomData", NULL);
94
95 $this->assign('add', $currentAddressBlock['address'][$locBlockNo]);
96 $this->assign('sharedAddresses', $sharedAddresses);
97 }
98 $contact = new CRM_Contact_BAO_Contact();
99 $contact->id = $contactId;
100 $contact->find(TRUE);
101 $privacy = array();
102 foreach (CRM_Contact_BAO_Contact::$_commPrefs as $name) {
103 if (isset($contact->$name)) {
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);
112
113 // check logged in user permission
114 CRM_Contact_Page_View::checkUserPermission($this, $contactId);
115
116 // finally call parent
117 parent::run();
118 }
119
120 }