/**
 * Implementation of hook_civicrm_check().
 *
 * Add a check to the status page/System.check results if $snafu is TRUE.
 */
function zombiefinder_civicrm_check(&$messages)
{
    // The API should be able to provide this (as below), but there are problems
    // in both 4.6 and 4.7 with finding privacy preferences (Do not mail, etc.)
    // that are null using the API.
    //
    // try {
    //   $result = civicrm_api3('Contact', 'getcount', array(
    //     'is_deceased' => array('IS NULL' => 1),
    //   ));
    // }
    // catch (CiviCRM_API3_Exception $e) {
    //   CRM_Core_Error::debug_log_message($e->getMessage());
    // }
    // Check for zombies.
    $fieldsToCheck = CRM_Core_SelectValues::privacy();
    $fieldsToCheck['is_deceased'] = ts('Is Deceased');
    $fieldsToCheck['is_deleted'] = ts('Deleted');
    $found = array();
    foreach ($fieldsToCheck as $fieldName => $displayName) {
        $sql = "SELECT COUNT(id) FROM civicrm_contact WHERE {$fieldName} IS NULL";
        if (CRM_Core_DAO::singleValueQuery($sql)) {
            $found[] = $displayName;
        }
    }
    if (count($found)) {
        $tsParams = array(1 => implode(', ', $found), 2 => 'http://civicrm.stackexchange.com/a/7396/44', 'domain' => 'com.aghstrategies.zombiefinder');
        $details = ts('Zombies found.  You have contacts who are undead or have null privacy options.  One or more contacts have null values in the following fields: %1.  <a href="%2">Read more about how to solve this.</a>', $tsParams);
        $messages[] = new CRM_Utils_Check_Message('zombiefinder_found', $details, ts('Gaaargh! Braaaains!', array('domain' => 'com.aghstrategies.zombiefinder')), \Psr\Log\LogLevel::WARNING, 'fa-user-times');
    }
}
 /**
  * Build the form object elements for Communication Preferences object.
  *
  * @param CRM_Core_Form $form
  *   Reference to the form object.
  *
  * @return void
  */
 public static function buildQuickForm(&$form)
 {
     // since the pcm - preferred comminication method is logically
     // grouped hence we'll use groups of HTML_QuickForm
     // checkboxes for DO NOT phone, email, mail
     // we take labels from SelectValues
     $privacy = $commPreff = $commPreference = array();
     $privacyOptions = CRM_Core_SelectValues::privacy();
     // we add is_opt_out as a separate checkbox below for display and help purposes so remove it here
     unset($privacyOptions['is_opt_out']);
     foreach ($privacyOptions as $name => $label) {
         $privacy[] = $form->createElement('advcheckbox', $name, NULL, $label);
     }
     $form->addGroup($privacy, 'privacy', ts('Privacy'), '&nbsp;');
     // preferred communication method
     $comm = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method', array('loclize' => TRUE));
     foreach ($comm as $value => $title) {
         $commPreff[] = $form->createElement('advcheckbox', $value, NULL, $title);
     }
     $form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Method(s)'));
     $form->addSelect('preferred_language');
     if (!empty($privacyOptions)) {
         $commPreference['privacy'] = $privacyOptions;
     }
     if (!empty($comm)) {
         $commPreference['preferred_communication_method'] = $comm;
     }
     //using for display purpose.
     $form->assign('commPreference', $commPreference);
     $form->add('select', 'preferred_mail_format', ts('Email Format'), CRM_Core_SelectValues::pmf());
     $form->add('checkbox', 'is_opt_out', ts('NO BULK EMAILS (User Opt Out)'));
     $communicationStyleOptions = array();
     $communicationStyle = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'communication_style_id', array('localize' => TRUE));
     foreach ($communicationStyle as $key => $var) {
         $communicationStyleOptions[$key] = $form->createElement('radio', NULL, ts('Communication Style'), $var, $key, array('id' => "civicrm_communication_style_{$var}_{$key}"));
     }
     if (!empty($communicationStyleOptions)) {
         $form->addGroup($communicationStyleOptions, 'communication_style_id', ts('Communication Style'));
     }
     //check contact type and build filter clause accordingly for greeting types, CRM-4575
     $greetings = self::getGreetingFields($form->_contactType);
     foreach ($greetings as $greeting => $fields) {
         $filter = array('contact_type' => $form->_contactType, 'greeting_type' => $greeting);
         //add addressee in Contact form
         $greetingTokens = CRM_Core_PseudoConstant::greeting($filter);
         if (!empty($greetingTokens)) {
             $form->addElement('select', $fields['field'], $fields['label'], array('' => ts('- select -')) + $greetingTokens);
             //custom addressee
             $form->addElement('text', $fields['customField'], $fields['customLabel'], CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', $fields['customField']), $fields['js']);
         }
     }
 }
 /**
  * Run the page.
  *
  * This method is called after the page is created.
  *
  * @return void
  * @access public
  *
  */
 function run()
 {
     // get the emails for this contact
     $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
     $params = array('id' => $contactId);
     $defaults = array();
     CRM_Contact_BAO_Contact::getValues($params, $defaults);
     $defaults['privacy_values'] = CRM_Core_SelectValues::privacy();
     $this->assign('contactId', $contactId);
     $this->assign($defaults);
     // check logged in user permission
     CRM_Contact_Page_View::checkUserPermission($this, $contactId);
     // finally call parent
     parent::run();
 }
 /**
  * build the form elements for Communication Preferences object
  *
  * @param CRM_Core_Form $form       reference to the form object
  *
  * @return void
  * @access public
  * @static
  */
 static function buildQuickForm(&$form)
 {
     // since the pcm - preferred comminication method is logically
     // grouped hence we'll use groups of HTML_QuickForm
     // checkboxes for DO NOT phone, email, mail
     // we take labels from SelectValues
     $privacy = $commPreff = $commPreference = array();
     $privacyOptions = CRM_Core_SelectValues::privacy();
     foreach ($privacyOptions as $name => $label) {
         $privacy[] = HTML_QuickForm::createElement('advcheckbox', $name, null, $label);
     }
     $form->addGroup($privacy, 'privacy', ts('Privacy'), '&nbsp;');
     // preferred communication method
     require_once 'CRM/Core/PseudoConstant.php';
     $comm = CRM_Core_PseudoConstant::pcm();
     foreach ($comm as $value => $title) {
         $commPreff[] = HTML_QuickForm::createElement('advcheckbox', $value, null, $title);
     }
     $form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Method(s)'));
     $form->add('select', 'preferred_language', ts('Preferred Language'), array('' => ts('- select -')) + CRM_Core_PseudoConstant::languages());
     if (!empty($privacyOptions)) {
         $commPreference['privacy'] = $privacyOptions;
     }
     if (!empty($comm)) {
         $commPreference['preferred_communication_method'] = $comm;
     }
     //using for display purpose.
     $form->assign('commPreference', $commPreference);
     $form->add('select', 'preferred_mail_format', ts('Email Format'), CRM_Core_SelectValues::pmf());
     $form->add('checkbox', 'is_opt_out', ts('NO BULK EMAILS (User Opt Out)'));
     //check contact type and build filter clause accordingly for greeting types, CRM-4575
     $greetings = self::getGreetingFields($form->_contactType);
     foreach ($greetings as $greeting => $fields) {
         $filter = array('contact_type' => $form->_contactType, 'greeting_type' => $greeting);
         //add addressee in Contact form
         $greetingTokens = CRM_Core_PseudoConstant::greeting($filter);
         if (!empty($greetingTokens)) {
             $form->addElement('select', $fields['field'], $fields['label'], array('' => ts('- select -')) + $greetingTokens);
             //custom addressee
             $form->addElement('text', $fields['customField'], $fields['customLabel'], CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', $fields['customField']), $fields['js']);
         }
     }
 }
 /**
  * Run the page.
  *
  * This method is called after the page is created.
  *
  * @return void
  */
 public function run()
 {
     // get the emails for this contact
     $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
     $params = array('id' => $contactId);
     $defaults = array();
     CRM_Contact_BAO_Contact::getValues($params, $defaults);
     $defaults['privacy_values'] = CRM_Core_SelectValues::privacy();
     $communicationStyle = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'communication_style_id');
     if (!empty($communicationStyle)) {
         if (!empty($defaults['communication_style_id'])) {
             $defaults['communication_style_display'] = $communicationStyle[CRM_Utils_Array::value('communication_style_id', $defaults)];
         } else {
             // Make sure the field is displayed as long as it is active, even if it is unset for this contact.
             $defaults['communication_style_display'] = '';
         }
     }
     $this->assign('contactId', $contactId);
     $this->assign($defaults);
     // check logged in user permission
     CRM_Contact_Page_View::checkUserPermission($this, $contactId);
     // finally call parent
     parent::run();
 }
 static function basic(&$form)
 {
     $form->addElement('hidden', 'hidden_basic', 1);
     if ($form->_searchOptions['contactType']) {
         // add checkboxes for contact type
         $contact_type = array();
         $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements();
         if ($contactTypes) {
             $form->add('select', 'contact_type', ts('Contact Type(s)'), $contactTypes, FALSE, array('id' => 'contact_type', 'multiple' => 'multiple', 'title' => ts('- select -')));
         }
     }
     if ($form->_searchOptions['groups']) {
         // multiselect for groups
         if ($form->_group) {
             $form->add('select', 'group', ts('Groups'), $form->_group, FALSE, array('id' => 'group', 'multiple' => 'multiple', 'title' => ts('- select -')));
         }
     }
     if ($form->_searchOptions['tags']) {
         // multiselect for categories
         $contactTags = CRM_Core_BAO_Tag::getTags();
         if ($contactTags) {
             $form->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE, array('id' => 'contact_tags', 'multiple' => 'multiple', 'title' => ts('- select -')));
         }
         $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact');
         CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', NULL, TRUE, FALSE, TRUE);
     }
     // add text box for last name, first name, street name, city
     $form->addElement('text', 'sort_name', ts('Find...'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
     // add text box for last name, first name, street name, city
     $form->add('text', 'email', ts('Contact Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
     //added contact source
     $form->add('text', 'contact_source', ts('Contact Source'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'source'));
     //added job title
     $attributes['job_title']['size'] = 30;
     $form->addElement('text', 'job_title', ts('Job Title'), $attributes['job_title'], 'size="30"');
     //added internal ID
     $attributes['id']['size'] = 30;
     $form->addElement('text', 'id', ts('Contact ID'), $attributes['id'], 'size="30"');
     //added external ID
     $attributes['external_identifier']['size'] = 30;
     $form->addElement('text', 'external_identifier', ts('External ID'), $attributes['external_identifier'], 'size="30"');
     $config = CRM_Core_Config::singleton();
     if (CRM_Core_Permission::check('access deleted contacts') and $config->contactUndelete) {
         $form->add('checkbox', 'deleted_contacts', ts('Search in Trash') . '<br />' . ts('(deleted contacts)'));
     }
     // add checkbox for cms users only
     $form->addYesNo('uf_user', ts('CMS User?'));
     // tag all search
     $form->add('text', 'tag_search', ts('All Tags'));
     // add search profiles
     // FIXME: This is probably a part of profiles - need to be
     // FIXME: eradicated from here when profiles are reworked.
     $types = array('Participant', 'Contribution', 'Membership');
     // get component profiles
     $componentProfiles = array();
     $componentProfiles = CRM_Core_BAO_UFGroup::getProfiles($types);
     $ufGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup('Search Profile', 1);
     $accessibleUfGroups = CRM_Core_Permission::ufGroup(CRM_Core_Permission::VIEW);
     $searchProfiles = array();
     foreach ($ufGroups as $key => $var) {
         if (!array_key_exists($key, $componentProfiles) && in_array($key, $accessibleUfGroups)) {
             $searchProfiles[$key] = $var['title'];
         }
     }
     $form->addElement('select', 'uf_group_id', ts('Search Views'), array('0' => ts('- default view -')) + $searchProfiles);
     $componentModes = CRM_Contact_Form_Search::getModeSelect();
     // unset contributions or participants if user does not have
     // permission on them
     if (!CRM_Core_Permission::access('CiviContribute')) {
         unset($componentModes['2']);
     }
     if (!CRM_Core_Permission::access('CiviEvent')) {
         unset($componentModes['3']);
     }
     if (!CRM_Core_Permission::access('CiviMember')) {
         unset($componentModes['5']);
     }
     if (!CRM_Core_Permission::check('view all activities')) {
         unset($componentModes['4']);
     }
     if (count($componentModes) > 1) {
         $form->addElement('select', 'component_mode', ts('Display Results As'), $componentModes);
     }
     $form->addElement('select', 'operator', ts('Search Operator'), array('AND' => ts('AND'), 'OR' => ts('OR')));
     // add the option to display relationships
     $rTypes = CRM_Core_PseudoConstant::relationshipType();
     $rSelect = array('' => ts('- Select Relationship Type-'));
     foreach ($rTypes as $rid => $rValue) {
         if ($rValue['label_a_b'] == $rValue['label_b_a']) {
             $rSelect[$rid] = $rValue['label_a_b'];
         } else {
             $rSelect["{$rid}_a_b"] = $rValue['label_a_b'];
             $rSelect["{$rid}_b_a"] = $rValue['label_b_a'];
         }
     }
     $form->addElement('select', 'display_relationship_type', ts('Display Results as Relationship'), $rSelect);
     // checkboxes for DO NOT phone, email, mail
     // we take labels from SelectValues
     $t = CRM_Core_SelectValues::privacy();
     $form->add('select', 'privacy_options', ts('Privacy'), $t, FALSE, array('id' => 'privacy_options', 'multiple' => 'multiple', 'title' => ts('- select -')));
     $form->addElement('select', 'privacy_operator', ts('Operator'), array('OR' => ts('OR'), 'AND' => ts('AND')));
     $toggleChoice = array();
     $toggleChoice[] = $form->createElement('radio', NULL, '', ' ' . ts('Exclude'), '1');
     $toggleChoice[] = $form->createElement('radio', NULL, '', ' ' . ts('Include by Privacy Option(s)'), '2');
     $form->addGroup($toggleChoice, 'privacy_toggle', 'Privacy Options');
     // preferred communication method
     $comm = CRM_Core_PseudoConstant::pcm();
     $commPreff = array();
     foreach ($comm as $k => $v) {
         $commPreff[] = $form->createElement('advcheckbox', $k, NULL, $v);
     }
     $onHold[] = $form->createElement('advcheckbox', 'on_hold', NULL, ts(''));
     $form->addGroup($onHold, 'email_on_hold', ts('Email On Hold'));
     $form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Communication Method'));
     //CRM-6138 Preferred Language
     $langPreff = CRM_Core_PseudoConstant::languages();
     $form->add('select', 'preferred_language', ts('Preferred Language'), array('' => ts('- select language -')) + $langPreff);
 }
 /**
  * View summary details of a contact
  *
  * @return void
  * @access public
  */
 function view()
 {
     $session = CRM_Core_Session::singleton();
     $url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId);
     $session->pushUserContext($url);
     $params = array();
     $defaults = array();
     $ids = array();
     $params['id'] = $params['contact_id'] = $this->_contactId;
     $params['noRelationships'] = $params['noNotes'] = $params['noGroups'] = true;
     $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, true);
     $communicationType = array('phone' => array('type' => 'phoneType', 'id' => 'phone_type'), 'im' => array('type' => 'IMProvider', 'id' => 'provider'), 'website' => array('type' => 'websiteType', 'id' => 'website_type'), 'address' => array('skip' => true, 'customData' => 1), 'email' => array('skip' => true), 'openid' => array('skip' => true));
     foreach ($communicationType as $key => $value) {
         if (CRM_Utils_Array::value($key, $defaults)) {
             foreach ($defaults[$key] as &$val) {
                 CRM_Utils_Array::lookupValue($val, 'location_type', CRM_Core_PseudoConstant::locationType(), false);
                 if (!CRM_Utils_Array::value('skip', $value)) {
                     eval('$pseudoConst = CRM_Core_PseudoConstant::' . $value['type'] . '( );');
                     CRM_Utils_Array::lookupValue($val, $value['id'], $pseudoConst, false);
                 }
             }
             if (isset($value['customData'])) {
                 foreach ($defaults[$key] as $blockId => $blockVal) {
                     $groupTree = CRM_Core_BAO_CustomGroup::getTree(ucfirst($key), $this, $blockVal['id']);
                     // we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var.
                     $defaults[$key][$blockId]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, false, null, "dnc_");
                 }
                 // reset template variable since that won't be of any use, and could be misleading
                 $this->assign("dnc_viewCustomData", null);
             }
         }
     }
     if (CRM_Utils_Array::value('gender_id', $defaults)) {
         $gender = CRM_Core_PseudoConstant::gender();
         $defaults['gender_display'] = $gender[CRM_Utils_Array::value('gender_id', $defaults)];
     }
     // to make contact type label available in the template -
     $contactType = array_key_exists('contact_sub_type', $defaults) ? $defaults['contact_sub_type'] : $defaults['contact_type'];
     $defaults['contact_type_label'] = CRM_Contact_BAO_ContactType::contactTypePairs(true, $contactType);
     // get contact tags
     require_once 'CRM/Core/BAO/EntityTag.php';
     $contactTags = CRM_Core_BAO_EntityTag::getContactTags($this->_contactId);
     if (!empty($contactTags)) {
         $defaults['contactTag'] = implode(', ', $contactTags);
     }
     $defaults['privacy_values'] = CRM_Core_SelectValues::privacy();
     //Show blocks only if they are visible in edit form
     require_once 'CRM/Core/BAO/Preferences.php';
     $this->_editOptions = CRM_Core_BAO_Preferences::valueOptions('contact_edit_options');
     $configItems = array('CommBlock' => 'Communication Preferences', 'Demographics' => 'Demographics', 'TagsAndGroups' => 'Tags and Groups', 'Notes' => 'Notes');
     foreach ($configItems as $c => $t) {
         $varName = '_show' . $c;
         $this->{$varName} = CRM_Utils_Array::value($c, $this->_editOptions);
         $this->assign(substr($varName, 1), $this->{$varName});
     }
     // get contact name of shared contact names
     $sharedAddresses = array();
     $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']);
         }
     }
     $this->assign('sharedAddresses', $sharedAddresses);
     //get the current employer name
     if (CRM_Utils_Array::value('contact_type', $defaults) == 'Individual') {
         if ($contact->employer_id && $contact->organization_name) {
             $defaults['current_employer'] = $contact->organization_name;
             $defaults['current_employer_id'] = $contact->employer_id;
         }
         //for birthdate format with respect to birth format set
         $this->assign('birthDateViewFormat', CRM_Utils_Array::value('qfMapping', CRM_Utils_Date::checkBirthDateFormat()));
     }
     $this->assign($defaults);
     // also assign the last modifed details
     require_once 'CRM/Core/BAO/Log.php';
     $lastModified =& CRM_Core_BAO_Log::lastModified($this->_contactId, 'civicrm_contact');
     $this->assign_by_ref('lastModified', $lastModified);
     $allTabs = array();
     $weight = 10;
     $this->_viewOptions = CRM_Core_BAO_Preferences::valueOptions('contact_view_options', true);
     $changeLog = $this->_viewOptions['log'];
     $this->assign_by_ref('changeLog', $changeLog);
     require_once 'CRM/Core/Component.php';
     $components = CRM_Core_Component::getEnabledComponents();
     foreach ($components as $name => $component) {
         if (CRM_Utils_Array::value($name, $this->_viewOptions) && CRM_Core_Permission::access($component->name)) {
             $elem = $component->registerTab();
             // FIXME: not very elegant, probably needs better approach
             // allow explicit id, if not defined, use keyword instead
             if (array_key_exists('id', $elem)) {
                 $i = $elem['id'];
             } else {
                 $i = $component->getKeyword();
             }
             $u = $elem['url'];
             //appending isTest to url for test soft credit CRM-3891.
             //FIXME: hack ajax url.
             $q = "reset=1&snippet=1&force=1&cid={$this->_contactId}";
             if (CRM_Utils_Request::retrieve('isTest', 'Positive', $this)) {
                 $q = $q . "&isTest=1";
             }
             $allTabs[] = array('id' => $i, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$u}", $q), 'title' => $elem['title'], 'weight' => $elem['weight'], 'count' => CRM_Contact_BAO_Contact::getCountComponent($u, $this->_contactId));
             // make sure to get maximum weight, rest of tabs go after
             // FIXME: not very elegant again
             if ($weight < $elem['weight']) {
                 $weight = $elem['weight'];
             }
         }
     }
     $rest = array('activity' => ts('Activities'), 'case' => ts('Cases'), 'rel' => ts('Relationships'), 'group' => ts('Groups'), 'note' => ts('Notes'), 'tag' => ts('Tags'), 'log' => ts('Change Log'));
     $config = CRM_Core_Config::singleton();
     if (isset($config->sunlight) && $config->sunlight) {
         $title = ts('Elected Officials');
         $rest['sunlight'] = $title;
         $this->_viewOptions[$title] = true;
     }
     foreach ($rest as $k => $v) {
         if (CRM_Utils_Array::value($k, $this->_viewOptions)) {
             $allTabs[] = array('id' => $k, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$k}", "reset=1&snippet=1&cid={$this->_contactId}"), 'title' => $v, 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($k, $this->_contactId));
             $weight += 10;
         }
     }
     // now add all the custom tabs
     $entityType = $this->get('contactType');
     $activeGroups = CRM_Core_BAO_CustomGroup::getActiveGroups($entityType, 'civicrm/contact/view/cd', $this->_contactId);
     foreach ($activeGroups as $group) {
         $id = "custom_{$group['id']}";
         $allTabs[] = array('id' => $id, 'url' => CRM_Utils_System::url($group['path'], $group['query'] . "&snippet=1&selectedChild={$id}"), 'title' => $group['title'], 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $group['table_name']));
         $weight += 10;
     }
     // see if any other modules want to add any tabs
     require_once 'CRM/Utils/Hook.php';
     CRM_Utils_Hook::tabs($allTabs, $this->_contactId);
     // now sort the tabs based on weight
     require_once 'CRM/Utils/Sort.php';
     usort($allTabs, array('CRM_Utils_Sort', 'cmpFunc'));
     $this->assign('allTabs', $allTabs);
     $selectedChild = CRM_Utils_Request::retrieve('selectedChild', 'String', $this, false, 'summary');
     $this->assign('selectedChild', $selectedChild);
     // hook for contact summary
     require_once 'CRM/Utils/Hook.php';
     $contentPlacement = CRM_Utils_Hook::SUMMARY_BELOW;
     // ignored but needed to prevent warnings
     CRM_Utils_Hook::summary($this->_contactId, $content, $contentPlacement);
     if ($content) {
         $this->assign_by_ref('hookContent', $content);
         $this->assign('hookContentPlacement', $contentPlacement);
     }
 }
Exemple #8
0
 /**
  * View summary details of a contact.
  */
 public function view()
 {
     // Add js for tabs, in-place editing, and jstree for tags
     CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'templates/CRM/Contact/Page/View/Summary.js', 2, 'html-header')->addStyleFile('civicrm', 'css/contactSummary.css', 2, 'html-header')->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header')->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')->addSetting(array('summaryPrint' => array('mode' => $this->_print), 'tabSettings' => array('active' => CRM_Utils_Request::retrieve('selectedChild', 'String', $this, FALSE, 'summary'))));
     $this->assign('summaryPrint', $this->_print);
     $session = CRM_Core_Session::singleton();
     $url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId);
     $session->pushUserContext($url);
     $params = array();
     $defaults = array();
     $ids = array();
     $params['id'] = $params['contact_id'] = $this->_contactId;
     $params['noRelationships'] = $params['noNotes'] = $params['noGroups'] = TRUE;
     $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, TRUE);
     // Let summary page know if outbound mail is disabled so email links can be built conditionally
     $mailingBackend = Civi::settings()->get('mailing_backend');
     $this->assign('mailingOutboundOption', $mailingBackend['outBound_option']);
     $communicationType = array('phone' => array('type' => 'phoneType', 'id' => 'phone_type', 'daoName' => 'CRM_Core_DAO_Phone', 'fieldName' => 'phone_type_id'), 'im' => array('type' => 'IMProvider', 'id' => 'provider', 'daoName' => 'CRM_Core_DAO_IM', 'fieldName' => 'provider_id'), 'website' => array('type' => 'websiteType', 'id' => 'website_type', 'daoName' => 'CRM_Core_DAO_Website', 'fieldName' => 'website_type_id'), 'address' => array('skip' => TRUE, 'customData' => 1), 'email' => array('skip' => TRUE), 'openid' => array('skip' => TRUE));
     foreach ($communicationType as $key => $value) {
         if (!empty($defaults[$key])) {
             foreach ($defaults[$key] as &$val) {
                 CRM_Utils_Array::lookupValue($val, 'location_type', CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name')), FALSE);
                 if (empty($value['skip'])) {
                     $daoName = $value['daoName'];
                     $pseudoConst = $daoName::buildOptions($value['fieldName'], 'get');
                     CRM_Utils_Array::lookupValue($val, $value['id'], $pseudoConst, FALSE);
                 }
             }
             if (isset($value['customData'])) {
                 foreach ($defaults[$key] as $blockId => $blockVal) {
                     $idValue = $blockVal['id'];
                     if ($key == 'address') {
                         if (!empty($blockVal['master_id'])) {
                             $idValue = $blockVal['master_id'];
                         }
                     }
                     $groupTree = CRM_Core_BAO_CustomGroup::getTree(ucfirst($key), $this, $idValue);
                     // we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var.
                     $defaults[$key][$blockId]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, "dnc_");
                 }
                 // reset template variable since that won't be of any use, and could be misleading
                 $this->assign("dnc_viewCustomData", NULL);
             }
         }
     }
     if (!empty($defaults['gender_id'])) {
         $defaults['gender_display'] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', 'gender_id', $defaults['gender_id']);
     }
     $communicationStyle = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'communication_style_id');
     if (!empty($communicationStyle)) {
         if (!empty($defaults['communication_style_id'])) {
             $defaults['communication_style_display'] = $communicationStyle[CRM_Utils_Array::value('communication_style_id', $defaults)];
         } else {
             // Make sure the field is displayed as long as it is active, even if it is unset for this contact.
             $defaults['communication_style_display'] = '';
         }
     }
     // to make contact type label available in the template -
     $contactType = array_key_exists('contact_sub_type', $defaults) ? $defaults['contact_sub_type'] : $defaults['contact_type'];
     $defaults['contact_type_label'] = CRM_Contact_BAO_ContactType::contactTypePairs(TRUE, $contactType, ', ');
     // get contact tags
     $contactTags = CRM_Core_BAO_EntityTag::getContactTags($this->_contactId);
     if (!empty($contactTags)) {
         $defaults['contactTag'] = implode(', ', $contactTags);
     }
     $defaults['privacy_values'] = CRM_Core_SelectValues::privacy();
     //Show blocks only if they are visible in edit form
     $this->_editOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_edit_options');
     foreach ($this->_editOptions as $blockName => $value) {
         $varName = '_show' . $blockName;
         $this->{$varName} = $value;
         $this->assign(substr($varName, 1), $this->{$varName});
     }
     // get contact name of shared contact names
     $sharedAddresses = array();
     $shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($defaults['address']);
     foreach ($defaults['address'] as $key => $addressValue) {
         if (!empty($addressValue['master_id']) && !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']) {
             $sharedAddresses[$key]['shared_address_display'] = array('address' => $addressValue['display'], 'name' => $shareAddressContactNames[$addressValue['master_id']]['name']);
         }
     }
     $this->assign('sharedAddresses', $sharedAddresses);
     //get the current employer name
     if (CRM_Utils_Array::value('contact_type', $defaults) == 'Individual') {
         if ($contact->employer_id && $contact->organization_name) {
             $defaults['current_employer'] = $contact->organization_name;
             $defaults['current_employer_id'] = $contact->employer_id;
         }
         //for birthdate format with respect to birth format set
         $this->assign('birthDateViewFormat', CRM_Utils_Array::value('qfMapping', CRM_Utils_Date::checkBirthDateFormat()));
     }
     $defaults['external_identifier'] = $contact->external_identifier;
     $this->assign($defaults);
     // FIXME: when we sort out TZ isssues with DATETIME/TIMESTAMP, we can skip next query
     // also assign the last modifed details
     $lastModified = CRM_Core_BAO_Log::lastModified($this->_contactId, 'civicrm_contact');
     $this->assign_by_ref('lastModified', $lastModified);
     $allTabs = array();
     $weight = 10;
     $this->_viewOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_view_options', TRUE);
     // show the tabs only if user has generic access to CiviCRM
     $accessCiviCRM = CRM_Core_Permission::check('access CiviCRM');
     $changeLog = $this->_viewOptions['log'];
     $this->assign_by_ref('changeLog', $changeLog);
     $components = CRM_Core_Component::getEnabledComponents();
     foreach ($components as $name => $component) {
         if (!empty($this->_viewOptions[$name]) && CRM_Core_Permission::access($component->name)) {
             $elem = $component->registerTab();
             // FIXME: not very elegant, probably needs better approach
             // allow explicit id, if not defined, use keyword instead
             if (array_key_exists('id', $elem)) {
                 $i = $elem['id'];
             } else {
                 $i = $component->getKeyword();
             }
             $u = $elem['url'];
             //appending isTest to url for test soft credit CRM-3891.
             //FIXME: hack ajax url.
             $q = "reset=1&force=1&cid={$this->_contactId}";
             if (CRM_Utils_Request::retrieve('isTest', 'Positive', $this)) {
                 $q .= "&isTest=1";
             }
             $allTabs[] = array('id' => $i, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$u}", $q), 'title' => $elem['title'], 'weight' => $elem['weight'], 'count' => CRM_Contact_BAO_Contact::getCountComponent($u, $this->_contactId), 'class' => 'livePage');
             // make sure to get maximum weight, rest of tabs go after
             // FIXME: not very elegant again
             if ($weight < $elem['weight']) {
                 $weight = $elem['weight'];
             }
         }
     }
     $rest = array('activity' => array('title' => ts('Activities'), 'class' => 'livePage'), 'rel' => array('title' => ts('Relationships'), 'class' => 'livePage'), 'group' => array('title' => ts('Groups'), 'class' => 'ajaxForm'), 'note' => array('title' => ts('Notes'), 'class' => 'livePage'), 'tag' => array('title' => ts('Tags')), 'log' => array('title' => ts('Change Log')));
     foreach ($rest as $k => $v) {
         if ($accessCiviCRM && !empty($this->_viewOptions[$k])) {
             $allTabs[] = $v + array('id' => $k, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$k}", "reset=1&cid={$this->_contactId}"), 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($k, $this->_contactId));
             $weight += 10;
         }
     }
     // now add all the custom tabs
     $entityType = $this->get('contactType');
     $activeGroups = CRM_Core_BAO_CustomGroup::getActiveGroups($entityType, 'civicrm/contact/view/cd', $this->_contactId);
     foreach ($activeGroups as $group) {
         $id = "custom_{$group['id']}";
         $allTabs[] = array('id' => $id, 'url' => CRM_Utils_System::url($group['path'], $group['query'] . "&selectedChild={$id}"), 'title' => $group['title'], 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $group['table_name']), 'hideCount' => !$group['is_multiple'], 'class' => 'livePage');
         $weight += 10;
     }
     $context = array('contact_id' => $this->_contactId);
     // see if any other modules want to add any tabs
     CRM_Utils_Hook::tabs($allTabs, $this->_contactId);
     CRM_Utils_Hook::tabset('civicrm/contact/view', $allTabs, $context);
     $allTabs[] = array('id' => 'summary', 'url' => '#contact-summary', 'title' => ts('Summary'), 'weight' => 0);
     // now sort the tabs based on weight
     usort($allTabs, array('CRM_Utils_Sort', 'cmpFunc'));
     $this->assign('allTabs', $allTabs);
     // hook for contact summary
     // ignored but needed to prevent warnings
     $contentPlacement = CRM_Utils_Hook::SUMMARY_BELOW;
     CRM_Utils_Hook::summary($this->_contactId, $content, $contentPlacement);
     if ($content) {
         $this->assign_by_ref('hookContent', $content);
         $this->assign('hookContentPlacement', $contentPlacement);
     }
 }
Exemple #9
0
 /**
  * @param CRM_Core_Form $form
  */
 public static function basic(&$form)
 {
     $form->addElement('hidden', 'hidden_basic', 1);
     if ($form->_searchOptions['contactType']) {
         // add checkboxes for contact type
         //@todo FIXME - using the CRM_Core_DAO::VALUE_SEPARATOR creates invalid html - if you can find the form
         // this is loaded onto then replace with something like '__' & test
         $separator = CRM_Core_DAO::VALUE_SEPARATOR;
         $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(FALSE, TRUE, $separator);
         if ($contactTypes) {
             $form->add('select', 'contact_type', ts('Contact Type(s)'), $contactTypes, FALSE, array('id' => 'contact_type', 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 100%;'));
         }
     }
     if ($form->_searchOptions['groups']) {
         // multiselect for groups
         if ($form->_group) {
             // Arrange groups into hierarchical listing (child groups follow their parents and have indentation spacing in title)
             $groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($form->_group, NULL, '&nbsp;&nbsp;', TRUE);
             $form->add('select', 'group', ts('Groups'), $groupHierarchy, FALSE, array('id' => 'group', 'multiple' => 'multiple', 'class' => 'crm-select2'));
             $groupOptions = CRM_Core_BAO_OptionValue::getOptionValuesAssocArrayFromName('group_type');
             $form->add('select', 'group_type', ts('Group Types'), $groupOptions, FALSE, array('id' => 'group_type', 'multiple' => 'multiple', 'class' => 'crm-select2'));
             $form->add('hidden', 'group_search_selected', 'group');
         }
     }
     if ($form->_searchOptions['tags']) {
         // multiselect for categories
         $contactTags = CRM_Core_BAO_Tag::getTags();
         if ($contactTags) {
             $form->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE, array('id' => 'contact_tags', 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 100%;'));
         }
         $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact');
         CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', NULL, TRUE, FALSE);
         $used_for = CRM_Core_OptionGroup::values('tag_used_for');
         $tagsTypes = array();
         $showAllTagTypes = FALSE;
         foreach ($used_for as $key => $value) {
             //check tags for every type and find if there are any defined
             $tags = CRM_Core_BAO_Tag::getTagsUsedFor($key, FALSE, TRUE, NULL);
             // check if there are tags other than contact type, if no - keep checkbox hidden on adv search
             // we will hide searching contact by attachments tags until it will be implemented in core
             if (count($tags) && $key != 'civicrm_file' && $key != 'civicrm_contact') {
                 //if tags exists then add type to display in adv search form help text
                 $tagsTypes[] = ts($value);
                 $showAllTagTypes = TRUE;
             }
         }
         $tagTypesText = implode(" or ", $tagsTypes);
         if ($showAllTagTypes) {
             $form->add('checkbox', 'all_tag_types', ts('Include tags used for %1', array(1 => $tagTypesText)));
             $form->add('hidden', 'tag_types_text', $tagTypesText);
         }
     }
     // add text box for last name, first name, street name, city
     $form->addElement('text', 'sort_name', ts('Find...'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
     // add text box for last name, first name, street name, city
     $form->add('text', 'email', ts('Contact Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
     //added contact source
     $form->add('text', 'contact_source', ts('Contact Source'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'contact_source'));
     //added job title
     $form->addElement('text', 'job_title', ts('Job Title'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'job_title'));
     //added internal ID
     $form->addElement('text', 'contact_id', ts('Contact ID'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'id'));
     $form->addRule('contact_id', ts('Please enter valid Contact ID'), 'positiveInteger');
     //added external ID
     $form->addElement('text', 'external_identifier', ts('External ID'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'external_identifier'));
     if (CRM_Core_Permission::check('access deleted contacts') and CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_undelete', NULL)) {
         $form->add('checkbox', 'deleted_contacts', ts('Search in Trash') . '<br />' . ts('(deleted contacts)'));
     }
     // add checkbox for cms users only
     $form->addYesNo('uf_user', ts('CMS User?'), TRUE);
     // tag all search
     $form->add('text', 'tag_search', ts('All Tags'));
     // add search profiles
     // FIXME: This is probably a part of profiles - need to be
     // FIXME: eradicated from here when profiles are reworked.
     $types = array('Participant', 'Contribution', 'Membership');
     // get component profiles
     $componentProfiles = array();
     $componentProfiles = CRM_Core_BAO_UFGroup::getProfiles($types);
     $ufGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup('Search Profile', 1);
     $accessibleUfGroups = CRM_Core_Permission::ufGroup(CRM_Core_Permission::VIEW);
     $searchProfiles = array();
     foreach ($ufGroups as $key => $var) {
         if (!array_key_exists($key, $componentProfiles) && in_array($key, $accessibleUfGroups)) {
             $searchProfiles[$key] = $var['title'];
         }
     }
     $form->add('select', 'uf_group_id', ts('Search Views'), array('0' => ts('- default view -')) + $searchProfiles, FALSE, array('class' => 'crm-select2'));
     $componentModes = CRM_Contact_Form_Search::getModeSelect();
     // unset contributions or participants if user does not have
     // permission on them
     if (!CRM_Core_Permission::access('CiviContribute')) {
         unset($componentModes['2']);
     }
     if (!CRM_Core_Permission::access('CiviEvent')) {
         unset($componentModes['3']);
     }
     if (!CRM_Core_Permission::access('CiviMember')) {
         unset($componentModes['5']);
     }
     if (!CRM_Core_Permission::check('view all activities')) {
         unset($componentModes['4']);
     }
     if (count($componentModes) > 1) {
         $form->add('select', 'component_mode', ts('Display Results As'), $componentModes, FALSE, array('class' => 'crm-select2'));
     }
     $form->addRadio('operator', ts('Search Operator'), array('AND' => ts('AND'), 'OR' => ts('OR')), array('allowClear' => FALSE));
     // add the option to display relationships
     $rTypes = CRM_Core_PseudoConstant::relationshipType();
     $rSelect = array('' => ts('- Select Relationship Type-'));
     foreach ($rTypes as $rid => $rValue) {
         if ($rValue['label_a_b'] == $rValue['label_b_a']) {
             $rSelect[$rid] = $rValue['label_a_b'];
         } else {
             $rSelect["{$rid}_a_b"] = $rValue['label_a_b'];
             $rSelect["{$rid}_b_a"] = $rValue['label_b_a'];
         }
     }
     $form->addElement('select', 'display_relationship_type', ts('Display Results as Relationship'), $rSelect, array('class' => 'crm-select2'));
     // checkboxes for DO NOT phone, email, mail
     // we take labels from SelectValues
     $t = CRM_Core_SelectValues::privacy();
     $form->add('select', 'privacy_options', ts('Privacy'), $t, FALSE, array('id' => 'privacy_options', 'multiple' => 'multiple', 'class' => 'crm-select2'));
     $form->addElement('select', 'privacy_operator', ts('Operator'), array('OR' => ts('OR'), 'AND' => ts('AND')));
     $options = array(1 => ts('Exclude'), 2 => ts('Include by Privacy Option(s)'));
     $form->addRadio('privacy_toggle', ts('Privacy Options'), $options, array('allowClear' => FALSE));
     // preferred communication method
     $comm = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
     $commPreff = array();
     foreach ($comm as $k => $v) {
         $commPreff[] = $form->createElement('advcheckbox', $k, NULL, $v);
     }
     $onHold[] = $form->createElement('advcheckbox', 'on_hold', NULL, '');
     $form->addGroup($onHold, 'email_on_hold', ts('Email On Hold'));
     $form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Communication Method'));
     //CRM-6138 Preferred Language
     $form->addSelect('preferred_language', array('class' => 'twenty', 'context' => 'search'));
     // Phone search
     $form->addElement('text', 'phone_numeric', ts('Phone Number'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone'));
     $locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
     $phoneType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
     $form->add('select', 'phone_location_type_id', ts('Phone Location'), array('' => ts('- any -')) + $locationType, FALSE, array('class' => 'crm-select2'));
     $form->add('select', 'phone_phone_type_id', ts('Phone Type'), array('' => ts('- any -')) + $phoneType, FALSE, array('class' => 'crm-select2'));
 }
Exemple #10
0
 static function basic(&$form)
 {
     $form->addElement('hidden', 'hidden_basic', 1);
     if ($form->_searchOptions['contactType']) {
         // add checkboxes for contact type
         $contact_type = array();
         require_once 'CRM/Contact/BAO/ContactType.php';
         $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements();
         foreach ($contactTypes as $k => $v) {
             if (!empty($k)) {
                 $contact_type[] = HTML_QuickForm::createElement('checkbox', $k, null, $v);
             }
         }
         $form->addGroup($contact_type, 'contact_type', ts('Contact Type(s)'), '<br />');
     }
     if ($form->_searchOptions['groups']) {
         // checkboxes for groups
         foreach ($form->_group as $groupID => $group) {
             $form->_groupElement =& $form->addElement('checkbox', "group[{$groupID}]", null, $group);
         }
     }
     if ($form->_searchOptions['tags']) {
         // checkboxes for categories
         require_once 'CRM/Core/BAO/Tag.php';
         $tags = new CRM_Core_BAO_Tag();
         $tree = $tags->getTree();
         $form->assign('tree', $tags->getTree());
         foreach ($form->_tag as $tagID => $tagName) {
             $form->_tagElement =& $form->addElement('checkbox', "tag[{$tagID}]", null, $tagName);
         }
     }
     // add text box for last name, first name, street name, city
     $form->addElement('text', 'sort_name', ts('Find...'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
     // add text box for last name, first name, street name, city
     $form->add('text', 'email', ts('Contact Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
     //added contact source
     $form->add('text', 'contact_source', ts('Contact Source'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'source'));
     // add checkbox for cms users only
     if (CIVICRM_UF != 'Standalone') {
         $form->addYesNo('uf_user', ts('CMS User?'));
     }
     // add search profiles
     require_once 'CRM/Core/BAO/UFGroup.php';
     // FIXME: This is probably a part of profiles - need to be
     // FIXME: eradicated from here when profiles are reworked.
     $types = array('Participant', 'Contribution', 'Membership');
     // get component profiles
     $componentProfiles = array();
     $componentProfiles = CRM_Core_BAO_UFGroup::getProfiles($types);
     $ufGroups =& CRM_Core_BAO_UFGroup::getModuleUFGroup('Search Profile', 1);
     $accessibleUfGroups = CRM_Core_Permission::ufGroup(CRM_Core_Permission::VIEW);
     $searchProfiles = array();
     foreach ($ufGroups as $key => $var) {
         if (!array_key_exists($key, $componentProfiles) && in_array($key, $accessibleUfGroups)) {
             $searchProfiles[$key] = $var['title'];
         }
     }
     $form->addElement('select', 'uf_group_id', ts('Search Views'), array('0' => ts('- default view -')) + $searchProfiles);
     // checkboxes for DO NOT phone, email, mail
     // we take labels from SelectValues
     $t = CRM_Core_SelectValues::privacy();
     $t['do_not_toggle'] = ts('Include contacts who have these privacy option(s).');
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_phone', null, $t['do_not_phone']);
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_email', null, $t['do_not_email']);
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_mail', null, $t['do_not_mail']);
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_sms', null, $t['do_not_sms']);
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_trade', null, $t['do_not_trade']);
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_toggle', null, $t['do_not_toggle']);
     $form->addGroup($privacy, 'privacy', ts('Privacy'), array('&nbsp;', '&nbsp;', '&nbsp;', '<br/>'));
     // preferred communication method
     require_once 'CRM/Core/PseudoConstant.php';
     $comm = CRM_Core_PseudoConstant::pcm();
     $commPreff = array();
     foreach ($comm as $k => $v) {
         $commPreff[] = HTML_QuickForm::createElement('advcheckbox', $k, null, $v);
     }
     $form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Communication Method'));
 }
Exemple #11
0
 /**
  * Process the user submitted custom data values.
  *
  * @access public
  * @return void
  */
 function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     $data = array();
     $data['contact_type'] = 'Individual';
     //get the custom fields for the contact
     $customFields = CRM_Core_BAO_CustomField::getFields($data['contact_type']);
     $locationType = array();
     $count = 1;
     if ($this->_id) {
         $primaryLocationType = CRM_Contact_BAO_Contact::getPrimaryLocationType($this->_id);
     }
     $phoneLoc = 0;
     foreach ($params as $key => $value) {
         $keyValue = explode('-', $key);
         if (is_numeric($keyValue[1])) {
             if (!in_array($keyValue[1], $locationType)) {
                 $locationType[$count] = $keyValue[1];
                 $count++;
             }
             require_once 'CRM/Utils/Array.php';
             $loc = CRM_Utils_Array::key($keyValue[1], $locationType);
             $data['location'][$loc]['location_type_id'] = $keyValue[1];
             if ($this->_id) {
                 //get the primary location type
                 if ($keyValue[1] == $primaryLocationType) {
                     $data['location'][$loc]['is_primary'] = 1;
                 }
             } else {
                 if ($loc == 1) {
                     $data['location'][$loc]['is_primary'] = 1;
                 }
             }
             if ($keyValue[0] == 'name') {
                 $data['location'][$loc]['name'] = $value;
             } else {
                 if ($keyValue[0] == 'phone') {
                     $phoneLoc++;
                     if ($keyValue[2]) {
                         $data['location'][$loc]['phone'][$phoneLoc]['phone_type'] = $keyValue[2];
                     } else {
                         $data['location'][$loc]['phone'][$phoneLoc]['phone_type'] = '';
                         $data['location'][$loc]['phone'][$phoneLoc]['is_primary'] = 1;
                     }
                     $data['location'][$loc]['phone'][$phoneLoc]['phone'] = $value;
                 } else {
                     if ($keyValue[0] == 'email') {
                         $data['location'][$loc]['email'][1]['email'] = $value;
                         $data['location'][$loc]['email'][1]['is_primary'] = 1;
                     } else {
                         if ($keyValue[0] == 'im') {
                             $data['location'][$loc]['im'][1]['name'] = $value;
                             $data['location'][$loc]['im'][1]['is_primary'] = 1;
                         } else {
                             if ($keyValue[0] === 'state_province') {
                                 $data['location'][$loc]['address']['state_province_id'] = $value;
                             } else {
                                 if ($keyValue[0] === 'country') {
                                     $data['location'][$loc]['address']['country_id'] = $value;
                                 } else {
                                     $data['location'][$loc]['address'][$keyValue[0]] = $value;
                                 }
                             }
                         }
                     }
                 }
             }
         } else {
             if ($key === 'individual_suffix') {
                 $data['suffix_id'] = $value;
             } else {
                 if ($key === 'individual_prefix') {
                     $data['prefix_id'] = $value;
                 } else {
                     if ($key === 'gender') {
                         $data['gender_id'] = $value;
                     } else {
                         if (substr($key, 0, 6) === 'custom') {
                             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
                                 //fix checkbox
                                 if ($customFields[$customFieldID][3] == 'CheckBox') {
                                     $value = implode(CRM_CORE_BAO_CUSTOMOPTION_VALUE_SEPERATOR, array_keys($value));
                                 }
                                 if ($customFields[$customFieldID][3] == 'Multi-Select') {
                                     $value = implode(CRM_CORE_BAO_CUSTOMOPTION_VALUE_SEPERATOR, $value);
                                 }
                                 // fix the date field
                                 if ($customFields[$customFieldID][2] == 'Date') {
                                     $date = CRM_Utils_Date::format($value);
                                     if (!$date) {
                                         $date = '';
                                     }
                                     $value = $date;
                                 }
                                 //to add the id of custom value if exits
                                 //$this->_contact['custom_value_5_id'] = 123;
                                 $str = 'custom_value_' . $customFieldID . '_id';
                                 if ($this->_contact[$str]) {
                                     $id = $this->_contact[$str];
                                 }
                                 $data['custom'][$customFieldID] = array('id' => $id, 'value' => $value, 'extends' => $customFields[$customFieldID][3], 'type' => $customFields[$customFieldID][2], 'custom_field_id' => $customFieldID);
                             }
                         } else {
                             if ($key == 'edit') {
                                 continue;
                             } else {
                                 $data[$key] = $value;
                             }
                         }
                     }
                 }
             }
         }
     }
     // fix all the custom field checkboxes which are empty
     foreach ($this->_fields as $name => $field) {
         $cfID = CRM_Core_BAO_CustomField::getKeyID($name);
         // if there is a custom field of type checkbox and it has not been set
         // then set it to null, thanx to html protocol
         if ($cfID && $customFields[$cfID][3] == 'CheckBox' && CRM_Utils_Array::value('custom', $data) && !CRM_Utils_Array::value($cfID, $data['custom'])) {
             $str = 'custom_value_' . $cfID . '_id';
             if ($this->_contact[$str]) {
                 $id = $this->_contact[$str];
             }
             $data['custom'][$cfID] = array('id' => $id, 'value' => '', 'extends' => $customFields[$cfID][3], 'type' => $customFields[$cfID][2], 'custom_field_id' => $cfID);
         }
     }
     if ($this->_id) {
         $objects = array('contact_id', 'individual_id', 'location_id', 'address_id');
         $ids = array();
         $phoneLoc = 0;
         foreach ($this->_fields as $name => $field) {
             $nameValue = explode('-', $name);
             foreach ($this->_contact as $key => $value) {
                 if (in_array($key, $objects)) {
                     $ids[substr($key, 0, strlen($key) - 3)] = $value;
                 } else {
                     if (is_array($value)) {
                         //fixed for CRM-665
                         if ($nameValue[1] == $value['location_type_id']) {
                             $locations[$value['location_type_id']] = 1;
                             $loc_no = count($locations);
                             if ($nameValue[0] == 'phone') {
                                 $phoneLoc++;
                                 if (isset($nameValue[2])) {
                                     $ids['location'][$loc_no]['phone'][$phoneLoc] = $value['phone'][$nameValue[2] . '_id'];
                                 } else {
                                     $ids['location'][$loc_no]['phone'][$phoneLoc] = $value['phone']['1_id'];
                                 }
                             } else {
                                 if ($nameValue[0] == 'im') {
                                     $ids['location'][$loc_no]['im'][1] = $value['im']['1_id'];
                                 } else {
                                     if ($nameValue[0] == 'email') {
                                         $ids['location'][$loc_no]['email'][1] = $value['email']['1_id'];
                                     } else {
                                         $ids['location'][$loc_no]['address'] = $value['address_id'];
                                     }
                                 }
                             }
                             $ids['location'][$loc_no]['id'] = $value['location_id'];
                         }
                     }
                 }
             }
         }
     }
     //set the values for checkboxes (do_not_email, do_not_mail, do_not_trade, do_not_phone)
     $privacy = CRM_Core_SelectValues::privacy();
     foreach ($privacy as $key => $value) {
         if (array_key_exists($key, $this->_fields)) {
             if ($params[$key]) {
                 $data[$key] = $params[$key];
             } else {
                 $data[$key] = 0;
             }
         }
     }
     // manage is_opt_out
     if (array_key_exists('is_opt_out', $this->_fields)) {
         $wasOptOut = $this->_contact['is_opt_out'] ? true : false;
         $isOptOut = $params['is_opt_out'] ? true : false;
         $data['is_opt_out'] = $isOptOut;
         // on change, create new civicrm_subscription_history entry
         if ($wasOptOut != $isOptOut) {
             $shParams = array('contact_id' => $this->_contact['contact_id'], 'status' => $isOptOut ? 'Removed' : 'Added', 'method' => 'Web');
             CRM_Contact_BAO_SubscriptionHistory::create($shParams);
         }
     }
     if ($this->_mode == CRM_PROFILE_FORM_MODE_REGISTER) {
         require_once 'CRM/Core/BAO/Address.php';
         CRM_Core_BAO_Address::setOverwrite(false);
     }
     require_once 'CRM/Contact/BAO/Contact.php';
     $contact = CRM_Contact_BAO_Contact::create($data, $ids, count($data['location']));
     // Process group and tag
     if (CRM_Utils_Array::value('group', $this->_fields)) {
         CRM_Contact_BAO_GroupContact::create($params['group'], $contact->id);
     }
     if (CRM_Utils_Array::value('tag', $this->_fields)) {
         require_once 'CRM/Core/BAO/EntityTag.php';
         CRM_Core_BAO_EntityTag::create($params['tag'], $contact->id);
     }
 }
 /**
  * Format profile contact parameters.
  *
  * @param array $params
  * @param $fields
  * @param int $contactID
  * @param int $ufGroupId
  * @param null $ctype
  * @param bool $skipCustom
  *
  * @return array
  */
 public static function formatProfileContactParams(&$params, &$fields, $contactID = NULL, $ufGroupId = NULL, $ctype = NULL, $skipCustom = FALSE)
 {
     $data = $contactDetails = array();
     // get the contact details (hier)
     if ($contactID) {
         list($details, $options) = self::getHierContactDetails($contactID, $fields);
         $contactDetails = $details[$contactID];
         $data['contact_type'] = CRM_Utils_Array::value('contact_type', $contactDetails);
         $data['contact_sub_type'] = CRM_Utils_Array::value('contact_sub_type', $contactDetails);
     } else {
         //we should get contact type only if contact
         if ($ufGroupId) {
             $data['contact_type'] = CRM_Core_BAO_UFField::getProfileType($ufGroupId);
             //special case to handle profile with only contact fields
             if ($data['contact_type'] == 'Contact') {
                 $data['contact_type'] = 'Individual';
             } elseif (CRM_Contact_BAO_ContactType::isaSubType($data['contact_type'])) {
                 $data['contact_type'] = CRM_Contact_BAO_ContactType::getBasicType($data['contact_type']);
             }
         } elseif ($ctype) {
             $data['contact_type'] = $ctype;
         } else {
             $data['contact_type'] = 'Individual';
         }
     }
     //fix contact sub type CRM-5125
     if (array_key_exists('contact_sub_type', $params) && !empty($params['contact_sub_type'])) {
         $data['contact_sub_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, (array) $params['contact_sub_type']) . CRM_Core_DAO::VALUE_SEPARATOR;
     } elseif (array_key_exists('contact_sub_type_hidden', $params) && !empty($params['contact_sub_type_hidden'])) {
         // if profile was used, and had any subtype, we obtain it from there
         $data['contact_sub_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, (array) $params['contact_sub_type_hidden']) . CRM_Core_DAO::VALUE_SEPARATOR;
     }
     if ($ctype == 'Organization') {
         $data['organization_name'] = CRM_Utils_Array::value('organization_name', $contactDetails);
     } elseif ($ctype == 'Household') {
         $data['household_name'] = CRM_Utils_Array::value('household_name', $contactDetails);
     }
     $locationType = array();
     $count = 1;
     if ($contactID) {
         //add contact id
         $data['contact_id'] = $contactID;
         $primaryLocationType = self::getPrimaryLocationType($contactID);
     } else {
         $defaultLocation = CRM_Core_BAO_LocationType::getDefault();
         $defaultLocationId = $defaultLocation->id;
     }
     // get the billing location type
     $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
     $billingLocationTypeId = array_search('Billing', $locationTypes);
     $blocks = array('email', 'phone', 'im', 'openid');
     $multiplFields = array('url');
     // prevent overwritten of formatted array, reset all block from
     // params if it is not in valid format (since import pass valid format)
     foreach ($blocks as $blk) {
         if (array_key_exists($blk, $params) && !is_array($params[$blk])) {
             unset($params[$blk]);
         }
     }
     $primaryPhoneLoc = NULL;
     $session = CRM_Core_Session::singleton();
     foreach ($params as $key => $value) {
         $fieldName = $locTypeId = $typeId = NULL;
         list($fieldName, $locTypeId, $typeId) = CRM_Utils_System::explode('-', $key, 3);
         //store original location type id
         $actualLocTypeId = $locTypeId;
         if ($locTypeId == 'Primary') {
             if ($contactID) {
                 if (in_array($fieldName, $blocks)) {
                     $locTypeId = self::getPrimaryLocationType($contactID, FALSE, $fieldName);
                 } else {
                     $locTypeId = self::getPrimaryLocationType($contactID, FALSE, 'address');
                 }
                 $primaryLocationType = $locTypeId;
             } else {
                 $locTypeId = $defaultLocationId;
             }
         }
         if (is_numeric($locTypeId) && !in_array($fieldName, $multiplFields) && substr($fieldName, 0, 7) != 'custom_') {
             $index = $locTypeId;
             if (is_numeric($typeId)) {
                 $index .= '-' . $typeId;
             }
             if (!in_array($index, $locationType)) {
                 $locationType[$count] = $index;
                 $count++;
             }
             $loc = CRM_Utils_Array::key($index, $locationType);
             $blockName = in_array($fieldName, $blocks) ? $fieldName : 'address';
             $data[$blockName][$loc]['location_type_id'] = $locTypeId;
             //set is_billing true, for location type "Billing"
             if ($locTypeId == $billingLocationTypeId) {
                 $data[$blockName][$loc]['is_billing'] = 1;
             }
             if ($contactID) {
                 //get the primary location type
                 if ($locTypeId == $primaryLocationType) {
                     $data[$blockName][$loc]['is_primary'] = 1;
                 }
             } elseif ($locTypeId == $defaultLocationId) {
                 $data[$blockName][$loc]['is_primary'] = 1;
             }
             if (in_array($fieldName, array('phone'))) {
                 if ($typeId) {
                     $data['phone'][$loc]['phone_type_id'] = $typeId;
                 } else {
                     $data['phone'][$loc]['phone_type_id'] = '';
                 }
                 $data['phone'][$loc]['phone'] = $value;
                 //special case to handle primary phone with different phone types
                 // in this case we make first phone type as primary
                 if (isset($data['phone'][$loc]['is_primary']) && !$primaryPhoneLoc) {
                     $primaryPhoneLoc = $loc;
                 }
                 if ($loc != $primaryPhoneLoc) {
                     unset($data['phone'][$loc]['is_primary']);
                 }
             } elseif ($fieldName == 'phone_ext') {
                 $data['phone'][$loc]['phone_ext'] = $value;
             } elseif ($fieldName == 'email') {
                 $data['email'][$loc]['email'] = $value;
             } elseif ($fieldName == 'im') {
                 if (isset($params[$key . '-provider_id'])) {
                     $data['im'][$loc]['provider_id'] = $params[$key . '-provider_id'];
                 }
                 if (strpos($key, '-provider_id') !== FALSE) {
                     $data['im'][$loc]['provider_id'] = $params[$key];
                 } else {
                     $data['im'][$loc]['name'] = $value;
                 }
             } elseif ($fieldName == 'openid') {
                 $data['openid'][$loc]['openid'] = $value;
             } else {
                 if ($fieldName === 'state_province') {
                     // CRM-3393
                     if (is_numeric($value) && (int) $value >= 1000) {
                         $data['address'][$loc]['state_province_id'] = $value;
                     } elseif (empty($value)) {
                         $data['address'][$loc]['state_province_id'] = '';
                     } else {
                         $data['address'][$loc]['state_province'] = $value;
                     }
                 } elseif ($fieldName === 'country') {
                     // CRM-3393
                     if (is_numeric($value) && (int) $value >= 1000) {
                         $data['address'][$loc]['country_id'] = $value;
                     } elseif (empty($value)) {
                         $data['address'][$loc]['country_id'] = '';
                     } else {
                         $data['address'][$loc]['country'] = $value;
                     }
                 } elseif ($fieldName === 'county') {
                     $data['address'][$loc]['county_id'] = $value;
                 } elseif ($fieldName == 'address_name') {
                     $data['address'][$loc]['name'] = $value;
                 } elseif (substr($fieldName, 0, 14) === 'address_custom') {
                     $data['address'][$loc][substr($fieldName, 8)] = $value;
                 } else {
                     $data['address'][$loc][$fieldName] = $value;
                 }
             }
         } else {
             if (substr($key, 0, 4) === 'url-') {
                 $websiteField = explode('-', $key);
                 $data['website'][$websiteField[1]]['website_type_id'] = $websiteField[1];
                 $data['website'][$websiteField[1]]['url'] = $value;
             } elseif (in_array($key, self::$_greetingTypes, TRUE)) {
                 //save email/postal greeting and addressee values if any, CRM-4575
                 $data[$key . '_id'] = $value;
             } elseif (!$skipCustom && ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key))) {
                 // for autocomplete transfer hidden value instead of label
                 if ($params[$key] && isset($params[$key . '_id'])) {
                     $value = $params[$key . '_id'];
                 }
                 // we need to append time with date
                 if ($params[$key] && isset($params[$key . '_time'])) {
                     $value .= ' ' . $params[$key . '_time'];
                 }
                 // if auth source is not checksum / login && $value is blank, do not proceed - CRM-10128
                 if (($session->get('authSrc') & CRM_Core_Permission::AUTH_SRC_CHECKSUM + CRM_Core_Permission::AUTH_SRC_LOGIN) == 0 && ($value == '' || !isset($value))) {
                     continue;
                 }
                 $valueId = NULL;
                 if (!empty($params['customRecordValues'])) {
                     if (is_array($params['customRecordValues']) && !empty($params['customRecordValues'])) {
                         foreach ($params['customRecordValues'] as $recId => $customFields) {
                             if (is_array($customFields) && !empty($customFields)) {
                                 foreach ($customFields as $customFieldName) {
                                     if ($customFieldName == $key) {
                                         $valueId = $recId;
                                         break;
                                     }
                                 }
                             }
                         }
                     }
                 }
                 $type = $data['contact_type'];
                 if (!empty($data['contact_sub_type'])) {
                     $type = $data['contact_sub_type'];
                     $type = explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($type, CRM_Core_DAO::VALUE_SEPARATOR));
                     // generally a contact even if, has multiple subtypes the parent-type is going to be one only
                     // and since formatCustomField() would be interested in parent type, lets consider only one subtype
                     // as the results going to be same.
                     $type = $type[0];
                 }
                 CRM_Core_BAO_CustomField::formatCustomField($customFieldId, $data['custom'], $value, $type, $valueId, $contactID);
             } elseif ($key == 'edit') {
                 continue;
             } else {
                 if ($key == 'location') {
                     foreach ($value as $locationTypeId => $field) {
                         foreach ($field as $block => $val) {
                             if ($block == 'address' && array_key_exists('address_name', $val)) {
                                 $value[$locationTypeId][$block]['name'] = $value[$locationTypeId][$block]['address_name'];
                             }
                         }
                     }
                 }
                 if ($key == 'phone' && isset($params['phone_ext'])) {
                     $data[$key] = $value;
                     foreach ($value as $cnt => $phoneBlock) {
                         if ($params[$key][$cnt]['location_type_id'] == $params['phone_ext'][$cnt]['location_type_id']) {
                             $data[$key][$cnt]['phone_ext'] = CRM_Utils_Array::retrieveValueRecursive($params['phone_ext'][$cnt], 'phone_ext');
                         }
                     }
                 } elseif (in_array($key, array('nick_name', 'job_title', 'middle_name', 'birth_date', 'gender_id', 'current_employer', 'prefix_id', 'suffix_id')) && ($value == '' || !isset($value)) && ($session->get('authSrc') & CRM_Core_Permission::AUTH_SRC_CHECKSUM + CRM_Core_Permission::AUTH_SRC_LOGIN) == 0) {
                     // CRM-10128: if auth source is not checksum / login && $value is blank, do not fill $data with empty value
                     // to avoid update with empty values
                     continue;
                 } else {
                     $data[$key] = $value;
                 }
             }
         }
     }
     if (!isset($data['contact_type'])) {
         $data['contact_type'] = 'Individual';
     }
     //set the values for checkboxes (do_not_email, do_not_mail, do_not_trade, do_not_phone)
     $privacy = CRM_Core_SelectValues::privacy();
     foreach ($privacy as $key => $value) {
         if (array_key_exists($key, $fields)) {
             // do not reset values for existing contacts, if fields are added to a profile
             if (array_key_exists($key, $params)) {
                 $data[$key] = $params[$key];
                 if (empty($params[$key])) {
                     $data[$key] = 0;
                 }
             } elseif (!$contactID) {
                 $data[$key] = 0;
             }
         }
     }
     return array($data, $contactDetails);
 }
Exemple #13
0
 /**
  * function to add/edit/register contacts through profile.
  *
  * @params  array  $params        Array of profile fields to be edited/added.
  * @params  int    $contactID     contact_id of the contact to be edited/added.
  * @params  array  $fields        array of fields from UFGroup
  * @params  int    $addToGroupID  specifies the default group to which contact is added.
  * @params  int    $ufGroupId     uf group id (profile id)
  * @param   string $ctype         contact type
  *
  * @return  int                   contact id created/edited
  * @static
  * @access public
  */
 static function createProfileContact(&$params, &$fields, $contactID = null, $addToGroupID = null, $ufGroupId = null, $ctype = null, $visibility = false)
 {
     // add ufGroupID to params array ( CRM-2012 )
     if ($ufGroupId) {
         $params['uf_group_id'] = $ufGroupId;
     }
     require_once 'CRM/Utils/Hook.php';
     if ($contactID) {
         $editHook = true;
         CRM_Utils_Hook::pre('edit', 'Profile', $contactID, $params);
     } else {
         $editHook = false;
         CRM_Utils_Hook::pre('create', 'Profile', null, $params);
     }
     $data = $contactDetails = array();
     // get the contact details (hier)
     if ($contactID) {
         list($details, $options) = self::getHierContactDetails($contactID, $fields);
         $contactDetails = $details[$contactID];
         $data['contact_type'] = CRM_Utils_Array::value('contact_type', $contactDetails);
     } else {
         //we should get contact type only if contact
         if ($ufGroupId) {
             require_once "CRM/Core/BAO/UFField.php";
             $data['contact_type'] = CRM_Core_BAO_UFField::getProfileType($ufGroupId);
             //special case to handle profile with only contact fields
             if ($data['contact_type'] == 'Contact') {
                 $data['contact_type'] = 'Individual';
             } else {
                 if (CRM_Contact_BAO_ContactType::isaSubType($data['contact_type'])) {
                     $data['contact_type'] = CRM_Contact_BAO_ContactType::getBasicType($data['contact_type']);
                 }
             }
         } else {
             if ($ctype) {
                 $data['contact_type'] = $ctype;
             } else {
                 $data['contact_type'] = 'Individual';
             }
         }
     }
     //fix contact sub type CRM-5125
     if ($subType = CRM_Utils_Array::value('contact_sub_type', $params)) {
         $data['contact_sub_type'] = $subType;
     } else {
         if ($ufGroupId) {
             $data['contact_sub_type'] = CRM_Core_BAO_UFField::getProfileSubType($ufGroupId, $data['contact_type']);
         }
     }
     if ($ctype == "Organization") {
         $data["organization_name"] = $contactDetails["organization_name"];
     } else {
         if ($ctype == "Household") {
             $data["household_name"] = $contactDetails["household_name"];
         }
     }
     $locationType = array();
     $count = 1;
     if ($contactID) {
         //add contact id
         $data['contact_id'] = $contactID;
         $primaryLocationType = self::getPrimaryLocationType($contactID);
     } else {
         require_once "CRM/Core/BAO/LocationType.php";
         $defaultLocation =& CRM_Core_BAO_LocationType::getDefault();
         $defaultLocationId = $defaultLocation->id;
     }
     // get the billing location type
     $locationTypes =& CRM_Core_PseudoConstant::locationType();
     $billingLocationTypeId = array_search('Billing', $locationTypes);
     $blocks = array('email', 'phone', 'im', 'openid');
     // prevent overwritten of formatted array, reset all block from
     // params if it is not in valid format (since import pass valid format)
     foreach ($blocks as $blk) {
         if (array_key_exists($blk, $params) && !is_array($params[$blk])) {
             unset($params[$blk]);
         }
     }
     $primaryPhoneLoc = null;
     foreach ($params as $key => $value) {
         $fieldName = $locTypeId = $typeId = null;
         list($fieldName, $locTypeId, $typeId) = CRM_Utils_System::explode('-', $key, 3);
         //store original location type id
         $actualLocTypeId = $locTypeId;
         if ($locTypeId == 'Primary') {
             if ($contactID) {
                 $locTypeId = $primaryLocationType;
             } else {
                 $locTypeId = $defaultLocationId;
             }
         }
         if (is_numeric($locTypeId)) {
             $index = $locTypeId;
             if (is_numeric($typeId)) {
                 $index .= '-' . $typeId;
             }
             if (!in_array($index, $locationType)) {
                 $locationType[$count] = $index;
                 $count++;
             }
             require_once 'CRM/Utils/Array.php';
             $loc = CRM_Utils_Array::key($index, $locationType);
             $blockName = 'address';
             if (in_array($fieldName, $blocks)) {
                 $blockName = $fieldName;
             }
             $data[$blockName][$loc]['location_type_id'] = $locTypeId;
             //set is_billing true, for location type "Billing"
             if ($locTypeId == $billingLocationTypeId) {
                 $data[$blockName][$loc]['is_billing'] = 1;
             }
             if ($contactID) {
                 //get the primary location type
                 if ($locTypeId == $primaryLocationType) {
                     $data[$blockName][$loc]['is_primary'] = 1;
                 }
             } else {
                 if (($locTypeId == $defaultLocationId || $locTypeId == $billingLocationTypeId) && ($loc == 1 || !CRM_Utils_Array::retrieveValueRecursive($data['location'][$loc - 1], 'is_primary'))) {
                     $data[$blockName][$loc]['is_primary'] = 1;
                 }
             }
             if ($fieldName == 'phone') {
                 if ($typeId) {
                     $data['phone'][$loc]['phone_type_id'] = $typeId;
                 } else {
                     $data['phone'][$loc]['phone_type_id'] = '';
                 }
                 $data['phone'][$loc]['phone'] = $value;
                 //special case to handle primary phone with different phone types
                 // in this case we make first phone type as primary
                 if (isset($data['phone'][$loc]['is_primary']) && !$primaryPhoneLoc) {
                     $primaryPhoneLoc = $loc;
                 }
                 if ($loc != $primaryPhoneLoc) {
                     unset($data['phone'][$loc]['is_primary']);
                 }
             } else {
                 if ($fieldName == 'email') {
                     $data['email'][$loc]['email'] = $value;
                 } else {
                     if ($fieldName == 'im') {
                         if (isset($params[$key . '-provider_id'])) {
                             $data['im'][$loc]['provider_id'] = $params[$key . '-provider_id'];
                         }
                         $data['im'][$loc]['name'] = $value;
                     } else {
                         if ($fieldName == 'openid') {
                             # $value should be a hash of the OpenID fields
                             foreach ($value as $key => $val) {
                                 $data['openid'][$loc][$key] = $val;
                             }
                         } else {
                             if ($fieldName === 'state_province') {
                                 // CRM-3393
                                 if (is_numeric($value) && (int) $value >= 1000) {
                                     $data['address'][$loc]['state_province_id'] = $value;
                                 } else {
                                     $data['address'][$loc]['state_province'] = $value;
                                 }
                             } else {
                                 if ($fieldName === 'country') {
                                     // CRM-3393
                                     if (is_numeric($value) && (int) $value >= 1000) {
                                         $data['address'][$loc]['country_id'] = $value;
                                     } else {
                                         $data['address'][$loc]['country'] = $value;
                                     }
                                 } else {
                                     if ($fieldName === 'county') {
                                         $data['address'][$loc]['address']['county_id'] = $value;
                                     } else {
                                         if ($fieldName == 'address_name') {
                                             $data['address'][$loc]['name'] = $value;
                                         } else {
                                             $data['address'][$loc][$fieldName] = $value;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         } else {
             if ($key === 'individual_suffix') {
                 $data['suffix_id'] = $value;
             } else {
                 if ($key === 'individual_prefix') {
                     $data['prefix_id'] = $value;
                 } else {
                     if ($key === 'gender') {
                         $data['gender_id'] = $value;
                     } else {
                         if ($key === 'email_greeting') {
                             //save email/postal greeting and addressee values if any, CRM-4575
                             $data['email_greeting_id'] = $value;
                         } else {
                             if ($key === 'postal_greeting') {
                                 $data['postal_greeting_id'] = $value;
                             } else {
                                 if ($key === 'addressee') {
                                     $data['addressee_id'] = $value;
                                 } else {
                                     if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key)) {
                                         // for autocomplete transfer hidden value instead of label
                                         if (isset($params[$key . '_id'])) {
                                             $value = $params[$key . '_id'];
                                         }
                                         $type = CRM_Utils_Array::value('contact_sub_type', $data) ? $data['contact_sub_type'] : $data['contact_type'];
                                         CRM_Core_BAO_CustomField::formatCustomField($customFieldId, $data['custom'], $value, $type, null, $contactID);
                                     } else {
                                         if ($key == 'edit') {
                                             continue;
                                         } else {
                                             if ($key == 'location') {
                                                 foreach ($value as $locationTypeId => $field) {
                                                     foreach ($field as $block => $val) {
                                                         if ($block == 'address' && array_key_exists('address_name', $val)) {
                                                             $value[$locationTypeId][$block]['name'] = $value[$locationTypeId][$block]['address_name'];
                                                         }
                                                     }
                                                 }
                                             }
                                             $data[$key] = $value;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // FIX ME: need to check if we need this code
     // //make sure primary location is at first position in location array
     // if ( isset( $data['location'] ) && count( $data['location'] ) > 1 ) {
     //     // if first location is primary skip manipulation
     //     if ( !isset($data['location'][1]['is_primary']) ) {
     //         //find the key for primary location
     //         foreach ( $data['location'] as $primaryLocationKey => $value ) {
     //             if ( isset( $value['is_primary'] ) ) {
     //                 break;
     //             }
     //         }
     //
     //         // swap first location with primary location
     //         $tempLocation        = $data['location'][1];
     //         $data['location'][1] = $data['location'][$primaryLocationKey];
     //         $data['location'][$primaryLocationKey] = $tempLocation;
     //     }
     // }
     if (!isset($data['contact_type'])) {
         $data['contact_type'] = 'Individual';
     }
     if (CRM_Core_Permission::access('Quest')) {
         $studentFieldPresent = 0;
         foreach ($fields as $name => $field) {
             // check if student fields present
             require_once 'CRM/Quest/BAO/Student.php';
             if (!$studentFieldPresent && array_key_exists($name, CRM_Quest_BAO_Student::exportableFields())) {
                 $studentFieldPresent = 1;
             }
         }
     }
     //set the values for checkboxes (do_not_email, do_not_mail, do_not_trade, do_not_phone)
     $privacy = CRM_Core_SelectValues::privacy();
     foreach ($privacy as $key => $value) {
         if (array_key_exists($key, $fields)) {
             if ($params[$key]) {
                 $data[$key] = $params[$key];
             } else {
                 $data[$key] = 0;
             }
         }
     }
     // manage is_opt_out
     if (array_key_exists('is_opt_out', $fields)) {
         $wasOptOut = CRM_Utils_Array::value('is_opt_out', $contactDetails, false);
         $isOptOut = CRM_Utils_Array::value('is_opt_out', $params, false);
         $data['is_opt_out'] = $isOptOut;
         // on change, create new civicrm_subscription_history entry
         if ($wasOptOut != $isOptOut && CRM_Utils_Array::value('contact_id', $contactDetails)) {
             $shParams = array('contact_id' => $contactDetails['contact_id'], 'status' => $isOptOut ? 'Removed' : 'Added', 'method' => 'Web');
             CRM_Contact_BAO_SubscriptionHistory::create($shParams);
         }
     }
     require_once 'CRM/Contact/BAO/Contact.php';
     if ($data['contact_type'] != 'Student') {
         $contact =& self::create($data);
     }
     // contact is null if the profile does not have any contact fields
     if ($contact) {
         $contactID = $contact->id;
     }
     if (!$contactID) {
         CRM_Core_Error::fatal('Cannot proceed without a valid contact id');
     }
     // Process group and tag
     if (CRM_Utils_Array::value('group', $fields)) {
         $method = 'Admin';
         // this for sure means we are coming in via profile since i added it to fix
         // removing contacts from user groups -- lobo
         if ($visibility) {
             $method = 'Web';
         }
         CRM_Contact_BAO_GroupContact::create($params['group'], $contactID, $visibility, $method);
     }
     if (CRM_Utils_Array::value('tag', $fields)) {
         require_once 'CRM/Core/BAO/EntityTag.php';
         CRM_Core_BAO_EntityTag::create($params['tag'], $contactID);
     }
     //to add profile in default group
     if (is_array($addToGroupID)) {
         $contactIds = array($contactID);
         foreach ($addToGroupID as $groupId) {
             CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $groupId);
         }
     } else {
         if ($addToGroupID) {
             $contactIds = array($contactID);
             CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $addToGroupID);
         }
     }
     //to update student record
     if (CRM_Core_Permission::access('Quest') && $studentFieldPresent) {
         $ids = array();
         $dao =& new CRM_Quest_DAO_Student();
         $dao->contact_id = $contactID;
         if ($dao->find(true)) {
             $ids['id'] = $dao->id;
         }
         $ssids = array();
         $studentSummary =& new CRM_Quest_DAO_StudentSummary();
         $studentSummary->contact_id = $contactID;
         if ($studentSummary->find(true)) {
             $ssids['id'] = $studentSummary->id;
         }
         $params['contact_id'] = $contactID;
         //fixed for check boxes
         $specialFields = array('educational_interest', 'college_type', 'college_interest', 'test_tutoring');
         foreach ($specialFields as $field) {
             if ($params[$field]) {
                 $params[$field] = implode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, array_keys($params[$field]));
             }
         }
         CRM_Quest_BAO_Student::create($params, $ids);
         CRM_Quest_BAO_Student::createStudentSummary($params, $ssids);
     }
     // reset the group contact cache for this group
     require_once 'CRM/Contact/BAO/GroupContactCache.php';
     CRM_Contact_BAO_GroupContactCache::remove();
     if ($editHook) {
         CRM_Utils_Hook::post('edit', 'Profile', $contactID, $params);
     } else {
         CRM_Utils_Hook::post('create', 'Profile', $contactID, $params);
     }
     return $contactID;
 }
 /**
  * Build the form
  *
  * @access public
  * @return void
  */
 function buildQuickForm()
 {
     // add checkboxes for contact type
     $contact_type = array();
     foreach (CRM_Core_SelectValues::contactType() as $k => $v) {
         if (!empty($k)) {
             $contact_type[] = HTML_QuickForm::createElement('checkbox', $k, null, $v);
         }
     }
     $this->addGroup($contact_type, 'contact_type', ts('Contact Type(s)'), '<br />');
     // checkboxes for groups
     $group = array();
     foreach ($this->_group as $groupID => $groupName) {
         $this->_groupElement =& $this->addElement('checkbox', "group[{$groupID}]", null, $groupName);
     }
     // checkboxes for categories
     foreach ($this->_tag as $tagID => $tagName) {
         $this->_tagElement =& $this->addElement('checkbox', "tag[{$tagID}]", null, $tagName);
     }
     // add text box for last name, first name, street name, city
     $this->addElement('text', 'sort_name', ts('Find...'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
     $this->addElement('text', 'street_address', ts('Street Address'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address', 'street_address'));
     $this->addElement('text', 'city', ts('City'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address', 'city'));
     // select for state province
     $stateProvince = array('' => ts('- any state/province -')) + CRM_Core_PseudoConstant::stateProvince();
     $this->addElement('select', 'state_province', ts('State/Province'), $stateProvince);
     // select for country
     $country = array('' => ts('- any country -')) + CRM_Core_PseudoConstant::country();
     $this->addElement('select', 'country', ts('Country'), $country);
     // add text box for postal code
     $this->addElement('text', 'postal_code', ts('Postal Code'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address', 'postal_code'));
     $this->addElement('text', 'postal_code_low', ts('Range-From'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address', 'postal_code'));
     $this->addElement('text', 'postal_code_high', ts('To'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address', 'postal_code'));
     $this->addElement('text', 'location_name', ts('Location Name'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Location', 'name'));
     // checkboxes for DO NOT phone, email, mail
     // we take labels from SelectValues
     $t = CRM_Core_SelectValues::privacy();
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_phone', null, $t['do_not_phone']);
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_email', null, $t['do_not_email']);
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_mail', null, $t['do_not_mail']);
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_trade', null, $t['do_not_trade']);
     $this->addGroup($privacy, 'privacy', ts('Privacy'), '&nbsp;');
     // checkboxes for location type
     $location_type = array();
     $locationType = CRM_Core_PseudoConstant::locationType();
     foreach ($locationType as $locationTypeID => $locationTypeName) {
         $location_type[] = HTML_QuickForm::createElement('checkbox', $locationTypeID, null, $locationTypeName);
     }
     $this->addGroup($location_type, 'location_type', ts('Location Types'), '&nbsp;');
     // textbox for Activity Type
     $this->addElement('text', 'activity_type', ts('Activity Type'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_ActivityHistory', 'activity_type'));
     // Date selects for activity date
     $this->add('date', 'activity_date_from', ts('Activity Dates - From'), CRM_Core_SelectValues::date('relative'));
     $this->addRule('activity_date_from', ts('Select a valid date.'), 'qfDate');
     $this->add('date', 'activity_date_to', ts('To'), CRM_Core_SelectValues::date('relative'));
     $this->addRule('activity_date_to', ts('Select a valid date.'), 'qfDate');
     $this->assign('validCiviContribute', false);
     if (CRM_Utils_System::accessCiviContribute()) {
         $this->assign('validCiviContribute', true);
         require_once 'CRM/Contribute/Form/Search.php';
         CRM_Contribute_Form_Search::buildQuickFormCommon($this);
     }
     //Custom data Search Fields
     $this->customDataSearch();
     $this->buildQuickFormCommon();
 }
Exemple #15
0
 /**
  * Create communication preferences block for the contact.
  *
  * @param object $form - CRM_Core_Form (or it's subclass)
  * @return none
  *
  * @access public
  * @static
  */
 function buildCommunicationBlock(&$form)
 {
     // since the pcm - preferred comminication method is logically
     // grouped hence we'll use groups of HTML_QuickForm
     $privacy = array();
     // checkboxes for DO NOT phone, email, mail
     // we take labels from SelectValues
     $t = CRM_Core_SelectValues::privacy();
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_phone', null, $t['do_not_phone']);
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_email', null, $t['do_not_email']);
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_mail', null, $t['do_not_mail']);
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_trade', null, $t['do_not_trade']);
     $form->addGroup($privacy, 'privacy', ts('Privacy'), '&nbsp;');
     // preferred communication method
     $form->add('select', 'preferred_communication_method', ts('Prefers'), CRM_Core_SelectValues::pcm());
     $form->add('select', 'preferred_mail_format', ts('Mail Format'), CRM_Core_SelectValues::pmf());
 }
Exemple #16
0
 /**
  * View summary details of a contact
  *
  * @return void
  * @access public
  */
 function view()
 {
     $session =& CRM_Core_Session::singleton();
     $url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId);
     $session->pushUserContext($url);
     $params = array();
     $defaults = array();
     $ids = array();
     $params['id'] = $params['contact_id'] = $this->_contactId;
     $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, true);
     $communicationType = array('phone' => array('type' => 'phoneType', 'id' => 'phone_type'), 'im' => array('type' => 'IMProvider', 'id' => 'provider'), 'address' => array('skip' => true), 'email' => array('skip' => true), 'openid' => array('skip' => true));
     foreach ($communicationType as $key => $value) {
         if (CRM_Utils_Array::value($key, $defaults)) {
             foreach ($defaults[$key] as &$val) {
                 CRM_Utils_Array::lookupValue($val, 'location_type', CRM_Core_PseudoConstant::locationType(), false);
                 if (!CRM_Utils_Array::value('skip', $value)) {
                     eval('$pseudoConst = CRM_Core_PseudoConstant::' . $value['type'] . '( );');
                     CRM_Utils_Array::lookupValue($val, $value['id'], $pseudoConst, false);
                 }
             }
         }
     }
     if (CRM_Utils_Array::value('gender_id', $defaults)) {
         $gender = CRM_Core_PseudoConstant::gender();
         $defaults['gender_display'] = $gender[CRM_Utils_Array::value('gender_id', $defaults)];
     }
     if (CRM_Utils_Array::value('contact_sub_type', $defaults)) {
         $defaults['contact_sub_type'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_ContactType', $defaults['contact_sub_type'], 'label', 'name');
     }
     // get the list of all the categories
     $tag =& CRM_Core_PseudoConstant::tag();
     // get categories for the contact id
     require_once 'CRM/Core/BAO/EntityTag.php';
     $entityTag =& CRM_Core_BAO_EntityTag::getTag($this->_contactId);
     if ($entityTag) {
         $categories = array();
         foreach ($entityTag as $key) {
             $categories[] = $tag[$key];
         }
         $defaults['contactTag'] = implode(', ', $categories);
     }
     $defaults['privacy_values'] = CRM_Core_SelectValues::privacy();
     //Show blocks only if they are visible in edit form
     require_once 'CRM/Core/BAO/Preferences.php';
     $this->_editOptions = CRM_Core_BAO_Preferences::valueOptions('contact_edit_options');
     $configItems = array('CommBlock' => 'Communication Preferences', 'Demographics' => 'Demographics', 'TagsAndGroups' => 'Tags and Groups', 'Notes' => 'Notes');
     foreach ($configItems as $c => $t) {
         $varName = '_show' . $c;
         $this->{$varName} = CRM_Utils_Array::value($c, $this->_editOptions);
         $this->assign(substr($varName, 1), $this->{$varName});
     }
     //get the householdname
     if (isset($defaults['mail_to_household_id'])) {
         $HouseholdName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $defaults['mail_to_household_id'], 'display_name', 'id');
         $this->assign('HouseholdName', $HouseholdName);
     }
     //get the current employer name
     if (CRM_Utils_Array::value('contact_type', $defaults) == 'Individual') {
         require_once 'CRM/Contact/BAO/Relationship.php';
         $currentEmployer = CRM_Contact_BAO_Relationship::getCurrentEmployer(array($this->_contactId));
         $defaults['current_employer'] = $currentEmployer[$this->_contactId]['org_name'];
         $defaults['current_employer_id'] = $currentEmployer[$this->_contactId]['org_id'];
         //for birthdate format with respect to birth format set
         $this->assign('birthDateViewFormat', CRM_Utils_Array::value('qfMapping', CRM_Utils_Date::checkBirthDateFormat()));
     }
     $this->assign($defaults);
     // also assign the last modifed details
     require_once 'CRM/Core/BAO/Log.php';
     $lastModified =& CRM_Core_BAO_Log::lastModified($this->_contactId, 'civicrm_contact');
     $this->assign_by_ref('lastModified', $lastModified);
     $allTabs = array();
     $weight = 10;
     $this->_viewOptions = CRM_Core_BAO_Preferences::valueOptions('contact_view_options', true);
     $changeLog = $this->_viewOptions['log'];
     $this->assign_by_ref('changeLog', $changeLog);
     require_once 'CRM/Core/Component.php';
     $components = CRM_Core_Component::getEnabledComponents();
     foreach ($components as $name => $component) {
         if (CRM_Utils_Array::value($name, $this->_viewOptions) && CRM_Core_Permission::access($component->name)) {
             $elem = $component->registerTab();
             // FIXME: not very elegant, probably needs better approach
             // allow explicit id, if not defined, use keyword instead
             if (array_key_exists('id', $elem)) {
                 $i = $elem['id'];
             } else {
                 $i = $component->getKeyword();
             }
             $u = $elem['url'];
             //appending isTest to url for test soft credit CRM-3891.
             //FIXME: hack ajax url.
             $q = "reset=1&snippet=1&force=1&cid={$this->_contactId}";
             if (CRM_Utils_Request::retrieve('isTest', 'Positive', $this)) {
                 $q = $q . "&isTest=1";
             }
             $allTabs[] = array('id' => $i, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$u}", $q), 'title' => $elem['title'], 'weight' => $elem['weight'], 'count' => CRM_Contact_BAO_Contact::getCountComponent($u, $this->_contactId));
             // make sure to get maximum weight, rest of tabs go after
             // FIXME: not very elegant again
             if ($weight < $elem['weight']) {
                 $weight = $elem['weight'];
             }
         }
     }
     $rest = array('activity' => ts('Activities'), 'case' => ts('Cases'), 'rel' => ts('Relationships'), 'group' => ts('Groups'), 'note' => ts('Notes'), 'tag' => ts('Tags'), 'log' => ts('Change Log'));
     $config =& CRM_Core_Config::singleton();
     if (isset($config->sunlight) && $config->sunlight) {
         $title = ts('Elected Officials');
         $rest['sunlight'] = $title;
         $this->_viewOptions[$title] = true;
     }
     foreach ($rest as $k => $v) {
         if (CRM_Utils_Array::value($k, $this->_viewOptions)) {
             $allTabs[] = array('id' => $k, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$k}", "reset=1&snippet=1&cid={$this->_contactId}"), 'title' => $v, 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($k, $this->_contactId));
             $weight += 10;
         }
     }
     // now add all the custom tabs
     $activeGroups =& CRM_Core_BAO_CustomGroup::getActiveGroups(CRM_Contact_BAO_Contact::getContactType($this->_contactId), 'civicrm/contact/view/cd', $this->_contactId);
     foreach ($activeGroups as $group) {
         $id = "custom_{$group['id']}";
         $allTabs[] = array('id' => $id, 'url' => CRM_Utils_System::url($group['path'], $group['query'] . "&snippet=1&selectedChild={$id}"), 'title' => $group['title'], 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId));
         $weight += 10;
     }
     // see if any other modules want to add any tabs
     require_once 'CRM/Utils/Hook.php';
     CRM_Utils_Hook::tabs($allTabs, $this->_contactId);
     if ($config->civiHRD) {
         $hrdOrder = array('rel' => 1, 'case' => 2, 'activity' => 3, 'participant' => 4, 'grant' => 5, 'contribute' => 6, 'group' => 7, 'note' => 8, 'tag' => 9, 'log' => 10);
         foreach ($allTabs as $i => $tab) {
             if (array_key_exists($tab['id'], $hrdOrder)) {
                 $allTabs[$i]['weight'] = $hrdOrder[$tab['id']];
             }
         }
     }
     // now sort the tabs based on weight
     require_once 'CRM/Utils/Sort.php';
     usort($allTabs, array('CRM_Utils_Sort', 'cmpFunc'));
     $this->assign('allTabs', $allTabs);
     $selectedChild = CRM_Utils_Request::retrieve('selectedChild', 'String', $this, false, 'summary');
     $this->assign('selectedChild', $selectedChild);
     // hook for contact summary
     require_once 'CRM/Utils/Hook.php';
     $contentPlacement = CRM_Utils_Hook::SUMMARY_BELOW;
     // ignored but needed to prevent warnings
     CRM_Utils_Hook::summary($this->_contactId, $content, $contentPlacement);
     if ($content) {
         $this->assign_by_ref('hookContent', $content);
         $this->assign('hookContentPlacement', $contentPlacement);
     }
 }
Exemple #17
0
 /**
  * View summary details of a contact
  *
  * @return void
  * @access public
  */
 function view()
 {
     $params = array();
     $defaults = array();
     $ids = array();
     $params['id'] = $params['contact_id'] = $this->_contactId;
     $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, $ids);
     CRM_Contact_BAO_Contact::resolveDefaults($defaults);
     if (CRM_Utils_Array::value('gender_id', $defaults)) {
         $gender = CRM_Core_PseudoConstant::gender();
         $defaults['gender_display'] = $gender[CRM_Utils_Array::value('gender_id', $defaults)];
     }
     // get the list of all the categories
     $tag =& CRM_Core_PseudoConstant::tag();
     // get categories for the contact id
     require_once 'CRM/Core/BAO/EntityTag.php';
     $entityTag =& CRM_Core_BAO_EntityTag::getTag('civicrm_contact', $this->_contactId);
     if ($entityTag) {
         $categories = array();
         foreach ($entityTag as $key) {
             $categories[] = $tag[$key];
         }
         $defaults['contactTag'] = implode(', ', $categories);
     }
     $defaults['privacy_values'] = CRM_Core_SelectValues::privacy();
     $this->assign($defaults);
     $this->setShowHide($defaults);
     // get the contributions, new style of doing stuff
     // do the below only if the person has access to contributions
     $config =& CRM_Core_Config::singleton();
     if (CRM_Utils_System::accessCiviContribute()) {
         $this->assign('accessContribution', true);
         $controller =& new CRM_Core_Controller_Simple('CRM_Contribute_Form_Search', ts('Contributions'), $this->_action);
         $controller->setEmbedded(true);
         $controller->reset();
         $controller->set('limit', 3);
         $controller->set('force', 1);
         $controller->set('cid', $this->_contactId);
         $controller->set('context', 'basic');
         $controller->process();
         $controller->run();
     } else {
         $this->assign('accessContribution', false);
     }
     //add link to CMS user
     if ($uid = CRM_Core_BAO_UFMatch::getUFId($this->_contactId)) {
         if ($config->userFramework == 'Drupal') {
             $url = CRM_Utils_System::url('user/' . $uid);
         } else {
             //$url = CRM_Utils_System::url( 'option=com_users&task=editA&hidemainmenu=1&id=' . $uid );
             $url = $config->userFrameworkBaseURL . 'index2.php?option=com_users&task=editA&hidemainmenu=1&id=' . $uid;
         }
         $this->assign('url', $url);
     }
 }
 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  *
  * @return void
  */
 public function postProcess()
 {
     //get the submitted values in an array
     $params = $this->controller->exportValues($this->_name);
     $actionTypeOption = CRM_Utils_Array::value('actionTypeOption', $params, NULL);
     // If remove option has been selected set new privacy value to "false"
     $privacyValueNew = empty($actionTypeOption);
     // check if any privay option has been checked
     if (!empty($params['pref'])) {
         $privacyValues = $params['pref'];
         $count = 0;
         foreach ($this->_contactIds as $contact_id) {
             $contact = new CRM_Contact_BAO_Contact();
             $contact->id = $contact_id;
             foreach ($privacyValues as $privacy_key => $privacy_value) {
                 $contact->{$privacy_key} = $privacyValueNew;
             }
             $contact->save();
             $count++;
         }
         // Status message
         $privacyOptions = CRM_Core_SelectValues::privacy();
         $status = array();
         foreach ($privacyValues as $privacy_key => $privacy_value) {
             $label = $privacyOptions[$privacy_key];
             $status[] = $privacyValueNew ? ts("Added '%1'", array(1 => $label)) : ts("Removed '%1'", array(1 => $label));
         }
         $status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>';
         if ($count > 1) {
             $title = ts('%1 Contacts Updated', array(1 => $count));
         } else {
             $name = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contact_id, 'display_name');
             $title = ts('%1 Updated', array(1 => $name));
         }
         CRM_Core_Session::setStatus($status, $title, 'success');
     }
 }
 static function basic(&$form)
 {
     $form->addElement('hidden', 'hidden_basic', 1);
     if ($form->_searchOptions['contactType']) {
         // add checkboxes for contact type
         $contact_type = array();
         require_once 'CRM/Contact/BAO/ContactType.php';
         $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements();
         if ($contactTypes) {
             $form->add('select', 'contact_type', ts('Contact Type(s)'), $contactTypes, false, array('id' => 'contact_type', 'multiple' => 'multiple', 'title' => ts('- select -')));
         }
     }
     if ($form->_searchOptions['groups']) {
         // multiselect for groups
         if ($form->_group) {
             $form->add('select', 'group', ts('Groups'), $form->_group, false, array('id' => 'group', 'multiple' => 'multiple', 'title' => ts('- select -')));
         }
     }
     if ($form->_searchOptions['tags']) {
         // multiselect for categories
         require_once 'CRM/Core/BAO/Tag.php';
         $contactTags = CRM_Core_BAO_Tag::getTags();
         if ($contactTags) {
             $form->add('select', 'contact_tags', ts('Tags'), $contactTags, false, array('id' => 'contact_tags', 'multiple' => 'multiple', 'title' => ts('- select -')));
         }
         require_once 'CRM/Core/Form/Tag.php';
         require_once 'CRM/Core/BAO/Tag.php';
         $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact');
         CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', null, true);
     }
     // add text box for last name, first name, street name, city
     $form->addElement('text', 'sort_name', ts('Find...'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
     // add text box for last name, first name, street name, city
     $form->add('text', 'email', ts('Contact Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
     //added contact source
     $form->add('text', 'contact_source', ts('Contact Source'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'source'));
     //added job title
     $attributes['job_title']['size'] = 30;
     $form->addElement('text', 'job_title', ts('Job Title'), $attributes['job_title'], 'size="30"');
     $config =& CRM_Core_Config::singleton();
     if (CRM_Core_Permission::check('access deleted contacts') and $config->contactUndelete) {
         $form->add('checkbox', 'deleted_contacts', ts('Search in Trash (deleted contacts)'));
     }
     // add checkbox for cms users only
     $form->addYesNo('uf_user', ts('CMS User?'));
     // add search profiles
     require_once 'CRM/Core/BAO/UFGroup.php';
     // FIXME: This is probably a part of profiles - need to be
     // FIXME: eradicated from here when profiles are reworked.
     $types = array('Participant', 'Contribution', 'Membership');
     // get component profiles
     $componentProfiles = array();
     $componentProfiles = CRM_Core_BAO_UFGroup::getProfiles($types);
     $ufGroups =& CRM_Core_BAO_UFGroup::getModuleUFGroup('Search Profile', 1);
     $accessibleUfGroups = CRM_Core_Permission::ufGroup(CRM_Core_Permission::VIEW);
     $searchProfiles = array();
     foreach ($ufGroups as $key => $var) {
         if (!array_key_exists($key, $componentProfiles) && in_array($key, $accessibleUfGroups)) {
             $searchProfiles[$key] = $var['title'];
         }
     }
     $form->addElement('select', 'uf_group_id', ts('Search Views'), array('0' => ts('- default view -')) + $searchProfiles);
     require_once 'CRM/Contact/Form/Search.php';
     $componentModes =& CRM_Contact_Form_Search::getModeSelect();
     // unset contributions or participants if user does not have
     // permission on them
     if (!CRM_Core_Permission::access('CiviContribute')) {
         unset($componentModes['2']);
     }
     if (!CRM_Core_Permission::access('CiviEvent')) {
         unset($componentModes['3']);
     }
     if (!CRM_Core_Permission::check('view all activities')) {
         unset($componentModes['4']);
     }
     if (count($componentModes) > 1) {
         $form->addElement('select', 'component_mode', ts('Display Results As'), $componentModes);
     }
     // checkboxes for DO NOT phone, email, mail
     // we take labels from SelectValues
     $t = CRM_Core_SelectValues::privacy();
     $t['do_not_toggle'] = ts('Include contacts who have these privacy option(s).');
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_phone', null, $t['do_not_phone']);
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_email', null, $t['do_not_email']);
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_mail', null, $t['do_not_mail']);
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_sms', null, $t['do_not_sms']);
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_trade', null, $t['do_not_trade']);
     $privacy[] = HTML_QuickForm::createElement('advcheckbox', 'do_not_toggle', null, $t['do_not_toggle']);
     $form->addGroup($privacy, 'privacy', ts('Privacy'), array('&nbsp;', '&nbsp;', '&nbsp;', '<br/>'));
     // preferred communication method
     require_once 'CRM/Core/PseudoConstant.php';
     $comm = CRM_Core_PseudoConstant::pcm();
     $commPreff = array();
     foreach ($comm as $k => $v) {
         $commPreff[] = HTML_QuickForm::createElement('advcheckbox', $k, null, $v);
     }
     $onHold[] = HTML_QuickForm::createElement('advcheckbox', 'on_hold', null, ts(''));
     $form->addGroup($onHold, 'email_on_hold', ts('Email On Hold'));
     $form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Communication Method'));
     //CRM-6138 Preferred Language
     $langPreff = CRM_Core_PseudoConstant::languages();
     $form->add('select', 'preferred_language', ts('Preferred Language'), array('' => ts('- select language -')) + $langPreff);
 }