コード例 #1
0
 /**
  * This function sets the default values for the form.
  *
  * @access public
  */
 function setDefaultValues()
 {
     $defaults = array();
     $defaults['volunteer_role_id'] = CRM_Volunteer_BAO_Need::FLEXIBLE_ROLE_ID;
     $cid = CRM_Utils_Array::value('userID', $_SESSION['CiviCRM'], NULL);
     if ($cid) {
         $fields = array_flip(array_keys(CRM_Core_BAO_UFGroup::getFields($this->_ufgroup_id)));
         CRM_Core_BAO_UFGroup::setProfileDefaults($cid, $fields, $defaults);
     }
     return $defaults;
 }
コード例 #2
0
 function setDefaultValues()
 {
     $defaults = array($this->html_field_name('email') => $this->participant->email);
     list($custom_fields_pre, $custom_fields_post) = $this->get_participant_custom_data_fields($this->participant->event_id);
     $all_fields = $custom_fields_pre + $custom_fields_post;
     $flat = array();
     CRM_Core_BAO_UFGroup::setProfileDefaults($this->participant->contact_id, $all_fields, $flat);
     foreach ($flat as $name => $field) {
         $defaults["field[{$this->participant->id}][{$name}]"] = $field;
     }
     return $defaults;
 }
コード例 #3
0
 /**
  * Set default values for the form.
  *
  * @access public
  */
 function setDefaultValues()
 {
     $defaults = array();
     $defaults['volunteer_role_id'] = CRM_Volunteer_BAO_Need::FLEXIBLE_ROLE_ID;
     if (key_exists('userID', $_SESSION['CiviCRM'])) {
         foreach ($this->getProfileIDs() as $profileID) {
             $fields = array_flip(array_keys(CRM_Core_BAO_UFGroup::getFields($profileID)));
             CRM_Core_BAO_UFGroup::setProfileDefaults($_SESSION['CiviCRM']['userID'], $fields, $defaults);
         }
     }
     return $defaults;
 }
コード例 #4
0
 function setDefaultValues()
 {
     if (!$this->_donorID) {
         return;
     }
     foreach ($this->_fields as $name => $dontcare) {
         $fields[$name] = 1;
     }
     require_once "CRM/Core/BAO/UFGroup.php";
     CRM_Core_BAO_UFGroup::setProfileDefaults($this->_donorID, $fields, $this->_defaults);
     //set custom field defaults
     require_once "CRM/Core/BAO/CustomField.php";
     foreach ($this->_fields as $name => $field) {
         if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
             if (!isset($this->_defaults[$name])) {
                 CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, NULL, CRM_Profile_Form::MODE_REGISTER);
             }
         }
     }
     return $this->_defaults;
 }
コード例 #5
0
ファイル: Form.php プロジェクト: hyebahi/civicrm-core
 /**
  * Set default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  *
  * @return void
  */
 public function setDefaultsValues()
 {
     $this->_defaults = array();
     if ($this->_multiRecordProfile && $this->_multiRecord == CRM_Core_Action::DELETE) {
         return;
     }
     if ($this->_mode != self::MODE_SEARCH) {
         // set default values for country / state to start with
         CRM_Core_BAO_UFGroup::setRegisterDefaults($this->_fields, $this->_defaults);
     }
     if ($this->_id && !$this->_multiRecordProfile) {
         if ($this->_isContactActivityProfile) {
             $contactFields = $activityFields = array();
             foreach ($this->_fields as $fieldName => $field) {
                 if (CRM_Utils_Array::value('field_type', $field) == 'Activity') {
                     $activityFields[$fieldName] = $field;
                 } else {
                     $contactFields[$fieldName] = $field;
                 }
             }
             CRM_Core_BAO_UFGroup::setProfileDefaults($this->_id, $contactFields, $this->_defaults, TRUE);
             if ($this->_activityId) {
                 CRM_Core_BAO_UFGroup::setComponentDefaults($activityFields, $this->_activityId, 'Activity', $this->_defaults, TRUE);
             }
         } else {
             CRM_Core_BAO_UFGroup::setProfileDefaults($this->_id, $this->_fields, $this->_defaults, TRUE);
         }
     }
     //set custom field defaults
     if ($this->_multiRecordProfile) {
         foreach ($this->_multiRecordFields as $key => $field) {
             $fieldIds[] = CRM_Core_BAO_CustomField::getKeyID($key);
         }
         $defaultValues = array();
         if ($this->_multiRecord && $this->_multiRecord == CRM_Core_Action::UPDATE) {
             $defaultValues = CRM_Core_BAO_CustomValueTable::getEntityValues($this->_id, NULL, $fieldIds, TRUE);
             if ($this->_recordExists == TRUE) {
                 $defaultValues = $defaultValues[$this->_recordId];
             } else {
                 $defaultValues = NULL;
             }
         }
         if (!empty($defaultValues)) {
             foreach ($defaultValues as $key => $value) {
                 $name = "custom_{$key}";
                 $htmlType = $this->_multiRecordFields[$name]['html_type'];
                 if ($htmlType != 'File') {
                     if (isset($value)) {
                         CRM_Core_BAO_CustomField::setProfileDefaults($key, $name, $this->_defaults, $this->_id, $this->_mode, $value);
                     } else {
                         $this->_defaults[$name] = "";
                     }
                 }
                 if ($htmlType == 'File') {
                     $entityId = $this->_id;
                     if (CRM_Utils_Array::value('field_type', $field) == 'Activity' && $this->_activityId) {
                         $entityId = $this->_activityId;
                     }
                     $url = CRM_Core_BAO_CustomField::getFileURL($entityId, $key);
                     if ($url) {
                         $customFiles[$name]['displayURL'] = ts("Attached File") . ": {$url['file_url']}";
                         $deleteExtra = ts("Are you sure you want to delete attached file?");
                         $fileId = $url['file_id'];
                         $deleteURL = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$entityId}&fid={$key}&action=delete");
                         $text = ts("Delete Attached File");
                         $customFiles[$field['name']]['deleteURL'] = "<a href=\"{$deleteURL}\" onclick = \"if (confirm( ' {$deleteExtra} ' )) this.href+='&amp;confirmed=1'; else return false;\">{$text}</a>";
                         // also delete the required rule that we've set on the form element
                         $this->removeFileRequiredRules($name);
                     }
                 }
             }
         }
     } else {
         foreach ($this->_fields as $name => $field) {
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 $htmlType = $field['html_type'];
                 if ((!isset($this->_defaults[$name]) || $htmlType == 'File') && CRM_Utils_Array::value('field_type', $field) != 'Activity') {
                     CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $this->_id, $this->_mode);
                 }
                 if ($htmlType == 'File') {
                     $entityId = $this->_id;
                     if (CRM_Utils_Array::value('field_type', $field) == 'Activity' && $this->_activityId) {
                         $entityId = $this->_activityId;
                     }
                     $url = CRM_Core_BAO_CustomField::getFileURL($entityId, $customFieldID);
                     if ($url) {
                         $customFiles[$field['name']]['displayURL'] = ts("Attached File") . ": {$url['file_url']}";
                         $deleteExtra = ts("Are you sure you want to delete attached file?");
                         $fileId = $url['file_id'];
                         $deleteURL = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$entityId}&fid={$customFieldID}&action=delete");
                         $text = ts("Delete Attached File");
                         $customFiles[$field['name']]['deleteURL'] = "<a href=\"{$deleteURL}\" onclick = \"if (confirm( ' {$deleteExtra} ' )) this.href+='&amp;confirmed=1'; else return false;\">{$text}</a>";
                         // also delete the required rule that we've set on the form element
                         $this->removeFileRequiredRules($field['name']);
                     }
                 }
             }
         }
     }
     if (isset($customFiles)) {
         $this->assign('customFiles', $customFiles);
     }
     if ($this->_multiRecordProfile) {
         $this->setDefaults($this->_defaults);
         return;
     }
     if (!empty($this->_defaults['image_URL'])) {
         list($imageWidth, $imageHeight) = getimagesize(CRM_Utils_String::unstupifyUrl($this->_defaults['image_URL']));
         list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight);
         $this->assign("imageWidth", $imageWidth);
         $this->assign("imageHeight", $imageHeight);
         $this->assign("imageThumbWidth", $imageThumbWidth);
         $this->assign("imageThumbHeight", $imageThumbHeight);
         $this->assign("imageURL", $this->_defaults['image_URL']);
         $this->removeFileRequiredRules('image_URL');
     }
     if (array_key_exists('contact_sub_type', $this->_defaults) && !empty($this->_defaults['contact_sub_type'])) {
         $this->_defaults['contact_sub_type'] = explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($this->_defaults['contact_sub_type'], CRM_Core_DAO::VALUE_SEPARATOR));
     }
     $this->setDefaults($this->_defaults);
 }
コード例 #6
0
ファイル: Profile.php プロジェクト: nielosz/civicrm-core
/**
 * Retrieve Profile field values.
 *
 * NOTE this api is not standard & since it is tested we need to honour that
 * but the correct behaviour is for it to return an id indexed array as this supports
 * multiple instances - if a  single profile is passed in we will not return a normal api result array
 * in order to avoid breaking code. (This could still be confusing :-( but we have to keep the tested behaviour working
 *
 * Note that if contact_id is empty an array of defaults is returned
 *
 * @param array $params
 *   Associative array of property name/value.
 *   pairs to get profile field values
 *
 * @throws API_Exception
 * @return array
 */
function civicrm_api3_profile_get($params)
{
    $nonStandardLegacyBehaviour = is_numeric($params['profile_id']) ? TRUE : FALSE;
    if (!empty($params['check_permissions']) && !empty($params['contact_id']) && !1 === civicrm_api3('contact', 'getcount', array('contact_id' => $params['contact_id'], 'check_permissions' => 1))) {
        throw new API_Exception('permission denied');
    }
    $profiles = (array) $params['profile_id'];
    $values = array();
    $ufGroupBAO = new CRM_Core_BAO_UFGroup();
    foreach ($profiles as $profileID) {
        $profileID = _civicrm_api3_profile_getProfileID($profileID);
        $values[$profileID] = array();
        if (strtolower($profileID) == 'billing') {
            $values[$profileID] = _civicrm_api3_profile_getbillingpseudoprofile($params);
            continue;
        }
        if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileID, 'is_active')) {
            throw new API_Exception('Invalid value for profile_id : ' . $profileID);
        }
        $isContactActivityProfile = CRM_Core_BAO_UFField::checkContactActivityProfileType($profileID);
        $profileFields = CRM_Core_BAO_UFGroup::getFields($profileID, FALSE, NULL, NULL, NULL, FALSE, NULL, empty($params['check_permissions']) ? FALSE : TRUE, NULL, CRM_Core_Permission::EDIT);
        if ($isContactActivityProfile) {
            civicrm_api3_verify_mandatory($params, NULL, array('activity_id'));
            $errors = CRM_Profile_Form::validateContactActivityProfile($params['activity_id'], $params['contact_id'], $params['profile_id']);
            if (!empty($errors)) {
                throw new API_Exception(array_pop($errors));
            }
            $contactFields = $activityFields = array();
            foreach ($profileFields as $fieldName => $field) {
                if (CRM_Utils_Array::value('field_type', $field) == 'Activity') {
                    $activityFields[$fieldName] = $field;
                } else {
                    $contactFields[$fieldName] = $field;
                    // we should return 'Primary' with & without capitalisation. it is more consistent with api to not
                    // capitalise, but for form support we need it for now. Hopefully we can move away from it
                    $contactFields[strtolower($fieldName)] = $field;
                }
            }
            $ufGroupBAO->setProfileDefaults($params['contact_id'], $contactFields, $values[$profileID], TRUE);
            if ($params['activity_id']) {
                $ufGroupBAO->setComponentDefaults($activityFields, $params['activity_id'], 'Activity', $values[$profileID], TRUE);
            }
        } elseif (!empty($params['contact_id'])) {
            $ufGroupBAO->setProfileDefaults($params['contact_id'], $profileFields, $values[$profileID], TRUE);
            foreach ($values[$profileID] as $fieldName => $field) {
                // we should return 'Primary' with & without capitalisation. it is more consistent with api to not
                // capitalise, but for form support we need it for now. Hopefully we can move away from it
                $values[$profileID][strtolower($fieldName)] = $field;
            }
        } else {
            $values[$profileID] = array_fill_keys(array_keys($profileFields), '');
        }
    }
    if ($nonStandardLegacyBehaviour) {
        $result = civicrm_api3_create_success();
        $result['values'] = $values[$profileID];
        return $result;
    } else {
        return civicrm_api3_create_success($values, $params, 'Profile', 'Get');
    }
}
コード例 #7
0
ファイル: Participant.php プロジェクト: ksecor/civicrm
 /**
  * This function sets the default values for the form in edit/view mode
  * the default values are retrieved from the database
  * 
  * @access public
  * @return None
  */
 public function setDefaultValues()
 {
     if ($this->_showFeeBlock) {
         return CRM_Event_Form_EventFees::setDefaultValues($this);
     }
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     $defaults = array();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return $defaults;
     }
     if ($this->_participantId) {
         $ids = array();
         $params = array('id' => $this->_participantId);
         require_once "CRM/Event/BAO/Participant.php";
         CRM_Event_BAO_Participant::getValues($params, $defaults, $ids);
         $this->_contactID = $defaults[$this->_participantId]['contact_id'];
         $this->_statusId = $defaults[$this->_participantId]['participant_status_id'];
         //set defaults for note
         $noteDetails = CRM_Core_BAO_Note::getNote($this->_participantId, 'civicrm_participant');
         $defaults[$this->_participantId]['note'] = array_pop($noteDetails);
     }
     if ($this->_action & (CRM_Core_Action::VIEW | CRM_Core_Action::BROWSE)) {
         $inactiveNeeded = true;
         $viewMode = true;
     } else {
         $viewMode = false;
         $inactiveNeeded = false;
     }
     //setting default register date
     if ($this->_action == CRM_Core_Action::ADD) {
         if (CRM_Utils_Array::value('event_id', $defaults[$this->_participantId])) {
             $contributionTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $defaults[$this->_participantId]['event_id'], 'contribution_type_id');
             if ($contributionTypeId) {
                 $defaults[$this->_participantId]['contribution_type_id'] = $contributionTypeId;
             }
         }
         if ($this->_mode) {
             $fields["email-{$this->_bltID}"] = 1;
             $fields["email-Primary"] = 1;
             require_once "CRM/Core/BAO/UFGroup.php";
             if ($this->_contactID) {
                 require_once "CRM/Core/BAO/UFGroup.php";
                 CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactID, $fields, $defaults);
             }
             if (empty($defaults["email-{$this->_bltID}"]) && !empty($defaults["email-Primary"])) {
                 $defaults[$this->_participantId]["email-{$this->_bltID}"] = $defaults["email-Primary"];
             }
         }
         $submittedRole = $this->getElementValue('role_id');
         if ($submittedRole[0]) {
             $roleID = $submittedRole[0];
         }
         $submittedEvent = $this->getElementValue('event_id');
         if ($submittedEvent[0]) {
             $eventID = $submittedEvent[0];
         }
     } else {
         $defaults[$this->_participantId]['record_contribution'] = 0;
         $recordContribution = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $defaults[$this->_participantId]['id'], 'contribution_id', 'participant_id');
         //contribution record exists for this participation
         if ($recordContribution) {
             foreach (array('contribution_type_id', 'payment_instrument_id', 'contribution_status_id', 'receive_date') as $field) {
                 $defaults[$this->_participantId][$field] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $recordContribution, $field);
             }
         }
         if ($defaults[$this->_participantId]['participant_is_pay_later']) {
             $this->assign('participant_is_pay_later', true);
         }
         $this->assign('participant_status_id', $defaults[$this->_participantId]['participant_status_id']);
         $roleID = $defaults[$this->_participantId]['participant_role_id'];
         $eventID = $defaults[$this->_participantId]['event_id'];
         $this->_discountId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_participantId, 'discount_id');
         if ($this->_discountId) {
             $this->set('discountId', $this->_discountId);
         }
     }
     list($defaults[$this->_participantId]['register_date'], $defaults[$this->_participantId]['register_date_time']) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value('register_date', $defaults[$this->_participantId]));
     //assign event and role id, this is needed for Custom data building
     if (isset($_POST['role_id'])) {
         $roleID = $_POST['role_id'];
     }
     if (isset($roleID)) {
         $this->assign('roleID', $roleID);
     }
     if (isset($_POST['event_id'])) {
         $eventID = $_POST['event_id'];
     }
     if (isset($eventID)) {
         $this->assign('eventID', $eventID);
         $this->set('eventId', $eventID);
     }
     $this->assign('event_is_test', CRM_Utils_Array::value('event_is_test', $defaults[$this->_participantId]));
     return $defaults[$this->_participantId];
 }
コード例 #8
0
ファイル: Batch.php プロジェクト: bhirsch/voipdev
 /**
  * This function sets the default values for the form.
  * 
  * @access public
  * @return None
  */
 function setDefaultValues()
 {
     if (empty($this->_fields)) {
         return;
     }
     $defaults = array();
     foreach ($this->_participantIds as $participantId) {
         $details[$participantId] = array();
         require_once 'CRM/Event/BAO/Participant.php';
         $details[$participantId] = CRM_Event_BAO_Participant::participantDetails($participantId);
         CRM_Core_BAO_UFGroup::setProfileDefaults(null, $this->_fields, $defaults, false, $participantId, 'Event');
         //get the from status ids, CRM-4323
         if (array_key_exists('participant_status_id', $this->_fields)) {
             $this->_fromStatusIds[$participantId] = CRM_Utils_Array::value("field[{$participantId}][participant_status_id]", $defaults);
         }
     }
     $this->assign('details', $details);
     return $defaults;
 }
コード例 #9
0
 /**
  * This function sets the default values for the form. MobileProvider that in edit/view mode
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return None
  */
 public function setDefaultValues()
 {
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     if ($this->_priceSetId) {
         return CRM_Price_BAO_Set::setDefaultPriceSet($this, $defaults);
     }
     $defaults = parent::setDefaultValues();
     //setting default join date and receive date
     list($now) = CRM_Utils_Date::setDateDefaults();
     if ($this->_action == CRM_Core_Action::ADD) {
         $defaults['receive_date'] = $now;
     }
     if (is_numeric($this->_memType)) {
         $defaults["membership_type_id"] = array();
         $defaults["membership_type_id"][0] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'member_of_contact_id', 'id');
         $defaults["membership_type_id"][1] = $this->_memType;
     } else {
         $defaults["membership_type_id"] = $this->_memType;
     }
     if (CRM_Utils_Array::value('id', $defaults)) {
         if ($this->_onlinePendingContributionId) {
             $defaults['record_contribution'] = $this->_onlinePendingContributionId;
         } else {
             $contributionId = CRM_Core_DAO::singleValueQuery("\n  SELECT contribution_id\n  FROM civicrm_membership_payment\n  WHERE membership_id = {$this->_id}\n  ORDER BY contribution_id\n  DESC limit 1");
             if ($contributionId) {
                 $defaults['record_contribution'] = $contributionId;
             }
         }
     }
     if (CRM_Utils_Array::value('record_contribution', $defaults) && !$this->_mode) {
         $contributionParams = array('id' => $defaults['record_contribution']);
         $contributionIds = array();
         //keep main object campaign in hand.
         $memberCampaignId = CRM_Utils_Array::value('campaign_id', $defaults);
         CRM_Contribute_BAO_Contribution::getValues($contributionParams, $defaults, $contributionIds);
         //get back original object campaign id.
         $defaults['campaign_id'] = $memberCampaignId;
         if (CRM_Utils_Array::value('receive_date', $defaults)) {
             list($defaults['receive_date']) = CRM_Utils_Date::setDateDefaults($defaults['receive_date']);
         }
         // Contribution::getValues() over-writes the membership record's source field value - so we need to restore it.
         if (CRM_Utils_Array::value('membership_source', $defaults)) {
             $defaults['source'] = $defaults['membership_source'];
         }
     }
     // User must explicitly choose to send a receipt in both add and update mode.
     $defaults['send_receipt'] = 0;
     if ($this->_action & CRM_Core_Action::UPDATE) {
         // in this mode by default uncheck this checkbox
         unset($defaults['record_contribution']);
     }
     if (CRM_Utils_Array::value('id', $defaults)) {
         $subscriptionCancelled = CRM_Member_BAO_Membership::isSubscriptionCancelled($this->_id);
     }
     $alreadyAutoRenew = FALSE;
     if (CRM_Utils_Array::value('contribution_recur_id', $defaults) && !$subscriptionCancelled) {
         $defaults['auto_renew'] = 1;
         $alreadyAutoRenew = TRUE;
     }
     $this->assign('alreadyAutoRenew', $alreadyAutoRenew);
     $this->assign("member_is_test", CRM_Utils_Array::value('member_is_test', $defaults));
     $this->assign('membership_status_id', CRM_Utils_Array::value('status_id', $defaults));
     if (CRM_Utils_Array::value('is_pay_later', $defaults)) {
         $this->assign('is_pay_later', TRUE);
     }
     if ($this->_mode) {
         $fields = array();
         foreach ($this->_fields as $name => $dontCare) {
             $fields[$name] = 1;
         }
         $names = array("first_name", "middle_name", "last_name", "street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "country_id-{$this->_bltID}", "state_province_id-{$this->_bltID}");
         foreach ($names as $name) {
             $fields[$name] = 1;
         }
         $fields["state_province-{$this->_bltID}"] = 1;
         $fields["country-{$this->_bltID}"] = 1;
         $fields["email-{$this->_bltID}"] = 1;
         $fields["email-Primary"] = 1;
         if ($this->_contactID) {
             CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactID, $fields, $this->_defaults);
         }
         // use primary email address if billing email address is empty
         if (empty($this->_defaults["email-{$this->_bltID}"]) && !empty($this->_defaults["email-Primary"])) {
             $defaults["email-{$this->_bltID}"] = $this->_defaults["email-Primary"];
         }
         foreach ($names as $name) {
             if (!empty($this->_defaults[$name])) {
                 $defaults["billing_" . $name] = $this->_defaults[$name];
             }
         }
         //             // hack to simplify credit card entry for testing
         //             $defaults['credit_card_type']     = 'Visa';
         //             $defaults['credit_card_number']   = '4807731747657838';
         //             $defaults['cvv2']                 = '000';
         //             $defaults['credit_card_exp_date'] = array( 'Y' => '2012', 'M' => '05' );
     }
     $dates = array('join_date', 'start_date', 'end_date');
     foreach ($dates as $key) {
         if (CRM_Utils_Array::value($key, $defaults)) {
             list($defaults[$key]) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value($key, $defaults));
         }
     }
     //setting default join date if there is no join date
     if (!CRM_Utils_Array::value('join_date', $defaults)) {
         $defaults['join_date'] = $now;
     }
     if (CRM_Utils_Array::value('membership_end_date', $defaults)) {
         $this->assign('endDate', $defaults['membership_end_date']);
     }
     return $defaults;
 }
コード例 #10
0
ファイル: MembershipRenewal.php プロジェクト: bhirsch/voipdev
 /**
  * This function sets the default values for the form.
  * the default values are retrieved from the database
  * 
  * @access public
  * @return None
  */
 public function setDefaultValues()
 {
     $defaults = array();
     $defaults =& parent::setDefaultValues();
     $this->_memType = $defaults["membership_type_id"];
     $defaults['renewal_date'] = CRM_Utils_Date::getToday($defaults['renewal_date'], 'm/d/Y');
     if ($defaults['id']) {
         $defaults['record_contribution'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipPayment', $defaults['id'], 'contribution_id', 'membership_id');
     }
     $defaults['contribution_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'contribution_type_id');
     $defaults['total_amount'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'minimum_fee');
     $defaults['record_contribution'] = 0;
     if ($defaults['record_contribution']) {
         $contributionParams = array('id' => $defaults['record_contribution']);
         $contributionIds = array();
         require_once "CRM/Contribute/BAO/Contribution.php";
         CRM_Contribute_BAO_Contribution::getValues($contributionParams, $defaults, $contributionIds);
     }
     $defaults['send_receipt'] = 0;
     if ($defaults['membership_type_id']) {
         $defaults['receipt_text_renewal'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $defaults['membership_type_id'], 'receipt_text_renewal');
     }
     $this->assign("member_is_test", CRM_Utils_Array::value('member_is_test', $defaults));
     if ($this->_mode) {
         $fields = array();
         foreach ($this->_fields as $name => $dontCare) {
             $fields[$name] = 1;
         }
         $names = array("first_name", "middle_name", "last_name", "street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "country_id-{$this->_bltID}", "state_province_id-{$this->_bltID}");
         foreach ($names as $name) {
             $fields[$name] = 1;
         }
         $fields["state_province-{$this->_bltID}"] = 1;
         $fields["country-{$this->_bltID}"] = 1;
         $fields["email-{$this->_bltID}"] = 1;
         $fields["email-Primary"] = 1;
         require_once "CRM/Core/BAO/UFGroup.php";
         CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactID, $fields, $this->_defaults);
         // use primary email address if billing email address is empty
         if (empty($this->_defaults["email-{$this->_bltID}"]) && !empty($this->_defaults["email-Primary"])) {
             $defaults["email-{$this->_bltID}"] = $this->_defaults["email-Primary"];
         }
         foreach ($names as $name) {
             if (!empty($this->_defaults[$name])) {
                 $defaults["billing_" . $name] = $this->_defaults[$name];
             }
         }
     }
     return $defaults;
 }
コード例 #11
0
 /**
  * CRM-17797 -- Format fields and setDefaults for primary and additional participants profile
  * @param int $contactId
  * @param CRM_Core_Form $form
  */
 public static function formatFieldsAndSetProfileDefaults($contactId, &$form)
 {
     if (!$contactId) {
         return;
     }
     $fields = array();
     if (!empty($form->_fields)) {
         $removeCustomFieldTypes = array('Participant');
         foreach ($form->_fields as $name => $dontCare) {
             if (substr($name, 0, 7) == 'custom_' && !$form->_allowConfirmation && !CRM_Core_BAO_CustomGroup::checkCustomField(substr($name, 7), $removeCustomFieldTypes) || substr($name, 0, 12) == 'participant_') {
                 continue;
             }
             $fields[$name] = 1;
         }
         if (!empty($fields)) {
             CRM_Core_BAO_UFGroup::setProfileDefaults($contactId, $fields, $form->_defaults);
         }
     }
 }
コード例 #12
0
ファイル: Batch.php プロジェクト: rajeshrhino/civicrm-core
 /**
  * Set default values for the form.
  *
  *
  * @return void
  */
 public function setDefaultValues()
 {
     if (empty($this->_fields)) {
         return;
     }
     $defaults = array();
     foreach ($this->_memberIds as $memberId) {
         $details[$memberId] = array();
         CRM_Core_BAO_UFGroup::setProfileDefaults(NULL, $this->_fields, $defaults, FALSE, $memberId, 'Membership');
     }
     return $defaults;
 }
コード例 #13
0
 /**
  * This function sets the default values for the form.
  *
  * @access public
  *
  * @return None
  */
 function setDefaultValues()
 {
     if (empty($this->_fields)) {
         return;
     }
     $defaults = array();
     foreach ($this->_participantIds as $participantId) {
         $details[$participantId] = array();
         $details[$participantId] = CRM_Event_BAO_Participant::participantDetails($participantId);
         CRM_Core_BAO_UFGroup::setProfileDefaults(NULL, $this->_fields, $defaults, FALSE, $participantId, 'Event');
         //get the from status ids, CRM-4323
         if (array_key_exists('participant_status', $this->_fields)) {
             $this->_fromStatusIds[$participantId] = CRM_Utils_Array::value("field[{$participantId}][participant_status]", $defaults);
         }
         if (array_key_exists('participant_role', $this->_fields)) {
             if ($defaults["field[{$participantId}][participant_role]"]) {
                 $roles = $defaults["field[{$participantId}][participant_role]"];
                 foreach (explode(CRM_Core_DAO::VALUE_SEPARATOR, $roles) as $k => $v) {
                     $defaults["field[{$participantId}][participant_role][{$v}]"] = 1;
                 }
                 unset($defaults["field[{$participantId}][participant_role]"]);
             }
         }
     }
     $this->assign('details', $details);
     return $defaults;
 }
コード例 #14
0
ファイル: UpdateBilling.php プロジェクト: indydas/civi-demo
 /**
  * @return array
  */
 public function setDefaultValues()
 {
     $this->_defaults = array();
     if ($this->_subscriptionDetails->contact_id) {
         $fields = array();
         $names = array('first_name', 'middle_name', 'last_name', "street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "country_id-{$this->_bltID}", "state_province_id-{$this->_bltID}");
         foreach ($names as $name) {
             $fields[$name] = 1;
         }
         $fields["state_province-{$this->_bltID}"] = 1;
         $fields["country-{$this->_bltID}"] = 1;
         $fields["email-{$this->_bltID}"] = 1;
         $fields['email-Primary'] = 1;
         CRM_Core_BAO_UFGroup::setProfileDefaults($this->_subscriptionDetails->contact_id, $fields, $this->_defaults);
         // use primary email address if billing email address is empty
         if (empty($this->_defaults["email-{$this->_bltID}"]) && !empty($this->_defaults['email-Primary'])) {
             $this->_defaults["email-{$this->_bltID}"] = $this->_defaults['email-Primary'];
         }
         foreach ($names as $name) {
             if (!empty($this->_defaults[$name])) {
                 $this->_defaults['billing_' . $name] = $this->_defaults[$name];
             }
         }
     }
     $config = CRM_Core_Config::singleton();
     // set default country from config if no country set
     if (empty($this->_defaults["billing_country_id-{$this->_bltID}"])) {
         $this->_defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
     }
     return $this->_defaults;
 }
コード例 #15
0
 /**
  * Set default values for the form.
  *
  * @access public
  */
 function setDefaultValues()
 {
     $defaults = array();
     if (key_exists('userID', $_SESSION['CiviCRM'])) {
         foreach ($this->getProfileIDs() as $profileID) {
             $fields = array_flip(array_keys(CRM_Core_BAO_UFGroup::getFields($profileID)));
             CRM_Core_BAO_UFGroup::setProfileDefaults($_SESSION['CiviCRM']['userID'], $fields, $defaults);
         }
     }
     return $defaults;
 }
コード例 #16
0
 /**
  * This function sets the default values for the form in edit/view mode
  * the default values are retrieved from the database
  * 
  * @access public
  * @return None
  */
 public function setDefaultValues()
 {
     if ($this->_showFeeBlock) {
         return CRM_Event_Form_EventFees::setDefaultValues($this);
     }
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     $defaults = array();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return $defaults;
     }
     if ($this->_id) {
         $ids = array();
         $params = array('id' => $this->_id);
         require_once "CRM/Event/BAO/Participant.php";
         CRM_Event_BAO_Participant::getValues($params, $defaults, $ids);
         $sep = CRM_Core_DAO::VALUE_SEPARATOR;
         if ($defaults[$this->_id]['role_id']) {
             foreach (explode($sep, $defaults[$this->_id]['role_id']) as $k => $v) {
                 $defaults[$this->_id]["role_id[{$v}]"] = 1;
             }
             unset($defaults[$this->_id]['role_id']);
         }
         $this->_contactId = $defaults[$this->_id]['contact_id'];
         $this->_statusId = $defaults[$this->_id]['participant_status_id'];
         //set defaults for note
         $noteDetails = CRM_Core_BAO_Note::getNote($this->_id, 'civicrm_participant');
         $defaults[$this->_id]['note'] = array_pop($noteDetails);
         // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true  (CRM-4859)
         if (CRM_Event_BAO_Participant::isPrimaryParticipant($this->_id)) {
             $this->assign('additionalParticipants', CRM_Event_BAO_Participant::getAdditionalParticipants($this->_id));
         }
         // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859)
         if (CRM_Utils_Array::value('participant_registered_by_id', $defaults[$this->_id])) {
             $registered_by_contact_id = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Participant", $defaults[$this->_id]['participant_registered_by_id'], 'contact_id', 'id');
             $this->assign('participant_registered_by_id', $defaults[$this->_id]['participant_registered_by_id']);
             $this->assign('registered_by_contact_id', $registered_by_contact_id);
             require_once 'CRM/Contact/BAO/Contact.php';
             $this->assign('registered_by_display_name', CRM_Contact_BAO_Contact::displayName($registered_by_contact_id));
         }
     }
     if ($this->_action & (CRM_Core_Action::VIEW | CRM_Core_Action::BROWSE)) {
         $inactiveNeeded = true;
         $viewMode = true;
     } else {
         $viewMode = false;
         $inactiveNeeded = false;
     }
     //setting default register date
     if ($this->_action == CRM_Core_Action::ADD) {
         $statuses = array_flip($this->_participantStatuses);
         $defaults[$this->_id]['status_id'] = CRM_Utils_Array::value(ts('Registered'), $statuses);
         if (CRM_Utils_Array::value('event_id', $defaults[$this->_id])) {
             $contributionTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $defaults[$this->_id]['event_id'], 'contribution_type_id');
             if ($contributionTypeId) {
                 $defaults[$this->_id]['contribution_type_id'] = $contributionTypeId;
             }
         }
         if ($this->_mode) {
             $fields["email-{$this->_bltID}"] = 1;
             $fields["email-Primary"] = 1;
             if ($this->_contactId) {
                 require_once "CRM/Core/BAO/UFGroup.php";
                 CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactId, $fields, $defaults);
             }
             if (empty($defaults["email-{$this->_bltID}"]) && !empty($defaults["email-Primary"])) {
                 $defaults[$this->_id]["email-{$this->_bltID}"] = $defaults["email-Primary"];
             }
         }
         $submittedRole = $this->getElementValue('role_id');
         if (CRM_Utils_Array::value(0, $submittedRole)) {
             $roleID = $submittedRole[0];
         }
         $submittedEvent = $this->getElementValue('event_id');
         if ($submittedEvent[0]) {
             $eventID = $submittedEvent[0];
         }
     } else {
         $defaults[$this->_id]['record_contribution'] = 0;
         if ($defaults[$this->_id]['participant_is_pay_later']) {
             $this->assign('participant_is_pay_later', true);
         }
         $this->assign('participant_status_id', $defaults[$this->_id]['participant_status_id']);
         $roleID = $defaults[$this->_id]['participant_role_id'];
         $eventID = $defaults[$this->_id]['event_id'];
         $this->_eventTypeId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $eventID, 'event_type_id', 'id');
         $this->_discountId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'discount_id');
         if ($this->_discountId) {
             $this->set('discountId', $this->_discountId);
         }
     }
     list($defaults[$this->_id]['register_date'], $defaults[$this->_id]['register_date_time']) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value('register_date', $defaults[$this->_id]), 'activityDateTime');
     //assign event and role id, this is needed for Custom data building
     $sep = CRM_Core_DAO::VALUE_SEPARATOR;
     if (CRM_Utils_Array::value('participant_role_id', $defaults[$this->_id])) {
         $roleIDs = explode($sep, $defaults[$this->_id]['participant_role_id']);
     }
     if (isset($roleIDs)) {
         $this->assign('roleID', $roleIDs);
     }
     if (isset($_POST['event_id'])) {
         $eventID = $_POST['event_id'];
         if ($eventID) {
             $this->_eventTypeId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $eventID, 'event_type_id', 'id');
         }
     }
     if (isset($eventID)) {
         $this->assign('eventID', $eventID);
         $this->set('eventId', $eventID);
     }
     if (isset($this->_eventTypeId)) {
         $this->assign('eventTypeID', $this->_eventTypeId);
     }
     $this->assign('event_is_test', CRM_Utils_Array::value('event_is_test', $defaults[$this->_id]));
     return $defaults[$this->_id];
 }
コード例 #17
0
ファイル: Form.php プロジェクト: ksecor/civicrm
 /** 
  * This function sets the default values for the form. Note that in edit/view mode 
  * the default values are retrieved from the database 
  *  
  * @access public 
  * @return void 
  */
 function setDefaultsValues()
 {
     $this->_defaults = array();
     if ($this->_id) {
         CRM_Core_BAO_UFGroup::setProfileDefaults($this->_id, $this->_fields, $this->_defaults, true);
     }
     //set custom field defaults
     require_once "CRM/Core/BAO/CustomField.php";
     foreach ($this->_fields as $name => $field) {
         if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
             $htmlType = $field['html_type'];
             if (!CRM_Utils_Array::value($name, $this->_defaults) || $htmlType == 'File') {
                 CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $this->_id, $this->_mode);
             }
             if ($htmlType == 'File') {
                 $url = CRM_Core_BAO_CustomField::getFileURL($this->_id, $customFieldID);
                 if ($url) {
                     $customFiles[$field['name']]['displayURL'] = "Attached File : {$url['file_url']}";
                     $deleteExtra = "Are you sure you want to delete attached file ?";
                     $fileId = $url['file_id'];
                     $deleteURL = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$this->_id}&fid={$customFieldID}&action=delete");
                     $customFiles[$field['name']]['deleteURL'] = "<a href=\"{$deleteURL}\" onclick = \"if (confirm( ' {$deleteExtra} ' )) this.href+='&amp;confirmed=1'; else return false;\">Delete Attached File</a>";
                 }
             }
         }
     }
     if (isset($customFiles)) {
         $this->assign('customFiles', $customFiles);
     }
     $this->setDefaults($this->_defaults);
 }
コード例 #18
0
 /**
  * @return array
  */
 public function setDefaultValues()
 {
     $this->_defaults = array();
     if ($this->_contactID) {
         foreach ($this->_fields as $name => $dontcare) {
             $fields[$name] = 1;
         }
         CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactID, $fields, $this->_defaults);
     }
     //set custom field defaults
     foreach ($this->_fields as $name => $field) {
         if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
             if (!isset($this->_defaults[$name])) {
                 CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, NULL, CRM_Profile_Form::MODE_REGISTER);
             }
         }
     }
     return $this->_defaults;
 }
コード例 #19
0
ファイル: Location.php プロジェクト: hyebahi/civicrm-core
 /**
  * FIXME: we should make this method like getLocBlock() OR use the same method and
  * remove this one.
  *
  * obtain the location of given contact-id.
  * This method is used by on-behalf-of form to dynamically generate poulate the
  * location field values for selected permissioned contact.
  */
 public static function getPermissionedLocation()
 {
     $cid = CRM_Utils_Request::retrieve('cid', 'Integer', CRM_Core_DAO::$_nullObject, TRUE);
     $ufId = CRM_Utils_Request::retrieve('ufId', 'Integer', CRM_Core_DAO::$_nullObject, TRUE);
     // Verify user id
     $user = CRM_Utils_Request::retrieve('uid', 'Integer', CRM_Core_DAO::$_nullObject, FALSE, CRM_Core_Session::singleton()->get('userID'));
     if (empty($user) || CRM_Utils_Request::retrieve('cs', 'String', $form, FALSE) && !CRM_Contact_BAO_Contact_Permission::validateChecksumContact($user, CRM_Core_DAO::$_nullObject, FALSE)) {
         CRM_Utils_System::civiExit();
     }
     // Verify user permission on related contact
     $organizations = CRM_Contact_BAO_Relationship::getPermissionedContacts($user, NULL, NULL, 'Organization');
     if (!isset($organizations[$cid])) {
         CRM_Utils_System::civiExit();
     }
     $values = array();
     $entityBlock = array('contact_id' => $cid);
     $location = CRM_Core_BAO_Location::getValues($entityBlock);
     $config = CRM_Core_Config::singleton();
     $addressSequence = array_flip($config->addressSequence());
     $profileFields = CRM_Core_BAO_UFGroup::getFields($ufId, FALSE, CRM_Core_Action::VIEW, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
     $website = CRM_Core_BAO_Website::getValues($entityBlock, $values);
     foreach ($location as $fld => $values) {
         if (is_array($values) && !empty($values)) {
             $locType = $values[1]['location_type_id'];
             if ($fld == 'email') {
                 $elements["onbehalf_{$fld}-{$locType}"] = array('type' => 'Text', 'value' => $location[$fld][1][$fld]);
                 unset($profileFields["{$fld}-{$locType}"]);
             } elseif ($fld == 'phone') {
                 $phoneTypeId = $values[1]['phone_type_id'];
                 $elements["onbehalf_{$fld}-{$locType}-{$phoneTypeId}"] = array('type' => 'Text', 'value' => $location[$fld][1][$fld]);
                 unset($profileFields["{$fld}-{$locType}-{$phoneTypeId}"]);
             } elseif ($fld == 'im') {
                 $providerId = $values[1]['provider_id'];
                 $elements["onbehalf_{$fld}-{$locType}"] = array('type' => 'Text', 'value' => $location[$fld][1][$fld]);
                 $elements["onbehalf_{$fld}-{$locType}provider_id"] = array('type' => 'Select', 'value' => $location[$fld][1]['provider_id']);
                 unset($profileFields["{$fld}-{$locType}-{$providerId}"]);
             }
         }
     }
     if (!empty($website)) {
         foreach ($website as $key => $val) {
             $websiteTypeId = $values[1]['website_type_id'];
             $elements["onbehalf_url-1"] = array('type' => 'Text', 'value' => $website[1]['url']);
             $elements["onbehalf_url-1-website_type_id"] = array('type' => 'Select', 'value' => $website[1]['website_type_id']);
             unset($profileFields["url-1"]);
         }
     }
     $locTypeId = isset($location['address'][1]) ? $location['address'][1]['location_type_id'] : NULL;
     $addressFields = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'county', 'state_province', 'country');
     foreach ($addressFields as $field) {
         if (array_key_exists($field, $addressSequence)) {
             $addField = $field;
             $type = 'Text';
             if (in_array($field, array('state_province', 'country', 'county'))) {
                 $addField = "{$field}_id";
                 $type = 'Select';
             }
             $elements["onbehalf_{$field}-{$locTypeId}"] = array('type' => $type, 'value' => isset($location['address'][1]) ? CRM_Utils_Array::value($addField, $location['address'][1]) : NULL);
             unset($profileFields["{$field}-{$locTypeId}"]);
         }
     }
     //set custom field defaults
     $defaults = array();
     CRM_Core_BAO_UFGroup::setProfileDefaults($cid, $profileFields, $defaults, TRUE, NULL, NULL, TRUE);
     if (!empty($defaults)) {
         foreach ($profileFields as $key => $val) {
             if (array_key_exists($key, $defaults)) {
                 $htmlType = CRM_Utils_Array::value('html_type', $val);
                 if ($htmlType == 'Radio') {
                     $elements["onbehalf_{$key}"]['type'] = $htmlType;
                     $elements["onbehalf_{$key}"]['value'] = $defaults[$key];
                 } elseif ($htmlType == 'CheckBox') {
                     $elements["onbehalf_{$key}"]['type'] = $htmlType;
                     foreach ($defaults[$key] as $k => $v) {
                         $elements["onbehalf_{$key}"]['value'][$k] = $v;
                     }
                 } elseif (strstr($htmlType, 'Multi-Select') && $htmlType != 'AdvMulti-Select') {
                     $elements["onbehalf_{$key}"]['type'] = 'Multi-Select';
                     $elements["onbehalf_{$key}"]['value'] = array_values($defaults[$key]);
                 } elseif ($htmlType == 'Autocomplete-Select') {
                     $elements["onbehalf_{$key}"]['type'] = $htmlType;
                     $elements["onbehalf_{$key}"]['value'] = $defaults[$key];
                 } elseif ($htmlType == 'Select Date') {
                     $elements["onbehalf_{$key}"]['type'] = $htmlType;
                     $elements["onbehalf_{$key}"]['value'] = $defaults[$key];
                     $elements["onbehalf_{$key}_display"]['value'] = $defaults[$key];
                 } else {
                     $elements["onbehalf_{$key}"]['type'] = $htmlType;
                     $elements["onbehalf_{$key}"]['value'] = $defaults[$key];
                 }
             } else {
                 $elements["onbehalf_{$key}"]['value'] = '';
             }
         }
     }
     CRM_Utils_JSON::output($elements);
 }
コード例 #20
0
 /**
  * This function sets the default values for the form in edit/view mode
  * the default values are retrieved from the database
  *
  *
  * @return void
  */
 public function setDefaultValues()
 {
     if ($this->_showFeeBlock) {
         return CRM_Event_Form_EventFees::setDefaultValues($this);
     }
     $defaults = array();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return $defaults;
     }
     if ($this->_id) {
         $ids = array();
         $params = array('id' => $this->_id);
         CRM_Event_BAO_Participant::getValues($params, $defaults, $ids);
         $sep = CRM_Core_DAO::VALUE_SEPARATOR;
         if ($defaults[$this->_id]['role_id']) {
             $roleIDs = explode($sep, $defaults[$this->_id]['role_id']);
         }
         $this->_contactId = $defaults[$this->_id]['contact_id'];
         $this->_statusId = $defaults[$this->_id]['participant_status_id'];
         //set defaults for note
         $noteDetails = CRM_Core_BAO_Note::getNote($this->_id, 'civicrm_participant');
         $defaults[$this->_id]['note'] = array_pop($noteDetails);
         // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true  (CRM-4859)
         if (CRM_Event_BAO_Participant::isPrimaryParticipant($this->_id)) {
             $this->assign('additionalParticipants', CRM_Event_BAO_Participant::getAdditionalParticipants($this->_id));
         }
         // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859)
         if (!empty($defaults[$this->_id]['participant_registered_by_id'])) {
             $registered_by_contact_id = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $defaults[$this->_id]['participant_registered_by_id'], 'contact_id', 'id');
             $this->assign('participant_registered_by_id', $defaults[$this->_id]['participant_registered_by_id']);
             $this->assign('registered_by_contact_id', $registered_by_contact_id);
             $this->assign('registered_by_display_name', CRM_Contact_BAO_Contact::displayName($registered_by_contact_id));
         }
     }
     if ($this->_action & (CRM_Core_Action::VIEW | CRM_Core_Action::BROWSE)) {
         $inactiveNeeded = TRUE;
         $viewMode = TRUE;
     } else {
         $viewMode = FALSE;
         $inactiveNeeded = FALSE;
     }
     //setting default register date
     if ($this->_action == CRM_Core_Action::ADD) {
         $statuses = array_flip($this->_participantStatuses);
         $defaults[$this->_id]['status_id'] = CRM_Utils_Array::value(ts('Registered'), $statuses);
         if (!empty($defaults[$this->_id]['event_id'])) {
             $contributionTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $defaults[$this->_id]['event_id'], 'financial_type_id');
             if ($contributionTypeId) {
                 $defaults[$this->_id]['financial_type_id'] = $contributionTypeId;
             }
         }
         if ($this->_mode) {
             $fields["email-{$this->_bltID}"] = 1;
             $fields['email-Primary'] = 1;
             if ($this->_contactId) {
                 CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactId, $fields, $defaults);
             }
             if (empty($defaults["email-{$this->_bltID}"]) && !empty($defaults['email-Primary'])) {
                 $defaults[$this->_id]["email-{$this->_bltID}"] = $defaults['email-Primary'];
             }
         }
         $submittedRole = $this->getElementValue('role_id');
         if (!empty($submittedRole[0])) {
             $roleID = $submittedRole[0];
         }
         $submittedEvent = $this->getElementValue('event_id');
         if (!empty($submittedEvent[0])) {
             $eventID = $submittedEvent[0];
         }
     } else {
         $defaults[$this->_id]['record_contribution'] = 0;
         if ($defaults[$this->_id]['participant_is_pay_later']) {
             $this->assign('participant_is_pay_later', TRUE);
         }
         $this->assign('participant_status_id', $defaults[$this->_id]['participant_status_id']);
         $eventID = $defaults[$this->_id]['event_id'];
         $this->_eventTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
         $this->_discountId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'discount_id');
         if ($this->_discountId) {
             $this->set('discountId', $this->_discountId);
         }
     }
     list($defaults[$this->_id]['register_date'], $defaults[$this->_id]['register_date_time']) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value('register_date', $defaults[$this->_id]), 'activityDateTime');
     //assign event and role id, this is needed for Custom data building
     $sep = CRM_Core_DAO::VALUE_SEPARATOR;
     if (!empty($defaults[$this->_id]['participant_role_id'])) {
         $roleIDs = explode($sep, $defaults[$this->_id]['participant_role_id']);
     }
     if (isset($_POST['event_id'])) {
         $eventID = $_POST['event_id'];
     }
     if ($this->_eID) {
         $eventID = $this->_eID;
         //@todo - rationalise the $this->_eID with $POST['event_id'],  $this->_eid is set when eid=x is in the url
         $roleID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_eID, 'default_role_id');
         if (empty($roleIDs)) {
             $roleIDs = (array) ($defaults[$this->_id]['participant_role_id'] = $roleID);
         }
         $defaults[$this->_id]['event_id'] = $eventID;
     }
     if (!empty($eventID)) {
         $this->_eventTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
     }
     //these should take precedence so we state them last
     $urlRoleIDS = CRM_Utils_Request::retrieve('roles', 'String');
     if ($urlRoleIDS) {
         $roleIDs = explode(',', $urlRoleIDS);
     }
     if (isset($roleIDs)) {
         $defaults[$this->_id]['role_id'] = implode(',', $roleIDs);
     }
     if (isset($eventID)) {
         $this->assign('eventID', $eventID);
         $this->set('eventId', $eventID);
     }
     if (isset($this->_eventTypeId)) {
         $this->assign('eventTypeID', $this->_eventTypeId);
     }
     $this->assign('event_is_test', CRM_Utils_Array::value('event_is_test', $defaults[$this->_id]));
     return $defaults[$this->_id];
 }
コード例 #21
0
ファイル: Signature.php プロジェクト: kcristiano/civicrm-core
 /**
  * Set default values for the form.
  */
 public function setDefaultValues()
 {
     $this->_defaults = array();
     if ($this->_contactId) {
         CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactId, $this->_contactProfileFields, $this->_defaults, TRUE);
         if ($this->_activityProfileId) {
             CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactId, $this->_activityProfileFields, $this->_defaults, TRUE);
         }
     }
     //set custom field defaults
     foreach ($this->_contactProfileFields as $name => $field) {
         if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
             $htmlType = $field['html_type'];
             if (!isset($this->_defaults[$name])) {
                 CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $this->_contactId, $this->_mode);
             }
         }
     }
     if ($this->_activityProfileFields) {
         foreach ($this->_activityProfileFields as $name => $field) {
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 $htmlType = $field['html_type'];
                 if (!isset($this->_defaults[$name])) {
                     CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $this->_contactId, $this->_mode);
                 }
             }
         }
     }
     $this->setDefaults($this->_defaults);
 }
コード例 #22
0
ファイル: Batch.php プロジェクト: hguru/224Civi
 /**
  * This function sets the default values for the form.
  *
  * @access public
  *
  * @return None
  */
 function setDefaultValues()
 {
     if (empty($this->_fields)) {
         return;
     }
     $defaults = $sortName = array();
     foreach ($this->_contactIds as $contactId) {
         $details[$contactId] = array();
         //build sortname
         $sortName[$contactId] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactId, 'sort_name');
         CRM_Core_BAO_UFGroup::setProfileDefaults($contactId, $this->_fields, $defaults, FALSE);
     }
     $this->assign('sortName', $sortName);
     // now fix all state country selectors
     CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults, $this->_stateCountryCountyFields);
     return $defaults;
 }
コード例 #23
0
ファイル: Batch.php プロジェクト: FundingWorks/civicrm-core
 /**
  * Set default values for the form.
  *
  *
  * @return array
  */
 public function setDefaultValues()
 {
     if (empty($this->_fields)) {
         return NULL;
     }
     $defaults = $sortName = array();
     foreach ($this->_contactIds as $contactId) {
         $details[$contactId] = array();
         //build sortname
         $sortName[$contactId] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactId, 'sort_name');
         CRM_Core_BAO_UFGroup::setProfileDefaults($contactId, $this->_fields, $defaults, FALSE);
     }
     $this->assign('sortName', $sortName);
     return $defaults;
 }
コード例 #24
0
 /**
  * This function sets the default values for the form.
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return void
  */
 public function setDefaultValues()
 {
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     $defaults = array();
     $defaults = parent::setDefaultValues();
     $this->_memType = $defaults['membership_type_id'];
     // set renewal_date and receive_date to today in correct input format (setDateDefaults uses today if no value passed)
     list($now, $currentTime) = CRM_Utils_Date::setDateDefaults();
     $defaults['renewal_date'] = $now;
     $defaults['receive_date'] = $now;
     $defaults['receive_date_time'] = $currentTime;
     if ($defaults['id']) {
         $defaults['record_contribution'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipPayment', $defaults['id'], 'contribution_id', 'membership_id');
     }
     if (is_numeric($this->_memType)) {
         $defaults['membership_type_id'] = array();
         $defaults['membership_type_id'][0] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'member_of_contact_id', 'id');
         $defaults['membership_type_id'][1] = $this->_memType;
     } else {
         $defaults['membership_type_id'] = $this->_memType;
     }
     $defaults['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'financial_type_id');
     //CRM-13420
     if (empty($defaults['payment_instrument_id'])) {
         $defaults['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1'));
     }
     $defaults['total_amount'] = CRM_Utils_Money::format(CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'minimum_fee'), NULL, '%a');
     $defaults['record_contribution'] = 0;
     $defaults['num_terms'] = 1;
     $defaults['send_receipt'] = 0;
     $renewalDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('renewal_date', $defaults), NULL, NULL, 'Y-m-d');
     $this->assign('renewalDate', $renewalDate);
     $this->assign('member_is_test', CRM_Utils_Array::value('member_is_test', $defaults));
     if ($this->_mode) {
         $fields = array();
         foreach ($this->_fields as $name => $dontCare) {
             $fields[$name] = 1;
         }
         $names = array('first_name', 'middle_name', 'last_name', "street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "country_id-{$this->_bltID}", "state_province_id-{$this->_bltID}");
         foreach ($names as $name) {
             $fields[$name] = 1;
         }
         $fields["state_province-{$this->_bltID}"] = 1;
         $fields["country-{$this->_bltID}"] = 1;
         $fields["email-{$this->_bltID}"] = 1;
         $fields['email-Primary'] = 1;
         CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactID, $fields, $this->_defaults);
         // use primary email address if billing email address is empty
         if (empty($this->_defaults["email-{$this->_bltID}"]) && !empty($this->_defaults['email-Primary'])) {
             $defaults["email-{$this->_bltID}"] = $this->_defaults['email-Primary'];
         }
         foreach ($names as $name) {
             if (!empty($this->_defaults[$name])) {
                 $defaults['billing_' . $name] = $this->_defaults[$name];
             }
         }
     }
     return $defaults;
 }
コード例 #25
0
ファイル: Main.php プロジェクト: nielosz/civicrm-core
 /**
  * Set the default values.
  */
 public function setDefaultValues()
 {
     // check if the user is registered and we have a contact ID
     $contactID = $this->getContactID();
     if (!empty($contactID)) {
         $fields = array();
         $removeCustomFieldTypes = array('Contribution', 'Membership');
         $contribFields = CRM_Contribute_BAO_Contribution::getContributionFields();
         // remove component related fields
         foreach ($this->_fields as $name => $dontCare) {
             //don't set custom data Used for Contribution (CRM-1344)
             if (substr($name, 0, 7) == 'custom_') {
                 $id = substr($name, 7);
                 if (!CRM_Core_BAO_CustomGroup::checkCustomField($id, $removeCustomFieldTypes)) {
                     continue;
                 }
                 // ignore component fields
             } elseif (array_key_exists($name, $contribFields) || substr($name, 0, 11) == 'membership_' || substr($name, 0, 13) == 'contribution_') {
                 continue;
             }
             $fields[$name] = 1;
         }
         if (!empty($fields)) {
             CRM_Core_BAO_UFGroup::setProfileDefaults($contactID, $fields, $this->_defaults);
         }
         $billingDefaults = $this->getProfileDefaults('Billing', $contactID);
         $this->_defaults = array_merge($this->_defaults, $billingDefaults);
     }
     if (!empty($this->_ccid) && !empty($this->_pendingAmount)) {
         $this->_defaults['total_amount'] = CRM_Utils_Money::format($this->_pendingAmount, NULL, '%a');
     }
     /*
      * hack to simplify credit card entry for testing
      *
      * $this->_defaults['credit_card_type']     = 'Visa';
      *         $this->_defaults['amount']               = 168;
      *         $this->_defaults['credit_card_number']   = '4111111111111111';
      *         $this->_defaults['cvv2']                 = '000';
      *         $this->_defaults['credit_card_exp_date'] = array('Y' => date('Y')+1, 'M' => '05');
      *         // hack to simplify direct debit entry for testing
      *         $this->_defaults['account_holder'] = 'Max Müller';
      *         $this->_defaults['bank_account_number'] = '12345678';
      *         $this->_defaults['bank_identification_number'] = '12030000';
      *         $this->_defaults['bank_name'] = 'Bankname';
      */
     //build set default for pledge overdue payment.
     if (!empty($this->_values['pledge_id'])) {
         //used to record completed pledge payment ids used later for honor default
         $completedContributionIds = array();
         $pledgePayments = CRM_Pledge_BAO_PledgePayment::getPledgePayments($this->_values['pledge_id']);
         $paymentAmount = 0;
         $duePayment = FALSE;
         foreach ($pledgePayments as $payId => $value) {
             if ($value['status'] == 'Overdue') {
                 $this->_defaults['pledge_amount'][$payId] = 1;
                 $paymentAmount += $value['scheduled_amount'];
             } elseif (!$duePayment && $value['status'] == 'Pending') {
                 $this->_defaults['pledge_amount'][$payId] = 1;
                 $paymentAmount += $value['scheduled_amount'];
                 $duePayment = TRUE;
             } elseif ($value['status'] == 'Completed' && $value['contribution_id']) {
                 $completedContributionIds[] = $value['contribution_id'];
             }
         }
         $this->_defaults['price_' . $this->_priceSetId] = $paymentAmount;
         if (count($completedContributionIds)) {
             $softCredit = array();
             foreach ($completedContributionIds as $id) {
                 $softCredit = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($id);
             }
             if (isset($softCredit['soft_credit'])) {
                 $this->_defaults['soft_credit_type_id'] = $softCredit['soft_credit'][1]['soft_credit_type'];
                 //since honoree profile fieldname of fields are prefixed with 'honor'
                 //we need to reformat the fieldname to append prefix during setting default values
                 CRM_Core_BAO_UFGroup::setProfileDefaults($softCredit['soft_credit'][1]['contact_id'], CRM_Core_BAO_UFGroup::getFields($this->_honoreeProfileId), $defaults);
                 foreach ($defaults as $fieldName => $value) {
                     $this->_defaults['honor[' . $fieldName . ']'] = $value;
                 }
             }
         }
     } elseif (!empty($this->_values['pledge_block_id'])) {
         //set default to one time contribution.
         $this->_defaults['is_pledge'] = 0;
     }
     // to process Custom data that are appended to URL
     $getDefaults = CRM_Core_BAO_CustomGroup::extractGetParams($this, "'Contact', 'Individual', 'Contribution'");
     $this->_defaults = array_merge($this->_defaults, $getDefaults);
     $config = CRM_Core_Config::singleton();
     // set default country from config if no country set
     if (empty($this->_defaults["billing_country_id-{$this->_bltID}"])) {
         $this->_defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
     }
     // set default state/province from config if no state/province set
     if (empty($this->_defaults["billing_state_province_id-{$this->_bltID}"])) {
         $this->_defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince;
     }
     $entityId = $memtypeID = NULL;
     if ($this->_priceSetId) {
         if ($this->_useForMember && !empty($this->_currentMemberships) || $this->_defaultMemTypeId) {
             $selectedCurrentMemTypes = array();
             foreach ($this->_priceSet['fields'] as $key => $val) {
                 foreach ($val['options'] as $keys => $values) {
                     $opMemTypeId = CRM_Utils_Array::value('membership_type_id', $values);
                     $priceFieldName = 'price_' . $values['price_field_id'];
                     $priceFieldValue = CRM_Price_BAO_PriceSet::getPriceFieldValueFromURL($this, $priceFieldName);
                     if (!empty($priceFieldValue)) {
                         CRM_Price_BAO_PriceSet::setDefaultPriceSetField($priceFieldName, $priceFieldValue, $val['html_type'], $this->_defaults);
                         // break here to prevent overwriting of default due to 'is_default'
                         // option configuration or setting of current membership or
                         // membership for related organization.
                         // The value sent via URL get's higher priority.
                         break;
                     } elseif ($opMemTypeId && in_array($opMemTypeId, $this->_currentMemberships) && !in_array($opMemTypeId, $selectedCurrentMemTypes)) {
                         CRM_Price_BAO_PriceSet::setDefaultPriceSetField($priceFieldName, $keys, $val['html_type'], $this->_defaults);
                         $memtypeID = $selectedCurrentMemTypes[] = $values['membership_type_id'];
                     } elseif (!empty($values['is_default']) && !$opMemTypeId && (!isset($this->_defaults[$priceFieldName]) || $val['html_type'] == 'CheckBox' && !isset($this->_defaults[$priceFieldName][$keys]))) {
                         CRM_Price_BAO_PriceSet::setDefaultPriceSetField($priceFieldName, $keys, $val['html_type'], $this->_defaults);
                         $memtypeID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $this->_defaults[$priceFieldName], 'membership_type_id');
                     }
                 }
             }
             $entityId = CRM_Utils_Array::value('id', CRM_Member_BAO_Membership::getContactMembership($contactID, $memtypeID, NULL));
         } else {
             CRM_Price_BAO_PriceSet::setDefaultPriceSet($this, $this->_defaults);
         }
     }
     //set custom field defaults set by admin if value is not set
     if (!empty($this->_fields)) {
         //load default campaign from page.
         if (array_key_exists('contribution_campaign_id', $this->_fields)) {
             $this->_defaults['contribution_campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values);
         }
         //set custom field defaults
         foreach ($this->_fields as $name => $field) {
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 if (!isset($this->_defaults[$name])) {
                     CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $entityId, CRM_Profile_Form::MODE_REGISTER);
                 }
             }
         }
     }
     if (!empty($this->_paymentProcessors)) {
         foreach ($this->_paymentProcessors as $pid => $value) {
             if (!empty($value['is_default'])) {
                 $this->_defaults['payment_processor_id'] = $pid;
             }
         }
     }
     return $this->_defaults;
 }
コード例 #26
0
ファイル: PCPAccount.php プロジェクト: hguru/224Civi
 function setDefaultValues()
 {
     $this->_defaults = array();
     if ($this->_contactID) {
         foreach ($this->_fields as $name => $dontcare) {
             $fields[$name] = 1;
         }
         CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactID, $fields, $this->_defaults);
     }
     $stateCountryMap = array();
     //set custom field defaults
     foreach ($this->_fields as $name => $field) {
         if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
             if (!isset($this->_defaults[$name])) {
                 CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, NULL, CRM_Profile_Form::MODE_REGISTER);
             }
         }
         if (substr($name, 0, 14) === 'state_province' || substr($name, 0, 7) === 'country' || substr($name, 0, 6) === 'county') {
             list($fieldName, $index) = CRM_Utils_System::explode('-', $name, 2);
             if (!array_key_exists($index, $stateCountryMap)) {
                 $stateCountryMap[$index] = array();
             }
             $stateCountryMap[$index][$fieldName] = $name;
         }
         // also take care of state country widget
         if (!empty($stateCountryMap)) {
             CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap, $this->_defaults);
         }
     }
     // now fix all state country selectors
     CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
     return $this->_defaults;
 }
コード例 #27
0
ファイル: Batch.php プロジェクト: bhirsch/voipdev
 /**
  * This function sets the default values for the form.
  * 
  * @access public
  * @return None
  */
 function setDefaultValues()
 {
     if (empty($this->_fields)) {
         return;
     }
     $defaults = array();
     foreach ($this->_contributionIds as $contributionId) {
         $details[$contributionId] = array();
         CRM_Core_BAO_UFGroup::setProfileDefaults(null, $this->_fields, $defaults, false, $contributionId, 'Contribute');
     }
     return $defaults;
 }
コード例 #28
0
 /**
  * This function sets the default values for the form. For edit/view mode
  * the default values are retrieved from the database
  * Adding discussion from CRM-11915 as code comments
  * When multiple payment processors are configured for a event and user does any selection changes for them on online event registeration page :
  * The 'Register' page gets loaded through ajax and following happens :
  * the setDefaults function is called with the variable _ppType set with selected payment processor type,
  * so in the 'if' condition checked whether the selected payment processor's billing mode is of 'billing form mode'. If its not, don't setDefaults for billing form and return instead.
  *- For payment processors of billing mode 'Notify' - return from setDefaults before the code for billing profile population execution .
  * (done this is because for payment processors with 'Notify' mode billing profile form doesn't get rendered on UI)
  *
  * @access public
  *
  * @return None
  */
 function setDefaultValues()
 {
     if ($this->_ppType && $this->_snippet && !($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM)) {
         // see function comment block for explanation of this
         return;
     }
     $this->_defaults = array();
     $contactID = $this->getContactID();
     $billingDefaults = $this->getProfileDefaults('Billing', $contactID);
     $this->_defaults = array_merge($this->_defaults, $billingDefaults);
     $config = CRM_Core_Config::singleton();
     // set default country from config if no country set
     // note the effect of this is to set the billing country to default to the site default
     // country if the person has an address but no country (for anonymous country is set above)
     // this could have implications if the billing profile is filled but hidden.
     // this behaviour has been in place for a while but the use of js to hide things has increased
     if (!CRM_Utils_Array::value("billing_country_id-{$this->_bltID}", $this->_defaults)) {
         $this->_defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
     }
     // set default state/province from config if no state/province set
     if (!CRM_Utils_Array::value("billing_state_province_id-{$this->_bltID}", $this->_defaults)) {
         $this->_defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince;
     }
     if ($this->_snippet) {
         // now fix all state country selectors
         CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
         return $this->_defaults;
     }
     if ($contactID) {
         $options = array();
         $fields = array();
         if (!empty($this->_fields)) {
             $removeCustomFieldTypes = array('Participant');
             foreach ($this->_fields as $name => $dontCare) {
                 if (substr($name, 0, 7) == 'custom_') {
                     $id = substr($name, 7);
                     if (!$this->_allowConfirmation && !CRM_Core_BAO_CustomGroup::checkCustomField($id, $removeCustomFieldTypes)) {
                         continue;
                     }
                     // ignore component fields
                 } elseif (substr($name, 0, 12) == 'participant_') {
                     continue;
                 }
                 $fields[$name] = 1;
             }
         }
     }
     if (!empty($fields)) {
         CRM_Core_BAO_UFGroup::setProfileDefaults($contactID, $fields, $this->_defaults);
     }
     // now fix all state country selectors
     CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
     // Set default payment processor as default payment_processor radio button value
     if (!empty($this->_paymentProcessors)) {
         foreach ($this->_paymentProcessors as $pid => $value) {
             if (CRM_Utils_Array::value('is_default', $value)) {
                 $this->_defaults['payment_processor'] = $pid;
             }
         }
     }
     //if event is monetary and pay later is enabled and payment
     //processor is not available then freeze the pay later checkbox with
     //default check
     if (CRM_Utils_Array::value('is_pay_later', $this->_values['event']) && !is_array($this->_paymentProcessor)) {
         $this->_defaults['is_pay_later'] = 1;
     }
     //set custom field defaults
     if (!empty($this->_fields)) {
         //load default campaign from page.
         if (array_key_exists('participant_campaign_id', $this->_fields)) {
             $this->_defaults['participant_campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values['event']);
         }
         foreach ($this->_fields as $name => $field) {
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 // fix for CRM-1743
                 if (!isset($this->_defaults[$name])) {
                     CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, NULL, CRM_Profile_Form::MODE_REGISTER);
                 }
             }
         }
     }
     //fix for CRM-3088, default value for discount set.
     $discountId = NULL;
     if (!empty($this->_values['discount'])) {
         $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
         if ($discountId) {
             if (isset($this->_values['event']['default_discount_fee_id'])) {
                 $discountKey = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_values['event']['default_discount_fee_id'], 'weight', 'id');
                 $this->_defaults['amount'] = key(array_slice($this->_values['discount'][$discountId], $discountKey - 1, $discountKey, TRUE));
             }
         }
     }
     // add this event's default participant role to defaults array
     // (for cases where participant_role field is included in form via profile)
     if ($this->_values['event']['default_role_id']) {
         $this->_defaults['participant_role'] = $this->_defaults['participant_role_id'] = $this->_values['event']['default_role_id'];
     }
     if ($this->_priceSetId && !empty($this->_feeBlock)) {
         foreach ($this->_feeBlock as $key => $val) {
             foreach ($val['options'] as $keys => $values) {
                 if ($values['is_default'] && !CRM_Utils_Array::value('is_full', $values)) {
                     if ($val['html_type'] == 'CheckBox') {
                         $this->_defaults["price_{$key}"][$keys] = 1;
                     } else {
                         $this->_defaults["price_{$key}"] = $keys;
                     }
                 }
             }
         }
     }
     //set default participant fields, CRM-4320.
     $hasAdditionalParticipants = FALSE;
     if ($this->_allowConfirmation) {
         $this->_contactId = $contactID;
         $this->_discountId = $discountId;
         $forcePayLater = CRM_Utils_Array::value('is_pay_later', $this->_defaults, FALSE);
         $this->_defaults = array_merge($this->_defaults, CRM_Event_Form_EventFees::setDefaultValues($this));
         $this->_defaults['is_pay_later'] = $forcePayLater;
         if ($this->_additionalParticipantIds) {
             $hasAdditionalParticipants = TRUE;
             $this->_defaults['additional_participants'] = count($this->_additionalParticipantIds);
         }
     }
     $this->assign('hasAdditionalParticipants', $hasAdditionalParticipants);
     //         //hack to simplify credit card entry for testing
     //         $this->_defaults['credit_card_type']     = 'Visa';
     //         $this->_defaults['credit_card_number']   = '4807731747657838';
     //         $this->_defaults['cvv2']                 = '000';
     //         $this->_defaults['credit_card_exp_date'] = array( 'Y' => '2010', 'M' => '05' );
     // to process Custom data that are appended to URL
     $getDefaults = CRM_Core_BAO_CustomGroup::extractGetParams($this, "'Contact', 'Individual', 'Contribution', 'Participant'");
     if (!empty($getDefaults)) {
         $this->_defaults = array_merge($this->_defaults, $getDefaults);
     }
     return $this->_defaults;
 }
コード例 #29
0
 /**
  * This function sets the default values for the form.
  *
  * @access public
  *
  * @return void
  */
 function setDefaultValues()
 {
     if (empty($this->_fields)) {
         return;
     }
     $defaults = array();
     foreach ($this->_activityHolderIds as $activityId) {
         $details[$activityId] = array();
         CRM_Core_BAO_UFGroup::setProfileDefaults(NULL, $this->_fields, $defaults, FALSE, $activityId, 'Activity');
     }
     return $defaults;
 }
コード例 #30
0
 /**
  * This function sets the default values for the form.
  *
  * @access public
  *
  * @return void
  */
 function setDefaultValues()
 {
     $this->_defaults = array();
     if ($this->_contactId) {
         CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactId, $this->_contactProfileFields, $this->_defaults, TRUE);
         if ($this->_activityProfileId) {
             CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactId, $this->_activityProfileFields, $this->_defaults, TRUE);
         }
     }
     //set custom field defaults
     foreach ($this->_contactProfileFields as $name => $field) {
         if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
             $htmlType = $field['html_type'];
             if (!isset($this->_defaults[$name])) {
                 CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $this->_contactId, $this->_mode);
             }
         }
     }
     if ($this->_activityProfileFields) {
         foreach ($this->_activityProfileFields as $name => $field) {
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 $htmlType = $field['html_type'];
                 if (!isset($this->_defaults[$name])) {
                     CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $this->_contactId, $this->_mode);
                 }
             }
         }
     }
     $this->setDefaults($this->_defaults);
     // add in all state country selectors for enabled countries
     CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
 }