/** * Create a new group * * @param array $params Associative array of parameters * @return object|null The new group BAO (if created) * @access public * @static */ public static function &create(&$params) { require_once 'CRM/Utils/Hook.php'; if (CRM_Utils_Array::value('id', $params)) { CRM_Utils_Hook::pre('edit', 'Group', $params['id'], $params); } else { CRM_Utils_Hook::pre('create', 'Group', null, $params); } // form the name only if missing: CRM-627 if (!CRM_Utils_Array::value('name', $params)) { require_once 'CRM/Utils/String.php'; $params['name'] = CRM_Utils_String::titleToVar($params['title']); } // convert params if array type if (isset($params['group_type'])) { if (is_array($params['group_type'])) { $params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['group_type'])) . CRM_Core_DAO::VALUE_SEPARATOR; } } else { $params['group_type'] = ''; } $group =& new CRM_Contact_BAO_Group(); $group->copyValues($params); $group->save(); if (!$group->id) { return null; } $group->buildClause(); $group->save(); // add custom field values if (CRM_Utils_Array::value('custom', $params)) { require_once 'CRM/Core/BAO/CustomValueTable.php'; CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_group', $group->id); } // make the group, child of domain/site group by default. require_once 'CRM/Contact/BAO/GroupContactCache.php'; require_once 'CRM/Core/BAO/Domain.php'; require_once 'CRM/Contact/BAO/GroupNesting.php'; $domainGroupID = CRM_Core_BAO_Domain::getGroupId(); if (CRM_Utils_Array::value('no_parent', $params) !== 1) { if (defined('CIVICRM_MULTISITE') && CIVICRM_MULTISITE && empty($params['parents']) && $domainGroupID != $group->id && !CRM_Contact_BAO_GroupNesting::hasParentGroups($group->id)) { // if no parent present and the group doesn't already have any parents, // make sure site group goes as parent $params['parents'] = array($domainGroupID => 1); } else { if (!is_array($params['parents'])) { $params['parents'] = array($params['parents'] => 1); } } foreach ($params['parents'] as $parentId => $dnc) { if ($parentId && !CRM_Contact_BAO_GroupNesting::isParentChild($parentId, $group->id)) { CRM_Contact_BAO_GroupNesting::add($parentId, $group->id); } } // clear any descendant groups cache if exists require_once 'CRM/Core/BAO/Cache.php'; $finalGroups =& CRM_Core_BAO_Cache::deleteGroup('descendant groups for an org'); // this is always required, since we don't know when a // parent group is removed require_once 'CRM/Contact/BAO/GroupNestingCache.php'; CRM_Contact_BAO_GroupNestingCache::update(); // update group contact cache for all parent groups $parentIds = CRM_Contact_BAO_GroupNesting::getParentGroupIds($group->id); foreach ($parentIds as $parentId) { CRM_Contact_BAO_GroupContactCache::add($parentId); } } if (CRM_Utils_Array::value('organization_id', $params)) { require_once 'CRM/Contact/BAO/GroupOrganization.php'; $groupOrg = array(); $groupOrg = $params; $groupOrg['group_id'] = $group->id; CRM_Contact_BAO_GroupOrganization::add($groupOrg); } CRM_Contact_BAO_GroupContactCache::add($group->id); if (CRM_Utils_Array::value('id', $params)) { CRM_Utils_Hook::post('edit', 'Group', $group->id, $group); } else { CRM_Utils_Hook::post('create', 'Group', $group->id, $group); } return $group; }
/** * 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() { // process url params $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); $this->assign('id', $this->_id); $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); //validate the qfKey if (!CRM_Utils_Rule::qfKey($qfKey)) { $qfKey = NULL; } $this->assign('searchKey', $qfKey); // retrieve the group contact id, so that we can get contact id $gcid = CRM_Utils_Request::retrieve('gcid', 'Positive', $this); if (!$gcid) { $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); } else { $this->_contactId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_GroupContact', $gcid, 'contact_id'); } if (!$this->_contactId) { CRM_Core_Error::statusBounce(ts('We could not find a contact id.'), CRM_Utils_System::url('civicrm/dashboard', 'reset=1')); } // ensure that the id does exist if (CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'id') != $this->_contactId) { CRM_Core_Error::statusBounce(ts('A Contact with that ID does not exist: %1', array(1 => $this->_contactId)), CRM_Utils_System::url('civicrm/dashboard', 'reset=1')); } $this->assign('contactId', $this->_contactId); // see if we can get prev/next positions from qfKey $navContacts = array('prevContactID' => NULL, 'prevContactName' => NULL, 'nextContactID' => NULL, 'nextContactName' => NULL, 'nextPrevError' => 0); if ($qfKey) { $pos = CRM_Core_BAO_PrevNextCache::getPositions("civicrm search {$qfKey}", $this->_contactId, $this->_contactId); $found = FALSE; if (isset($pos['prev'])) { $navContacts['prevContactID'] = $pos['prev']['id1']; $navContacts['prevContactName'] = $pos['prev']['data']; $found = TRUE; } if (isset($pos['next'])) { $navContacts['nextContactID'] = $pos['next']['id1']; $navContacts['nextContactName'] = $pos['next']['data']; $found = TRUE; } $context = CRM_Utils_Array::value('context', $_GET); if (!$found) { // seems like we did not find any contacts // maybe due to bug CRM-9096 // however we should account for 1 contact results (which dont have prev next) if (!$pos['foundEntry']) { $navContacts['nextPrevError'] = 1; } } elseif ($context) { $this->assign('context', $context); CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Search Results'), 'url' => CRM_Utils_System::url("civicrm/contact/search/{$context}", array('qfKey' => $qfKey))))); } } $this->assign($navContacts); $path = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId); CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('View Contact'), 'url' => $path))); if ($image_URL = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'image_URL')) { //CRM-7265 --time being fix. $config = CRM_Core_Config::singleton(); $image_URL = str_replace('https://', 'http://', $image_URL); if (Civi::settings()->get('enableSSL')) { $image_URL = str_replace('http://', 'https://', $image_URL); } list($imageWidth, $imageHeight) = getimagesize(CRM_Utils_String::unstupifyUrl($image_URL)); list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight); $this->assign("imageWidth", $imageWidth); $this->assign("imageHeight", $imageHeight); $this->assign("imageThumbWidth", $imageThumbWidth); $this->assign("imageThumbHeight", $imageThumbHeight); $this->assign("imageURL", $image_URL); } // also store in session for future use $session = CRM_Core_Session::singleton(); $session->set('view.id', $this->_contactId); $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); $this->assign('action', $this->_action); // check logged in user permission self::checkUserPermission($this); list($displayName, $contactImage, $contactType, $contactSubtype, $contactImageUrl) = self::getContactDetails($this->_contactId); $this->assign('displayName', $displayName); $this->set('contactType', $contactType); // note: there could still be multiple subtypes. We just trimming the outer separator. $this->set('contactSubtype', trim($contactSubtype, CRM_Core_DAO::VALUE_SEPARATOR)); // add to recently viewed block $isDeleted = (bool) CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'is_deleted'); $recentOther = array('imageUrl' => $contactImageUrl, 'subtype' => $contactSubtype, 'isDeleted' => $isDeleted); if (CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/add', "reset=1&action=update&cid={$this->_contactId}"); } if ($session->get('userID') != $this->_contactId && CRM_Core_Permission::check('delete contacts') && !$isDeleted) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/delete', "reset=1&delete=1&cid={$this->_contactId}"); } CRM_Utils_Recent::add($displayName, CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_contactId}"), $this->_contactId, $contactType, $this->_contactId, $displayName, $recentOther); $this->assign('isDeleted', $isDeleted); // set page title $title = self::setTitle($this->_contactId, $isDeleted); $this->assign('title', $title); // Check if this is default domain contact CRM-10482 if (CRM_Contact_BAO_Contact::checkDomainContact($this->_contactId)) { $this->assign('domainContact', TRUE); } else { $this->assign('domainContact', FALSE); } // Add links for actions menu self::addUrls($this, $this->_contactId); if ($contactType == 'Organization' && CRM_Core_Permission::check('administer Multiple Organizations') && Civi::settings()->get('is_enabled')) { //check is any relationship between the organization and groups $groupOrg = CRM_Contact_BAO_GroupOrganization::hasGroupAssociated($this->_contactId); if ($groupOrg) { $groupOrganizationUrl = CRM_Utils_System::url('civicrm/group', "reset=1&oid={$this->_contactId}"); $this->assign('groupOrganizationUrl', $groupOrganizationUrl); } } }
/** * Create a new group. * * @param array $params * * @return CRM_Contact_BAO_Group|NULL * The new group BAO (if created) */ public static function &create(&$params) { if (!empty($params['id'])) { CRM_Utils_Hook::pre('edit', 'Group', $params['id'], $params); } else { CRM_Utils_Hook::pre('create', 'Group', NULL, $params); } // form the name only if missing: CRM-627 $nameParam = CRM_Utils_Array::value('name', $params, NULL); if (!$nameParam && empty($params['id'])) { $params['name'] = CRM_Utils_String::titleToVar($params['title']); } // convert params if array type if (isset($params['group_type'])) { if (is_array($params['group_type'])) { $params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['group_type'])) . CRM_Core_DAO::VALUE_SEPARATOR; } } else { $params['group_type'] = ''; } $session = CRM_Core_Session::singleton(); $cid = $session->get('userID'); // this action is add if ($cid && empty($params['id'])) { $params['created_id'] = $cid; } // this action is update if ($cid && !empty($params['id'])) { $params['modified_id'] = $cid; } $group = new CRM_Contact_BAO_Group(); $group->copyValues($params); //@todo very hacky fix for the fact this function wants to receive 'parents' as an array further down but // needs it as a separated string for the DB. Preferred approaches are having the copyParams or save fn // use metadata to translate the array to the appropriate DB type or altering the param in the api layer, // or at least altering the param in same section as 'group_type' rather than repeating here. However, further down // we need the $params one to be in it's original form & we are not sure what test coverage we have on that if (isset($group->parents) && is_array($group->parents)) { $group->parents = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($group->parents)) . CRM_Core_DAO::VALUE_SEPARATOR; } if (empty($params['id']) && !$nameParam) { $group->name .= "_tmp"; } $group->save(); if (!$group->id) { return NULL; } if (empty($params['id']) && !$nameParam) { $group->name = substr($group->name, 0, -4) . "_{$group->id}"; } $group->buildClause(); $group->save(); // add custom field values if (!empty($params['custom'])) { CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_group', $group->id); } // make the group, child of domain/site group by default. $domainGroupID = CRM_Core_BAO_Domain::getGroupId(); if (CRM_Utils_Array::value('no_parent', $params) !== 1) { if (empty($params['parents']) && $domainGroupID != $group->id && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME, 'is_enabled') && !CRM_Contact_BAO_GroupNesting::hasParentGroups($group->id)) { // if no parent present and the group doesn't already have any parents, // make sure site group goes as parent $params['parents'] = array($domainGroupID => 1); } elseif (array_key_exists('parents', $params) && !is_array($params['parents'])) { $params['parents'] = array($params['parents'] => 1); } if (!empty($params['parents'])) { foreach ($params['parents'] as $parentId => $dnc) { if ($parentId && !CRM_Contact_BAO_GroupNesting::isParentChild($parentId, $group->id)) { CRM_Contact_BAO_GroupNesting::add($parentId, $group->id); } } } // clear any descendant groups cache if exists $finalGroups = CRM_Core_BAO_Cache::deleteGroup('descendant groups for an org'); // this is always required, since we don't know when a // parent group is removed CRM_Contact_BAO_GroupNestingCache::update(); // update group contact cache for all parent groups $parentIds = CRM_Contact_BAO_GroupNesting::getParentGroupIds($group->id); foreach ($parentIds as $parentId) { CRM_Contact_BAO_GroupContactCache::add($parentId); } } if (!empty($params['organization_id'])) { $groupOrg = array(); $groupOrg = $params; $groupOrg['group_id'] = $group->id; CRM_Contact_BAO_GroupOrganization::add($groupOrg); } CRM_Contact_BAO_GroupContactCache::add($group->id); if (!empty($params['id'])) { CRM_Utils_Hook::post('edit', 'Group', $group->id, $group); } else { CRM_Utils_Hook::post('create', 'Group', $group->id, $group); } $recentOther = array(); if (CRM_Core_Permission::check('edit groups')) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/group', 'reset=1&action=update&id=' . $group->id); // currently same permission we are using for delete a group $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/group', 'reset=1&action=delete&id=' . $group->id); } // add the recently added group (unless hidden: CRM-6432) if (!$group->is_hidden) { CRM_Utils_Recent::add($group->title, CRM_Utils_System::url('civicrm/group/search', 'reset=1&force=1&context=smog&gid=' . $group->id), $group->id, 'Group', NULL, NULL, $recentOther); } return $group; }
/** * Deletes an existing Group Organization * * This API is used for deleting a Group Organization * * @param Array $params ID of the Group Organization to be deleted * * @return null if successfull, array with is_error = 1 otherwise * @access public */ function civicrm_group_organization_remove(&$params) { _civicrm_initialize(); if (!is_array($params)) { $error = civicrm_create_error('Input parameter is not an array'); return $error; } if (empty($params)) { return civicrm_create_error('No input parameter present'); } if (!CRM_Utils_Array::value('id', $params)) { $error = civicrm_create_error('Invalid or no value for Group Organization ID'); return $error; } require_once 'CRM/Contact/BAO/GroupOrganization.php'; $result = CRM_Contact_BAO_GroupOrganization::delete($params); return $result ? civicrm_create_success(ts('Deleted Group Organization successfully')) : civicrm_create_error(ts('Could not delete Group Organization')); }
function setDefaultValues() { $defaults = array(); if (isset($this->_id)) { $defaults = $this->_groupValues; if (CRM_Utils_Array::value('group_type', $defaults)) { $types = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($defaults['group_type'], 1, -1)); $defaults['group_type'] = array(); foreach ($types as $type) { $defaults['group_type'][$type] = 1; } } if (defined('CIVICRM_MULTISITE') && CIVICRM_MULTISITE && CRM_Core_Permission::check('administer Multiple Organizations')) { require_once 'CRM/Contact/BAO/GroupOrganization.php'; CRM_Contact_BAO_GroupOrganization::retrieve($this->_id, $defaults); if (CRM_Utils_Array::value('group_organization', $defaults)) { //used in edit mode $this->_groupOrganizationID = $defaults['group_organization']; } $this->assign('organizationID', $defaults['organization_id']); } } if (!CRM_Utils_Array::value('parents', $defaults)) { $defaults['parents'] = CRM_Core_BAO_Domain::getGroupId(); } // custom data set defaults $defaults += CRM_Custom_Form_Customdata::setDefaultValues($this); return $defaults; }
/** * Set default values for the form. * * @return array */ public function setDefaultValues() { $defaults = array(); if (isset($this->_id)) { $defaults = $this->_groupValues; if (!empty($defaults['group_type'])) { $types = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($defaults['group_type'], 1, -1)); $defaults['group_type'] = array(); foreach ($types as $type) { $defaults['group_type'][$type] = 1; } } if (CRM_Core_Permission::check('administer Multiple Organizations') && CRM_Core_Permission::isMultisiteEnabled()) { CRM_Contact_BAO_GroupOrganization::retrieve($this->_id, $defaults); } } if (!(CRM_Core_Permission::check('access CiviMail') || CRM_Mailing_Info::workflowEnabled() && CRM_Core_Permission::check('create mailings'))) { $groupTypes = CRM_Core_OptionGroup::values('group_type', TRUE); if ($defaults['group_type'][$groupTypes['Mailing List']] == 1) { $this->assign('freezeMailignList', $groupTypes['Mailing List']); } else { $this->assign('hideMailignList', $groupTypes['Mailing List']); } } if (empty($defaults['parents'])) { $defaults['parents'] = CRM_Core_BAO_Domain::getGroupId(); } // custom data set defaults $defaults += CRM_Custom_Form_CustomData::setDefaultValues($this); return $defaults; }
/** * Create a new group * * @param array $params Associative array of parameters * * @return object|null The new group BAO (if created) * @access public * @static */ public static function &create(&$params) { if (CRM_Utils_Array::value('id', $params)) { CRM_Utils_Hook::pre('edit', 'Group', $params['id'], $params); } else { CRM_Utils_Hook::pre('create', 'Group', NULL, $params); } // form the name only if missing: CRM-627 if (!CRM_Utils_Array::value('name', $params) && !CRM_Utils_Array::value('id', $params)) { $params['name'] = CRM_Utils_String::titleToVar($params['title']); } // convert params if array type if (isset($params['group_type'])) { if (is_array($params['group_type'])) { $params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['group_type'])) . CRM_Core_DAO::VALUE_SEPARATOR; } } else { $params['group_type'] = ''; } $group = new CRM_Contact_BAO_Group(); $group->copyValues($params); if (!CRM_Utils_Array::value('id', $params)) { $group->name .= "_tmp"; } $group->save(); if (!$group->id) { return NULL; } if (!CRM_Utils_Array::value('id', $params)) { $group->name = substr($group->name, 0, -4) . "_{$group->id}"; } $group->buildClause(); $group->save(); // add custom field values if (CRM_Utils_Array::value('custom', $params)) { CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_group', $group->id); } // make the group, child of domain/site group by default. $domainGroupID = CRM_Core_BAO_Domain::getGroupId(); if (CRM_Utils_Array::value('no_parent', $params) !== 1) { if (empty($params['parents']) && $domainGroupID != $group->id && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME, 'is_enabled') && !CRM_Contact_BAO_GroupNesting::hasParentGroups($group->id)) { // if no parent present and the group doesn't already have any parents, // make sure site group goes as parent $params['parents'] = array($domainGroupID => 1); } elseif (array_key_exists('parents', $params) && !is_array($params['parents'])) { $params['parents'] = array($params['parents'] => 1); } if (!empty($params['parents'])) { foreach ($params['parents'] as $parentId => $dnc) { if ($parentId && !CRM_Contact_BAO_GroupNesting::isParentChild($parentId, $group->id)) { CRM_Contact_BAO_GroupNesting::add($parentId, $group->id); } } } // clear any descendant groups cache if exists $finalGroups = CRM_Core_BAO_Cache::deleteGroup('descendant groups for an org'); // this is always required, since we don't know when a // parent group is removed CRM_Contact_BAO_GroupNestingCache::update(); // update group contact cache for all parent groups $parentIds = CRM_Contact_BAO_GroupNesting::getParentGroupIds($group->id); foreach ($parentIds as $parentId) { CRM_Contact_BAO_GroupContactCache::add($parentId); } } if (CRM_Utils_Array::value('organization_id', $params)) { $groupOrg = array(); $groupOrg = $params; $groupOrg['group_id'] = $group->id; CRM_Contact_BAO_GroupOrganization::add($groupOrg); } CRM_Contact_BAO_GroupContactCache::add($group->id); if (CRM_Utils_Array::value('id', $params)) { CRM_Utils_Hook::post('edit', 'Group', $group->id, $group); } else { CRM_Utils_Hook::post('create', 'Group', $group->id, $group); } $recentOther = array(); if (CRM_Core_Permission::check('edit groups')) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/group', 'reset=1&action=update&id=' . $group->id); // currently same permission we are using for delete a group $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/group', 'reset=1&action=delete&id=' . $group->id); } // add the recently added group (unless hidden: CRM-6432) if (!$group->is_hidden) { CRM_Utils_Recent::add($group->title, CRM_Utils_System::url('civicrm/group/search', 'reset=1&force=1&context=smog&gid=' . $group->id), $group->id, 'Group', NULL, NULL, $recentOther); } return $group; }
/** * Deletes an existing Group Organization * * This API is used for deleting a Group Organization * * @param array $params with 'id' = ID of the Group Organization to be deleted * * @return array API Result * {@getfields GroupOrganization_delete} * @example GroupOrganizationDelete.php * @access public */ function civicrm_api3_group_organization_delete($params) { $result = CRM_Contact_BAO_GroupOrganization::deleteGroupOrganization($params['id']); return $result ? civicrm_api3_create_success('Deleted Group Organization successfully') : civicrm_api3_create_error('Could not delete Group Organization'); }
/** * Heart of the viewing process. The runner gets all the meta data for * the contact and calls the appropriate type of page to view. * * @return void * @access public * */ function preProcess() { // process url params $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); $this->assign('id', $this->_id); $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); //validate the qfKey if (!CRM_Utils_Rule::qfKey($qfKey)) { $qfKey = NULL; } $this->assign('searchKey', $qfKey); // retrieve the group contact id, so that we can get contact id $gcid = CRM_Utils_Request::retrieve('gcid', 'Positive', $this); if (!$gcid) { $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); } else { $this->_contactId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_GroupContact', $gcid, 'contact_id'); } if (!$this->_contactId) { CRM_Core_Error::statusBounce(ts('We could not find a contact id.'), CRM_Utils_System::url('civicrm/dashboard', 'reset=1')); } // ensure that the id does exist if (CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'id') != $this->_contactId) { CRM_Core_Error::statusBounce(ts('A Contact with that ID does not exist: %1', array(1 => $this->_contactId)), CRM_Utils_System::url('civicrm/dashboard', 'reset=1')); } $this->assign('contactId', $this->_contactId); // see if we can get prev/next positions from qfKey $navContacts = array('prevContactID' => NULL, 'prevContactName' => NULL, 'nextContactID' => NULL, 'nextContactName' => NULL, 'nextPrevError' => 0); if ($qfKey) { $pos = CRM_Core_BAO_PrevNextCache::getPositions("civicrm search {$qfKey}", $this->_contactId, $this->_contactId); $found = FALSE; if (isset($pos['prev'])) { $navContacts['prevContactID'] = $pos['prev']['id1']; $navContacts['prevContactName'] = $pos['prev']['data']; $found = TRUE; } if (isset($pos['next'])) { $navContacts['nextContactID'] = $pos['next']['id1']; $navContacts['nextContactName'] = $pos['next']['data']; $found = TRUE; } if (!$found) { // seems like we did not find any contacts // maybe due to bug CRM-9096 // however we should account for 1 contact results (which dont have prev next) if (!$pos['foundEntry']) { $navContacts['nextPrevError'] = 1; } } } $this->assign($navContacts); $path = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId); CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('View Contact'), 'url' => $path))); CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Search Results'), 'url' => self::getSearchURL()))); if ($image_URL = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'image_URL')) { //CRM-7265 --time being fix. $config = CRM_Core_Config::singleton(); $image_URL = str_replace('https://', 'http://', $image_URL); if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enableSSL')) { $image_URL = str_replace('http://', 'https://', $image_URL); } list($imageWidth, $imageHeight) = getimagesize($image_URL); list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight); $this->assign("imageWidth", $imageWidth); $this->assign("imageHeight", $imageHeight); $this->assign("imageThumbWidth", $imageThumbWidth); $this->assign("imageThumbHeight", $imageThumbHeight); $this->assign("imageURL", $image_URL); } // also store in session for future use $session = CRM_Core_Session::singleton(); $session->set('view.id', $this->_contactId); $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); $this->assign('action', $this->_action); // check logged in user permission self::checkUserPermission($this); list($displayName, $contactImage, $contactType, $contactSubtype, $contactImageUrl) = self::getContactDetails($this->_contactId); $this->assign('displayName', $displayName); $this->set('contactType', $contactType); $this->set('contactSubtype', $contactSubtype); // see if other modules want to add a link activtity bar $hookLinks = CRM_Utils_Hook::links('view.contact.activity', 'Contact', $this->_contactId, CRM_Core_DAO::$_nullObject, CRM_Core_DAO::$_nullObject); if (is_array($hookLinks)) { $this->assign('hookLinks', $hookLinks); } // add to recently viewed block $isDeleted = (bool) CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'is_deleted'); $recentOther = array('imageUrl' => $contactImageUrl, 'subtype' => $contactSubtype, 'isDeleted' => $isDeleted); if ($session->get('userID') == $this->_contactId || CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/add', "reset=1&action=update&cid={$this->_contactId}"); } if ($session->get('userID') != $this->_contactId && CRM_Core_Permission::check('delete contacts') && !$isDeleted) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/delete', "reset=1&delete=1&cid={$this->_contactId}"); } CRM_Utils_Recent::add($displayName, CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_contactId}"), $this->_contactId, $contactType, $this->_contactId, $displayName, $recentOther); $this->assign('isDeleted', $isDeleted); // set page title self::setTitle($this->_contactId, $isDeleted); $config = CRM_Core_Config::singleton(); $uid = CRM_Core_BAO_UFMatch::getUFId($this->_contactId); if ($uid) { // To do: we should also allow drupal users with CRM_Core_Permission::check( 'view user profiles' ) true to access $userRecordUrl // but this is currently returning false regardless of permission set for the role. dgg if ($config->userSystem->is_drupal == '1' && ($session->get('userID') == $this->_contactId || CRM_Core_Permission::check('administer users'))) { $userRecordUrl = CRM_Utils_System::url('user/' . $uid); } elseif ($config->userFramework == 'Joomla') { $userRecordUrl = NULL; // if logged in user is super user, then he can view other users joomla profile if (JFactory::getUser()->authorise('core.admin')) { $userRecordUrl = $config->userFrameworkBaseURL . "index.php?option=com_users&view=user&task=user.edit&id=" . $uid; } elseif ($session->get('userID') == $this->_contactId) { $userRecordUrl = $config->userFrameworkBaseURL . "index.php?option=com_admin&view=profile&layout=edit&id=" . $uid; } } else { $userRecordUrl = NULL; } $this->assign('userRecordUrl', $userRecordUrl); $this->assign('userRecordId', $uid); } elseif ($config->userSystem->is_drupal == '1' && CRM_Core_Permission::check('administer users') || $config->userFramework == 'Joomla' && JFactory::getUser()->authorise('core.create', 'com_users')) { $userAddUrl = CRM_Utils_System::url('civicrm/contact/view/useradd', 'reset=1&action=add&cid=' . $this->_contactId); $this->assign('userAddUrl', $userAddUrl); } if (CRM_Core_Permission::check('access Contact Dashboard')) { $dashboardURL = CRM_Utils_System::url('civicrm/user', "reset=1&id={$this->_contactId}"); $this->assign('dashboardURL', $dashboardURL); } if ($contactType == 'Organization' && CRM_Core_Permission::check('administer Multiple Organizations') && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME, 'is_enabled')) { //check is any relationship between the organization and groups $groupOrg = CRM_Contact_BAO_GroupOrganization::hasGroupAssociated($this->_contactId); if ($groupOrg) { $groupOrganizationUrl = CRM_Utils_System::url('civicrm/group', "reset=1&oid={$this->_contactId}"); $this->assign('groupOrganizationUrl', $groupOrganizationUrl); } } }
/** * Heart of the viewing process. The runner gets all the meta data for * the contact and calls the appropriate type of page to view. * * @return void * @access public * */ function preProcess() { // process url params $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); $this->assign('id', $this->_id); // retrieve the group contact id, so that we can get contact id $gcid = CRM_Utils_Request::retrieve('gcid', 'Positive', $this); if (!$gcid) { $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, true); } else { $this->_contactId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_GroupContact', $gcid, 'contact_id'); } if (!$this->_contactId) { CRM_Core_Error::statusBounce(ts('We could not find a contact id.')); } $this->assign('contactId', $this->_contactId); $path = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId); CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('View Contact'), 'url' => $path))); CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Search Results'), 'url' => self::getSearchURL()))); // also store in session for future use $session =& CRM_Core_Session::singleton(); $session->set('view.id', $this->_contactId); $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'browse'); $this->assign('action', $this->_action); // check logged in url permission self::checkUserPermission($this); list($displayName, $contactImage, $contactType, $contactSubtype, $contactImageUrl) = $this->getContactDetails(); $this->assign('displayName', $displayName); $this->set('contactType', $contactType); $this->set('contactSubtype', $contactSubtype); // see if other modules want to add a link activtity bar require_once 'CRM/Utils/Hook.php'; $hookLinks = CRM_Utils_Hook::links('view.contact.activity', 'Contact', $this->_contactId); if (is_array($hookLinks)) { $this->assign('hookLinks', $hookLinks); } // set page title CRM_Utils_System::setTitle($displayName, $contactImage . ' ' . $displayName); // add to recently viewed block CRM_Utils_Recent::add($displayName, CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId), $this->_contactId, $contactType, $this->_contactId, $displayName, $contactImageUrl, $contactSubtype); $config = CRM_Core_Config::singleton(); require_once 'CRM/Core/BAO/UFMatch.php'; if ($uid = CRM_Core_BAO_UFMatch::getUFId($this->_contactId)) { if ($config->userFramework == 'Drupal') { $url = CRM_Utils_System::url('user/' . $uid); } else { if ($config->userFramework == 'Joomla') { $url = $config->userFrameworkBaseURL . 'index2.php?option=com_users&view=user&task=edit&cid[]=' . $uid; } else { $url = null; } } $this->assign('url', $url); } if (CRM_Core_Permission::check('access Contact Dashboard')) { $dashboardURL = CRM_Utils_System::url('civicrm/user', "reset=1&id={$this->_contactId}"); $this->assign('dashboardURL', $dashboardURL); } if (defined('CIVICRM_MULTISITE') && CIVICRM_MULTISITE && $contactType == 'Organization' && CRM_Core_Permission::check('administer Multiple Organizations')) { require_once 'CRM/Contact/BAO/GroupOrganization.php'; //check is any relationship between the organization and groups $groupOrg = CRM_Contact_BAO_GroupOrganization::hasGroupAssociated($this->_contactId); if ($groupOrg) { $groupOrganizationUrl = CRM_Utils_System::url('civicrm/group', "reset=1&oid={$this->_contactId}"); $this->assign('groupOrganizationUrl', $groupOrganizationUrl); } } }
/** * Heart of the viewing process. The runner gets all the meta data for * the contact and calls the appropriate type of page to view. * * @return void * @access public * */ function preProcess() { $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); $this->assign('id', $this->_id); // retrieve the group contact id, so that we can get contact id $gcid = CRM_Utils_Request::retrieve('gcid', 'Positive', $this); if (!$gcid) { $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, true); } else { $this->_contactId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_GroupContact', $gcid, 'contact_id'); } if (!$this->_contactId) { CRM_Core_Error::statusBounce(ts('We could not find a contact id.')); } $this->assign('contactId', $this->_contactId); $path = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId); CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('View Contact'), 'url' => $path))); CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Search Results'), 'url' => self::getSearchURL()))); // also store in session for future use $session =& CRM_Core_Session::singleton(); $session->set('view.id', $this->_contactId); $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'browse'); $this->assign('action', $this->_action); // check for permissions $this->_permission = null; // automatically grant permissin for users on their own record. makes // things easier in dashboard require_once 'CRM/Contact/BAO/Contact/Permission.php'; if ($session->get('userID') == $this->_contactId) { $this->assign('permission', 'edit'); $this->_permission = CRM_Core_Permission::EDIT; } else { if (CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) { $this->assign('permission', 'edit'); $this->_permission = CRM_Core_Permission::EDIT; } else { if (CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::VIEW)) { $this->assign('permission', 'view'); $this->_permission = CRM_Core_Permission::VIEW; } else { $session->pushUserContext(CRM_Utils_System::url('civicrm', 'reset=1')); CRM_Core_Error::statusBounce(ts('You do not have the necessary permission to view this contact.')); } } } $this->getContactDetails(); $contactImage = $this->get('contactImage'); $displayName = $this->get('displayName'); $contactType = $this->get('contactType'); $contactSubtype = $this->get('contactSubType'); $contactImageUrl = $this->get('contactImageUrl'); $this->assign('displayName', $displayName); // see if other modules want to add a link activtity bar require_once 'CRM/Utils/Hook.php'; $hookLinks = CRM_Utils_Hook::links('view.contact.activity', 'Contact', $this->_contactId); if (is_array($hookLinks)) { $this->assign('hookLinks', $hookLinks); } CRM_Utils_System::setTitle($displayName, $contactImage . ' ' . $displayName); CRM_Utils_Recent::add($displayName, CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId), $this->_contactId, $contactType, $this->_contactId, $displayName, $contactImageUrl, $contactSubtype); //display OtherActivity link $otherAct = CRM_Core_PseudoConstant::activityType(false); $activityNum = count($otherAct); $this->assign('showOtherActivityLink', $activityNum); $config =& CRM_Core_Config::singleton(); require_once 'CRM/Core/BAO/UFMatch.php'; if ($uid = CRM_Core_BAO_UFMatch::getUFId($this->_contactId)) { if ($config->userFramework == 'Drupal') { $url = CRM_Utils_System::url('user/' . $uid); } else { if ($config->userFramework == 'Joomla') { $url = $config->userFrameworkBaseURL . 'index2.php?option=com_users&view=user&task=edit&cid[]=' . $uid; } else { $url = null; } } $this->assign('url', $url); } if (CRM_Core_Permission::check('access Contact Dashboard')) { $dashboardURL = CRM_Utils_System::url('civicrm/user', "reset=1&id={$this->_contactId}"); $this->assign('dashboardURL', $dashboardURL); } if ($contactType == 'Organization' && CRM_Core_Permission::check('administer Multiple Organizations')) { require_once 'CRM/Contact/BAO/GroupOrganization.php'; //check is any relationship between the organization and groups $groupOrg = CRM_Contact_BAO_GroupOrganization::hasGroupAssociated($this->_contactId); if ($groupOrg) { $groupOrganizationUrl = CRM_Utils_System::url('civicrm/group', "reset=1&oid={$this->_contactId}"); $this->assign('groupOrganizationUrl', $groupOrganizationUrl); } } }