First commit

This commit is contained in:
Theodotos Andreou 2018-01-14 13:10:16 +00:00
commit c6e2478c40
13918 changed files with 2303184 additions and 0 deletions

View file

@ -0,0 +1,108 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
class CRM_Contact_Page_View_ContactSmartGroup extends CRM_Core_Page {
/**
* @var int contact id
*/
public $_contactId;
/**
* called when action is browse.
*
*/
public function browse() {
$in = CRM_Contact_BAO_GroupContact::getContactGroup($this->_contactId, 'Added');
// keep track of all 'added' contact groups so we can remove them from the smart group
// section
$staticGroups = array();
if (!empty($in)) {
foreach ($in as $group) {
$staticGroups[$group['group_id']] = 1;
}
}
$allGroup = CRM_Contact_BAO_GroupContactCache::contactGroup($this->_contactId);
$this->assign('groupSmart', NULL);
$this->assign('groupParent', NULL);
if (!empty($allGroup)) {
$smart = $parent = array();
foreach ($allGroup['group'] as $group) {
// delete all smart groups which are also in static groups
if (isset($staticGroups[$group['id']])) {
continue;
}
if (empty($group['children'])) {
$smart[] = $group;
}
else {
$parent[] = $group;
}
}
if (!empty($smart)) {
$this->assign_by_ref('groupSmart', $smart);
}
if (!empty($parent)) {
$this->assign_by_ref('groupParent', $parent);
}
}
}
public function preProcess() {
$this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
$this->assign('contactId', $this->_contactId);
$displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
$this->assign('displayName', $displayName);
// check logged in url permission
CRM_Contact_Page_View::checkUserPermission($this);
}
/**
* the main function that is called
* when the page loads, it decides the which action has
* to be taken for the page.
*
* @return null
*/
public function run() {
$this->preProcess();
$this->browse();
return parent::run();
}
}

View file

@ -0,0 +1,177 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* Page for displaying custom data.
*/
class CRM_Contact_Page_View_CustomData extends CRM_Core_Page {
/**
* The id of the object being viewed (note/relationship etc).
*
* @int
*/
public $_groupId;
/**
* Class constructor.
*
* @return CRM_Contact_Page_View_CustomData
*/
public function __construct() {
parent::__construct();
}
/**
* Add a few specific things to view contact.
*/
public function preProcess() {
$this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
$this->assign('contactId', $this->_contactId);
// check logged in url permission
CRM_Contact_Page_View::checkUserPermission($this);
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
$this->assign('action', $this->_action);
$this->_groupId = CRM_Utils_Request::retrieve('gid', 'Positive', $this, TRUE);
$this->assign('groupId', $this->_groupId);
$this->_multiRecordDisplay = CRM_Utils_Request::retrieve('multiRecordDisplay', 'String', $this, FALSE);
$this->_cgcount = CRM_Utils_Request::retrieve('cgcount', 'Positive', $this, FALSE);
$this->_recId = CRM_Utils_Request::retrieve('recId', 'Positive', $this, FALSE);
}
/**
* Run the page.
*
* This method is called after the page is created. It checks for the
* type of action and executes that action.
*/
public function run() {
$this->preProcess();
//set the userContext stack
$doneURL = 'civicrm/contact/view';
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url($doneURL, 'action=browse&selectedChild=custom_' . $this->_groupId), FALSE);
// Get permission detail - view or edit.
// use a contact id specific function which gives us much better granularity
// CRM-12646
$editCustomData = CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT);
$this->assign('editCustomData', $editCustomData);
// Allow to edit own custom data CRM-5518.
$editOwnCustomData = FALSE;
if ($session->get('userID') == $this->_contactId) {
$editOwnCustomData = TRUE;
}
$this->assign('editOwnCustomData', $editOwnCustomData);
if ($this->_action == CRM_Core_Action::BROWSE) {
$displayStyle = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup',
$this->_groupId,
'style'
);
if ($this->_multiRecordDisplay != 'single') {
$id = "custom_{$this->_groupId}";
$tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_groupId, 'table_name');
$this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $tableName);
}
if ($displayStyle === 'Tab with table' && $this->_multiRecordDisplay != 'single') {
$ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
$this->_contactId,
'contact_type'
);
$this->assign('displayStyle', 'tableOriented');
// here the multi custom data listing code will go
$multiRecordFieldListing = TRUE;
$page = new CRM_Profile_Page_MultipleRecordFieldsListing();
$page->set('contactId', $this->_contactId);
$page->set('customGroupId', $this->_groupId);
$page->set('action', CRM_Core_Action::BROWSE);
$page->set('multiRecordFieldListing', $multiRecordFieldListing);
$page->set('pageViewType', 'customDataView');
$page->set('contactType', $ctype);
$page->_headersOnly = TRUE;
$page->run();
}
else {
//Custom Groups Inline
$entityType = CRM_Contact_BAO_Contact::getContactType($this->_contactId);
$entitySubType = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId);
$recId = NULL;
if ($this->_multiRecordDisplay == 'single') {
$groupTitle = CRM_Core_BAO_CustomGroup::getTitle($this->_groupId);
CRM_Utils_System::setTitle(ts('View %1 Record', array(1 => $groupTitle)));
$groupTree = CRM_Core_BAO_CustomGroup::getTree($entityType, NULL, $this->_contactId,
$this->_groupId, $entitySubType, NULL, TRUE, NULL, FALSE, TRUE, $this->_cgcount
);
$recId = $this->_recId;
$this->assign('multiRecordDisplay', $this->_multiRecordDisplay);
$this->assign('skipTitle', 1);
}
else {
$groupTree = CRM_Core_BAO_CustomGroup::getTree($entityType, NULL, $this->_contactId,
$this->_groupId, $entitySubType
);
}
CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, $recId, $this->_contactId);
}
}
else {
$controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_CustomData',
ts('Custom Data'),
$this->_action
);
$controller->setEmbedded(TRUE);
$controller->set('tableId', $this->_contactId);
$controller->set('groupId', $this->_groupId);
$controller->set('entityType', CRM_Contact_BAO_Contact::getContactType($this->_contactId));
$controller->set('entitySubType', CRM_Contact_BAO_Contact::getContactSubType($this->_contactId, ','));
$controller->process();
$controller->run();
}
return parent::run();
}
}

View file

@ -0,0 +1,192 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
class CRM_Contact_Page_View_GroupContact extends CRM_Core_Page {
/**
* Called when action is browse.
*/
public function browse() {
$count = CRM_Contact_BAO_GroupContact::getContactGroup($this->_contactId, NULL, NULL, TRUE, FALSE, FALSE, TRUE, NULL, TRUE);
$in = CRM_Contact_BAO_GroupContact::getContactGroup($this->_contactId, 'Added', NULL, FALSE, FALSE, FALSE, TRUE, NULL, TRUE);
$pending = CRM_Contact_BAO_GroupContact::getContactGroup($this->_contactId, 'Pending', NULL, FALSE, FALSE, FALSE, TRUE, NULL, TRUE);
$out = CRM_Contact_BAO_GroupContact::getContactGroup($this->_contactId, 'Removed', NULL, FALSE, FALSE, FALSE, TRUE, NULL, TRUE);
// keep track of all 'added' contact groups so we can remove them from the smart group
// section
$staticGroups = array();
if (!empty($in)) {
foreach ($in as $group) {
$staticGroups[$group['group_id']] = 1;
}
}
$this->assign('groupCount', $count);
$this->assign_by_ref('groupIn', $in);
$this->assign_by_ref('groupPending', $pending);
$this->assign_by_ref('groupOut', $out);
// get the info on contact smart groups
$contactSmartGroupSettings = Civi::settings()->get('contact_smart_group_display');
$this->assign('contactSmartGroupSettings', $contactSmartGroupSettings);
$this->ajaxResponse['tabCount'] = count($in);
}
/**
* called when action is update.
*
* @param int $groupId
*
*/
public function edit($groupId = NULL) {
$controller = new CRM_Core_Controller_Simple(
'CRM_Contact_Form_GroupContact',
ts('Contact\'s Groups'),
$this->_action
);
$controller->setEmbedded(TRUE);
// set the userContext stack
$session = CRM_Core_Session::singleton();
$session->pushUserContext(
CRM_Utils_System::url(
'civicrm/contact/view',
"action=browse&selectedChild=group&cid={$this->_contactId}"
),
FALSE
);
$controller->reset();
$controller->set('contactId', $this->_contactId);
$controller->set('groupId', $groupId);
$controller->process();
$controller->run();
}
public function preProcess() {
$this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
$this->assign('contactId', $this->_contactId);
// check logged in url permission
CRM_Contact_Page_View::checkUserPermission($this);
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
$this->assign('action', $this->_action);
}
/**
* the main function that is called
* when the page loads, it decides the which action has
* to be taken for the page.
*
* @return null
*/
public function run() {
$this->preProcess();
$displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
$this->assign('displayName', $displayName);
if ($this->_action == CRM_Core_Action::DELETE) {
$groupContactId = CRM_Utils_Request::retrieve('gcid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE);
$status = CRM_Utils_Request::retrieve('st', 'String', CRM_Core_DAO::$_nullObject, TRUE);
if (is_numeric($groupContactId) && $status) {
$this->del($groupContactId, $status, $this->_contactId);
}
$session = CRM_Core_Session::singleton();
CRM_Utils_System::redirect($session->popUserContext());
}
$this->edit(NULL, CRM_Core_Action::ADD);
$this->browse();
return parent::run();
}
/**
* Remove/ rejoin the group
*
* @param int $groupContactId
* Id of crm_group_contact.
* @param string $status
* This is the status that should be updated.
*
* $access public
* @param int $contactID
*
* @return bool
*/
public static function del($groupContactId, $status, $contactID) {
$groupId = CRM_Contact_BAO_GroupContact::getGroupId($groupContactId);
switch ($status) {
case 'i':
$groupStatus = 'Added';
break;
case 'p':
$groupStatus = 'Pending';
break;
case 'o':
$groupStatus = 'Removed';
break;
case 'd':
$groupStatus = 'Deleted';
break;
}
$groupNum = CRM_Contact_BAO_GroupContact::getContactGroup($contactID, 'Added', NULL, TRUE, TRUE);
if ($groupNum == 1 && $groupStatus == 'Removed' && Civi::settings()->get('is_enabled')) {
CRM_Core_Session::setStatus(ts('Please ensure at least one contact group association is maintained.'), ts('Could Not Remove'));
return FALSE;
}
$ids = array($contactID);
$method = 'Admin';
$session = CRM_Core_Session::singleton();
$userID = $session->get('userID');
if ($userID == $contactID) {
$method = 'Web';
}
CRM_Contact_BAO_GroupContact::removeContactsFromGroup($ids, $groupId, $method, $groupStatus);
}
}

View file

@ -0,0 +1,102 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
class CRM_Contact_Page_View_Log extends CRM_Core_Page {
/**
* Called when action is browse.
*
* @return null
*/
public function browse() {
$loggingReport = CRM_Core_BAO_Log::useLoggingReport();
$this->assign('useLogging', $loggingReport);
if ($loggingReport) {
$this->assign('instanceUrl',
CRM_Utils_System::url("civicrm/report/instance/{$loggingReport}",
"reset=1&force=1&snippet=4&section=2&altered_contact_id_op=eq&altered_contact_id_value={$this->_contactId}&cid={$this->_contactId}", FALSE, NULL, FALSE));
return NULL;
}
$log = new CRM_Core_DAO_Log();
$log->entity_table = 'civicrm_contact';
$log->entity_id = $this->_contactId;
$log->orderBy('modified_date desc');
$log->find();
$logEntries = array();
while ($log->fetch()) {
list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($log->modified_id);
$logEntries[] = array(
'id' => $log->modified_id,
'name' => $displayName,
'image' => $contactImage,
'date' => $log->modified_date,
);
}
$this->assign('logCount', count($logEntries));
$this->ajaxResponse['tabCount'] = count($logEntries);
$this->ajaxResponse += CRM_Contact_Form_Inline::renderFooter($this->_contactId, FALSE);
$this->assign_by_ref('log', $logEntries);
}
public function preProcess() {
$this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
$this->assign('contactId', $this->_contactId);
$displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
$this->assign('displayName', $displayName);
// check logged in url permission
CRM_Contact_Page_View::checkUserPermission($this);
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
$this->assign('action', $this->_action);
}
/**
* the main function that is called when the page loads, it decides the which action has to be taken for the page.
*
* @return null
*/
public function run() {
$this->preProcess();
$this->browse();
return parent::run();
}
}

View file

@ -0,0 +1,306 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* Main page for viewing Notes.
*/
class CRM_Contact_Page_View_Note extends CRM_Core_Page {
/**
* The action links for notes that we need to display for the browse screen
*
* @var array
*/
static $_links = NULL;
/**
* The action links for comments that we need to display for the browse screen
*
* @var array
*/
static $_commentLinks = NULL;
/**
* View details of a note.
*/
public function view() {
$note = new CRM_Core_DAO_Note();
$note->id = $this->_id;
if ($note->find(TRUE)) {
$values = array();
CRM_Core_DAO::storeValues($note, $values);
$values['privacy'] = CRM_Core_PseudoConstant::getLabel('CRM_Core_BAO_Note', 'privacy', $values['privacy']);
$this->assign('note', $values);
}
$comments = CRM_Core_BAO_Note::getNoteTree($values['id'], 1);
if (!empty($comments)) {
$this->assign('comments', $comments);
}
// add attachments part
$currentAttachmentInfo = CRM_Core_BAO_File::getEntityFile('civicrm_note', $this->_id);
$this->assign('currentAttachmentInfo', $currentAttachmentInfo);
}
/**
* called when action is browse.
*/
public function browse() {
$note = new CRM_Core_DAO_Note();
$note->entity_table = 'civicrm_contact';
$note->entity_id = $this->_contactId;
$note->orderBy('modified_date desc');
//CRM-4418, handling edit and delete separately.
$permissions = array($this->_permission);
if ($this->_permission == CRM_Core_Permission::EDIT) {
//previously delete was subset of edit
//so for consistency lets grant delete also.
$permissions[] = CRM_Core_Permission::DELETE;
}
$mask = CRM_Core_Action::mask($permissions);
$values = array();
$links = self::links();
$action = array_sum(array_keys($links)) & $mask;
$note->find();
while ($note->fetch()) {
if (!CRM_Core_BAO_Note::getNotePrivacyHidden($note)) {
CRM_Core_DAO::storeValues($note, $values[$note->id]);
$values[$note->id]['action'] = CRM_Core_Action::formLink($links,
$action,
array(
'id' => $note->id,
'cid' => $this->_contactId,
),
ts('more'),
FALSE,
'note.selector.row',
'Note',
$note->id
);
$contact = new CRM_Contact_DAO_Contact();
$contact->id = $note->contact_id;
$contact->find();
$contact->fetch();
$values[$note->id]['createdBy'] = $contact->display_name;
$values[$note->id]['comment_count'] = CRM_Core_BAO_Note::getChildCount($note->id);
// paper icon view for attachments part
$paperIconAttachmentInfo = CRM_Core_BAO_File::paperIconAttachment('civicrm_note', $note->id);
$values[$note->id]['attachment'] = $paperIconAttachmentInfo;
}
}
$this->assign('notes', $values);
$commentLinks = self::commentLinks();
$action = array_sum(array_keys($commentLinks)) & $mask;
$commentAction = CRM_Core_Action::formLink($commentLinks,
$action,
array(
'id' => $note->id,
'pid' => $note->entity_id,
'cid' => $note->entity_id,
),
ts('more'),
FALSE,
'note.comment.action',
'Note',
$note->id
);
$this->assign('commentAction', $commentAction);
$this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('note', $this->_contactId);
}
/**
* called when action is update or new.
*/
public function edit() {
$controller = new CRM_Core_Controller_Simple('CRM_Note_Form_Note', ts('Contact Notes'), $this->_action);
$controller->setEmbedded(TRUE);
// set the userContext stack
$session = CRM_Core_Session::singleton();
$url = CRM_Utils_System::url('civicrm/contact/view',
'action=browse&selectedChild=note&cid=' . $this->_contactId
);
$session->pushUserContext($url);
if (CRM_Utils_Request::retrieve('confirmed', 'Boolean')) {
CRM_Core_BAO_Note::del($this->_id);
CRM_Utils_System::redirect($url);
}
$controller->reset();
$controller->set('entityTable', 'civicrm_contact');
$controller->set('entityId', $this->_contactId);
$controller->set('id', $this->_id);
$controller->process();
$controller->run();
}
public function preProcess() {
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
if ($this->_id && CRM_Core_BAO_Note::getNotePrivacyHidden($this->_id)) {
CRM_Core_Error::statusBounce(ts('You do not have access to this note.'));
}
$this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
$this->assign('contactId', $this->_contactId);
// check logged in url permission
CRM_Contact_Page_View::checkUserPermission($this);
$displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
CRM_Utils_System::setTitle(ts('Notes for') . ' ' . $displayName);
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
$this->assign('action', $this->_action);
}
/**
* the main function that is called when the page loads,
* it decides the which action has to be taken for the page.
*
* @return null
*/
public function run() {
$this->preProcess();
if ($this->_action & CRM_Core_Action::VIEW) {
$this->view();
}
elseif ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) {
$this->edit();
}
elseif ($this->_action & CRM_Core_Action::DELETE) {
// we use the edit screen the confirm the delete
$this->edit();
}
$this->browse();
return parent::run();
}
/**
* Delete the note object from the db.
*/
public function delete() {
CRM_Core_BAO_Note::del($this->_id);
}
/**
* Get action links.
*
* @return array
* (reference) of action links
*/
public static function &links() {
if (!(self::$_links)) {
$deleteExtra = ts('Are you sure you want to delete this note?');
self::$_links = array(
CRM_Core_Action::VIEW => array(
'name' => ts('View'),
'url' => 'civicrm/contact/view/note',
'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
'title' => ts('View Note'),
),
CRM_Core_Action::UPDATE => array(
'name' => ts('Edit'),
'url' => 'civicrm/contact/view/note',
'qs' => 'action=update&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
'title' => ts('Edit Note'),
),
CRM_Core_Action::ADD => array(
'name' => ts('Comment'),
'url' => 'civicrm/contact/view/note',
'qs' => 'action=add&reset=1&cid=%%cid%%&parentId=%%id%%&selectedChild=note',
'title' => ts('Add Comment'),
),
CRM_Core_Action::DELETE => array(
'name' => ts('Delete'),
'url' => 'civicrm/contact/view/note',
'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
'title' => ts('Delete Note'),
),
);
}
return self::$_links;
}
/**
* Get action links for comments.
*
* @return array
* (reference) of action links
*/
public static function &commentLinks() {
if (!(self::$_commentLinks)) {
self::$_commentLinks = array(
CRM_Core_Action::VIEW => array(
'name' => ts('View'),
'url' => 'civicrm/contact/view/note',
'qs' => 'action=view&reset=1&cid=%%cid%%&id={id}&selectedChild=note',
'title' => ts('View Comment'),
),
CRM_Core_Action::UPDATE => array(
'name' => ts('Edit'),
'url' => 'civicrm/contact/view/note',
'qs' => 'action=update&reset=1&cid=%%cid%%&id={id}&parentId=%%pid%%&selectedChild=note',
'title' => ts('Edit Comment'),
),
CRM_Core_Action::DELETE => array(
'name' => ts('Delete'),
'url' => 'civicrm/contact/view/note',
'qs' => 'action=delete&reset=1&cid=%%cid%%&id={id}&selectedChild=note',
'title' => ts('Delete Comment'),
),
);
}
return self::$_commentLinks;
}
}

View file

@ -0,0 +1,70 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* Main page for viewing contact.
*/
class CRM_Contact_Page_View_Print extends CRM_Contact_Page_View_Summary {
/**
* Heart of the viewing process.
*
* The runner gets all the meta data for the contact and calls the appropriate type of page to view.
*/
public function run() {
$this->_print = CRM_Core_Smarty::PRINT_PAGE;
$this->preProcess();
$this->view();
return parent::run();
}
/**
* View summary details of a contact.
*/
public function view() {
$params = array();
$defaults = array();
$ids = array();
$params['id'] = $params['contact_id'] = $this->_contactId;
$contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, $ids);
$this->assign('pageTitle', $contact->sort_name);
return parent::view();
}
}

View file

@ -0,0 +1,298 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
class CRM_Contact_Page_View_Relationship extends CRM_Core_Page {
/**
* The action links that we need to display for the browse screen.
*
* @var array
*/
static $_links = NULL;
/**
* Casid set if called from case context.
*
* @var int
*/
public $_caseId = NULL;
public $_permission = NULL;
public $_contactId = NULL;
/**
* View details of a relationship.
*/
public function view() {
$viewRelationship = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId, NULL, NULL, NULL, $this->_id);
//To check whether selected contact is a contact_id_a in
//relationship type 'a_b' in relationship table, if yes then
//revert the permissionship text in template
$relationship = new CRM_Contact_DAO_Relationship();
$relationship->id = $viewRelationship[$this->_id]['id'];
if ($relationship->find(TRUE)) {
if (($viewRelationship[$this->_id]['rtype'] == 'a_b') && ($this->_contactId == $relationship->contact_id_a)) {
$this->assign("is_contact_id_a", TRUE);
}
}
$relType = $viewRelationship[$this->_id]['civicrm_relationship_type_id'];
$this->assign('viewRelationship', $viewRelationship);
$employerId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'employer_id');
$this->assign('isCurrentEmployer', FALSE);
$relTypes = CRM_Utils_Array::index(array('name_a_b'), CRM_Core_PseudoConstant::relationshipType('name'));
if ($viewRelationship[$this->_id]['employer_id'] == $this->_contactId) {
$this->assign('isCurrentEmployer', TRUE);
}
elseif ($relType == $relTypes['Employee of']['id'] &&
($viewRelationship[$this->_id]['cid'] == $employerId)
) {
// make sure we are viewing employee of relationship
$this->assign('isCurrentEmployer', TRUE);
}
$viewNote = CRM_Core_BAO_Note::getNote($this->_id);
$this->assign('viewNote', $viewNote);
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Relationship', NULL, $this->_id, 0, $relType);
CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_id);
$rType = CRM_Utils_Array::value('rtype', $viewRelationship[$this->_id]);
// add viewed contribution to recent items list
$url = CRM_Utils_System::url('civicrm/contact/view/rel',
"action=view&reset=1&id={$viewRelationship[$this->_id]['id']}&cid={$this->_contactId}&context=home"
);
$session = CRM_Core_Session::singleton();
$recentOther = array();
if (($session->get('userID') == $this->_contactId) ||
CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)
) {
$recentOther = array(
'editUrl' => CRM_Utils_System::url('civicrm/contact/view/rel',
"action=update&reset=1&id={$viewRelationship[$this->_id]['id']}&cid={$this->_contactId}&rtype={$rType}&context=home"
),
'deleteUrl' => CRM_Utils_System::url('civicrm/contact/view/rel',
"action=delete&reset=1&id={$viewRelationship[$this->_id]['id']}&cid={$this->_contactId}&rtype={$rType}&context=home"
),
);
}
$displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
$this->assign('displayName', $displayName);
CRM_Utils_System::setTitle(ts('View Relationship for') . ' ' . $displayName);
$title = $displayName . ' (' . $viewRelationship[$this->_id]['relation'] . ' ' . CRM_Contact_BAO_Contact::displayName($viewRelationship[$this->_id]['cid']) . ')';
// add the recently viewed Relationship
CRM_Utils_Recent::add($title,
$url,
$viewRelationship[$this->_id]['id'],
'Relationship',
$this->_contactId,
NULL,
$recentOther
);
}
/**
* called when action is browse.
*
*/
public function browse() {
// do nothing :) we are using datatable for rendering relationship selectors
}
/**
* called when action is update or new.
*
*/
public function edit() {
$controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_Relationship', ts('Contact Relationships'), $this->_action);
$controller->setEmbedded(TRUE);
// set the userContext stack
$session = CRM_Core_Session::singleton();
// if this is called from case view, we need to redirect back to same page
if ($this->_caseId) {
$url = CRM_Utils_System::url('civicrm/contact/view/case', "action=view&reset=1&cid={$this->_contactId}&id={$this->_caseId}");
}
else {
$url = CRM_Utils_System::url('civicrm/contact/view', "action=browse&selectedChild=rel&reset=1&cid={$this->_contactId}");
}
$session->pushUserContext($url);
if (CRM_Utils_Request::retrieve('confirmed', 'Boolean')) {
if ($this->_caseId) {
//create an activity for case role removal.CRM-4480
CRM_Case_BAO_Case::createCaseRoleActivity($this->_caseId, $this->_id);
CRM_Core_Session::setStatus(ts('Case Role has been deleted successfully.'), ts('Record Deleted'), 'success');
}
// delete relationship
CRM_Contact_BAO_Relationship::del($this->_id);
CRM_Utils_System::redirect($url);
}
$controller->set('contactId', $this->_contactId);
$controller->set('id', $this->_id);
$controller->process();
$controller->run();
}
public function preProcess() {
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
$this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
$this->assign('contactId', $this->_contactId);
// check logged in url permission
CRM_Contact_Page_View::checkUserPermission($this);
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
$this->assign('action', $this->_action);
}
/**
* the main function that is called when the page loads,
* it decides the which action has to be taken for the page.
*
* @return null
*/
public function run() {
$this->preProcess();
$this->setContext();
$this->_caseId = CRM_Utils_Request::retrieve('caseID', 'Integer', $this);
if ($this->_action & CRM_Core_Action::VIEW) {
$this->view();
}
elseif ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) {
$this->edit();
}
// if this is called from case view, suppress browse relationships form
else {
$this->browse();
}
return parent::run();
}
public function setContext() {
$context = CRM_Utils_Request::retrieve('context', 'String',
$this, FALSE, 'search'
);
if ($context == 'dashboard') {
$cid = CRM_Utils_Request::retrieve('cid', 'Integer',
$this, FALSE
);
$url = CRM_Utils_System::url('civicrm/user',
"reset=1&id={$cid}"
);
}
else {
$url = CRM_Utils_System::url('civicrm/contact/view', 'action=browse&selectedChild=rel');
}
$session = CRM_Core_Session::singleton();
$session->pushUserContext($url);
}
/**
* called to delete the relationship of a contact.
*
*/
public function delete() {
// calls a function to delete relationship
CRM_Contact_BAO_Relationship::del($this->_id);
}
/**
* Get action links.
*
* @return array
* (reference) of action links
*/
public static function &links() {
if (!(self::$_links)) {
self::$_links = array(
CRM_Core_Action::VIEW => array(
'name' => ts('View'),
'url' => 'civicrm/contact/view/rel',
'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%&selectedChild=rel',
'title' => ts('View Relationship'),
),
CRM_Core_Action::UPDATE => array(
'name' => ts('Edit'),
'url' => 'civicrm/contact/view/rel',
'qs' => 'action=update&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%',
'title' => ts('Edit Relationship'),
),
CRM_Core_Action::ENABLE => array(
'name' => ts('Enable'),
'ref' => 'crm-enable-disable',
'title' => ts('Enable Relationship'),
),
CRM_Core_Action::DISABLE => array(
'name' => ts('Disable'),
'ref' => 'crm-enable-disable',
'title' => ts('Disable Relationship'),
),
CRM_Core_Action::DELETE => array(
'name' => ts('Delete'),
'url' => 'civicrm/contact/view/rel',
'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%',
'title' => ts('Delete Relationship'),
),
// FIXME: Not sure what to put as the key.
// We want to use it differently later anyway (see CRM_Contact_BAO_Relationship::getRelationship). NONE should make it hidden by default.
CRM_Core_Action::NONE => array(
'name' => ts('Manage Case'),
'url' => 'civicrm/contact/view/case',
'qs' => 'action=view&reset=1&cid=%%clientid%%&id=%%caseid%%',
'title' => ts('Manage Case'),
),
);
}
return self::$_links;
}
}

View file

@ -0,0 +1,431 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* Main page for viewing contact.
*/
class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View {
/**
* Heart of the viewing process.
*
* The runner gets all the meta data for the contact and calls the appropriate type of page to view.
*/
public function preProcess() {
parent::preProcess();
// actions buttom contextMenu
$menuItems = CRM_Contact_BAO_Contact::contextMenu($this->_contactId);
$this->assign('actionsMenuList', $menuItems);
//retrieve inline custom data
$entityType = $this->get('contactType');
if ($entitySubType = $this->get('contactSubtype')) {
$entitySubType = explode(CRM_Core_DAO::VALUE_SEPARATOR,
trim($entitySubType, CRM_Core_DAO::VALUE_SEPARATOR)
);
}
$groupTree = CRM_Core_BAO_CustomGroup::getTree($entityType,
NULL,
$this->_contactId,
NULL,
$entitySubType
);
CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_contactId);
// also create the form element for the activity links box
$controller = new CRM_Core_Controller_Simple(
'CRM_Activity_Form_ActivityLinks',
ts('Activity Links'),
NULL,
FALSE,
FALSE,
TRUE
);
$controller->setEmbedded(TRUE);
$controller->run();
}
/**
* Heart of the viewing process.
*
* The runner gets all the meta data for the contact and calls the appropriate type of page to view.
*/
public function run() {
$this->preProcess();
if ($this->_action & CRM_Core_Action::UPDATE) {
$this->edit();
}
else {
$this->view();
}
return parent::run();
}
/**
* Edit name and address of a contact.
*/
public function edit() {
// set the userContext stack
$session = CRM_Core_Session::singleton();
$url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId);
$session->pushUserContext($url);
$controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_Contact', ts('Contact Page'), CRM_Core_Action::UPDATE);
$controller->setEmbedded(TRUE);
$controller->process();
return $controller->run();
}
/**
* View summary details of a contact.
*/
public function view() {
// Add js for tabs, in-place editing, and jstree for tags
CRM_Core_Resources::singleton()
->addScriptFile('civicrm', 'templates/CRM/Contact/Page/View/Summary.js', 2, 'html-header')
->addStyleFile('civicrm', 'css/contactSummary.css', 2, 'html-header')
->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
->addSetting(array(
'summaryPrint' => array('mode' => $this->_print),
'tabSettings' => array('active' => CRM_Utils_Request::retrieve('selectedChild', 'String', $this, FALSE, 'summary')),
));
$this->assign('summaryPrint', $this->_print);
$session = CRM_Core_Session::singleton();
$url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId);
$session->pushUserContext($url);
$this->assignFieldMetadataToTemplate('Contact');
$params = array();
$defaults = array();
$params['id'] = $params['contact_id'] = $this->_contactId;
$params['noRelationships'] = $params['noNotes'] = $params['noGroups'] = TRUE;
$contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, TRUE);
// Let summary page know if outbound mail is disabled so email links can be built conditionally
$mailingBackend = Civi::settings()->get('mailing_backend');
$this->assign('mailingOutboundOption', $mailingBackend['outBound_option']);
$communicationType = array(
'phone' => array(
'type' => 'phoneType',
'id' => 'phone_type',
'daoName' => 'CRM_Core_DAO_Phone',
'fieldName' => 'phone_type_id',
),
'im' => array(
'type' => 'IMProvider',
'id' => 'provider',
'daoName' => 'CRM_Core_DAO_IM',
'fieldName' => 'provider_id',
),
'website' => array(
'type' => 'websiteType',
'id' => 'website_type',
'daoName' => 'CRM_Core_DAO_Website',
'fieldName' => 'website_type_id',
),
'address' => array('skip' => TRUE, 'customData' => 1),
'email' => array('skip' => TRUE),
'openid' => array('skip' => TRUE),
);
foreach ($communicationType as $key => $value) {
if (!empty($defaults[$key])) {
foreach ($defaults[$key] as & $val) {
CRM_Utils_Array::lookupValue($val, 'location_type', CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name')), FALSE);
if (empty($value['skip'])) {
$daoName = $value['daoName'];
$pseudoConst = $daoName::buildOptions($value['fieldName'], 'get');
CRM_Utils_Array::lookupValue($val, $value['id'], $pseudoConst, FALSE);
}
}
if (isset($value['customData'])) {
foreach ($defaults[$key] as $blockId => $blockVal) {
$idValue = $blockVal['id'];
if ($key == 'address') {
if (!empty($blockVal['master_id'])) {
$idValue = $blockVal['master_id'];
}
}
$groupTree = CRM_Core_BAO_CustomGroup::getTree(ucfirst($key), NULL, $idValue);
// we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var.
$defaults[$key][$blockId]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, "dnc_");
}
// reset template variable since that won't be of any use, and could be misleading
$this->assign("dnc_viewCustomData", NULL);
}
}
}
if (!empty($defaults['gender_id'])) {
$defaults['gender_display'] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', 'gender_id', $defaults['gender_id']);
}
$communicationStyle = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'communication_style_id');
if (!empty($communicationStyle)) {
if (!empty($defaults['communication_style_id'])) {
$defaults['communication_style_display'] = $communicationStyle[CRM_Utils_Array::value('communication_style_id', $defaults)];
}
else {
// Make sure the field is displayed as long as it is active, even if it is unset for this contact.
$defaults['communication_style_display'] = '';
}
}
// to make contact type label available in the template -
$contactType = array_key_exists('contact_sub_type', $defaults) ? $defaults['contact_sub_type'] : $defaults['contact_type'];
$defaults['contact_type_label'] = CRM_Contact_BAO_ContactType::contactTypePairs(TRUE, $contactType, ', ');
// get contact tags
$contactTags = CRM_Core_BAO_EntityTag::getContactTags($this->_contactId);
if (!empty($contactTags)) {
$defaults['contactTag'] = $contactTags;
$defaults['allTags'] = CRM_Core_BAO_Tag::getTagsUsedFor('civicrm_contact', FALSE);
}
$defaults['privacy_values'] = CRM_Core_SelectValues::privacy();
//Show blocks only if they are visible in edit form
$this->_editOptions = CRM_Core_BAO_Setting::valueOptions(
CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'contact_edit_options'
);
foreach ($this->_editOptions as $blockName => $value) {
$varName = '_show' . $blockName;
$this->$varName = $value;
$this->assign(substr($varName, 1), $this->$varName);
}
// get contact name of shared contact names
$sharedAddresses = array();
$shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($defaults['address']);
foreach ($defaults['address'] as $key => $addressValue) {
if (!empty($addressValue['master_id']) &&
!$shareAddressContactNames[$addressValue['master_id']]['is_deleted']
) {
$sharedAddresses[$key]['shared_address_display'] = array(
'address' => $addressValue['display'],
'name' => $shareAddressContactNames[$addressValue['master_id']]['name'],
);
}
}
$this->assign('sharedAddresses', $sharedAddresses);
//get the current employer name
if (CRM_Utils_Array::value('contact_type', $defaults) == 'Individual') {
if ($contact->employer_id && $contact->organization_name) {
$defaults['current_employer'] = $contact->organization_name;
$defaults['current_employer_id'] = $contact->employer_id;
}
}
$defaults['external_identifier'] = $contact->external_identifier;
$this->assign($defaults);
// FIXME: when we sort out TZ isssues with DATETIME/TIMESTAMP, we can skip next query
// also assign the last modifed details
$lastModified = CRM_Core_BAO_Log::lastModified($this->_contactId, 'civicrm_contact');
$this->assign_by_ref('lastModified', $lastModified);
$allTabs = array();
$weight = 10;
$this->_viewOptions = CRM_Core_BAO_Setting::valueOptions(
CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'contact_view_options',
TRUE
);
// show the tabs only if user has generic access to CiviCRM
$accessCiviCRM = CRM_Core_Permission::check('access CiviCRM');
$changeLog = $this->_viewOptions['log'];
$this->assign_by_ref('changeLog', $changeLog);
$components = CRM_Core_Component::getEnabledComponents();
foreach ($components as $name => $component) {
if (!empty($this->_viewOptions[$name]) &&
CRM_Core_Permission::access($component->name)
) {
$elem = $component->registerTab();
// FIXME: not very elegant, probably needs better approach
// allow explicit id, if not defined, use keyword instead
if (array_key_exists('id', $elem)) {
$i = $elem['id'];
}
else {
$i = $component->getKeyword();
}
$u = $elem['url'];
//appending isTest to url for test soft credit CRM-3891.
//FIXME: hack ajax url.
$q = "reset=1&force=1&cid={$this->_contactId}";
if (CRM_Utils_Request::retrieve('isTest', 'Positive', $this)) {
$q .= "&isTest=1";
}
$allTabs[] = array(
'id' => $i,
'url' => CRM_Utils_System::url("civicrm/contact/view/$u", $q),
'title' => $elem['title'],
'weight' => $elem['weight'],
'count' => CRM_Contact_BAO_Contact::getCountComponent($u, $this->_contactId),
'class' => 'livePage',
);
// make sure to get maximum weight, rest of tabs go after
// FIXME: not very elegant again
if ($weight < $elem['weight']) {
$weight = $elem['weight'];
}
}
}
$rest = array(
'activity' => array(
'title' => ts('Activities'),
'class' => 'livePage',
),
'rel' => array(
'title' => ts('Relationships'),
'class' => 'livePage',
),
'group' => array(
'title' => ts('Groups'),
'class' => 'ajaxForm',
),
'note' => array(
'title' => ts('Notes'),
'class' => 'livePage',
),
'tag' => array(
'title' => ts('Tags'),
),
'log' => array(
'title' => ts('Change Log'),
),
);
foreach ($rest as $k => $v) {
if ($accessCiviCRM && !empty($this->_viewOptions[$k])) {
$allTabs[] = $v + array(
'id' => $k,
'url' => CRM_Utils_System::url(
"civicrm/contact/view/$k",
"reset=1&cid={$this->_contactId}"
),
'weight' => $weight,
'count' => CRM_Contact_BAO_Contact::getCountComponent($k, $this->_contactId),
);
$weight += 10;
}
}
// now add all the custom tabs
$entityType = $this->get('contactType');
$activeGroups = CRM_Core_BAO_CustomGroup::getActiveGroups(
$entityType,
'civicrm/contact/view/cd',
$this->_contactId
);
foreach ($activeGroups as $group) {
$id = "custom_{$group['id']}";
$allTabs[] = array(
'id' => $id,
'url' => CRM_Utils_System::url($group['path'], $group['query'] . "&selectedChild=$id"),
'title' => $group['title'],
'weight' => $weight,
'count' => CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $group['table_name']),
'hideCount' => !$group['is_multiple'],
'class' => 'livePage',
);
$weight += 10;
}
$context = array('contact_id' => $this->_contactId);
// see if any other modules want to add any tabs
CRM_Utils_Hook::tabs($allTabs, $this->_contactId);
CRM_Utils_Hook::tabset('civicrm/contact/view', $allTabs, $context);
$allTabs[] = array(
'id' => 'summary',
'url' => '#contact-summary',
'title' => ts('Summary'),
'weight' => 0,
);
// now sort the tabs based on weight
usort($allTabs, array('CRM_Utils_Sort', 'cmpFunc'));
$this->assign('allTabs', $allTabs);
// hook for contact summary
// ignored but needed to prevent warnings
$contentPlacement = CRM_Utils_Hook::SUMMARY_BELOW;
CRM_Utils_Hook::summary($this->_contactId, $content, $contentPlacement);
if ($content) {
$this->assign_by_ref('hookContent', $content);
$this->assign('hookContentPlacement', $contentPlacement);
}
}
/**
* @return string
*/
public function getTemplateFileName() {
if ($this->_contactId) {
$contactSubtypes = $this->get('contactSubtype') ? explode(CRM_Core_DAO::VALUE_SEPARATOR, $this->get('contactSubtype')) : array();
// there could be multiple subtypes. We check templates for each of the subtype, and return the first one found.
foreach ($contactSubtypes as $csType) {
if ($csType) {
$templateFile = "CRM/Contact/Page/View/SubType/{$csType}.tpl";
$template = CRM_Core_Page::getTemplate();
if ($template->template_exists($templateFile)) {
return $templateFile;
}
}
}
}
return parent::getTemplateFileName();
}
}

View file

@ -0,0 +1,77 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
class CRM_Contact_Page_View_Tag extends CRM_Core_Page {
/**
* Called when action is browse.
*/
public function browse() {
$controller = new CRM_Core_Controller_Simple('CRM_Tag_Form_Tag', ts('Contact Tags'), $this->_action);
$controller->setEmbedded(TRUE);
// set the userContext stack
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/contact/view', 'action=browse&selectedChild=tag'), FALSE);
$controller->reset();
$controller->set('contactId', $this->_contactId);
$controller->process();
$controller->run();
}
public function preProcess() {
$this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
$this->assign('contactId', $this->_contactId);
// check logged in url permission
CRM_Contact_Page_View::checkUserPermission($this);
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
$this->assign('action', $this->_action);
}
/**
* the main function that is called when the page loads
* it decides the which action has to be taken for the page.
*
* @return null
*/
public function run() {
$this->preProcess();
$this->browse();
return parent::run();
}
}

View file

@ -0,0 +1,251 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class is used to build User Dashboard
*/
class CRM_Contact_Page_View_UserDashBoard extends CRM_Core_Page {
public $_contactId = NULL;
/**
* Always show public groups.
* @var bool
*/
public $_onlyPublicGroups = TRUE;
public $_edit = TRUE;
/**
* The action links that we need to display for the browse screen.
*
* @var array
*/
static $_links = NULL;
/**
* @throws Exception
*/
public function __construct() {
parent::__construct();
$check = CRM_Core_Permission::check('access Contact Dashboard');
if (!$check) {
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/dashboard', 'reset=1'));
}
$this->_contactId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
$session = CRM_Core_Session::singleton();
$userID = $session->get('userID');
if (!$this->_contactId) {
$this->_contactId = $userID;
}
elseif ($this->_contactId != $userID) {
if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::VIEW)) {
CRM_Core_Error::fatal(ts('You do not have permission to access this contact.'));
}
if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) {
$this->_edit = FALSE;
}
}
}
/**
* Heart of the viewing process.
*
* The runner gets all the meta data for the contact and calls the appropriate type of page to view.
*/
public function preProcess() {
if (!$this->_contactId) {
CRM_Core_Error::fatal(ts('You must be logged in to view this page.'));
}
list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($this->_contactId);
$this->set('displayName', $displayName);
$this->set('contactImage', $contactImage);
CRM_Utils_System::setTitle(ts('Dashboard - %1', array(1 => $displayName)));
$this->assign('recentlyViewed', FALSE);
}
/**
* Build user dashboard.
*/
public function buildUserDashBoard() {
//build component selectors
$dashboardElements = array();
$config = CRM_Core_Config::singleton();
$this->_userOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'user_dashboard_options'
);
$components = CRM_Core_Component::getEnabledComponents();
$this->assign('contactId', $this->_contactId);
foreach ($components as $name => $component) {
$elem = $component->getUserDashboardElement();
if (!$elem) {
continue;
}
if (!empty($this->_userOptions[$name]) &&
(CRM_Core_Permission::access($component->name) ||
CRM_Core_Permission::check($elem['perm'][0])
)
) {
$userDashboard = $component->getUserDashboardObject();
$dashboardElements[] = array(
'class' => 'crm-dashboard-' . strtolower($component->name),
'sectionTitle' => $elem['title'],
'templatePath' => $userDashboard->getTemplateFileName(),
'weight' => $elem['weight'],
);
$userDashboard->run();
}
}
// CRM-16512 - Hide related contact table if user lacks permission to view self
if (!empty($this->_userOptions['Permissioned Orgs']) && CRM_Core_Permission::check('view my contact')) {
$dashboardElements[] = array(
'class' => 'crm-dashboard-permissionedOrgs',
'templatePath' => 'CRM/Contact/Page/View/RelationshipSelector.tpl',
'sectionTitle' => ts('Your Contacts / Organizations'),
'weight' => 40,
);
}
if (!empty($this->_userOptions['PCP'])) {
$dashboardElements[] = array(
'class' => 'crm-dashboard-pcp',
'templatePath' => 'CRM/Contribute/Page/PcpUserDashboard.tpl',
'sectionTitle' => ts('Personal Campaign Pages'),
'weight' => 40,
);
list($pcpBlock, $pcpInfo) = CRM_PCP_BAO_PCP::getPcpDashboardInfo($this->_contactId);
$this->assign('pcpBlock', $pcpBlock);
$this->assign('pcpInfo', $pcpInfo);
}
if (!empty($this->_userOptions['Assigned Activities'])) {
// Assigned Activities section
$dashboardElements[] = array(
'class' => 'crm-dashboard-assignedActivities',
'templatePath' => 'CRM/Activity/Page/UserDashboard.tpl',
'sectionTitle' => ts('Your Assigned Activities'),
'weight' => 5,
);
$userDashboard = new CRM_Activity_Page_UserDashboard();
$userDashboard->run();
}
usort($dashboardElements, array('CRM_Utils_Sort', 'cmpFunc'));
$this->assign('dashboardElements', $dashboardElements);
// return true when 'Invoices / Credit Notes' checkbox is checked
$this->assign('invoices', $this->_userOptions['Invoices / Credit Notes']);
if (!empty($this->_userOptions['Groups'])) {
$this->assign('showGroup', TRUE);
//build group selector
$gContact = new CRM_Contact_Page_View_UserDashBoard_GroupContact();
$gContact->run();
}
else {
$this->assign('showGroup', FALSE);
}
}
/**
* Perform actions and display for user dashboard.
*/
public function run() {
$this->preProcess();
$this->buildUserDashBoard();
return parent::run();
}
/**
* Get action links.
*
* @return array
* (reference) of action links
*/
public static function &links() {
if (!(self::$_links)) {
$disableExtra = ts('Are you sure you want to disable this relationship?');
self::$_links = array(
CRM_Core_Action::UPDATE => array(
'name' => ts('Edit Contact Information'),
'url' => 'civicrm/contact/relatedcontact',
'qs' => 'action=update&reset=1&cid=%%cbid%%&rcid=%%cid%%',
'title' => ts('Edit Relationship'),
),
CRM_Core_Action::VIEW => array(
'name' => ts('Dashboard'),
'url' => 'civicrm/user',
'class' => 'no-popup',
'qs' => 'reset=1&id=%%cbid%%',
'title' => ts('View Relationship'),
),
);
if (CRM_Core_Permission::check('access CiviCRM')) {
self::$_links = array_merge(self::$_links, array(
CRM_Core_Action::DISABLE => array(
'name' => ts('Disable'),
'url' => 'civicrm/contact/view/rel',
'qs' => 'action=disable&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%&selectedChild=rel&context=dashboard',
'extra' => 'onclick = "return confirm(\'' . $disableExtra . '\');"',
'title' => ts('Disable Relationship'),
),
));
}
}
// call the hook so we can modify it
CRM_Utils_Hook::links('view.contact.userDashBoard',
'Contact',
CRM_Core_DAO::$_nullObject,
self::$_links
);
return self::$_links;
}
}

View file

@ -0,0 +1,139 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
class CRM_Contact_Page_View_UserDashBoard_GroupContact extends CRM_Contact_Page_View_UserDashBoard {
/**
* Called when action is browse.
*/
public function browse() {
$count = CRM_Contact_BAO_GroupContact::getContactGroup(
$this->_contactId,
NULL,
NULL, TRUE, TRUE,
$this->_onlyPublicGroups,
NULL, NULL, TRUE
);
$in = CRM_Contact_BAO_GroupContact::getContactGroup(
$this->_contactId,
'Added',
NULL, FALSE, TRUE,
$this->_onlyPublicGroups,
NULL, NULL, TRUE
);
$pending = CRM_Contact_BAO_GroupContact::getContactGroup(
$this->_contactId,
'Pending',
NULL, FALSE, TRUE,
$this->_onlyPublicGroups,
NULL, NULL, TRUE
);
$out = CRM_Contact_BAO_GroupContact::getContactGroup(
$this->_contactId,
'Removed',
NULL, FALSE, TRUE,
$this->_onlyPublicGroups,
NULL, NULL, TRUE
);
$this->assign('groupCount', $count);
$this->assign_by_ref('groupIn', $in);
$this->assign_by_ref('groupPending', $pending);
$this->assign_by_ref('groupOut', $out);
}
/**
* called when action is update.
*
* @param int $groupId
*
* @return null
*/
public function edit($groupId = NULL) {
$this->assign('edit', $this->_edit);
if (!$this->_edit) {
return NULL;
}
$action = CRM_Utils_Request::retrieve('action', 'String',
CRM_Core_DAO::$_nullObject,
FALSE, 'browse'
);
if ($action == CRM_Core_Action::DELETE) {
$groupContactId = CRM_Utils_Request::retrieve('gcid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE);
$status = CRM_Utils_Request::retrieve('st', 'String', CRM_Core_DAO::$_nullObject, TRUE);
if (is_numeric($groupContactId) && $status) {
CRM_Contact_Page_View_GroupContact::del($groupContactId, $status, $this->_contactId);
}
$url = CRM_Utils_System::url('civicrm/user', "reset=1&id={$this->_contactId}");
CRM_Utils_System::redirect($url);
}
$controller = new CRM_Core_Controller_Simple(
'CRM_Contact_Form_GroupContact',
ts("Contact's Groups"),
CRM_Core_Action::ADD,
FALSE, FALSE, TRUE, FALSE
);
$controller->setEmbedded(TRUE);
$session = CRM_Core_Session::singleton();
$session->pushUserContext(
CRM_Utils_System::url('civicrm/user', "reset=1&id={$this->_contactId}"),
FALSE
);
$controller->reset();
$controller->set('contactId', $this->_contactId);
$controller->set('groupId', $groupId);
$controller->set('context', 'user');
$controller->set('onlyPublicGroups', $this->_onlyPublicGroups);
$controller->process();
$controller->run();
}
/**
* The main function that is called when the page loads.
*
* It decides the which action has to be taken for the page.
*/
public function run() {
$this->edit();
$this->browse();
}
}

View file

@ -0,0 +1,56 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
*/
/**
* Dummy page for details of Email.
*/
class CRM_Contact_Page_View_Useradd extends CRM_Core_Page {
/**
* Run the page.
*
* This method is called after the page is created.
*/
public function run() {
$controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_Task_Useradd',
ts('Add User'),
CRM_Core_Action::ADD
);
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
return parent::run();
}
}

View file

@ -0,0 +1,171 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
require_once 'Contact/Vcard/Build.php';
/**
* vCard export class.
*/
class CRM_Contact_Page_View_Vcard extends CRM_Contact_Page_View {
/**
* Heart of the vCard data assignment process.
*
* The runner gets all the metadata for the contact and calls the writeVcard method to output the vCard
* to the user.
*/
public function run() {
$this->preProcess();
$params = array();
$defaults = array();
$ids = array();
$params['id'] = $params['contact_id'] = $this->_contactId;
$contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, $ids);
// now that we have the contact's data - let's build the vCard
// TODO: non-US-ASCII support (requires changes to the Contact_Vcard_Build class)
$vcardNames = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'vcard_name'));
$vcard = new Contact_Vcard_Build('2.1');
if ($defaults['contact_type'] == 'Individual') {
$vcard->setName(CRM_Utils_Array::value('last_name', $defaults),
CRM_Utils_Array::value('first_name', $defaults),
CRM_Utils_Array::value('middle_name', $defaults),
CRM_Utils_Array::value('prefix', $defaults),
CRM_Utils_Array::value('suffix', $defaults)
);
$organizationName = CRM_Utils_Array::value('organization_name', $defaults);
if ($organizationName !== NULL) {
$vcard->addOrganization($organizationName);
}
}
elseif ($defaults['contact_type'] == 'Organization') {
$vcard->setName($defaults['organization_name'], '', '', '', '');
}
elseif ($defaults['contact_type'] == 'Household') {
$vcard->setName($defaults['household_name'], '', '', '', '');
}
$vcard->setFormattedName($defaults['display_name']);
$vcard->setSortString($defaults['sort_name']);
if (!empty($defaults['nick_name'])) {
$vcard->addNickname($defaults['nick_name']);
}
if (!empty($defaults['job_title'])) {
$vcard->setTitle($defaults['job_title']);
}
if (!empty($defaults['birth_date'])) {
$vcard->setBirthday(CRM_Utils_Array::value('birth_date', $defaults));
}
if (!empty($defaults['home_URL'])) {
$vcard->setURL($defaults['home_URL']);
}
// TODO: $vcard->setGeo($lat, $lon);
if (!empty($defaults['address'])) {
$stateProvices = CRM_Core_PseudoConstant::stateProvince();
$countries = CRM_Core_PseudoConstant::country();
foreach ($defaults['address'] as $location) {
// we don't keep PO boxes in separate fields
$pob = '';
$extend = CRM_Utils_Array::value('supplemental_address_1', $location);
if (!empty($location['supplemental_address_2'])) {
$extend .= ', ' . $location['supplemental_address_2'];
}
if (!empty($location['supplemental_address_3'])) {
$extend .= ', ' . $location['supplemental_address_3'];
}
$street = CRM_Utils_Array::value('street_address', $location);
$locality = CRM_Utils_Array::value('city', $location);
$region = NULL;
if (!empty($location['state_province_id'])) {
$region = $stateProvices[CRM_Utils_Array::value('state_province_id', $location)];
}
$country = NULL;
if (!empty($location['country_id'])) {
$country = $countries[CRM_Utils_Array::value('country_id', $location)];
}
$postcode = CRM_Utils_Array::value('postal_code', $location);
if (!empty($location['postal_code_suffix'])) {
$postcode .= '-' . $location['postal_code_suffix'];
}
$vcard->addAddress($pob, $extend, $street, $locality, $region, $postcode, $country);
$vcardName = $vcardNames[$location['location_type_id']];
if ($vcardName) {
$vcard->addParam('TYPE', $vcardName);
}
if (!empty($location['is_primary'])) {
$vcard->addParam('TYPE', 'PREF');
}
}
}
if (!empty($defaults['phone'])) {
foreach ($defaults['phone'] as $phone) {
$vcard->addTelephone($phone['phone']);
$vcardName = $vcardNames[$phone['location_type_id']];
if ($vcardName) {
$vcard->addParam('TYPE', $vcardName);
}
if ($phone['is_primary']) {
$vcard->addParam('TYPE', 'PREF');
}
}
}
if (!empty($defaults['email'])) {
foreach ($defaults['email'] as $email) {
$vcard->addEmail($email['email']);
$vcardName = $vcardNames[$email['location_type_id']];
if ($vcardName) {
$vcard->addParam('TYPE', $vcardName);
}
if ($email['is_primary']) {
$vcard->addParam('TYPE', 'PREF');
}
}
}
// all that's left is sending the vCard to the browser
$filename = CRM_Utils_String::munge($defaults['display_name']);
$vcard->send($filename . '.vcf', 'attachment', 'utf-8');
CRM_Utils_System::civiExit();
}
}