Exemplo n.º 1
0
 function __construct()
 {
     $this->_columns = array('civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('display_name' => array('title' => ts('Contact Name'), 'required' => true, 'no_repeat' => true), 'gender_id' => array('title' => ts('Gender'), 'default' => true), 'birth_date' => array('title' => ts('Birthdate'), 'default' => false), 'id' => array('no_display' => true, 'required' => true)), 'filters' => array('sort_name' => array('title' => ts('Contact Name')), 'contact_type' => array('title' => ts('Contact Type'), 'operatorType' => CRM_Report_Form::OP_SELECT, 'options' => array('' => ts('-select-'), 'Individual' => ts('Individual'), 'Organization' => ts('Organization'), 'Household' => ts('Household')), 'default' => 'Individual'), 'id' => array('title' => ts('Contact ID'), 'no_display' => true)), 'grouping' => 'contact-fields'), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('email' => array('title' => ts('Email'), 'no_repeat' => true)), 'grouping' => 'contact-fields'), 'civicrm_address' => array('dao' => 'CRM_Core_DAO_Address', 'grouping' => 'contact-fields', 'fields' => array('street_address' => array('default' => false), 'city' => array('default' => true), 'postal_code' => null, 'state_province_id' => array('title' => ts('State/Province')), 'country_id' => array('title' => ts('Country'), 'default' => false))), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('phone' => null), 'grouping' => 'contact-fields'), 'civicrm_activity' => array('dao' => 'CRM_Activity_DAO_Activity', 'fields' => array('id' => array('title' => ts('Activity ID'), 'no_display' => true, 'required' => true))), 'civicrm_case' => array('dao' => 'CRM_Case_DAO_Case', 'fields' => array('id' => array('title' => ts('Case ID'), 'required' => true), 'start_date' => array('title' => ts('Case Start'), 'required' => true), 'end_date' => array('title' => ts('Case End'), 'required' => true)), 'filters' => array('case_id_filter' => array('name' => 'id', 'title' => ts('Cases?'), 'operatorType' => CRM_Report_Form::OP_SELECT, 'options' => array(1 => ts('Exclude non-case'), 2 => ts('Exclude cases'), 3 => ts('Include Both')), 'default' => 3), 'start_date' => array('title' => ts('Case Start'), 'operatorType' => CRM_Report_Form::OP_DATE), 'end_date' => array('title' => ts('Case End'), 'operatorType' => CRM_Report_Form::OP_DATE))), 'civicrm_group' => array('dao' => 'CRM_Contact_DAO_Group', 'alias' => 'cgroup', 'filters' => array('gid' => array('name' => 'group_id', 'title' => ts('Group'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'group' => true, 'options' => CRM_Core_PseudoConstant::group()))));
     $open_case_val = CRM_Core_OptionGroup::getValue('activity_type', 'Open Case', 'name');
     $crmDAO =& CRM_Core_DAO::executeQuery("SELECT cg.table_name, cg.extends AS ext, cf.label, cf.column_name FROM civicrm_custom_group cg INNER JOIN civicrm_custom_field cf ON cg.id = cf.custom_group_id\nwhere (cg.extends='Contact' OR cg.extends='Individual' OR cg.extends_entity_column_value='{$open_case_val}') AND cg.is_active=1 AND cf.is_active=1 ORDER BY cg.table_name");
     $curTable = '';
     $curExt = '';
     $curFields = array();
     while ($crmDAO->fetch()) {
         if ($curTable == '') {
             $curTable = $crmDAO->table_name;
             $curExt = $crmDAO->ext;
         } elseif ($curTable != $crmDAO->table_name) {
             $this->_columns[$curTable] = array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => $curFields, 'ext' => $curExt);
             $curTable = $crmDAO->table_name;
             $curExt = $crmDAO->ext;
             $curFields = array();
         }
         $curFields[$crmDAO->column_name] = array('title' => $crmDAO->label);
     }
     if (!empty($curFields)) {
         $this->_columns[$curTable] = array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => $curFields, 'ext' => $curExt);
     }
     $this->_genders = CRM_Core_PseudoConstant::gender();
     parent::__construct();
 }
Exemplo n.º 2
0
 /**
  * This function provides the HTML form elements that are specific to the Individual Contact Type
  * 
  * @access public
  * @return None 
  */
 function buildQuickForm(&$form)
 {
     $form->applyFilter('__ALL__', 'trim');
     // prefix
     $form->addElement('select', 'prefix_id', ts('Prefix'), array('' => ts('- prefix -')) + CRM_Core_PseudoConstant::individualPrefix());
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Individual');
     // first_name
     $form->addElement('text', 'first_name', ts('First Name'), $attributes['first_name']);
     //middle_name
     $form->addElement('text', 'middle_name', ts('Middle Name'), $attributes['middle_name']);
     // last_name
     $form->addElement('text', 'last_name', ts('Last Name'), $attributes['last_name']);
     // suffix
     $form->addElement('select', 'suffix_id', ts('Suffix'), array('' => ts('- suffix -')) + CRM_Core_PseudoConstant::individualSuffix());
     // nick_name
     $form->addElement('text', 'nick_name', ts('Nick Name'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'nick_name'));
     // greeting type
     $form->addElement('select', 'greeting_type', ts('Greeting'), CRM_Core_SelectValues::greeting());
     // job title
     $form->addElement('text', 'job_title', ts('Job title'), $attributes['job_title']);
     // radio button for gender
     $genderOptions = array();
     $gender = CRM_Core_PseudoConstant::gender();
     foreach ($gender as $key => $var) {
         $genderOptions[$key] = HTML_QuickForm::createElement('radio', null, ts('Gender'), $var, $key);
     }
     $form->addGroup($genderOptions, 'gender_id', ts('Gender'));
     $form->addElement('checkbox', 'is_deceased', null, ts('Contact is deceased'));
     $form->addElement('date', 'birth_date', ts('Date of birth'), CRM_Core_SelectValues::date('birth'));
     $form->addRule('birth_date', ts('Select a valid date.'), 'qfDate');
     $form->addElement('text', 'home_URL', ts('Website'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'home_URL'));
     $form->addRule('home_URL', ts('Enter a valid Website.'), 'url');
     $config =& CRM_Core_Config::singleton();
     CRM_Core_ShowHideBlocks::links($this, 'demographics', '', '');
 }
/**
 * Create or update a contact (note you should always call this via civicrm_api() & never directly)
 *
 * @param  array   $params   input parameters
 *
 * Allowed @params array keys are:
 * {@getfields contact_create}
 *
 *
 * @example ContactCreate.php Example of Create Call
 *
 * @return array  API Result Array
 *
 * @static void
 * @access public
 */
function civicrm_api3_contact_create($params)
{
    $contactID = CRM_Utils_Array::value('contact_id', $params, CRM_Utils_Array::value('id', $params));
    $dupeCheck = CRM_Utils_Array::value('dupe_check', $params, FALSE);
    $values = _civicrm_api3_contact_check_params($params, $dupeCheck);
    if ($values) {
        return $values;
    }
    if (empty($contactID)) {
        // If we get here, we're ready to create a new contact
        if (($email = CRM_Utils_Array::value('email', $params)) && !is_array($params['email'])) {
            require_once 'CRM/Core/BAO/LocationType.php';
            $defLocType = CRM_Core_BAO_LocationType::getDefault();
            $params['email'] = array(1 => array('email' => $email, 'is_primary' => 1, 'location_type_id' => $defLocType->id ? $defLocType->id : 1));
        }
    }
    if (CRM_Utils_Array::value('home_url', $params)) {
        require_once 'CRM/Core/PseudoConstant.php';
        $websiteTypes = CRM_Core_PseudoConstant::websiteType();
        $params['website'] = array(1 => array('website_type_id' => key($websiteTypes), 'url' => $params['home_url']));
    }
    if (isset($params['suffix_id']) && !is_numeric($params['suffix_id'])) {
        $params['suffix_id'] = array_search($params['suffix_id'], CRM_Core_PseudoConstant::individualSuffix());
    }
    if (isset($params['prefix_id']) && !is_numeric($params['prefix_id'])) {
        $params['prefix_id'] = array_search($params['prefix_id'], CRM_Core_PseudoConstant::individualPrefix());
    }
    if (isset($params['gender_id']) && !is_numeric($params['gender_id'])) {
        $params['gender_id'] = array_search($params['gender_id'], CRM_Core_PseudoConstant::gender());
    }
    $error = _civicrm_api3_greeting_format_params($params);
    if (civicrm_error($error)) {
        return $error;
    }
    $values = array();
    $entityId = $contactID;
    if (!CRM_Utils_Array::value('contact_type', $params) && $entityId) {
        $params['contact_type'] = CRM_Contact_BAO_Contact::getContactType($entityId);
    }
    if (!isset($params['contact_sub_type']) && $entityId) {
        require_once 'CRM/Contact/BAO/Contact.php';
        $params['contact_sub_type'] = CRM_Contact_BAO_Contact::getContactSubType($entityId);
    }
    _civicrm_api3_custom_format_params($params, $values, $params['contact_type'], $entityId);
    $params = array_merge($params, $values);
    $contact = _civicrm_api3_contact_update($params, $contactID);
    if (is_a($contact, 'CRM_Core_Error')) {
        return civicrm_api3_create_error($contact->_errors[0]['message']);
    } else {
        $values = array();
        _civicrm_api3_object_to_array_unique_fields($contact, $values[$contact->id]);
    }
    return civicrm_api3_create_success($values, $params, 'Contact', 'create');
}
 /**
  * build the form elements for Demographics object
  *
  * @param CRM_Core_Form $form       reference to the form object
  *
  * @return void
  * @access public
  * @static
  */
 static function buildQuickForm(&$form)
 {
     // radio button for gender
     $genderOptions = array();
     $gender = CRM_Core_PseudoConstant::gender(TRUE);
     foreach ($gender as $key => $var) {
         $genderOptions[$key] = $form->createElement('radio', NULL, ts('Gender'), $var, $key, array('id' => "civicrm_gender_{$var}_{$key}"));
     }
     $form->addGroup($genderOptions, 'gender_id', ts('Gender'));
     $form->addDate('birth_date', ts('Date of birth'), FALSE, array('formatType' => 'birth'));
     $form->addElement('checkbox', 'is_deceased', NULL, ts('Contact is deceased'), array('onclick' => "showDeceasedDate()"));
     $form->addDate('deceased_date', ts('Deceased date'), FALSE, array('formatType' => 'birth'));
 }
Exemplo n.º 5
0
 /**
  * build the form elements for Demographics object
  *
  * @param CRM_Core_Form $form       reference to the form object
  *
  * @return void
  * @access public
  * @static
  */
 static function buildQuickForm(&$form)
 {
     // radio button for gender
     $genderOptions = array();
     $gender = CRM_Core_PseudoConstant::gender();
     foreach ($gender as $key => $var) {
         $genderOptions[$key] = HTML_QuickForm::createElement('radio', null, ts('Gender'), $var, $key);
     }
     $form->addGroup($genderOptions, 'gender_id', ts('Gender'));
     $form->addDate('birth_date', ts('Date of birth'), false, array('formatType' => 'birth'));
     $form->addElement('checkbox', 'is_deceased', null, ts('Contact is deceased'), array('onclick' => "showDeceasedDate()"));
     $form->addDate('deceased_date', ts('Deceased date'), false, array('formatType' => 'birth'));
 }
 /**
  * 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);
     if (CRM_Utils_Array::value('gender_id', $defaults)) {
         $gender = CRM_Core_PseudoConstant::gender();
         $defaults['gender_display'] = $gender[CRM_Utils_Array::value('gender_id', $defaults)];
     }
     $this->assign('contactId', $contactId);
     $this->assign($defaults);
     //for birthdate format with respect to birth format set
     $this->assign('birthDateViewFormat', CRM_Utils_Array::value('qfMapping', CRM_Utils_Date::checkBirthDateFormat()));
     // check logged in user permission
     CRM_Contact_Page_View::checkUserPermission($this, $contactId);
     // finally call parent
     parent::run();
 }
Exemplo n.º 7
0
 /**
  * build a form for the given UF group
  *
  * @param int           $id        the group id
  * @param CRM_Core_Form $form      the form element
  * @param string        $name      the name that we should store the fields as
  * @param array         $allFields reference to the array where all the fields are stored
  *
  * @return void
  * @static
  * @access public
  */
 function buildQuickForm($id, &$form, $name, &$allFields)
 {
     $fields =& CRM_Core_BAO_UFGroup::getFields($id, false, $action);
     foreach ($fields as $n => $fld) {
         if (!array_key_exists($n, $allFields)) {
             $allFields[$n] = $fld;
         }
     }
     $form->assign($name, $fields);
     foreach ($fields as $name => $field) {
         $required = $field['is_required'];
         if (substr($field['name'], 0, 14) === 'state_province') {
             $form->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required);
         } else {
             if (substr($field['name'], 0, 7) === 'country') {
                 $form->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required);
             } else {
                 if ($field['name'] === 'birth_date') {
                     $form->add('date', $field['name'], $field['title'], CRM_Core_SelectValues::date('birth'));
                 } else {
                     if ($field['name'] === 'gender') {
                         $genderOptions = array();
                         $gender = CRM_Core_PseudoConstant::gender();
                         foreach ($gender as $key => $var) {
                             $genderOptions[$key] = HTML_QuickForm::createElement('radio', null, ts('Gender'), $var, $key);
                         }
                         $form->addGroup($genderOptions, $field['name'], $field['title']);
                     } else {
                         if ($field['name'] === 'individual_prefix') {
                             $form->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix());
                         } else {
                             if ($field['name'] === 'individual_suffix') {
                                 $form->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix());
                             } else {
                                 if ($field['name'] === 'group') {
                                     require_once 'CRM/Contact/Form/GroupTag.php';
                                     CRM_Contact_Form_GroupTag::buildGroupTagBlock($form, 0, CRM_CONTACT_FORM_GROUPTAG_GROUP);
                                 } else {
                                     if ($field['name'] === 'tag') {
                                         require_once 'CRM/Contact/Form/GroupTag.php';
                                         CRM_Contact_Form_GroupTag::buildGroupTagBlock($form, 0, CRM_CONTACT_FORM_GROUPTAG_TAG);
                                     } else {
                                         if (substr($field['name'], 0, 6) === 'custom') {
                                             $customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name']);
                                             CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, $inactiveNeeded, false);
                                             if ($required) {
                                                 $form->addRule($name, ts('%1 is a required field.', array(1 => $field['title'])), 'required');
                                             }
                                         } else {
                                             $form->add('text', $name, $field['title'], $field['attributes'], $required);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if ($field['rule']) {
             $form->addRule($name, ts('Please enter a valid %1', array(1 => $field['title'])), $field['rule']);
         }
     }
 }
Exemplo n.º 8
0
 function __construct()
 {
     $this->_columns = array('civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('display_name' => array('title' => ts('Contact Name'), 'required' => true, 'no_repeat' => true)), 'grouping' => 'contact-fields', 'filters' => array('display_name' => array('title' => ts('Contact Name'), 'operator' => 'like'), 'gender_id' => array('title' => ts('Gender'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::gender()))), 'civicrm_address' => array('dao' => 'CRM_Core_DAO_Address', 'filters' => array('country_id' => array('title' => ts('Country'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::country()), 'state_province_id' => array('title' => ts('State/Province'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::stateProvince()))), 'civicrm_grant' => array('dao' => 'CRM_Grant_DAO_Grant', 'fields' => array('grant_type_id' => array('name' => 'grant_type_id', 'title' => ts('Grant Type')), 'status_id' => array('name' => 'status_id', 'title' => ts('Grant Status')), 'amount_requested' => array('name' => 'amount_requested', 'title' => ts('Amount Requested'), 'type' => CRM_Utils_Type::T_MONEY), 'amount_granted' => array('name' => 'amount_granted', 'title' => ts('Amount Granted')), 'application_received_date' => array('name' => 'application_received_date', 'title' => ts('Application Received Date'), 'default' => true), 'money_transfer_date' => array('name' => 'money_transfer_date', 'title' => ts('Money Transfer Date'), 'type' => CRM_Utils_Type::T_DATE), 'grant_due_date' => array('name' => 'grant_due_date', 'title' => ts('Grant Due Date'), 'type' => CRM_Utils_Type::T_DATE), 'rationale' => array('name' => 'rationale', 'title' => ts('Rationale')), 'grant_report_received' => array('name' => 'grant_report_received', 'title' => ts('Grant Report Received'))), 'filters' => array('grant_type' => array('name' => 'grant_type_id', 'title' => ts('Grant Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Grant_PseudoConstant::grantType()), 'status_id' => array('name' => 'status_id', 'title' => ts('Grant Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Grant_PseudoConstant::grantStatus()), 'amount_granted' => array('title' => ts('Amount Granted'), 'operatorType' => CRM_Report_Form::OP_INT), 'amount_requested' => array('title' => ts('Amount Requested'), 'operatorType' => CRM_Report_Form::OP_INT), 'application_received_date' => array('title' => ts('Application Received Date'), 'operatorType' => CRM_Report_Form::OP_DATE), 'money_transfer_date' => array('title' => ts('Money Transfer Date'), 'operatorType' => CRM_Report_Form::OP_DATE), 'grant_due_date' => array('title' => ts('Grant Due Date'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Report_Form::OP_DATE)), 'group_bys' => array('grant_type_id' => array('title' => ts('Grant Type')), 'status_id' => array('title' => ts('Grant Status')), 'amount_requested' => array('title' => ts('Amount Requested')), 'amount_granted' => array('title' => ts('Amount Granted')), 'application_received_date' => array('title' => ts('Application Received Date')), 'money_transfer_date' => array('title' => ts('Money Transfer Date')))));
     parent::__construct();
 }
Exemplo n.º 9
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;
     $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);
     }
 }
Exemplo n.º 10
0
 /**
  * Get all Gender.
  *
  * The static array gender is returned
  *
  * @access public
  * @static
  *
  * @param boolean $all - get All Gender - default is to get only active ones.
  *
  * @return array - array reference of all gender.
  *
  */
 public static function &gender()
 {
     if (!self::$gender) {
         require_once 'CRM/Core/OptionGroup.php';
         self::$gender = CRM_Core_OptionGroup::values('gender');
     }
     return self::$gender;
 }
Exemplo n.º 11
0
 static function demographics(&$form)
 {
     $form->add('hidden', 'hidden_demographics', 1);
     // radio button for gender
     $genderOptions = array();
     $gender = CRM_Core_PseudoConstant::gender();
     foreach ($gender as $key => $var) {
         $genderOptions[$key] = HTML_QuickForm::createElement('radio', null, ts('Gender'), $var, $key);
     }
     $form->addGroup($genderOptions, 'gender', ts('Gender'));
     $form->addDate('birth_date_low', ts('Birth Dates - From'), false, array('formatType' => 'searchDate'));
     $form->addDate('birth_date_high', ts('To'), false, array('formatType' => 'searchDate'));
     $form->addDate('deceased_date_low', ts('Deceased Dates - From'), false, array('formatType' => 'searchDate'));
     $form->addDate('deceased_date_high', ts('To'), false, array('formatType' => 'searchDate'));
 }
Exemplo n.º 12
0
 /** 
  * Given a list of conditions in params generate the required
  * where clause
  * 
  * @return void 
  * @access public 
  */
 function whereClause()
 {
     //CRM_Core_Error::debug( 'p', $this->_params );
     // domain id is always part of the where clause
     $config =& CRM_Core_Config::singleton();
     $this->_where[] = 'civicrm_contact.domain_id = ' . $config->domainID();
     // check for both id and contact_id
     $id = CRM_Utils_Array::value('id', $this->_params);
     if (!$id) {
         $id = CRM_Utils_Array::value('contact_id', $this->_params);
     }
     if ($id) {
         $this->_where[] = "civicrm_contact.id = {$id}";
     }
     $this->contactType();
     $this->sortName();
     $this->sortByCharacter();
     $this->locationTypeAndName();
     $this->group();
     $this->tag();
     $this->postalCode();
     $this->activity();
     $this->includeContactIds();
     $this->contribution();
     //CRM_Core_Error::debug( 'p', $this->_params );
     //CRM_Core_Error::debug( 'f', $this->_fields );
     foreach ($this->_fields as $name => $field) {
         if (empty($name) || in_array($name, $GLOBALS['_CRM_CONTACT_BAO_QUERY']['skipFields'])) {
             continue;
         }
         $value = CRM_Utils_Array::value($name, $this->_params);
         if (!isset($value) || $value == null) {
             continue;
         }
         if (CRM_Core_BAO_CustomField::getKeyID($name)) {
             continue;
         }
         //check if the location type exits for fields
         $lType = '';
         $locType = array();
         $locType = explode('-', $name);
         if (is_numeric($locType[1])) {
             $this->_params['location_type'] = array($locType[1] => 1);
             $lType = $this->locationTypeAndName(true);
         }
         //add phone type if exists
         if ($locType[2]) {
             $this->_where[] = "civicrm_phone.phone_type ='" . $locType[2] . "'";
         }
         // FIXME: the LOWER/strtolower pairs below most probably won't work
         // with non-US-ASCII characters, as even if MySQL does the proper
         // thing with LOWER-ing them (4.0 almost certainly won't, but then
         // we don't officially support 4.0 for non-US-ASCII data), PHP
         // won't do the proper thing with strtolower-ing them unless the
         // underlying operating system uses an UTF-8 locale for LC_CTYPE
         // for the user the webserver runs at (or suEXECs); we should use
         // mb_strtolower(), but then we'd require mb_strings support; we
         // could wrap this in function_exist(), though
         if (substr($name, 0, 14) === 'state_province') {
             $states =& CRM_Core_PseudoConstant::stateProvince();
             if (is_numeric($value)) {
                 $value = $states[(int) $value];
             }
             $this->_where[] = 'LOWER(' . $field['where'] . ') = "' . strtolower(addslashes($value)) . '"';
             if (!$lType) {
                 $this->_qill[] = ts('State - "%1"', array(1 => $value));
             } else {
                 $this->_qill[] = ts('State (%2) - "%1"', array(1 => $value, 2 => $lType));
             }
         } else {
             if (substr($name, 0, 7) === 'country') {
                 $countries =& CRM_Core_PseudoConstant::country();
                 if (is_numeric($value)) {
                     $value = $countries[(int) $value];
                 }
                 $this->_where[] = 'LOWER(' . $field['where'] . ') = "' . strtolower(addslashes($value)) . '"';
                 if (!$lType) {
                     $this->_qill[] = ts('Country - "%1"', array(1 => $value));
                 } else {
                     $this->_qill[] = ts('Country (%2) - "%1"', array(1 => $value, 2 => $lType));
                 }
             } else {
                 if ($name === 'individual_prefix') {
                     $individualPrefixs =& CRM_Core_PseudoConstant::individualPrefix();
                     if (is_numeric($value)) {
                         $value = $individualPrefixs[(int) $value];
                     }
                     $this->_where[] = 'LOWER(' . $field['where'] . ') = "' . strtolower(addslashes($value)) . '"';
                     $this->_qill[] = ts('Individual Prefix - "%1"', array(1 => $value));
                 } else {
                     if ($name === 'individual_suffix') {
                         $individualSuffixs =& CRM_Core_PseudoConstant::individualsuffix();
                         if (is_numeric($value)) {
                             $value = $individualSuffixs[(int) $value];
                         }
                         $this->_where[] = 'LOWER(' . $field['where'] . ') = "' . strtolower(addslashes($value)) . '"';
                         $this->_qill[] = ts('Individual Suffix - "%1"', array(1 => $value));
                     } else {
                         if ($name === 'gender') {
                             $genders =& CRM_Core_PseudoConstant::gender();
                             if (is_numeric($value)) {
                                 $value = $genders[(int) $value];
                             }
                             $this->_where[] = 'LOWER(' . $field['where'] . ') = "' . strtolower(addslashes($value)) . '"';
                             $this->_qill[] = ts('Gender - "%1"', array(1 => $value));
                         } else {
                             if ($name === 'birth_date') {
                                 $date = CRM_Utils_Date::format($value);
                                 if (!$date) {
                                     continue;
                                 }
                                 $this->_where[] = $field['where'] . " = {$date}";
                                 $date = CRM_Utils_Date::customFormat($value);
                                 $this->_qill[] = "{$field['title']} \"{$date}\"";
                             } else {
                                 if ($name === 'contact_id') {
                                     if (is_int($value)) {
                                         $this->_where[] = $field['where'] . " = {$value}";
                                         $this->_qill[] = ts('%1 is equal to %2', array(1 => $field['title'], 2 => $value));
                                     }
                                 } else {
                                     if ($name === 'name') {
                                         $this->_where[] = 'LOWER(' . $field['where'] . ') LIKE "%' . strtolower(addslashes($value)) . '%"';
                                         $this->_qill[] = ts('%1 like "%2"', array(1 => $field['title'], 2 => $value));
                                     } else {
                                         // sometime the value is an array, need to investigate and fix
                                         if (is_array($value)) {
                                             $value = $value[0];
                                         }
                                         if (!empty($field['where'])) {
                                             if ($this->_strict) {
                                                 $this->_where[] = 'LOWER(' . $field['where'] . ') = "' . strtolower(str_replace("\"", "", $value)) . '"';
                                                 $this->_qill[] = ts('%1 = "%2"', array(1 => $field['title'], 2 => $value));
                                             } else {
                                                 $this->_where[] = 'LOWER(' . $field['where'] . ') LIKE "%' . strtolower(addslashes($value)) . '%"';
                                                 $this->_qill[] = ts('%1 like "%2"', array(1 => $field['title'], 2 => $value));
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         list($tableName, $fieldName) = explode('.', $field['where'], 2);
         if (isset($tableName)) {
             $this->_tables[$tableName] = 1;
             $this->_whereTables[$tableName] = 1;
         }
         // CRM_Core_Error::debug( 'f', $field );
         // CRM_Core_Error::debug( $value, $this->_qill );
     }
     if ($this->_customQuery) {
         $this->_where = array_merge($this->_where, $this->_customQuery->_where);
         $this->_qill = array_merge($this->_qill, $this->_customQuery->_qill);
     }
     return implode(' AND ', $this->_where);
 }
Exemplo n.º 13
0
 /**
  * function to check if an error in Core( non-custom fields ) field
  *
  * @param String   $errorMessage   A string containing all the error-fields.
  *
  * @access public
  */
 function isErrorInCoreData($params, &$errorMessage)
 {
     foreach ($params as $key => $value) {
         if ($value) {
             switch ($key) {
                 case 'birth_date':
                     if (!CRM_Utils_Rule::date($value)) {
                         //return _crm_error('Birth Date');
                         CRM_Import_Parser_Contact::addToErrorMsg('Birth Date', $errorMessage);
                     }
                     break;
                 case 'gender':
                     if (!CRM_Import_Parser_Contact::in_value($value, CRM_Core_PseudoConstant::gender(true))) {
                         //return _crm_error('Invalid value for field  : Gender');
                         CRM_Import_Parser_Contact::addToErrorMsg('Gender', $errorMessage);
                     }
                     break;
                 case 'preferred_communication_method':
                     if (!array_key_exists(strtolower($value), array_change_key_case(CRM_Core_SelectValues::pcm(), CASE_LOWER))) {
                         //return _crm_error('Invalid value for field  : Preferred Communication Method');
                         CRM_Import_Parser_Contact::addToErrorMsg('Preferred Communication Method', $errorMessage);
                     }
                     break;
                 case 'preferred_mail_format':
                     if (!array_key_exists(strtolower($value), array_change_key_case(CRM_Core_SelectValues::pmf(), CASE_LOWER))) {
                         //return _crm_error('Invalid value for field  : Preferred Communication Method');
                         CRM_Import_Parser_Contact::addToErrorMsg('Preferred Mail Format', $errorMessage);
                     }
                     break;
                 case 'individual_prefix':
                     if (!CRM_Import_Parser_Contact::in_value($value, CRM_Core_PseudoConstant::individualPrefix(true))) {
                         //return _crm_error('Invalid value for field  : Individual Prefix');
                         CRM_Import_Parser_Contact::addToErrorMsg('Individual Prefix', $errorMessage);
                     }
                     break;
                 case 'individual_suffix':
                     if (!CRM_Import_Parser_Contact::in_value($value, CRM_Core_PseudoConstant::individualSuffix(true))) {
                         //return _crm_error('Invalid value for field  : Individual Suffix');
                         CRM_Import_Parser_Contact::addToErrorMsg('Individual Suffix', $errorMessage);
                     }
                     break;
                 case 'state_province':
                     if (!empty($value)) {
                         foreach ($value as $stateValue) {
                             if ($stateValue['state_province']) {
                                 if (CRM_Import_Parser_Contact::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvinceAbbreviation()) || CRM_Import_Parser_Contact::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvince())) {
                                     continue;
                                 } else {
                                     //return _crm_error('Invalid value for field  : State Province ');
                                     CRM_Import_Parser_Contact::addToErrorMsg('State Province', $errorMessage);
                                 }
                             }
                         }
                     }
                     break;
                 case 'country':
                     if (!empty($value)) {
                         foreach ($value as $stateValue) {
                             if ($stateValue['country']) {
                                 if (CRM_Import_Parser_Contact::in_value($stateValue['country'], CRM_Core_PseudoConstant::countryIsoCode()) || CRM_Import_Parser_Contact::in_value($stateValue['country'], CRM_Core_PseudoConstant::country())) {
                                     continue;
                                 } else {
                                     //return _crm_error('Invalid value for field  : Country');
                                     CRM_Import_Parser_Contact::addToErrorMsg('Country', $errorMessage);
                                 }
                             }
                         }
                     }
                     break;
                 case 'geo_code_1':
                     if (!empty($value)) {
                         foreach ($value as $codeValue) {
                             if ($codeValue['geo_code_1']) {
                                 if (CRM_Utils_Rule::numeric($codeValue['geo_code_1'])) {
                                     continue;
                                 } else {
                                     //return _crm_error('Invalid value for field  : geo_code_1');
                                     CRM_Import_Parser_Contact::addToErrorMsg('geo_code_1', $errorMessage);
                                 }
                             }
                         }
                     }
                     break;
                 case 'geo_code_2':
                     if (!empty($value)) {
                         foreach ($value as $codeValue) {
                             if ($codeValue['geo_code_2']) {
                                 if (CRM_Utils_Rule::numeric($codeValue['geo_code_2'])) {
                                     continue;
                                 } else {
                                     //return _crm_error('Invalid value for field  : geo_code_2');
                                     CRM_Import_Parser_Contact::addToErrorMsg('geo_code_2', $errorMessage);
                                 }
                             }
                         }
                     }
             }
         }
     }
     //return true;
 }
Exemplo n.º 14
0
 function restWhere(&$values)
 {
     list($name, $op, $value, $grouping, $wildcard) = $values;
     if (!CRM_Utils_Array::value($grouping, $this->_where)) {
         $this->_where[$grouping] = array();
     }
     $multipleFields = array('url');
     //check if the location type exits for fields
     $lType = '';
     $locType = array();
     $locType = explode('-', $name);
     if (!in_array($locType[0], $multipleFields)) {
         //add phone type if exists
         if (isset($locType[2]) && $locType[2]) {
             $locType[2] = CRM_Core_DAO::escapeString($locType[2]);
         }
     }
     $field = CRM_Utils_Array::value($name, $this->_fields);
     if (!$field) {
         $field = CRM_Utils_Array::value($locType[0], $this->_fields);
         if (!$field) {
             return;
         }
     }
     $setTables = TRUE;
     $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
     if (substr($name, 0, 14) === 'state_province') {
         if (isset($locType[1]) && is_numeric($locType[1])) {
             $setTables = FALSE;
             //get the location name
             $locationType = CRM_Core_PseudoConstant::locationType();
             list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
             $this->_whereTables[$tName] = $this->_tables[$tName];
             $where = "`{$tName}`.{$fldName}";
         } else {
             $where = $field['where'];
         }
         $wc = $op != 'LIKE' ? "LOWER({$where})" : $where;
         if (is_numeric($value)) {
             $where = str_replace('.name', '.id', $where);
             $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive');
             $states = CRM_Core_PseudoConstant::stateProvince();
             $value = $states[(int) $value];
         } else {
             $wc = $op != 'LIKE' ? "LOWER({$where})" : $where;
             $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         }
         if (!$lType) {
             $this->_qill[$grouping][] = ts('State') . " {$op} '{$value}'";
         } else {
             $this->_qill[$grouping][] = ts('State') . " ({$lType}) {$op} '{$value}'";
         }
     } elseif (substr($name, 0, 7) === 'country') {
         if (isset($locType[1]) && is_numeric($locType[1])) {
             $setTables = FALSE;
             //get the location name
             $locationType = CRM_Core_PseudoConstant::locationType();
             list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
             $this->_whereTables[$tName] = $this->_tables[$tName];
             $where = "`{$tName}`.{$fldName}";
         } else {
             $where = $field['where'];
         }
         if (is_numeric($value)) {
             $where = str_replace('.name', '.id', $where);
             $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive');
             $countries = CRM_Core_PseudoConstant::country();
             $value = $countries[(int) $value];
         } else {
             $wc = $op != 'LIKE' ? "LOWER({$where})" : $where;
             $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         }
         if (!$lType) {
             $this->_qill[$grouping][] = ts('Country') . " {$op} '{$value}'";
         } else {
             $this->_qill[$grouping][] = ts('Country') . " ({$lType}) {$op} '{$value}'";
         }
     } elseif (substr($name, 0, 6) === 'county') {
         if (isset($locType[1]) && is_numeric($locType[1])) {
             $setTables = FALSE;
             //get the location name
             $locationType = CRM_Core_PseudoConstant::locationType();
             list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
             $this->_whereTables[$tName] = $this->_tables[$tName];
             $where = "`{$tName}`.{$fldName}";
         } else {
             $where = $field['where'];
         }
         if (is_numeric($value)) {
             $where = str_replace('.name', '.id', $where);
             $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive');
             $counties = CRM_Core_PseudoConstant::county();
             $value = $counties[(int) $value];
         } else {
             $wc = $op != 'LIKE' ? "LOWER({$where})" : $where;
             $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         }
         if (!$lType) {
             $this->_qill[$grouping][] = ts('County') . " {$op} '{$value}'";
         } else {
             $this->_qill[$grouping][] = ts('County') . " ({$lType}) {$op} '{$value}'";
         }
     } elseif ($name === 'world_region') {
         $worldRegions = CRM_Core_PseudoConstant::worldRegion();
         if (is_numeric($value)) {
             $value = $worldRegions[(int) $value];
         }
         $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
         $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         $this->_qill[$grouping][] = ts('World Region') . " {$op} '{$value}'";
     } elseif ($name === 'individual_prefix') {
         $individualPrefixs = CRM_Core_PseudoConstant::individualPrefix();
         if (is_numeric($value)) {
             $value = $individualPrefixs[(int) $value];
         }
         $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
         $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         $this->_qill[$grouping][] = ts('Individual Prefix') . " {$op} '{$value}'";
     } elseif ($name === 'individual_suffix') {
         $individualSuffixs = CRM_Core_PseudoConstant::individualsuffix();
         if (is_numeric($value)) {
             $value = $individualSuffixs[(int) $value];
         }
         $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
         $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         $this->_qill[$grouping][] = ts('Individual Suffix') . " {$op} '{$value}'";
     } elseif ($name === 'gender') {
         $genders = CRM_Core_PseudoConstant::gender();
         if (is_numeric($value)) {
             $value = $genders[(int) $value];
         }
         $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
         $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         $this->_qill[$grouping][] = ts('Gender') . " {$op} '{$value}'";
         self::$_openedPanes['Demographics'] = TRUE;
     } elseif ($name === 'birth_date') {
         $date = CRM_Utils_Date::processDate($value);
         $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $date);
         if ($date) {
             $date = CRM_Utils_Date::customFormat($date);
             $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$date}\"";
         } else {
             $this->_qill[$grouping][] = "{$field['title']} {$op}";
         }
         self::$_openedPanes['Demographics'] = TRUE;
     } elseif ($name === 'deceased_date') {
         $date = CRM_Utils_Date::processDate($value);
         $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $date);
         if ($date) {
             $date = CRM_Utils_Date::customFormat($date);
             $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$date}\"";
         } else {
             $this->_qill[$grouping][] = "{$field['title']} {$op}";
         }
         self::$_openedPanes['Demographics'] = TRUE;
     } elseif ($name === 'is_deceased') {
         $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $value);
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
         self::$_openedPanes['Demographics'] = TRUE;
     } elseif ($name === 'contact_id') {
         if (is_int($value)) {
             $this->_where[$grouping][] = self::buildClause($field['where'], $op, $value);
             $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}";
         }
     } elseif ($name === 'name') {
         $value = $strtolower(CRM_Core_DAO::escapeString($value));
         if ($wildcard) {
             $value = "%{$value}%";
             $op = 'LIKE';
         }
         $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
         $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}'");
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
     } elseif ($name === 'current_employer') {
         $value = $strtolower(CRM_Core_DAO::escapeString($value));
         if ($wildcard) {
             $value = "%{$value}%";
             $op = 'LIKE';
         }
         $wc = $op != 'LIKE' ? "LOWER(contact_a.organization_name)" : "contact_a.organization_name";
         $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}' AND contact_a.contact_type ='Individual'");
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
     } elseif ($name === 'email_greeting') {
         $filterCondition = array('greeting_type' => 'email_greeting');
         $emailGreetings = CRM_Core_PseudoConstant::greeting($filterCondition);
         if (is_numeric($value)) {
             $value = $emailGreetings[(int) $value];
         }
         $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
         $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         $this->_qill[$grouping][] = ts('Email Greeting') . " {$op} '{$value}'";
     } elseif ($name === 'postal_greeting') {
         $filterCondition = array('greeting_type' => 'postal_greeting');
         $postalGreetings = CRM_Core_PseudoConstant::greeting($filterCondition);
         if (is_numeric($value)) {
             $value = $postalGreetings[(int) $value];
         }
         $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
         $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         $this->_qill[$grouping][] = ts('Postal Greeting') . " {$op} '{$value}'";
     } elseif ($name === 'addressee') {
         $filterCondition = array('greeting_type' => 'addressee');
         $addressee = CRM_Core_PseudoConstant::greeting($filterCondition);
         if (is_numeric($value)) {
             $value = $addressee[(int) $value];
         }
         $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
         $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         $this->_qill[$grouping][] = ts('Addressee') . " {$op} '{$value}'";
     } elseif (substr($name, 0, 4) === 'url-') {
         $tName = 'civicrm_website';
         $this->_whereTables[$tName] = $this->_tables[$tName] = "\nLEFT JOIN civicrm_website ON ( civicrm_website.contact_id = contact_a.id )";
         $value = $strtolower(CRM_Core_DAO::escapeString($value));
         if ($wildcard) {
             $value = "%{$value}%";
             $op = 'LIKE';
         }
         $wc = 'civicrm_website.url';
         $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}'");
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
     } elseif ($name === 'contact_is_deleted') {
         $this->_where[$grouping][] = self::buildClause("contact_a.is_deleted", $op, $value);
         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
     } else {
         // sometime the value is an array, need to investigate and fix
         if (is_array($value)) {
             CRM_Core_Error::fatal();
         }
         if (!empty($field['where'])) {
             if ($op != 'IN') {
                 $value = $strtolower(CRM_Core_DAO::escapeString($value));
             }
             if ($wildcard) {
                 $value = "'%{$value}%'";
                 $op = 'LIKE';
             }
             if (isset($locType[1]) && is_numeric($locType[1])) {
                 $setTables = FALSE;
                 //get the location name
                 $locationType = CRM_Core_PseudoConstant::locationType();
                 list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
                 $where = "`{$tName}`.{$fldName}";
                 $this->_where[$grouping][] = self::buildClause("LOWER({$where})", $op, $value);
                 $this->_whereTables[$tName] = $this->_tables[$tName];
                 $this->_qill[$grouping][] = "{$field['title']} {$op} '{$value}'";
             } else {
                 list($tableName, $fieldName) = explode('.', $field['where'], 2);
                 if ($tableName == 'civicrm_contact') {
                     $fieldName = "LOWER(contact_a.{$fieldName})";
                 } else {
                     if ($op != 'IN' && !is_numeric($value)) {
                         $fieldName = "LOWER({$field['where']})";
                     } else {
                         $fieldName = "{$field['where']}";
                     }
                 }
                 $type = NULL;
                 if (CRM_Utils_Array::value('type', $field)) {
                     $type = CRM_Utils_Type::typeToString($field['type']);
                 }
                 $this->_where[$grouping][] = self::buildClause($fieldName, $op, $value, $type);
                 $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}";
             }
         }
     }
     if ($setTables) {
         list($tableName, $fieldName) = explode('.', $field['where'], 2);
         if (isset($tableName)) {
             $this->_tables[$tableName] = 1;
             $this->_whereTables[$tableName] = 1;
         }
     }
 }
Exemplo n.º 15
0
 function executePrintmode($rows)
 {
     //only get these last contribution related variables in print mode if selected on previous form
     if (array_key_exists('civicrm_contribution_cont_receive_date', $rows[0])) {
         $receiveDate = ', date_received   DATE';
     }
     if (array_key_exists('civicrm_contribution_cont_total_amount', $rows[0])) {
         $contAmount = ' , total_amount    INT';
     }
     //  Separate out fields and build a temporary table
     $tempTable = "WalkList_" . uniqid();
     $sql = "CREATE TEMPORARY TABLE {$tempTable}" . " ( id              INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,\n                  street_name     VARCHAR(255),\n                  s_street_number VARCHAR(32),\n                  i_street_number INT,\n                  odd             TINYINT,\n                  apt_number      VARCHAR(32),\n                  city            VARCHAR(64),\n                  state           VARCHAR(32),\n                  zip             VARCHAR(32),\n                  name            VARCHAR(255),\n                  phone           VARCHAR(255),\n                  age             INT,\n                  sex             VARCHAR(16),\n                  lang            CHAR(2),\n                  party           CHAR(1),\n                  vh              CHAR(1),\n                  contact_type    VARCHAR(32),\n                  other_name      VARCHAR(128),\n                  contact_id      INT \n                  {$receiveDate} {$contAmount}\n                  )\n                 ENGINE=HEAP\n                 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci";
     CRM_Core_DAO::executeQuery($sql);
     $gender = CRM_Core_PseudoConstant::gender();
     foreach ($rows as $key => $value) {
         $dob = $value['civicrm_contact_birth_date'];
         $age = empty($dob) ? 0 : $this->dob2age($dob);
         $sex = $gender[CRM_Utils_Array::value('civicrm_contact_gender_id', $value)];
         $sex = is_null($sex) ? '' : $sex;
         $lang = strtoupper(substr($value[$this->_demoTable . '_' . $this->_demoLangCol], 0, 2));
         $party = substr($value["{$this->_voterInfoTable}_{$this->_partyCol}"], 0, 1);
         $vh = substr($value["{$this->_voterInfoTable}_{$this->_vhCol}"], 0, 1);
         $contactType = $value[$this->_coreInfoTable . '_' . $this->_coreTypeCol];
         $on = $value[$this->_coreInfoTable . '_' . $this->_coreOtherCol];
         $otherName = empty($on) ? 0 : "'{$on}'";
         $type = '';
         if (!empty($contactType)) {
             $type = $this->hexOne2str($contactType);
         }
         $contact_id = (int) $value['civicrm_contact_id'];
         $state = '';
         if (!empty($value['civicrm_address_state_province_id'])) {
             $state = CRM_Core_PseudoConstant::stateProvince($value['civicrm_address_state_province_id']);
         }
         $sStreetNumber = $value['civicrm_address_street_number'];
         $iStreetNumber = $value['civicrm_address_street_number'] ? (int) $value['civicrm_address_street_number'] : 0;
         $odd = $value['civicrm_address_street_number'] ? (int) $value['civicrm_address_street_number'] % 2 : 0;
         $apt_number = $value['civicrm_address_street_number'] ? $value['civicrm_address_street_number'] : '';
         $phone_number = $value['civicrm_phone_phone'] ? $value['civicrm_phone_phone'] : '';
         $query = "INSERT INTO {$tempTable} SET\n                       street_name     = %1,\n                       s_street_number = %2,\n                       i_street_number = %3,\n                       odd             = %4, \n                       apt_number      = %5,\n                       city            = %6,\n                       state           = %7,\n                       zip             = %8,\n                       name            = %9,\n                       phone           = %10,\n                       age             = %11,\n                       sex             = %12,\n                       lang            = %13,\n                       party           = %14,\n                       vh              = %15,\n                       contact_type    = %16,\n                       other_name      = %17,\n                       contact_id      = %18";
         $params = array(1 => array($value['civicrm_address_street_name'] ? $value['civicrm_address_street_name'] : '', 'String'), 2 => array((string) $sStreetNumber, 'String'), 3 => array($iStreetNumber, 'Integer'), 4 => array($odd, 'Integer'), 5 => array($apt_number, 'String'), 6 => array($value['civicrm_address_city'] ? $value['civicrm_address_city'] : '', 'String'), 7 => array($state, 'String'), 8 => array($value['civicrm_address_postal_code'] ? $value['civicrm_address_postal_code'] : '', 'String'), 9 => array($value['civicrm_contact_display_name'] ? $value['civicrm_contact_display_name'] : '', 'String'), 10 => array($phone_number, 'String'), 11 => array($age, 'Integer'), 12 => array($sex, 'String'), 13 => array($lang, 'String'), 14 => array($party, 'String'), 15 => array($vh, 'String'), 16 => array($type, 'String'), 17 => array($otherName, 'String'), 18 => array($contact_id, 'Integer'));
         if (!empty($contAmount)) {
             $query .= ",total_amount      = %19";
             $total_amount = $value['civicrm_contribution_cont_total_amount'] ? $value['civicrm_contribution_cont_total_amount'] : '';
             $params[19] = array($total_amount, 'String');
         }
         if (!empty($receiveDate)) {
             $query .= ",date_received      = %20";
             $date_received = $value['civicrm_contribution_cont_receive_date'] ? $value['civicrm_contribution_cont_receive_date'] : '';
             $params[20] = array($date_received, 'String');
         }
         CRM_Core_DAO::executeQuery($query, $params);
     }
     //  With the data normalized and in a table, we can
     //  retrieve it in the order we need to present it
     $query = "SELECT * FROM {$tempTable} ORDER BY state, city, zip,\n                  street_name, odd, i_street_number, apt_number";
     $dao = CRM_Core_DAO::executeQuery($query);
     //  Initialize output state
     $first = TRUE;
     $state = '';
     $city = '';
     $zip = '';
     $street_name = '';
     $odd = '';
     $pageRow = 0;
     $reportDate = date('F j, Y');
     $pdfRows = array();
     $groupRows = array();
     $groupCounts = 0;
     $pdfHeaders = array('s_street_number' => array('title' => 'STREET#'), 'apt_number' => array('title' => 'APT'), 'name' => array('title' => 'Name'), 'phone' => array('title' => 'PHONE'), 'age' => array('title' => 'AGE'), 'sex' => array('title' => 'SEX'), 'lang' => array('title' => 'Lang'), 'party' => array('title' => 'Party'), 'vh' => array('title' => 'VH'), 'contact_type' => array('title' => 'Constituent Type'), 'note' => array('title' => 'NOTES'), 'rcode' => array('title' => 'RESPONSE CODES'), 'status' => array('title' => 'STATUS'), 'contact_id' => array('title' => 'ID', 'class' => 'width=7%'));
     if (variable_get('civicrm_engage_groupbreak_street', "1") != 1) {
         $pdfHeaders['street_name']['title'] = 'Street';
     }
     if ($receiveDate) {
         $pdfHeaders['date_received'] = array('title' => 'Last donation Date');
     }
     if ($contAmount) {
         $pdfHeaders['total_amount'] = array('title' => 'Last donation');
     }
     $groupInfo = array('date' => $reportDate, 'descr' => empty($this->_groupDescr) ? '' : "<br>Group {$this->_groupDescr}");
     while ($dao->fetch()) {
         if (strtolower($state) != strtolower($dao->state) || variable_get('civicrm_engage_groupbreak_city', "1") == 1 && strtolower($city) != strtolower($dao->city) || variable_get('civicrm_engage_groupbreak_zip', "1") == 1 && strtolower($zip) != strtolower($dao->zip) || variable_get('civicrm_engage_groupbreak_street', "1") == 1 && strtolower($street_name) != strtolower($dao->street_name) || variable_get('civicrm_engage_groupbreak_odd_even', "1") == 1 && $odd != $dao->odd || $pageRow > variable_get('civicrm_engage_lines_per_group', "6") - 1) {
             $state = $dao->state;
             $city = $dao->city;
             $zip = $dao->zip;
             $street_name = $dao->street_name;
             $odd = $dao->odd;
             $pageRow = 0;
             unset($groupRow['city_zip']);
             $groupRow['org'] = $this->_orgName;
             if (variable_get('civicrm_engage_groupbreak_street', "1") == 1) {
                 $groupRow['street_name'] = $street_name;
             }
             if (variable_get('civicrm_engage_groupbreak_city', "1") == 1) {
                 $groupRow['city_zip'] .= $city . ', ';
             }
             $groupRow['city_zip'] .= $state;
             //don't give zip or odd-even if not grouped on
             if (variable_get('civicrm_engage_groupbreak_zip', "1") == 1) {
                 $groupRow['city_zip'] .= ' ' . $zip;
             }
             if (variable_get('civicrm_engage_groupbreak_odd_even', "1") == 1) {
                 $groupRow['odd'] = $odd ? 'Odd' : 'Even';
             }
             $groupCounts++;
             $groupRows[$groupCounts] = $groupRow;
         }
         // if admin settings have been defined to specify not to canvas people for a period change date to specified text
         if (variable_get('civicrm_engage_no_canvas_period', "0") > 0 && $dao->date_received > 0 && (strtotime("now") - strtotime($dao->date_received)) / 60 / 60 / 24 / 30 < variable_get('civicrm_engage_no_canvas_period', "0")) {
             $dao->date_received = variable_get('civicrm_engage_no_canvass_text', "Do Not Canvass");
         }
         $pdfRow = array();
         foreach ($pdfHeaders as $k => $v) {
             if (property_exists($dao, $k)) {
                 if ($k == 'name' && $dao->other_name) {
                     $pdfRow[$k] = $dao->{$k} . "<br />" . $dao->other_name;
                     continue;
                 }
                 $pdfRow[$k] = $dao->{$k};
             } else {
                 $pdfRow[$k] = "";
             }
         }
         $pdfRows[$groupCounts][] = $pdfRow;
         $pageRow++;
     }
     if (variable_get('civicrm_engage_group_per_page', "1")) {
         $this->assign('newgroupdiv', 'class="page"');
     }
     $this->assign('pageTotal', $groupCounts);
     $this->assign('pdfHeaders', $pdfHeaders);
     $this->assign('groupInfo', $groupInfo);
     $this->assign('pdfRows', $pdfRows);
     $this->assign('groupRows', $groupRows);
 }
Exemplo n.º 16
0
/**
 * This function adds the contact variable in $values to the
 * parameter list $params.  For most cases, $values should have length 1.  If
 * the variable being added is a child of Location, a location_type_id must
 * also be included.  If it is a child of phone, a phone_type must be included.
 *
 * @param array  $values    The variable(s) to be added
 * @param array  $params    The structured parameter list
 * 
 * @return bool|CRM_Utils_Error
 * @access public
 */
function _civicrm_add_formatted_param(&$values, &$params)
{
    /* Crawl through the possible classes: 
     * Contact 
     *      Individual 
     *      Household
     *      Organization
     *          Location 
     *              Address 
     *              Email 
     *              Phone 
     *              IM 
     *      Note
     *      Custom 
     */
    /* Cache the various object fields */
    static $fields = null;
    if ($fields == null) {
        $fields = array();
    }
    //first add core contact values since for other Civi modules they are not added
    require_once 'CRM/Contact/BAO/Contact.php';
    $contactFields =& CRM_Contact_DAO_Contact::fields();
    _civicrm_store_values($contactFields, $values, $params);
    if (isset($values['contact_type'])) {
        /* we're an individual/household/org property */
        $fields[$values['contact_type']] = CRM_Contact_DAO_Contact::fields();
        _civicrm_store_values($fields[$values['contact_type']], $values, $params);
        return true;
    }
    if (isset($values['individual_prefix'])) {
        if ($params['prefix_id']) {
            $prefixes = array();
            $prefixes = CRM_Core_PseudoConstant::individualPrefix();
            $params['prefix'] = $prefixes[$params['prefix_id']];
        } else {
            $params['prefix'] = $values['individual_prefix'];
        }
        return true;
    }
    if (isset($values['individual_suffix'])) {
        if ($params['suffix_id']) {
            $suffixes = array();
            $suffixes = CRM_Core_PseudoConstant::individualSuffix();
            $params['suffix'] = $suffixes[$params['suffix_id']];
        } else {
            $params['suffix'] = $values['individual_suffix'];
        }
        return true;
    }
    //CRM-4575
    if (isset($values['email_greeting'])) {
        if ($params['email_greeting_id']) {
            $emailGreetings = array();
            $emailGreetingFilter = array('contact_type' => CRM_Utils_Array::value('contact_type', $params), 'greeting_type' => 'email_greeting');
            $emailGreetings = CRM_Core_PseudoConstant::greeting($emailGreetingFilter);
            $params['email_greeting'] = $emailGreetings[$params['email_greeting_id']];
        } else {
            $params['email_greeting'] = $values['email_greeting'];
        }
        return true;
    }
    if (isset($values['postal_greeting'])) {
        if ($params['postal_greeting_id']) {
            $postalGreetings = array();
            $postalGreetingFilter = array('contact_type' => CRM_Utils_Array::value('contact_type', $params), 'greeting_type' => 'postal_greeting');
            $postalGreetings = CRM_Core_PseudoConstant::greeting($postalGreetingFilter);
            $params['postal_greeting'] = $postalGreetings[$params['postal_greeting_id']];
        } else {
            $params['postal_greeting'] = $values['postal_greeting'];
        }
        return true;
    }
    if (isset($values['addressee'])) {
        if ($params['addressee_id']) {
            $addressee = array();
            $addresseeFilter = array('contact_type' => CRM_Utils_Array::value('contact_type', $params), 'greeting_type' => 'addressee');
            $addressee = CRM_Core_PseudoConstant::addressee($addresseeFilter);
            $params['addressee'] = $addressee[$params['addressee_id']];
        } else {
            $params['addressee'] = $values['addressee'];
        }
        return true;
    }
    if (isset($values['gender'])) {
        if ($params['gender_id']) {
            $genders = array();
            $genders = CRM_Core_PseudoConstant::gender();
            $params['gender'] = $genders[$params['gender_id']];
        } else {
            $params['gender'] = $values['gender'];
        }
        return true;
    }
    if (isset($values['preferred_communication_method'])) {
        $comm = array();
        $preffComm = array();
        $pcm = array();
        $pcm = array_change_key_case(array_flip(CRM_Core_PseudoConstant::pcm()), CASE_LOWER);
        $preffComm = explode(',', $values['preferred_communication_method']);
        foreach ($preffComm as $v) {
            $v = strtolower(trim($v));
            if (array_key_exists($v, $pcm)) {
                $comm[$pcm[$v]] = 1;
            }
        }
        $params['preferred_communication_method'] = $comm;
        return true;
    }
    // get the formatted location blocks into params - w/ 3.0 format, CRM-4605
    if (CRM_Utils_Array::value('location_type_id', $values)) {
        _civicrm_add_formatted_location_blocks($values, $params);
        return true;
    }
    if (isset($values['note'])) {
        /* add a note field */
        if (!isset($params['note'])) {
            $params['note'] = array();
        }
        $noteBlock = count($params['note']) + 1;
        $params['note'][$noteBlock] = array();
        if (!isset($fields['Note'])) {
            $fields['Note'] = CRM_Core_DAO_Note::fields();
        }
        // get the current logged in civicrm user
        $session =& CRM_Core_Session::singleton();
        $userID = $session->get('userID');
        if ($userID) {
            $values['contact_id'] = $userID;
        }
        _civicrm_store_values($fields['Note'], $values, $params['note'][$noteBlock]);
        return true;
    }
    /* Check for custom field values */
    if ($fields['custom'] == null) {
        $fields['custom'] =& CRM_Core_BAO_CustomField::getFields($values['contact_type']);
    }
    foreach ($values as $key => $value) {
        if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
            /* check if it's a valid custom field id */
            if (!array_key_exists($customFieldID, $fields['custom'])) {
                return civicrm_create_error('Invalid custom field ID');
            } else {
                $params[$key] = $value;
            }
        }
    }
}
Exemplo n.º 17
0
 function alterDisplay(&$rows)
 {
     // custom code to alter rows
     $checkList = array();
     $entryFound = false;
     foreach ($rows as $rowNum => $row) {
         // convert employer name to links
         if (array_key_exists('civicrm_employer_organization_name', $row) && array_key_exists('civicrm_employer_id', $row)) {
             $url = CRM_Report_Utils_Report::getNextUrl('contact/detail', 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_employer_id'], $this->_absoluteUrl, $this->_id);
             $rows[$rowNum]['civicrm_employer_organization_name_link'] = $url;
             $entryFound = true;
         }
         if (!empty($this->_noRepeats) && $this->_outputMode != 'csv') {
             // not repeat contact display names if it matches with the one
             // in previous row
             foreach ($row as $colName => $colVal) {
                 if (is_array($checkList[$colName]) && in_array($colVal, $checkList[$colName])) {
                     $rows[$rowNum][$colName] = "";
                 }
                 if (in_array($colName, $this->_noRepeats)) {
                     $checkList[$colName][] = $colVal;
                 }
             }
         }
         //handle gender
         if (array_key_exists('civicrm_contact_gender_id', $row)) {
             if ($value = $row['civicrm_contact_gender_id']) {
                 $gender = CRM_Core_PseudoConstant::gender();
                 $rows[$rowNum]['civicrm_contact_gender_id'] = $gender[$value];
             }
             $entryFound = true;
         }
         // convert employee name to links
         if (array_key_exists('civicrm_contact_display_name', $row) && array_key_exists('civicrm_contact_id', $row)) {
             $url = CRM_Report_Utils_Report::getNextUrl('contact/detail', 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contact_id'], $this->_absoluteUrl, $this->_id);
             $rows[$rowNum]['civicrm_contact_display_name_link'] = $url;
             $entryFound = true;
         }
         // handle country
         if (array_key_exists('civicrm_address_country_id', $row)) {
             if ($value = $row['civicrm_address_country_id']) {
                 $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value, false);
             }
             $entryFound = true;
         }
         if (array_key_exists('civicrm_address_state_province_id', $row)) {
             if ($value = $row['civicrm_address_state_province_id']) {
                 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value, false);
             }
             $entryFound = true;
         }
         // skip looking further in rows, if first row itself doesn't
         // have the column we need
         if (!$entryFound) {
             break;
         }
     }
 }
Exemplo n.º 18
0
 /**
  * Function to build profile form
  *
  * @params object  $form       form object
  * @params array   $field      array field properties
  * @params int     $mode       profile mode
  * @params int     $contactID  contact id
  *
  * @return null
  * @static
  * @access public
  */
 static function buildProfile(&$form, &$field, $mode, $contactId = NULL, $online = FALSE, $onBehalf = FALSE, $rowNumber = NULL, $prefix = '')
 {
     $defaultValues = array();
     $fieldName = $field['name'];
     $title = $field['title'];
     $attributes = $field['attributes'];
     $rule = $field['rule'];
     $view = $field['is_view'];
     $required = $mode == CRM_Profile_Form::MODE_SEARCH ? FALSE : $field['is_required'];
     $search = $mode == CRM_Profile_Form::MODE_SEARCH ? TRUE : FALSE;
     $isShared = CRM_Utils_Array::value('is_shared', $field, 0);
     // do not display view fields in drupal registration form
     // CRM-4632
     if ($view && $mode == CRM_Profile_Form::MODE_REGISTER) {
         return;
     }
     if ($onBehalf) {
         $name = "onbehalf[{$fieldName}]";
     } elseif ($contactId && !$online) {
         $name = "field[{$contactId}][{$fieldName}]";
     } elseif ($rowNumber) {
         $name = "field[{$rowNumber}][{$fieldName}]";
     } elseif (!empty($prefix)) {
         $name = $prefix . "[{$fieldName}]";
     } else {
         $name = $fieldName;
     }
     if ($fieldName == 'image_URL' && $mode == CRM_Profile_Form::MODE_EDIT) {
         $deleteExtra = ts('Are you sure you want to delete contact image.');
         $deleteURL = array(CRM_Core_Action::DELETE => array('name' => ts('Delete Contact Image'), 'url' => 'civicrm/contact/image', 'qs' => 'reset=1&id=%%id%%&gid=%%gid%%&action=delete', 'extra' => 'onclick = "if (confirm( \'' . $deleteExtra . '\' ) ) this.href+=\'&amp;confirmed=1\'; else return false;"'));
         $deleteURL = CRM_Core_Action::formLink($deleteURL, CRM_Core_Action::DELETE, array('id' => $form->get('id'), 'gid' => $form->get('gid')));
         $form->assign('deleteURL', $deleteURL);
     }
     $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE);
     if (substr($fieldName, 0, 14) === 'state_province') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required);
     } elseif (substr($fieldName, 0, 7) === 'country') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required);
         $config = CRM_Core_Config::singleton();
         if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactCountry) {
             $defaultValues[$name] = $config->defaultContactCountry;
             $form->setDefaults($defaultValues);
         }
     } elseif (substr($fieldName, 0, 6) === 'county') {
         if ($addressOptions['county']) {
             $form->add('select', $name, $title, array('' => ts('- select state -')), $required);
         }
     } elseif (substr($fieldName, 0, 9) === 'image_URL') {
         $form->add('file', $name, $title, $attributes, $required);
         $form->addUploadElement($name);
     } elseif (substr($fieldName, 0, 2) === 'im') {
         $form->add('text', $name, $title, $attributes, $required);
         if (!$contactId) {
             if ($onBehalf) {
                 if (substr($name, -1) == ']') {
                     $providerName = substr($name, 0, -1) . '-provider_id]';
                 }
                 $form->add('select', $providerName, NULL, array('' => ts('- select -')) + CRM_Core_PseudoConstant::IMProvider(), $required);
             } else {
                 $form->add('select', $name . '-provider_id', $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::IMProvider(), $required);
             }
             if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) {
                 $form->freeze($name . '-provider_id');
             }
         }
     } elseif ($fieldName === 'birth_date' || $fieldName === 'deceased_date') {
         $form->addDate($name, $title, $required, array('formatType' => 'birth'));
     } elseif (in_array($fieldName, array('membership_start_date', 'membership_end_date', 'join_date'))) {
         $form->addDate($name, $title, $required, array('formatType' => 'custom'));
     } elseif ($field['name'] == 'membership_type') {
         list($orgInfo, $types) = CRM_Member_BAO_MembershipType::getMembershipTypeInfo();
         $sel =& $form->addElement('hierselect', $name, $title);
         $select = array('' => ts('- select -'));
         $sel->setOptions(array($select + $orgInfo, $types));
     } elseif ($field['name'] == 'membership_status') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'), $required);
     } elseif ($fieldName === 'gender') {
         $genderOptions = array();
         $gender = CRM_Core_PseudoConstant::gender();
         foreach ($gender as $key => $var) {
             $genderOptions[$key] = $form->createElement('radio', NULL, ts('Gender'), $var, $key);
         }
         $form->addGroup($genderOptions, $name, $title);
         if ($required) {
             $form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required');
         }
     } elseif ($fieldName === 'individual_prefix') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix(), $required);
     } elseif ($fieldName === 'individual_suffix') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix(), $required);
     } elseif ($fieldName === 'contact_sub_type') {
         $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $form->_fields[$fieldName]);
         if ($onBehalf) {
             $profileType = 'Organization';
         } else {
             $profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : NULL;
         }
         $setSubtype = FALSE;
         if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
             $setSubtype = $profileType;
             $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
         }
         $subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array();
         if ($setSubtype) {
             $subtypeList = array();
             $subtypeList[$setSubtype] = $subtypes[$setSubtype];
         } else {
             $subtypeList = $subtypes;
         }
         $sel = $form->add('select', $name, $title, $subtypeList, $required);
         $sel->setMultiple(TRUE);
     } elseif (in_array($fieldName, CRM_Contact_BAO_Contact::$_greetingTypes)) {
         //add email greeting, postal greeting, addressee, CRM-4575
         $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
         $profileType = CRM_Core_BAO_UFField::getProfileType($gId, TRUE, FALSE, TRUE);
         if (empty($profileType) || in_array($profileType, array('Contact', 'Contribution', 'Participant', 'Membership'))) {
             $profileType = 'Individual';
         }
         if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
             $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
         }
         $greeting = array('contact_type' => $profileType, 'greeting_type' => $fieldName);
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($greeting), $required);
         // add custom greeting element
         $form->add('text', $fieldName . '_custom', ts('Custom %1', array(1 => ucwords(str_replace('_', ' ', $fieldName)))), NULL, FALSE);
     } elseif ($fieldName === 'preferred_communication_method') {
         $communicationFields = CRM_Core_PseudoConstant::pcm();
         foreach ($communicationFields as $key => $var) {
             if ($key == '') {
                 continue;
             }
             $communicationOptions[] = $form->createElement('checkbox', $key, NULL, $var);
         }
         $form->addGroup($communicationOptions, $name, $title, '<br/>');
     } elseif ($fieldName === 'preferred_mail_format') {
         $form->add('select', $name, $title, CRM_Core_SelectValues::pmf());
     } elseif ($fieldName === 'preferred_language') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::languages());
     } elseif ($fieldName == 'external_identifier') {
         $form->add('text', $name, $title, $attributes, $required);
         $contID = $contactId;
         if (!$contID) {
             $contID = $form->get('id');
         }
         $form->addRule($name, ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $contID, 'external_identifier'));
     } elseif ($fieldName === 'group') {
         CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, TRUE, $required, $title, NULL, $name);
     } elseif ($fieldName === 'tag') {
         CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::TAG, FALSE, $required, NULL, $title, $name);
     } elseif (substr($fieldName, 0, 4) === 'url-') {
         $form->addElement('text', $name, $title, array_merge(CRM_Core_DAO::getAttribute('CRM_Core_DAO_Website', 'url'), array('onfocus' => "if (!this.value) {  this.value='http://';} else return false", 'onblur' => "if ( this.value == 'http://') {  this.value='';} else return false")));
         $form->addRule($name, ts('Enter a valid Website.'), 'url');
         //Website type select
         if ($onBehalf) {
             if (substr($name, -1) == ']') {
                 $websiteTypeName = substr($name, 0, -1) . '-website_type_id]';
             }
             $form->addElement('select', $websiteTypeName, NULL, CRM_Core_PseudoConstant::websiteType());
         } else {
             $form->addElement('select', $name . '-website_type_id', NULL, CRM_Core_PseudoConstant::websiteType());
         }
         // added because note appeared as a standard text input
     } elseif ($fieldName == 'note') {
         $form->add('textarea', $name, $title, $attributes, $required);
     } elseif (substr($fieldName, 0, 6) === 'custom') {
         $customFieldID = CRM_Core_BAO_CustomField::getKeyID($fieldName);
         if ($customFieldID) {
             CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title);
         }
     } elseif (substr($fieldName, 0, 14) === 'address_custom') {
         list($fName, $locTypeId) = CRM_Utils_System::explode('-', $fieldName, 2);
         $customFieldID = CRM_Core_BAO_CustomField::getKeyID(substr($fName, 8));
         if ($customFieldID) {
             CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title);
         }
     } elseif (in_array($fieldName, array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) {
         $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
     } elseif ($fieldName == 'send_receipt') {
         $form->addElement('checkbox', $name, $title);
     } elseif ($fieldName == 'soft_credit') {
         CRM_Contact_Form_NewContact::buildQuickForm($form, $rowNumber, NULL, FALSE, 'soft_credit_');
     } elseif ($fieldName == 'product_name') {
         list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo();
         $sel =& $form->addElement('hierselect', $name, $title);
         $products = array('0' => ts('- select -')) + $products;
         $sel->setOptions(array($products, $options));
     } elseif ($fieldName == 'payment_instrument') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required);
     } elseif ($fieldName == 'contribution_type') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType(), $required);
     } elseif ($fieldName == 'contribution_status_id') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionStatus(), $required);
     } elseif ($fieldName == 'currency') {
         $form->addCurrency($name, $title, $required);
     } elseif ($fieldName == 'contribution_page_id') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage(), $required, 'class="big"');
     } elseif ($fieldName == 'participant_register_date') {
         $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
     } elseif ($fieldName == 'activity_status_id') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::activityStatus(), $required);
     } elseif ($fieldName == 'activity_engagement_level') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Campaign_PseudoConstant::engagementLevel(), $required);
     } elseif ($fieldName == 'activity_date_time') {
         $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
     } elseif ($fieldName == 'participant_status') {
         $cond = NULL;
         if ($online == TRUE) {
             $cond = 'visibility_id = 1';
         }
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantStatus(NULL, $cond, 'label'), $required);
     } elseif ($fieldName == 'participant_role') {
         if (CRM_Utils_Array::value('is_multiple', $field)) {
             $form->addCheckBox($name, $title, CRM_Event_PseudoConstant::participantRole(), NULL, NULL, NULL, NULL, '&nbsp', TRUE);
         } else {
             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantRole(), $required);
         }
     } elseif ($fieldName == 'scholarship_type_id') {
         $form->add('select', $name, $title, array('' => '-- Select -- ') + array_flip(CRM_Core_OptionGroup::values('scholarship_type', TRUE)));
     } elseif ($fieldName == 'applicant_status_id') {
         $form->add('select', $name, $title, array('' => '-- Select -- ') + array_flip(CRM_Core_OptionGroup::values('applicant_status', TRUE)));
     } elseif ($fieldName == 'highschool_gpa_id') {
         $form->add('select', $name, $title, array('' => '-- Select -- ') + CRM_Core_OptionGroup::values('highschool_gpa'));
     } elseif ($fieldName == 'world_region') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::worldRegion(), $required);
     } elseif ($fieldName == 'signature_html') {
         $form->addWysiwyg($name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName));
     } elseif ($fieldName == 'signature_text') {
         $form->add('textarea', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName));
     } elseif (substr($fieldName, -11) == 'campaign_id') {
         if (CRM_Campaign_BAO_Campaign::isCampaignEnable()) {
             $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(CRM_Utils_Array::value($contactId, $form->_componentCampaigns));
             $campaign =& $form->add('select', $name, $title, array('' => ts('- select -')) + $campaigns, $required, 'class="big"');
         }
     } elseif ($fieldName == 'activity_details') {
         $form->addWysiwyg($fieldName, $title, array('rows' => 4, 'cols' => 60), $required);
     } elseif ($fieldName == 'activity_duration') {
         $form->add('text', $fieldName, $title, $attributes, $required);
         $form->addRule($name, ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger');
     } else {
         $processed = FALSE;
         if (CRM_Core_Permission::access('Quest', FALSE)) {
             $processed = CRM_Quest_BAO_Student::buildStudentForm($form, $fieldName, $title, $contactId);
         }
         if (!$processed) {
             if (substr($fieldName, 0, 3) === 'is_' or substr($fieldName, 0, 7) === 'do_not_') {
                 $form->add('advcheckbox', $name, $title, $attributes, $required);
             } else {
                 $form->add('text', $name, $title, $attributes, $required);
             }
         }
     }
     static $hiddenSubtype = FALSE;
     if (!$hiddenSubtype && CRM_Contact_BAO_ContactType::isaSubType($field['field_type'])) {
         // In registration mode params are submitted via POST and we don't have any clue
         // about profile-id or the profile-type (which could be a subtype)
         // To generalize the  behavior and simplify the process,
         // lets always add the hidden
         //subtype value if there is any, and we won't have to
         // compute it while processing.
         if ($onBehalf) {
             $form->addElement('hidden', 'onbehalf[contact_sub_type]', $field['field_type']);
         } else {
             $form->addElement('hidden', 'contact_sub_type_hidden', $field['field_type']);
         }
         $hiddenSubtype = TRUE;
     }
     if ($view && $mode != CRM_Profile_Form::MODE_SEARCH || $isShared) {
         $form->freeze($name);
     }
     //add the rules
     if (in_array($fieldName, array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) {
         $form->addRule($name, ts('Please enter a valid amount.'), 'money');
     }
     if ($rule) {
         if (!($rule == 'email' && $mode == CRM_Profile_Form::MODE_SEARCH)) {
             $form->addRule($name, ts('Please enter a valid %1', array(1 => $title)), $rule);
         }
     }
 }
Exemplo n.º 19
0
 static function demographics(&$form)
 {
     $form->add('hidden', 'hidden_demographics', 1);
     // radio button for gender
     $genderOptions = array();
     $gender = CRM_Core_PseudoConstant::gender();
     foreach ($gender as $key => $var) {
         $genderOptions[$key] = $form->createElement('radio', NULL, ts('Gender'), $var, $key, array('id' => "civicrm_gender_{$var}_{$key}"));
     }
     $form->addGroup($genderOptions, 'gender', ts('Gender'));
     CRM_Core_Form_Date::buildDateRange($form, 'birth_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth');
     CRM_Core_Form_Date::buildDateRange($form, 'deceased_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth');
     // radio button for is_deceased
     $deceasedOptions = array();
     $deceasedOptions[1] = $form->createElement('radio', NULL, ts('Deceased'), 'Yes', 1);
     $deceasedOptions[0] = $form->createElement('radio', NULL, ts('Deceased'), 'No', 0);
     $form->addGroup($deceasedOptions, 'is_deceased', ts('Deceased'));
 }
Exemplo n.º 20
0
 /**
  * Function to get the list the export fields
  *
  * @param int    $selectAll user preference while export
  * @param array  $ids  contact ids
  * @param array  $params associated array of fields
  * @param string $order order by clause
  * @param array  $associated array of fields
  * @param array  $moreReturnProperties additional return fields
  * @param int    $exportMode export mode
  * @param string $componentClause component clause
  *
  * @static
  * @access public
  */
 static function exportComponents($selectAll, $ids, $params, $order = null, $fields = null, $moreReturnProperties = null, $exportMode = CRM_Export_Form_Select::CONTACT_EXPORT, $componentClause = null)
 {
     $headerRows = array();
     $primary = false;
     $returnProperties = array();
     $origFields = $fields;
     $queryMode = null;
     $paymentFields = false;
     $phoneTypes = CRM_Core_PseudoConstant::phoneType();
     $imProviders = CRM_Core_PseudoConstant::IMProvider();
     $contactRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, null, null, null, true, 'label', false);
     $queryMode = CRM_Contact_BAO_Query::MODE_CONTACTS;
     switch ($exportMode) {
         case CRM_Export_Form_Select::CONTRIBUTE_EXPORT:
             $queryMode = CRM_Contact_BAO_Query::MODE_CONTRIBUTE;
             break;
         case CRM_Export_Form_Select::EVENT_EXPORT:
             $queryMode = CRM_Contact_BAO_Query::MODE_EVENT;
             break;
         case CRM_Export_Form_Select::MEMBER_EXPORT:
             $queryMode = CRM_Contact_BAO_Query::MODE_MEMBER;
             break;
         case CRM_Export_Form_Select::PLEDGE_EXPORT:
             $queryMode = CRM_Contact_BAO_Query::MODE_PLEDGE;
             break;
         case CRM_Export_Form_Select::CASE_EXPORT:
             $queryMode = CRM_Contact_BAO_Query::MODE_CASE;
             break;
     }
     require_once 'CRM/Core/BAO/CustomField.php';
     if ($fields) {
         //construct return properties
         $locationTypes =& CRM_Core_PseudoConstant::locationType();
         $locationTypeFields = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'geo_code_1', 'geo_code_2', 'state_province', 'country', 'phone', 'email', 'im');
         foreach ($fields as $key => $value) {
             $phoneTypeId = null;
             $imProviderId = null;
             $relationshipTypes = $fieldName = CRM_Utils_Array::value(1, $value);
             if (!$fieldName) {
                 continue;
             }
             // get phoneType id and IM service provider id seperately
             if ($fieldName == 'phone') {
                 $phoneTypeId = CRM_Utils_Array::value(3, $value);
             } else {
                 if ($fieldName == 'im') {
                     $imProviderId = CRM_Utils_Array::value(3, $value);
                 }
             }
             if (array_key_exists($relationshipTypes, $contactRelationshipTypes)) {
                 if (CRM_Utils_Array::value(2, $value)) {
                     $relationField = CRM_Utils_Array::value(2, $value);
                     if (trim(CRM_Utils_Array::value(3, $value))) {
                         $relLocTypeId = CRM_Utils_Array::value(3, $value);
                     } else {
                         $relLocTypeId = 1;
                     }
                     if ($relationField == 'phone') {
                         $relPhoneTypeId = CRM_Utils_Array::value(4, $value);
                     } else {
                         if ($relationField == 'im') {
                             $relIMProviderId = CRM_Utils_Array::value(4, $value);
                         }
                     }
                 } else {
                     if (CRM_Utils_Array::value(4, $value)) {
                         $relationField = CRM_Utils_Array::value(4, $value);
                         $relLocTypeId = CRM_Utils_Array::value(5, $value);
                         if ($relationField == 'phone') {
                             $relPhoneTypeId = CRM_Utils_Array::value(6, $value);
                         } else {
                             if ($relationField == 'im') {
                                 $relIMProviderId = CRM_Utils_Array::value(6, $value);
                             }
                         }
                     }
                 }
             }
             $contactType = CRM_Utils_Array::value(0, $value);
             $locTypeId = CRM_Utils_Array::value(2, $value);
             $phoneTypeId = CRM_Utils_Array::value(3, $value);
             if ($relationField) {
                 if (in_array($relationField, $locationTypeFields)) {
                     if ($relPhoneTypeId) {
                         $returnProperties[$relationshipTypes]['location'][$locationTypes[$relLocTypeId]]['phone-' . $relPhoneTypeId] = 1;
                     } else {
                         if ($relIMProviderId) {
                             $returnProperties[$relationshipTypes]['location'][$locationTypes[$relLocTypeId]]['im-' . $relIMProviderId] = 1;
                         } else {
                             $returnProperties[$relationshipTypes]['location'][$locationTypes[$relLocTypeId]][$relationField] = 1;
                         }
                     }
                     $relPhoneTypeId = $relIMProviderId = null;
                 } else {
                     $returnProperties[$relationshipTypes][$relationField] = 1;
                 }
             } else {
                 if (is_numeric($locTypeId)) {
                     if ($phoneTypeId) {
                         $returnProperties['location'][$locationTypes[$locTypeId]]['phone-' . $phoneTypeId] = 1;
                     } else {
                         if (isset($imProviderId)) {
                             //build returnProperties for IM service provider
                             $returnProperties['location'][$locationTypes[$locTypeId]]['im-' . $imProviderId] = 1;
                         } else {
                             $returnProperties['location'][$locationTypes[$locTypeId]][$fieldName] = 1;
                         }
                     }
                 } else {
                     //hack to fix component fields
                     if ($fieldName == 'event_id') {
                         $returnProperties['event_title'] = 1;
                     } else {
                         $returnProperties[$fieldName] = 1;
                     }
                 }
             }
         }
         // hack to add default returnproperty based on export mode
         if ($exportMode == CRM_Export_Form_Select::CONTRIBUTE_EXPORT) {
             $returnProperties['contribution_id'] = 1;
         } else {
             if ($exportMode == CRM_Export_Form_Select::EVENT_EXPORT) {
                 $returnProperties['participant_id'] = 1;
             } else {
                 if ($exportMode == CRM_Export_Form_Select::MEMBER_EXPORT) {
                     $returnProperties['membership_id'] = 1;
                 } else {
                     if ($exportMode == CRM_Export_Form_Select::PLEDGE_EXPORT) {
                         $returnProperties['pledge_id'] = 1;
                     } else {
                         if ($exportMode == CRM_Export_Form_Select::CASE_EXPORT) {
                             $returnProperties['case_id'] = 1;
                         }
                     }
                 }
             }
         }
     } else {
         $primary = true;
         $fields = CRM_Contact_BAO_Contact::exportableFields('All', true, true);
         foreach ($fields as $key => $var) {
             if ($key && substr($key, 0, 6) != 'custom') {
                 //for CRM=952
                 $returnProperties[$key] = 1;
             }
         }
         if ($primary) {
             $returnProperties['location_type'] = 1;
             $returnProperties['im_provider'] = 1;
             $returnProperties['phone_type_id'] = 1;
             $returnProperties['provider_id'] = 1;
             $returnProperties['current_employer'] = 1;
         }
         $extraReturnProperties = array();
         $paymentFields = false;
         switch ($queryMode) {
             case CRM_Contact_BAO_Query::MODE_EVENT:
                 $paymentFields = true;
                 $paymentTableId = "participant_id";
                 break;
             case CRM_Contact_BAO_Query::MODE_MEMBER:
                 $paymentFields = true;
                 $paymentTableId = "membership_id";
                 break;
             case CRM_Contact_BAO_Query::MODE_PLEDGE:
                 require_once 'CRM/Pledge/BAO/Query.php';
                 $extraReturnProperties = CRM_Pledge_BAO_Query::extraReturnProperties($queryMode);
                 $paymentFields = true;
                 $paymentTableId = "pledge_payment_id";
                 break;
             case CRM_Contact_BAO_Query::MODE_CASE:
                 require_once 'CRM/Case/BAO/Query.php';
                 $extraReturnProperties = CRM_Case_BAO_Query::extraReturnProperties($queryMode);
                 break;
         }
         if ($queryMode != CRM_Contact_BAO_Query::MODE_CONTACTS) {
             $componentReturnProperties =& CRM_Contact_BAO_Query::defaultReturnProperties($queryMode);
             $returnProperties = array_merge($returnProperties, $componentReturnProperties);
             if (!empty($extraReturnProperties)) {
                 $returnProperties = array_merge($returnProperties, $extraReturnProperties);
             }
             // unset groups, tags, notes for components
             foreach (array('groups', 'tags', 'notes') as $value) {
                 unset($returnProperties[$value]);
             }
         }
     }
     if ($moreReturnProperties) {
         $returnProperties = array_merge($returnProperties, $moreReturnProperties);
     }
     $query =& new CRM_Contact_BAO_Query(0, $returnProperties, null, false, false, $queryMode);
     list($select, $from, $where) = $query->query();
     // make sure the groups stuff is included only if specifically specified
     // by the fields param (CRM-1969), else we limit the contacts outputted to only
     // ones that are part of a group
     if (CRM_Utils_Array::value('groups', $returnProperties)) {
         $oldClause = "contact_a.id = civicrm_group_contact.contact_id";
         $newClause = " ( {$oldClause} AND civicrm_group_contact.status = 'Added' OR civicrm_group_contact.status IS NULL ) ";
         // total hack for export, CRM-3618
         $from = str_replace($oldClause, $newClause, $from);
     }
     if ($componentClause) {
         if (empty($where)) {
             $where = "WHERE {$componentClause}";
         } else {
             $where .= " AND {$componentClause}";
         }
     }
     $queryString = "{$select} {$from} {$where}";
     if (CRM_Utils_Array::value('tags', $returnProperties) || CRM_Utils_Array::value('groups', $returnProperties) || CRM_Utils_Array::value('notes', $returnProperties) || $query->_useGroupBy) {
         $queryString .= " GROUP BY contact_a.id";
     }
     if ($order) {
         list($field, $dir) = explode(' ', $order, 2);
         $field = trim($field);
         if (CRM_Utils_Array::value($field, $returnProperties)) {
             $queryString .= " ORDER BY {$order}";
         }
     }
     //hack for student data
     require_once 'CRM/Core/OptionGroup.php';
     $multipleSelectFields = array('preferred_communication_method' => 1);
     if (CRM_Core_Permission::access('Quest')) {
         require_once 'CRM/Quest/BAO/Student.php';
         $studentFields = array();
         $studentFields = CRM_Quest_BAO_Student::$multipleSelectFields;
         $multipleSelectFields = array_merge($multipleSelectFields, $studentFields);
     }
     $dao =& CRM_Core_DAO::executeQuery($queryString, CRM_Core_DAO::$_nullArray);
     $header = false;
     $addPaymentHeader = false;
     if ($paymentFields) {
         $addPaymentHeader = true;
         //special return properties for event and members
         $paymentHeaders = array(ts('Total Amount'), ts('Contribution Status'), ts('Received Date'), ts('Payment Instrument'), ts('Transaction ID'));
         // get payment related in for event and members
         require_once 'CRM/Contribute/BAO/Contribution.php';
         $paymentDetails = CRM_Contribute_BAO_Contribution::getContributionDetails($exportMode, $ids);
     }
     $componentDetails = $headerRows = array();
     $setHeader = true;
     while ($dao->fetch()) {
         $row = array();
         //first loop through returnproperties so that we return what is required, and in same order.
         $relationshipField = 0;
         foreach ($returnProperties as $field => $value) {
             //we should set header only once
             if ($setHeader) {
                 if (isset($query->_fields[$field]['title'])) {
                     $headerRows[] = $query->_fields[$field]['title'];
                 } else {
                     if ($field == 'phone_type_id') {
                         $headerRows[] = 'Phone Type';
                     } else {
                         if ($field == 'provider_id') {
                             $headerRows[] = 'Im Service Provider';
                         } else {
                             if (is_array($value) && $field == 'location') {
                                 // fix header for location type case
                                 foreach ($value as $ltype => $val) {
                                     foreach (array_keys($val) as $fld) {
                                         $type = explode('-', $fld);
                                         $hdr = "{$ltype}-" . $query->_fields[$type[0]]['title'];
                                         if (CRM_Utils_Array::value(1, $type)) {
                                             if (CRM_Utils_Array::value(0, $type) == 'phone') {
                                                 $hdr .= "-" . CRM_Utils_Array::value($type[1], $phoneTypes);
                                             } else {
                                                 if (CRM_Utils_Array::value(0, $type) == 'im') {
                                                     $hdr .= "-" . CRM_Utils_Array::value($type[1], $imProviders);
                                                 }
                                             }
                                         }
                                         $headerRows[] = $hdr;
                                     }
                                 }
                             } else {
                                 if (substr($field, 0, 5) == 'case_') {
                                     if ($query->_fields['case'][$field]['title']) {
                                         $headerRows[] = $query->_fields['case'][$field]['title'];
                                     } else {
                                         if ($query->_fields['activity'][$field]['title']) {
                                             $headerRows[] = $query->_fields['activity'][$field]['title'];
                                         }
                                     }
                                 } else {
                                     if (array_key_exists($field, $contactRelationshipTypes)) {
                                         foreach ($value as $relationField => $relationValue) {
                                             if (is_array($relationValue)) {
                                                 foreach ($relationValue as $locType => $locValue) {
                                                     if ($relationField == 'location') {
                                                         foreach ($locValue as $locKey => $dont) {
                                                             list($serviceProvider, $serviceProviderID) = explode('-', $locKey);
                                                             if ($serviceProvider == 'phone') {
                                                                 $headerRows[] = $contactRelationshipTypes[$field] . ' : ' . $locType . ' - ' . $serviceProvider . ' - ' . CRM_Utils_Array::value($serviceProviderID, $phoneTypes, 'Primary');
                                                             } else {
                                                                 if ($serviceProvider == 'im') {
                                                                     $headerRows[] = $contactRelationshipTypes[$field] . ' : ' . $locType . ' - ' . $serviceProvider . ' - ' . CRM_Utils_Array::value($serviceProviderID, $imProviders, 'Primary');
                                                                 } else {
                                                                     $headerRows[] = $contactRelationshipTypes[$field] . ' : ' . $locType . ' - ' . $query->_fields[$locKey]['title'];
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             } else {
                                                 if ($query->_fields[$relationField]['title']) {
                                                     $headerRows[] = $contactRelationshipTypes[$field] . ' : ' . $query->_fields[$relationField]['title'];
                                                 } else {
                                                     $headerRows[] = $contactRelationshipTypes[$field] . ' : ' . $relationField;
                                                 }
                                             }
                                         }
                                     } else {
                                         $headerRows[] = $field;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             //build row values (data)
             if (property_exists($dao, $field)) {
                 $fieldValue = $dao->{$field};
                 // to get phone type from phone type id
                 if ($field == 'phone_type_id') {
                     $fieldValue = $phoneTypes[$fieldValue];
                 } else {
                     if ($field == 'provider_id') {
                         $fieldValue = CRM_Utils_Array::value($fieldValue, $imProviders);
                     }
                 }
             } else {
                 $fieldValue = '';
             }
             if ($field == 'id') {
                 $row[$field] = $dao->contact_id;
             } else {
                 if ($field == 'pledge_balance_amount') {
                     //special case for calculated field
                     $row[$field] = $dao->pledge_amount - $dao->pledge_total_paid;
                 } else {
                     if ($field == 'pledge_next_pay_amount') {
                         //special case for calculated field
                         $row[$field] = $dao->pledge_next_pay_amount + $dao->pledge_outstanding_amount;
                     } else {
                         if (is_array($value) && $field == 'location') {
                             // fix header for location type case
                             foreach ($value as $ltype => $val) {
                                 foreach (array_keys($val) as $fld) {
                                     $type = explode('-', $fld);
                                     $fldValue = "{$ltype}-" . $type[0];
                                     if (CRM_Utils_Array::value(1, $type)) {
                                         $fldValue .= "-" . $type[1];
                                     }
                                     $row[$fldValue] = $dao->{$fldValue};
                                 }
                             }
                         } else {
                             if (array_key_exists($field, $contactRelationshipTypes)) {
                                 list($id, $direction) = explode('_', $field, 2);
                                 require_once 'api/v2/Relationship.php';
                                 require_once 'CRM/Contact/BAO/Contact.php';
                                 require_once 'CRM/Core/BAO/CustomValueTable.php';
                                 require_once 'CRM/Core/BAO/CustomQuery.php';
                                 $params['relationship_type_id'] = $contactRelationshipTypes[$field];
                                 $contact_id['contact_id'] = $dao->contact_id;
                                 //Get relationships
                                 $val = civicrm_contact_relationship_get($contact_id, null, $params);
                                 if (is_array($val['result'])) {
                                     asort($val['result']);
                                 }
                                 $is_valid = null;
                                 $data = null;
                                 if ($val['result']) {
                                     foreach ($val['result'] as $k => $v) {
                                         //consider only active relationships
                                         if ($v['is_active'] && $v['rtype'] == $direction) {
                                             $cID['contact_id'] = $v['cid'];
                                             if ($cID) {
                                                 //Get Contact Details
                                                 $data = CRM_Contact_BAO_Contact::retrieve($cID, $defaults);
                                             }
                                             $is_valid = true;
                                             break;
                                         }
                                     }
                                 }
                                 $relCustomIDs = array();
                                 foreach ($value as $relationkey => $relationvalue) {
                                     if ($val['result'] && ($cfID = CRM_Core_BAO_CustomField::getKeyID($relationkey))) {
                                         foreach ($val['result'] as $k1 => $v1) {
                                             $contID = $v1['cid'];
                                             $param1 = array('entityID' => $contID, $relationkey => 1);
                                             $getcustomValue = CRM_Core_BAO_CustomValueTable::getValues($param1);
                                             $custom_ID = CRM_Core_BAO_CustomField::getKeyID($relationkey);
                                             if ($cfID = CRM_Core_BAO_CustomField::getKeyID($relationkey)) {
                                                 if (empty($query->_options)) {
                                                     $relCustomIDs[$cfID] = array();
                                                     $relQuery = new CRM_Core_BAO_CustomQuery($relCustomIDs);
                                                     $relQuery->query();
                                                     $relOptions = $relQuery->_options;
                                                 } else {
                                                     $relOptions = $query->_options;
                                                 }
                                                 $custom_data = CRM_Core_BAO_CustomField::getDisplayValue($getcustomValue[$relationkey], $cfID, $relOptions);
                                             } else {
                                                 $custom_data = '';
                                             }
                                         }
                                     }
                                     //Get all relationships type custom fields
                                     list($id, $atype, $btype) = explode('_', $field);
                                     $relCustomData = CRM_Core_BAO_CustomField::getFields('Relationship', null, null, $id, null, null);
                                     $tmpArray = array_keys($relCustomData);
                                     $customIDs = array();
                                     foreach ($tmpArray as $customID) {
                                         $customIDs[$customID] = array();
                                     }
                                     require_once 'CRM/Core/BAO/CustomQuery.php';
                                     $customQuery = new CRM_Core_BAO_CustomQuery($customIDs);
                                     $customQuery->query();
                                     $options = $customQuery->_options;
                                     foreach ($relCustomData as $id => $customdatavalue) {
                                         if (in_array($relationkey, $customdatavalue)) {
                                             $customkey = "custom_{$id}";
                                             if ($val['result']) {
                                                 foreach ($val['result'] as $k => $v) {
                                                     $cid = $v['id'];
                                                     $param = array('entityID' => $cid, $customkey => 1);
                                                     //Get custom data values
                                                     $getCustomValueRel = CRM_Core_BAO_CustomValueTable::getValues($param);
                                                     if (!array_key_exists('error_message', $getCustomValueRel)) {
                                                         $customData = CRM_Core_BAO_CustomField::getDisplayValue($getCustomValueRel[$customkey], $id, $options);
                                                     } else {
                                                         $customData = '';
                                                     }
                                                     if ($customData) {
                                                         break;
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                     if (is_array($relationvalue)) {
                                         if (array_key_exists('location', $value)) {
                                             foreach ($value['location'] as $columnkey => $columnvalue) {
                                                 foreach ($columnvalue as $colkey => $colvalue) {
                                                     list($serviceProvider, $serviceProviderID) = explode('-', $colkey);
                                                     if (in_array($serviceProvider, array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'state_province', 'country'))) {
                                                         $serviceProvider = 'address';
                                                     }
                                                     $output = null;
                                                     foreach ((array) $data->{$serviceProvider} as $datakey => $datavalue) {
                                                         if ($columnkey == 'Primary') {
                                                             $columnkey = $locationTypes[$datavalue['location_type_id']];
                                                         }
                                                         if ($locationTypes[$datavalue['location_type_id']] == $columnkey) {
                                                             if (array_key_exists($colkey, $datavalue)) {
                                                                 $output = $datavalue[$colkey];
                                                             } else {
                                                                 if ($colkey == 'country') {
                                                                     $countryId = $datavalue['country_id'];
                                                                     if ($countryId) {
                                                                         require_once 'CRM/Core/PseudoConstant.php';
                                                                         $country =& CRM_Core_PseudoConstant::country($countryId);
                                                                     } else {
                                                                         $country = '';
                                                                     }
                                                                     $output = $country;
                                                                 } else {
                                                                     if ($colkey == 'state_province') {
                                                                         $stateProvinceId = $datavalue['state_province_id'];
                                                                         if ($stateProvinceId) {
                                                                             $stateProvince =& CRM_Core_PseudoConstant::stateProvince($stateProvinceId);
                                                                         } else {
                                                                             $stateProvince = '';
                                                                         }
                                                                         $output = $stateProvince;
                                                                     } else {
                                                                         if (is_numeric($serviceProviderID)) {
                                                                             if ($serviceProvider == 'phone') {
                                                                                 if (isset($datavalue['phone'])) {
                                                                                     $output = $datavalue['phone'];
                                                                                 } else {
                                                                                     $output = '';
                                                                                 }
                                                                             } else {
                                                                                 if ($serviceProvider == 'im') {
                                                                                     if (isset($datavalue['name'])) {
                                                                                         $output = $datavalue['name'];
                                                                                     } else {
                                                                                         $output = '';
                                                                                     }
                                                                                 }
                                                                             }
                                                                         } else {
                                                                             if ($datavalue['location_type_id']) {
                                                                                 if ($colkey == 'im') {
                                                                                     $output = $datavalue['name'];
                                                                                 } else {
                                                                                     $output = $datavalue[$colkey];
                                                                                 }
                                                                             } else {
                                                                                 $output = '';
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                     if ($is_valid) {
                                                         $row[] = $output;
                                                     } else {
                                                         $row[] = '';
                                                     }
                                                 }
                                             }
                                         }
                                     } else {
                                         if ($cfID = CRM_Core_BAO_CustomField::getKeyID($relationkey) && $is_valid) {
                                             $row[] = $custom_data;
                                         } else {
                                             if ($query->_fields[$relationkey]['name'] && $is_valid) {
                                                 if ($query->_fields[$relationkey]['name'] == 'gender') {
                                                     $getGenders =& CRM_Core_PseudoConstant::gender();
                                                     $gender = array_search($data->gender_id, array_flip($getGenders));
                                                     $row[] = $gender;
                                                 } else {
                                                     if ($query->_fields[$relationkey]['name'] == 'greeting_type') {
                                                         $getgreeting =& CRM_Core_PseudoConstant::greeting();
                                                         $greeting = array_search($data->greeting_type_id, array_flip($getgreeting));
                                                         $row[] = $greeting;
                                                     } else {
                                                         $colValue = $query->_fields[$relationkey]['name'];
                                                         $row[] = $data->{$colValue};
                                                     }
                                                 }
                                             } else {
                                                 if ($customData && $is_valid) {
                                                     $row[] = $customData;
                                                 } else {
                                                     $row[] = '';
                                                 }
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 if (isset($fieldValue) && $fieldValue != '') {
                                     //check for custom data
                                     if ($cfID = CRM_Core_BAO_CustomField::getKeyID($field)) {
                                         $row[$field] = CRM_Core_BAO_CustomField::getDisplayValue($fieldValue, $cfID, $query->_options);
                                     } else {
                                         if (array_key_exists($field, $multipleSelectFields)) {
                                             //option group fixes
                                             $paramsNew = array($field => $fieldValue);
                                             if ($field == 'test_tutoring') {
                                                 $name = array($field => array('newName' => $field, 'groupName' => 'test'));
                                             } else {
                                                 if (substr($field, 0, 4) == 'cmr_') {
                                                     //for  readers group
                                                     $name = array($field => array('newName' => $field, 'groupName' => substr($field, 0, -3)));
                                                 } else {
                                                     $name = array($field => array('newName' => $field, 'groupName' => $field));
                                                 }
                                             }
                                             CRM_Core_OptionGroup::lookupValues($paramsNew, $name, false);
                                             $row[$field] = $paramsNew[$field];
                                         } else {
                                             if (in_array($field, array('email_greeting', 'postal_greeting', 'addressee'))) {
                                                 //special case for greeting replacement
                                                 $fldValue = "{$field}_display";
                                                 $row[$field] = $dao->{$fldValue};
                                             } else {
                                                 //normal fields
                                                 $row[$field] = $fieldValue;
                                             }
                                         }
                                     }
                                 } else {
                                     // if field is empty or null
                                     $row[$field] = '';
                                 }
                             }
                         }
                     }
                 }
             }
         }
         //build header only once
         $setHeader = false;
         // add payment headers if required
         if ($addPaymentHeader && $paymentFields) {
             $headerRows = array_merge($headerRows, $paymentHeaders);
             $addPaymentHeader = false;
         }
         // add payment related information
         if ($paymentFields && isset($paymentDetails[$row[$paymentTableId]])) {
             $row = array_merge($row, $paymentDetails[$row[$paymentTableId]]);
         }
         //remove organization name for individuals if it is set for current employer
         if (CRM_Utils_Array::value('contact_type', $row) && $row['contact_type'] == 'Individual') {
             $row['organization_name'] = '';
         }
         // add component info
         $componentDetails[] = $row;
     }
     require_once 'CRM/Core/Report/Excel.php';
     CRM_Core_Report_Excel::writeCSVFile(self::getExportFileName('csv', $exportMode), $headerRows, $componentDetails);
     exit;
 }
Exemplo n.º 21
0
/**
 * @todo Write sth
 * @todo Serious FIXMES in the code! File issues.
 */
function civicrm_contact_update(&$params, $create_new = FALSE)
{
    _civicrm_initialize();
    try {
        civicrm_api_check_permission(__FUNCTION__, $params, TRUE);
    } catch (Exception $e) {
        return civicrm_create_error($e->getMessage());
    }
    require_once 'CRM/Utils/Array.php';
    $entityId = CRM_Utils_Array::value('contact_id', $params, NULL);
    if (!CRM_Utils_Array::value('contact_type', $params) && $entityId) {
        $params['contact_type'] = CRM_Contact_BAO_Contact::getContactType($entityId);
    }
    $dupeCheck = CRM_Utils_Array::value('dupe_check', $params, FALSE);
    $values = civicrm_contact_check_params($params, $dupeCheck);
    if ($values) {
        return $values;
    }
    if ($create_new) {
        // Make sure nothing is screwed up before we create a new contact
        if (!empty($entityId)) {
            return civicrm_create_error('Cannot create new contact when contact_id is present');
        }
        if (empty($params['contact_type'])) {
            return civicrm_create_error('Contact Type not specified');
        }
        // If we get here, we're ready to create a new contact
        if (($email = CRM_Utils_Array::value('email', $params)) && !is_array($params['email'])) {
            require_once 'CRM/Core/BAO/LocationType.php';
            $defLocType = CRM_Core_BAO_LocationType::getDefault();
            $params['email'] = array(1 => array('email' => $email, 'is_primary' => 1, 'location_type_id' => $defLocType->id ? $defLocType->id : 1));
        }
    }
    if ($homeUrl = CRM_Utils_Array::value('home_url', $params)) {
        require_once 'CRM/Core/PseudoConstant.php';
        $websiteTypes = CRM_Core_PseudoConstant::websiteType();
        $params['website'] = array(1 => array('website_type_id' => key($websiteTypes), 'url' => $homeUrl));
    }
    // FIXME: Some legacy support cruft, should get rid of this in 3.1
    $change = array('individual_prefix' => 'prefix', 'prefix' => 'prefix_id', 'individual_suffix' => 'suffix', 'suffix' => 'suffix_id', 'gender' => 'gender_id');
    foreach ($change as $field => $changeAs) {
        if (array_key_exists($field, $params)) {
            $params[$changeAs] = $params[$field];
            unset($params[$field]);
        }
    }
    // End legacy support cruft
    if (isset($params['suffix_id']) && !is_numeric($params['suffix_id'])) {
        $params['suffix_id'] = array_search($params['suffix_id'], CRM_Core_PseudoConstant::individualSuffix());
    }
    if (isset($params['prefix_id']) && !is_numeric($params['prefix_id'])) {
        $params['prefix_id'] = array_search($params['prefix_id'], CRM_Core_PseudoConstant::individualPrefix());
    }
    if (isset($params['gender_id']) && !is_numeric($params['gender_id'])) {
        $params['gender_id'] = array_search($params['gender_id'], CRM_Core_PseudoConstant::gender());
    }
    $error = _civicrm_greeting_format_params($params);
    if (civicrm_error($error)) {
        return $error;
    }
    $values = array();
    if (!($csType = CRM_Utils_Array::value('contact_sub_type', $params)) && $entityId) {
        require_once 'CRM/Contact/BAO/Contact.php';
        $csType = CRM_Contact_BAO_Contact::getContactSubType($entityId);
    }
    $customValue = civicrm_contact_check_custom_params($params, $csType);
    if ($customValue) {
        return $customValue;
    }
    _civicrm_custom_format_params($params, $values, $params['contact_type'], $entityId);
    $params = array_merge($params, $values);
    $contact =& _civicrm_contact_update($params, $entityId);
    if (is_a($contact, 'CRM_Core_Error')) {
        return civicrm_create_error($contact->_errors[0]['message']);
    } else {
        $values = array();
        $values['contact_id'] = $contact->id;
        $values['is_error'] = 0;
    }
    return $values;
}
Exemplo n.º 22
0
 function restWhere(&$values)
 {
     list($name, $op, $value, $grouping, $wildcard) = $values;
     if (!CRM_Utils_Array::value($grouping, $this->_where)) {
         $this->_where[$grouping] = array();
     }
     //check if the location type exits for fields
     $lType = '';
     $locType = array();
     $locType = explode('-', $name);
     //add phone type if exists
     if (isset($locType[2]) && $locType[2]) {
         $locType[2] = CRM_Core_DAO::escapeString($locType[2]);
     }
     $field = CRM_Utils_Array::value($name, $this->_fields);
     if (!$field) {
         $field = CRM_Utils_Array::value($locType[0], $this->_fields);
         if (!$field) {
             return;
         }
     }
     $setTables = true;
     // FIXME: the LOWER/strtolower pairs below most probably won't work
     // with non-US-ASCII characters, as even if MySQL does the proper
     // thing with LOWER-ing them (4.0 almost certainly won't, but then
     // we don't officially support 4.0 for non-US-ASCII data), PHP
     // won't do the proper thing with strtolower-ing them unless the
     // underlying operating system uses an UTF-8 locale for LC_CTYPE
     // for the user the webserver runs at (or suEXECs); we should use
     // mb_strtolower(), but then we'd require mb_strings support; we
     // could wrap this in function_exist(), though
     if (substr($name, 0, 14) === 'state_province') {
         if (isset($locType[1]) && is_numeric($locType[1])) {
             $setTables = false;
             //get the location name
             $locationType =& CRM_Core_PseudoConstant::locationType();
             list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
             $this->_whereTables[$tName] = $this->_tables[$tName];
             $where = "`{$tName}`.{$fldName}";
         } else {
             $where = $field['where'];
         }
         $wc = $op != 'LIKE' ? "LOWER({$where})" : $where;
         if (is_numeric($value)) {
             $where = str_replace('.name', '.id', $where);
             $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive');
             $states =& CRM_Core_PseudoConstant::stateProvince();
             $value = $states[(int) $value];
         } else {
             $wc = $op != 'LIKE' ? "LOWER({$where})" : $where;
             $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
         }
         if (!$lType) {
             $this->_qill[$grouping][] = ts('State') . " {$op} '{$value}'";
         } else {
             $this->_qill[$grouping][] = ts('State') . " ({$lType}) {$op} '{$value}'";
         }
     } else {
         if (substr($name, 0, 7) === 'country') {
             if (isset($locType[1]) && is_numeric($locType[1])) {
                 $setTables = false;
                 //get the location name
                 $locationType =& CRM_Core_PseudoConstant::locationType();
                 list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
                 $this->_whereTables[$tName] = $this->_tables[$tName];
                 $where = "`{$tName}`.{$fldName}";
             } else {
                 $where = $field['where'];
             }
             if (is_numeric($value)) {
                 $where = str_replace('.name', '.id', $where);
                 $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive');
                 $countries =& CRM_Core_PseudoConstant::country();
                 $value = $countries[(int) $value];
             } else {
                 $wc = $op != 'LIKE' ? "LOWER({$where})" : $where;
                 $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
             }
             if (!$lType) {
                 $this->_qill[$grouping][] = ts('Country') . " {$op} '{$value}'";
             } else {
                 $this->_qill[$grouping][] = ts('Country') . " ({$lType}) {$op} '{$value}'";
             }
         } else {
             if (substr($name, 0, 6) === 'county') {
                 if (isset($locType[1]) && is_numeric($locType[1])) {
                     $setTables = false;
                     //get the location name
                     $locationType =& CRM_Core_PseudoConstant::locationType();
                     list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
                     $this->_whereTables[$tName] = $this->_tables[$tName];
                     $where = "`{$tName}`.{$fldName}";
                 } else {
                     $where = $field['where'];
                 }
                 if (is_numeric($value)) {
                     $where = str_replace('.name', '.id', $where);
                     $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive');
                     $counties =& CRM_Core_PseudoConstant::county();
                     $value = $counties[(int) $value];
                 } else {
                     $wc = $op != 'LIKE' ? "LOWER({$where})" : $where;
                     $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                 }
                 if (!$lType) {
                     $this->_qill[$grouping][] = ts('County') . " {$op} '{$value}'";
                 } else {
                     $this->_qill[$grouping][] = ts('County') . " ({$lType}) {$op} '{$value}'";
                 }
             } else {
                 if ($name === 'world_region') {
                     $worldRegions =& CRM_Core_PseudoConstant::worldRegion();
                     if (is_numeric($value)) {
                         $value = $worldRegions[(int) $value];
                     }
                     $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                     $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                     $this->_qill[$grouping][] = ts('World Region') . " {$op} '{$value}'";
                 } else {
                     if ($name === 'individual_prefix') {
                         $individualPrefixs =& CRM_Core_PseudoConstant::individualPrefix();
                         if (is_numeric($value)) {
                             $value = $individualPrefixs[(int) $value];
                         }
                         $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                         $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                         $this->_qill[$grouping][] = ts('Individual Prefix') . " {$op} '{$value}'";
                     } else {
                         if ($name === 'individual_suffix') {
                             $individualSuffixs =& CRM_Core_PseudoConstant::individualsuffix();
                             if (is_numeric($value)) {
                                 $value = $individualSuffixs[(int) $value];
                             }
                             $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                             $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                             $this->_qill[$grouping][] = ts('Individual Suffix') . " {$op} '{$value}'";
                         } else {
                             if ($name === 'gender') {
                                 $genders =& CRM_Core_PseudoConstant::gender();
                                 if (is_numeric($value)) {
                                     $value = $genders[(int) $value];
                                 }
                                 $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                                 $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                                 $this->_qill[$grouping][] = ts('Gender') . " {$op} '{$value}'";
                             } else {
                                 if ($name === 'birth_date') {
                                     $date = CRM_Utils_Date::format($value);
                                     $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $date);
                                     if ($date) {
                                         $date = CRM_Utils_Date::customFormat($date);
                                         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$date}\"";
                                     } else {
                                         $this->_qill[$grouping][] = "{$field['title']} {$op}";
                                     }
                                 } else {
                                     if ($name === 'deceased_date') {
                                         $date = CRM_Utils_Date::format($value);
                                         $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $date);
                                         if ($date) {
                                             $date = CRM_Utils_Date::customFormat($date);
                                             $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$date}\"";
                                         } else {
                                             $this->_qill[$grouping][] = "{$field['title']} {$op}";
                                         }
                                     } else {
                                         if ($name === 'is_deceased') {
                                             $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $value);
                                             $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
                                         } else {
                                             if ($name === 'contact_id') {
                                                 if (is_int($value)) {
                                                     $this->_where[$grouping][] = self::buildClause($field['where'], $op, $value);
                                                     $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}";
                                                 }
                                             } else {
                                                 if ($name === 'name') {
                                                     $value = strtolower(CRM_Core_DAO::escapeString($value));
                                                     if ($wildcard) {
                                                         $value = "%{$value}%";
                                                         $op = 'LIKE';
                                                     }
                                                     $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                                                     $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}'");
                                                     $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
                                                 } else {
                                                     if ($name === 'current_employer') {
                                                         $value = strtolower(CRM_Core_DAO::escapeString($value));
                                                         if ($wildcard) {
                                                             $value = "%{$value}%";
                                                             $op = 'LIKE';
                                                         }
                                                         $wc = $op != 'LIKE' ? "LOWER(contact_a.organization_name)" : "contact_a.organization_name";
                                                         $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}' AND contact_a.contact_type ='Individual'");
                                                         $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\"";
                                                     } else {
                                                         if ($name === 'email_greeting') {
                                                             $filterCondition = array('greeting_type' => 'email_greeting');
                                                             $emailGreetings =& CRM_Core_PseudoConstant::greeting($filterCondition);
                                                             if (is_numeric($value)) {
                                                                 $value = $emailGreetings[(int) $value];
                                                             }
                                                             $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                                                             $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                                                             $this->_qill[$grouping][] = ts('Email Greeting') . " {$op} '{$value}'";
                                                         } else {
                                                             if ($name === 'postal_greeting') {
                                                                 $filterCondition = array('greeting_type' => 'postal_greeting');
                                                                 $postalGreetings =& CRM_Core_PseudoConstant::greeting($filterCondition);
                                                                 if (is_numeric($value)) {
                                                                     $value = $postalGreetings[(int) $value];
                                                                 }
                                                                 $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                                                                 $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                                                                 $this->_qill[$grouping][] = ts('Postal Greeting') . " {$op} '{$value}'";
                                                             } else {
                                                                 if ($name === 'addressee') {
                                                                     $filterCondition = array('greeting_type' => 'addressee');
                                                                     $addressee =& CRM_Core_PseudoConstant::greeting($filterCondition);
                                                                     if (is_numeric($value)) {
                                                                         $value = $addressee[(int) $value];
                                                                     }
                                                                     $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}";
                                                                     $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String');
                                                                     $this->_qill[$grouping][] = ts('Addressee') . " {$op} '{$value}'";
                                                                 } else {
                                                                     // sometime the value is an array, need to investigate and fix
                                                                     if (is_array($value)) {
                                                                         CRM_Core_Error::fatal();
                                                                     }
                                                                     if (!empty($field['where'])) {
                                                                         if ($op != 'IN') {
                                                                             $value = strtolower(CRM_Core_DAO::escapeString($value));
                                                                         }
                                                                         if ($wildcard) {
                                                                             $value = "%{$value}%";
                                                                             $op = 'LIKE';
                                                                         }
                                                                         if ($op != 'IN') {
                                                                             $value = "'{$value}'";
                                                                         }
                                                                         if (isset($locType[1]) && is_numeric($locType[1])) {
                                                                             $setTables = false;
                                                                             //get the location name
                                                                             $locationType =& CRM_Core_PseudoConstant::locationType();
                                                                             list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
                                                                             $where = "`{$tName}`.{$fldName}";
                                                                             $this->_where[$grouping][] = self::buildClause("LOWER({$where})", $op, $value);
                                                                             $this->_whereTables[$tName] = $this->_tables[$tName];
                                                                             $this->_qill[$grouping][] = "{$field['title']} {$op} '{$value}'";
                                                                         } else {
                                                                             list($tableName, $fieldName) = explode('.', $field['where'], 2);
                                                                             if ($tableName == 'civicrm_contact') {
                                                                                 $fieldName = "LOWER(contact_a.{$fieldName})";
                                                                             } else {
                                                                                 if ($op != 'IN' && !is_numeric($value)) {
                                                                                     $fieldName = "LOWER({$field['where']})";
                                                                                 } else {
                                                                                     $fieldName = "{$field['where']}";
                                                                                 }
                                                                             }
                                                                             $this->_where[$grouping][] = self::buildClause($fieldName, $op, $value);
                                                                             $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}";
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($setTables) {
         list($tableName, $fieldName) = explode('.', $field['where'], 2);
         if (isset($tableName)) {
             $this->_tables[$tableName] = 1;
             $this->_whereTables[$tableName] = 1;
         }
     }
 }
Exemplo n.º 23
0
 /**
  * Function to build profile form
  *
  * @params object  $form       form object
  * @params array   $field      array field properties
  * @params int     $mode       profile mode
  * @params int     $contactID  contact id
  *
  * @return null
  * @static
  * @access public
  */
 static function buildProfile(&$form, &$field, $mode, $contactId = null, $online = false)
 {
     require_once "CRM/Profile/Form.php";
     require_once "CRM/Core/OptionGroup.php";
     require_once 'CRM/Core/BAO/UFField.php';
     require_once 'CRM/Contact/BAO/ContactType.php';
     $defaultValues = array();
     $fieldName = $field['name'];
     $title = $field['title'];
     $attributes = $field['attributes'];
     $rule = $field['rule'];
     $view = $field['is_view'];
     $required = $mode == CRM_Profile_Form::MODE_SEARCH ? false : $field['is_required'];
     $search = $mode == CRM_Profile_Form::MODE_SEARCH ? true : false;
     // do not display view fields in drupal registration form
     // CRM-4632
     if ($view && $mode == CRM_Profile_Form::MODE_REGISTER) {
         return;
     }
     if ($contactId && !$online) {
         $name = "field[{$contactId}][{$fieldName}]";
     } else {
         $name = $fieldName;
     }
     require_once 'CRM/Core/BAO/Preferences.php';
     $addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true);
     if (substr($fieldName, 0, 14) === 'state_province') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required);
     } else {
         if (substr($fieldName, 0, 7) === 'country') {
             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required);
             $config =& CRM_Core_Config::singleton();
             if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactCountry) {
                 $defaultValues[$name] = $config->defaultContactCountry;
                 $form->setDefaults($defaultValues);
             }
         } else {
             if (substr($fieldName, 0, 6) === 'county') {
                 if ($addressOptions['county']) {
                     $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::county(), $required);
                 }
             } else {
                 if (substr($fieldName, 0, 2) === 'im') {
                     if (!$contactId) {
                         $form->add('select', $name . '-provider_id', $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::IMProvider(), $required);
                         if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) {
                             $form->freeze($name . "-provider_id");
                         }
                     }
                     $form->add('text', $name, $title, $attributes, $required);
                 } else {
                     if ($fieldName === 'birth_date' || $fieldName === 'deceased_date') {
                         $form->addDate($name, $title, $required, array('formatType' => 'birth'));
                     } else {
                         if (in_array($fieldName, array("membership_start_date", "membership_end_date", "join_date"))) {
                             $form->addDate($name, $title, $required, array('formatType' => 'custom'));
                         } else {
                             if ($field['name'] == 'membership_type_id') {
                                 require_once 'CRM/Member/PseudoConstant.php';
                                 $form->add('select', 'membership_type_id', $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipType(), $required);
                             } else {
                                 if ($field['name'] == 'status_id') {
                                     require_once 'CRM/Member/PseudoConstant.php';
                                     $form->add('select', 'status_id', $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(), $required);
                                 } else {
                                     if ($fieldName === 'gender') {
                                         $genderOptions = array();
                                         $gender = CRM_Core_PseudoConstant::gender();
                                         foreach ($gender as $key => $var) {
                                             $genderOptions[$key] = HTML_QuickForm::createElement('radio', null, ts('Gender'), $var, $key);
                                         }
                                         $form->addGroup($genderOptions, $name, $title);
                                         if ($required) {
                                             $form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required');
                                         }
                                     } else {
                                         if ($fieldName === 'individual_prefix') {
                                             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix(), $required);
                                         } else {
                                             if ($fieldName === 'individual_suffix') {
                                                 $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix(), $required);
                                             } else {
                                                 if ($fieldName === 'contact_sub_type') {
                                                     $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $form->_fields[$fieldName]);
                                                     $profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : null;
                                                     $setSubtype = false;
                                                     if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
                                                         $setSubtype = $profileType;
                                                         $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
                                                     }
                                                     $subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array();
                                                     if ($setSubtype) {
                                                         $subtypeList = array();
                                                         $subtypeList[$setSubtype] = $subtypes[$setSubtype];
                                                     } else {
                                                         $subtypeList = array('' => ts('- select -')) + $subtypes;
                                                     }
                                                     $form->add('select', $name, $title, $subtypeList, $required);
                                                 } else {
                                                     if (in_array($fieldName, array('email_greeting', 'postal_greeting', 'addressee'))) {
                                                         //add email greeting, postal greeting, addressee, CRM-4575
                                                         $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
                                                         $profileType = CRM_Core_BAO_UFField::getProfileType($gId, true, false, true);
                                                         if (empty($profileType) || in_array($profileType, array('Contact', 'Contribution', 'Participant', 'Membership'))) {
                                                             $profileType = 'Individual';
                                                         }
                                                         if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
                                                             $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
                                                         }
                                                         if ($fieldName == 'email_greeting') {
                                                             $emailGreeting = array('contact_type' => $profileType, 'greeting_type' => 'email_greeting');
                                                             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($emailGreeting), $required);
                                                             // adding custom email greeting element alongwith email greeting
                                                             $form->add('text', 'email_greeting_custom', ts('Custom Email Greeting'), null, false);
                                                         } else {
                                                             if ($fieldName === 'postal_greeting') {
                                                                 $postalGreeting = array('contact_type' => $profileType, 'greeting_type' => 'postal_greeting');
                                                                 $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($postalGreeting), $required);
                                                                 // adding custom postal greeting element alongwith postal greeting
                                                                 $form->add('text', 'postal_greeting_custom', ts('Custom Postal Greeting'), null, false);
                                                             } else {
                                                                 if ($fieldName === 'addressee') {
                                                                     $addressee = array('contact_type' => $profileType, 'greeting_type' => 'addressee');
                                                                     $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($addressee), $required);
                                                                     // adding custom addressee  element alongwith addressee type
                                                                     $form->add('text', 'addressee_custom', ts('Custom Addressee'), null, false);
                                                                 }
                                                             }
                                                         }
                                                     } else {
                                                         if ($fieldName === 'preferred_communication_method') {
                                                             $communicationFields = CRM_Core_PseudoConstant::pcm();
                                                             foreach ($communicationFields as $key => $var) {
                                                                 if ($key == '') {
                                                                     continue;
                                                                 }
                                                                 $communicationOptions[] =& HTML_QuickForm::createElement('checkbox', $key, null, $var);
                                                             }
                                                             $form->addGroup($communicationOptions, $name, $title, '<br/>');
                                                         } else {
                                                             if ($fieldName === 'preferred_mail_format') {
                                                                 $form->add('select', $name, $title, CRM_Core_SelectValues::pmf());
                                                             } else {
                                                                 if ($fieldName == 'external_identifier') {
                                                                     $form->add('text', $name, $title, $attributes, $required);
                                                                     $contID = $contactId;
                                                                     if (!$contID) {
                                                                         $contID = $form->get('id');
                                                                     }
                                                                     $form->addRule($name, ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $contID, 'external_identifier'));
                                                                 } else {
                                                                     if ($fieldName === 'group') {
                                                                         require_once 'CRM/Contact/Form/Edit/TagsAndGroups.php';
                                                                         CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, true, $required, $title, null, $name);
                                                                     } else {
                                                                         if ($fieldName === 'tag') {
                                                                             require_once 'CRM/Contact/Form/Edit/TagsAndGroups.php';
                                                                             CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::TAG, false, $required, null, $title, $name);
                                                                         } else {
                                                                             if ($fieldName === 'home_URL') {
                                                                                 $form->addElement('text', $name, $title, array_merge(CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'home_URL'), array('onfocus' => "if (!this.value) this.value='http://'; else return false", 'onblur' => "if ( this.value == 'http://') this.value=''; else return false")));
                                                                                 $form->addRule($name, ts('Enter a valid Website.'), 'url');
                                                                             } else {
                                                                                 if (substr($fieldName, 0, 6) === 'custom') {
                                                                                     $customFieldID = CRM_Core_BAO_CustomField::getKeyID($fieldName);
                                                                                     if ($customFieldID) {
                                                                                         CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, false, $required, $search, $title);
                                                                                     }
                                                                                 } else {
                                                                                     if (in_array($fieldName, array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) {
                                                                                         $form->addDate($name, $title, $required, array('formatType' => 'custom'));
                                                                                     } else {
                                                                                         if ($fieldName == 'payment_instrument') {
                                                                                             require_once "CRM/Contribute/PseudoConstant.php";
                                                                                             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required);
                                                                                         } else {
                                                                                             if ($fieldName == 'contribution_type') {
                                                                                                 require_once "CRM/Contribute/PseudoConstant.php";
                                                                                                 $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType(), $required);
                                                                                             } else {
                                                                                                 if ($fieldName == 'contribution_status_id') {
                                                                                                     require_once "CRM/Contribute/PseudoConstant.php";
                                                                                                     $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionStatus(), $required);
                                                                                                 } else {
                                                                                                     if ($fieldName == 'participant_register_date') {
                                                                                                         $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
                                                                                                     } else {
                                                                                                         if ($fieldName == 'participant_status_id') {
                                                                                                             require_once "CRM/Event/PseudoConstant.php";
                                                                                                             $cond = null;
                                                                                                             if ($online == true) {
                                                                                                                 $cond = "visibility_id = 1";
                                                                                                             }
                                                                                                             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantStatus(null, $cond), $required);
                                                                                                         } else {
                                                                                                             if ($fieldName == 'participant_role_id') {
                                                                                                                 require_once "CRM/Event/PseudoConstant.php";
                                                                                                                 $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantRole(), $required);
                                                                                                             } else {
                                                                                                                 if ($fieldName == 'scholarship_type_id') {
                                                                                                                     $form->add('select', $name, $title, array("" => "-- Select -- ") + array_flip(CRM_Core_OptionGroup::values('scholarship_type', true)));
                                                                                                                 } else {
                                                                                                                     if ($fieldName == 'applicant_status_id') {
                                                                                                                         $form->add('select', $name, $title, array("" => "-- Select -- ") + array_flip(CRM_Core_OptionGroup::values('applicant_status', true)));
                                                                                                                     } else {
                                                                                                                         if ($fieldName == 'highschool_gpa_id') {
                                                                                                                             $form->add('select', $name, $title, array("" => "-- Select -- ") + CRM_Core_OptionGroup::values('highschool_gpa'));
                                                                                                                         } else {
                                                                                                                             if ($fieldName == 'world_region') {
                                                                                                                                 require_once "CRM/Core/PseudoConstant.php";
                                                                                                                                 $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::worldRegion(), $required);
                                                                                                                             } else {
                                                                                                                                 $processed = false;
                                                                                                                                 if (CRM_Core_Permission::access('Quest', false)) {
                                                                                                                                     require_once 'CRM/Quest/BAO/Student.php';
                                                                                                                                     $processed = CRM_Quest_BAO_Student::buildStudentForm($form, $fieldName, $title, $contactId);
                                                                                                                                 }
                                                                                                                                 if (!$processed) {
                                                                                                                                     if (substr($fieldName, 0, 3) === 'is_' or substr($fieldName, 0, 7) === 'do_not_') {
                                                                                                                                         $form->add('checkbox', $name, $title, $attributes, $required);
                                                                                                                                     } else {
                                                                                                                                         $form->add('text', $name, $title, $attributes, $required);
                                                                                                                                     }
                                                                                                                                 }
                                                                                                                             }
                                                                                                                         }
                                                                                                                     }
                                                                                                                 }
                                                                                                             }
                                                                                                         }
                                                                                                     }
                                                                                                 }
                                                                                             }
                                                                                         }
                                                                                     }
                                                                                 }
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     static $hiddenSubtype = false;
     if (!$hiddenSubtype && CRM_Contact_BAO_ContactType::isaSubType($field['field_type'])) {
         // In registration mode params are submitted via POST and we don't have any clue
         // about profile-id or the profile-type (which could be a subtype)
         // To generalize the  behavior and simplify the process,
         // lets always add the hidden
         //subtype value if there is any, and we won't have to
         // compute it while processing.
         $form->addElement('hidden', 'contact_sub_type_hidden', $field['field_type']);
         $hiddenSubtype = true;
     }
     if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) {
         $form->freeze($name);
     }
     //add the rules
     if (in_array($fieldName, array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) {
         $form->addRule($name, ts('Please enter a valid amount.'), 'money');
     }
     if ($rule) {
         if (!($rule == 'email' && $mode == CRM_Profile_Form::MODE_SEARCH)) {
             $form->addRule($name, ts('Please enter a valid %1', array(1 => $title)), $rule);
         }
     }
 }
Exemplo n.º 24
0
/**
 * @todo Write sth
 * @todo Serious FIXMES in the code! File issues.
 */
function civicrm_contact_update(&$params, $create_new = false)
{
    _civicrm_initialize();
    require_once 'CRM/Utils/Array.php';
    $contactID = CRM_Utils_Array::value('contact_id', $params);
    if ($create_new) {
        // Make sure nothing is screwed up before we create a new contact
        if (!empty($contactID)) {
            return civicrm_create_error('Cannot create new contact when contact_id is present');
        }
        if (empty($params['contact_type'])) {
            return civicrm_create_error('Contact Type not specified');
        }
        $dupeCheck = CRM_Utils_Array::value('dupe_check', $params, false);
        $values = civicrm_contact_check_params($params, $dupeCheck);
        if ($values) {
            return $values;
        }
        // If we get here, we're ready to create a new contact
        if (($email = CRM_Utils_Array::value('email', $params)) && !is_array($params['email'])) {
            require_once 'CRM/Core/BAO/LocationType.php';
            $defLocType = CRM_Core_BAO_LocationType::getDefault();
            $params['email'] = array(1 => array('email' => $email, 'is_primary' => 1, 'location_type_id' => $defLocType->id ? $defLocType->id : 1));
        }
    }
    // FIXME: Some legacy support cruft, should get rid of this in 3.1
    $change = array('individual_prefix' => 'prefix', 'prefix' => 'prefix_id', 'individual_suffix' => 'suffix', 'suffix' => 'suffix_id', 'gender' => 'gender_id');
    foreach ($change as $field => $changeAs) {
        if (array_key_exists($field, $params)) {
            $params[$changeAs] = $params[$field];
            unset($params[$field]);
        }
    }
    // End legacy support cruft
    if (isset($params['suffix_id']) && !is_numeric($params['suffix_id'])) {
        $params['suffix_id'] = array_search($params['suffix_id'], CRM_Core_PseudoConstant::individualSuffix());
    }
    if (isset($params['prefix_id']) && !is_numeric($params['prefix_id'])) {
        $params['prefix_id'] = array_search($params['prefix_id'], CRM_Core_PseudoConstant::individualPrefix());
    }
    if (isset($params['gender_id']) && !is_numeric($params['gender_id'])) {
        $params['gender_id'] = array_search($params['gender_id'], CRM_Core_PseudoConstant::gender());
    }
    $values = array();
    $entityId = CRM_Utils_Array::value('contact_id', $params, null);
    _civicrm_custom_format_params($params, $values, $params['contact_type'], $entityId);
    $params = array_merge($params, $values);
    $contact =& _civicrm_contact_update($params, $contactID);
    if (is_a($contact, 'CRM_Core_Error')) {
        return civicrm_create_error($contact->_errors[0]['message']);
    } else {
        $values = array();
        $values['contact_id'] = $contact->id;
        $values['is_error'] = 0;
    }
    return $values;
}
Exemplo n.º 25
0
 /**
  *  Check if value present in all genders or 
  *  as a substring of any gender value, if yes than return corresponding gender.
  *  eg value might be  m/M, ma/MA, mal/MAL, male return 'Male' 
  *  but if value is 'maleabc' than return false
  *  
  *  @param string $gender check this value across gender values.
  *
  *  retunr gender value / false
  *  @access public
  */
 public function checkGender($gender)
 {
     $gender = trim($gender, '.');
     if (!$gender) {
         return false;
     }
     $allGenders = CRM_Core_PseudoConstant::gender();
     foreach ($allGenders as $key => $value) {
         if (strlen($gender) > strlen($value)) {
             continue;
         }
         if ($gender == $value) {
             return $value;
         }
         if (substr_compare($value, $gender, 0, strlen($gender), true) === 0) {
             return $value;
         }
     }
     return false;
 }
Exemplo n.º 26
0
 /**
  *
  * Get the values for pseudoconstants for name->value and reverse.
  *
  * @param array   $defaults (reference) the default values, some of which need to be resolved.
  * @param boolean $reverse  true if we want to resolve the values in the reverse direction (value -> name)
  *
  * @return none
  * @access public
  * @static
  */
 static function resolveDefaults(&$defaults, $reverse = false)
 {
     // hack for birth_date
     if (CRM_Utils_Array::value('birth_date', $defaults)) {
         if (is_array($defaults['birth_date'])) {
             $defaults['birth_date'] = CRM_Utils_Date::format($defaults['birth_date'], '-');
         }
     }
     CRM_Utils_Array::lookupValue($defaults, 'prefix', CRM_Core_PseudoConstant::individualPrefix(), $reverse);
     CRM_Utils_Array::lookupValue($defaults, 'suffix', CRM_Core_PseudoConstant::individualSuffix(), $reverse);
     CRM_Utils_Array::lookupValue($defaults, 'gender', CRM_Core_PseudoConstant::gender(), $reverse);
     //lookup value of email/postal greeting, addressee, CRM-4575
     $filterCondition = array('contact_type' => CRM_Utils_Array::value('contact_type', $defaults), 'greeting_type' => 'email_greeting');
     CRM_Utils_Array::lookupValue($defaults, 'email_greeting', CRM_Core_PseudoConstant::greeting($filterCondition), $reverse);
     $filterCondition = array('contact_type' => CRM_Utils_Array::value('contact_type', $defaults), 'greeting_type' => 'postal_greeting');
     CRM_Utils_Array::lookupValue($defaults, 'postal_greeting', CRM_Core_PseudoConstant::greeting($filterCondition), $reverse);
     $filterCondition = array('contact_type' => CRM_Utils_Array::value('contact_type', $defaults), 'greeting_type' => 'addressee');
     CRM_Utils_Array::lookupValue($defaults, 'addressee', CRM_Core_PseudoConstant::greeting($filterCondition), $reverse);
     $blocks = array('address', 'im', 'phone');
     foreach ($blocks as $name) {
         if (!array_key_exists($name, $defaults) || !is_array($defaults[$name])) {
             continue;
         }
         foreach ($defaults[$name] as $count => &$values) {
             //get location type id.
             CRM_Utils_Array::lookupValue($values, 'location_type', CRM_Core_PseudoConstant::locationType(), $reverse);
             if ($name == 'address') {
                 // FIXME: lookupValue doesn't work for vcard_name
                 if (CRM_Utils_Array::value('location_type_id', $values)) {
                     $vcardNames =& CRM_Core_PseudoConstant::locationVcardName();
                     $values['vcard_name'] = $vcardNames[$values['location_type_id']];
                 }
                 if (!CRM_Utils_Array::lookupValue($values, 'state_province', CRM_Core_PseudoConstant::stateProvince(), $reverse) && $reverse) {
                     CRM_Utils_Array::lookupValue($values, 'state_province', CRM_Core_PseudoConstant::stateProvinceAbbreviation(), $reverse);
                 }
                 if (!CRM_Utils_Array::lookupValue($values, 'country', CRM_Core_PseudoConstant::country(), $reverse) && $reverse) {
                     CRM_Utils_Array::lookupValue($values, 'country', CRM_Core_PseudoConstant::countryIsoCode(), $reverse);
                 }
                 CRM_Utils_Array::lookupValue($values, 'county', CRM_Core_PseudoConstant::county(), $reverse);
             }
             if ($name == 'im') {
                 CRM_Utils_Array::lookupValue($values, 'provider', CRM_Core_PseudoConstant::IMProvider(), $reverse);
             }
             if ($name == 'phone') {
                 CRM_Utils_Array::lookupValue($values, 'phone_type', CRM_Core_PseudoConstant::phoneType(), $reverse);
             }
             //kill the reference.
             unset($values);
         }
     }
 }
Exemplo n.º 27
0
 /**  
  * Function to build the array for display the profile fields
  *  
  * @param array $params key value. 
  * @param int $gid profile Id
  * @param array $groupTitle Profile Group Title.
  * @param array $values formatted array of key value
  *
  * @return None  
  * @access public  
  */
 function displayProfile(&$params, $gid, &$groupTitle, &$values)
 {
     if ($gid) {
         require_once 'CRM/Core/BAO/UFGroup.php';
         require_once 'CRM/Profile/Form.php';
         require_once 'CRM/Event/PseudoConstant.php';
         $session = CRM_Core_Session::singleton();
         $contactID = $session->get('userID');
         if ($contactID) {
             if (CRM_Core_BAO_UFGroup::filterUFGroups($gid, $contactID)) {
                 $fields = CRM_Core_BAO_UFGroup::getFields($gid, false, CRM_Core_Action::VIEW);
             }
         } else {
             $fields = CRM_Core_BAO_UFGroup::getFields($gid, false, CRM_Core_Action::ADD);
         }
         if (is_array($fields)) {
             // unset any email-* fields since we already collect it, CRM-2888
             foreach (array_keys($fields) as $fieldName) {
                 if (substr($fieldName, 0, 6) == 'email-') {
                     unset($fields[$fieldName]);
                 }
             }
         }
         foreach ($fields as $v) {
             if (CRM_Utils_Array::value('groupTitle', $v)) {
                 $groupTitle['groupTitle'] = $v["groupTitle"];
                 break;
             }
         }
         $config = CRM_Core_Config::singleton();
         require_once 'CRM/Core/PseudoConstant.php';
         $locationTypes = $imProviders = array();
         $locationTypes = CRM_Core_PseudoConstant::locationType();
         $imProviders = CRM_Core_PseudoConstant::IMProvider();
         //start of code to set the default values
         foreach ($fields as $name => $field) {
             $index = $field['title'];
             $customFieldName = null;
             if ($name === 'organization_name') {
                 $values[$index] = $params[$name];
             }
             if ('state_province' == substr($name, 0, 14)) {
                 if ($params[$name]) {
                     $values[$index] = CRM_Core_PseudoConstant::stateProvince($params[$name]);
                 } else {
                     $values[$index] = '';
                 }
             } else {
                 if ('country' == substr($name, 0, 7)) {
                     if ($params[$name]) {
                         $values[$index] = CRM_Core_PseudoConstant::country($params[$name]);
                     } else {
                         $values[$index] = '';
                     }
                 } else {
                     if ('county' == substr($name, 0, 6)) {
                         if ($params[$name]) {
                             $values[$index] = CRM_Core_PseudoConstant::county($params[$name]);
                         } else {
                             $values[$index] = '';
                         }
                     } else {
                         if ('gender' == substr($name, 0, 6)) {
                             $gender = CRM_Core_PseudoConstant::gender();
                             $values[$index] = $gender[$params[$name]];
                         } else {
                             if ('individual_prefix' == substr($name, 0, 17)) {
                                 $prefix = CRM_Core_PseudoConstant::individualPrefix();
                                 $values[$index] = $prefix[$params[$name]];
                             } else {
                                 if ('individual_suffix' == substr($name, 0, 17)) {
                                     $suffix = CRM_Core_PseudoConstant::individualSuffix();
                                     $values[$index] = $suffix[$params[$name]];
                                 } else {
                                     if (in_array($name, array('addressee', 'email_greeting', 'postal_greeting'))) {
                                         $filterCondition = array('greeting_type' => $name);
                                         $greeting =& CRM_Core_PseudoConstant::greeting($filterCondition);
                                         $values[$index] = $greeting[$params[$name]];
                                     } else {
                                         if ($name === 'preferred_communication_method') {
                                             $communicationFields = CRM_Core_PseudoConstant::pcm();
                                             $pref = array();
                                             $compref = array();
                                             $pref = $params[$name];
                                             if (is_array($pref)) {
                                                 foreach ($pref as $k => $v) {
                                                     if ($v) {
                                                         $compref[] = $communicationFields[$k];
                                                     }
                                                 }
                                             }
                                             $values[$index] = implode(",", $compref);
                                         } else {
                                             if ($name == 'group') {
                                                 require_once 'CRM/Contact/BAO/GroupContact.php';
                                                 $groups = CRM_Contact_BAO_GroupContact::getGroupList();
                                                 $title = array();
                                                 foreach ($params[$name] as $gId => $dontCare) {
                                                     if ($dontCare) {
                                                         $title[] = $groups[$gId];
                                                     }
                                                 }
                                                 $values[$index] = implode(', ', $title);
                                             } else {
                                                 if ($name == 'tag') {
                                                     require_once 'CRM/Core/BAO/EntityTag.php';
                                                     $entityTags = $params[$name];
                                                     $allTags =& CRM_Core_PseudoConstant::tag();
                                                     $title = array();
                                                     if (is_array($entityTags)) {
                                                         foreach ($entityTags as $tagId => $dontCare) {
                                                             $title[] = $allTags[$tagId];
                                                         }
                                                     }
                                                     $values[$index] = implode(', ', $title);
                                                 } else {
                                                     if ('participant_role_id' == $name) {
                                                         $roles = CRM_Event_PseudoConstant::participantRole();
                                                         $values[$index] = $roles[$params[$name]];
                                                     } else {
                                                         if ('participant_status_id' == $name) {
                                                             $status = CRM_Event_PseudoConstant::participantStatus();
                                                             $values[$index] = $status[$params[$name]];
                                                         } else {
                                                             if (strpos($name, '-') !== false) {
                                                                 list($fieldName, $id) = CRM_Utils_System::explode('-', $name, 2);
                                                                 $detailName = str_replace(' ', '_', $name);
                                                                 if (in_array($fieldName, array('state_province', 'country', 'county'))) {
                                                                     $values[$index] = $params[$detailName];
                                                                     $idx = $detailName . '_id';
                                                                     $values[$index] = $params[$idx];
                                                                 } else {
                                                                     if ($fieldName == 'im') {
                                                                         $providerName = null;
                                                                         if ($providerId = $detailName . '-provider_id') {
                                                                             $providerName = CRM_Utils_Array::value($params[$providerId], $imProviders);
                                                                         }
                                                                         if ($providerName) {
                                                                             $values[$index] = $params[$detailName] . " (" . $providerName . ")";
                                                                         } else {
                                                                             $values[$index] = $params[$detailName];
                                                                         }
                                                                     } else {
                                                                         $values[$index] = $params[$detailName];
                                                                     }
                                                                 }
                                                             } else {
                                                                 if (substr($name, 0, 7) === 'do_not_' or substr($name, 0, 3) === 'is_') {
                                                                     if ($params[$name]) {
                                                                         $values[$index] = '[ x ]';
                                                                     }
                                                                 } else {
                                                                     require_once 'CRM/Core/BAO/CustomField.php';
                                                                     if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                                                                         $query = "\nSELECT html_type, data_type\nFROM   civicrm_custom_field\nWHERE  id = {$cfID}\n";
                                                                         $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
                                                                         $dao->fetch();
                                                                         $htmlType = $dao->html_type;
                                                                         $dataType = $dao->data_type;
                                                                         if ($htmlType == 'File') {
                                                                             //$fileURL = CRM_Core_BAO_CustomField::getFileURL( $contactID, $cfID );
                                                                             //$params[$index] = $values[$index] = $fileURL['file_url'];
                                                                             $values[$index] = $params[$index];
                                                                         } else {
                                                                             if ($dao->data_type == 'Int' || $dao->data_type == 'Boolean') {
                                                                                 $customVal = (int) $params[$name];
                                                                             } else {
                                                                                 if ($dao->data_type == 'Float') {
                                                                                     $customVal = (double) $params[$name];
                                                                                 } else {
                                                                                     if ($dao->data_type == 'Date') {
                                                                                         $date = CRM_Utils_Date::format($params[$name], null, 'invalidDate');
                                                                                         if ($date != 'invalidDate') {
                                                                                             $customVal = $date;
                                                                                         }
                                                                                     } else {
                                                                                         $customVal = $params[$name];
                                                                                     }
                                                                                 }
                                                                             }
                                                                             //take the custom field options
                                                                             $returnProperties = array($name => 1);
                                                                             require_once 'CRM/Contact/BAO/Query.php';
                                                                             $query = new CRM_Contact_BAO_Query($params, $returnProperties, $fields);
                                                                             $options =& $query->_options;
                                                                             $displayValue = CRM_Core_BAO_CustomField::getDisplayValue($customVal, $cfID, $options);
                                                                             //Hack since we dont have function to check empty.
                                                                             //FIXME in 2.3 using crmIsEmptyArray()
                                                                             $customValue = true;
                                                                             if (is_array($customVal) && is_array($displayValue)) {
                                                                                 $customValue = array_diff($customVal, $displayValue);
                                                                             }
                                                                             //use difference of arrays
                                                                             if (empty($customValue) || !$customValue) {
                                                                                 $values[$index] = '';
                                                                             } else {
                                                                                 $values[$index] = $displayValue;
                                                                             }
                                                                             if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $cfID, 'is_search_range')) {
                                                                                 $customFieldName = "{$name}_from";
                                                                             }
                                                                         }
                                                                     } else {
                                                                         if ($name == 'home_URL' && !empty($params[$name])) {
                                                                             $url = CRM_Utils_System::fixURL($params[$name]);
                                                                             $values[$index] = "<a href=\"{$url}\">{$params[$name]}</a>";
                                                                         } else {
                                                                             if (in_array($name, array('birth_date', 'deceased_date', 'participant_register_date'))) {
                                                                                 require_once 'CRM/Utils/Date.php';
                                                                                 $values[$index] = CRM_Utils_Date::customFormat(CRM_Utils_Date::format($params[$name]));
                                                                             } else {
                                                                                 $values[$index] = $params[$name];
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 28
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 function buildQuickForm()
 {
     // add the form elements
     require_once "CRM/Contribute/PseudoConstant.php";
     foreach ($this->_fields as $name => $field) {
         $required = $field['is_required'];
         if (substr($field['name'], 0, 14) === 'state_province') {
             $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required);
         } else {
             if (substr($field['name'], 0, 7) === 'country') {
                 $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required);
             } else {
                 if ($field['name'] === 'birth_date') {
                     $this->add('date', $field['name'], $field['title'], CRM_Core_SelectValues::date('birth'), $required);
                 } else {
                     if ($field['name'] === 'gender') {
                         $genderOptions = array();
                         $gender = CRM_Core_PseudoConstant::gender();
                         foreach ($gender as $key => $var) {
                             $genderOptions[$key] = HTML_QuickForm::createElement('radio', null, ts('Gender'), $var, $key);
                         }
                         $this->addGroup($genderOptions, $field['name'], $field['title']);
                         if ($required) {
                             $this->addRule($field['name'], ts('%1 is a required field.', array(1 => $field['title'])), 'required');
                         }
                     } else {
                         if ($field['name'] === 'individual_prefix') {
                             $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix(), $required);
                         } else {
                             if ($field['name'] === 'individual_suffix') {
                                 $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix(), $required);
                             } else {
                                 if ($field['name'] === 'preferred_communication_method') {
                                     $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_SelectValues::pcm());
                                 } else {
                                     if ($field['name'] === 'preferred_mail_format') {
                                         $this->add('select', $name, $field['title'], array(CRM_Core_SelectValues::pcm()));
                                     } else {
                                         if (substr($field['name'], 0, 7) === 'do_not_') {
                                             $this->add('checkbox', $name, $field['title'], $field['attributes'], $required);
                                         } else {
                                             if ($field['name'] === 'group') {
                                                 require_once 'CRM/Contact/Form/GroupTag.php';
                                                 CRM_Contact_Form_GroupTag::buildGroupTagBlock($this, $this->_id, CRM_CONTACT_FORM_GROUPTAG_GROUP, false, $required, $field['title'], null);
                                             } else {
                                                 if ($field['name'] === 'tag') {
                                                     require_once 'CRM/Contact/Form/GroupTag.php';
                                                     CRM_Contact_Form_GroupTag::buildGroupTagBlock($this, $this->_id, CRM_CONTACT_FORM_GROUPTAG_TAG, false, $required, null, $field['title']);
                                                 } else {
                                                     if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name'])) {
                                                         CRM_Core_BAO_CustomField::addQuickFormElement($this, $name, $customFieldID, $inactiveNeeded, $required, false, $field['title']);
                                                     } else {
                                                         if (in_array($field['name'], array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) {
                                                             $this->add('date', $field['name'], $field['title'], CRM_Core_SelectValues::date('manual', 3, 1), $required);
                                                         } else {
                                                             if ($field['name'] == 'payment_instrument') {
                                                                 $this->add('select', 'payment_instrument', ts('Paid By'), array('' => ts('-select-')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required);
                                                             } else {
                                                                 if ($field['name'] == 'contribution_type') {
                                                                     $this->add('select', 'contribution_type', ts('Contribution Type'), array('' => ts('-select-')) + CRM_Contribute_PseudoConstant::contributionType(), $required);
                                                                 } else {
                                                                     $this->add('text', $name, $field['title'], $field['attributes'], $required);
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done with Preview'), 'isDefault' => true)));
 }
Exemplo n.º 29
0
 function alterDisplay(&$rows)
 {
     // custom code to alter rows
     $genderList = CRM_Core_PseudoConstant::gender();
     $entryFound = false;
     foreach ($rows as $rowNum => $row) {
         // handle state province
         if (array_key_exists('civicrm_address_state_province_id', $row)) {
             if ($value = $row['civicrm_address_state_province_id']) {
                 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value);
             }
             $entryFound = true;
         }
         // handle country
         if (array_key_exists('civicrm_address_country_id', $row)) {
             if ($value = $row['civicrm_address_country_id']) {
                 $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value);
             }
             $entryFound = true;
         }
         // Handle contactType
         if (!empty($row[$this->_coreInfoTable . '_' . $this->_coreTypeCol])) {
             $rows[$rowNum][$this->_coreInfoTable . '_' . $this->_coreTypeCol] = $this->type2str($rows[$rowNum][$this->_coreInfoTable . '_' . $this->_coreTypeCol]);
             $entryFound = true;
         }
         // date of birth to age
         if (!empty($row['civicrm_contact_birth_date'])) {
             $rows[$rowNum]['civicrm_contact_birth_date'] = $this->dob2age($row['civicrm_contact_birth_date']);
             $entryFound = true;
         }
         // gender label
         if (!empty($row['civicrm_contact_gender_id'])) {
             $rows[$rowNum]['civicrm_contact_gender_id'] = $genderList[$row['civicrm_contact_gender_id']];
             $entryFound = true;
         }
         if ($this->_outputMode != 'html' && !empty($row[$this->_coreInfoTable . '_' . $this->_coreOtherCol])) {
             $rows[$rowNum]['civicrm_contact_display_name'] .= "<br />" . $row[$this->_coreInfoTable . '_' . $this->_coreOtherCol];
             $entryFound = true;
         }
         // skip looking further in rows, if first row itself doesn't
         // have the column we need
         if (!$entryFound) {
             break;
         }
     }
     $columnOrder = array('civicrm_phone_phone', 'civicrm_contact_display_name', 'civicrm_address_street_address', 'civicrm_contact_birth_date', 'civicrm_contact_gender_id', $this->_demoTable . '_' . $this->_demoLangCol, $this->_coreInfoTable . '_' . $this->_coreTypeCol, 'civicrm_contact_id');
     if ($this->_outputMode == 'print' || $this->_outputMode == 'pdf') {
         $this->_columnHeaders = array('civicrm_phone_phone' => array('title' => 'PHONE', 'type' => CRM_Utils_Type::T_STRING, 'class' => 'width=68'), 'civicrm_contact_display_name' => array('title' => 'NAME', 'type' => CRM_Utils_Type::T_STRING, 'class' => 'width=83'), 'civicrm_address_street_address' => array('title' => 'ADDRESS', 'type' => CRM_Utils_Type::T_STRING, 'class' => 'width=117'), 'civicrm_contact_birth_date' => array('title' => 'AGE', 'type' => CRM_Utils_Type::T_STRING, 'class' => 'width=25'), 'civicrm_contact_gender_id' => array('title' => 'SEX', 'type' => CRM_Utils_Type::T_STRING, 'class' => 'width=18'), $this->_demoTable . '_' . $this->_demoLangCol => array('title' => 'Lang', 'type' => CRM_Utils_Type::T_STRING, 'class' => 'width=27'), $this->_coreInfoTable . '_' . $this->_coreTypeCol => array('title' => 'Contact Type', 'type' => CRM_Utils_Type::T_STRING, 'class' => 'width=48'), 'notes' => array('title' => 'NOTES', 'type' => CRM_Utils_Type::T_STRING, 'class' => 'width=48'), 'response_codes' => array('title' => 'RESPONSE CODES', 'type' => CRM_Utils_Type::T_STRING, 'class' => 'width=91'), 'status' => array('title' => 'STATUS', 'type' => CRM_Utils_Type::T_STRING, 'class' => 'width=70'), 'civicrm_contact_id' => array('title' => 'ID', 'type' => CRM_Utils_Type::T_STRING, 'class' => 'width=100'));
         $newRows = array();
         foreach ($columnOrder as $col) {
             foreach ($rows as $rowNum => $row) {
                 $newRows[$rowNum][$col] = $row[$col];
                 $newRows[$rowNum]['notes'] = '&nbsp;';
                 $newRows[$rowNum]['status'] = 'NH&nbsp;MV&nbsp;D&nbsp;WN';
                 $newRows[$rowNum]['response_codes'] = '
     Q1&nbsp;&nbsp;&nbsp;&nbsp;Y&nbsp;&nbsp;&nbsp;&nbsp;N&nbsp;&nbsp;&nbsp;&nbsp;U&nbsp;&nbsp;&nbsp;&nbsp;D<br />
     Q2&nbsp;&nbsp;&nbsp;&nbsp;Y&nbsp;&nbsp;&nbsp;&nbsp;N&nbsp;&nbsp;&nbsp;&nbsp;U&nbsp;&nbsp;&nbsp;&nbsp;D<br />
     Q3&nbsp;&nbsp;&nbsp;&nbsp;Y&nbsp;&nbsp;&nbsp;&nbsp;N&nbsp;&nbsp;&nbsp;&nbsp;U&nbsp;&nbsp;&nbsp;&nbsp;D<br />
     Q4&nbsp;&nbsp;&nbsp;&nbsp;Y&nbsp;&nbsp;&nbsp;&nbsp;N&nbsp;&nbsp;&nbsp;&nbsp;U&nbsp;&nbsp;&nbsp;&nbsp;D';
             }
         }
         $rows = $newRows;
         $this->assign('pageTotal', ceil(count($newRows) / 7));
     } else {
         // make sure column order is same as in print mode
         $tempHeaders = $this->_columnHeaders;
         $this->_columnHeaders = array();
         foreach ($columnOrder as $col) {
             if (array_key_exists($col, $tempHeaders)) {
                 $this->_columnHeaders[$col] = $tempHeaders[$col];
                 unset($tempHeaders[$col]);
             }
         }
         $this->_columnHeaders = $this->_columnHeaders + $tempHeaders;
     }
 }
Exemplo n.º 30
0
 private function diffsInTable($table)
 {
     // caches for pretty field titles and value mappings
     static $titles = null;
     static $values = null;
     $params = array(1 => array($this->log_conn_id, 'Integer'), 2 => array($this->log_date, 'String'));
     // we look for the last change in the given connection that happended less than 10 seconds later than log_date to catch multi-query changes
     $changedSQL = "SELECT * FROM `{$this->loggingDB}`.`{$table}` WHERE log_conn_id = %1 AND log_date < DATE_ADD(%2, INTERVAL 10 SECOND) ORDER BY log_date DESC LIMIT 1";
     $changed = $this->sqlToArray($changedSQL, $params);
     // return early if nothing found
     if (empty($changed)) {
         return array();
     }
     // seed caches with civicrm_contact titles/values
     if (!isset($titles['log_civicrm_contact']) or !isset($values['log_civicrm_contact'])) {
         $titles['log_civicrm_contact'] = array('gender_id' => ts('Gender'), 'preferred_communication_method' => ts('Preferred Communication Method'), 'preferred_language' => ts('Preferred Language'), 'prefix_id' => ts('Prefix'), 'suffix_id' => ts('Suffix'));
         $values['log_civicrm_contact'] = array('gender_id' => CRM_Core_PseudoConstant::gender(), 'preferred_communication_method' => CRM_Core_PseudoConstant::pcm(), 'preferred_language' => CRM_Core_PseudoConstant::languages(), 'prefix_id' => CRM_Core_PseudoConstant::individualPrefix(), 'suffix_id' => CRM_Core_PseudoConstant::individualSuffix());
         require_once 'CRM/Contact/DAO/Contact.php';
         $dao = new CRM_Contact_DAO_Contact();
         foreach ($dao->fields() as $field) {
             if (!isset($titles['log_civicrm_contact'][$field['name']])) {
                 $titles['log_civicrm_contact'][$field['name']] = $field['title'];
             }
             if ($field['type'] == CRM_Utils_Type::T_BOOLEAN) {
                 $values['log_civicrm_contact'][$field['name']] = array('0' => ts('false'), '1' => ts('true'));
             }
         }
     }
     // add custom data titles/values for the given table
     if (!isset($titles[$table]) or !isset($values[$table])) {
         $titles[$table] = array();
         $values[$table] = array();
         $params[3] = array(substr($table, 4), 'String');
         $sql = "SELECT id, title FROM `{$this->loggingDB}`.log_civicrm_custom_group WHERE log_date <= %2 AND table_name = %3 ORDER BY log_date DESC LIMIT 1";
         $cgDao =& CRM_Core_DAO::executeQuery($sql, $params);
         $cgDao->fetch();
         $params[3] = array($cgDao->id, 'Integer');
         $sql = "SELECT column_name, data_type, label, name FROM `{$this->loggingDB}`.log_civicrm_custom_field WHERE log_date <= %2 AND custom_group_id = %3 ORDER BY log_date";
         $cfDao =& CRM_Core_DAO::executeQuery($sql, $params);
         while ($cfDao->fetch()) {
             $titles[$table][$cfDao->column_name] = "{$cgDao->title}: {$cfDao->label}";
             switch ($cfDao->data_type) {
                 case 'Boolean':
                     $values[$table][$cfDao->column_name] = array('0' => ts('false'), '1' => ts('true'));
                     break;
                 case 'String':
                     $values[$table][$cfDao->column_name] = array();
                     $params[3] = array("custom_{$cfDao->name}", 'String');
                     $sql = "SELECT id FROM `{$this->loggingDB}`.log_civicrm_option_group WHERE log_date <= %2 AND name = %3 ORDER BY log_date DESC LIMIT 1";
                     $ogId = CRM_Core_DAO::singleValueQuery($sql, $params);
                     $params[3] = array($ogId, 'Integer');
                     $sql = "SELECT label, value FROM `{$this->loggingDB}`.log_civicrm_option_value WHERE log_date <= %2 AND option_group_id = %3 ORDER BY log_date";
                     $ovDao =& CRM_Core_DAO::executeQuery($sql, $params);
                     while ($ovDao->fetch()) {
                         $values[$table][$cfDao->column_name][$ovDao->value] = $ovDao->label;
                     }
                     break;
             }
         }
     }
     // we look for the previous state (different log_conn_id) of the found id
     $params[3] = array($changed['id'], 'Integer');
     $originalSQL = "SELECT * FROM `{$this->loggingDB}`.`{$table}` WHERE log_conn_id != %1 AND log_date < %2 AND id = %3 ORDER BY log_date DESC LIMIT 1";
     $original = $this->sqlToArray($originalSQL, $params);
     $rows = array();
     // populate $rows with only the differences between $changed and $original (skipping certain columns and NULL ↔ empty changes)
     $skipped = array('entity_id', 'id', 'log_action', 'log_conn_id', 'log_date', 'log_user_id');
     foreach (array_keys(array_diff_assoc($changed, $original)) as $diff) {
         if (in_array($diff, $skipped)) {
             continue;
         }
         if ($original[$diff] == $changed[$diff]) {
             continue;
         }
         $rows[] = array('field' => isset($titles[$table][$diff]) ? $titles[$table][$diff] : substr($table, 4) . ".{$diff}", 'from' => isset($values[$table][$diff][$original[$diff]]) ? $values[$table][$diff][$original[$diff]] : $original[$diff], 'to' => isset($values[$table][$diff][$changed[$diff]]) ? $values[$table][$diff][$changed[$diff]] : $changed[$diff]);
     }
     return $rows;
 }