/** * 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'])) { $this->assign("imageURL", CRM_Utils_File::getImageURL($defaults['image_URL'])); } //set location type and country to default for each block $this->blockSetDefaults($defaults); $this->_preEditValues = $defaults; return $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. */ 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')) { $this->assign("imageURL", CRM_Utils_File::getImageURL($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); } } }
/** * 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'])) { $this->assign("imageURL", CRM_Utils_File::getImageURL($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); }