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,432 @@
<?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
*/
/**
* Create a page for displaying CiviCRM Profile Fields.
*
* Heart of this class is the run method which checks
* for action type and then displays the appropriate
* page.
*
*/
class CRM_Profile_Page_Dynamic extends CRM_Core_Page {
/**
* The contact id of the person we are viewing.
*
* @var int
*/
protected $_id;
/**
* The profile group are are interested in.
*
* @var int
*/
protected $_gid;
/**
* The profile types we restrict this page to display.
*
* @var string
*/
protected $_restrict;
/**
* Should we bypass permissions.
*
* @var boolean
*/
protected $_skipPermission;
/**
* Store profile ids if multiple profile ids are passed using comma separated.
* Currently lets implement this functionality only for dialog mode
*/
protected $_profileIds = array();
/**
* Contact profile having activity fields?
*
* @var string
*/
protected $_isContactActivityProfile = FALSE;
/**
* Activity Id connected to the profile.
*
* @var string
*/
protected $_activityId = NULL;
protected $_multiRecord = NULL;
protected $_recordId = NULL;
/*
* fetch multirecord as well as non-multirecord fields
*/
protected $_allFields = NULL;
/**
* Class constructor.
*
* @param int $id
* The contact id.
* @param int $gid
* The group id.
*
* @param $restrict
* @param bool $skipPermission
* @param null $profileIds
*
* @return \CRM_Profile_Page_Dynamic
*/
public function __construct($id, $gid, $restrict, $skipPermission = FALSE, $profileIds = NULL) {
parent::__construct();
$this->_id = $id;
$this->_gid = $gid;
$this->_restrict = $restrict;
$this->_skipPermission = $skipPermission;
if (!array_key_exists('multiRecord', $_GET)) {
$this->set('multiRecord', NULL);
}
if (!array_key_exists('recordId', $_GET)) {
$this->set('recordId', NULL);
}
if (!array_key_exists('allFields', $_GET)) {
$this->set('allFields', NULL);
}
//specifies the action being done on a multi record field
$multiRecordAction = CRM_Utils_Request::retrieve('multiRecord', 'String', $this);
$this->_multiRecord = (!is_numeric($multiRecordAction)) ? CRM_Core_Action::resolve($multiRecordAction) : $multiRecordAction;
if ($this->_multiRecord) {
$this->set('multiRecord', $this->_multiRecord);
}
if ($this->_multiRecord & CRM_Core_Action::VIEW) {
$this->_recordId = CRM_Utils_Request::retrieve('recordId', 'Positive', $this);
$this->_allFields = CRM_Utils_Request::retrieve('allFields', 'Integer', $this);
}
if ($profileIds) {
$this->_profileIds = $profileIds;
}
else {
$this->_profileIds = array($gid);
}
$this->_activityId = CRM_Utils_Request::retrieve('aid', 'Positive', $this, FALSE, 0, 'GET');
if (is_numeric($this->_activityId)) {
$latestRevisionId = CRM_Activity_BAO_Activity::getLatestActivityId($this->_activityId);
if ($latestRevisionId) {
$this->_activityId = $latestRevisionId;
}
}
$this->_isContactActivityProfile = CRM_Core_BAO_UFField::checkContactActivityProfileType($this->_gid);
}
/**
* Get the action links for this page.
*
* @return array
*/
public function &actionLinks() {
return NULL;
}
/**
* 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() {
$template = CRM_Core_Smarty::singleton();
if ($this->_id && $this->_gid) {
// first check that id is part of the limit group id, CRM-4822
$limitListingsGroupsID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup',
$this->_gid,
'limit_listings_group_id'
);
$config = CRM_Core_Config::singleton();
if ($limitListingsGroupsID) {
if (!CRM_Contact_BAO_GroupContact::isContactInGroup($this->_id,
$limitListingsGroupsID
)
) {
CRM_Utils_System::setTitle(ts('Profile View - Permission Denied'));
return CRM_Core_Session::setStatus(ts('You do not have permission to view this contact record. Contact the site administrator if you need assistance.'), ts('Permission Denied'), 'error');
}
}
$session = CRM_Core_Session::singleton();
$userID = $session->get('userID');
$this->_isPermissionedChecksum = $allowPermission = FALSE;
$permissionType = CRM_Core_Permission::VIEW;
if (CRM_Core_Permission::check('administer users') || CRM_Core_Permission::check('view all contacts') || CRM_Contact_BAO_Contact_Permission::allow($this->_id)) {
$allowPermission = TRUE;
}
if ($this->_id != $userID) {
// do not allow edit for anon users in joomla frontend, CRM-4668, unless u have checksum CRM-5228
if ($config->userFrameworkFrontend) {
$this->_isPermissionedChecksum = CRM_Contact_BAO_Contact_Permission::validateOnlyChecksum($this->_id, $this, FALSE);
if (!$this->_isPermissionedChecksum) {
$this->_isPermissionedChecksum = $allowPermission;
}
}
else {
$this->_isPermissionedChecksum = CRM_Contact_BAO_Contact_Permission::validateChecksumContact($this->_id, $this, FALSE);
}
}
// CRM-10853
// Users with create or edit permission should be allowed to view their own profile
if ($this->_id == $userID || $this->_isPermissionedChecksum) {
if (!CRM_Core_Permission::check('profile view')) {
if (CRM_Core_Permission::check('profile create') || CRM_Core_Permission::check('profile edit')) {
$this->_skipPermission = TRUE;
}
}
}
// make sure we dont expose all fields based on permission
$admin = FALSE;
if ((!$config->userFrameworkFrontend && $allowPermission) ||
$this->_id == $userID ||
$this->_isPermissionedChecksum
) {
$admin = TRUE;
}
$values = array();
$fields = CRM_Core_BAO_UFGroup::getFields($this->_profileIds, FALSE, CRM_Core_Action::VIEW,
NULL, NULL, FALSE, $this->_restrict,
$this->_skipPermission, NULL,
$permissionType
);
if ($this->_multiRecord & CRM_Core_Action::VIEW && $this->_recordId && !$this->_allFields) {
CRM_Core_BAO_UFGroup::shiftMultiRecordFields($fields, $multiRecordFields);
$fields = $multiRecordFields;
}
if ($this->_isContactActivityProfile && $this->_gid) {
$errors = CRM_Profile_Form::validateContactActivityProfile($this->_activityId, $this->_id, $this->_gid);
if (!empty($errors)) {
CRM_Core_Error::fatal(array_pop($errors));
}
}
//reformat fields array
foreach ($fields as $name => $field) {
// also eliminate all formatting fields
if (CRM_Utils_Array::value('field_type', $field) == 'Formatting') {
unset($fields[$name]);
}
// make sure that there is enough permission to expose this field
if (!$admin && $field['visibility'] == 'User and User Admin Only') {
unset($fields[$name]);
}
}
if ($this->_isContactActivityProfile) {
$contactFields = $activityFields = array();
foreach ($fields as $fieldName => $field) {
if (CRM_Utils_Array::value('field_type', $field) == 'Activity') {
$activityFields[$fieldName] = $field;
}
else {
$contactFields[$fieldName] = $field;
}
}
CRM_Core_BAO_UFGroup::getValues($this->_id, $contactFields, $values);
if ($this->_activityId) {
CRM_Core_BAO_UFGroup::getValues(
NULL,
$activityFields,
$values,
TRUE,
array(array('activity_id', '=', $this->_activityId, 0, 0))
);
}
}
else {
$customWhereClause = NULL;
if ($this->_multiRecord & CRM_Core_Action::VIEW && $this->_recordId) {
if ($this->_allFields) {
$copyFields = $fields;
CRM_Core_BAO_UFGroup::shiftMultiRecordFields($copyFields, $multiRecordFields);
$fieldKey = key($multiRecordFields);
}
else {
$fieldKey = key($fields);
}
if ($fieldID = CRM_Core_BAO_CustomField::getKeyID($fieldKey)) {
$tableColumnGroup = CRM_Core_BAO_CustomField::getTableColumnGroup($fieldID);
$columnName = "{$tableColumnGroup[0]}.id";
$customWhereClause = $columnName . ' = ' . $this->_recordId;
}
}
CRM_Core_BAO_UFGroup::getValues($this->_id, $fields, $values, TRUE, NULL, FALSE, $customWhereClause);
}
// $profileFields array can be used for customized display of field labels and values in Profile/View.tpl
$profileFields = array();
$labels = array();
foreach ($fields as $name => $field) {
//CRM-14338
// Create a unique, non-empty index for each field.
$index = $field['title'];
if ($index === '') {
$index = ' ';
}
while (array_key_exists($index, $labels)) {
$index .= ' ';
}
$labels[$index] = preg_replace('/\s+|\W+/', '_', $name);
}
foreach ($values as $title => $value) {
$profileFields[$labels[$title]] = array(
'label' => $title,
'value' => $value,
);
}
$template->assign_by_ref('row', $values);
$template->assign_by_ref('profileFields', $profileFields);
}
$name = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'name');
$this->assign('ufGroupName', $name);
CRM_Utils_Hook::viewProfile($name);
if (strtolower($name) == 'summary_overlay') {
$template->assign('overlayProfile', TRUE);
}
if (($this->_multiRecord & CRM_Core_Action::VIEW) && $this->_recordId && !$this->_allFields) {
$fieldDetail = reset($fields);
$fieldId = CRM_Core_BAO_CustomField::getKeyID($fieldDetail['name']);
$customGroupDetails = CRM_Core_BAO_CustomGroup::getGroupTitles(array($fieldId));
$multiRecTitle = $customGroupDetails[$fieldId]['groupTitle'];
}
else {
$title = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'title');
}
//CRM-4131.
$displayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_id, 'display_name');
if ($displayName) {
$session = CRM_Core_Session::singleton();
$config = CRM_Core_Config::singleton();
if ($session->get('userID') &&
CRM_Core_Permission::check('access CiviCRM') &&
CRM_Contact_BAO_Contact_Permission::allow($session->get('userID'), CRM_Core_Permission::VIEW) &&
!$config->userFrameworkFrontend
) {
$contactViewUrl = CRM_Utils_System::url('civicrm/contact/view', "action=view&reset=1&cid={$this->_id}", TRUE);
$this->assign('displayName', $displayName);
$displayName = "<a href=\"$contactViewUrl\">{$displayName}</a>";
}
$title .= ' - ' . $displayName;
}
$title = isset($multiRecTitle) ? ts('View %1 Record', array(1 => $multiRecTitle)) : $title;
CRM_Utils_System::setTitle($title);
// invoke the pagRun hook, CRM-3906
CRM_Utils_Hook::pageRun($this);
return trim($template->fetch($this->getHookedTemplateFileName()));
}
/**
* @param string $suffix
*
* @return null|string
*/
public function checkTemplateFileExists($suffix = '') {
if ($this->_gid) {
$templateFile = "CRM/Profile/Page/{$this->_gid}/Dynamic.{$suffix}tpl";
$template = CRM_Core_Page::getTemplate();
if ($template->template_exists($templateFile)) {
return $templateFile;
}
// lets see if we have customized by name
$ufGroupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'name');
if ($ufGroupName) {
$templateFile = "CRM/Profile/Page/{$ufGroupName}/Dynamic.{$suffix}tpl";
if ($template->template_exists($templateFile)) {
return $templateFile;
}
}
}
return NULL;
}
/**
* Use the form name to create the tpl file name.
*
* @return string
*/
public function getTemplateFileName() {
$fileName = $this->checkTemplateFileExists();
return $fileName ? $fileName : parent::getTemplateFileName();
}
/**
* Default extra tpl file basically just replaces .tpl with .extra.tpl
* i.e. we dont override
*
* @return string
*/
public function overrideExtraTemplateFileName() {
$fileName = $this->checkTemplateFileExists('extra.');
return $fileName ? $fileName : parent::overrideExtraTemplateFileName();
}
}

View file

@ -0,0 +1,513 @@
<?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 implements the profile page for all contacts. It uses a selector
* object to do the actual dispay. The fields displayd are controlled by
* the admin.
*/
class CRM_Profile_Page_Listings extends CRM_Core_Page {
/**
* All the fields that are listings related.
*
* @var array
*/
protected $_fields;
/**
* The custom fields for this domain.
*
* @var array
*/
protected $_customFields;
/**
* The input params from the request.
*
* @var array
*/
protected $_params;
/**
* The group id that we are editing.
*
* @var int
*/
protected $_gid;
/**
* State whether to display search form or not.
*
* @var int
*/
protected $_search;
/**
* Should we display a map.
*
* @var int
*/
protected $_map;
/**
* Store profile ids if multiple profile ids are passed using comma separated.
* Currently lets implement this functionality only for dialog mode
*/
protected $_profileIds = array();
/**
* Extracts the parameters from the request and constructs information for
* the selector object to do a query
*
*/
public function preProcess() {
$this->_search = TRUE;
$search = CRM_Utils_Request::retrieve('search', 'Boolean', $this, FALSE, 0, 'GET');
if (isset($search) && $search == 0) {
$this->_search = FALSE;
}
$this->_gid = $this->get('gid');
$this->_profileIds = $this->get('profileIds');
$gids = explode(',', CRM_Utils_Request::retrieve('gid', 'String', CRM_Core_DAO::$_nullObject, FALSE, 0, 'GET'));
if ((count($gids) > 1) && !$this->_profileIds && empty($this->_profileIds)) {
if (!empty($gids)) {
foreach ($gids as $pfId) {
$this->_profileIds[] = CRM_Utils_Type::escape($pfId, 'Positive');
}
}
// check if we are rendering mixed profiles
if (CRM_Core_BAO_UFGroup::checkForMixProfiles($this->_profileIds)) {
CRM_Core_Error::fatal(ts('You cannot combine profiles of multiple types.'));
}
$this->_gid = $this->_profileIds[0];
$this->set('profileIds', $this->_profileIds);
$this->set('gid', $this->_gid);
}
if (!$this->_gid) {
$this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, FALSE, 0, 'GET');
}
if (empty($this->_profileIds)) {
$gids = $this->_gid;
}
else {
$gids = $this->_profileIds;
}
$this->_fields = CRM_Core_BAO_UFGroup::getListingFields(CRM_Core_Action::UPDATE,
CRM_Core_BAO_UFGroup::PUBLIC_VISIBILITY | CRM_Core_BAO_UFGroup::LISTINGS_VISIBILITY,
FALSE, $gids, FALSE, 'Profile',
CRM_Core_Permission::SEARCH
);
$this->_customFields = CRM_Core_BAO_CustomField::getFieldsForImport(NULL, FALSE, FALSE, FALSE, TRUE, TRUE);
$this->_params = array();
$resetArray = array(
'group',
'tag',
'preferred_communication_method',
'do_not_phone',
'do_not_email',
'do_not_mail',
'do_not_sms',
'do_not_trade',
'gender',
);
foreach ($this->_fields as $name => $field) {
if ((substr($name, 0, 6) == 'custom') && !empty($field['is_search_range'])) {
$from = CRM_Utils_Request::retrieve($name . '_from', 'String', $this);
$to = CRM_Utils_Request::retrieve($name . '_to', 'String', $this);
$value = array();
if ($from && $to) {
$value[$name . '_from'] = $from;
$value[$name . '_to'] = $to;
}
elseif ($from) {
$value[$name . '_from'] = $from;
}
elseif ($to) {
$value[$name . '_to'] = $to;
}
}
elseif ((substr($name, 0, 7) == 'custom_') &&
(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField',
substr($name, 7), 'html_type'
) == 'TextArea')
) {
$value = trim(CRM_Utils_Request::retrieve($name, 'String',
$this, FALSE, NULL, 'REQUEST'
));
if (!empty($value) &&
!((substr($value, 0, 1) == '%') &&
(substr($value, -1, 1) == '%')
)
) {
$value = '%' . $value . '%';
}
}
elseif (CRM_Utils_Array::value('html_type', $field) == 'Multi-Select State/Province'
|| CRM_Utils_Array::value('html_type', $field) == 'Multi-Select Country'
) {
$value = CRM_Utils_Request::retrieve($name, 'String', $this, FALSE, NULL, 'REQUEST');
if (!is_array($value)) {
$value = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($value, 1, -1));
}
}
elseif ($name == 'contact_sub_type') {
$v = CRM_Utils_Request::retrieve($name, 'String', $this, FALSE, NULL, 'REQUEST');
if ($v && !is_array($v)) {
$v = explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($v, CRM_Core_DAO::VALUE_SEPARATOR));
}
if (!empty($v)) {
foreach ($v as $item) {
$value[$item] = 1;
}
}
}
else {
$value = CRM_Utils_Request::retrieve($name, 'String',
$this, FALSE, NULL, 'REQUEST'
);
}
if (($name == 'group' || $name == 'tag') && !empty($value) && !is_array($value)) {
$v = explode(',', $value);
$value = array();
foreach ($v as $item) {
$value[$item] = 1;
}
}
$customField = CRM_Utils_Array::value($name, $this->_customFields);
if (!empty($_POST) && empty($_POST[$name])) {
if ($customField) {
// reset checkbox/radio because a form does not send null checkbox values
if (in_array($customField['html_type'],
array('Multi-Select', 'CheckBox', 'Multi-Select State/Province', 'Multi-Select Country', 'Radio', 'Select')
)) {
// only reset on a POST submission if we don't see any value
$value = NULL;
$this->set($name, $value);
}
}
elseif (in_array($name, $resetArray)) {
$value = NULL;
$this->set($name, $value);
}
}
if (isset($value) && $value != NULL) {
if (!is_array($value)) {
$value = trim($value);
}
$operator = CRM_Utils_Request::retrieve($name . '_operator', 'String', $this);
if ($operator) {
$this->_params[$name . '_operator'] = $operator;
}
if ((substr($name, 0, 6) == 'custom') && !empty($field['is_search_range'])) {
$this->_params += $value;
}
else {
$this->_params[$name] = $this->_fields[$name]['value'] = $value;
}
}
}
// set the prox params
// need to ensure proximity searching is enabled
$proximityVars = array(
'street_address',
'city',
'postal_code',
'state_province_id',
'country_id',
'distance',
'distance_unit',
);
foreach ($proximityVars as $var) {
$value = CRM_Utils_Request::retrieve("prox_{$var}",
'String',
$this, FALSE, NULL, 'REQUEST'
);
if ($value) {
$this->_params["prox_{$var}"] = $value;
}
}
// set the params in session
$session = CRM_Core_Session::singleton();
$session->set('profileParams', $this->_params);
}
/**
* Run this page (figure out the action needed and perform it).
*
*/
public function run() {
$this->preProcess();
$this->assign('recentlyViewed', FALSE);
// override later (if possible):
$this->assign('ufGroupName', 'unknown');
if ($this->_gid) {
$ufgroupDAO = new CRM_Core_DAO_UFGroup();
$ufgroupDAO->id = $this->_gid;
if (!$ufgroupDAO->find(TRUE)) {
CRM_Core_Error::fatal();
}
}
if ($this->_gid) {
// set the title of the page
if ($ufgroupDAO->title) {
CRM_Utils_System::setTitle($ufgroupDAO->title);
}
if ($ufgroupDAO->name) {
$this->assign('ufGroupName', $ufgroupDAO->name);
}
}
$this->assign('isReset', TRUE);
$formController = new CRM_Core_Controller_Simple('CRM_Profile_Form_Search',
ts('Search Profile'),
CRM_Core_Action::ADD
);
$formController->setEmbedded(TRUE);
$formController->set('gid', $this->_gid);
$formController->process();
$searchError = FALSE;
// check if there is a POST
if (!empty($_POST)) {
if ($formController->validate() !== TRUE) {
$searchError = TRUE;
}
}
// also get the search tpl name
$this->assign('searchTPL', $formController->getHookedTemplateFileName());
$this->assign('search', $this->_search);
// search if search returned a form error?
if ((empty($_GET['reset']) || !empty($_GET['force'])) &&
!$searchError
) {
$this->assign('isReset', FALSE);
$gidString = $this->_gid;
if (empty($this->_profileIds)) {
$gids = $this->_gid;
}
else {
$gids = $this->_profileIds;
$gidString = implode(',', $this->_profileIds);
}
$map = 0;
$linkToUF = 0;
$editLink = FALSE;
if ($this->_gid) {
$map = $ufgroupDAO->is_map;
$linkToUF = $ufgroupDAO->is_uf_link;
$editLink = $ufgroupDAO->is_edit_link;
}
if ($map) {
$this->assign('mapURL',
CRM_Utils_System::url('civicrm/profile/map',
"map=1&gid={$gidString}&reset=1"
)
);
}
if (!empty($this->_params['group'])) {
foreach ($this->_params['group'] as $key => $val) {
if (!$val) {
unset($this->_params['group'][$key]);
}
}
}
// the selector will override this if the user does have
// edit permissions as determined by the mask, CRM-4341
// do not allow edit for anon users in joomla frontend, CRM-4668
$config = CRM_Core_Config::singleton();
if (!CRM_Core_Permission::check('access CiviCRM') ||
$config->userFrameworkFrontend == 1
) {
$editLink = FALSE;
}
$selector = new CRM_Profile_Selector_Listings($this->_params, $this->_customFields, $gids,
$map, $editLink, $linkToUF
);
$controller = new CRM_Core_Selector_Controller($selector,
$this->get(CRM_Utils_Pager::PAGE_ID),
$this->get(CRM_Utils_Sort::SORT_ID),
CRM_Core_Action::VIEW,
$this,
CRM_Core_Selector_Controller::TEMPLATE
);
$controller->setEmbedded(TRUE);
$controller->run();
}
//CRM-6862 -run form controller after
//selector, since it erase $_POST
$formController->run();
return parent::run();
}
/**
* Get the list of contacts for a profile.
*
* @param int $gid
*
* @return array
*/
public static function getProfileContact($gid) {
$session = CRM_Core_Session::singleton();
$params = $session->get('profileParams');
$details = array();
$ufGroupParam = array('id' => $gid);
CRM_Core_BAO_UFGroup::retrieve($ufGroupParam, $details);
// make sure this group can be mapped
if (!$details['is_map']) {
CRM_Core_Error::statusBounce(ts('This profile does not have the map feature turned on.'));
}
$groupId = CRM_Utils_Array::value('limit_listings_group_id', $details);
// add group id to params if a uf group belong to a any group
if ($groupId) {
if (!empty($params['group'])) {
$params['group'][$groupId] = 1;
}
else {
$params['group'] = array($groupId => 1);
}
}
$fields = CRM_Core_BAO_UFGroup::getListingFields(
CRM_Core_Action::VIEW,
CRM_Core_BAO_UFGroup::PUBLIC_VISIBILITY | CRM_Core_BAO_UFGroup::LISTINGS_VISIBILITY,
FALSE,
$gid
);
$returnProperties = CRM_Contact_BAO_Contact::makeHierReturnProperties($fields);
$returnProperties['contact_type'] = 1;
$returnProperties['sort_name'] = 1;
$queryParams = CRM_Contact_BAO_Query::convertFormValues($params, 1);
$query = new CRM_Contact_BAO_Query($queryParams, $returnProperties, $fields);
$additionalWhereClause = 'contact_a.is_deleted = 0';
$ids = $query->searchQuery(0, 0, NULL,
FALSE, FALSE, FALSE,
TRUE, FALSE,
$additionalWhereClause
);
$contactIds = explode(',', $ids);
return $contactIds;
}
/**
* @param string $suffix
*
* @return null|string
*/
public function checkTemplateFileExists($suffix = '') {
if ($this->_gid) {
$templateFile = "CRM/Profile/Page/{$this->_gid}/Listings.{$suffix}tpl";
$template = CRM_Core_Page::getTemplate();
if ($template->template_exists($templateFile)) {
return $templateFile;
}
// lets see if we have customized by name
$ufGroupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'name');
if ($ufGroupName) {
$templateFile = "CRM/Profile/Page/{$ufGroupName}/Listings.{$suffix}tpl";
if ($template->template_exists($templateFile)) {
return $templateFile;
}
}
}
return NULL;
}
/**
* Use the form name to create the tpl file name.
*
* @return string
*/
public function getTemplateFileName() {
$fileName = $this->checkTemplateFileExists();
return $fileName ? $fileName : parent::getTemplateFileName();
}
/**
* Default extra tpl file basically just replaces .tpl with .extra.tpl
* i.e. we dont override
*
* @return string
*/
public function overrideExtraTemplateFileName() {
$fileName = $this->checkTemplateFileExists('extra.');
return $fileName ? $fileName : parent::overrideExtraTemplateFileName();
}
}

View file

@ -0,0 +1,499 @@
<?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_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
/**
* The action links that we need to display for the browse screen.
*
* @var array
*/
static $_links = NULL;
protected $_fields = NULL;
protected $_profileId = NULL;
public $_contactId = NULL;
public $_customGroupTitle = NULL;
public $_pageViewType = NULL;
public $_contactType = NULL;
/**
* Get BAO Name.
*
* @return string
* Classname of BAO.
*/
public function getBAOName() {
return '';
}
/**
* Get action Links.
*
* @return array
* (reference) of action links
*/
public function &links() {
if (!(self::$_links[$this->_pageViewType])) {
// helper variable for nicer formatting
$links = array();
$view = array_search(CRM_Core_Action::VIEW, CRM_Core_Action::$_names);
$update = array_search(CRM_Core_Action::UPDATE, CRM_Core_Action::$_names);
$delete = array_search(CRM_Core_Action::DELETE, CRM_Core_Action::$_names);
// names and titles
$links[CRM_Core_Action::VIEW] = array(
'name' => ts('View'),
'title' => ts('View %1', array(1 => $this->_customGroupTitle . ' record')),
);
$links[CRM_Core_Action::UPDATE] = array(
'name' => ts('Edit'),
'title' => ts('Edit %1', array(1 => $this->_customGroupTitle . ' record')),
);
$links[CRM_Core_Action::DELETE] = array(
'name' => ts('Delete'),
'title' => ts('Delete %1', array(1 => $this->_customGroupTitle . ' record')),
);
// urls and queryStrings
if ($this->_pageViewType == 'profileDataView') {
$links[CRM_Core_Action::VIEW]['url'] = 'civicrm/profile/view';
$links[CRM_Core_Action::VIEW]['qs'] = "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$view}";
$links[CRM_Core_Action::UPDATE]['url'] = 'civicrm/profile/edit';
$links[CRM_Core_Action::UPDATE]['qs'] = "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$update}";
$links[CRM_Core_Action::DELETE]['url'] = 'civicrm/profile/edit';
$links[CRM_Core_Action::DELETE]['qs'] = "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$delete}";
}
elseif ($this->_pageViewType == 'customDataView') {
// custom data specific view links
$links[CRM_Core_Action::VIEW]['url'] = 'civicrm/contact/view/cd';
$links[CRM_Core_Action::VIEW]['qs'] = 'reset=1&gid=%%gid%%&cid=%%cid%%&recId=%%recId%%&cgcount=%%cgcount%%&multiRecordDisplay=single&mode=view';
// custom data specific update links
$links[CRM_Core_Action::UPDATE]['url'] = 'civicrm/contact/view/cd/edit';
$links[CRM_Core_Action::UPDATE]['qs'] = 'reset=1&type=%%type%%&groupID=%%groupID%%&entityID=%%entityID%%&cgcount=%%cgcount%%&multiRecordDisplay=single&mode=edit';
// NOTE : links for DELETE action for customDataView is handled in browse
// copy action
$links[CRM_Core_Action::COPY] = array(
'name' => ts('Copy'),
'title' => ts('Copy %1', array(1 => $this->_customGroupTitle . ' record')),
'url' => 'civicrm/contact/view/cd/edit',
'qs' => 'reset=1&type=%%type%%&groupID=%%groupID%%&entityID=%%entityID%%&cgcount=%%newCgCount%%&multiRecordDisplay=single&copyValueId=%%cgcount%%&mode=copy',
);
}
self::$_links[$this->_pageViewType] = $links;
}
return self::$_links[$this->_pageViewType];
}
/**
* Run the page.
*
* This method is called after the page is created. It checks for the type
* of action and executes that action. Finally it calls the parent's run
* method.
*
*/
public function run() {
// get the requested action, default to 'browse'
$action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, FALSE);
// assign vars to templates
$this->assign('action', $action);
$profileId = CRM_Utils_Request::retrieve('profileId', 'Positive', $this, FALSE);
if (!is_array($profileId) && is_numeric($profileId)) {
$this->_profileId = $profileId;
}
$this->_contactId = CRM_Utils_Request::retrieve('contactId', 'Positive', $this, FALSE);
$this->_pageViewType = CRM_Utils_Request::retrieve('pageViewType', 'Positive', $this, FALSE, 'profileDataView');
$this->_customGroupId = CRM_Utils_Request::retrieve('customGroupId', 'Positive', $this, FALSE, 0);
$this->_contactType = CRM_Utils_Request::retrieve('contactType', 'String', $this, FALSE);
if ($action & CRM_Core_Action::BROWSE) {
//browse
$this->browse();
return;
}
// parent run
return parent::run();
}
/**
* Browse the listing.
*
*/
public function browse() {
$dateFields = NULL;
$newCgCount = $cgcount = 0;
$attributes = $result = $headerAttr = array();
$dateFieldsVals = NULL;
if ($this->_pageViewType == 'profileDataView' && $this->_profileId) {
$fields = CRM_Core_BAO_UFGroup::getFields($this->_profileId, FALSE, NULL,
NULL, NULL,
FALSE, NULL,
FALSE,
NULL,
CRM_Core_Permission::EDIT
);
$multiRecordFields = array();
$fieldIDs = NULL;
$result = NULL;
$multiRecordFieldsWithSummaryListing = CRM_Core_BAO_UFGroup::shiftMultiRecordFields($fields, $multiRecordFields, TRUE);
$multiFieldId = CRM_Core_BAO_CustomField::getKeyID(key($multiRecordFields));
$customGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $multiFieldId, 'custom_group_id');
$reached = CRM_Core_BAO_CustomGroup::hasReachedMaxLimit($customGroupId, $this->_contactId);
if (!$reached) {
$this->assign('contactId', $this->_contactId);
$this->assign('gid', $this->_profileId);
}
$this->assign('reachedMax', $reached);
if ($multiRecordFieldsWithSummaryListing && !empty($multiRecordFieldsWithSummaryListing)) {
$fieldIDs = array_keys($multiRecordFieldsWithSummaryListing);
}
}
elseif ($this->_pageViewType == 'customDataView') {
// require custom group id for _pageViewType of customDataView
$customGroupId = $this->_customGroupId;
$reached = CRM_Core_BAO_CustomGroup::hasReachedMaxLimit($customGroupId, $this->_contactId);
if (!$reached) {
$this->assign('contactId', $this->_contactId);
$this->assign('customGroupId', $customGroupId);
$this->assign('ctype', $this->_contactType);
}
$this->assign('reachedMax', $reached);
// custom group info : this consists of the field title of group fields
$groupDetail = CRM_Core_BAO_CustomGroup::getGroupDetail($customGroupId, NULL, CRM_Core_DAO::$_nullObject, TRUE);
// field ids of fields in_selector for the custom group id provided
$fieldIDs = array_keys($groupDetail[$customGroupId]['fields']);
// field labels for headers
$fieldLabels = $groupDetail[$customGroupId]['fields'];
// from the above customGroupInfo we can get $this->_customGroupTitle
$this->_customGroupTitle = $groupDetail[$customGroupId]['title'];
}
if (!empty($fieldIDs) && $this->_contactId) {
$options = array();
$returnProperities = array(
'html_type',
'data_type',
'date_format',
'time_format',
'default_value',
'is_required',
'is_view',
);
foreach ($fieldIDs as $key => $fieldID) {
$fieldIDs[$key] = !is_numeric($fieldID) ? CRM_Core_BAO_CustomField::getKeyID($fieldID) : $fieldID;
$param = array('id' => $fieldIDs[$key]);
$returnValues = array();
CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $param, $returnValues, $returnProperities);
if ($returnValues['data_type'] == 'Date') {
$dateFields[$fieldIDs[$key]] = 1;
$actualPHPFormats = CRM_Utils_Date::datePluginToPHPFormats();
$dateFormat = (array) CRM_Utils_Array::value($returnValues['date_format'], $actualPHPFormats);
$timeFormat = CRM_Utils_Array::value('time_format', $returnValues);
}
$optionValuePairs = CRM_Core_BAO_CustomOption::getCustomOption($fieldIDs[$key]);
if (!empty($optionValuePairs)) {
foreach ($optionValuePairs as $optionPairs) {
$options[$fieldIDs[$key]][$optionPairs['value']] = $optionPairs['label'];
}
}
$options[$fieldIDs[$key]]['attributes']['html_type'] = $returnValues['html_type'];
$options[$fieldIDs[$key]]['attributes']['data_type'] = $returnValues['data_type'];
$options[$fieldIDs[$key]]['attributes']['is_required'] = !empty($returnValues['is_required']);
$options[$fieldIDs[$key]]['attributes']['default_value'] = CRM_Utils_Array::value('default_value', $returnValues);
$options[$fieldIDs[$key]]['attributes']['is_view'] = CRM_Utils_Array::value('is_view', $returnValues);
$options[$fieldIDs[$key]]['attributes']['format']
= $options[$fieldIDs[$key]]['attributes']['date_format'] = CRM_Utils_Array::value('date_format', $returnValues);
$options[$fieldIDs[$key]]['attributes']['time_format'] = CRM_Utils_Array::value('time_format', $returnValues);
}
$linkAction = array_sum(array_keys($this->links()));
}
if (!empty($fieldIDs) && $this->_contactId) {
$DTparams = !empty($this->_DTparams) ? $this->_DTparams : NULL;
// commonly used for both views i.e profile listing view (profileDataView) and custom data listing view (customDataView)
$result = CRM_Core_BAO_CustomValueTable::getEntityValues($this->_contactId, NULL, $fieldIDs, TRUE, $DTparams);
$resultCount = !empty($result['count']) ? $result['count'] : count($result);
$sortedResult = !empty($result['sortedResult']) ? $result['sortedResult'] : array();
unset($result['count']);
unset($result['sortedResult']);
if ($this->_pageViewType == 'profileDataView') {
if (!empty($fieldIDs)) {
//get the group info of multi rec fields in listing view
$fieldInput = $fieldIDs;
$fieldIdInput = $fieldIDs[0];
}
else {
//if no listing fields exist, take the group title for display
$nonListingFieldIds = array_keys($multiRecordFields);
$singleField = CRM_Core_BAO_CustomField::getKeyID($nonListingFieldIds[0]);
$fieldIdInput = $singleField;
$singleField = array($singleField);
$fieldInput = $singleField;
}
$customGroupInfo = CRM_Core_BAO_CustomGroup::getGroupTitles($fieldInput);
$this->_customGroupTitle = $customGroupInfo[$fieldIdInput]['groupTitle'];
}
// $cgcount is defined before 'if' condition as entity may have no record
// and $cgcount is used to build new record url
$cgcount = 1;
$newCgCount = (!$reached) ? $resultCount + 1 : NULL;
if (!empty($result) && empty($this->_headersOnly)) {
$links = self::links();
if ($this->_pageViewType == 'profileDataView') {
$pageCheckSum = $this->get('pageCheckSum');
if ($pageCheckSum) {
foreach ($links as $key => $link) {
$links[$key] = $link['qs'] . "&cs=%%cs%%";
}
}
}
if ($reached) {
unset($links[CRM_Core_Action::COPY]);
}
if (!empty($DTparams)) {
$this->_total = $resultCount;
$cgcount = $DTparams['offset'] + 1;
}
foreach ($result as $recId => &$value) {
foreach ($value as $fieldId => &$val) {
if (is_numeric($fieldId)) {
$customValue = &$val;
if (!empty($dateFields) && array_key_exists($fieldId, $dateFields)) {
// formatted date capture value capture
$dateFieldsVals[$fieldId][$recId] = CRM_Core_BAO_CustomField::displayValue($customValue, $fieldId);
//set date and time format
switch ($timeFormat) {
case 1:
$dateFormat[1] = 'g:iA';
break;
case 2:
$dateFormat[1] = 'G:i';
break;
default:
// if time is not selected remove time from value
$result[$recId][$fieldId] = substr($result[$recId][$fieldId], 0, 10);
}
$result[$recId][$fieldId] = CRM_Utils_Date::processDate($result[$recId][$fieldId], NULL, FALSE, implode(" ", $dateFormat));
}
else {
// assign to $result
$customValue = CRM_Core_BAO_CustomField::displayValue($customValue, $fieldId);
}
// Set field attributes to support crmEditable
// Note that $fieldAttributes[data-type] actually refers to the html type not the sql data type
// TODO: Not all widget types and validation rules are supported by crmEditable so some fields will not be in-place editable
$fieldAttributes = array('class' => "crmf-custom_{$fieldId}_$recId");
$editable = FALSE;
if (!$options[$fieldId]['attributes']['is_view'] && $linkAction & CRM_Core_Action::UPDATE) {
$spec = $options[$fieldId]['attributes'];
switch ($spec['html_type']) {
case 'Text':
// Other data types like money would require some extra validation
// FIXME: crmEditable currently does not support any validation rules :(
$supportedDataTypes = array('Float', 'String', 'Int');
$editable = in_array($spec['data_type'], $supportedDataTypes);
break;
case 'TextArea':
$editable = TRUE;
$fieldAttributes['data-type'] = 'textarea';
break;
case 'Radio':
case 'Select':
case 'Select Country':
case 'Select State/Province':
$editable = TRUE;
$fieldAttributes['data-type'] = $spec['data_type'] == 'Boolean' ? 'boolean' : 'select';
if (!$spec['is_required']) {
$fieldAttributes['data-empty-option'] = ts('- none -');
}
break;
}
}
if ($editable) {
$fieldAttributes['class'] .= ' crm-editable';
}
$attributes[$fieldId][$recId] = $fieldAttributes;
$op = NULL;
if ($this->_pageViewType == 'profileDataView') {
$actionParams = array(
'recordId' => $recId,
'gid' => $this->_profileId,
'id' => $this->_contactId,
);
$op = 'profile.multiValue.row';
}
else {
// different set of url params
$actionParams['gid'] = $actionParams['groupID'] = $this->_customGroupId;
$actionParams['cid'] = $actionParams['entityID'] = $this->_contactId;
$actionParams['recId'] = $recId;
$actionParams['type'] = $this->_contactType;
$actionParams['cgcount'] = empty($DTparams['sort']) ? $cgcount : $sortedResult[$recId];
$actionParams['newCgCount'] = $newCgCount;
// DELETE action links
$deleteData = array(
'valueID' => $recId,
'groupID' => $this->_customGroupId,
'contactId' => $this->_contactId,
'key' => CRM_Core_Key::get('civicrm/ajax/customvalue'),
);
$links[CRM_Core_Action::DELETE]['url'] = '#';
$links[CRM_Core_Action::DELETE]['extra'] = ' data-delete_params="' . htmlspecialchars(json_encode($deleteData)) . '"';
$links[CRM_Core_Action::DELETE]['class'] = 'delete-custom-row';
}
if (!empty($pageCheckSum)) {
$actionParams['cs'] = $pageCheckSum;
}
$value['action'] = CRM_Core_Action::formLink(
$links,
$linkAction,
$actionParams,
ts('more'),
FALSE,
$op,
'customValue',
$fieldId
);
}
}
$cgcount++;
}
}
}
$headers = array();
if (!empty($fieldIDs)) {
$fields = array('Radio', 'Select', 'Select Country', 'Select State/Province');
foreach ($fieldIDs as $fieldID) {
if ($this->_pageViewType == 'profileDataView') {
$headers[$fieldID] = $customGroupInfo[$fieldID]['fieldLabel'];
}
elseif (!empty($this->_headersOnly)) {
if (!$options[$fieldID]['attributes']['is_view'] && $linkAction & CRM_Core_Action::UPDATE) {
$spec = $options[$fieldID]['attributes'];
if (in_array($spec['html_type'], $fields)) {
$headerAttr[$fieldID]['dataType'] = $spec['data_type'] == 'Boolean' ? 'boolean' : 'select';
if (!$spec['is_required']) {
$headerAttr[$fieldID]['dataEmptyOption'] = ts('- none -');
}
}
elseif ($spec['html_type'] == 'TextArea') {
$headerAttr[$fieldID]['dataType'] = 'textarea';
}
}
$headers[$fieldID] = $fieldLabels[$fieldID]['label'];
$headerAttr[$fieldID]['columnName'] = $fieldLabels[$fieldID]['column_name'];
}
}
}
$this->assign('dateFields', $dateFields);
$this->assign('dateFieldsVals', $dateFieldsVals);
$this->assign('cgcount', $cgcount);
$this->assign('newCgCount', $newCgCount);
$this->assign('contactId', $this->_contactId);
$this->assign('contactType', $this->_contactType);
$this->assign('customGroupTitle', $this->_customGroupTitle);
$this->assign('headers', $headers);
$this->assign('headerAttr', $headerAttr);
$this->assign('records', $result);
$this->assign('attributes', $attributes);
return array($result, $attributes);
}
/**
* Get name of edit form.
*
* @return string
* classname of edit form
*/
public function editForm() {
return '';
}
/**
* Get edit form name.
*
* @return string
* name of this page
*/
public function editName() {
return '';
}
/**
* Get user context.
*
* @param null $mode
*
* @return string
* user context
*/
public function userContext($mode = NULL) {
return '';
}
}

View file

@ -0,0 +1,130 @@
<?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 is some kind of special-purpose router/front-controller for the various profile URLs.
*/
class CRM_Profile_Page_Router extends CRM_Core_Page {
/**
* This is some kind of special-purpose router/front-controller for the various profile URLs.
*
* @param array $args
* this array contains the arguments of the url.
*
* @return string|void
*/
public function run($args = NULL) {
if ($args[1] !== 'profile') {
return NULL;
}
$secondArg = CRM_Utils_Array::value(2, $args, '');
if ($secondArg == 'map') {
$controller = new CRM_Core_Controller_Simple(
'CRM_Contact_Form_Task_Map',
ts('Map Contact'),
NULL, FALSE, FALSE, TRUE
);
$gids = explode(',', CRM_Utils_Request::retrieve('gid', 'String', CRM_Core_DAO::$_nullObject, FALSE, 0, 'GET'));
if (count($gids) > 1) {
foreach ($gids as $pfId) {
$profileIds[] = CRM_Utils_Type::escape($pfId, 'Positive');
}
$controller->set('gid', $profileIds[0]);
$profileGID = $profileIds[0];
}
else {
$profileGID = CRM_Utils_Request::retrieve('gid', 'Integer', $controller, TRUE);
}
// make sure that this profile enables mapping
// CRM-8609
$isMap = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileGID, 'is_map');
if (!$isMap) {
CRM_Core_Error::statusBounce(ts('This profile does not have the map feature turned on.'));
}
$profileView = CRM_Utils_Request::retrieve('pv', 'Integer', $controller, FALSE);
// set the userContext stack
$session = CRM_Core_Session::singleton();
if ($profileView) {
$session->pushUserContext(CRM_Utils_System::url('civicrm/profile/view'));
}
else {
$session->pushUserContext(CRM_Utils_System::url('civicrm/profile', 'force=1'));
}
$controller->set('profileGID', $profileGID);
$controller->process();
return $controller->run();
}
if ($secondArg == 'edit' || $secondArg == 'create') {
$allowRemoteSubmit = Civi::settings()->get('remote_profile_submissions');
if ($secondArg == 'edit') {
$controller = new CRM_Core_Controller_Simple('CRM_Profile_Form_Edit',
ts('Create Profile'),
CRM_Core_Action::UPDATE,
FALSE, FALSE, $allowRemoteSubmit
);
$controller->set('edit', 1);
$controller->process();
return $controller->run();
}
else {
$wrapper = new CRM_Utils_Wrapper();
return $wrapper->run('CRM_Profile_Form_Edit',
ts('Create Profile'),
array(
'mode' => CRM_Core_Action::ADD,
'ignoreKey' => $allowRemoteSubmit,
)
);
}
}
if ($secondArg == 'view' || empty($secondArg)) {
$page = new CRM_Profile_Page_Listings();
return $page->run();
}
CRM_Utils_System::permissionDenied();
}
}

View file

@ -0,0 +1,218 @@
<?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_Profile_Page_View extends CRM_Core_Page {
/**
* The id of the contact.
*
* @var int
*/
protected $_id;
/**
* The group id that we are editing.
*
* @var int
*/
protected $_gid;
/**
* 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() {
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive',
$this, FALSE
);
if (!$this->_id) {
$session = CRM_Core_Session::singleton();
$this->_id = $session->get('userID');
if (!$this->_id) {
CRM_Core_Error::fatal(ts('Could not find the required contact id parameter (id=) for viewing a contact record with a Profile.'));
}
}
$this->assign('cid', $this->_id);
$gids = explode(',', CRM_Utils_Request::retrieve('gid', 'String', CRM_Core_DAO::$_nullObject, FALSE, 0, 'GET'));
$profileIds = array();
if (count($gids) > 1) {
if (!empty($gids)) {
foreach ($gids as $pfId) {
$profileIds[] = CRM_Utils_Type::escape($pfId, 'Positive');
}
}
// check if we are rendering mixed profiles
if (CRM_Core_BAO_UFGroup::checkForMixProfiles($profileIds)) {
CRM_Core_Error::fatal(ts('You cannot combine profiles of multiple types.'));
}
$this->_gid = $profileIds[0];
}
if (!$this->_gid) {
$this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, FALSE, 0, 'GET');
}
$anyContent = TRUE;
if ($this->_gid) {
$page = new CRM_Profile_Page_Dynamic($this->_id, $this->_gid, 'Profile', FALSE, $profileIds);
$profileGroup = array();
$profileGroup['title'] = NULL;
$profileGroup['content'] = $page->run();
if (empty($profileGroup['content'])) {
$anyContent = FALSE;
}
$profileGroups[] = $profileGroup;
$gidString = $this->_gid;
if (!empty($profileIds)) {
$gidString = implode(',', $profileIds);
}
$map = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'is_map');
if ($map) {
$this->assign('mapURL',
CRM_Utils_System::url("civicrm/profile/map",
"reset=1&pv=1&cid={$this->_id}&gid={$gidString}"
)
);
}
if (CRM_Core_Permission::ufGroupValid($this->_gid,
CRM_Core_Permission::SEARCH
)
) {
$this->assign('listingURL',
CRM_Utils_System::url("civicrm/profile",
"force=1&gid={$gidString}"
)
);
}
}
else {
$ufGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup('Profile');
$profileGroups = array();
foreach ($ufGroups as $groupid => $group) {
$page = new CRM_Profile_Page_Dynamic($this->_id, $groupid, 'Profile', FALSE, $profileIds);
$profileGroup = array();
$profileGroup['title'] = $group['title'];
$profileGroup['content'] = $page->run();
if (empty($profileGroup['content'])) {
$anyContent = FALSE;
}
$profileGroups[] = $profileGroup;
}
$this->assign('listingURL',
CRM_Utils_System::url("civicrm/profile",
"force=1"
)
);
}
$this->assign('groupID', $this->_gid);
$this->assign('profileGroups', $profileGroups);
$this->assign('recentlyViewed', FALSE);
// do not set title if there is no content
// CRM-6081
if (!$anyContent) {
CRM_Utils_System::setTitle('');
}
}
/**
* Build the outcome basing on the CRM_Profile_Page_Dynamic's HTML.
*
*/
public function run() {
$this->preProcess();
return parent::run();
}
/**
* @param string $suffix
*
* @return null|string
*/
public function checkTemplateFileExists($suffix = '') {
if ($this->_gid) {
$templateFile = "CRM/Profile/Page/{$this->_gid}/View.{$suffix}tpl";
$template = CRM_Core_Page::getTemplate();
if ($template->template_exists($templateFile)) {
return $templateFile;
}
// lets see if we have customized by name
$ufGroupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'name');
if ($ufGroupName) {
$templateFile = "CRM/Profile/Page/{$ufGroupName}/View.{$suffix}tpl";
if ($template->template_exists($templateFile)) {
return $templateFile;
}
}
}
return NULL;
}
/**
* Use the form name to create the tpl file name.
*
* @return string
*/
public function getTemplateFileName() {
$fileName = $this->checkTemplateFileExists();
return $fileName ? $fileName : parent::getTemplateFileName();
}
/**
* Default extra tpl file basically just replaces .tpl with .extra.tpl
* i.e. we dont override
*
* @return string
*/
public function overrideExtraTemplateFileName() {
$fileName = $this->checkTemplateFileExists('extra.');
return $fileName ? $fileName : parent::overrideExtraTemplateFileName();
}
}