/**
  * Build the form object elements for Communication Preferences object.
  *
  * @param CRM_Core_Form $form
  *   Reference to the form object.
  *
  * @return void
  */
 public static function buildQuickForm(&$form)
 {
     // since the pcm - preferred comminication method is logically
     // grouped hence we'll use groups of HTML_QuickForm
     // checkboxes for DO NOT phone, email, mail
     // we take labels from SelectValues
     $privacy = $commPreff = $commPreference = array();
     $privacyOptions = CRM_Core_SelectValues::privacy();
     // we add is_opt_out as a separate checkbox below for display and help purposes so remove it here
     unset($privacyOptions['is_opt_out']);
     foreach ($privacyOptions as $name => $label) {
         $privacy[] = $form->createElement('advcheckbox', $name, NULL, $label);
     }
     $form->addGroup($privacy, 'privacy', ts('Privacy'), ' ');
     // preferred communication method
     $comm = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method', array('loclize' => TRUE));
     foreach ($comm as $value => $title) {
         $commPreff[] = $form->createElement('advcheckbox', $value, NULL, $title);
     }
     $form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Method(s)'));
     $form->addSelect('preferred_language');
     if (!empty($privacyOptions)) {
         $commPreference['privacy'] = $privacyOptions;
     }
     if (!empty($comm)) {
         $commPreference['preferred_communication_method'] = $comm;
     }
     //using for display purpose.
     $form->assign('commPreference', $commPreference);
     $form->add('select', 'preferred_mail_format', ts('Email Format'), CRM_Core_SelectValues::pmf());
     $form->add('checkbox', 'is_opt_out', ts('NO BULK EMAILS (User Opt Out)'));
     $communicationStyleOptions = array();
     $communicationStyle = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'communication_style_id', array('localize' => TRUE));
     foreach ($communicationStyle as $key => $var) {
         $communicationStyleOptions[$key] = $form->createElement('radio', NULL, ts('Communication Style'), $var, $key, array('id' => "civicrm_communication_style_{$var}_{$key}"));
     }
     if (!empty($communicationStyleOptions)) {
         $form->addGroup($communicationStyleOptions, 'communication_style_id', ts('Communication Style'));
     }
     //check contact type and build filter clause accordingly for greeting types, CRM-4575
     $greetings = self::getGreetingFields($form->_contactType);
     foreach ($greetings as $greeting => $fields) {
         $filter = array('contact_type' => $form->_contactType, 'greeting_type' => $greeting);
         //add addressee in Contact form
         $greetingTokens = CRM_Core_PseudoConstant::greeting($filter);
         if (!empty($greetingTokens)) {
             $form->addElement('select', $fields['field'], $fields['label'], array('' => ts('- select -')) + $greetingTokens);
             //custom addressee
             $form->addElement('text', $fields['customField'], $fields['customLabel'], CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', $fields['customField']), $fields['js']);
         }
     }
 }
Beispiel #2
0
 /**
  * Function used to build form element for soft credit block.
  *
  * @param CRM_Core_Form $form
  *
  * @return \CRM_Core_Form
  */
 public static function buildQuickForm(&$form)
 {
     if (!empty($form->_honor_block_is_active)) {
         $ufJoinDAO = new CRM_Core_DAO_UFJoin();
         $ufJoinDAO->module = 'soft_credit';
         $ufJoinDAO->entity_id = $form->_id;
         if ($ufJoinDAO->find(TRUE)) {
             $jsonData = CRM_Contribute_BAO_ContributionPage::formatModuleData($ufJoinDAO->module_data, TRUE, 'soft_credit');
             if ($jsonData) {
                 foreach (array('honor_block_title', 'honor_block_text') as $name) {
                     $form->assign($name, $jsonData[$name]);
                 }
                 $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
                 // radio button for Honor Type
                 foreach ($jsonData['soft_credit_types'] as $value) {
                     $honorTypes[$value] = $form->createElement('radio', NULL, NULL, $softCreditTypes[$value], $value);
                 }
                 $form->addGroup($honorTypes, 'soft_credit_type_id', NULL)->setAttribute('allowClear', TRUE);
             }
         }
         return $form;
     }
     // by default generate 10 blocks
     $item_count = 11;
     $showSoftCreditRow = 2;
     if ($form->getAction() & CRM_Core_Action::UPDATE) {
         $form->_softCreditInfo = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($form->_id, TRUE);
     } elseif (!empty($form->_pledgeID)) {
         //Check and select most recent completed contrubtion and use it to retrieve
         //soft-credit information to use as default for current pledge payment, CRM-13981
         $pledgePayments = CRM_Pledge_BAO_PledgePayment::getPledgePayments($form->_pledgeID);
         foreach ($pledgePayments as $id => $record) {
             if ($record['contribution_id']) {
                 $softCredits = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($record['contribution_id'], TRUE);
                 if ($record['status'] == 'Completed' && count($softCredits) > 0) {
                     $form->_softCreditInfo = $softCredits;
                 }
             }
         }
     }
     if (property_exists($form, "_softCreditInfo")) {
         if (!empty($form->_softCreditInfo['soft_credit'])) {
             $showSoftCreditRow = count($form->_softCreditInfo['soft_credit']);
             $showSoftCreditRow++;
         }
     }
     for ($rowNumber = 1; $rowNumber <= $item_count; $rowNumber++) {
         $form->addEntityRef("soft_credit_contact_id[{$rowNumber}]", ts('Contact'), array('create' => TRUE));
         $form->addMoney("soft_credit_amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE);
         $form->addSelect("soft_credit_type[{$rowNumber}]", array('entity' => 'contribution_soft', 'field' => 'soft_credit_type_id', 'label' => ts('Type')));
         if (!empty($form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id'])) {
             $form->add('hidden', "soft_credit_id[{$rowNumber}]", $form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id']);
         }
     }
     self::addPCPFields($form);
     $form->assign('showSoftCreditRow', $showSoftCreditRow);
     $form->assign('rowCount', $item_count);
     $form->addElement('hidden', 'sct_default_id', CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"), array('id' => 'sct_default_id'));
 }
 /**
  * Build the form object for Advance Settings.
  *
  *
  * @param CRM_Core_Form $form
  *
  * @return void
  */
 public static function buildAdvanceSetting(&$form)
 {
     // should mapping be enabled for this group
     $form->addElement('checkbox', 'is_map', ts('Enable mapping for this profile?'));
     // should we allow updates on a exisitng contact
     $options = array();
     $options[] = $form->createElement('radio', NULL, NULL, ts('Issue warning and do not save'), 0);
     $options[] = $form->createElement('radio', NULL, NULL, ts('Update the matching contact'), 1);
     $options[] = $form->createElement('radio', NULL, NULL, ts('Allow duplicate contact to be created'), 2);
     $form->addGroup($options, 'is_update_dupe', ts('What to do upon duplicate match'));
     // we do not have any url checks to allow relative urls
     $form->addElement('text', 'post_URL', ts('Redirect URL'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFGroup', 'post_URL'));
     $form->addElement('text', 'cancel_URL', ts('Cancel Redirect URL'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFGroup', 'cancel_URL'));
     // add select for groups
     $group = array('' => ts('- select -')) + $form->_group;
     $form->_groupElement =& $form->addElement('select', 'group', ts('Limit listings to a specific Group?'), $group);
     //add notify field
     $form->addElement('text', 'notify', ts('Notify when profile form is submitted?'));
     //group where new contacts are directed.
     $form->addElement('select', 'add_contact_to_group', ts('Add new contacts to a Group?'), $group);
     // add CAPTCHA To this group ?
     $form->addElement('checkbox', 'add_captcha', ts('Include reCAPTCHA?'));
     // should we display an edit link
     $form->addElement('checkbox', 'is_edit_link', ts('Include profile edit links in search results?'));
     // should we display a link to the website profile
     $config = CRM_Core_Config::singleton();
     $form->addElement('checkbox', 'is_uf_link', ts('Include %1 user account information links in search results?', array(1 => $config->userFramework)));
     // want to create cms user
     $session = CRM_Core_Session::singleton();
     $cmsId = FALSE;
     if ($form->_cId = $session->get('userID')) {
         $form->_cmsId = TRUE;
     }
     $options = array();
     $options[] = $form->createElement('radio', NULL, NULL, ts('No account create option'), 0);
     $options[] = $form->createElement('radio', NULL, NULL, ts('Give option, but not required'), 1);
     $options[] = $form->createElement('radio', NULL, NULL, ts('Account creation required'), 2);
     $form->addGroup($options, 'is_cms_user', ts('%1 user account registration option?', array(1 => $config->userFramework)));
     // options for including Proximity Search in the profile search form
     $proxOptions = array();
     $proxOptions[] = $form->createElement('radio', NULL, NULL, ts('None'), 0);
     $proxOptions[] = $form->createElement('radio', NULL, NULL, ts('Optional'), 1);
     $proxOptions[] = $form->createElement('radio', NULL, NULL, ts('Required'), 2);
     $form->addGroup($proxOptions, 'is_proximity_search', ts('Proximity Search'));
 }
 /**
  * build the form elements for Communication Preferences object
  *
  * @param CRM_Core_Form $form       reference to the form object
  *
  * @return void
  * @access public
  * @static
  */
 static function buildQuickForm(&$form)
 {
     // since the pcm - preferred comminication method is logically
     // grouped hence we'll use groups of HTML_QuickForm
     // checkboxes for DO NOT phone, email, mail
     // we take labels from SelectValues
     $privacy = $commPreff = $commPreference = array();
     $privacyOptions = CRM_Core_SelectValues::privacy();
     foreach ($privacyOptions as $name => $label) {
         $privacy[] = HTML_QuickForm::createElement('advcheckbox', $name, null, $label);
     }
     $form->addGroup($privacy, 'privacy', ts('Privacy'), '&nbsp;');
     // preferred communication method
     require_once 'CRM/Core/PseudoConstant.php';
     $comm = CRM_Core_PseudoConstant::pcm();
     foreach ($comm as $value => $title) {
         $commPreff[] = HTML_QuickForm::createElement('advcheckbox', $value, null, $title);
     }
     $form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Method(s)'));
     $form->add('select', 'preferred_language', ts('Preferred Language'), array('' => ts('- select -')) + CRM_Core_PseudoConstant::languages());
     if (!empty($privacyOptions)) {
         $commPreference['privacy'] = $privacyOptions;
     }
     if (!empty($comm)) {
         $commPreference['preferred_communication_method'] = $comm;
     }
     //using for display purpose.
     $form->assign('commPreference', $commPreference);
     $form->add('select', 'preferred_mail_format', ts('Email Format'), CRM_Core_SelectValues::pmf());
     $form->add('checkbox', 'is_opt_out', ts('NO BULK EMAILS (User Opt Out)'));
     //check contact type and build filter clause accordingly for greeting types, CRM-4575
     $greetings = self::getGreetingFields($form->_contactType);
     foreach ($greetings as $greeting => $fields) {
         $filter = array('contact_type' => $form->_contactType, 'greeting_type' => $greeting);
         //add addressee in Contact form
         $greetingTokens = CRM_Core_PseudoConstant::greeting($filter);
         if (!empty($greetingTokens)) {
             $form->addElement('select', $fields['field'], $fields['label'], array('' => ts('- select -')) + $greetingTokens);
             //custom addressee
             $form->addElement('text', $fields['customField'], $fields['customLabel'], CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', $fields['customField']), $fields['js']);
         }
     }
 }
 /**
  * build the form elements for Demographics object
  *
  * @param CRM_Core_Form $form       reference to the form object
  *
  * @return void
  * @access public
  * @static
  */
 static function buildQuickForm(&$form)
 {
     // radio button for gender
     $genderOptions = array();
     $gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id', array('localize' => TRUE));
     foreach ($gender as $key => $var) {
         $genderOptions[$key] = $form->createElement('radio', NULL, ts('Gender'), $var, $key, array('id' => "civicrm_gender_{$var}_{$key}"));
     }
     $form->addGroup($genderOptions, 'gender_id', ts('Gender'))->setAttribute('unselectable', TRUE);
     $form->addDate('birth_date', ts('Date of Birth'), FALSE, array('formatType' => 'birth'));
     $form->addElement('checkbox', 'is_deceased', NULL, ts('Contact is deceased'), array('onclick' => "showDeceasedDate()"));
     $form->addDate('deceased_date', ts('Deceased date'), FALSE, array('formatType' => 'birth'));
 }
 /**
  * build the form elements for Demographics object
  *
  * @param CRM_Core_Form $form       reference to the form object
  *
  * @return void
  * @access public
  * @static
  */
 static function buildQuickForm(&$form)
 {
     // radio button for gender
     $genderOptions = array();
     $gender = CRM_Core_PseudoConstant::gender();
     foreach ($gender as $key => $var) {
         $genderOptions[$key] = HTML_QuickForm::createElement('radio', null, ts('Gender'), $var, $key);
     }
     $form->addGroup($genderOptions, 'gender_id', ts('Gender'));
     $form->addDate('birth_date', ts('Date of birth'), false, array('formatType' => 'birth'));
     $form->addElement('checkbox', 'is_deceased', null, ts('Contact is deceased'), array('onclick' => "showDeceasedDate()"));
     $form->addDate('deceased_date', ts('Deceased date'), false, array('formatType' => 'birth'));
 }
Beispiel #7
0
 /**
  * Add profile field to a form.
  *
  * @param CRM_Core_Form $form
  * @param array $field
  *   Properties.
  * @param int $mode
  *   Profile mode.
  * @param int $contactId
  * @param bool $online
  * @param string $usedFor
  *   For building up prefixed fieldname for special cases (e.g. onBehalf, Honor).
  * @param int $rowNumber
  * @param string $prefix
  *
  * @return null
  */
 public static function buildProfile(&$form, &$field, $mode, $contactId = NULL, $online = FALSE, $usedFor = NULL, $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 NULL;
     }
     if ($usedFor == 'onbehalf') {
         $name = "onbehalf[{$fieldName}]";
     } elseif ($usedFor == 'honor') {
         $name = "honor[{$fieldName}]";
     } elseif ($contactId && !$online) {
         $name = "field[{$contactId}][{$fieldName}]";
     } elseif ($rowNumber) {
         $name = "field[{$rowNumber}][{$fieldName}]";
     } elseif (!empty($prefix)) {
         $name = $prefix . "[{$fieldName}]";
     } else {
         $name = $fieldName;
     }
     $selectAttributes = array('class' => 'crm-select2', 'placeholder' => TRUE);
     if ($fieldName == 'image_URL' && $mode == CRM_Profile_Form::MODE_EDIT) {
         $deleteExtra = json_encode(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 = "' . htmlspecialchars("if (confirm({$deleteExtra})) this.href+='&confirmed=1'; else return false;") . '"'));
         $deleteURL = CRM_Core_Action::formLink($deleteURL, CRM_Core_Action::DELETE, array('id' => $form->get('id'), 'gid' => $form->get('gid')), ts('more'), FALSE, 'contact.profileimage.delete', 'Contact', $form->get('id'));
         $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->addChainSelect($name, array('label' => $title, 'required' => $required));
         $config = CRM_Core_Config::singleton();
         if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactStateProvince) {
             $defaultValues[$name] = $config->defaultContactStateProvince;
             $form->setDefaults($defaultValues);
         }
     } elseif (substr($fieldName, 0, 7) === 'country') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required, $selectAttributes);
         $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->addChainSelect($name, array('label' => $title, 'required' => $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 ($usedFor) {
                 if (substr($name, -1) == ']') {
                     $providerName = substr($name, 0, -1) . '-provider_id]';
                 }
                 $form->add('select', $providerName, NULL, array('' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $required);
             } else {
                 $form->add('select', $name . '-provider_id', $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $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' => 'activityDate'));
     } elseif (CRM_Utils_Array::value('name', $field) == 'membership_type') {
         list($orgInfo, $types) = CRM_Member_BAO_MembershipType::getMembershipTypeInfo();
         $sel =& $form->addElement('hierselect', $name, $title);
         $select = array('' => ts('- select -'));
         if (count($orgInfo) == 1 && $field['is_required']) {
             // we only have one org - so we should default to it. Not sure about defaulting to first type
             // as it could be missed - so adding a select
             // however, possibly that is more similar to the membership form
             if (count($types[1]) > 1) {
                 $types[1] = $select + $types[1];
             }
         } else {
             $orgInfo = $select + $orgInfo;
         }
         $sel->setOptions(array($orgInfo, $types));
     } elseif (CRM_Utils_Array::value('name', $field) == 'membership_status') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'), $required);
     } elseif (in_array($fieldName, array('gender_id', 'communication_style_id'))) {
         $options = array();
         $pseudoValues = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', $fieldName);
         foreach ($pseudoValues as $key => $var) {
             $options[$key] = $form->createElement('radio', NULL, ts($title), $var, $key);
         }
         $group = $form->addGroup($options, $name, $title);
         if ($required) {
             $form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required');
         } else {
             $group->setAttribute('allowClear', TRUE);
         }
     } elseif ($fieldName === 'prefix_id' || $fieldName === 'suffix_id') {
         $form->addSelect($name, array('label' => $title, 'entity' => 'contact', 'field' => $fieldName, 'class' => 'six', 'placeholder' => ''), $required);
     } elseif ($fieldName === 'contact_sub_type') {
         $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
         if ($usedFor == 'onbehalf') {
             $profileType = 'Organization';
         } elseif ($usedFor == 'honor') {
             $profileType = CRM_Core_BAO_UFField::getProfileType($form->_params['honoree_profile_id']);
         } else {
             $profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : NULL;
             if ($profileType == 'Contact') {
                 $profileType = 'Individual';
             }
         }
         $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;
         }
         $form->add('select', $name, $title, $subtypeList, $required, array('class' => 'crm-select2', 'multiple' => 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::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
         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_Contact_BAO_Contact::buildOptions('preferred_language'));
     } 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->add('text', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Website', 'url'), $required);
         $form->addRule($name, ts('Enter a valid web address beginning with \'http://\' or \'https://\'.'), 'url');
     } elseif (substr($fieldName, -4) == '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') {
         $form->addEntityRef("soft_credit_contact_id[{$rowNumber}]", ts('Soft Credit To'), array('create' => TRUE));
         $form->addMoney("soft_credit_amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE);
     } 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 == 'financial_type') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType(), $required);
     } elseif ($fieldName == 'contribution_status_id') {
         $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus();
         $statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
         foreach (array('In Progress', 'Overdue', 'Refunded') as $suppress) {
             unset($contributionStatuses[CRM_Utils_Array::key($suppress, $statusName)]);
         }
         $form->add('select', $name, $title, array('' => ts('- select -')) + $contributionStatuses, $required);
     } elseif ($fieldName == 'soft_credit_type') {
         $name = "soft_credit_type[{$rowNumber}]";
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_OptionGroup::values("soft_credit_type"));
         //CRM-15350: choose SCT field default value as 'Gift' for membership use
         //else (for contribution), use configured SCT default value
         $SCTDefaultValue = CRM_Core_OptionGroup::getDefaultValue("soft_credit_type");
         if ($field['field_type'] == 'Membership') {
             $SCTDefaultValue = CRM_Core_OptionGroup::getValue('soft_credit_type', 'Gift', 'name');
         }
         $form->addElement('hidden', 'sct_default_id', $SCTDefaultValue, array('id' => 'sct_default_id'));
     } 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 (!empty($field['is_multiple'])) {
             $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 == 'world_region') {
         $form->add('select', $name, $title, CRM_Core_PseudoConstant::worldRegion(), $required, $selectAttributes);
     } elseif ($fieldName == 'signature_html') {
         $form->add('wysiwyg', $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));
             $form->add('select', $name, $title, array('' => ts('- select -')) + $campaigns, $required, 'class="crm-select2 big"');
         }
     } elseif ($fieldName == 'activity_details') {
         $form->add('wysiwyg', $fieldName, $title, array('rows' => 4, 'cols' => 60), $required);
     } elseif ($fieldName == 'activity_duration') {
         $form->add('text', $name, $title, $attributes, $required);
         $form->addRule($name, ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger');
     } else {
         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 ($usedFor) {
             $form->addElement('hidden', $usedFor . '[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);
         }
     }
 }
Beispiel #8
0
 /**
  * Build Premium B im Contribution Pages.
  *
  * @param CRM_Core_Form $form
  * @param int $productID
  * @param int $premiumProductID
  */
 public function buildPremiumPreviewBlock($form, $productID, $premiumProductID = NULL)
 {
     if ($premiumProductID) {
         $dao = new CRM_Contribute_DAO_PremiumsProduct();
         $dao->id = $premiumProductID;
         $dao->find(TRUE);
         $productID = $dao->product_id;
     }
     $productDAO = new CRM_Contribute_DAO_Product();
     $productDAO->id = $productID;
     $productDAO->is_active = 1;
     if ($productDAO->find(TRUE)) {
         CRM_Core_DAO::storeValues($productDAO, $products[$productDAO->id]);
     }
     $radio[$productDAO->id] = $form->createElement('radio', NULL, NULL, NULL, $productDAO->id, NULL);
     $options = $temp = array();
     $temp = explode(',', $productDAO->options);
     foreach ($temp as $value) {
         $options[$value] = $value;
     }
     if ($temp[0] != '') {
         $form->add('select', 'options_' . $productDAO->id, NULL, $options);
     }
     $form->addGroup($radio, 'selectProduct', NULL);
     $form->assign('showRadio', TRUE);
     $form->assign('showSelectOptions', TRUE);
     $form->assign('products', $products);
     $form->assign('preview', TRUE);
 }
 /**
  * build form elements.
  * params object $form object of the form
  *
  * @param CRM_Core_Form $form
  *   The form object that we are operating on.
  * @param int $contactId
  *   Contact id.
  * @param int $type
  *   What components are we interested in.
  * @param bool $visibility
  *   Visibility of the field.
  * @param null $isRequired
  * @param string $groupName
  *   If used for building group block.
  * @param string $tagName
  *   If used for building tag block.
  * @param string $fieldName
  *   This is used in batch profile(i.e to build multiple blocks).
  *
  * @param string $groupElementType
  *
  */
 public static function buildQuickForm(&$form, $contactId = 0, $type = self::ALL, $visibility = FALSE, $isRequired = NULL, $groupName = 'Group(s)', $tagName = 'Tag(s)', $fieldName = NULL, $groupElementType = 'checkbox')
 {
     if (!isset($form->_tagGroup)) {
         $form->_tagGroup = array();
     }
     // NYSS 5670
     if (!$contactId && !empty($form->_contactId)) {
         $contactId = $form->_contactId;
     }
     $type = (int) $type;
     if ($type & self::GROUP) {
         $fName = 'group';
         if ($fieldName) {
             $fName = $fieldName;
         }
         $groupID = isset($form->_grid) ? $form->_grid : NULL;
         if ($groupID && $visibility) {
             $ids = array($groupID => $groupID);
         } else {
             if ($visibility) {
                 $group = CRM_Core_PseudoConstant::allGroup();
             } else {
                 $group = CRM_Core_PseudoConstant::group();
             }
             $ids = $group;
         }
         if ($groupID || !empty($group)) {
             $groups = CRM_Contact_BAO_Group::getGroupsHierarchy($ids);
             $attributes['skiplabel'] = TRUE;
             $elements = array();
             $groupsOptions = array();
             foreach ($groups as $id => $group) {
                 // make sure that this group has public visibility
                 if ($visibility && $group['visibility'] == 'User and User Admin Only') {
                     continue;
                 }
                 if ($groupElementType == 'select') {
                     $groupsOptions[$id] = $group['title'];
                 } else {
                     $form->_tagGroup[$fName][$id]['description'] = $group['description'];
                     $elements[] =& $form->addElement('advcheckbox', $id, NULL, $group['title'], $attributes);
                 }
             }
             if ($groupElementType == 'select' && !empty($groupsOptions)) {
                 $form->add('select', $fName, $groupName, $groupsOptions, FALSE, array('id' => $fName, 'multiple' => 'multiple', 'class' => 'crm-select2'));
                 $form->assign('groupCount', count($groupsOptions));
             }
             if ($groupElementType == 'checkbox' && !empty($elements)) {
                 $form->addGroup($elements, $fName, $groupName, '&nbsp;<br />');
                 $form->assign('groupCount', count($elements));
                 if ($isRequired) {
                     $form->addRule($fName, ts('%1 is a required field.', array(1 => $groupName)), 'required');
                 }
             }
             $form->assign('groupElementType', $groupElementType);
         }
     }
     if ($type & self::TAG) {
         $fName = 'tag';
         if ($fieldName) {
             $fName = $fieldName;
         }
         $form->_tagGroup[$fName] = 1;
         // get the list of all the categories
         $tags = new CRM_Core_BAO_Tag();
         $tree = $tags->getTree('civicrm_contact', TRUE);
         // let's not load jstree if there are not children. This also fixes blank
         // display at the beginning of checkboxes
         $loadJsTree = CRM_Utils_Array::retrieveValueRecursive($tree, 'children');
         $form->assign('loadjsTree', FALSE);
         if (!empty($loadJsTree)) {
             // CODE FROM CRM/Tag/Form/Tag.php //
             CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header');
             $form->assign('loadjsTree', TRUE);
         }
         $elements = array();
         self::climbtree($form, $tree, $elements);
         $form->addGroup($elements, $fName, $tagName, '<br />');
         $form->assign('tagCount', count($elements));
         $form->assign('tree', $tree);
         $form->assign('tag', $tree);
         $form->assign('entityID', $contactId);
         $form->assign('entityTable', 'civicrm_contact');
         if ($isRequired) {
             $form->addRule($fName, ts('%1 is a required field.', array(1 => $tagName)), 'required');
         }
         // build tag widget
         $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact');
         CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', $contactId, FALSE, TRUE);
     }
     $form->assign('tagGroup', $form->_tagGroup);
 }
 /**
  * Build form.
  *
  * @param CRM_Core_Form $form
  */
 public static function buildQuickForm(&$form)
 {
     // FIXME: this is using the following as keys rather than the standard numeric keys returned by CRM_Utils_Date
     $dayOfTheWeek = array();
     $dayKeys = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday');
     foreach (CRM_Utils_Date::getAbbrWeekdayNames() as $k => $label) {
         $dayOfTheWeek[$dayKeys[$k]] = $label;
     }
     $form->add('select', 'repetition_frequency_unit', ts('Repeats every'), CRM_Core_SelectValues::getRecurringFrequencyUnits(), FALSE, array('class' => 'required'));
     $numericOptions = CRM_Core_SelectValues::getNumericOptions(1, 30);
     $form->add('select', 'repetition_frequency_interval', NULL, $numericOptions, FALSE, array('class' => 'required'));
     $form->addDateTime('repetition_start_date', ts('Repetition Start Date'), FALSE, array('formatType' => 'activityDateTime'));
     foreach ($dayOfTheWeek as $key => $val) {
         $startActionCondition[] = $form->createElement('checkbox', $key, NULL, $val);
     }
     $form->addGroup($startActionCondition, 'start_action_condition', ts('Repeats on'));
     $roptionTypes = array('1' => ts('day of the month'), '2' => ts('day of the week'));
     $form->addRadio('repeats_by', ts("Repeats by"), $roptionTypes, array('required' => TRUE), NULL);
     $form->add('select', 'limit_to', '', CRM_Core_SelectValues::getNumericOptions(1, 31));
     $dayOfTheWeekNo = array('first' => ts('First'), 'second' => ts('Second'), 'third' => ts('Third'), 'fourth' => ts('Fourth'), 'last' => ts('Last'));
     $form->add('select', 'entity_status_1', '', $dayOfTheWeekNo);
     $form->add('select', 'entity_status_2', '', $dayOfTheWeek);
     $eoptionTypes = array('1' => ts('After'), '2' => ts('On'));
     $form->addRadio('ends', ts("Ends"), $eoptionTypes, array('class' => 'required'), NULL);
     // Offset options gets key=>val pairs like 1=>2 because the BAO wants to know the number of
     // children while it makes more sense to the user to see the total number including the parent.
     $offsetOptions = range(1, 30);
     unset($offsetOptions[0]);
     $form->add('select', 'start_action_offset', NULL, $offsetOptions, FALSE);
     $form->addFormRule(array('CRM_Core_Form_RecurringEntity', 'formRule'));
     $form->addDate('repeat_absolute_date', ts('On'), FALSE, array('formatType' => 'mailing'));
     $form->add('text', 'exclude_date_list', ts('Exclude Dates'), array('class' => 'twenty'));
     $form->addElement('hidden', 'allowRepeatConfigToSubmit', '', array('id' => 'allowRepeatConfigToSubmit'));
     $form->addButtons(array(array('type' => 'submit', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
     // For client-side pluralization
     $form->assign('recurringFrequencyOptions', array('single' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::getRecurringFrequencyUnits()), 'plural' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::getRecurringFrequencyUnits(2))));
 }
Beispiel #11
0
 /**
  * This function for building custom fields.
  *
  * @param CRM_Core_Form $qf
  *   Form object (reference).
  * @param string $elementName
  *   Name of the custom field.
  * @param int $fieldId
  * @param bool $inactiveNeeded
  * @param bool $useRequired
  *   True if required else false.
  * @param string $label
  *   Label for custom field.
  *
  * @param null $fieldOptions
  * @param array $freezeOptions
  *
  * @return null
  */
 public static function addQuickFormElement(&$qf, $elementName, $fieldId, $inactiveNeeded, $useRequired = TRUE, $label = NULL, $fieldOptions = NULL, $freezeOptions = array())
 {
     $field = new CRM_Price_DAO_PriceField();
     $field->id = $fieldId;
     if (!$field->find(TRUE)) {
         /* FIXME: failure! */
         return NULL;
     }
     $is_pay_later = 0;
     if (isset($qf->_mode) && empty($qf->_mode)) {
         $is_pay_later = 1;
     } elseif (isset($qf->_values)) {
         $is_pay_later = CRM_Utils_Array::value('is_pay_later', $qf->_values);
     }
     $otherAmount = $qf->get('values');
     $config = CRM_Core_Config::singleton();
     $currencySymbol = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_Currency', $config->defaultCurrency, 'symbol', 'name');
     $qf->assign('currencySymbol', $currencySymbol);
     // get currency name for price field and option attributes
     $currencyName = $config->defaultCurrency;
     if (!isset($label)) {
         $label = !empty($qf->_membershipBlock) && $field->name == 'contribution_amount' ? ts('Additional Contribution') : $field->label;
     }
     if ($field->name == 'contribution_amount') {
         $qf->_contributionAmount = 1;
     }
     if (isset($qf->_online) && $qf->_online) {
         $useRequired = FALSE;
     }
     $customOption = $fieldOptions;
     if (!is_array($customOption)) {
         $customOption = CRM_Price_BAO_PriceField::getOptions($field->id, $inactiveNeeded);
     }
     //use value field.
     $valueFieldName = 'amount';
     $seperator = '|';
     $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
     $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
     $displayOpt = CRM_Utils_Array::value('tax_display_settings', $invoiceSettings);
     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
     switch ($field->html_type) {
         case 'Text':
             $optionKey = key($customOption);
             $count = CRM_Utils_Array::value('count', $customOption[$optionKey], '');
             $max_value = CRM_Utils_Array::value('max_value', $customOption[$optionKey], '');
             $taxAmount = CRM_Utils_Array::value('tax_amount', $customOption[$optionKey]);
             if (isset($taxAmount) && $displayOpt && $invoicing) {
                 $qf->assign('displayOpt', $displayOpt);
                 $qf->assign('taxTerm', $taxTerm);
                 $qf->assign('invoicing', $invoicing);
             }
             $priceVal = implode($seperator, array($customOption[$optionKey][$valueFieldName] + $taxAmount, $count, $max_value));
             $extra = array();
             if (!empty($qf->_membershipBlock) && !empty($qf->_quickConfig) && $field->name == 'other_amount' && empty($qf->_contributionAmount)) {
                 $useRequired = 0;
             } elseif (!empty($fieldOptions[$optionKey]['label'])) {
                 //check for label.
                 $label = $fieldOptions[$optionKey]['label'];
                 if (!empty($qf->_quickConfig) && !empty($qf->_contributionAmount) && strtolower($fieldOptions[$optionKey]['name']) == 'other_amount') {
                     $label .= '  ' . $currencySymbol;
                     $qf->assign('priceset', $elementName);
                     $extra = array('onclick' => 'useAmountOther();');
                 }
             }
             $element =& $qf->add('text', $elementName, $label, array_merge($extra, array('price' => json_encode(array($optionKey, $priceVal)), 'size' => '4')), $useRequired && $field->is_required);
             if ($is_pay_later) {
                 $qf->add('text', 'txt-' . $elementName, $label, array('size' => '4'));
             }
             // CRM-6902 - Add "max" option for a price set field
             if (in_array($optionKey, $freezeOptions)) {
                 self::freezeIfEnabled($element, $fieldOptions[$optionKey]);
                 // CRM-14696 - Improve display for sold out price set options
                 $element->setLabel($label . '&nbsp;<span class="sold-out-option">' . ts('Sold out') . '</span>');
             }
             //CRM-10117
             if (!empty($qf->_quickConfig)) {
                 $message = ts('Please enter a valid amount.');
                 $type = 'money';
             } else {
                 $message = ts('%1 must be a number (with or without decimal point).', array(1 => $label));
                 $type = 'numeric';
             }
             // integers will have numeric rule applied to them.
             $qf->addRule($elementName, $message, $type);
             break;
         case 'Radio':
             $choice = array();
             if (!empty($qf->_quickConfig) && !empty($qf->_contributionAmount)) {
                 $qf->assign('contriPriceset', $elementName);
             }
             foreach ($customOption as $opId => $opt) {
                 $taxAmount = CRM_Utils_Array::value('tax_amount', $opt);
                 if ($field->is_display_amounts) {
                     $opt['label'] = !empty($opt['label']) ? $opt['label'] . '<span class="crm-price-amount-label-separator">&nbsp;-&nbsp;</span>' : '';
                     $preHelpText = $postHelpText = '';
                     if (isset($opt['help_pre'])) {
                         $preHelpText = '<span class="crm-price-amount-help-pre description">' . $opt['help_pre'] . '</span>: ';
                     }
                     if (isset($opt['help_post'])) {
                         $postHelpText = ': <span class="crm-price-amount-help-post description">' . $opt['help_post'] . '</span>';
                     }
                     if (isset($taxAmount) && $invoicing) {
                         if ($displayOpt == 'Do_not_show') {
                             $opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName] + $taxAmount) . '</span>';
                         } elseif ($displayOpt == 'Inclusive') {
                             $opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName] + $taxAmount) . '</span>';
                             $opt['label'] .= '<span class="crm-price-amount-tax"> (includes ' . $taxTerm . ' of ' . CRM_Utils_Money::format($opt['tax_amount']) . ')</span>';
                         } else {
                             $opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName]) . '</span>';
                             $opt['label'] .= '<span class="crm-price-amount-tax"> + ' . CRM_Utils_Money::format($opt['tax_amount']) . ' ' . $taxTerm . '</span>';
                         }
                     } else {
                         $opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName]) . '</span>';
                     }
                     $opt['label'] = $preHelpText . $opt['label'] . $postHelpText;
                 }
                 $count = CRM_Utils_Array::value('count', $opt, '');
                 $max_value = CRM_Utils_Array::value('max_value', $opt, '');
                 $priceVal = implode($seperator, array($opt[$valueFieldName] + $taxAmount, $count, $max_value));
                 $extra = array('price' => json_encode(array($elementName, $priceVal)), 'data-amount' => $opt[$valueFieldName], 'data-currency' => $currencyName, 'data-price-field-values' => json_encode($customOption));
                 if (!empty($qf->_quickConfig) && $field->name == 'contribution_amount') {
                     $extra += array('onclick' => 'clearAmountOther();');
                 } elseif (!empty($qf->_quickConfig) && $field->name == 'membership_amount') {
                     $extra += array('onclick' => "return showHideAutoRenew({$opt['membership_type_id']});", 'membership-type' => $opt['membership_type_id']);
                     $qf->assign('membershipFieldID', $field->id);
                 }
                 $choice[$opId] = $qf->createElement('radio', NULL, '', $opt['label'], $opt['id'], $extra);
                 if ($is_pay_later) {
                     $qf->add('text', 'txt-' . $elementName, $label, array('size' => '4'));
                 }
                 // CRM-6902 - Add "max" option for a price set field
                 if (in_array($opId, $freezeOptions)) {
                     self::freezeIfEnabled($choice[$opId], $customOption[$opId]);
                     // CRM-14696 - Improve display for sold out price set options
                     $choice[$opId]->setText('<span class="sold-out-option">' . $choice[$opId]->getText() . '&nbsp;(' . ts('Sold out') . ')</span>');
                 }
             }
             if (!empty($qf->_membershipBlock) && $field->name == 'contribution_amount') {
                 $choice[] = $qf->createElement('radio', NULL, '', ts('No thank you'), '-1', array('price' => json_encode(array($elementName, '0|0')), 'data-currency' => $currencyName, 'onclick' => 'clearAmountOther();'));
             }
             if (!$field->is_required) {
                 // add "none" option
                 if (!empty($otherAmount['is_allow_other_amount']) && $field->name == 'contribution_amount') {
                     $none = ts('Other Amount');
                 } elseif (!empty($qf->_membershipBlock) && empty($qf->_membershipBlock['is_required']) && $field->name == 'membership_amount') {
                     $none = ts('No thank you');
                 } else {
                     $none = ts('- none -');
                 }
                 $choice[] = $qf->createElement('radio', NULL, '', $none, '0', array('price' => json_encode(array($elementName, '0'))));
             }
             $element =& $qf->addGroup($choice, $elementName, $label);
             // make contribution field required for quick config when membership block is enabled
             if (($field->name == 'membership_amount' || $field->name == 'contribution_amount') && !empty($qf->_membershipBlock) && !$field->is_required) {
                 $useRequired = $field->is_required = TRUE;
             }
             if ($useRequired && $field->is_required) {
                 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
             }
             break;
         case 'Select':
             $selectOption = $allowedOptions = $priceVal = array();
             foreach ($customOption as $opt) {
                 $taxAmount = CRM_Utils_Array::value('tax_amount', $opt);
                 $count = CRM_Utils_Array::value('count', $opt, '');
                 $max_value = CRM_Utils_Array::value('max_value', $opt, '');
                 if ($field->is_display_amounts) {
                     $opt['label'] .= '&nbsp;-&nbsp;';
                     if (isset($taxAmount) && $invoicing) {
                         $opt['label'] = $opt['label'] . self::getTaxLabel($opt, $valueFieldName, $displayOpt, $taxTerm);
                     } else {
                         $opt['label'] = $opt['label'] . CRM_Utils_Money::format($opt[$valueFieldName]);
                     }
                 }
                 $priceVal[$opt['id']] = implode($seperator, array($opt[$valueFieldName] + $taxAmount, $count, $max_value));
                 if (!in_array($opt['id'], $freezeOptions)) {
                     $allowedOptions[] = $opt['id'];
                 } else {
                     $opt['id'] = 'crm_disabled_opt-' . $opt['id'];
                     $opt['label'] = $opt['label'] . ' (' . ts('Sold out') . ')';
                 }
                 $selectOption[$opt['id']] = $opt['label'];
                 if ($is_pay_later) {
                     $qf->add('text', 'txt-' . $elementName, $label, array('size' => '4'));
                 }
             }
             $element =& $qf->add('select', $elementName, $label, array('' => ts('- select -')) + $selectOption, $useRequired && $field->is_required, array('price' => json_encode($priceVal), 'class' => 'crm-select2', 'data-price-field-values' => json_encode($customOption)));
             // CRM-6902 - Add "max" option for a price set field
             $button = substr($qf->controller->getButtonName(), -4);
             if (!empty($freezeOptions) && $button != 'skip') {
                 $qf->addRule($elementName, ts('Sorry, this option is currently sold out.'), 'regex', "/" . implode('|', $allowedOptions) . "/");
             }
             break;
         case 'CheckBox':
             $check = array();
             foreach ($customOption as $opId => $opt) {
                 $taxAmount = CRM_Utils_Array::value('tax_amount', $opt);
                 $count = CRM_Utils_Array::value('count', $opt, '');
                 $max_value = CRM_Utils_Array::value('max_value', $opt, '');
                 if ($field->is_display_amounts) {
                     $preHelpText = $postHelpText = '';
                     if (isset($opt['help_pre'])) {
                         $preHelpText = '<span class="crm-price-amount-help-pre description">' . $opt['help_pre'] . '</span>: ';
                     }
                     if (isset($opt['help_post'])) {
                         $postHelpText = ': <span class="crm-price-amount-help-post description">' . $opt['help_post'] . '</span>';
                     }
                     $opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>&nbsp;-&nbsp;';
                     if (isset($taxAmount) && $invoicing) {
                         $opt['label'] .= self::getTaxLabel($opt, $valueFieldName, $displayOpt, $taxTerm);
                     } else {
                         $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]);
                     }
                     $opt['label'] = $preHelpText . $opt['label'] . $postHelpText;
                 }
                 $priceVal = implode($seperator, array($opt[$valueFieldName] + $taxAmount, $count, $max_value));
                 $check[$opId] =& $qf->createElement('checkbox', $opt['id'], NULL, $opt['label'], array('price' => json_encode(array($opt['id'], $priceVal)), 'data-amount' => $opt[$valueFieldName], 'data-currency' => $currencyName));
                 if ($is_pay_later) {
                     $txtcheck[$opId] =& $qf->createElement('text', $opId, $opt['label'], array('size' => '4'));
                     $qf->addGroup($txtcheck, 'txt-' . $elementName, $label);
                 }
                 // CRM-6902 - Add "max" option for a price set field
                 if (in_array($opId, $freezeOptions)) {
                     self::freezeIfEnabled($check[$opId], $customOption[$opId]);
                     // CRM-14696 - Improve display for sold out price set options
                     $check[$opId]->setText('<span class="sold-out-option">' . $check[$opId]->getText() . '&nbsp;(' . ts('Sold out') . ')</span>');
                 }
             }
             $element =& $qf->addGroup($check, $elementName, $label);
             if ($useRequired && $field->is_required) {
                 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
             }
             break;
     }
     if (isset($qf->_online) && $qf->_online) {
         $element->freeze();
     }
 }
Beispiel #12
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']);
         }
     }
 }
Beispiel #13
0
 /**
  * Build Pledge Block in Contribution Pages.
  *
  * @param CRM_Core_Form $form
  */
 public static function buildPledgeBlock($form)
 {
     //build pledge payment fields.
     if (!empty($form->_values['pledge_id'])) {
         //get all payments required details.
         $allPayments = array();
         $returnProperties = array('status_id', 'scheduled_date', 'scheduled_amount', 'currency', 'pledge_start_date');
         CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_PledgePayment', 'pledge_id', $form->_values['pledge_id'], $allPayments, $returnProperties);
         // get all status
         $allStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
         $nextPayment = array();
         $isNextPayment = FALSE;
         $overduePayments = array();
         foreach ($allPayments as $payID => $value) {
             if ($allStatus[$value['status_id']] == 'Overdue') {
                 $overduePayments[$payID] = array('id' => $payID, 'scheduled_amount' => CRM_Utils_Rule::cleanMoney($value['scheduled_amount']), 'scheduled_amount_currency' => $value['currency'], 'scheduled_date' => CRM_Utils_Date::customFormat($value['scheduled_date'], '%B %d'));
             } elseif (!$isNextPayment && $allStatus[$value['status_id']] == 'Pending') {
                 // get the next payment.
                 $nextPayment = array('id' => $payID, 'scheduled_amount' => CRM_Utils_Rule::cleanMoney($value['scheduled_amount']), 'scheduled_amount_currency' => $value['currency'], 'scheduled_date' => CRM_Utils_Date::customFormat($value['scheduled_date'], '%B %d'));
                 $isNextPayment = TRUE;
             }
         }
         // build check box array for payments.
         $payments = array();
         if (!empty($overduePayments)) {
             foreach ($overduePayments as $id => $payment) {
                 $label = ts("%1 - due on %2 (overdue)", array(1 => CRM_Utils_Money::format(CRM_Utils_Array::value('scheduled_amount', $payment), CRM_Utils_Array::value('scheduled_amount_currency', $payment)), 2 => CRM_Utils_Array::value('scheduled_date', $payment)));
                 $paymentID = CRM_Utils_Array::value('id', $payment);
                 $payments[] = $form->createElement('checkbox', $paymentID, NULL, $label, array('amount' => CRM_Utils_Array::value('scheduled_amount', $payment)));
             }
         }
         if (!empty($nextPayment)) {
             $label = ts("%1 - due on %2", array(1 => CRM_Utils_Money::format(CRM_Utils_Array::value('scheduled_amount', $nextPayment), CRM_Utils_Array::value('scheduled_amount_currency', $nextPayment)), 2 => CRM_Utils_Array::value('scheduled_date', $nextPayment)));
             $paymentID = CRM_Utils_Array::value('id', $nextPayment);
             $payments[] = $form->createElement('checkbox', $paymentID, NULL, $label, array('amount' => CRM_Utils_Array::value('scheduled_amount', $nextPayment)));
         }
         // give error if empty or build form for payment.
         if (empty($payments)) {
             CRM_Core_Error::fatal(ts("Oops. It looks like there is no valid payment status for online payment."));
         } else {
             $form->assign('is_pledge_payment', TRUE);
             $form->addGroup($payments, 'pledge_amount', ts('Make Pledge Payment(s):'), '<br />');
         }
     } else {
         $pledgeBlock = self::getPledgeBlock($form->_id);
         // build form for pledge creation.
         $pledgeOptions = array('0' => ts('I want to make a one-time contribution'), '1' => ts('I pledge to contribute this amount every'));
         $form->addRadio('is_pledge', ts('Pledge Frequency Interval'), $pledgeOptions, NULL, array('<br/>'));
         $form->addElement('text', 'pledge_installments', ts('Installments'), array('size' => 3));
         if (!empty($pledgeBlock['is_pledge_interval'])) {
             $form->assign('is_pledge_interval', CRM_Utils_Array::value('is_pledge_interval', $pledgeBlock));
             $form->addElement('text', 'pledge_frequency_interval', NULL, array('size' => 3));
         } else {
             $form->add('hidden', 'pledge_frequency_interval', 1);
         }
         // Frequency unit drop-down label suffixes switch from *ly to *(s)
         $freqUnitVals = explode(CRM_Core_DAO::VALUE_SEPARATOR, $pledgeBlock['pledge_frequency_unit']);
         $freqUnits = array();
         $frequencyUnits = CRM_Core_OptionGroup::values('recur_frequency_units');
         foreach ($freqUnitVals as $key => $val) {
             if (array_key_exists($val, $frequencyUnits)) {
                 $freqUnits[$val] = !empty($pledgeBlock['is_pledge_interval']) ? "{$frequencyUnits[$val]}(s)" : $frequencyUnits[$val];
             }
         }
         $form->addElement('select', 'pledge_frequency_unit', NULL, $freqUnits);
         // CRM-18854
         if (CRM_Utils_Array::value('is_pledge_start_date_visible', $pledgeBlock)) {
             if (CRM_Utils_Array::value('pledge_start_date', $pledgeBlock)) {
                 $defaults = array();
                 $date = (array) json_decode($pledgeBlock['pledge_start_date']);
                 list($field, $value) = each($date);
                 switch ($field) {
                     case 'contribution_date':
                         $form->addDate('start_date', ts('First installment payment'));
                         $paymentDate = $value = date('d/m/Y');
                         list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults($value);
                         $form->assign('is_date', TRUE);
                         break;
                     case 'calendar_date':
                         $form->addDate('start_date', ts('First installment payment'));
                         list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults($value);
                         $form->assign('is_date', TRUE);
                         $paymentDate = $value;
                         break;
                     case 'calendar_month':
                         $month = CRM_Utils_Date::getCalendarDayOfMonth();
                         $form->add('select', 'start_date', ts('Day of month installments paid'), $month);
                         $paymentDate = CRM_Pledge_BAO_Pledge::getPaymentDate($value);
                         list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults($paymentDate);
                         break;
                     default:
                         break;
                 }
                 $form->setDefaults($defaults);
                 $form->assign('start_date_display', $paymentDate);
                 $form->assign('start_date_editable', FALSE);
                 if (CRM_Utils_Array::value('is_pledge_start_date_editable', $pledgeBlock)) {
                     $form->assign('start_date_editable', TRUE);
                     if ($field == 'calendar_month') {
                         $form->assign('is_date', FALSE);
                         $form->setDefaults(array('start_date' => $value));
                     }
                 }
             }
         }
     }
 }
Beispiel #14
0
 /**
  * Function used to build form element for soft credit block.
  *
  * @param CRM_Core_Form $form
  *
  * @return void
  */
 public static function buildQuickForm(&$form)
 {
     if (!empty($form->_honor_block_is_active)) {
         $ufJoinDAO = new CRM_Core_DAO_UFJoin();
         $ufJoinDAO->module = 'soft_credit';
         $ufJoinDAO->entity_id = $form->_id;
         if ($ufJoinDAO->find(TRUE)) {
             $jsonData = CRM_Contribute_BAO_ContributionPage::formatMultilingualHonorParams($ufJoinDAO->module_data, TRUE);
             if ($jsonData) {
                 foreach (array('honor_block_title', 'honor_block_text') as $name) {
                     $form->assign($name, $jsonData[$name]);
                 }
                 $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
                 // radio button for Honor Type
                 foreach ($jsonData['soft_credit_types'] as $value) {
                     $honorTypes[$value] = $form->createElement('radio', NULL, NULL, $softCreditTypes[$value], $value);
                 }
                 $form->addGroup($honorTypes, 'soft_credit_type_id', NULL)->setAttribute('allowClear', TRUE);
             }
         }
         return $form;
     }
     // by default generate 10 blocks
     $item_count = 11;
     $showSoftCreditRow = 2;
     if ($form->getAction() & CRM_Core_Action::UPDATE) {
         $form->_softCreditInfo = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($form->_id, TRUE);
     } elseif (!empty($form->_pledgeID)) {
         //Check and select most recent completed contrubtion and use it to retrieve
         //soft-credit information to use as default for current pledge payment, CRM-13981
         $pledgePayments = CRM_Pledge_BAO_PledgePayment::getPledgePayments($form->_pledgeID);
         foreach ($pledgePayments as $id => $record) {
             if ($record['contribution_id']) {
                 $softCredits = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($record['contribution_id'], TRUE);
                 if ($record['status'] == 'Completed' && count($softCredits) > 0) {
                     $form->_softCreditInfo = $softCredits;
                 }
             }
         }
     }
     if (property_exists($form, "_softCreditInfo")) {
         if (!empty($form->_softCreditInfo['soft_credit'])) {
             $showSoftCreditRow = count($form->_softCreditInfo['soft_credit']);
             $showSoftCreditRow++;
         }
     }
     for ($rowNumber = 1; $rowNumber <= $item_count; $rowNumber++) {
         $form->addEntityRef("soft_credit_contact_id[{$rowNumber}]", ts('Contact'), array('create' => TRUE));
         $form->addMoney("soft_credit_amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE);
         $form->addSelect("soft_credit_type[{$rowNumber}]", array('entity' => 'contribution_soft', 'field' => 'soft_credit_type_id', 'label' => ts('Type')));
         if (!empty($form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id'])) {
             $form->add('hidden', "soft_credit_id[{$rowNumber}]", $form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id']);
         }
     }
     // CRM-7368 allow user to set or edit PCP link for contributions
     $siteHasPCPs = CRM_Contribute_PseudoConstant::pcPage();
     if (!CRM_Utils_Array::crmIsEmptyArray($siteHasPCPs)) {
         $form->assign('siteHasPCPs', 1);
         // Fixme: Not a true entityRef field. Relies on PCP.js.tpl
         $form->add('text', 'pcp_made_through_id', ts('Credit to a Personal Campaign Page'), array('class' => 'twenty', 'placeholder' => ts('- select -')));
         // stores the label
         $form->add('hidden', 'pcp_made_through');
         $form->addElement('checkbox', 'pcp_display_in_roll', ts('Display in Honor Roll?'), NULL);
         $form->addElement('text', 'pcp_roll_nickname', ts('Name (for Honor Roll)'));
         $form->addElement('textarea', 'pcp_personal_note', ts('Personal Note (for Honor Roll)'));
     }
     $form->assign('showSoftCreditRow', $showSoftCreditRow);
     $form->assign('rowCount', $item_count);
     $form->addElement('hidden', 'sct_default_id', CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"), array('id' => 'sct_default_id'));
 }
 /**
  * Add onbehalf/honoree profile fields and native module fields.
  *
  * @param int $id
  * @param CRM_Core_Form $form
  */
 public function buildComponentForm($id, $form)
 {
     if (empty($id)) {
         return;
     }
     $contactID = $this->getContactID();
     foreach (array('soft_credit', 'on_behalf') as $module) {
         if ($module == 'soft_credit') {
             if (empty($form->_values['honoree_profile_id'])) {
                 continue;
             }
             if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_values['honoree_profile_id'], 'is_active')) {
                 CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of honoree and the selected honoree profile is either disabled or not found.'));
             }
             $profileContactType = CRM_Core_BAO_UFGroup::getContactType($form->_values['honoree_profile_id']);
             $requiredProfileFields = array('Individual' => array('first_name', 'last_name'), 'Organization' => array('organization_name', 'email'), 'Household' => array('household_name', 'email'));
             $validProfile = CRM_Core_BAO_UFGroup::checkValidProfile($form->_values['honoree_profile_id'], $requiredProfileFields[$profileContactType]);
             if (!$validProfile) {
                 CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of honoree and the required fields of the selected honoree profile are disabled or doesn\'t exist.'));
             }
             foreach (array('honor_block_title', 'honor_block_text') as $name) {
                 $form->assign($name, $form->_values[$name]);
             }
             $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
             // radio button for Honor Type
             foreach ($form->_values['soft_credit_types'] as $value) {
                 $honorTypes[$value] = $form->createElement('radio', NULL, NULL, $softCreditTypes[$value], $value);
             }
             $form->addGroup($honorTypes, 'soft_credit_type_id', NULL)->setAttribute('allowClear', TRUE);
             $honoreeProfileFields = CRM_Core_BAO_UFGroup::getFields($this->_values['honoree_profile_id'], FALSE, NULL, NULL, NULL, FALSE, NULL, TRUE, NULL, CRM_Core_Permission::CREATE);
             $form->assign('honoreeProfileFields', $honoreeProfileFields);
             // add the form elements
             foreach ($honoreeProfileFields as $name => $field) {
                 // If soft credit type is not chosen then make omit requiredness from honoree profile fields
                 if (count($form->_submitValues) && empty($form->_submitValues['soft_credit_type_id']) && !empty($field['is_required'])) {
                     $field['is_required'] = FALSE;
                 }
                 CRM_Core_BAO_UFGroup::buildProfile($form, $field, CRM_Profile_Form::MODE_CREATE, NULL, FALSE, FALSE, NULL, 'honor');
             }
         } else {
             if (empty($form->_values['onbehalf_profile_id'])) {
                 continue;
             }
             if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_values['onbehalf_profile_id'], 'is_active')) {
                 CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of an organization and the selected onbehalf profile is either disabled or not found.'));
             }
             $member = CRM_Member_BAO_Membership::getMembershipBlock($form->_id);
             if (empty($member['is_active'])) {
                 $msg = ts('Mixed profile not allowed for on behalf of registration/sign up.');
                 $onBehalfProfile = CRM_Core_BAO_UFGroup::profileGroups($form->_values['onbehalf_profile_id']);
                 foreach (array('Individual', 'Organization', 'Household') as $contactType) {
                     if (in_array($contactType, $onBehalfProfile) && (in_array('Membership', $onBehalfProfile) || in_array('Contribution', $onBehalfProfile))) {
                         CRM_Core_Error::fatal($msg);
                     }
                 }
             }
             if ($contactID) {
                 // retrieve all permissioned organizations of contact $contactID
                 $organizations = CRM_Contact_BAO_Relationship::getPermissionedContacts($contactID, NULL, NULL, 'Organization');
                 if (count($organizations)) {
                     // Related org url - pass checksum if needed
                     $args = array('ufId' => $form->_values['onbehalf_profile_id'], 'cid' => '');
                     if (!empty($_GET['cs'])) {
                         $args = array('ufId' => $form->_values['onbehalf_profile_id'], 'uid' => $this->_contactID, 'cs' => $_GET['cs'], 'cid' => '');
                     }
                     $locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', $args, FALSE, NULL, FALSE);
                     $form->assign('locDataURL', $locDataURL);
                 }
                 if (count($organizations) > 0) {
                     $form->add('select', 'onbehalfof_id', '', CRM_Utils_Array::collect('name', $organizations));
                     $orgOptions = array(0 => ts('Select an existing organization'), 1 => ts('Enter a new organization'));
                     $form->addRadio('org_option', ts('options'), $orgOptions);
                     $form->setDefaults(array('org_option' => 0));
                 }
             }
             $form->assign('fieldSetTitle', ts('Organization Details'));
             if (CRM_Utils_Array::value('is_for_organization', $form->_values)) {
                 if ($form->_values['is_for_organization'] == 2) {
                     $form->assign('onBehalfRequired', TRUE);
                 } else {
                     $form->addElement('checkbox', 'is_for_organization', $form->_values['for_organization'], NULL);
                 }
             }
             $profileFields = CRM_Core_BAO_UFGroup::getFields($form->_values['onbehalf_profile_id'], FALSE, CRM_Core_Action::VIEW, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
             $form->assign('onBehalfOfFields', $profileFields);
             if (!empty($form->_submitValues['onbehalf'])) {
                 if (!empty($form->_submitValues['onbehalfof_id'])) {
                     $form->assign('submittedOnBehalf', $form->_submitValues['onbehalfof_id']);
                 }
                 $form->assign('submittedOnBehalfInfo', json_encode($form->_submitValues['onbehalf']));
             }
             $fieldTypes = array('Contact', 'Organization');
             $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
             $fieldTypes = array_merge($fieldTypes, $contactSubType);
             foreach ($profileFields as $name => $field) {
                 if (in_array($field['field_type'], $fieldTypes)) {
                     list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
                     if (in_array($prefixName, array('organization_name', 'email')) && empty($field['is_required'])) {
                         $field['is_required'] = 1;
                     }
                     if (count($form->_submitValues) && empty($form->_submitValues['is_for_organization']) && $form->_values['is_for_organization'] == 1 && !empty($field['is_required'])) {
                         $field['is_required'] = FALSE;
                     }
                     CRM_Core_BAO_UFGroup::buildProfile($form, $field, NULL, NULL, FALSE, 'onbehalf', NULL, 'onbehalf');
                 }
             }
         }
     }
 }
 /**
  * This function for building custom fields
  *
  * @param CRM_Core_Form $qf form object (reference)
  * @param string $elementName name of the custom field
  * @param $fieldId
  * @param boolean $inactiveNeeded
  * @param boolean $useRequired true if required else false
  * @param string $label label for custom field
  *
  * @param null $fieldOptions
  * @param array $feezeOptions
  *
  * @return null
  * @internal param bool $search true if used for search else false
  * @access public
  * @static
  */
 public static function addQuickFormElement(&$qf, $elementName, $fieldId, $inactiveNeeded, $useRequired = TRUE, $label = NULL, $fieldOptions = NULL, $feezeOptions = array())
 {
     $field = new CRM_Price_DAO_PriceField();
     $field->id = $fieldId;
     if (!$field->find(TRUE)) {
         /* FIXME: failure! */
         return NULL;
     }
     $is_pay_later = 0;
     if (isset($qf->_mode) && empty($qf->_mode)) {
         $is_pay_later = 1;
     } elseif (isset($qf->_values)) {
         $is_pay_later = CRM_Utils_Array::value('is_pay_later', $qf->_values);
     }
     $otherAmount = $qf->get('values');
     $config = CRM_Core_Config::singleton();
     $currencySymbol = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_Currency', $config->defaultCurrency, 'symbol', 'name');
     $qf->assign('currencySymbol', $currencySymbol);
     // get currency name for price field and option attributes
     $currencyName = $config->defaultCurrency;
     if (!isset($label)) {
         $label = !empty($qf->_membershipBlock) && $field->name == 'contribution_amount' ? ts('Additional Contribution') : $field->label;
     }
     if ($field->name == 'contribution_amount') {
         $qf->_contributionAmount = 1;
     }
     if (isset($qf->_online) && $qf->_online) {
         $useRequired = FALSE;
     }
     $customOption = $fieldOptions;
     if (!is_array($customOption)) {
         $customOption = CRM_Price_BAO_PriceField::getOptions($field->id, $inactiveNeeded);
     }
     //use value field.
     $valueFieldName = 'amount';
     $seperator = '|';
     switch ($field->html_type) {
         case 'Text':
             $optionKey = key($customOption);
             $count = CRM_Utils_Array::value('count', $customOption[$optionKey], '');
             $max_value = CRM_Utils_Array::value('max_value', $customOption[$optionKey], '');
             $priceVal = implode($seperator, array($customOption[$optionKey][$valueFieldName], $count, $max_value));
             $extra = array();
             if (!empty($qf->_quickConfig) && !empty($qf->_contributionAmount)) {
                 foreach ($fieldOptions as &$fieldOption) {
                     if ($fieldOption['name'] == 'other_amount') {
                         $fieldOption['label'] = $fieldOption['label'] . '  ' . $currencySymbol;
                     }
                 }
                 $qf->assign('priceset', $elementName);
                 $extra = array('onclick' => 'useAmountOther();');
             }
             if (!empty($qf->_membershipBlock) && !empty($qf->_quickConfig) && $field->name == 'other_amount' && empty($qf->_contributionAmount)) {
                 $useRequired = 0;
             } elseif (!empty($fieldOptions[$optionKey]['label'])) {
                 //check for label.
                 $label = $fieldOptions[$optionKey]['label'];
             }
             $element =& $qf->add('text', $elementName, $label, array_merge($extra, array('price' => json_encode(array($optionKey, $priceVal)), 'size' => '4')), $useRequired && $field->is_required);
             if ($is_pay_later) {
                 $qf->add('text', 'txt-' . $elementName, $label, array('size' => '4'));
             }
             // CRM-6902
             if (in_array($optionKey, $feezeOptions)) {
                 $element->freeze();
             }
             //CRM-10117
             if (!empty($qf->_quickConfig)) {
                 $message = ts('Please enter a valid amount.');
                 $type = 'money';
             } else {
                 $message = ts('%1 must be an integer (whole number).', array(1 => $label));
                 $type = 'positiveInteger';
             }
             // integers will have numeric rule applied to them.
             $qf->addRule($elementName, $message, $type);
             break;
         case 'Radio':
             $choice = array();
             if (!empty($qf->_quickConfig) && !empty($qf->_contributionAmount)) {
                 $qf->assign('contriPriceset', $elementName);
             }
             foreach ($customOption as $opId => $opt) {
                 if ($field->is_display_amounts) {
                     $opt['label'] = !empty($opt['label']) ? $opt['label'] : '';
                     $opt['label'] = '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName]) . '</span> <span class="crm-price-amount-label">' . $opt['label'] . '</span>';
                 }
                 $count = CRM_Utils_Array::value('count', $opt, '');
                 $max_value = CRM_Utils_Array::value('max_value', $opt, '');
                 $priceVal = implode($seperator, array($opt[$valueFieldName], $count, $max_value));
                 $extra = array('price' => json_encode(array($elementName, $priceVal)), 'data-amount' => $opt[$valueFieldName], 'data-currency' => $currencyName);
                 if (!empty($qf->_quickConfig) && $field->name == 'contribution_amount') {
                     $extra += array('onclick' => 'clearAmountOther();');
                 } elseif (!empty($qf->_quickConfig) && $field->name == 'membership_amount') {
                     $extra += array('onclick' => "return showHideAutoRenew({$opt['membership_type_id']});", 'membership-type' => $opt['membership_type_id']);
                     $qf->assign('membershipFieldID', $field->id);
                 }
                 $choice[$opId] = $qf->createElement('radio', NULL, '', $opt['label'], $opt['id'], $extra);
                 if ($is_pay_later) {
                     $qf->add('text', 'txt-' . $elementName, $label, array('size' => '4'));
                 }
                 // CRM-6902
                 if (in_array($opId, $feezeOptions)) {
                     $choice[$opId]->freeze();
                 }
             }
             if (!empty($qf->_membershipBlock) && $field->name == 'contribution_amount') {
                 $choice[] = $qf->createElement('radio', NULL, '', ts('No thank you'), '-1', array('onclick' => 'clearAmountOther();'));
             }
             if (!$field->is_required) {
                 // add "none" option
                 if (!empty($otherAmount['is_allow_other_amount']) && $field->name == 'contribution_amount') {
                     $none = ts('Other Amount');
                 } elseif (!empty($qf->_membershipBlock) && empty($qf->_membershipBlock['is_required']) && $field->name == 'membership_amount') {
                     $none = ts('No thank you');
                 } else {
                     $none = ts('- none -');
                 }
                 $choice[] = $qf->createElement('radio', NULL, '', $none, '0', array('price' => json_encode(array($elementName, '0'))));
             }
             $element =& $qf->addGroup($choice, $elementName, $label);
             // make contribution field required for quick config when membership block is enabled
             if (($field->name == 'membership_amount' || $field->name == 'contribution_amount') && !empty($qf->_membershipBlock) && !$field->is_required) {
                 $useRequired = $field->is_required = TRUE;
             }
             if ($useRequired && $field->is_required) {
                 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
             }
             break;
         case 'Select':
             $selectOption = $allowedOptions = $priceVal = array();
             foreach ($customOption as $opt) {
                 $count = CRM_Utils_Array::value('count', $opt, '');
                 $max_value = CRM_Utils_Array::value('max_value', $opt, '');
                 $priceVal[$opt['id']] = implode($seperator, array($opt[$valueFieldName], $count, $max_value));
                 if ($field->is_display_amounts) {
                     $opt['label'] .= '&nbsp;-&nbsp;';
                     $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]);
                 }
                 $selectOption[$opt['id']] = $opt['label'];
                 if (!in_array($opt['id'], $feezeOptions)) {
                     $allowedOptions[] = $opt['id'];
                 }
                 if ($is_pay_later) {
                     $qf->add('text', 'txt-' . $elementName, $label, array('size' => '4'));
                 }
             }
             $element =& $qf->add('select', $elementName, $label, array('' => ts('- select -')) + $selectOption, $useRequired && $field->is_required, array('price' => json_encode($priceVal)));
             // CRM-6902
             $button = substr($qf->controller->getButtonName(), -4);
             if (!empty($feezeOptions) && $button != 'skip') {
                 $qf->addRule($elementName, ts('Sorry, this option is currently sold out.'), 'regex', "/" . implode('|', $allowedOptions) . "/");
             }
             break;
         case 'CheckBox':
             $check = array();
             foreach ($customOption as $opId => $opt) {
                 $count = CRM_Utils_Array::value('count', $opt, '');
                 $max_value = CRM_Utils_Array::value('max_value', $opt, '');
                 $priceVal = implode($seperator, array($opt[$valueFieldName], $count, $max_value));
                 if ($field->is_display_amounts) {
                     $opt['label'] .= '&nbsp;-&nbsp;';
                     $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]);
                 }
                 $check[$opId] =& $qf->createElement('checkbox', $opt['id'], NULL, $opt['label'], array('price' => json_encode(array($opt['id'], $priceVal)), 'data-amount' => $opt[$valueFieldName], 'data-currency' => $currencyName));
                 if ($is_pay_later) {
                     $txtcheck[$opId] =& $qf->createElement('text', $opId, $opt['label'], array('size' => '4'));
                     $qf->addGroup($txtcheck, 'txt-' . $elementName, $label);
                 }
                 // CRM-6902
                 if (in_array($opId, $feezeOptions)) {
                     $check[$opId]->freeze();
                 }
             }
             $element =& $qf->addGroup($check, $elementName, $label);
             if ($useRequired && $field->is_required) {
                 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
             }
             break;
     }
     if (isset($qf->_online) && $qf->_online) {
         $element->freeze();
     }
 }
 /**
  * This function for building custom fields.
  *
  * @param CRM_Core_Form $qf
  *   Form object (reference).
  * @param string $elementName
  *   Name of the custom field.
  * @param int $fieldId
  * @param bool $inactiveNeeded
  *   -deprecated.
  * @param bool $useRequired
  *   True if required else false.
  * @param bool $search
  *   True if used for search else false.
  * @param string $label
  *   Label for custom field.
  *
  */
 public static function addQuickFormElement(&$qf, $elementName, $fieldId, $inactiveNeeded = FALSE, $useRequired = TRUE, $search = FALSE, $label = NULL)
 {
     $field = self::getFieldObject($fieldId);
     $widget = $field->html_type;
     // Custom field HTML should indicate group+field name
     $groupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $field->custom_group_id);
     $dataCrmCustomVal = $groupName . ':' . $field->name;
     $dataCrmCustomAttr = 'data-crm-custom="' . $dataCrmCustomVal . '"';
     $field->attributes .= $dataCrmCustomAttr;
     // Fixed for Issue CRM-2183
     if ($widget == 'TextArea' && $search) {
         $widget = 'Text';
     }
     $placeholder = $search ? ts('- any -') : ($useRequired ? ts('- select -') : ts('- none -'));
     // FIXME: Why are select state/country separate widget types?
     $isSelect = in_array($widget, array('Select', 'Multi-Select', 'Select State/Province', 'Multi-Select State/Province', 'Select Country', 'Multi-Select Country', 'AdvMulti-Select', 'CheckBox', 'Radio'));
     if ($isSelect) {
         $options = CRM_Utils_Array::value('values', civicrm_api3('contact', 'getoptions', array('field' => "custom_{$fieldId}", 'context' => $search ? 'search' : 'create'), array()));
         // Consolidate widget types to simplify the below switch statement
         if ($search || $widget !== 'AdvMulti-Select' && strpos($widget, 'Select') !== FALSE) {
             $widget = 'Select';
         }
         $selectAttributes = array('data-crm-custom' => $dataCrmCustomVal, 'class' => 'crm-select2');
         // Search field is always multi-select
         if ($search || strpos($field->html_type, 'Multi') !== FALSE) {
             $selectAttributes['class'] .= ' huge';
             $selectAttributes['multiple'] = 'multiple';
             $selectAttributes['placeholder'] = $placeholder;
         }
         // Add data for popup link. Normally this is handled by CRM_Core_Form->addSelect
         if ($field->option_group_id && !$search && $widget == 'Select' && CRM_Core_Permission::check('administer CiviCRM')) {
             $selectAttributes += array('data-api-entity' => 'contact', 'data-api-field' => 'custom_' . $field->id, 'data-option-edit-path' => 'civicrm/admin/options/' . CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $field->option_group_id));
         }
     }
     if (!isset($label)) {
         $label = $field->label;
     }
     /**
      * at some point in time we might want to split the below into small functions
      **/
     switch ($widget) {
         case 'Text':
         case 'Link':
             if ($field->is_search_range && $search) {
                 $qf->add('text', $elementName . '_from', $label . ' ' . ts('From'), $field->attributes);
                 $qf->add('text', $elementName . '_to', ts('To'), $field->attributes);
             } else {
                 $element =& $qf->add('text', $elementName, $label, $field->attributes, $useRequired && !$search);
             }
             break;
         case 'TextArea':
             $attributes = $dataCrmCustomAttr;
             if ($field->note_rows) {
                 $attributes .= 'rows=' . $field->note_rows;
             } else {
                 $attributes .= 'rows=4';
             }
             if ($field->note_columns) {
                 $attributes .= ' cols=' . $field->note_columns;
             } else {
                 $attributes .= ' cols=60';
             }
             if ($field->text_length) {
                 $attributes .= ' maxlength=' . $field->text_length;
             }
             $element =& $qf->add('textarea', $elementName, $label, $attributes, $useRequired && !$search);
             break;
         case 'Select Date':
             if ($field->is_search_range && $search) {
                 $qf->addDate($elementName . '_from', $label . ' - ' . ts('From'), FALSE, array('format' => $field->date_format, 'timeFormat' => $field->time_format, 'startOffset' => $field->start_date_years, 'endOffset' => $field->end_date_years, 'data-crm-custom' => $dataCrmCustomVal));
                 $qf->addDate($elementName . '_to', ts('To'), FALSE, array('format' => $field->date_format, 'timeFormat' => $field->time_format, 'startOffset' => $field->start_date_years, 'endOffset' => $field->end_date_years, 'data-crm-custom' => $dataCrmCustomVal));
             } else {
                 $required = $useRequired && !$search;
                 $qf->addDate($elementName, $label, $required, array('format' => $field->date_format, 'timeFormat' => $field->time_format, 'startOffset' => $field->start_date_years, 'endOffset' => $field->end_date_years, 'data-crm-custom' => $dataCrmCustomVal));
             }
             break;
         case 'Radio':
             $choice = array();
             foreach ($options as $v => $l) {
                 $choice[] = $qf->createElement('radio', NULL, '', $l, (string) $v, $field->attributes);
             }
             $group = $qf->addGroup($choice, $elementName, $label);
             if ($useRequired && !$search) {
                 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
             } else {
                 $group->setAttribute('allowClear', TRUE);
             }
             break;
             // For all select elements
         // For all select elements
         case 'Select':
             if (empty($selectAttributes['multiple'])) {
                 $options = array('' => $placeholder) + $options;
             }
             $qf->add('select', $elementName, $label, $options, $useRequired && !$search, $selectAttributes);
             // Add and/or option for fields that store multiple values
             if ($search && self::isSerialized($field)) {
                 $operators = array($qf->createElement('radio', NULL, '', ts('Any'), 'or', array('title' => ts('Results may contain any of the selected options'))), $qf->createElement('radio', NULL, '', ts('All'), 'and', array('title' => ts('Results must have all of the selected options'))));
                 $qf->addGroup($operators, $elementName . '_operator');
                 $qf->setDefaults(array($elementName . '_operator' => 'or'));
             }
             break;
         case 'AdvMulti-Select':
             $include =& $qf->addElement('advmultiselect', $elementName, $label, $options, array('size' => 5, 'style' => '', 'class' => 'advmultiselect', 'data-crm-custom' => $dataCrmCustomVal));
             $include->setButtonAttributes('add', array('value' => ts('Add >>')));
             $include->setButtonAttributes('remove', array('value' => ts('<< Remove')));
             if ($useRequired && !$search) {
                 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
             }
             break;
         case 'CheckBox':
             $check = array();
             foreach ($options as $v => $l) {
                 $check[] =& $qf->addElement('advcheckbox', $v, NULL, $l, array('data-crm-custom' => $dataCrmCustomVal));
             }
             $qf->addGroup($check, $elementName, $label);
             if ($useRequired && !$search) {
                 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
             }
             break;
         case 'File':
             // we should not build upload file in search mode
             if ($search) {
                 return;
             }
             $qf->add(strtolower($field->html_type), $elementName, $label, $field->attributes, $useRequired && !$search);
             $qf->addUploadElement($elementName);
             break;
         case 'RichTextEditor':
             $attributes = array('rows' => $field->note_rows, 'cols' => $field->note_columns, 'data-crm-custom' => $dataCrmCustomVal);
             if ($field->text_length) {
                 $attributes['maxlength'] = $field->text_length;
             }
             $qf->addWysiwyg($elementName, $label, $attributes, $search);
             break;
         case 'Autocomplete-Select':
             static $customUrls = array();
             // Fixme: why is this a string in the first place??
             $attributes = array();
             if ($field->attributes) {
                 foreach (explode(' ', $field->attributes) as $at) {
                     if (strpos($at, '=')) {
                         list($k, $v) = explode('=', $at);
                         $attributes[$k] = trim($v, ' "');
                     }
                 }
             }
             if ($field->data_type == 'ContactReference') {
                 $attributes['class'] = (isset($attributes['class']) ? $attributes['class'] . ' ' : '') . 'crm-form-contact-reference huge';
                 $attributes['data-api-entity'] = 'contact';
                 $qf->add('text', $elementName, $label, $attributes, $useRequired && !$search);
                 $urlParams = "context=customfield&id={$field->id}";
                 $customUrls[$elementName] = CRM_Utils_System::url('civicrm/ajax/contactref', $urlParams, FALSE, NULL, FALSE);
             } else {
                 // FIXME: This won't work with customFieldOptions hook
                 $attributes += array('entity' => 'option_value', 'placeholder' => $placeholder, 'multiple' => $search, 'api' => array('params' => array('option_group_id' => $field->option_group_id)));
                 $qf->addEntityRef($elementName, $label, $attributes, $useRequired && !$search);
             }
             $qf->assign('customUrls', $customUrls);
             break;
     }
     switch ($field->data_type) {
         case 'Int':
             // integers will have numeric rule applied to them.
             if ($field->is_search_range && $search) {
                 $qf->addRule($elementName . '_from', ts('%1 From must be an integer (whole number).', array(1 => $label)), 'integer');
                 $qf->addRule($elementName . '_to', ts('%1 To must be an integer (whole number).', array(1 => $label)), 'integer');
             } elseif ($widget == 'Text') {
                 $qf->addRule($elementName, ts('%1 must be an integer (whole number).', array(1 => $label)), 'integer');
             }
             break;
         case 'Float':
             if ($field->is_search_range && $search) {
                 $qf->addRule($elementName . '_from', ts('%1 From must be a number (with or without decimal point).', array(1 => $label)), 'numeric');
                 $qf->addRule($elementName . '_to', ts('%1 To must be a number (with or without decimal point).', array(1 => $label)), 'numeric');
             } elseif ($widget == 'Text') {
                 $qf->addRule($elementName, ts('%1 must be a number (with or without decimal point).', array(1 => $label)), 'numeric');
             }
             break;
         case 'Money':
             if ($field->is_search_range && $search) {
                 $qf->addRule($elementName . '_from', ts('%1 From must in proper money format. (decimal point/comma/space is allowed).', array(1 => $label)), 'money');
                 $qf->addRule($elementName . '_to', ts('%1 To must in proper money format. (decimal point/comma/space is allowed).', array(1 => $label)), 'money');
             } elseif ($widget == 'Text') {
                 $qf->addRule($elementName, ts('%1 must be in proper money format. (decimal point/comma/space is allowed).', array(1 => $label)), 'money');
             }
             break;
         case 'Link':
             $element->setAttribute('onfocus', "if (!this.value) {this.value='http://';}");
             $element->setAttribute('onblur', "if (this.value == 'http://') {this.value='';}");
             $element->setAttribute('class', "url");
             $qf->addRule($elementName, ts('Enter a valid Website.'), 'wikiURL');
             break;
     }
     if ($field->is_view && !$search) {
         $qf->freeze($elementName);
     }
 }