function fileDisplay() { // Display evidence file $postParams = $_POST; $fileID = CRM_Core_BAO_File::getEntityFile($postParams['entityTable'], $postParams['entityID']); if ($fileID) { foreach ($fileID as $k => $v) { $fileType = $v['mime_type']; $fid = $v['fileID']; $eid = $postParams['entityID']; if ($fileType == 'image/jpeg' || $fileType == 'image/pjpeg' || $fileType == 'image/gif' || $fileType == 'image/x-png' || $fileType == 'image/png') { list($path) = CRM_Core_BAO_File::path($fid, $eid, NULL, NULL); list($imageWidth, $imageHeight) = getimagesize($path); list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight); $url = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fid}&eid={$eid}", FALSE, NULL, TRUE, TRUE); $file_url = "\n <a href=\"{$url}\" class='crm-image-popup'>\n <img src=\"{$url}\" width={$imageThumbWidth} height={$imageThumbHeight}/>\n </a>"; // for non image files } else { $uri = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_File', $fid, 'uri'); $url = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fid}&eid={$eid}"); $file_url = "<a href=\"{$url}\">{$uri}</a>"; } if (isset($fid)) { $deleteurl = "<div class=file-delete><a class='action-item crm-hover-button' href='javascript:void(0)' id=file_{$fid}>Delete Attached File</a></div>"; echo "<div id='del_{$fid}'>{$file_url}{$deleteurl}</div>"; } } } CRM_Utils_System::civiExit(); }
/** * Set default values for the form. Note that in edit/view mode * the default values are retrieved from the database * * * @return void */ public function setDefaultsValues() { $this->_defaults = array(); if ($this->_multiRecordProfile && $this->_multiRecord == CRM_Core_Action::DELETE) { return; } if ($this->_mode != self::MODE_SEARCH) { // set default values for country / state to start with CRM_Core_BAO_UFGroup::setRegisterDefaults($this->_fields, $this->_defaults); } if ($this->_id && !$this->_multiRecordProfile) { if ($this->_isContactActivityProfile) { $contactFields = $activityFields = array(); foreach ($this->_fields as $fieldName => $field) { if (CRM_Utils_Array::value('field_type', $field) == 'Activity') { $activityFields[$fieldName] = $field; } else { $contactFields[$fieldName] = $field; } } CRM_Core_BAO_UFGroup::setProfileDefaults($this->_id, $contactFields, $this->_defaults, TRUE); if ($this->_activityId) { CRM_Core_BAO_UFGroup::setComponentDefaults($activityFields, $this->_activityId, 'Activity', $this->_defaults, TRUE); } } else { CRM_Core_BAO_UFGroup::setProfileDefaults($this->_id, $this->_fields, $this->_defaults, TRUE); } } //set custom field defaults if ($this->_multiRecordProfile) { foreach ($this->_multiRecordFields as $key => $field) { $fieldIds[] = CRM_Core_BAO_CustomField::getKeyID($key); } $defaultValues = array(); if ($this->_multiRecord && $this->_multiRecord == CRM_Core_Action::UPDATE) { $defaultValues = CRM_Core_BAO_CustomValueTable::getEntityValues($this->_id, NULL, $fieldIds, TRUE); if ($this->_recordExists == TRUE) { $defaultValues = $defaultValues[$this->_recordId]; } else { $defaultValues = NULL; } } if (!empty($defaultValues)) { foreach ($defaultValues as $key => $value) { $name = "custom_{$key}"; $htmlType = $this->_multiRecordFields[$name]['html_type']; if ($htmlType != 'File') { if (isset($value)) { CRM_Core_BAO_CustomField::setProfileDefaults($key, $name, $this->_defaults, $this->_id, $this->_mode, $value); } else { $this->_defaults[$name] = ""; } } if ($htmlType == 'File') { $entityId = $this->_id; if (CRM_Utils_Array::value('field_type', $field) == 'Activity' && $this->_activityId) { $entityId = $this->_activityId; } $url = CRM_Core_BAO_CustomField::getFileURL($entityId, $key); if ($url) { $customFiles[$name]['displayURL'] = ts("Attached File") . ": {$url['file_url']}"; $deleteExtra = ts("Are you sure you want to delete attached file?"); $fileId = $url['file_id']; $deleteURL = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$entityId}&fid={$key}&action=delete"); $text = ts("Delete Attached File"); $customFiles[$field['name']]['deleteURL'] = "<a href=\"{$deleteURL}\" onclick = \"if (confirm( ' {$deleteExtra} ' )) this.href+='&confirmed=1'; else return false;\">{$text}</a>"; // also delete the required rule that we've set on the form element $this->removeFileRequiredRules($name); } } } } } else { foreach ($this->_fields as $name => $field) { if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) { $htmlType = $field['html_type']; if ((!isset($this->_defaults[$name]) || $htmlType == 'File') && CRM_Utils_Array::value('field_type', $field) != 'Activity') { CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $this->_id, $this->_mode); } if ($htmlType == 'File') { $entityId = $this->_id; if (CRM_Utils_Array::value('field_type', $field) == 'Activity' && $this->_activityId) { $entityId = $this->_activityId; } $url = CRM_Core_BAO_CustomField::getFileURL($entityId, $customFieldID); if ($url) { $customFiles[$field['name']]['displayURL'] = ts("Attached File") . ": {$url['file_url']}"; $deleteExtra = ts("Are you sure you want to delete attached file?"); $fileId = $url['file_id']; $deleteURL = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$entityId}&fid={$customFieldID}&action=delete"); $text = ts("Delete Attached File"); $customFiles[$field['name']]['deleteURL'] = "<a href=\"{$deleteURL}\" onclick = \"if (confirm( ' {$deleteExtra} ' )) this.href+='&confirmed=1'; else return false;\">{$text}</a>"; // also delete the required rule that we've set on the form element $this->removeFileRequiredRules($field['name']); } } } } } if (isset($customFiles)) { $this->assign('customFiles', $customFiles); } if ($this->_multiRecordProfile) { $this->setDefaults($this->_defaults); return; } if (!empty($this->_defaults['image_URL'])) { list($imageWidth, $imageHeight) = getimagesize(CRM_Utils_String::unstupifyUrl($this->_defaults['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", $this->_defaults['image_URL']); $this->removeFileRequiredRules('image_URL'); } if (array_key_exists('contact_sub_type', $this->_defaults) && !empty($this->_defaults['contact_sub_type'])) { $this->_defaults['contact_sub_type'] = explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($this->_defaults['contact_sub_type'], CRM_Core_DAO::VALUE_SEPARATOR)); } $this->setDefaults($this->_defaults); }
/** * Given a contact id and a field set, return the values from the db * for this contact * * @param int $cid * @param array $fields * The profile fields of interest. * @param array $values * The values for the above fields. * @param bool $searchable * Searchable or not. * @param array $componentWhere * Component condition. * @param bool $absolute * Return urls in absolute form (useful when sending an email). * @param null $additionalWhereClause */ public static function getValues($cid, &$fields, &$values, $searchable = TRUE, $componentWhere = NULL, $absolute = FALSE, $additionalWhereClause = NULL) { if (empty($cid) && empty($componentWhere)) { return NULL; } // get the contact details (hier) $returnProperties = CRM_Contact_BAO_Contact::makeHierReturnProperties($fields); $params = $cid ? array(array('contact_id', '=', $cid, 0, 0)) : array(); // add conditions specified by components. eg partcipant_id etc if (!empty($componentWhere)) { $params = array_merge($params, $componentWhere); } $query = new CRM_Contact_BAO_Query($params, $returnProperties, $fields); $options =& $query->_options; $details = $query->searchQuery(0, 0, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, $additionalWhereClause); if (!$details->fetch()) { return; } $query->convertToPseudoNames($details); $config = CRM_Core_Config::singleton(); $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'); $websiteTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id'); $multipleFields = array('url'); //start of code to set the default values foreach ($fields as $name => $field) { // fix for CRM-3962 if ($name == 'id') { $name = 'contact_id'; } // skip fields that should not be displayed separately if (!empty($field['skipDisplay'])) { continue; } // Create a unique, non-empty index for each field. $index = $field['title']; if ($index === '') { $index = ' '; } while (array_key_exists($index, $values)) { $index .= ' '; } $params[$index] = $values[$index] = ''; $customFieldName = NULL; // hack for CRM-665 if (isset($details->{$name}) || $name == 'group' || $name == 'tag') { // to handle gender / suffix / prefix if (in_array(substr($name, 0, -3), array('gender', 'prefix', 'suffix'))) { $params[$index] = $details->{$name}; $values[$index] = $details->{$name}; } elseif (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes)) { $dname = $name . '_display'; $values[$index] = $details->{$dname}; $name = $name . '_id'; $params[$index] = $details->{$name}; } elseif (in_array($name, array('state_province', 'country', 'county'))) { $values[$index] = $details->{$name}; $idx = $name . '_id'; $params[$index] = $details->{$idx}; } elseif ($name === 'preferred_communication_method') { $communicationFields = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method'); $compref = array(); $pref = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details->{$name}); foreach ($pref as $k) { if ($k) { $compref[] = $communicationFields[$k]; } } $params[$index] = $details->{$name}; $values[$index] = implode(',', $compref); } elseif ($name === 'preferred_language') { $params[$index] = $details->{$name}; $values[$index] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', 'preferred_language', $details->{$name}); } elseif ($name == 'group') { $groups = CRM_Contact_BAO_GroupContact::getContactGroup($cid, 'Added', NULL, FALSE, TRUE); $title = $ids = array(); foreach ($groups as $g) { // CRM-8362: User and User Admin visibility groups should be included in display if user has // VIEW permission on that group $groupPerm = CRM_Contact_BAO_Group::checkPermission($g['group_id'], $g['title']); if ($g['visibility'] != 'User and User Admin Only' || CRM_Utils_Array::key(CRM_Core_Permission::VIEW, $groupPerm)) { $title[] = $g['title']; if ($g['visibility'] == 'Public Pages') { $ids[] = $g['group_id']; } } } $values[$index] = implode(', ', $title); $params[$index] = implode(',', $ids); } elseif ($name == 'tag') { $entityTags = CRM_Core_BAO_EntityTag::getTag($cid); $allTags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE)); $title = array(); foreach ($entityTags as $tagId) { $title[] = $allTags[$tagId]; } $values[$index] = implode(', ', $title); $params[$index] = implode(',', $entityTags); } elseif ($name == 'activity_status_id') { $activityStatus = CRM_Core_PseudoConstant::activityStatus(); $values[$index] = $activityStatus[$details->{$name}]; $params[$index] = $details->{$name}; } elseif ($name == 'activity_date_time') { $values[$index] = CRM_Utils_Date::customFormat($details->{$name}); $params[$index] = $details->{$name}; } elseif ($name == 'contact_sub_type') { $contactSubTypeNames = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details->{$name}); if (!empty($contactSubTypeNames)) { $contactSubTypeLabels = array(); // get all contact subtypes $allContactSubTypes = CRM_Contact_BAO_ContactType::subTypeInfo(); // build contact subtype labels array foreach ($contactSubTypeNames as $cstName) { if ($cstName) { $contactSubTypeLabels[] = $allContactSubTypes[$cstName]['label']; } } $values[$index] = implode(',', $contactSubTypeLabels); } $params[$index] = $details->{$name}; } else { if (substr($name, 0, 7) === 'do_not_' || substr($name, 0, 3) === 'is_') { if ($details->{$name}) { $values[$index] = '[ x ]'; } } else { if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) { $htmlType = $field['html_type']; // field_type is only set when we are retrieving profile values // when sending email, we call the same function to get custom field // values etc, i.e. emulating a profile $fieldType = CRM_Utils_Array::value('field_type', $field); if ($htmlType == 'File') { $entityId = $cid; if (!$cid && $fieldType == 'Activity' && !empty($componentWhere[0][2])) { $entityId = $componentWhere[0][2]; } $fileURL = CRM_Core_BAO_CustomField::getFileURL($entityId, $cfID, NULL, $absolute, $additionalWhereClause); $params[$index] = $values[$index] = $fileURL['file_url']; } else { $customVal = NULL; if (isset($dao) && property_exists($dao, 'data_type') && ($dao->data_type == 'Int' || $dao->data_type == 'Boolean')) { $customVal = (int) $details->{$name}; } elseif (isset($dao) && property_exists($dao, 'data_type') && $dao->data_type == 'Float') { $customVal = (double) $details->{$name}; } elseif (!CRM_Utils_System::isNull(explode(CRM_Core_DAO::VALUE_SEPARATOR, $details->{$name}))) { $customVal = $details->{$name}; } //CRM-4582 if (CRM_Utils_System::isNull($customVal)) { continue; } $params[$index] = $customVal; $values[$index] = CRM_Core_BAO_CustomField::getDisplayValue($customVal, $cfID, $options); if ($field['data_type'] == 'ContactReference') { $params[$index] = $values[$index]; } if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $cfID, 'is_search_range')) { $customFieldName = "{$name}_from"; } } } elseif ($name == 'image_URL') { list($width, $height) = getimagesize(CRM_Utils_String::unstupifyUrl($details->{$name})); list($thumbWidth, $thumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($width, $height); $image_URL = '<img src="' . $details->{$name} . '" height= ' . $thumbHeight . ' width= ' . $thumbWidth . ' />'; $values[$index] = "<a href='#' onclick='contactImagePopUp(\"{$details->{$name}}\", {$width}, {$height});'>{$image_URL}</a>"; } elseif (in_array($name, array('birth_date', 'deceased_date', 'membership_start_date', 'membership_end_date', 'join_date'))) { $values[$index] = CRM_Utils_Date::customFormat($details->{$name}); $params[$index] = CRM_Utils_Date::isoToMysql($details->{$name}); } else { $dao = ''; if ($index == 'Campaign') { $dao = 'CRM_Campaign_DAO_Campaign'; } elseif ($index == 'Contribution Page') { $dao = 'CRM_Contribute_DAO_ContributionPage'; } if ($dao) { $value = CRM_Core_DAO::getFieldValue($dao, $details->{$name}, 'title'); } else { $value = $details->{$name}; } $values[$index] = $value; } } } } elseif (strpos($name, '-') !== FALSE) { list($fieldName, $id, $type) = CRM_Utils_System::explode('-', $name, 3); if (!in_array($fieldName, $multipleFields)) { if ($id == 'Primary') { // fix for CRM-1543 // not sure why we'd every use Primary location type id // we need to fix the source if we are using it // $locationTypeName = CRM_Contact_BAO_Contact::getPrimaryLocationType( $cid ); $locationTypeName = 1; } else { $locationTypeName = CRM_Utils_Array::value($id, $locationTypes); } if (!$locationTypeName) { continue; } $detailName = "{$locationTypeName}-{$fieldName}"; $detailName = str_replace(' ', '_', $detailName); if (in_array($fieldName, array('phone', 'im', 'email', 'openid'))) { if ($type) { $detailName .= "-{$type}"; } } if (in_array($fieldName, array('state_province', 'country', 'county'))) { $values[$index] = $details->{$detailName}; $idx = $detailName . '_id'; $params[$index] = $details->{$idx}; } elseif ($fieldName == 'im') { $providerId = $detailName . '-provider_id'; if (isset($imProviders[$details->{$providerId}])) { $values[$index] = $details->{$detailName} . " (" . $imProviders[$details->{$providerId}] . ")"; } else { $values[$index] = $details->{$detailName}; } $params[$index] = $details->{$detailName}; } elseif ($fieldName == 'phone') { $phoneExtField = str_replace('phone', 'phone_ext', $detailName); if (isset($details->{$phoneExtField})) { $values[$index] = $details->{$detailName} . " (" . $details->{$phoneExtField} . ")"; } else { $values[$index] = $details->{$detailName}; } $params[$index] = $details->{$detailName}; } else { $values[$index] = $params[$index] = $details->{$detailName}; } } else { $detailName = "website-{$id}-{$fieldName}"; $url = CRM_Utils_System::fixURL($details->{$detailName}); if ($details->{$detailName}) { $websiteTypeId = "website-{$id}-website_type_id"; $websiteType = $websiteTypes[$details->{$websiteTypeId}]; $values[$index] = "<a href=\"{$url}\">{$details->{$detailName}} ( {$websiteType} )</a>"; } else { $values[$index] = ''; } } } if (CRM_Utils_Array::value('visibility', $field) == 'Public Pages and Listings' && CRM_Core_Permission::check('profile listings and forms')) { if (CRM_Utils_System::isNull($params[$index])) { $params[$index] = $values[$index]; } if (!isset($params[$index])) { continue; } if (!$customFieldName) { $fieldName = $field['name']; } else { $fieldName = $customFieldName; } $url = NULL; if (CRM_Core_BAO_CustomField::getKeyID($field['name'])) { $htmlType = $field['html_type']; if ($htmlType == 'Link') { $url = $params[$index]; } elseif (in_array($htmlType, array('CheckBox', 'Multi-Select', 'AdvMulti-Select', 'Multi-Select State/Province', 'Multi-Select Country'))) { $valSeperator = CRM_Core_DAO::VALUE_SEPARATOR; $selectedOptions = explode($valSeperator, $params[$index]); foreach ($selectedOptions as $key => $multiOption) { if ($multiOption) { $url[] = CRM_Utils_System::url('civicrm/profile', 'reset=1&force=1&gid=' . $field['group_id'] . '&' . urlencode($fieldName) . '=' . urlencode($multiOption)); } } } else { $url = CRM_Utils_System::url('civicrm/profile', 'reset=1&force=1&gid=' . $field['group_id'] . '&' . urlencode($fieldName) . '=' . urlencode($params[$index])); } } else { $url = CRM_Utils_System::url('civicrm/profile', 'reset=1&force=1&gid=' . $field['group_id'] . '&' . urlencode($fieldName) . '=' . urlencode($params[$index])); } if ($url && !empty($values[$index]) && $searchable) { if (is_array($url) && !empty($url)) { $links = array(); $eachMultiValue = explode(', ', $values[$index]); foreach ($eachMultiValue as $key => $valueLabel) { $links[] = '<a href="' . $url[$key] . '">' . $valueLabel . '</a>'; } $values[$index] = implode(', ', $links); } else { $values[$index] = '<a href="' . $url . '">' . $values[$index] . '</a>'; } } } } }
/** * Build the entity-specific custom data into the group tree on a per-field basis * * @param object $dao * Object representing the custom field to be populated into the groupTree. * @param array $groupTree * (reference) the group tree being build. * @param string $table * Table name. * @param int $groupID * Custom group ID. * @param int $fieldID * Custom field ID. */ public static function buildCustomFieldData($dao, &$groupTree, $table, $groupID, $fieldID) { $column = $groupTree[$groupID]['fields'][$fieldID]['column_name']; $idName = "{$table}_id"; $fieldName = "{$table}_{$column}"; $dataType = $groupTree[$groupID]['fields'][$fieldID]['data_type']; if ($dataType == 'File') { if (isset($dao->{$fieldName})) { $config = CRM_Core_Config::singleton(); $fileDAO = new CRM_Core_DAO_File(); $fileDAO->id = $dao->{$fieldName}; if ($fileDAO->find(TRUE)) { $entityIDName = "{$table}_entity_id"; $customValue['id'] = $dao->{$idName}; $customValue['data'] = $fileDAO->uri; $customValue['fid'] = $fileDAO->id; $customValue['fileURL'] = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileDAO->id}&eid={$dao->{$entityIDName}}"); $customValue['displayURL'] = NULL; $deleteExtra = ts('Are you sure you want to delete attached file.'); $deleteURL = array(CRM_Core_Action::DELETE => array('name' => ts('Delete Attached File'), 'url' => 'civicrm/file', 'qs' => 'reset=1&id=%%id%%&eid=%%eid%%&fid=%%fid%%&action=delete', 'extra' => 'onclick = "if (confirm( \'' . $deleteExtra . '\' ) ) this.href+=\'&confirmed=1\'; else return false;"')); $customValue['deleteURL'] = CRM_Core_Action::formLink($deleteURL, CRM_Core_Action::DELETE, array('id' => $fileDAO->id, 'eid' => $dao->{$entityIDName}, 'fid' => $fieldID), ts('more'), FALSE, 'file.manage.delete', 'File', $fileDAO->id); $customValue['deleteURLArgs'] = CRM_Core_BAO_File::deleteURLArgs($table, $dao->{$entityIDName}, $fileDAO->id); $customValue['fileName'] = CRM_Utils_File::cleanFileName(basename($fileDAO->uri)); if ($fileDAO->mime_type == "image/jpeg" || $fileDAO->mime_type == "image/pjpeg" || $fileDAO->mime_type == "image/gif" || $fileDAO->mime_type == "image/x-png" || $fileDAO->mime_type == "image/png") { $customValue['displayURL'] = $customValue['fileURL']; $entityId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_EntityFile', $fileDAO->id, 'entity_id', 'file_id'); $customValue['imageURL'] = str_replace('persist/contribute', 'custom', $config->imageUploadURL) . $fileDAO->uri; list($path) = CRM_Core_BAO_File::path($fileDAO->id, $entityId, NULL, NULL); if ($path && file_exists($path)) { list($imageWidth, $imageHeight) = getimagesize($path); list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight); $customValue['imageThumbWidth'] = $imageThumbWidth; $customValue['imageThumbHeight'] = $imageThumbHeight; } } } } else { $customValue = array('id' => $dao->{$idName}, 'data' => ''); } } else { $customValue = array('id' => $dao->{$idName}, 'data' => $dao->{$fieldName}); } if (!array_key_exists('customValue', $groupTree[$groupID]['fields'][$fieldID])) { $groupTree[$groupID]['fields'][$fieldID]['customValue'] = array(); } if (empty($groupTree[$groupID]['fields'][$fieldID]['customValue'])) { $groupTree[$groupID]['fields'][$fieldID]['customValue'] = array(1 => $customValue); } else { $groupTree[$groupID]['fields'][$fieldID]['customValue'][] = $customValue; } }
/** * This function sets the default values for the form. Note that in edit/view mode * the default values are retrieved from the database * * @access public * * @return None */ function setDefaultValues() { $defaults = $this->_values; $params = array(); if ($this->_action & CRM_Core_Action::ADD) { if (array_key_exists('TagsAndGroups', $this->_editOptions)) { // set group and tag defaults if any if ($this->_gid) { $defaults['group'][$this->_gid] = 1; } if ($this->_tid) { $defaults['tag'][$this->_tid] = 1; } } if ($this->_contactSubType) { $defaults['contact_sub_type'] = $this->_contactSubType; } } else { $currentEmployer = CRM_Contact_BAO_Relationship::getCurrentEmployer(array($this->_contactId)); $defaults['current_employer_id'] = CRM_Utils_Array::value('org_id', $currentEmployer[$this->_contactId]); foreach ($defaults['email'] as $dontCare => &$val) { if (isset($val['signature_text'])) { $val['signature_text_hidden'] = $val['signature_text']; } if (isset($val['signature_html'])) { $val['signature_html_hidden'] = $val['signature_html']; } } if (CRM_Utils_Array::value('contact_sub_type', $defaults)) { $defaults['contact_sub_type'] = $this->_oldSubtypes; } } $this->assign('currentEmployer', CRM_Utils_Array::value('current_employer_id', $defaults)); // set defaults for blocks ( custom data, address, communication preference, notes, tags and groups ) foreach ($this->_editOptions as $name => $label) { if (!in_array($name, array('Address', 'Notes'))) { eval('CRM_Contact_Form_Edit_' . $name . '::setDefaultValues( $this, $defaults );'); } } //set address block defaults CRM_Contact_Form_Edit_Address::setDefaultValues($defaults, $this); if (CRM_Utils_Array::value('image_URL', $defaults)) { list($imageWidth, $imageHeight) = getimagesize($defaults['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', $defaults['image_URL']); } //set location type and country to default for each block $this->blockSetDefaults($defaults); $this->_preEditValues = $defaults; return $defaults; }
/** * @param int $contactID * @param int $cfID * @param int $fileID * @param bool $absolute * * @return array */ public static function getFileURL($contactID, $cfID, $fileID = NULL, $absolute = FALSE, $multiRecordWhereClause = NULL) { if ($contactID) { if (!$fileID) { $params = array('id' => $cfID); $defaults = array(); CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $params, $defaults); $columnName = $defaults['column_name']; //table name of custom data $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $defaults['custom_group_id'], 'table_name', 'id'); //query to fetch id from civicrm_file if ($multiRecordWhereClause) { $query = "SELECT {$columnName} FROM {$tableName} where entity_id = {$contactID} AND {$multiRecordWhereClause}"; } else { $query = "SELECT {$columnName} FROM {$tableName} where entity_id = {$contactID}"; } $fileID = CRM_Core_DAO::singleValueQuery($query); } $result = array(); if ($fileID) { $fileType = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_File', $fileID, 'mime_type', 'id'); $result['file_id'] = $fileID; if ($fileType == 'image/jpeg' || $fileType == 'image/pjpeg' || $fileType == 'image/gif' || $fileType == 'image/x-png' || $fileType == 'image/png') { $entityId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_EntityFile', $fileID, 'entity_id', 'id'); list($path) = CRM_Core_BAO_File::path($fileID, $entityId, NULL, NULL); list($imageWidth, $imageHeight) = getimagesize($path); list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight); $url = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileID}&eid={$contactID}", $absolute, NULL, TRUE, TRUE); $result['file_url'] = "\n <a href=\"{$url}\" class='crm-image-popup'>\n <img src=\"{$url}\" width={$imageThumbWidth} height={$imageThumbHeight}/>\n </a>"; // for non image files } else { $uri = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_File', $fileID, 'uri'); $url = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileID}&eid={$contactID}", $absolute, NULL, TRUE, TRUE); $result['file_url'] = "<a href=\"{$url}\">{$uri}</a>"; } } return $result; } }
/** * Get custom groups/fields for type of entity. * * An array containing all custom groups and their custom fields is returned. * * @param string $entityType - of the contact whose contact type is needed * @param int $entityId - optional - id of entity if we need to populate the tree with custom values. * @param int $groupId - optional group id (if we need it for a single group only) * - if groupId is 0 it gets for inline groups only * - if groupId is -1 we get for all groups * * @return array $groupTree - array consisting of all groups and fields and optionally populated with custom data values. * * @access public * * @static * */ public static function &getTree($entityType, &$form, $entityID = null, $groupID = null, $subType = null, $subName = null) { if ($entityID) { $entityID = CRM_Utils_Type::escape($entityID, 'Integer'); } require_once 'CRM/Core/Action.php'; // create a new tree $groupTree = array(); $strSelect = $strFrom = $strWhere = $orderBy = ''; $tableData = array(); // using tableData to build the queryString $tableData = array('civicrm_custom_field' => array('id', 'label', 'column_name', 'data_type', 'html_type', 'default_value', 'attributes', 'is_required', 'is_view', 'help_pre', 'help_post', 'options_per_line', 'start_date_years', 'end_date_years', 'date_format', 'time_format', 'option_group_id'), 'civicrm_custom_group' => array('id', 'name', 'table_name', 'title', 'help_pre', 'help_post', 'collapse_display', 'is_multiple', 'extends', 'extends_entity_column_id', 'extends_entity_column_value', 'max_multiple')); // create select $select = array(); foreach ($tableData as $tableName => $tableColumn) { foreach ($tableColumn as $columnName) { $alias = $tableName . "_" . $columnName; $select[] = "{$tableName}.{$columnName} as {$tableName}_{$columnName}"; } } $strSelect = "SELECT " . implode(', ', $select); // from, where, order by $strFrom = "\nFROM civicrm_custom_group\nLEFT JOIN civicrm_custom_field ON (civicrm_custom_field.custom_group_id = civicrm_custom_group.id)\n"; // if entity is either individual, organization or household pls get custom groups for 'contact' too. if ($entityType == "Individual" || $entityType == 'Organization' || $entityType == 'Household') { $in = "'{$entityType}', 'Contact'"; } else { if (strpos($entityType, "'") !== false) { // this allows the calling function to send in multiple entity types $in = $entityType; } else { // quote it $in = "'{$entityType}'"; } } if ($subType) { $subType = CRM_Core_DAO::VALUE_SEPARATOR . trim($subType, CRM_Core_DAO::VALUE_SEPARATOR) . CRM_Core_DAO::VALUE_SEPARATOR; $strWhere = "\nWHERE civicrm_custom_group.is_active = 1 \n AND civicrm_custom_field.is_active = 1 \n AND civicrm_custom_group.extends IN ({$in})\n AND ( civicrm_custom_group.extends_entity_column_value LIKE '%{$subType}%'\n OR civicrm_custom_group.extends_entity_column_value IS NULL )\n"; if ($subName) { $strWhere .= " AND civicrm_custom_group.extends_entity_column_id = {$subName} "; } } else { $strWhere = "\nWHERE civicrm_custom_group.is_active = 1 \n AND civicrm_custom_field.is_active = 1 \n AND civicrm_custom_group.extends IN ({$in})\n AND civicrm_custom_group.extends_entity_column_value IS NULL\n"; } $params = array(); if ($groupID > 0) { // since we want a specific group id we add it to the where clause $strWhere .= " AND civicrm_custom_group.id = %1"; $params[1] = array($groupID, 'Integer'); } else { if (!$groupID) { // since groupID is false we need to show all Inline groups $strWhere .= " AND civicrm_custom_group.style = 'Inline'"; } } require_once 'CRM/Core/Permission.php'; // ensure that the user has access to these custom groups $strWhere .= " AND " . CRM_Core_Permission::customGroupClause(CRM_Core_Permission::VIEW, 'civicrm_custom_group.'); $orderBy = "\nORDER BY civicrm_custom_group.weight,\n civicrm_custom_group.title,\n civicrm_custom_field.weight,\n civicrm_custom_field.label\n"; // final query string $queryString = "{$strSelect} {$strFrom} {$strWhere} {$orderBy}"; //crm_core_error::debug('$queryString', $queryString ); // dummy dao needed $crmDAO =& CRM_Core_DAO::executeQuery($queryString, $params); $customValueTables = array(); // process records while ($crmDAO->fetch()) { // get the id's $groupID = $crmDAO->civicrm_custom_group_id; $fieldId = $crmDAO->civicrm_custom_field_id; // create an array for groups if it does not exist if (!array_key_exists($groupID, $groupTree)) { $groupTree[$groupID] = array(); $groupTree[$groupID]['id'] = $groupID; // populate the group information foreach ($tableData['civicrm_custom_group'] as $fieldName) { $fullFieldName = "civicrm_custom_group_{$fieldName}"; if ($fieldName == 'id' || is_null($crmDAO->{$fullFieldName})) { continue; } if ($fieldName == 'extends_entity_column_value' && $subType) { // CRM-5507 $groupTree[$groupID]['subtype'] = trim($subType, CRM_Core_DAO::VALUE_SEPARATOR); } $groupTree[$groupID][$fieldName] = $crmDAO->{$fullFieldName}; } $groupTree[$groupID]['fields'] = array(); $customValueTables[$crmDAO->civicrm_custom_group_table_name] = array(); } // add the fields now (note - the query row will always contain a field) // we only reset this once, since multiple values come is as multiple rows if (!array_key_exists($fieldId, $groupTree[$groupID]['fields'])) { $groupTree[$groupID]['fields'][$fieldId] = array(); } $customValueTables[$crmDAO->civicrm_custom_group_table_name][$crmDAO->civicrm_custom_field_column_name] = 1; $groupTree[$groupID]['fields'][$fieldId]['id'] = $fieldId; // populate information for a custom field foreach ($tableData['civicrm_custom_field'] as $fieldName) { $fullFieldName = "civicrm_custom_field_{$fieldName}"; if ($fieldName == 'id' || is_null($crmDAO->{$fullFieldName})) { continue; } $groupTree[$groupID]['fields'][$fieldId][$fieldName] = $crmDAO->{$fullFieldName}; } } require_once 'CRM/Core/Action.php'; // now that we have all the groups and fields, lets get the values // since we need to know the table and field names // add info to groupTree if (!empty($customValueTables)) { $groupTree['info'] = array('tables' => $customValueTables); $select = $from = $where = array(); foreach ($groupTree['info']['tables'] as $table => $fields) { $from[] = $table; $select[] = "{$table}.id as {$table}_id"; $select[] = "{$table}.entity_id as {$table}_entity_id"; foreach ($fields as $column => $dontCare) { $select[] = "{$table}.{$column} as {$table}_{$column}"; } if ($entityID) { $where[] = "{$table}.entity_id = {$entityID}"; } } $groupTree['info']['select'] = $select; $groupTree['info']['from'] = $from; $groupTree['info']['where'] = null; if ($entityID) { $groupTree['info']['where'] = $where; $select = implode(', ', $select); // this is a hack to find a table that has some values for this // entityID to make the below LEFT JOIN work (CRM-2518) $firstTable = null; foreach ($from as $table) { $query = "\nSELECT id\nFROM {$table}\nWHERE entity_id = {$entityID}\n"; $recordExists = CRM_Core_DAO::singleValueQuery($query); if ($recordExists) { $firstTable = $table; break; } } if ($firstTable) { $fromSQL = $firstTable; foreach ($from as $table) { if ($table != $firstTable) { $fromSQL .= "\nLEFT JOIN {$table} USING (entity_id)"; } } $query = "\nSELECT {$select}\n FROM {$fromSQL}\n WHERE {$firstTable}.entity_id = {$entityID}\n"; $dao = CRM_Core_DAO::executeQuery($query); while ($dao->fetch()) { foreach ($groupTree as $groupID => $group) { if ($groupID === 'info') { continue; } $table = $groupTree[$groupID]['table_name']; foreach ($group['fields'] as $fieldID => $dontCare) { $column = $groupTree[$groupID]['fields'][$fieldID]['column_name']; $idName = "{$table}_id"; $fieldName = "{$table}_{$column}"; $dataType = $groupTree[$groupID]['fields'][$fieldID]['data_type']; if ($dataType == 'File') { if (isset($dao->{$fieldName})) { require_once 'CRM/Core/DAO/File.php'; $config = CRM_Core_Config::singleton(); $fileDAO = new CRM_Core_DAO_File(); $fileDAO->id = $dao->{$fieldName}; if ($fileDAO->find(true)) { $entityIDName = "{$table}_entity_id"; $customValue['id'] = $dao->{$idName}; $customValue['data'] = $fileDAO->uri; $customValue['fid'] = $fileDAO->id; $customValue['fileURL'] = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileDAO->id}&eid={$dao->{$entityIDName}}"); $customValue['displayURL'] = null; $deleteExtra = ts('Are you sure you want to delete attached file.'); $deleteURL = array(CRM_Core_Action::DELETE => array('name' => ts('Delete Attached File'), 'url' => 'civicrm/file', 'qs' => 'reset=1&id=%%id%%&eid=%%eid%%&fid=%%fid%%&action=delete', 'extra' => 'onclick = "if (confirm( \'' . $deleteExtra . '\' ) ) this.href+=\'&confirmed=1\'; else return false;"')); $customValue['deleteURL'] = CRM_Core_Action::formLink($deleteURL, CRM_Core_Action::DELETE, array('id' => $fileDAO->id, 'eid' => $dao->{$entityIDName}, 'fid' => $fieldID)); $customValue['fileName'] = CRM_Utils_File::cleanFileName(basename($fileDAO->uri)); if ($fileDAO->mime_type == "image/jpeg" || $fileDAO->mime_type == "image/pjpeg" || $fileDAO->mime_type == "image/gif" || $fileDAO->mime_type == "image/x-png" || $fileDAO->mime_type == "image/png") { $customValue['displayURL'] = $customValue['fileURL']; $entityId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_EntityFile', $fileDAO->id, 'entity_id', 'id'); require_once 'CRM/Core/BAO/File.php'; list($path) = CRM_Core_BAO_File::path($fileDAO->id, $entityId, null, null); list($imageWidth, $imageHeight) = getimagesize($path); require_once 'CRM/Contact/BAO/Contact.php'; list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight); $customValue['imageThumbWidth'] = $imageThumbWidth; $customValue['imageThumbHeight'] = $imageThumbHeight; } } } else { $customValue = array('id' => $dao->{$idName}, 'data' => ''); } } else { $customValue = array('id' => $dao->{$idName}, 'data' => $dao->{$fieldName}); } if (!array_key_exists('customValue', $groupTree[$groupID]['fields'][$fieldID])) { $groupTree[$groupID]['fields'][$fieldID]['customValue'] = array(); } if (empty($groupTree[$groupID]['fields'][$fieldID]['customValue'])) { $groupTree[$groupID]['fields'][$fieldID]['customValue'] = array(1 => $customValue); } else { $groupTree[$groupID]['fields'][$fieldID]['customValue'][] = $customValue; } } } } } } } return $groupTree; }
/** * This function sets the default values for the form. Note that in edit/view mode * the default values are retrieved from the database * * @access public * @return void */ function setDefaultsValues() { $this->_defaults = array(); if ($this->_id) { CRM_Core_BAO_UFGroup::setProfileDefaults($this->_id, $this->_fields, $this->_defaults, true); } //set custom field defaults require_once "CRM/Core/BAO/CustomField.php"; foreach ($this->_fields as $name => $field) { if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) { $htmlType = $field['html_type']; if (!isset($this->_defaults[$name]) || $htmlType == 'File') { CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $this->_id, $this->_mode); } if ($htmlType == 'File') { $url = CRM_Core_BAO_CustomField::getFileURL($this->_id, $customFieldID); if ($url) { $customFiles[$field['name']]['displayURL'] = "Attached File : {$url['file_url']}"; $deleteExtra = "Are you sure you want to delete attached file ?"; $fileId = $url['file_id']; $deleteURL = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$this->_id}&fid={$customFieldID}&action=delete"); $customFiles[$field['name']]['deleteURL'] = "<a href=\"{$deleteURL}\" onclick = \"if (confirm( ' {$deleteExtra} ' )) this.href+='&confirmed=1'; else return false;\">Delete Attached File</a>"; } } } } if (isset($customFiles)) { $this->assign('customFiles', $customFiles); } if (CRM_Utils_Array::value('image_URL', $this->_defaults)) { list($imageWidth, $imageHeight) = getimagesize($this->_defaults['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", $this->_defaults['image_URL']); } $this->setDefaults($this->_defaults); }
/** * 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); } } }
/** * Return formatted file URL, like for image file return image url with image icon * * @param string $path * Absoulte file path * @param string $fileType * @param string $url * File preview link e.g. https://example.com/civicrm/file?reset=1&filename=image.png&mime-type=image/png * * @return string $url */ public static function getFileURL($path, $fileType, $url = NULL) { if (empty($path) || empty($fileType)) { return ''; } elseif (empty($url)) { $fileName = basename($path); $url = CRM_Utils_System::url('civicrm/file', "reset=1&filename={$fileName}&mime-type={$fileType}"); } switch ($fileType) { case 'image/jpeg': case 'image/pjpeg': case 'image/gif': case 'image/x-png': case 'image/png': case 'image/jpg': list($imageWidth, $imageHeight) = getimagesize($path); list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight); $url = "<a href=\"{$url}\" class='crm-image-popup'>\n <img src=\"{$url}\" width={$imageThumbWidth} height={$imageThumbHeight}/>\n </a>"; break; default: $url = sprintf('<a href="%s">%s</a>', $url, basename($path)); break; } return $url; }
/** * This function sets the default values for the form. Note that in edit/view mode * the default values are retrieved from the database * * @access public * * @return void */ function setDefaultsValues() { $this->_defaults = array(); if ($this->_id) { if ($this->_isContactActivityProfile) { $contactFields = $activityFields = array(); foreach ($this->_fields as $fieldName => $field) { if (CRM_Utils_Array::value('field_type', $field) == 'Activity') { $activityFields[$fieldName] = $field; } else { $contactFields[$fieldName] = $field; } } CRM_Core_BAO_UFGroup::setProfileDefaults($this->_id, $contactFields, $this->_defaults, TRUE); if ($this->_activityId) { CRM_Core_BAO_UFGroup::setComponentDefaults($activityFields, $this->_activityId, 'Activity', $this->_defaults, TRUE); } } else { CRM_Core_BAO_UFGroup::setProfileDefaults($this->_id, $this->_fields, $this->_defaults, TRUE); } } //set custom field defaults foreach ($this->_fields as $name => $field) { if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) { $htmlType = $field['html_type']; if ((!isset($this->_defaults[$name]) || $htmlType == 'File') && CRM_Utils_Array::value('field_type', $field) != 'Activity') { CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $this->_id, $this->_mode); } if ($htmlType == 'File') { $entityId = $this->_id; if (CRM_Utils_Array::value('field_type', $field) == 'Activity' && $this->_activityId) { $entityId = $this->_activityId; } $url = CRM_Core_BAO_CustomField::getFileURL($entityId, $customFieldID); if ($url) { $customFiles[$field['name']]['displayURL'] = ts("Attached File") . ": {$url['file_url']}"; $deleteExtra = ts("Are you sure you want to delete attached file?"); $fileId = $url['file_id']; $deleteURL = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$entityId}&fid={$customFieldID}&action=delete"); $text = ts("Delete Attached File"); $customFiles[$field['name']]['deleteURL'] = "<a href=\"{$deleteURL}\" onclick = \"if (confirm( ' {$deleteExtra} ' )) this.href+='&confirmed=1'; else return false;\">{$text}</a>"; // also delete the required rule that we've set on the form element $this->removeFileRequiredRules($field['name']); } } } } if (isset($customFiles)) { $this->assign('customFiles', $customFiles); } if (CRM_Utils_Array::value('image_URL', $this->_defaults)) { list($imageWidth, $imageHeight) = getimagesize($this->_defaults['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", $this->_defaults['image_URL']); } if (array_key_exists('contact_sub_type', $this->_defaults) && !empty($this->_defaults['contact_sub_type'])) { $this->_defaults['contact_sub_type'] = explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($this->_defaults['contact_sub_type'], CRM_Core_DAO::VALUE_SEPARATOR)); } $this->setDefaults($this->_defaults); }
/** * 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 require_once 'CRM/Utils/Rule.php'; 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.')); } $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()))); if ($image_URL = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, '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 url 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 require_once 'CRM/Utils/Hook.php'; $hookLinks = CRM_Utils_Hook::links('view.contact.activity', 'Contact', $this->_contactId, 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); require_once 'CRM/Contact/BAO/Contact/Permission.php'; 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(); require_once 'CRM/Core/BAO/UFMatch.php'; if ($uid = CRM_Core_BAO_UFMatch::getUFId($this->_contactId)) { if ($config->userFramework == 'Drupal') { $userRecordUrl = CRM_Utils_System::url('user/' . $uid); } else { if ($config->userFramework == 'Joomla') { $userRecordUrl = $config->userFrameworkBaseURL . 'index2.php?option=com_users&view=user&task=edit&cid[]=' . $uid; } else { $userRecordUrl = null; } } $this->assign('userRecordUrl', $userRecordUrl); $this->assign('userRecordId', $uid); } 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); } } }
/** * Given a contact id and a field set, return the values from the db * for this contact * * @param int $id the contact id * @param array $fields the profile fields of interest * @param array $values the values for the above fields * @param boolean $searchable searchable or not * @param array $componentWhere component condition * * @return void * @access public * @static */ public static function getValues($cid, &$fields, &$values, $searchable = true, $componentWhere = null) { if (empty($cid)) { return null; } $options = $studentFields = array(); if (CRM_Core_Permission::access('Quest', false)) { //student fields ( check box ) require_once 'CRM/Quest/BAO/Student.php'; $studentFields = CRM_Quest_BAO_Student::$multipleSelectFields; } // get the contact details (hier) $returnProperties =& CRM_Contact_BAO_Contact::makeHierReturnProperties($fields); $params = array(array('contact_id', '=', $cid, 0, 0)); // add conditions specified by components. eg partcipant_id etc if (!empty($componentWhere)) { $params = array_merge($params, $componentWhere); } $query = new CRM_Contact_BAO_Query($params, $returnProperties, $fields); $options =& $query->_options; $details = $query->searchQuery(); if (!$details->fetch()) { return; } $config = CRM_Core_Config::singleton(); require_once 'CRM/Core/PseudoConstant.php'; $locationTypes = $imProviders = array(); $locationTypes = CRM_Core_PseudoConstant::locationType(); $imProviders = CRM_Core_PseudoConstant::IMProvider(); $websiteTypes = CRM_Core_PseudoConstant::websiteType(); $multipleFields = array('url'); $nullIndex = $nullValueIndex = ' '; //start of code to set the default values foreach ($fields as $name => $field) { // fix for CRM-3962 if ($name == 'id') { $name = 'contact_id'; } $index = $field['title']; //handle for the label not set for the field if (empty($field['title'])) { $index = $nullIndex; $nullIndex .= $nullIndex; } //handle the case to avoid re-write where the profile field labels are the same if (CRM_Utils_Array::value($index, $values)) { $index .= $nullValueIndex; $nullValueIndex .= $nullValueIndex; } $params[$index] = $values[$index] = ''; $customFieldName = null; $elements = array('email_greeting_custom' => 'email_greeting', 'postal_greeting_custom' => 'postal_greeting', 'addressee_custom' => 'addressee'); if (isset($details->{$name}) || $name == 'group' || $name == 'tag') { //hack for CRM-665 // to handle gender / suffix / prefix if (in_array($name, array('gender', 'individual_prefix', 'individual_suffix'))) { $values[$index] = $details->{$name}; $name = $name . '_id'; $params[$index] = $details->{$name}; } else { if (in_array($name, array('email_greeting', 'postal_greeting', 'addressee'))) { $dname = $name . '_display'; $values[$index] = $details->{$dname}; $name = $name . '_id'; $params[$index] = $details->{$name}; } else { if (in_array($name, array('state_province', 'country', 'county'))) { $values[$index] = $details->{$name}; $idx = $name . '_id'; $params[$index] = $details->{$idx}; } else { if ($name === 'preferred_communication_method') { $communicationFields = CRM_Core_PseudoConstant::pcm(); $pref = $compref = array(); $pref = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $details->{$name}); foreach ($pref as $k) { if ($k) { $compref[] = $communicationFields[$k]; } } $params[$index] = $details->{$name}; $values[$index] = implode(",", $compref); } else { if ($name === 'preferred_language') { $languages = CRM_Core_PseudoConstant::languages(); $params[$index] = $details->{$name}; $values[$index] = $languages[$details->{$name}]; } else { if ($name == 'group') { $groups = CRM_Contact_BAO_GroupContact::getContactGroup($cid, 'Added', null, false, true); $title = $ids = array(); foreach ($groups as $g) { if ($g['visibility'] != 'User and User Admin Only') { $title[] = $g['title']; if ($g['visibility'] == 'Public Pages') { $ids[] = $g['group_id']; } } } $values[$index] = implode(', ', $title); $params[$index] = implode(',', $ids); } else { if ($name == 'tag') { require_once 'CRM/Core/BAO/EntityTag.php'; $entityTags =& CRM_Core_BAO_EntityTag::getTag($cid); $allTags =& CRM_Core_PseudoConstant::tag(); $title = array(); foreach ($entityTags as $tagId) { $title[] = $allTags[$tagId]; } $values[$index] = implode(', ', $title); $params[$index] = implode(',', $entityTags); } else { if (array_key_exists($name, $studentFields)) { require_once 'CRM/Core/OptionGroup.php'; $paramsNew = array($name => $details->{$name}); if ($name == 'test_tutoring') { $names = array($name => array('newName' => $index, 'groupName' => 'test')); } else { if (substr($name, 0, 4) == 'cmr_') { //for readers group $names = array($name => array('newName' => $index, 'groupName' => substr($name, 0, -3))); } else { $names = array($name => array('newName' => $index, 'groupName' => $name)); } } CRM_Core_OptionGroup::lookupValues($paramsNew, $names, false); $values[$index] = $paramsNew[$index]; $params[$index] = $paramsNew[$name]; } else { $processed = false; if (CRM_Core_Permission::access('Quest', false)) { require_once 'CRM/Quest/BAO/Student.php'; $processed = CRM_Quest_BAO_Student::buildStudentForm($this, $field); } if (!$processed) { if (substr($name, 0, 7) === 'do_not_' or substr($name, 0, 3) === 'is_') { if ($details->{$name}) { $values[$index] = '[ x ]'; } } else { require_once 'CRM/Core/BAO/CustomField.php'; if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) { $htmlType = $field['html_type']; $dataType = $field['data_type']; if ($htmlType == 'File') { $fileURL = CRM_Core_BAO_CustomField::getFileURL($cid, $cfID); $params[$index] = $values[$index] = $fileURL['file_url']; } else { $customVal = null; if (isset($dao) && ($dao->data_type == 'Int' || $dao->data_type == 'Boolean')) { $customVal = (int) $details->{$name}; } else { if (isset($dao) && $dao->data_type == 'Float') { $customVal = (double) $details->{$name}; } else { if (!CRM_Utils_System::isNull(explode(CRM_Core_DAO::VALUE_SEPARATOR, $details->{$name}))) { $customVal = $details->{$name}; } } } //CRM-4582 if (CRM_Utils_System::isNull($customVal)) { continue; } $params[$index] = $customVal; $values[$index] = CRM_Core_BAO_CustomField::getDisplayValue($customVal, $cfID, $options); if ($htmlType == 'Autocomplete-Select') { $params[$index] = $values[$index]; } if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $cfID, 'is_search_range')) { $customFieldName = "{$name}_from"; } } } else { if ($name == 'image_URL') { list($width, $height) = getimagesize($details->{$name}); list($thumbWidth, $thumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($width, $height); $image_URL = '<img src="' . $details->{$name} . '" height= ' . $thumbHeight . ' width= ' . $thumbWidth . ' />'; $values[$index] = "<a href='#' onclick='contactImagePopUp(\"{$details->{$name}}\", {$width}, {$height});'>{$image_URL}</a>"; } else { if (in_array($name, array('birth_date', 'deceased_date', 'membership_start_date', 'membership_end_date', 'join_date'))) { require_once 'CRM/Utils/Date.php'; $values[$index] = CRM_Utils_Date::customFormat($details->{$name}); $params[$index] = CRM_Utils_Date::isoToMysql($details->{$name}); } else { $values[$index] = $details->{$name}; } } } } } } } } } } } } } } else { if (strpos($name, '-') !== false) { list($fieldName, $id, $type) = CRM_Utils_System::explode('-', $name, 3); if (!in_array($fieldName, $multipleFields)) { if ($id == 'Primary') { // fix for CRM-1543 // not sure why we'd every use Primary location type id // we need to fix the source if we are using it // $locationTypeName = CRM_Contact_BAO_Contact::getPrimaryLocationType( $cid ); $locationTypeName = 1; } else { $locationTypeName = CRM_Utils_Array::value($id, $locationTypes); } if (!$locationTypeName) { continue; } $detailName = "{$locationTypeName}-{$fieldName}"; $detailName = str_replace(' ', '_', $detailName); if (in_array($fieldName, array('phone', 'im', 'email', 'openid'))) { if ($type) { $detailName .= "-{$type}"; } } if (in_array($fieldName, array('state_province', 'country', 'county'))) { $values[$index] = $details->{$detailName}; $idx = $detailName . '_id'; $params[$index] = $details->{$idx}; } else { if ($fieldName == 'im') { $providerId = $detailName . '-provider_id'; $providerName = $imProviders[$details->{$providerId}]; if ($providerName) { $values[$index] = $details->{$detailName} . " (" . $providerName . ")"; } else { $values[$index] = $details->{$detailName}; } $params[$index] = $details->{$detailName}; } else { $values[$index] = $params[$index] = $details->{$detailName}; } } } else { $detailName = "website-{$id}-{$fieldName}"; $url = CRM_Utils_System::fixURL($details->{$detailName}); $websiteTypeId = "website-{$id}-website_type_id"; $websiteType = $websiteTypes[$details->{$websiteTypeId}]; if ($details->{$detailName}) { $values[$index] = "<a href=\"{$url}\">{$details->{$detailName}} ( {$websiteType} )</a>"; } else { $values[$index] = ''; } } } } if ($field['visibility'] == "Public Pages and Listings" && CRM_Core_Permission::check('profile listings and forms')) { if (CRM_Utils_System::isNull($params[$index])) { $params[$index] = $values[$index]; } if (!isset($params[$index])) { continue; } $customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name']); if (!$customFieldName) { $fieldName = $field['name']; } else { $fieldName = $customFieldName; } $url = null; if (CRM_Core_BAO_CustomField::getKeyID($field['name'])) { $htmlType = $field['html_type']; if ($htmlType == 'Link') { $url = $params[$index]; } else { if (in_array($htmlType, array('CheckBox', 'Multi-Select', 'AdvMulti-Select', 'Multi-Select State/Province', 'Multi-Select Country'))) { $valSeperator = CRM_Core_BAO_CustomOption::VALUE_SEPERATOR; $selectedOptions = explode($valSeperator, $params[$index]); foreach ($selectedOptions as $key => $multiOption) { if ($multiOption) { $url[] = CRM_Utils_System::url('civicrm/profile', 'reset=1&force=1&gid=' . $field['group_id'] . '&' . urlencode($fieldName) . '=' . urlencode($multiOption)); } } } else { $url = CRM_Utils_System::url('civicrm/profile', 'reset=1&force=1&gid=' . $field['group_id'] . '&' . urlencode($fieldName) . '=' . urlencode($params[$index])); } } } else { $url = CRM_Utils_System::url('civicrm/profile', 'reset=1&force=1&gid=' . $field['group_id'] . '&' . urlencode($fieldName) . '=' . urlencode($params[$index])); } if ($url && !empty($values[$index]) && $searchable) { if (is_array($url) && !empty($url)) { $links = array(); $eachMultiValue = explode(', ', $values[$index]); foreach ($eachMultiValue as $key => $valueLabel) { $links[] = '<a href="' . $url[$key] . '">' . $valueLabel . '</a>'; } $values[$index] = implode(', ', $links); } else { $values[$index] = '<a href="' . $url . '">' . $values[$index] . '</a>'; } } } } }
/** * 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); } } }
static function getFileURL($contactID, $cfID, $fileID = NULL) { if ($contactID) { if (!$fileID) { $params = array('id' => $cfID); $defaults = array(); CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $params, $defaults); $columnName = $defaults['column_name']; //table name of custom data $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $defaults['custom_group_id'], 'table_name', 'id'); //query to fetch id from civicrm_file $query = "SELECT {$columnName} FROM {$tableName} where entity_id = {$contactID}"; $fileID = CRM_Core_DAO::singleValueQuery($query); } $result = array(); if ($fileID) { $fileType = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_File', $fileID, 'mime_type', 'id'); $result['file_id'] = $fileID; if ($fileType == "image/jpeg" || $fileType == "image/pjpeg" || $fileType == "image/gif" || $fileType == "image/x-png" || $fileType == "image/png") { $entityId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_EntityFile', $fileID, 'entity_id', 'id'); require_once 'CRM/Core/BAO/File.php'; list($path) = CRM_Core_BAO_File::path($fileID, $entityId, null, null); list($imageWidth, $imageHeight) = getimagesize($path); list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight); $url = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileID}&eid={$contactID}"); $result['file_url'] = "<a href='javascript:imagePopUp(\"{$url}\");'><img src=\"{$url}\" width={$imageThumbWidth} height={$imageThumbHeight}/></a>"; } else { // for non image files $uri = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_File', $fileID, 'uri'); $url = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileID}&eid={$contactID}"); $result['file_url'] = "<a href=\"{$url}\">{$uri}</a>"; } } return $result; } }
/** * Set default values for the form. * * Note that in edit/view mode the default values are retrieved from the database */ public function setDefaultValues() { $defaults = $this->_values; if ($this->_action & CRM_Core_Action::ADD) { if (array_key_exists('TagsAndGroups', $this->_editOptions)) { // set group and tag defaults if any if ($this->_gid) { $defaults['group'][] = $this->_gid; } if ($this->_tid) { $defaults['tag'][$this->_tid] = 1; } } if ($this->_contactSubType) { $defaults['contact_sub_type'] = $this->_contactSubType; } } else { foreach ($defaults['email'] as $dontCare => &$val) { if (isset($val['signature_text'])) { $val['signature_text_hidden'] = $val['signature_text']; } if (isset($val['signature_html'])) { $val['signature_html_hidden'] = $val['signature_html']; } } if (!empty($defaults['contact_sub_type'])) { $defaults['contact_sub_type'] = $this->_oldSubtypes; } } // set defaults for blocks ( custom data, address, communication preference, notes, tags and groups ) foreach ($this->_editOptions as $name => $label) { if (!in_array($name, array('Address', 'Notes'))) { $className = 'CRM_Contact_Form_Edit_' . $name; $className::setDefaultValues($this, $defaults); } } //set address block defaults CRM_Contact_Form_Edit_Address::setDefaultValues($defaults, $this); if (!empty($defaults['image_URL'])) { list($imageWidth, $imageHeight) = getimagesize(CRM_Utils_String::unstupifyUrl($defaults['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', $defaults['image_URL']); } //set location type and country to default for each block $this->blockSetDefaults($defaults); $this->_preEditValues = $defaults; return $defaults; }
/** * This function sets the default values for the form. Note that in edit/view mode * the default values are retrieved from the database * * @access public * @return None */ function setDefaultValues() { $defaults = $this->_values; $params = array(); if ($this->_action & CRM_Core_Action::ADD) { if (array_key_exists('TagsAndGroups', $this->_editOptions)) { // set group and tag defaults if any if ($this->_gid) { $defaults['group'][$this->_gid] = 1; } if ($this->_tid) { $defaults['tag'][$this->_tid] = 1; } } if ($this->_contactSubType) { $defaults['contact_sub_type'] = $this->_contactSubType; } } else { require_once 'CRM/Contact/BAO/Relationship.php'; $currentEmployer = CRM_Contact_BAO_Relationship::getCurrentEmployer(array($this->_contactId)); $defaults['current_employer_id'] = CRM_Utils_Array::value('org_id', $currentEmployer[$this->_contactId]); $this->assign('currentEmployer', $defaults['current_employer_id']); foreach ($defaults['email'] as $dontCare => &$val) { if (isset($val['signature_text'])) { $val['signature_text_hidden'] = $val['signature_text']; } if (isset($val['signature_html'])) { $val['signature_html_hidden'] = $val['signature_html']; } } } // set defaults for blocks ( custom data, address, communication preference, notes, tags and groups ) foreach ($this->_editOptions as $name => $label) { if (!in_array($name, array('Address', 'Notes'))) { require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Contact_Form_Edit_" . $name) . ".php"; eval('CRM_Contact_Form_Edit_' . $name . '::setDefaultValues( $this, $defaults );'); } } $addressValues = array(); if (isset($defaults['address']) && is_array($defaults['address']) && !CRM_Utils_system::isNull($defaults['address'])) { // start of contact shared adddress defaults $sharedAddresses = array(); $masterAddress = array(); // get contact name of shared contact names $shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($defaults['address']); foreach ($defaults['address'] as $key => $addressValue) { if (CRM_Utils_Array::value('master_id', $addressValue) && !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']) { $sharedAddresses[$key]['shared_address_display'] = array('address' => $addressValue['display'], 'name' => $shareAddressContactNames[$addressValue['master_id']]['name']); } else { $defaults['address'][$key]['use_shared_address'] = 0; } //check if any address is shared by any other contacts $masterAddress[$key] = CRM_Core_BAO_Address::checkContactSharedAddress($addressValue['id']); } $this->assign('sharedAddresses', $sharedAddresses); $this->assign('masterAddress', $masterAddress); // end of shared address defaults // start of parse address functionality // build street address, CRM-5450. if ($this->_parseStreetAddress) { $parseFields = array('street_address', 'street_number', 'street_name', 'street_unit'); foreach ($defaults['address'] as $cnt => &$address) { $streetAddress = null; foreach (array('street_number', 'street_number_suffix', 'street_name', 'street_unit') as $fld) { if (in_array($fld, array('street_name', 'street_unit'))) { $streetAddress .= ' '; } $streetAddress .= CRM_Utils_Array::value($fld, $address); } $streetAddress = trim($streetAddress); if (!empty($streetAddress)) { $address['street_address'] = $streetAddress; } $address['street_number'] .= CRM_Utils_Array::value('street_number_suffix', $address); // build array for set default. foreach ($parseFields as $field) { $addressValues["{$field}_{$cnt}"] = CRM_Utils_Array::value($field, $address); } // don't load fields, use js to populate. foreach (array('street_number', 'street_name', 'street_unit') as $f) { if (isset($address[$f])) { unset($address[$f]); } } } $this->assign('allAddressFieldValues', json_encode($addressValues)); //hack to handle show/hide address fields. $parsedAddress = array(); if ($this->_contactId && CRM_Utils_Array::value('address', $_POST) && is_array($_POST['address'])) { foreach ($_POST['address'] as $cnt => $values) { $showField = 'streetAddress'; foreach (array('street_number', 'street_name', 'street_unit') as $fld) { if (CRM_Utils_Array::value($fld, $values)) { $showField = 'addressElements'; break; } } $parsedAddress[$cnt] = $showField; } } $this->assign('showHideAddressFields', $parsedAddress); $this->assign('loadShowHideAddressFields', empty($parsedAddress) ? false : true); } // end of parse address functionality } if (CRM_Utils_Array::value('image_URL', $defaults)) { list($imageWidth, $imageHeight) = getimagesize($defaults['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", $defaults['image_URL']); } //set location type and country to default for each block $this->blockSetDefaults($defaults); return $defaults; }