コード例 #1
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', '', '');
 }
コード例 #2
0
ファイル: Individual.php プロジェクト: bhirsch/voipdev
 /**
  * This function provides the HTML form elements that are specific to the Individual Contact Type
  * 
  * @access public
  * @return None 
  */
 public function buildQuickForm(&$form, $action = null)
 {
     $form->applyFilter('__ALL__', 'trim');
     //prefix
     $prefix = CRM_Core_PseudoConstant::individualPrefix();
     if (!empty($prefix)) {
         $form->addElement('select', 'prefix_id', ts('Prefix'), array('' => '') + $prefix);
     }
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact');
     // 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
     $suffix = CRM_Core_PseudoConstant::individualSuffix();
     if ($suffix) {
         $form->addElement('select', 'suffix_id', ts('Suffix'), array('' => '') + $suffix);
     }
     // nick_name
     $form->addElement('text', 'nick_name', ts('Nick Name'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'nick_name'));
     // job title
     // override the size for UI to look better
     $attributes['job_title']['size'] = 30;
     $form->addElement('text', 'job_title', ts('Job title'), $attributes['job_title'], 'size="30"');
     if ($action & CRM_Core_Action::UPDATE) {
         $mailToHouseholdID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $form->_contactId, 'mail_to_household_id', 'id');
         $form->assign('mailToHouseholdID', $mailToHouseholdID);
     }
     //Shared Address Element
     require_once 'CRM/Contact/BAO/ContactType.php';
     if (CRM_Contact_BAO_ContactType::isActive('Household')) {
         $label = CRM_Contact_BAO_ContactType::getLabel('Household');
         $form->addElement('checkbox', 'use_household_address', null, ts('Use %1 Address', array(1 => $label)));
     }
     $housholdDataURL = CRM_Utils_System::url('civicrm/ajax/search', "hh=1", false, null, false);
     $form->assign('housholdDataURL', $housholdDataURL);
     $form->add('text', 'shared_household', ts('Select Household'));
     $form->add('hidden', 'shared_household_id', '', array('id' => 'shared_household_id'));
     //Home Url Element
     $form->addElement('text', 'home_URL', ts('Website'), 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('home_URL', ts('Enter a valid web location beginning with \'http://\' or \'https://\'. EXAMPLE: http://www.mysite.org/'), 'url');
     //Current Employer Element
     $employerDataURL = CRM_Utils_System::url('civicrm/ajax/contactlist', 'org=1', false, null, false);
     $form->assign('employerDataURL', $employerDataURL);
     $form->addElement('text', 'current_employer', ts('Current Employer'), '');
     $form->addElement('hidden', 'current_employer_id', '', array('id' => 'current_employer_id'));
     $form->addElement('text', 'contact_source', ts('Source'));
     //External Identifier Element
     $form->add('text', 'external_identifier', ts('External Id'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'external_identifier'), false);
     $form->addRule('external_identifier', ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier'));
     $config =& CRM_Core_Config::singleton();
     CRM_Core_ShowHideBlocks::links($form, 'demographics', '', '');
 }
コード例 #3
0
/**
 * 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');
}
コード例 #4
0
 /**
  * This function provides the HTML form elements that are specific to the Individual Contact Type
  *
  * @access public
  *
  * @return None
  */
 public function buildQuickForm(&$form, $action = NULL)
 {
     $form->applyFilter('__ALL__', 'trim');
     //prefix
     $prefix = CRM_Core_PseudoConstant::individualPrefix();
     if (!empty($prefix)) {
         $form->addElement('select', 'prefix_id', ts('Prefix'), array('' => '') + $prefix);
     }
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact');
     // 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
     $suffix = CRM_Core_PseudoConstant::individualSuffix();
     if ($suffix) {
         $form->addElement('select', 'suffix_id', ts('Suffix'), array('' => '') + $suffix);
     }
     // nick_name
     $form->addElement('text', 'nick_name', ts('Nick Name'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'nick_name'));
     // job title
     // override the size for UI to look better
     $attributes['job_title']['size'] = 30;
     $form->addElement('text', 'job_title', ts('Job title'), $attributes['job_title'], 'size="30"');
     //Current Employer Element
     $employerDataURL = CRM_Utils_System::url('civicrm/ajax/rest', 'className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=contact&org=1&employee_id=' . $this->_contactId, FALSE, NULL, FALSE);
     $form->assign('employerDataURL', $employerDataURL);
     $form->addElement('text', 'current_employer', ts('Current Employer'), '');
     $form->addElement('hidden', 'current_employer_id', '', array('id' => 'current_employer_id'));
     $form->addElement('text', 'contact_source', ts('Source'));
     $checkSimilar = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_ajax_check_similar', NULL, TRUE);
     if ($checkSimilar == null) {
         $checkSimilar = 0;
     }
     $form->assign('checkSimilar', $checkSimilar);
     //External Identifier Element
     $form->add('text', 'external_identifier', ts('External Id'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'external_identifier'), FALSE);
     $form->addRule('external_identifier', ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier'));
     $config = CRM_Core_Config::singleton();
     CRM_Core_ShowHideBlocks::links($form, 'demographics', '', '');
 }
コード例 #5
0
 function __construct()
 {
     self::$nscd_fid = _iats_civicrm_nscd_fid();
     self::$version = _iats_civicrm_domain_info('version');
     self::$financial_types = self::$version[0] <= 4 && self::$version[1] <= 2 ? array() : CRM_Contribute_PseudoConstant::financialType();
     if (self::$version[0] <= 4 && self::$version[1] < 4) {
         self::$prefixes = CRM_Core_PseudoConstant::individualPrefix();
         self::$contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus();
     } else {
         self::$prefixes = CRM_Contact_BAO_Contact::buildOptions('individual_prefix_id');
         self::$contributionStatus = CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id');
     }
     $params = array('version' => 3, 'sequential' => 1, 'is_test' => 0, 'return.name' => 1);
     $result = civicrm_api('PaymentProcessor', 'get', $params);
     foreach ($result['values'] as $pp) {
         self::$processors[$pp['id']] = $pp['name'];
     }
     $this->_columns = array('civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'order_bys' => array('sort_name' => array('title' => ts("Last name, First name"))), 'fields' => array('first_name' => array('title' => ts('First Name')), 'last_name' => array('title' => ts('Last Name')), 'prefix_id' => array('title' => ts('Prefix')), 'sort_name' => array('title' => ts('Contact Name'), 'no_repeat' => TRUE, 'default' => TRUE), 'id' => array('no_display' => TRUE, 'required' => TRUE))), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'order_bys' => array('email' => array('title' => ts('Email'))), 'fields' => array('email' => array('title' => ts('Email'), 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('phone' => array('title' => ts('Phone'), 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_contribution' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'fields' => array('id' => array('title' => ts('Contribution ID(s)'), 'required' => TRUE, 'dbAlias' => "GROUP_CONCAT(contribution_civireport.id SEPARATOR ', ')"), 'total_amount' => array('title' => ts('Amount Contributed to date'), 'required' => TRUE, 'statistics' => array('sum' => ts("Total Amount contributed")))), 'filters' => array('total_amount' => array('title' => ts('Total Amount'), 'operatorType' => CRM_Report_Form::OP_FLOAT, 'type' => CRM_Utils_Type::T_FLOAT))), 'civicrm_iats_customer_codes' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'order_bys' => array('expiry' => array('title' => ts("Expiry Date"))), 'fields' => array('customer_code' => array('title' => 'customer code', 'default' => TRUE), 'expiry' => array('title' => 'Expiry Date', 'default' => TRUE))), 'civicrm_contribution_recur' => array('dao' => 'CRM_Contribute_DAO_ContributionRecur', 'order_bys' => array('id' => array('title' => ts("Series ID")), 'amount' => array('title' => ts("Current Amount")), 'start_date' => array('title' => ts('Start Date')), 'modified_date' => array('title' => ts('Modified Date')), self::$nscd_fid => array('title' => ts('Next Scheduled Contribution Date')), 'cycle_day' => array('title' => ts('Cycle Day')), 'payment_processor_id' => array('title' => ts('Payment Processor'))), 'fields' => array('id' => array('required' => TRUE, 'title' => ts("Series ID")), 'recur_id' => array('name' => 'id', 'title' => ts('Series ID')), 'invoice_id' => array('title' => ts('Invoice ID'), 'default' => FALSE), 'currency' => array('title' => ts("Currency")), 'amount' => array('title' => ts('Amount'), 'default' => TRUE), 'contribution_status_id' => array('title' => ts('Donation Status')), 'frequency_interval' => array('title' => ts('Frequency interval'), 'default' => TRUE), 'frequency_unit' => array('title' => ts('Frequency unit'), 'default' => TRUE), 'installments' => array('title' => ts('Installments'), 'default' => TRUE), 'start_date' => array('title' => ts('Start Date'), 'default' => TRUE), 'create_date' => array('title' => ts('Create Date')), 'modified_date' => array('title' => ts('Modified Date')), 'cancel_date' => array('title' => ts('Cancel Date')), self::$nscd_fid => array('title' => ts('Next Scheduled Contribution Date'), 'default' => TRUE), 'next_scheduled_day' => array('name' => self::$nscd_fid, 'dbAlias' => 'DAYOFMONTH(contribution_recur_civireport.next_sched_contribution)', 'title' => ts('Next Scheduled Day of the Month')), 'cycle_day' => array('title' => ts('Cycle Day')), 'failure_count' => array('title' => ts('Failure Count')), 'failure_retry_date' => array('title' => ts('Failure Retry Date')), 'payment_processor_id' => array('title' => ts('Payment Processor'), 'default' => TRUE)), 'filters' => array('contribution_status_id' => array('title' => ts('Donation Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => self::$contributionStatus, 'default' => array(5), 'type' => CRM_Utils_Type::T_INT), 'payment_processor_id' => array('title' => ts('Payment Processor'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => self::$processors, 'type' => CRM_Utils_Type::T_INT), 'currency' => array('title' => 'Currency', 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_OptionGroup::values('currencies_enabled'), 'default' => NULL, 'type' => CRM_Utils_Type::T_STRING), 'financial_type_id' => array('title' => ts('Financial Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => self::$financial_types, 'type' => CRM_Utils_Type::T_INT), 'frequency_unit' => array('title' => ts('Frequency Unit'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_OptionGroup::values('recur_frequency_units')), self::$nscd_fid => array('title' => ts('Next Scheduled Contribution Date'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE), 'next_scheduled_day' => array('title' => ts('Next Scheduled Day'), 'operatorType' => CRM_Report_Form::OP_INT, 'type' => CRM_Utils_Type::T_INT), 'cycle_day' => array('title' => ts('Cycle Day'), 'operatorType' => CRM_Report_Form::OP_INT, 'type' => CRM_Utils_Type::T_INT), 'start_date' => array('title' => ts('Start Date'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE), 'modified_date' => array('title' => ts('Modified Date'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE), 'cancel_date' => array('title' => ts('Cancel Date'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE))), 'civicrm_address' => array('dao' => 'CRM_Core_DAO_Address', 'fields' => array('street_address' => array('title' => ts('Address'), 'default' => FALSE), 'supplemental_address_1' => array('title' => ts('Supplementary Address Field 1'), 'default' => FALSE), 'supplemental_address_2' => array('title' => ts('Supplementary Address Field 2'), 'default' => FALSE), 'city' => array('title' => 'City', 'default' => FALSE), 'state_province_id' => array('title' => 'Province', 'default' => FALSE, 'alter_display' => 'alterStateProvinceID'), 'postal_code' => array('title' => 'Postal Code', 'default' => FALSE), 'country_id' => array('title' => 'Country', 'default' => FALSE, 'alter_display' => 'alterCountryID')), 'grouping' => 'contact-fields'));
     if (empty(self::$financial_types)) {
         unset($this->_columns['civicrm_contribution_recur']['filters']['financial_type_id']);
     }
     parent::__construct();
 }
コード例 #6
0
ファイル: Utils.php プロジェクト: hampelm/Ginsberg-CiviDemo
 /**
  * Function to build form for related contacts / on behalf of organization.
  * 
  * @param $form              object  invoking Object
  * @param $contactType       string  contact type
  * @param $title             string  fieldset title
  * @param $maxLocationBlocks int     number of location blocks
  * 
  * @static
  *
  */
 static function buildOnBehalfForm(&$form, $contactType = 'Individual', $countryID = null, $stateID = null, $title = 'Contact Information', $contactEditMode = false, $maxLocationBlocks = 1)
 {
     if ($title == 'Contact Information') {
         $title = ts('Contact Information');
     }
     require_once 'CRM/Contact/Form/Location.php';
     $config = CRM_Core_Config::singleton();
     $form->assign('contact_type', $contactType);
     $form->assign('fieldSetTitle', $title);
     $form->assign('contactEditMode', $contactEditMode);
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact');
     switch ($contactType) {
         case 'Organization':
             $session = CRM_Core_Session::singleton();
             $contactID = $session->get('userID');
             if ($contactID) {
                 require_once 'CRM/Contact/BAO/Relationship.php';
                 $employers = CRM_Contact_BAO_Relationship::getPermissionedEmployer($contactID);
             }
             if (!$contactEditMode && $contactID && count($employers) >= 1) {
                 $locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', "cid=", false, null, false);
                 $form->assign('locDataURL', $locDataURL);
                 $dataURL = CRM_Utils_System::url('civicrm/ajax/employer', "cid=" . $contactID, false, null, false);
                 $form->assign('employerDataURL', $dataURL);
                 $form->add('text', 'organization_id', ts('Select an existing related Organization OR Enter a new one'));
                 $form->add('hidden', 'onbehalfof_id', '', array('id' => 'onbehalfof_id'));
                 $orgOptions = array('0' => ts('Create new organization'), '1' => ts('Select existing organization'));
                 $orgOptionExtra = array('onclick' => "showHideByValue('org_option','true','select_org','table-row','radio',true);showHideByValue('org_option','true','create_org','table-row','radio',false);");
                 $form->addRadio('org_option', ts('options'), $orgOptions, $orgOptionExtra);
                 $form->assign('relatedOrganizationFound', true);
             }
             $isRequired = false;
             if (CRM_Utils_Array::value('is_for_organization', $form->_values) == 2) {
                 $isRequired = true;
             }
             $form->add('text', 'organization_name', ts('Organization Name'), $attributes['organization_name'], $isRequired);
             break;
         case 'Household':
             $form->add('text', 'household_name', ts('Household Name'), $attributes['household_name']);
             break;
         default:
             // individual
             $form->addElement('select', 'prefix_id', ts('Prefix'), array('' => ts('- prefix -')) + CRM_Core_PseudoConstant::individualPrefix());
             $form->addElement('text', 'first_name', ts('First Name'), $attributes['first_name']);
             $form->addElement('text', 'middle_name', ts('Middle Name'), $attributes['middle_name']);
             $form->addElement('text', 'last_name', ts('Last Name'), $attributes['last_name']);
             $form->addElement('select', 'suffix_id', ts('Suffix'), array('' => ts('- suffix -')) + CRM_Core_PseudoConstant::individualSuffix());
     }
     $addressSequence = $config->addressSequence();
     $form->assign('addressSequence', array_fill_keys($addressSequence, 1));
     //Primary Phone
     $form->addElement('text', "phone[1][phone]", ts('Primary Phone'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone'));
     //Primary Email
     $form->addElement('text', "email[1][email]", ts('Primary Email'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', 'email'));
     //build the address block
     require_once 'CRM/Contact/Form/Edit/Address.php';
     CRM_Contact_Form_Edit_Address::buildQuickForm($form);
     // also fix the state country selector
     CRM_Contact_Form_Edit_Address::fixStateSelect($form, "address[1][country_id]", "address[1][state_province_id]", $countryID);
 }
コード例 #7
0
 /**
  * Get all Individual Prefix.
  *
  * The static array individualPrefix is returned
  *
  * @access public
  * @static
  *
  * @param boolean $all - get All Individual Prefix - default is to get only active ones.
  *
  * @return array - array reference of all individual prefix.
  *
  */
 public static function &individualPrefix()
 {
     if (!self::$individualPrefix) {
         require_once 'CRM/Core/OptionGroup.php';
         self::$individualPrefix = CRM_Core_OptionGroup::values('individual_prefix');
     }
     return self::$individualPrefix;
 }
コード例 #8
0
 /**
  * Create the Honor contact
  *
  * @return void
  * @access public
  */
 function createHonorContact()
 {
     $params = $this->controller->exportValues('Main');
     // email is enough to create a contact
     if (!CRM_Utils_Array::value('honor_email', $params) && (!CRM_Utils_Array::value('honor_first_name', $params) || !CRM_Utils_Array::value('honor_last_name', $params))) {
         //don't create contact - possibly the form was left blank
         return null;
     }
     //assign to template for email receipt
     $honor_block_is_active = $this->get('honor_block_is_active');
     $this->assign('honor_block_is_active', $honor_block_is_active);
     $this->assign('honor_block_title', CRM_Utils_Array::value('honor_block_title', $this->_values));
     $prefix = CRM_Core_PseudoConstant::individualPrefix();
     $honorType = CRM_Core_PseudoConstant::honor();
     $this->assign('honor_type', CRM_Utils_Array::value(CRM_Utils_Array::value('honor_type_id', $params), $honorType));
     $this->assign('honor_prefix', CRM_Utils_Array::value(CRM_Utils_Array::value('honor_prefix_id', $params), $prefix));
     $this->assign('honor_first_name', CRM_Utils_Array::value('honor_first_name', $params));
     $this->assign('honor_last_name', CRM_Utils_Array::value('honor_last_name', $params));
     $this->assign('honor_email', CRM_Utils_Array::value('honor_email', $params));
     //create honoree contact
     return CRM_Contribute_BAO_Contribution::createHonorContact($params);
 }
コード例 #9
0
ファイル: Individual.php プロジェクト: bhirsch/voipdev
 /**
  * creates display name
  *
  * @return string  the constructed display name
  */
 function displayName()
 {
     $prefix =& CRM_Core_PseudoConstant::individualPrefix();
     $suffix =& CRM_Core_PseudoConstant::individualSuffix();
     return str_replace('  ', ' ', trim($prefix[$this->prefix_id] . ' ' . $this->first_name . ' ' . $this->middle_name . ' ' . $this->last_name . ' ' . $suffix[$this->suffix_id]));
 }
コード例 #10
0
ファイル: Query.php プロジェクト: bhirsch/voipdrupal-4.7-1.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);
 }
コード例 #11
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;
}
コード例 #12
0
ファイル: utils.php プロジェクト: ksecor/civicrm
/**
 * 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;
            }
        }
    }
}
コード例 #13
0
 /** 
  * Function to send email receipt.
  * 
  * @form object  of Contribution form.
  * @param array  $params (reference ) an assoc array of name/value pairs.
  * @$ccContribution boolen,  is it credit card contribution.
  * @access public. 
  * @return None.
  */
 function emailReceipt(&$form, &$params, $ccContribution = false)
 {
     $this->assign('receiptType', 'contribution');
     // Retrieve Contribution Type Name from contribution_type_id
     $params['contributionType_name'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionType', $params['contribution_type_id']);
     if (CRM_Utils_Array::value('payment_instrument_id', $params)) {
         require_once 'CRM/Contribute/PseudoConstant.php';
         $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
         $params['paidBy'] = $paymentInstrument[$params['payment_instrument_id']];
     }
     // retrieve individual prefix value for honoree
     if (CRM_Utils_Array::value('hidden_Honoree', $params)) {
         $individualPrefix = CRM_Core_PseudoConstant::individualPrefix();
         $honor = CRM_Core_PseudoConstant::honor();
         $params['honor_prefix'] = CRM_Utils_Array::value($params['honor_prefix_id'], $individualPrefix);
         $params["honor_type"] = CRM_Utils_Array::value($params["honor_type_id"], $honor);
     }
     // retrieve premium product name and assigned fulfilled
     // date to template
     if (CRM_Utils_Array::value('hidden_Premium', $params)) {
         if (CRM_Utils_Array::value($params['product_name'][0], $form->_options)) {
             $params['product_option'] = $form->_options[$params['product_name'][0]][$params['product_name'][1]];
         }
         //fix for crm-4584
         if (!empty($params['product_name'])) {
             require_once 'CRM/Contribute/DAO/Product.php';
             $productDAO = new CRM_Contribute_DAO_Product();
             $productDAO->id = $params['product_name'][0];
             $productDAO->find(true);
             $params['product_name'] = $productDAO->name;
             $params['product_sku'] = $productDAO->sku;
         }
         $this->assign('fulfilled_date', CRM_Utils_Date::processDate($params['fulfilled_date']));
     }
     $this->assign('ccContribution', $ccContribution);
     if ($ccContribution) {
         //build the name.
         $name = CRM_Utils_Array::value('billing_first_name', $params);
         if (CRM_Utils_Array::value('billing_middle_name', $params)) {
             $name .= " {$params['billing_middle_name']}";
         }
         $name .= ' ' . CRM_Utils_Array::value('billing_last_name', $params);
         $name = trim($name);
         $this->assign('billingName', $name);
         //assign the address formatted up for display
         $addressParts = array("street_address" => "billing_street_address-{$form->_bltID}", "city" => "billing_city-{$form->_bltID}", "postal_code" => "billing_postal_code-{$form->_bltID}", "state_province" => "state_province-{$form->_bltID}", "country" => "country-{$form->_bltID}");
         $addressFields = array();
         foreach ($addressParts as $name => $field) {
             $addressFields[$name] = CRM_Utils_Array::value($field, $params);
         }
         require_once 'CRM/Utils/Address.php';
         $this->assign('address', CRM_Utils_Address::format($addressFields));
         $date = CRM_Utils_Date::format($params['credit_card_exp_date']);
         $date = CRM_Utils_Date::mysqlToIso($date);
         $this->assign('credit_card_type', CRM_Utils_Array::value('credit_card_type', $params));
         $this->assign('credit_card_exp_date', $date);
         $this->assign('credit_card_number', CRM_Utils_System::mungeCreditCard($params['credit_card_number']));
     } else {
         //offline contribution
         //Retrieve the name and email from receipt is to be send
         $params['receipt_from_name'] = $form->userDisplayName;
         $params['receipt_from_email'] = $form->userEmail;
         // assigned various dates to the templates
         $form->assign('receipt_date', CRM_Utils_Date::processDate($params['receipt_date']));
         $form->assign('cancel_date', CRM_Utils_Date::processDate($params['cancel_date']));
         if (CRM_Utils_Array::value('thankyou_date', $params)) {
             $form->assign('thankyou_date', CRM_Utils_Date::processDate($params['thankyou_date']));
         }
         if ($form->_action & CRM_Core_Action::UPDATE) {
             $form->assign('lineItem', empty($form->_lineItems) ? false : $form->_lineItems);
         }
     }
     //handle custom data
     if (CRM_Utils_Array::value('hidden_custom', $params)) {
         $contribParams = array(array('contribution_id', '=', $params['contribution_id'], 0, 0));
         if ($form->_mode == 'test') {
             $contribParams[] = array('contribution_test', '=', 1, 0, 0);
         }
         //retrieve custom data
         require_once "CRM/Core/BAO/UFGroup.php";
         $customGroup = array();
         foreach ($form->_groupTree as $groupID => $group) {
             $customFields = $customValues = array();
             if ($groupID == 'info') {
                 continue;
             }
             foreach ($group['fields'] as $k => $field) {
                 $field['title'] = $field['label'];
                 $customFields["custom_{$k}"] = $field;
             }
             //build the array of customgroup contain customfields.
             CRM_Core_BAO_UFGroup::getValues($params['contact_id'], $customFields, $customValues, false, $contribParams);
             $customGroup[$group['title']] = $customValues;
         }
         //assign all custom group and corresponding fields to template.
         $form->assign('customGroup', $customGroup);
     }
     $form->assign_by_ref('formValues', $params);
     require_once 'CRM/Contact/BAO/Contact/Location.php';
     require_once 'CRM/Utils/Mail.php';
     list($contributorDisplayName, $contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($params['contact_id']);
     $this->assign('contactID', $params['contact_id']);
     $this->assign('contributionID', $params['contribution_id']);
     $this->assign('currency', $params['currency']);
     $this->assign('receive_date', CRM_Utils_Date::processDate($params['receive_date']));
     $session = CRM_Core_Session::singleton();
     $userID = $session->get('userID');
     list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID);
     require_once 'CRM/Core/BAO/MessageTemplates.php';
     list($sendReceipt, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_contribution', 'valueName' => 'contribution_offline_receipt', 'contactId' => $params['contact_id'], 'from' => "{$userName} <{$userEmail}>", 'toName' => $contributorDisplayName, 'toEmail' => $contributorEmail, 'isTest' => $form->_mode == 'test'));
     return $sendReceipt;
 }
コード例 #14
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);
         }
     }
 }
コード例 #15
0
 /**
  * Function to add the honor block
  *
  * @return None
  * @access public
  */
 function buildHonorBlock()
 {
     $this->assign('honor_block_is_active', TRUE);
     $this->set('honor_block_is_active', TRUE);
     $this->assign('honor_block_title', CRM_Utils_Array::value('honor_block_title', $this->_values));
     $this->assign('honor_block_text', CRM_Utils_Array::value('honor_block_text', $this->_values));
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact');
     $extraOption = array('onclick' => "enableHonorType();");
     // radio button for Honor Type
     $honorOptions = array();
     $honor = CRM_Core_PseudoConstant::honor();
     foreach ($honor as $key => $var) {
         $honorTypes[$key] = $this->createElement('radio', NULL, NULL, $var, $key, $extraOption);
     }
     $this->addGroup($honorTypes, 'honor_type_id', NULL);
     // prefix
     $this->addElement('select', 'honor_prefix_id', ts('Prefix'), array('' => ts('- prefix -')) + CRM_Core_PseudoConstant::individualPrefix());
     // first_name
     $this->addElement('text', 'honor_first_name', ts('First Name'), $attributes['first_name']);
     //last_name
     $this->addElement('text', 'honor_last_name', ts('Last Name'), $attributes['last_name']);
     //email
     $this->addElement('text', 'honor_email', ts('Email Address'));
     $this->addRule('honor_email', ts('Honoree Email is not valid.'), 'email');
 }
コード例 #16
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;
 }
コード例 #17
0
ファイル: Contact.php プロジェクト: ksecor/civicrm
 /**
  *
  * 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);
         }
     }
 }
コード例 #18
0
ファイル: BaseIPN.php プロジェクト: bhirsch/voipdev
 function sendMail(&$input, &$ids, &$objects, &$values, $recur = false, $returnMessageText = false)
 {
     $contribution =& $objects['contribution'];
     $membership =& $objects['membership'];
     $participant =& $objects['participant'];
     $event =& $objects['event'];
     if (empty($values)) {
         $values = array();
         if ($input['component'] == 'contribute') {
             require_once 'CRM/Contribute/BAO/ContributionPage.php';
             if (isset($contribution->contribution_page_id)) {
                 CRM_Contribute_BAO_ContributionPage::setValues($contribution->contribution_page_id, $values);
             } else {
                 // Handle re-print receipt for offline contributions (call from PDF.php - no contribution_page_id)
                 $values['is_email_receipt'] = 1;
                 $values['title'] = 'Contribution';
             }
         } else {
             // event
             $eventParams = array('id' => $objects['event']->id);
             $values['event'] = array();
             require_once 'CRM/Event/BAO/Event.php';
             CRM_Event_BAO_Event::retrieve($eventParams, $values['event']);
             $eventParams = array('id' => $objects['event']->id);
             $values['event'] = array();
             require_once 'CRM/Event/BAO/Event.php';
             CRM_Event_BAO_Event::retrieve($eventParams, $values['event']);
             //get location details
             $locationParams = array('entity_id' => $objects['event']->id, 'entity_table' => 'civicrm_event');
             require_once 'CRM/Core/BAO/Location.php';
             require_once 'CRM/Event/Form/ManageEvent/Location.php';
             $values['location'] = CRM_Core_BAO_Location::getValues($locationParams);
             require_once 'CRM/Core/BAO/UFJoin.php';
             $ufJoinParams = array('entity_table' => 'civicrm_event', 'entity_id' => $ids['event'], 'weight' => 1);
             $values['custom_pre_id'] = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParams);
             $ufJoinParams['weight'] = 2;
             $values['custom_post_id'] = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParams);
         }
     }
     $template =& CRM_Core_Smarty::singleton();
     // CRM_Core_Error::debug('tpl',$template);
     //assign honor infomation to receiptmessage
     if ($honarID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contribution->id, 'honor_contact_id')) {
         $honorDefault = array();
         $honorIds = array();
         $honorIds['contribution'] = $contribution->id;
         $idParams = array('id' => $honarID, 'contact_id' => $honarID);
         require_once "CRM/Contact/BAO/Contact.php";
         CRM_Contact_BAO_Contact::retrieve($idParams, $honorDefault, $honorIds);
         require_once "CRM/Core/PseudoConstant.php";
         $honorType = CRM_Core_PseudoConstant::honor();
         $prefix = CRM_Core_PseudoConstant::individualPrefix();
         $template->assign('honor_block_is_active', 1);
         $template->assign('honor_prefix', $prefix[$honorDefault["prefix_id"]]);
         $template->assign('honor_first_name', CRM_Utils_Array::value("first_name", $honorDefault));
         $template->assign('honor_last_name', CRM_Utils_Array::value("last_name", $honorDefault));
         $template->assign('honor_email', CRM_Utils_Array::value("email", $honorDefault["email"][1]));
         $template->assign('honor_type', $honorType[$contribution->honor_type_id]);
     }
     require_once 'CRM/Contribute/DAO/ContributionProduct.php';
     $dao =& new CRM_Contribute_DAO_ContributionProduct();
     $dao->contribution_id = $contribution->id;
     if ($dao->find(true)) {
         $premiumId = $dao->product_id;
         $template->assign('option', $dao->product_option);
         require_once 'CRM/Contribute/DAO/Product.php';
         $productDAO =& new CRM_Contribute_DAO_Product();
         $productDAO->id = $premiumId;
         $productDAO->find(true);
         $template->assign('selectPremium', true);
         $template->assign('product_name', $productDAO->name);
         $template->assign('price', $productDAO->price);
         $template->assign('sku', $productDAO->sku);
     }
     // add the new contribution values
     if ($input['component'] == 'contribute') {
         $template->assign('title', $values['title']);
         $template->assign('amount', $input['amount']);
         //PCP Info
         require_once 'CRM/Contribute/DAO/ContributionSoft.php';
         $softDAO =& new CRM_Contribute_DAO_ContributionSoft();
         $softDAO->contribution_id = $contribution->id;
         if ($softDAO->find(true)) {
             $template->assign('pcpBlock', true);
             $template->assign('pcp_display_in_roll', $softDAO->pcp_display_in_roll);
             $template->assign('pcp_roll_nickname', $softDAO->pcp_roll_nickname);
             $template->assign('pcp_personal_note', $softDAO->pcp_personal_note);
             //assign the pcp page title for email subject
             require_once 'CRM/Contribute/DAO/PCP.php';
             $pcpDAO =& new CRM_Contribute_DAO_PCP();
             $pcpDAO->id = $softDAO->pcp_id;
             if ($pcpDAO->find(true)) {
                 $template->assign('title', $pcpDAO->title);
             }
         }
     } else {
         $template->assign('title', $values['event']['title']);
         $template->assign('totalAmount', $input['amount']);
     }
     $template->assign('trxn_id', $contribution->trxn_id);
     $template->assign('receive_date', CRM_Utils_Date::mysqlToIso($contribution->receive_date));
     $template->assign('contributeMode', 'notify');
     $template->assign('action', $contribution->is_test ? 1024 : 1);
     $template->assign('receipt_text', CRM_Utils_Array::value('receipt_text', $values));
     $template->assign('is_monetary', 1);
     $template->assign('is_recur', $recur);
     if ($recur) {
         require_once 'CRM/Core/Payment.php';
         $paymentObject =& CRM_Core_Payment::singleton($contribution->is_test ? 'test' : 'live', 'Contribute', $objects['paymentProcessor']);
         $url = $paymentObject->cancelSubscriptionURL();
         $template->assign('cancelSubscriptionUrl', $url);
         if ($objects['paymentProcessor']['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM) {
             //direct mode showing billing block, so use directIPN for temporary
             $template->assign('contributeMode', 'directIPN');
         }
     }
     require_once 'CRM/Utils/Address.php';
     $template->assign('address', CRM_Utils_Address::format($input));
     if ($input['component'] == 'event') {
         require_once 'CRM/Core/OptionGroup.php';
         $participant_role = CRM_Core_OptionGroup::values('participant_role');
         $values['event']['participant_role'] = $participant_role[$participant->role_id];
         $template->assign('event', $values['event']);
         $template->assign('location', $values['location']);
         $template->assign('customPre', $values['custom_pre_id']);
         $template->assign('customPost', $values['custom_post_id']);
         $isTest = false;
         if ($participant->is_test) {
             $isTest = true;
         }
         $values['params'] = array();
         require_once "CRM/Event/BAO/Event.php";
         //to get email of primary participant.
         $primaryEmail = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Email', $participant->contact_id, 'email', 'contact_id');
         $primaryAmount[] = array('label' => $participant->fee_level . ' - ' . $primaryEmail, 'amount' => $participant->fee_amount);
         //build an array of cId/pId of participants
         $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($participant->id, null, $ids['contact'], $isTest, true);
         unset($additionalIDs[$participant->id]);
         //send receipt to additional participant if exists
         if (count($additionalIDs)) {
             $template->assign('isPrimary', 0);
             $template->assign('customProfile', null);
             //set additionalParticipant true
             $values['params']['additionalParticipant'] = true;
             foreach ($additionalIDs as $pId => $cId) {
                 $amount = array();
                 //to change the status pending to completed
                 $additional =& new CRM_Event_DAO_Participant();
                 $additional->id = $pId;
                 $additional->contact_id = $cId;
                 $additional->find(true);
                 $additional->register_date = $participant->register_date;
                 $additional->status_id = 1;
                 $additionalParticipantInfo = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Email', $additional->contact_id, 'email', 'contact_id');
                 //if additional participant dont have email
                 //use display name.
                 if (!$additionalParticipantInfo) {
                     require_once "CRM/Contact/BAO/Contact.php";
                     $additionalParticipantInfo = CRM_Contact_BAO_Contact::displayName($additional->contact_id);
                 }
                 $amount[0] = array('label' => $additional->fee_level, 'amount' => $additional->fee_amount);
                 $primaryAmount[] = array('label' => $additional->fee_level . ' - ' . $additionalParticipantInfo, 'amount' => $additional->fee_amount);
                 $additional->save();
                 $additional->free();
                 $template->assign('amount', $amount);
                 CRM_Event_BAO_Event::sendMail($cId, $values, $pId, $isTest, $returnMessageText);
             }
         }
         //build an array of custom profile and assigning it to template
         $customProfile = CRM_Event_BAO_Event::buildCustomProfile($participant->id, $values, null, $isTest);
         if (count($customProfile)) {
             $template->assign('customProfile', $customProfile);
         }
         // for primary contact
         $values['params']['additionalParticipant'] = false;
         $template->assign('isPrimary', 1);
         $template->assign('amount', $primaryAmount);
         // carry paylater, since we did not created billing,
         // so need to pull email from primary location, CRM-4395
         $values['params']['is_pay_later'] = $participant->is_pay_later;
         return CRM_Event_BAO_Event::sendMail($ids['contact'], $values, $participant->id, $isTest, $returnMessageText);
     } else {
         if ($membership) {
             $values['membership_id'] = $membership->id;
             // need to set the membership values here
             $template->assign('membership_assign', 1);
             require_once 'CRM/Member/PseudoConstant.php';
             $template->assign('membership_name', CRM_Member_PseudoConstant::membershipType($membership->membership_type_id));
             $template->assign('mem_start_date', $membership->start_date);
             $template->assign('mem_end_date', $membership->end_date);
             // if separate payment there are two contributions recorded and the
             // admin will need to send a receipt for each of them separately.
             // we dont link the two in the db (but can potentially infer it if needed)
             $template->assign('is_separate_payment', 0);
         }
         $values['contribution_id'] = $contribution->id;
         if (CRM_Utils_Array::value('related_contact', $ids)) {
             $values['related_contact'] = $ids['related_contact'];
             if (isset($ids['onbehalf_dupe_alert'])) {
                 $values['onbehalf_dupe_alert'] = $ids['onbehalf_dupe_alert'];
             }
             require_once 'CRM/Core/BAO/Address.php';
             $entityBlock = array('contact_id' => $ids['contact'], 'location_type_id' => CRM_Core_DAO::getFieldValue('CRM_Core_DAO_LocationType', 'Main', 'id', 'name'));
             $address = CRM_Core_BAO_Address::getValues($entityBlock);
             $template->assign('onBehalfAddress', $address[$entityBlock['location_type_id']]['display']);
         }
         $isTest = false;
         if ($contribution->is_test) {
             $isTest = true;
         }
         // CRM_Core_Error::debug('val',$values);
         return CRM_Contribute_BAO_ContributionPage::sendMail($ids['contact'], $values, $isTest, $returnMessageText);
     }
 }
コード例 #19
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']);
         }
     }
 }
コード例 #20
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     $this->assignToTemplate();
     $productID = $this->get('productID');
     $option = $this->get('option');
     $membershipTypeID = $this->get('membershipTypeID');
     $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values));
     if ($productID) {
         require_once 'CRM/Contribute/BAO/Premium.php';
         CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, false, $productID, $option);
     }
     $this->assign('lineItem', $this->_lineItem);
     $this->assign('priceSetID', $this->_priceSetId);
     $params = $this->_params;
     $honor_block_is_active = $this->get('honor_block_is_active');
     if ($honor_block_is_active && (!empty($params["honor_first_name"]) && !empty($params["honor_last_name"]) || !empty($params["honor_email"]))) {
         $this->assign('honor_block_is_active', $honor_block_is_active);
         $this->assign('honor_block_title', CRM_Utils_Array::value('honor_block_title', $this->_values));
         require_once "CRM/Core/PseudoConstant.php";
         $prefix = CRM_Core_PseudoConstant::individualPrefix();
         $honor = CRM_Core_PseudoConstant::honor();
         $this->assign('honor_type', $honor[$params["honor_type_id"]]);
         $this->assign('honor_prefix', $params["honor_prefix_id"] ? $prefix[$params["honor_prefix_id"]] : ' ');
         $this->assign('honor_first_name', $params["honor_first_name"]);
         $this->assign('honor_last_name', $params["honor_last_name"]);
         $this->assign('honor_email', $params["honor_email"]);
     }
     //pcp elements
     if ($this->_pcpId) {
         $this->assign('pcpBlock', true);
         foreach (array('pcp_display_in_roll', 'pcp_is_anonymous', 'pcp_roll_nickname', 'pcp_personal_note') as $val) {
             if (CRM_Utils_Array::value($val, $this->_params)) {
                 $this->assign($val, $this->_params[$val]);
             }
         }
     }
     if ($membershipTypeID) {
         $transactionID = $this->get('membership_trx_id');
         $membershipAmount = $this->get('membership_amount');
         $renewalMode = $this->get('renewal_mode');
         $this->assign('membership_trx_id', $transactionID);
         $this->assign('membership_amount', $membershipAmount);
         $this->assign('renewal_mode', $renewalMode);
         CRM_Member_BAO_Membership::buildMembershipBlock($this, $this->_id, false, $membershipTypeID, true, null, $this->_membershipContactID);
     }
     $this->_separateMembershipPayment = $this->get('separateMembershipPayment');
     $this->assign("is_separate_payment", $this->_separateMembershipPayment);
     $this->buildCustom($this->_values['custom_pre_id'], 'customPre', true);
     $this->buildCustom($this->_values['custom_post_id'], 'customPost', true);
     $this->assign('trxn_id', CRM_Utils_Array::value('trxn_id', $this->_params));
     $this->assign('receive_date', CRM_Utils_Date::mysqlToIso(CRM_Utils_Array::value('receive_date', $this->_params)));
     $defaults = array();
     $options = array();
     $fields = array();
     require_once "CRM/Core/BAO/CustomGroup.php";
     $removeCustomFieldTypes = array('Contribution');
     foreach ($this->_fields as $name => $dontCare) {
         $fields[$name] = 1;
     }
     $fields['state_province'] = $fields['country'] = $fields['email'] = 1;
     $contact = $this->_params = $this->controller->exportValues('Main');
     foreach ($fields as $name => $dontCare) {
         if (isset($contact[$name])) {
             $defaults[$name] = $contact[$name];
             if (substr($name, 0, 7) == 'custom_') {
                 $timeField = "{$name}_time";
                 if (isset($contact[$timeField])) {
                     $defaults[$timeField] = $contact[$timeField];
                 }
             } else {
                 if (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && CRM_Utils_Array::value($name . '_custom', $contact)) {
                     $defaults[$name . '_custom'] = $contact[$name . '_custom'];
                 }
             }
         }
     }
     $this->_submitValues = array_merge($this->_submitValues, $defaults);
     $this->setDefaults($defaults);
     require_once 'CRM/Friend/BAO/Friend.php';
     $values['entity_id'] = $this->_id;
     $values['entity_table'] = 'civicrm_contribution_page';
     CRM_Friend_BAO_Friend::retrieve($values, $data);
     $tellAFriend = false;
     if ($this->_pcpId) {
         if ($this->_pcpBlock['is_tellfriend_enabled']) {
             $this->assign('friendText', ts('Tell a Friend'));
             $subUrl = "eid={$this->_pcpId}&blockId={$this->_pcpBlock['id']}&page=pcp";
             $tellAFriend = true;
         }
     } else {
         if (CRM_Utils_Array::value('is_active', $data)) {
             $friendText = $data['title'];
             $this->assign('friendText', $friendText);
             $subUrl = "eid={$this->_id}&page=contribution";
             $tellAFriend = true;
         }
     }
     if ($tellAFriend) {
         if ($this->_action & CRM_Core_Action::PREVIEW) {
             $url = CRM_Utils_System::url("civicrm/friend", "reset=1&action=preview&{$subUrl}");
         } else {
             $url = CRM_Utils_System::url("civicrm/friend", "reset=1&{$subUrl}");
         }
         $this->assign('friendURL', $url);
     }
     $this->freeze();
     // can we blow away the session now to prevent hackery
 }
コード例 #21
0
ファイル: UFGroup.php プロジェクト: bhirsch/voipdev
 /**
  * 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);
         }
     }
 }
コード例 #22
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)));
 }
コード例 #23
0
ファイル: Pledge.php プロジェクト: hampelm/Ginsberg-CiviDemo
 /** 
  * Function to send Acknowledgment and create activity.
  * 
  * @param object $form form object.
  * @param array  $params (reference ) an assoc array of name/value pairs.
  * @access public 
  * @return None.
  */
 function sendAcknowledgment(&$form, $params)
 {
     //handle Acknowledgment.
     $allPayments = $payments = array();
     //get All Payments status types.
     require_once 'CRM/Contribute/PseudoConstant.php';
     $paymentStatusTypes = CRM_Contribute_PseudoConstant::contributionStatus(null, 'name');
     $returnProperties = array('status_id', 'scheduled_amount', 'scheduled_date', 'contribution_id');
     //get all paymnets details.
     CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_Payment', 'pledge_id', $params['id'], $allPayments, $returnProperties);
     if (!empty($allPayments)) {
         foreach ($allPayments as $payID => $values) {
             $contributionValue = $contributionStatus = array();
             if (isset($values['contribution_id'])) {
                 $contributionParams = array('id' => $values['contribution_id']);
                 $returnProperties = array('contribution_status_id', 'receive_date');
                 CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_Contribution', $contributionParams, $contributionStatus, $returnProperties);
                 $contributionValue = array('status' => CRM_Utils_Array::value('contribution_status_id', $contributionStatus), 'receive_date' => CRM_Utils_Array::value('receive_date', $contributionStatus));
             }
             $payments[$payID] = array_merge($contributionValue, array('amount' => CRM_Utils_Array::value('scheduled_amount', $values), 'due_date' => CRM_Utils_Array::value('scheduled_date', $values)));
             //get the first valid payment id.
             if (!$form->paymentId && ($paymentStatusTypes[$values['status_id']] == 'Pending' || $paymentStatusTypes[$values['status_id']] == 'Overdue')) {
                 $form->paymentId = $values['id'];
             }
         }
     }
     //end
     //assign pledge fields value to template.
     $pledgeFields = array('create_date', 'total_pledge_amount', 'frequency_interval', 'frequency_unit', 'installments', 'frequency_day', 'scheduled_amount');
     foreach ($pledgeFields as $field) {
         if (CRM_Utils_Array::value($field, $params)) {
             $form->assign($field, $params[$field]);
         }
     }
     //assign all payments details.
     if ($payments) {
         $form->assign('payments', $payments);
     }
     //assign honor fields.
     $honor_block_is_active = false;
     //make sure we have values for it
     if (CRM_Utils_Array::value('honor_type_id', $params) && (!empty($params["honor_first_name"]) && !empty($params["honor_last_name"]) || !empty($params["honor_email"]))) {
         $honor_block_is_active = true;
         require_once "CRM/Core/PseudoConstant.php";
         $prefix = CRM_Core_PseudoConstant::individualPrefix();
         $honor = CRM_Core_PseudoConstant::honor();
         $form->assign("honor_type", $honor[$params["honor_type_id"]]);
         $form->assign("honor_prefix", $prefix[$params["honor_prefix_id"]]);
         $form->assign("honor_first_name", $params["honor_first_name"]);
         $form->assign("honor_last_name", $params["honor_last_name"]);
         $form->assign("honor_email", $params["honor_email"]);
     }
     $form->assign('honor_block_is_active', $honor_block_is_active);
     //handle domain token values
     require_once 'CRM/Core/BAO/Domain.php';
     $domain =& CRM_Core_BAO_Domain::getDomain();
     $tokens = array('domain' => array('name', 'phone', 'address', 'email'), 'contact' => CRM_Core_SelectValues::contactTokens());
     require_once 'CRM/Utils/Token.php';
     $domainValues = array();
     foreach ($tokens['domain'] as $token) {
         $domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain);
     }
     $form->assign('domain', $domainValues);
     //handle contact token values.
     require_once 'CRM/Contact/BAO/Contact.php';
     require_once 'CRM/Mailing/BAO/Mailing.php';
     $ids = array($params['contact_id']);
     $fields = array_merge(array_keys(CRM_Contact_BAO_Contact::importableFields()), array('display_name', 'checksum', 'contact_id'));
     foreach ($fields as $key => $val) {
         $returnProperties[$val] = true;
     }
     $details = CRM_Mailing_BAO_Mailing::getDetails($ids, $returnProperties);
     $form->assign('contact', $details[0][$params['contact_id']]);
     //handle custom data.
     if (CRM_Utils_Array::value('hidden_custom', $params)) {
         require_once 'CRM/Core/BAO/CustomGroup.php';
         $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Pledge', CRM_Core_DAO::$_nullObject, $params['id']);
         $pledgeParams = array(array('pledge_id', '=', $params['id'], 0, 0));
         $customGroup = array();
         // retrieve custom data
         require_once "CRM/Core/BAO/UFGroup.php";
         foreach ($groupTree as $groupID => $group) {
             $customFields = $customValues = array();
             if ($groupID == 'info') {
                 continue;
             }
             foreach ($group['fields'] as $k => $field) {
                 $field['title'] = $field['label'];
                 $customFields["custom_{$k}"] = $field;
             }
             //to build array of customgroup & customfields in it
             CRM_Core_BAO_UFGroup::getValues($params['contact_id'], $customFields, $customValues, false, $pledgeParams);
             $customGroup[$group['title']] = $customValues;
         }
         $form->assign('customGroup', $customGroup);
     }
     //handle acknowledgment email stuff.
     require_once 'CRM/Contact/BAO/Contact.php';
     require_once 'CRM/Contact/BAO/Contact/Location.php';
     list($pledgerDisplayName, $pledgerEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($params['contact_id']);
     //check for online pledge.
     $session = CRM_Core_Session::singleton();
     if (CRM_Utils_Array::value('receipt_from_email', $params)) {
         $userName = CRM_Utils_Array::value('receipt_from_name', $params);
         $userEmail = CRM_Utils_Array::value('receipt_from_email', $params);
     } else {
         if ($userID = $session->get('userID')) {
             //check for loged in user.
             list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID);
         } else {
             //set the domain values.
             $userName = CRM_Utils_Array::value('name', $domainValues);
             $userEmail = CRM_Utils_Array::value('email', $domainValues);
         }
     }
     $receiptFrom = "{$userName} <{$userEmail}>";
     require_once 'CRM/Core/BAO/MessageTemplates.php';
     list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_pledge', 'valueName' => 'pledge_acknowledge', 'contactId' => $params['contact_id'], 'from' => $receiptFrom, 'toName' => $pledgerDisplayName, 'toEmail' => $pledgerEmail));
     //check if activity record exist for this pledge
     //Acknowledgment, if exist do not add activity.
     require_once "CRM/Activity/DAO/Activity.php";
     $activityType = 'Pledge Acknowledgment';
     $activity = new CRM_Activity_DAO_Activity();
     $activity->source_record_id = $params['id'];
     $activity->activity_type_id = CRM_Core_OptionGroup::getValue('activity_type', $activityType, 'name');
     $config = CRM_Core_Config::singleton();
     $money = $config->defaultCurrencySymbol;
     $details = 'Total Amount ' . $money . $params['total_pledge_amount'] . ' To be paid in ' . $params['installments'] . ' installments of ' . $money . $params['scheduled_amount'] . ' every ' . $params['frequency_interval'] . ' ' . $params['frequency_unit'] . '(s)';
     if (!$activity->find()) {
         $activityParams = array('subject' => $subject, 'source_contact_id' => $params['contact_id'], 'source_record_id' => $params['id'], 'activity_type_id' => CRM_Core_OptionGroup::getValue('activity_type', $activityType, 'name'), 'activity_date_time' => CRM_Utils_Date::isoToMysql($params['acknowledge_date']), 'is_test' => $params['is_test'], 'status_id' => 2, 'details' => $details);
         require_once 'api/v2/Activity.php';
         if (is_a(civicrm_activity_create($activityParams), 'CRM_Core_Error')) {
             CRM_Core_Error::fatal("Failed creating Activity for acknowledgment");
         }
     }
 }
コード例 #24
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     $this->assignToTemplate();
     $productID = $this->get('productID');
     $option = $this->get('option');
     $membershipTypeID = $this->get('membershipTypeID');
     $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values));
     if ($productID) {
         CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE, $productID, $option);
     }
     if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $this->_priceSetId, 'is_quick_config')) {
         $this->assign('lineItem', $this->_lineItem);
     } else {
         if (is_array($membershipTypeID)) {
             $membershipTypeID = current($membershipTypeID);
         }
         $this->assign('is_quick_config', 1);
         $this->_params['is_quick_config'] = 1;
     }
     $this->assign('priceSetID', $this->_priceSetId);
     $this->assign('useForMember', $this->get('useForMember'));
     $params = $this->_params;
     $honor_block_is_active = $this->get('honor_block_is_active');
     if ($honor_block_is_active && (!empty($params["honor_first_name"]) && !empty($params["honor_last_name"]) || !empty($params["honor_email"]))) {
         $this->assign('honor_block_is_active', $honor_block_is_active);
         $this->assign('honor_block_title', CRM_Utils_Array::value('honor_block_title', $this->_values));
         $prefix = CRM_Core_PseudoConstant::individualPrefix();
         $honor = CRM_Core_PseudoConstant::honor();
         $this->assign('honor_type', $honor[$params["honor_type_id"]]);
         $this->assign('honor_prefix', $params["honor_prefix_id"] ? $prefix[$params["honor_prefix_id"]] : ' ');
         $this->assign('honor_first_name', $params["honor_first_name"]);
         $this->assign('honor_last_name', $params["honor_last_name"]);
         $this->assign('honor_email', $params["honor_email"]);
     }
     $qParams = "reset=1&amp;id={$this->_id}";
     //pcp elements
     if ($this->_pcpId) {
         $qParams .= "&amp;pcpId={$this->_pcpId}";
         $this->assign('pcpBlock', TRUE);
         foreach (array('pcp_display_in_roll', 'pcp_is_anonymous', 'pcp_roll_nickname', 'pcp_personal_note') as $val) {
             if (CRM_Utils_Array::value($val, $this->_params)) {
                 $this->assign($val, $this->_params[$val]);
             }
         }
     }
     $this->assign('qParams', $qParams);
     if ($membershipTypeID) {
         $transactionID = $this->get('membership_trx_id');
         $membershipAmount = $this->get('membership_amount');
         $renewalMode = $this->get('renewal_mode');
         $this->assign('membership_trx_id', $transactionID);
         $this->assign('membership_amount', $membershipAmount);
         $this->assign('renewal_mode', $renewalMode);
         CRM_Member_BAO_Membership::buildMembershipBlock($this, $this->_id, FALSE, $membershipTypeID, TRUE, NULL, $this->_membershipContactID);
     }
     $this->_separateMembershipPayment = $this->get('separateMembershipPayment');
     $this->assign("is_separate_payment", $this->_separateMembershipPayment);
     $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE);
     $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE);
     if (CRM_Utils_Array::value('hidden_onbehalf_profile', $params)) {
         $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id);
         $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         $profileId = $OnBehalfProfile[0];
         $fieldTypes = array('Contact', 'Organization');
         $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
         $fieldTypes = array_merge($fieldTypes, $contactSubType);
         if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) {
             $fieldTypes = array_merge($fieldTypes, array('Membership'));
         } else {
             $fieldTypes = array_merge($fieldTypes, array('Contribution'));
         }
         $this->buildCustom($profileId, 'onbehalfProfile', TRUE, TRUE, $fieldTypes);
     }
     $this->assign('trxn_id', CRM_Utils_Array::value('trxn_id', $this->_params));
     $this->assign('receive_date', CRM_Utils_Date::mysqlToIso(CRM_Utils_Array::value('receive_date', $this->_params)));
     $defaults = array();
     $options = array();
     $fields = array();
     $removeCustomFieldTypes = array('Contribution');
     foreach ($this->_fields as $name => $dontCare) {
         if ($name == 'onbehalf') {
             foreach ($dontCare as $key => $value) {
                 $fields['onbehalf'][$key] = 1;
             }
         } else {
             $fields[$name] = 1;
         }
     }
     $fields['state_province'] = $fields['country'] = $fields['email'] = 1;
     $contact = $this->_params = $this->controller->exportValues('Main');
     foreach ($fields as $name => $dontCare) {
         if ($name == 'onbehalf') {
             foreach ($dontCare as $key => $value) {
                 //$defaults[$key] = $contact['onbehalf'][$key];
                 if (isset($contact['onbehalf'][$key])) {
                     $defaults[$key] = $contact['onbehalf'][$key];
                 }
                 if (isset($contact['onbehalf']["{$key}_id"])) {
                     $defaults["{$key}_id"] = $contact['onbehalf']["{$key}_id"];
                 }
             }
         } elseif (isset($contact[$name])) {
             $defaults[$name] = $contact[$name];
             if (substr($name, 0, 7) == 'custom_') {
                 $timeField = "{$name}_time";
                 if (isset($contact[$timeField])) {
                     $defaults[$timeField] = $contact[$timeField];
                 }
             } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && CRM_Utils_Array::value($name . '_custom', $contact)) {
                 $defaults[$name . '_custom'] = $contact[$name . '_custom'];
             }
         }
     }
     // now fix all state country selectors
     CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
     $this->_submitValues = array_merge($this->_submitValues, $defaults);
     $this->setDefaults($defaults);
     $values['entity_id'] = $this->_id;
     $values['entity_table'] = 'civicrm_contribution_page';
     CRM_Friend_BAO_Friend::retrieve($values, $data);
     $tellAFriend = FALSE;
     if ($this->_pcpId) {
         if ($this->_pcpBlock['is_tellfriend_enabled']) {
             $this->assign('friendText', ts('Tell a Friend'));
             $subUrl = "eid={$this->_pcpId}&blockId={$this->_pcpBlock['id']}&pcomponent=pcp";
             $tellAFriend = TRUE;
         }
     } elseif (CRM_Utils_Array::value('is_active', $data)) {
         $friendText = $data['title'];
         $this->assign('friendText', $friendText);
         $subUrl = "eid={$this->_id}&pcomponent=contribute";
         $tellAFriend = TRUE;
     }
     if ($tellAFriend) {
         if ($this->_action & CRM_Core_Action::PREVIEW) {
             $url = CRM_Utils_System::url("civicrm/friend", "reset=1&action=preview&{$subUrl}");
         } else {
             $url = CRM_Utils_System::url("civicrm/friend", "reset=1&{$subUrl}");
         }
         $this->assign('friendURL', $url);
     }
     $this->freeze();
     // can we blow away the session now to prevent hackery
     // CRM-9491
     $this->controller->reset();
 }
コード例 #25
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;
 }
コード例 #26
0
ファイル: Event.php プロジェクト: hampelm/Ginsberg-CiviDemo
 /**  
  * 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];
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #27
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;
         }
     }
 }
コード例 #28
0
ファイル: Contact.php プロジェクト: ksecor/civicrm
/**
 * @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;
}
コード例 #29
0
ファイル: Contact.php プロジェクト: bhirsch/voipdev
 /**
  * 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)
 {
     require_once 'CRM/Core/OptionGroup.php';
     foreach ($params as $key => $value) {
         if ($value) {
             $session =& CRM_Core_Session::singleton();
             $dateType = $session->get("dateTypes");
             switch ($key) {
                 case 'birth_date':
                     if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
                         if (!CRM_Utils_Rule::date($params[$key])) {
                             self::addToErrorMsg(ts('Birth Date'), $errorMessage);
                         }
                     } else {
                         self::addToErrorMsg(ts('Birth-Date'), $errorMessage);
                     }
                     break;
                 case 'deceased_date':
                     if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) {
                         if (!CRM_Utils_Rule::date($params[$key])) {
                             self::addToErrorMsg(ts('Deceased Date'), $errorMessage);
                         }
                     } else {
                         self::addToErrorMsg(ts('Deceased Date'), $errorMessage);
                     }
                     break;
                 case 'is_deceased':
                     if (CRM_Utils_String::strtoboolstr($value) === false) {
                         self::addToErrorMsg(ts('Is Deceased'), $errorMessage);
                     }
                     break;
                 case 'gender':
                     if (!self::checkGender($value)) {
                         self::addToErrorMsg(ts('Gender'), $errorMessage);
                     }
                     break;
                 case 'preferred_communication_method':
                     $preffComm = array();
                     $preffComm = explode(',', $value);
                     foreach ($preffComm as $v) {
                         if (!self::in_value(trim($v), CRM_Core_PseudoConstant::pcm())) {
                             self::addToErrorMsg(ts('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))) {
                         self::addToErrorMsg(ts('Preferred Mail Format'), $errorMessage);
                     }
                     break;
                 case 'individual_prefix':
                     if (!self::in_value($value, CRM_Core_PseudoConstant::individualPrefix())) {
                         self::addToErrorMsg(ts('Individual Prefix'), $errorMessage);
                     }
                     break;
                 case 'individual_suffix':
                     if (!self::in_value($value, CRM_Core_PseudoConstant::individualSuffix())) {
                         self::addToErrorMsg(ts('Individual Suffix'), $errorMessage);
                     }
                     break;
                 case 'state_province':
                     if (!empty($value)) {
                         foreach ($value as $stateValue) {
                             if ($stateValue['state_province']) {
                                 if (self::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvinceAbbreviation()) || self::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvince())) {
                                     continue;
                                 } else {
                                     self::addToErrorMsg(ts('State / Province'), $errorMessage);
                                 }
                             }
                         }
                     }
                     break;
                 case 'country':
                     if (!empty($value)) {
                         foreach ($value as $stateValue) {
                             if ($stateValue['country']) {
                                 CRM_Core_PseudoConstant::populate($countryNames, 'CRM_Core_DAO_Country', true, 'name', 'is_active');
                                 CRM_Core_PseudoConstant::populate($countryIsoCodes, 'CRM_Core_DAO_Country', true, 'iso_code');
                                 $config =& CRM_Core_Config::singleton();
                                 $limitCodes = $config->countryLimit();
                                 //If no country is selected in
                                 //localization then take all countries
                                 if (empty($limitCodes)) {
                                     $limitCodes = $countryIsoCodes;
                                 }
                                 if (self::in_value($stateValue['country'], $limitCodes) || self::in_value($stateValue['country'], CRM_Core_PseudoConstant::country())) {
                                     continue;
                                 } else {
                                     if (self::in_value($stateValue['country'], $countryIsoCodes) || self::in_value($stateValue['country'], $countryNames)) {
                                         self::addToErrorMsg(ts('Country input value is in table but not "available": "This Country is valid but is NOT in the list of Available Countries currently configured for your site. This can be viewed and modifed from Global Settings >> Localization." '), $errorMessage);
                                     } else {
                                         self::addToErrorMsg(ts('Country input value not in country table: "The Country value appears to be invalid. It does not match any value in CiviCRM table of countries."'), $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 {
                                     self::addToErrorMsg(ts('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 {
                                     self::addToErrorMsg(ts('Geo code 2'), $errorMessage);
                                 }
                             }
                         }
                     }
                     break;
                     //check for any error in email/postal greeting, addressee,
                     //custom email/postal greeting, custom addressee, CRM-4575
                 //check for any error in email/postal greeting, addressee,
                 //custom email/postal greeting, custom addressee, CRM-4575
                 case 'email_greeting':
                     $emailGreetingFilter = array('contact_type' => $this->_contactType, 'greeting_type' => 'email_greeting');
                     if (!self::in_value($value, CRM_Core_PseudoConstant::greeting($emailGreetingFilter))) {
                         self::addToErrorMsg(ts('Email Greeting must be one of the configured format options. Check Administer >> Option Lists >> Email Greetings for valid values'), $errorMessage);
                     }
                     break;
                 case 'postal_greeting':
                     $postalGreetingFilter = array('contact_type' => $this->_contactType, 'greeting_type' => 'postal_greeting');
                     if (!self::in_value($value, CRM_Core_PseudoConstant::greeting($postalGreetingFilter))) {
                         self::addToErrorMsg(ts('Postal Greeting must be one of the configured format options. Check Administer >> Option Lists >> Postal Greetings for valid values'), $errorMessage);
                     }
                     break;
                 case 'addressee':
                     $addresseeFilter = array('contact_type' => $this->_contactType, 'greeting_type' => 'addressee');
                     if (!self::in_value($value, CRM_Core_PseudoConstant::greeting($addresseeFilter))) {
                         self::addToErrorMsg(ts('Addressee must be one of the configured format options. Check Administer >> Option Lists >> Addressee for valid values'), $errorMessage);
                     }
                     break;
                 case 'email_greeting_custom':
                     if (array_key_exists('email_greeting', $params)) {
                         $emailGreetingLabel = key(CRM_Core_OptionGroup::values('email_greeting', true, null, null, 'AND v.name = "Customized"'));
                         if (CRM_Utils_Array::value('email_greeting', $params) != $emailGreetingLabel) {
                             self::addToErrorMsg(ts('Email Greeting - Custom'), $errorMessage);
                         }
                     }
                     break;
                 case 'postal_greeting_custom':
                     if (array_key_exists('postal_greeting', $params)) {
                         $postalGreetingLabel = key(CRM_Core_OptionGroup::values('postal_greeting', true, null, null, 'AND v.name = "Customized"'));
                         if (CRM_Utils_Array::value('postal_greeting', $params) != $postalGreetingLabel) {
                             self::addToErrorMsg(ts('Postal Greeting - Custom'), $errorMessage);
                         }
                     }
                     break;
                 case 'addressee_custom':
                     if (array_key_exists('addressee', $params)) {
                         $addresseeLabel = key(CRM_Core_OptionGroup::values('addressee', true, null, null, 'AND v.name = "Customized"'));
                         if (CRM_Utils_Array::value('addressee', $params) != $addresseeLabel) {
                             self::addToErrorMsg(ts('Addressee - Custom'), $errorMessage);
                         }
                     }
                     break;
                 case 'home_URL':
                     if (CRM_Utils_Rule::url($value) === false) {
                         self::addToErrorMsg(ts('Website'), $errorMessage);
                     }
                     break;
                 case 'do_not_email':
                 case 'do_not_phone':
                 case 'do_not_mail':
                 case 'do_not_sms':
                 case 'do_not_trade':
                     if (CRM_Utils_Rule::boolean($value) == false) {
                         $key = ucwords(str_replace("_", " ", $key));
                         self::addToErrorMsg($key, $errorMessage);
                     }
                     break;
                 case 'email':
                     if (is_array($value)) {
                         foreach ($value as $values) {
                             if (CRM_Utils_Array::value('email', $values) && !CRM_Utils_Rule::email($values['email'])) {
                                 self::addToErrorMsg($key, $errorMessage);
                                 break;
                             }
                         }
                     }
                     break;
                 default:
                     if (is_array($params[$key]) && isset($params[$key]["contact_type"])) {
                         //check for any relationship data ,FIX ME
                         self::isErrorInCoreData($params[$key], $errorMessage);
                     }
             }
         }
     }
 }
コード例 #30
0
ファイル: Confirm.php プロジェクト: bhirsch/civicrm
 /**
  * Create the Honor contact
  *
  * @return void
  * @access public
  */
 function createHonorContact()
 {
     $params = $this->controller->exportValues('Main');
     // return if we dont have enough information
     if (empty($params["honor_first_name"]) && empty($params["honor_last_name"]) && empty($params["honor_email"])) {
         return null;
     }
     //assign to template for email reciept
     $honor_block_is_active = $this->get('honor_block_is_active');
     $this->assign('honor_block_is_active', $honor_block_is_active);
     $this->assign("honor_block_title", $this->_values['honor_block_title']);
     require_once "CRM/Core/PseudoConstant.php";
     $prefix = CRM_Core_PseudoConstant::individualPrefix();
     $honorType = CRM_Core_PseudoConstant::honor();
     $this->assign("honor_type", $honorType[$params["honor_type_id"]]);
     $this->assign("honor_prefix", $prefix[$params["honor_prefix_id"]]);
     $this->assign("honor_first_name", $params["honor_first_name"]);
     $this->assign("honor_last_name", $params["honor_last_name"]);
     $this->assign("honor_email", $params["honor_email"]);
     //create honoree contact
     require_once 'CRM/Contribute/BAO/Contribution.php';
     return CRM_Contribute_BAO_Contribution::createHonorContact($params);
 }