| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.4 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2013 | |
| 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-2013 |
| 32 | * $Id$ |
| 33 | * |
| 34 | */ |
| 35 | |
| 36 | /** |
| 37 | * Page for displaying custom data |
| 38 | * |
| 39 | */ |
| 40 | class CRM_Contact_Page_View_CustomData extends CRM_Core_Page { |
| 41 | |
| 42 | /** |
| 43 | * the id of the object being viewed (note/relationship etc) |
| 44 | * |
| 45 | * @int |
| 46 | * @access protected |
| 47 | */ |
| 48 | public $_groupId; |
| 49 | |
| 50 | /** |
| 51 | * class constructor |
| 52 | * |
| 53 | * @return CRM_Contact_Page_View_CustomData |
| 54 | */ |
| 55 | public function __construct() { |
| 56 | parent::__construct(); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * add a few specific things to view contact |
| 61 | * |
| 62 | * @return void |
| 63 | * @access public |
| 64 | * |
| 65 | */ |
| 66 | function preProcess() { |
| 67 | $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); |
| 68 | $this->assign('contactId', $this->_contactId); |
| 69 | |
| 70 | // check logged in url permission |
| 71 | CRM_Contact_Page_View::checkUserPermission($this); |
| 72 | |
| 73 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); |
| 74 | $this->assign('action', $this->_action); |
| 75 | |
| 76 | $this->_groupId = CRM_Utils_Request::retrieve('gid', 'Positive', $this, TRUE); |
| 77 | $this->assign('groupId', $this->_groupId); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Run the page. |
| 82 | * |
| 83 | * This method is called after the page is created. It checks for the |
| 84 | * type of action and executes that action. |
| 85 | * |
| 86 | * @access public |
| 87 | * |
| 88 | * @param object $page - the view page which created this one |
| 89 | * |
| 90 | * @return none |
| 91 | * @static |
| 92 | * |
| 93 | */ |
| 94 | function run() { |
| 95 | $this->preProcess(); |
| 96 | |
| 97 | //set the userContext stack |
| 98 | $doneURL = 'civicrm/contact/view'; |
| 99 | $session = CRM_Core_Session::singleton(); |
| 100 | $session->pushUserContext(CRM_Utils_System::url($doneURL, 'action=browse&selectedChild=custom_' . $this->_groupId), FALSE); |
| 101 | |
| 102 | // get permission detail view or edit |
| 103 | // use a comtact id specific function which gives us much better granularity |
| 104 | // CRM-12646 |
| 105 | $editCustomData = CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT); |
| 106 | $this->assign('editCustomData', $editCustomData); |
| 107 | |
| 108 | //allow to edit own customdata CRM-5518 |
| 109 | $editOwnCustomData = FALSE; |
| 110 | if ($session->get('userID') == $this->_contactId) { |
| 111 | $editOwnCustomData = TRUE; |
| 112 | } |
| 113 | $this->assign('editOwnCustomData', $editOwnCustomData); |
| 114 | |
| 115 | if ($this->_action == CRM_Core_Action::BROWSE) { |
| 116 | //Custom Groups Inline |
| 117 | $entityType = CRM_Contact_BAO_Contact::getContactType($this->_contactId); |
| 118 | $entitySubType = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId); |
| 119 | $groupTree = &CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $this->_contactId, |
| 120 | $this->_groupId, $entitySubType |
| 121 | ); |
| 122 | CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); |
| 123 | } |
| 124 | else { |
| 125 | |
| 126 | $controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_CustomData', |
| 127 | ts('Custom Data'), |
| 128 | $this->_action |
| 129 | ); |
| 130 | $controller->setEmbedded(TRUE); |
| 131 | |
| 132 | $controller->set('tableId', $this->_contactId); |
| 133 | $controller->set('groupId', $this->_groupId); |
| 134 | $controller->set('entityType', CRM_Contact_BAO_Contact::getContactType($this->_contactId)); |
| 135 | $controller->set('entitySubType', CRM_Contact_BAO_Contact::getContactSubType($this->_contactId, ',')); |
| 136 | $controller->process(); |
| 137 | $controller->run(); |
| 138 | } |
| 139 | return parent::run(); |
| 140 | } |
| 141 | } |
| 142 | |