/** * Run the page. * * This method is called after the page is created. It checks for the * type of action and executes that action. * * @return void */ 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())); }
/** * Build the form object. */ public function buildQuickForm() { // Is proximity search enabled for this profile? $proxSearch = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->get('gid'), 'is_proximity_search', 'id'); if ($proxSearch) { CRM_Contact_Form_Task_ProximityCommon::buildQuickForm($this, $proxSearch); } $this->addButtons(array(array('type' => 'refresh', 'name' => ts('Search'), 'isDefault' => TRUE))); parent::buildQuickForm(); }
/** * Submit a set of fields against a profile. * * Note choice of submit versus create is discussed CRM-13234 & related to the fact * 'profile' is being treated as a data-entry entity * * @param array $params * * @throws API_Exception * @return array * API result array */ function civicrm_api3_profile_submit($params) { $profileID = _civicrm_api3_profile_getProfileID($params['profile_id']); if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileID, 'is_active')) { //@todo declare pseudoconstant & let api do this throw new API_Exception('Invalid value for profile_id'); } $isContactActivityProfile = CRM_Core_BAO_UFField::checkContactActivityProfileType($profileID); if (!empty($params['id']) && CRM_Core_BAO_UFField::checkProfileType($profileID) && !$isContactActivityProfile) { throw new API_Exception('Update profiles including more than one entity not currently supported'); } $contactParams = $activityParams = $missingParams = array(); $profileFields = civicrm_api3('Profile', 'getfields', array('action' => 'submit', 'profile_id' => $profileID)); $profileFields = $profileFields['values']; if ($isContactActivityProfile) { civicrm_api3_verify_mandatory($params, NULL, array('activity_id')); $errors = CRM_Profile_Form::validateContactActivityProfile($params['activity_id'], $params['contact_id'], $profileID); if (!empty($errors)) { throw new API_Exception(array_pop($errors)); } } foreach ($profileFields as $fieldName => $field) { if (!isset($params[$fieldName])) { continue; } $value = $params[$fieldName]; if ($params[$fieldName] && isset($params[$fieldName . '_id'])) { $value = $params[$fieldName . '_id']; } $contactEntities = array('contact', 'individual', 'organization', 'household'); $locationEntities = array('email', 'address', 'phone', 'website', 'im'); $entity = strtolower(CRM_Utils_Array::value('entity', $field)); if ($entity && !in_array($entity, array_merge($contactEntities, $locationEntities))) { $contactParams['api.' . $entity . '.create'][$fieldName] = $value; //@todo we are not currently declaring this option if (isset($params['batch_id']) && strtolower($entity) == 'contribution') { $contactParams['api.' . $entity . '.create']['batch_id'] = $params['batch_id']; } if (isset($params[$entity . '_id'])) { //todo possibly declare $entity_id in getfields ? $contactParams['api.' . $entity . '.create']['id'] = $params[$entity . '_id']; } } else { $contactParams[_civicrm_api3_profile_translate_fieldnames_for_bao($fieldName)] = $value; } } if (isset($contactParams['api.contribution.create']) && isset($contactParams['api.membership.create'])) { $contactParams['api.membership_payment.create'] = array('contribution_id' => '$value.api.contribution.create.id', 'membership_id' => '$value.api.membership.create.id'); } if (isset($contactParams['api.contribution.create']) && isset($contactParams['api.participant.create'])) { $contactParams['api.participant_payment.create'] = array('contribution_id' => '$value.api.contribution.create.id', 'participant_id' => '$value.api.participant.create.id'); } $contactParams['contact_id'] = CRM_Utils_Array::value('contact_id', $params); $contactParams['profile_id'] = $profileID; $contactParams['skip_custom'] = 1; $contactProfileParams = civicrm_api3_profile_apply($contactParams); // Contact profile fields $profileParams = $contactProfileParams['values']; // If profile having activity fields if ($isContactActivityProfile && !empty($activityParams)) { $activityParams['id'] = $params['activity_id']; $profileParams['api.activity.create'] = $activityParams; } return civicrm_api3('contact', 'create', $profileParams); }
/** * Process the user submitted custom data values. * * @access public * @return void */ function postProcess() { parent::postProcess(); }
/** * Intercept QF validation and do our own redirection. * * We use this to send control back to the user for a user formatted page * This allows the user to maintain the same state and display the error messages * in their own theme along with any modifications * * This is a first version and will be tweaked over a period of time * * * @return bool * true if no error found */ public function validate() { $errors = parent::validate(); if (!$errors && !empty($_POST['errorURL'])) { $message = NULL; foreach ($this->_errors as $name => $mess) { $message .= $mess; $message .= '<p>'; } CRM_Utils_System::setUFMessage($message); $message = urlencode($message); $errorURL = $_POST['errorURL']; if (strpos($errorURL, '?') !== FALSE) { $errorURL .= '&'; } else { $errorURL .= '?'; } $errorURL .= "gid={$this->_gid}&msg={$message}"; CRM_Utils_System::redirect($errorURL); } return $errors; }
/** * Function to intercept QF validation and do our own redirection * * We use this to send control back to the user for a user formatted page * This allows the user to maintain the same state and display the error messages * in their own theme along with any modifications * * This is a first version and will be tweaked over a period of time * * @access public * @return boolean true if no error found */ function validate() { $errors = parent::validate(); if (!$errors && CRM_Utils_Array::value('errorURL', $_POST)) { $message = null; foreach ($this->_errors as $name => $mess) { $message .= $mess; $message .= '<p>'; } if (function_exists('drupal_set_message')) { drupal_set_message($message); } $message = urlencode($message); $errorURL = $_POST['errorURL']; if (strpos($errorURL, '?') !== false) { $errorURL .= '&'; } else { $errorURL .= '?'; } $errorURL .= "gid={$this->_gid}&msg={$message}"; CRM_Utils_System::redirect($errorURL); } return $errors; }
/** * Function to actually build the form * * @return void * @access public */ function buildQuickForm() { $this->addButtons(array(array('type' => 'refresh', 'name' => ts('Search'), 'isDefault' => true))); parent::buildQuickForm(); }
/** * Run the page. * * This method is called after the page is created. It checks for the * type of action and executes that action. * * @return void * @access 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.')); } } $values = array(); $fields = CRM_Core_BAO_UFGroup::getFields($this->_profileIds, FALSE, CRM_Core_Action::VIEW, NULL, NULL, FALSE, $this->_restrict, $this->_skipPermission, NULL, CRM_Core_Permission::VIEW); 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)); } } $session = CRM_Core_Session::singleton(); $userID = $session->get('userID'); $this->_isPermissionedChecksum = FALSE; 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); } else { $this->_isPermissionedChecksum = CRM_Contact_BAO_Contact_Permission::validateChecksumContact($this->_id, $this, FALSE); } } // make sure we dont expose all fields based on permission $admin = FALSE; if (!$config->userFrameworkFrontend && (CRM_Core_Permission::check('administer users') || CRM_Core_Permission::check('view all contacts') || CRM_Contact_BAO_Contact_Permission::allow($this->_id, CRM_Core_Permission::VIEW)) || $this->_id == $userID || $this->_isPermissionedChecksum) { $admin = TRUE; } if (!$admin) { foreach ($fields as $name => $field) { // make sure that there is enough permission to expose this field if ($field['visibility'] == 'User and User Admin Only') { unset($fields[$name]); } } } // also eliminate all formatting fields foreach ($fields as $name => $field) { if (CRM_Utils_Array::value('field_type', $field) == 'Formatting') { 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 { CRM_Core_BAO_UFGroup::getValues($this->_id, $fields, $values); } // $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) { $labels[$field['title']] = 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'); if (strtolower($name) == 'summary_overlay') { $template->assign('overlayProfile', TRUE); } $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; } CRM_Utils_System::setTitle($title); // invoke the pagRun hook, CRM-3906 CRM_Utils_Hook::pageRun($this); return trim($template->fetch($this->getTemplateFileName())); }
/** * Update Profile field values. * * @param array $params Associative array of property name/value * pairs to update profile field values * * @return Updated Contact/ Activity object|CRM_Error * * @todo add example * @todo add test cases * */ function civicrm_api3_profile_set($params) { civicrm_api3_verify_mandatory($params, NULL, array('profile_id')); if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $params['profile_id'], 'is_active')) { return civicrm_api3_create_error('Invalid value for profile_id'); } $isContactActivityProfile = CRM_Core_BAO_UFField::checkContactActivityProfileType($params['profile_id']); if (CRM_Core_BAO_UFField::checkProfileType($params['profile_id']) && !$isContactActivityProfile) { return civicrm_api3_create_error('Can not retrieve values for profiles include fields for more than one record type.'); } $contactParams = $activityParams = $missingParams = array(); $profileFields = CRM_Core_BAO_UFGroup::getFields($params['profile_id'], FALSE, NULL, NULL, NULL, FALSE, NULL, TRUE, NULL, CRM_Core_Permission::EDIT); if ($isContactActivityProfile) { civicrm_api3_verify_mandatory($params, NULL, array('activity_id')); require_once 'CRM/Profile/Form.php'; $errors = CRM_Profile_Form::validateContactActivityProfile($params['activity_id'], $params['contact_id'], $params['profile_id']); if (!empty($errors)) { return civicrm_api3_create_error(array_pop($errors)); } } foreach ($profileFields as $fieldName => $field) { if (CRM_Utils_Array::value('is_required', $field)) { if (!CRM_Utils_Array::value($fieldName, $params) || empty($params[$fieldName])) { $missingParams[] = $fieldName; } } if (!isset($params[$fieldName])) { continue; } $value = $params[$fieldName]; if ($params[$fieldName] && isset($params[$fieldName . '_id'])) { $value = $params[$fieldName . '_id']; } if ($isContactActivityProfile && CRM_Utils_Array::value('field_type', $field) == 'Activity') { $activityParams[$fieldName] = $value; } else { $contactParams[$fieldName] = $value; } } if (!empty($missingParams)) { return civicrm_api3_create_error("Missing required parameters for profile id {$params['profile_id']}: " . implode(', ', $missingParams)); } $contactParams['version'] = 3; $contactParams['contact_id'] = CRM_Utils_Array::value('contact_id', $params); $contactParams['profile_id'] = $params['profile_id']; $contactParams['skip_custom'] = 1; $contactProfileParams = civicrm_api3_profile_apply($contactParams); if (CRM_Utils_Array::value('is_error', $contactProfileParams)) { return $contactProfileParams; } // Contact profile fields $profileParams = $contactProfileParams['values']; // If profile having activity fields if ($isContactActivityProfile && !empty($activityParams)) { $activityParams['id'] = $params['activity_id']; $profileParams['api.activity.create'] = $activityParams; } $groups = $tags = array(); if (isset($profileParams['group'])) { $groups = $profileParams['group']; unset($profileParams['group']); } if (isset($profileParams['tag'])) { $tags = $profileParams['tag']; unset($profileParams['tag']); } $result = civicrm_api('contact', 'create', $profileParams); if (CRM_Utils_Array::value('is_error', $result)) { return $result; } $ufGroupDetails = array(); $ufGroupParams = array('id' => $params['profile_id']); CRM_Core_BAO_UFGroup::retrieve($ufGroupParams, $ufGroupDetails); if (isset($profileFields['group'])) { CRM_Contact_BAO_GroupContact::create($groups, $params['contact_id'], FALSE, 'Admin'); } if (isset($profileFields['tag'])) { require_once 'CRM/Core/BAO/EntityTag.php'; CRM_Core_BAO_EntityTag::create($tags, 'civicrm_contact', $params['contact_id']); } if (CRM_Utils_Array::value('add_to_group_id', $ufGroupDetails)) { $contactIds = array($params['contact_id']); CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $ufGroupDetails['add_to_group_id']); } return $result; }