d325ea8cc25247b3f37820c0e0b1450fbcbdb206
[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-2014 |
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-2014
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 */
50 public function run() {
51 // get the emails for this contact
52 $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
53 $locBlockNo = CRM_Utils_Request::retrieve('locno', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
54 $addressId = CRM_Utils_Request::retrieve('aid', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, NULL, $_REQUEST);
55
56 $address = array();
57 if ( $addressId > 0 ) {
58 $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name'));
59
60 $entityBlock = array('id' => $addressId);
61 $address = CRM_Core_BAO_Address::getValues($entityBlock, FALSE, 'id');
62 if (!empty($address)) {
63 foreach ($address as $key =>& $value) {
64 $value['location_type'] = $locationTypes[$value['location_type_id']];
65 }
66 }
67 }
68
69 // we just need current address block
70 $currentAddressBlock['address'][$locBlockNo] = array_pop( $address );
71
72 if ( !empty( $currentAddressBlock['address'][$locBlockNo] ) ) {
73 // get contact name of shared contact names
74 $sharedAddresses = array();
75 $shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($currentAddressBlock['address']);
76 foreach ($currentAddressBlock['address'] as $key => $addressValue) {
77 if (!empty($addressValue['master_id']) &&
78 !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']
79 ) {
80 $sharedAddresses[$key]['shared_address_display'] = array(
81 'address' => $addressValue['display'],
82 'name' => $shareAddressContactNames[$addressValue['master_id']]['name'],
83 );
84 }
85 }
86
87 // add custom data of type address
88 $groupTree = CRM_Core_BAO_CustomGroup::getTree( 'Address',
89 $this, $currentAddressBlock['address'][$locBlockNo]['id']
90 );
91
92 // we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var.
93 $currentAddressBlock['address'][$locBlockNo]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView( $this, $groupTree, FALSE, NULL, "dnc_");
94 $this->assign("dnc_viewCustomData", NULL);
95
96 $this->assign('add', $currentAddressBlock['address'][$locBlockNo]);
97 $this->assign('sharedAddresses', $sharedAddresses);
98 }
99 $contact = new CRM_Contact_BAO_Contact( );
100 $contact->id = $contactId;
101 $contact->find(true);
102 $privacy = array( );
103 foreach ( CRM_Contact_BAO_Contact::$_commPrefs as $name ) {
104 if ( isset( $contact->$name ) ) {
105 $privacy[$name] = $contact->$name;
106 }
107 }
108
109 $this->assign('contactId', $contactId);
110 $this->assign('locationIndex', $locBlockNo);
111 $this->assign('addressId', $addressId);
112 $this->assign('privacy', $privacy);
113
114 // check logged in user permission
115 CRM_Contact_Page_View::checkUserPermission($this, $contactId);
116
117 // finally call parent
118 parent::run();
119 }
120 }