/** * add all the elements shared between, * normal voter search and voter listing (GOTV form) * * @access public * * @return void * @static */ static function buildSearchForm(&$form) { $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address'); $className = CRM_Utils_System::getClassName($form); $form->add('text', 'sort_name', ts('Contact Name'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); $form->add('text', 'street_name', ts('Street Name'), $attributes['street_name']); $form->add('text', 'street_number', ts('Street Number'), $attributes['street_number']); $form->add('text', 'street_unit', ts('Street Unit'), $attributes['street_unit']); $form->add('text', 'street_address', ts('Street Address'), $attributes['street_address']); $form->add('text', 'city', ts('City'), $attributes['city']); $form->add('text', 'postal_code', ts('Zip / Postal Code'), $attributes['postal_code']); $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(); $form->add('select', 'contact_type', ts('Contact Type(s)'), $contactTypes, FALSE, array('id' => 'contact_type', 'multiple' => 'multiple', 'class' => 'crm-select2')); $groups = CRM_Core_PseudoConstant::group(); $form->add('select', 'group', ts('Groups'), $groups, FALSE, array('id' => 'group', 'multiple' => 'multiple', 'class' => 'crm-select2')); $showInterviewer = FALSE; if (CRM_Core_Permission::check('administer CiviCampaign')) { $showInterviewer = TRUE; } $form->assign('showInterviewer', $showInterviewer); if ($showInterviewer || $className == 'CRM_Campaign_Form_Gotv') { //autocomplete url $dataUrl = CRM_Utils_System::url('civicrm/ajax/rest', 'className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&reset=1', FALSE, NULL, FALSE); $form->assign('dataUrl', $dataUrl); $form->add('text', 'survey_interviewer_name', ts('Interviewer')); $form->add('hidden', 'survey_interviewer_id', '', array('id' => 'survey_interviewer_id')); $userId = NULL; if (isset($form->_interviewerId) && $form->_interviewerId) { $userId = $form->_interviewerId; } if (!$userId) { $session = CRM_Core_Session::singleton(); $userId = $session->get('userID'); } if ($userId) { $defaults = array(); $defaults['survey_interviewer_id'] = $userId; $defaults['survey_interviewer_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $userId, 'sort_name', 'id'); $form->setDefaults($defaults); } } //build ward and precinct custom fields. $query = ' SELECT fld.id, fld.label FROM civicrm_custom_field fld INNER JOIN civicrm_custom_group grp on fld.custom_group_id = grp.id WHERE grp.name = %1'; $dao = CRM_Core_DAO::executeQuery($query, array(1 => array('Voter_Info', 'String'))); $customSearchFields = array(); while ($dao->fetch()) { foreach (array('ward', 'precinct') as $name) { if (stripos($name, $dao->label) !== FALSE) { $fieldId = $dao->id; $fieldName = 'custom_' . $dao->id; $customSearchFields[$name] = $fieldName; CRM_Core_BAO_CustomField::addQuickFormElement($form, $fieldName, $fieldId, FALSE, FALSE); break; } } } $form->assign('customSearchFields', $customSearchFields); $surveys = CRM_Campaign_BAO_Survey::getSurveys(); if (empty($surveys) && $className == 'CRM_Campaign_Form_Search') { CRM_Core_Error::statusBounce(ts('Could not find survey for %1 respondents.', array(1 => $form->get('op'))), CRM_Utils_System::url('civicrm/survey/add', 'reset=1&action=add')); } //CRM-7406 -- //If survey had associated campaign and //campaign has some contact groups, don't //allow to search the contacts those are not //in given campaign groups ( ie not in constituents ) $groupJs = NULL; if ($form->get('searchVoterFor') == 'reserve') { $groupJs = array('onChange' => "buildCampaignGroups( );return false;"); } $form->add('select', 'campaign_survey_id', ts('Survey'), $surveys, TRUE, $groupJs); }
/** * Add all the elements shared between contribute search and advnaced search. * * * @param CRM_Core_Form $form * * @return void */ public static function buildSearchForm(&$form) { // Added contribution source $form->addElement('text', 'contribution_source', ts('Contribution Source'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'source')); CRM_Core_Form_Date::buildDateRange($form, 'contribution_date', 1, '_low', '_high', ts('From:'), FALSE); $form->add('text', 'contribution_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8)); $form->addRule('contribution_amount_low', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('9.99', ' '))), 'money'); $form->add('text', 'contribution_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8)); $form->addRule('contribution_amount_high', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money'); // Adding select option for curreny type -- CRM-4711 $form->add('select', 'contribution_currency_type', ts('Currency Type'), array('' => ts('- any -')) + CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'currency', array('labelColumn' => 'name')), FALSE, array('class' => 'crm-select2')); // CRM-13848 $form->addSelect('financial_type_id', array('entity' => 'contribution', 'multiple' => 'multiple', 'context' => 'search')); $form->add('select', 'contribution_page_id', ts('Contribution Page'), array('' => ts('- any -')) + CRM_Contribute_PseudoConstant::contributionPage(), FALSE, array('class' => 'crm-select2')); $form->addSelect('payment_instrument_id', array('entity' => 'contribution', 'label' => ts('Payment Method'), 'option_url' => NULL, 'placeholder' => ts('- any -'))); $form->add('select', 'contribution_pcp_made_through_id', ts('Personal Campaign Page'), array('' => ts('- any -')) + CRM_Contribute_PseudoConstant::pcPage(), FALSE, array('class' => 'crm-select2')); $status = array(); $statusValues = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status'); // Remove status values that are only used for recurring contributions or pledges (In Progress, Overdue). unset($statusValues['5'], $statusValues['6']); $form->addSelect('contribution_status_id', array('entity' => 'contribution', 'multiple' => 'multiple', 'label' => ts('Contribution Status(s)'), 'option_url' => NULL, 'placeholder' => ts('- any -'))); // Add fields for thank you and receipt $form->addYesNo('contribution_thankyou_date_is_not_null', ts('Thank-you sent?'), TRUE); $form->addYesNo('contribution_receipt_date_is_not_null', ts('Receipt sent?'), TRUE); $form->addYesNo('contribution_pay_later', ts('Contribution is Pay Later?'), TRUE); $form->addYesNo('contribution_recurring', ts('Contribution is Recurring?'), TRUE); // Recurring contribution fields foreach (self::getRecurringFields() as $key => $label) { CRM_Core_Form_Date::buildDateRange($form, $key, 1, '_low', '_high'); // If data has been entered for a recurring field, tell the tpl layer to open the pane if (!empty($form->_formValues[$key . '_relative']) || !empty($form->_formValues[$key . '_low']) || !empty($form->_formValues[$key . '_high'])) { $form->assign('contribution_recur_pane_open', TRUE); } } $form->addYesNo('contribution_test', ts('Contribution is a Test?'), TRUE); // Add field for transaction ID search $form->addElement('text', 'contribution_trxn_id', ts("Transaction ID")); $form->addElement('text', 'contribution_check_number', ts('Check Number')); // Add field for pcp display in roll search $form->addYesNo('contribution_pcp_display_in_roll', ts('Personal Campaign Page Honor Roll?'), TRUE); // Soft credit related fields $options = array('only_contribs' => ts('Contributions Only'), 'only_scredits' => ts('Soft Credits Only'), 'both_related' => ts('Soft Credits with related Hard Credit'), 'both' => ts('Both')); $form->add('select', 'contribution_or_softcredits', ts('Contributions OR Soft Credits?'), $options, FALSE, array('class' => "crm-select2")); $form->addSelect('contribution_soft_credit_type_id', array('entity' => 'contribution_soft', 'field' => 'soft_credit_type_id', 'multiple' => TRUE, 'context' => 'search')); // Add all the custom searchable fields $contribution = array('Contribution'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $contribution); if ($groupDetails) { $form->assign('contributeGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'contribution_campaign_id'); // Add batch select $batches = CRM_Contribute_PseudoConstant::batch(); if (!empty($batches)) { $form->add('select', 'contribution_batch_id', ts('Batch Name'), array('' => ts('- any -')) + $batches, FALSE, array('class' => 'crm-select2')); } $form->assign('validCiviContribute', TRUE); $form->setDefaults(array('contribution_test' => 0)); }
/** * Build the search form. * * @param CRM_Core_Form $form */ public static function buildSearchForm(&$form) { $membershipStatus = CRM_Member_PseudoConstant::membershipStatus(); $form->add('select', 'membership_status_id', ts('Membership Status(s)'), $membershipStatus, FALSE, array('id' => 'membership_status_id', 'multiple' => 'multiple', 'class' => 'crm-select2')); $form->addEntityRef('membership_type_id', ts('Membership Type(s)'), array('entity' => 'MembershipType', 'multiple' => TRUE, 'placeholder' => ts('- any -'), 'select' => array('minimumInputLength' => 0))); $form->addElement('text', 'member_source', ts('Source')); CRM_Core_Form_Date::buildDateRange($form, 'member_join_date', 1, '_low', '_high', ts('From'), FALSE); CRM_Core_Form_Date::buildDateRange($form, 'member_start_date', 1, '_low', '_high', ts('From'), FALSE); CRM_Core_Form_Date::buildDateRange($form, 'member_end_date', 1, '_low', '_high', ts('From'), FALSE); $form->addYesNo('member_is_primary', ts('Primary Member?'), TRUE); $form->addYesNo('member_pay_later', ts('Pay Later?'), TRUE); $form->addYesNo('member_auto_renew', ts('Auto-Renew?'), TRUE); $form->addYesNo('member_test', ts('Membership is a Test?'), TRUE); $form->addYesNo('member_is_override', ts('Membership Status Is Override?'), TRUE); // add all the custom searchable fields $extends = array('Membership'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); if ($groupDetails) { $form->assign('membershipGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'member_campaign_id'); $form->assign('validCiviMember', TRUE); $form->setDefaults(array('member_test' => 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, ' ', 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); } } }
/** * @param CRM_Core_Form $form */ public static function buildSearchForm(&$form) { // pledge related dates CRM_Core_Form_Date::buildDateRange($form, 'pledge_start_date', 1, '_low', '_high', ts('From'), FALSE); CRM_Core_Form_Date::buildDateRange($form, 'pledge_end_date', 1, '_low', '_high', ts('From'), FALSE); CRM_Core_Form_Date::buildDateRange($form, 'pledge_create_date', 1, '_low', '_high', ts('From'), FALSE); // pledge payment related dates CRM_Core_Form_Date::buildDateRange($form, 'pledge_payment_date', 1, '_low', '_high', ts('From'), FALSE); $form->addYesNo('pledge_test', ts('Pledge is a Test?'), TRUE); $form->add('text', 'pledge_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8)); $form->addRule('pledge_amount_low', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('9.99', ' '))), 'money'); $form->add('text', 'pledge_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8)); $form->addRule('pledge_amount_high', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money'); $statusValues = CRM_Contribute_PseudoConstant::contributionStatus(); // Remove status values that are only used for recurring contributions for now (Failed and In Progress). unset($statusValues['4']); $form->add('select', 'pledge_status_id', ts('Pledge Status'), $statusValues, FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple')); //unset in progress for payment unset($statusValues['5']); $form->add('select', 'pledge_payment_status_id', ts('Pledge Payment Status'), $statusValues, FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple')); $form->add('select', 'pledge_financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType(), FALSE, array('class' => 'crm-select2')); $form->add('select', 'pledge_contribution_page_id', ts('Contribution Page'), array('' => ts('- any -')) + CRM_Contribute_PseudoConstant::contributionPage(), FALSE, array('class' => 'crm-select2')); //add fields for pledge frequency $form->add('text', 'pledge_frequency_interval', ts('Every'), array('size' => 8, 'maxlength' => 8)); $form->addRule('pledge_frequency_interval', ts('Please enter valid Pledge Frequency Interval'), 'integer'); $frequencies = CRM_Core_OptionGroup::values('recur_frequency_units'); foreach ($frequencies as $val => $label) { $freqUnitsDisplay["'{$val}'"] = ts('%1(s)', array(1 => $label)); } $form->add('select', 'pledge_frequency_unit', ts('Pledge Frequency'), array('' => ts('- any -')) + $freqUnitsDisplay); // add all the custom searchable fields $pledge = array('Pledge'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $pledge); if ($groupDetails) { $form->assign('pledgeGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'pledge_campaign_id'); $form->assign('validCiviPledge', TRUE); $form->setDefaults(array('pledge_test' => 0)); }
/** * add all the elements shared between contribute search and advnaced search * * @access public * @return void * @static */ static function buildSearchForm(&$form) { require_once 'CRM/Utils/Money.php'; //added contribution source $form->addElement('text', 'contribution_source', ts('Contribution Source'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'source')); $form->addDate('contribution_date_low', ts('Contribution Dates - From'), false, array('formatType' => 'searchDate')); $form->addDate('contribution_date_high', ts('To'), false, array('formatType' => 'searchDate')); $form->add('text', 'contribution_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8)); $form->addRule('contribution_amount_low', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('9.99', ' '))), 'money'); $form->add('text', 'contribution_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8)); $form->addRule('contribution_amount_high', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money'); require_once 'CRM/Contribute/PseudoConstant.php'; $form->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType()); $form->add('select', 'contribution_page_id', ts('Contribution Page'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage()); $form->add('select', 'contribution_payment_instrument_id', ts('Payment Instrument'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument()); $form->add('select', 'contribution_pcp_made_through_id', ts('Personal Campaign Page'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::pcPage()); $status = array(); require_once "CRM/Core/OptionGroup.php"; $statusValues = CRM_Core_OptionGroup::values("contribution_status"); // Remove status values that are only used for recurring contributions or pledges (In Progress, Overdue). unset($statusValues['5']); unset($statusValues['6']); foreach ($statusValues as $key => $val) { $status[] = $form->createElement('advcheckbox', $key, null, $val); } $form->addGroup($status, 'contribution_status_id', ts('Contribution Status')); // add null checkboxes for thank you and receipt $form->addElement('checkbox', 'contribution_thankyou_date_isnull', ts('Thank-you date not set?')); $form->addElement('checkbox', 'contribution_receipt_date_isnull', ts('Receipt not sent?')); //add fields for honor search $form->addElement('text', 'contribution_in_honor_of', ts("In Honor Of")); $form->addElement('checkbox', 'contribution_test', ts('Find Test Contributions?')); $form->addElement('checkbox', 'contribution_pay_later', ts('Find Pay Later Contributions?')); //add field for transaction ID search $form->addElement('text', 'contribution_transaction_id', ts("Transaction ID")); $form->addElement('checkbox', 'contribution_recurring', ts('Find Recurring Contributions?')); $form->addElement('text', 'contribution_check_number', ts('Check Number')); //add field for pcp display in roll search $form->addYesNo('contribution_pcp_display_in_roll', ts('Display In Roll ?')); // add all the custom searchable fields require_once 'CRM/Core/BAO/CustomGroup.php'; $contribution = array('Contribution'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(null, true, $contribution); if ($groupDetails) { require_once 'CRM/Core/BAO/CustomField.php'; $form->assign('contributeGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, false, false, true); } } } $form->assign('validCiviContribute', true); }
/** * Generic function to build all the form elements for a specific group tree. * * @param CRM_Core_Form $form * The form object. * @param array $groupTree * The group tree object. * @param bool $inactiveNeeded * Return inactive custom groups. * @param string $prefix * Prefix for custom grouptree assigned to template. */ public static function buildQuickForm(&$form, &$groupTree, $inactiveNeeded = FALSE, $prefix = '') { $form->assign_by_ref("{$prefix}groupTree", $groupTree); foreach ($groupTree as $id => $group) { CRM_Core_ShowHideBlocks::links($form, $group['title'], '', ''); foreach ($group['fields'] as $field) { $required = CRM_Utils_Array::value('is_required', $field); //fix for CRM-1620 if ($field['data_type'] == 'File') { if (!empty($field['element_value']['data'])) { $required = 0; } } $fieldId = $field['id']; $elementName = $field['element_name']; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, $required); } } }
/** * Generate the custom Data Fields based * on the is_searchable * * * @param $form * * @return void */ public static function custom(&$form) { $form->add('hidden', 'hidden_custom', 1); $extends = array_merge(array('Contact', 'Individual', 'Household', 'Organization'), CRM_Contact_BAO_ContactType::subTypes()); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); $form->assign('groupTree', $groupDetails); foreach ($groupDetails as $key => $group) { $_groupTitle[$key] = $group['name']; CRM_Core_ShowHideBlocks::links($form, $group['name'], '', ''); $groupId = $group['id']; foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; if ($field['data_type'] == 'Date' && $field['is_search_range']) { CRM_Core_Form_Date::buildDateRange($form, $elementName, 1, '_from', '_to', ts('From:'), FALSE); } else { CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } //TODO: validate for only one state if prox_distance isset }
/** * Adds a field based on metadata. * * @param $name * Field name to go on the form. * @param array $props * Mix of html attributes and special properties, namely. * - entity (api entity name, can usually be inferred automatically from the form class) * - name (field name - only needed if different from name used on the form) * - option_url - path to edit this option list - usually retrieved automatically - set to NULL to disable link * - placeholder - set to NULL to disable * - multiple - bool * - context - @see CRM_Core_DAO::buildOptionsContext * @param bool $required * @throws \CiviCRM_API3_Exception * @throws \Exception * @return HTML_QuickForm_Element */ public function addField($name, $props = array(), $required = FALSE) { // Resolve context. if (empty($props['context'])) { $props['context'] = $this->getDefaultContext(); } $context = $props['context']; // Resolve entity. if (empty($props['entity'])) { $props['entity'] = $this->getDefaultEntity(); } // Resolve field. if (empty($props['name'])) { $props['name'] = strrpos($name, '[') ? rtrim(substr($name, 1 + strrpos($name, '[')), ']') : $name; } // Resolve action. if (empty($props['action'])) { $props['action'] = $this->getApiAction(); } // Handle custom fields if (strpos($name, 'custom_') === 0 && is_numeric($name[7])) { $fieldId = (int) substr($name, 7); return CRM_Core_BAO_CustomField::addQuickFormElement($this, $name, $fieldId, $required, $context == 'search', CRM_Utils_Array::value('label', $props)); } // Core field - get metadata. $fieldSpec = civicrm_api3($props['entity'], 'getfield', $props); $fieldSpec = $fieldSpec['values']; $label = CRM_Utils_Array::value('label', $props, isset($fieldSpec['title']) ? $fieldSpec['title'] : NULL); $widget = isset($props['type']) ? $props['type'] : $fieldSpec['html']['type']; if ($widget == 'TextArea' && $context == 'search') { $widget = 'Text'; } $isSelect = in_array($widget, array('Select', 'CheckBoxGroup', 'RadioGroup', 'Radio')); if ($isSelect) { // Fetch options from the api unless passed explicitly. if (isset($props['options'])) { $options = $props['options']; } else { $options = isset($fieldSpec['options']) ? $fieldSpec['options'] : NULL; } if ($context == 'search') { $widget = 'Select'; $props['multiple'] = CRM_Utils_Array::value('multiple', $props, TRUE); } // Add data for popup link. if ((!empty($props['option_url']) || !array_key_exists('option_url', $props)) && ($context != 'search' && $widget == 'Select' && CRM_Core_Permission::check('administer CiviCRM'))) { $props['data-option-edit-path'] = !empty($props['option_url']) ? $props['option_url'] : CRM_Core_PseudoConstant::getOptionEditUrl($fieldSpec); $props['data-api-entity'] = $props['entity']; $props['data-api-field'] = $props['name']; } } $props += CRM_Utils_Array::value('html', $fieldSpec, array()); CRM_Utils_Array::remove($props, 'entity', 'name', 'context', 'label', 'action', 'type', 'option_url', 'options'); // TODO: refactor switch statement, to separate methods. switch ($widget) { case 'Text': case 'Url': case 'Number': case 'Email': //TODO: Autodetect ranges $props['size'] = isset($props['size']) ? $props['size'] : 60; return $this->add(strtolower($widget), $name, $label, $props, $required); case 'hidden': return $this->add('hidden', $name, NULL, $props, $required); case 'TextArea': //Set default columns and rows for textarea. $props['rows'] = isset($props['rows']) ? $props['rows'] : 4; $props['cols'] = isset($props['cols']) ? $props['cols'] : 60; return $this->add('textarea', $name, $label, $props, $required); case 'Select Date': //TODO: add range support //TODO: Add date formats //TODO: Add javascript template for dates. return $this->addDate($name, $label, $required, $props); case 'Radio': $separator = isset($props['separator']) ? $props['separator'] : NULL; unset($props['separator']); if (!isset($props['allowClear'])) { $props['allowClear'] = !$required; } return $this->addRadio($name, $label, $options, $props, $separator, $required); case 'ChainSelect': $props += array('required' => $required, 'label' => $label, 'multiple' => $context == 'search'); return $this->addChainSelect($name, $props); case 'Select': $props['class'] = CRM_Utils_Array::value('class', $props, 'big') . ' crm-select2'; if (!array_key_exists('placeholder', $props)) { $props['placeholder'] = $required ? ts('- select -') : ($context == 'search' ? ts('- any -') : ts('- none -')); } // TODO: Add and/or option for fields that store multiple values return $this->add('select', $name, $label, $options, $required, $props); case 'CheckBoxGroup': return $this->addCheckBox($name, $label, array_flip($options), $required, $props); case 'RadioGroup': return $this->addRadio($name, $label, $options, $props, NULL, $required); case 'CheckBox': $text = isset($props['text']) ? $props['text'] : NULL; unset($props['text']); return $this->addElement('checkbox', $name, $label, $text, $props); //add support for 'Advcheckbox' field //add support for 'Advcheckbox' field case 'advcheckbox': $text = isset($props['text']) ? $props['text'] : NULL; unset($props['text']); return $this->addElement('advcheckbox', $name, $label, $text, $props); case 'File': // We should not build upload file in search mode. if ($context == 'search') { return; } $file = $this->add('file', $name, $label, $props, $required); $this->addUploadElement($name); return $file; case 'RichTextEditor': return $this->add('wysiwyg', $name, $label, $props, $required); case 'EntityRef': return $this->addEntityRef($name, $label, $props, $required); // Check datatypes of fields // case 'Int': //case 'Float': //case 'Money': //case read only fields // Check datatypes of fields // case 'Int': //case 'Float': //case 'Money': //case read only fields default: throw new Exception("Unsupported html-element " . $widget); } }
/** * Function to actually build the form * * @return void * @access public */ function buildQuickForm() { // add the form elements require_once "CRM/Contribute/PseudoConstant.php"; foreach ($this->_fields as $name => $field) { $required = $field['is_required']; if (substr($field['name'], 0, 14) === 'state_province') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required); } else { if (substr($field['name'], 0, 7) === 'country') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required); } else { if ($field['name'] === 'birth_date') { $this->add('date', $field['name'], $field['title'], CRM_Core_SelectValues::date('birth'), $required); } else { if ($field['name'] === 'gender') { $genderOptions = array(); $gender = CRM_Core_PseudoConstant::gender(); foreach ($gender as $key => $var) { $genderOptions[$key] = HTML_QuickForm::createElement('radio', null, ts('Gender'), $var, $key); } $this->addGroup($genderOptions, $field['name'], $field['title']); if ($required) { $this->addRule($field['name'], ts('%1 is a required field.', array(1 => $field['title'])), 'required'); } } else { if ($field['name'] === 'individual_prefix') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix(), $required); } else { if ($field['name'] === 'individual_suffix') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix(), $required); } else { if ($field['name'] === 'preferred_communication_method') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_SelectValues::pcm()); } else { if ($field['name'] === 'preferred_mail_format') { $this->add('select', $name, $field['title'], array(CRM_Core_SelectValues::pcm())); } else { if (substr($field['name'], 0, 7) === 'do_not_') { $this->add('checkbox', $name, $field['title'], $field['attributes'], $required); } else { if ($field['name'] === 'group') { require_once 'CRM/Contact/Form/GroupTag.php'; CRM_Contact_Form_GroupTag::buildGroupTagBlock($this, $this->_id, CRM_CONTACT_FORM_GROUPTAG_GROUP, false, $required, $field['title'], null); } else { if ($field['name'] === 'tag') { require_once 'CRM/Contact/Form/GroupTag.php'; CRM_Contact_Form_GroupTag::buildGroupTagBlock($this, $this->_id, CRM_CONTACT_FORM_GROUPTAG_TAG, false, $required, null, $field['title']); } else { if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name'])) { CRM_Core_BAO_CustomField::addQuickFormElement($this, $name, $customFieldID, $inactiveNeeded, $required, false, $field['title']); } else { if (in_array($field['name'], array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) { $this->add('date', $field['name'], $field['title'], CRM_Core_SelectValues::date('manual', 3, 1), $required); } else { if ($field['name'] == 'payment_instrument') { $this->add('select', 'payment_instrument', ts('Paid By'), array('' => ts('-select-')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required); } else { if ($field['name'] == 'contribution_type') { $this->add('select', 'contribution_type', ts('Contribution Type'), array('' => ts('-select-')) + CRM_Contribute_PseudoConstant::contributionType(), $required); } else { $this->add('text', $name, $field['title'], $field['attributes'], $required); } } } } } } } } } } } } } } } } $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done with Preview'), 'isDefault' => true))); }
/** * Generate the custom Data Fields based * on the is_searchable * * @access private * @return void */ static function custom(&$form) { $form->add('hidden', 'hidden_custom', 1); $extends = array_merge(array('Contact', 'Individual', 'Household', 'Organization'), CRM_Contact_BAO_ContactType::subTypes()); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(null, true, $extends); $form->assign('groupTree', $groupDetails); foreach ($groupDetails as $key => $group) { $_groupTitle[$key] = $group['name']; CRM_Core_ShowHideBlocks::links($form, $group['name'], '', ''); $groupId = $group['id']; foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, false, false, true); } } }
static function buildSearchForm(&$form) { // pledge related dates $form->addDate('pledge_start_date_low', ts('Payments Start Date - From'), false, array('formatType' => 'relative')); $form->addDate('pledge_start_date_high', ts('To'), false, array('formatType' => 'relative')); $form->addDate('pledge_end_date_low', ts('Payments Ended Date - From'), false, array('formatType' => 'relative')); $form->addDate('pledge_end_date_high', ts('To'), false, array('formatType' => 'relative')); $form->addDate('pledge_create_date_low', ts('Pledge Made - From'), false, array('formatType' => 'relative')); $form->addDate('pledge_create_date_high', ts('To'), false, array('formatType' => 'relative')); // pledge payment related dates $form->addDate('pledge_payment_date_low', ts('Payment Scheduled - From'), false, array('formatType' => 'relative')); $form->addDate('pledge_payment_date_high', ts('To'), false, array('formatType' => 'relative')); $form->addElement('checkbox', 'pledge_test', ts('Find Test Pledges?')); require_once 'CRM/Utils/Money.php'; $form->add('text', 'pledge_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8)); $form->addRule('pledge_amount_low', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('9.99', ' '))), 'money'); $form->add('text', 'pledge_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8)); $form->addRule('pledge_amount_high', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money'); require_once 'CRM/Contribute/PseudoConstant.php'; $statusValues = CRM_Contribute_PseudoConstant::contributionStatus(); // Remove status values that are only used for recurring contributions for now (Failed and In Progress). unset($statusValues['4']); foreach ($statusValues as $key => $val) { $status[] = $form->createElement('advcheckbox', $key, null, $val); } $form->addGroup($status, 'pledge_status_id', ts('Pledge Status')); //unset in progress for payment unset($statusValues['5']); foreach ($statusValues as $key => $val) { $paymentStatus[] = $form->createElement('advcheckbox', $key, null, $val); } $form->addGroup($paymentStatus, 'pledge_payment_status_id', ts('Pledge Payment Status')); require_once 'CRM/Contribute/PseudoConstant.php'; $form->add('select', 'pledge_contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType()); $form->add('select', 'pledge_contribution_page_id', ts('Contribution Page'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage()); //add fields for honor search $form->addElement('text', 'pledge_in_honor_of', ts("In Honor Of")); // add all the custom searchable fields require_once 'CRM/Core/BAO/CustomGroup.php'; $pledge = array('Pledge'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(null, true, $pledge); if ($groupDetails) { require_once 'CRM/Core/BAO/CustomField.php'; $form->assign('pledgeGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, false, false, true); } } } $form->assign('validCiviPledge', true); }
static function buildSearchForm(&$form) { $dataURLEvent = CRM_Utils_System::url('civicrm/ajax/event', "reset=1", false, null, false); $dataURLEventType = CRM_Utils_System::url('civicrm/ajax/eventType', "reset=1", false, null, false); $dataURLEventFee = CRM_Utils_System::url('civicrm/ajax/eventFee', "reset=1", false, null, false); $form->assign('dataURLEvent', $dataURLEvent); $form->assign('dataURLEventType', $dataURLEventType); $form->assign('dataURLEventFee', $dataURLEventFee); $eventId =& $form->add('text', 'event_name', ts('Event Name')); $eventType =& $form->add('text', 'event_type', ts('Event Type')); $participantFee =& $form->add('text', 'participant_fee_level', ts('Fee Level')); //elements for assigning value operation $eventNameId =& $form->add('hidden', 'event_id', '', array('id' => 'event_id')); $eventTypeId =& $form->add('hidden', 'event_type_id', '', array('id' => 'event_type_id')); $participantFeeId =& $form->add('hidden', 'participant_fee_id', '', array('id' => 'participant_fee_id')); $form->addDate('event_start_date_low', ts('Event Dates - From'), false, array('formatType' => 'searchDate')); $form->addDate('event_end_date_high', ts('To'), false, array('formatType' => 'searchDate')); require_once 'CRM/Event/PseudoConstant.php'; $status = CRM_Event_PseudoConstant::participantStatus(null, null, 'label'); asort($status); foreach ($status as $id => $Name) { $form->_participantStatus =& $form->addElement('checkbox', "participant_status_id[{$id}]", null, $Name); } foreach (CRM_Event_PseudoConstant::participantRole() as $rId => $rName) { $form->_participantRole =& $form->addElement('checkbox', "participant_role_id[{$rId}]", null, $rName); } $form->addElement('checkbox', 'participant_test', ts('Find Test Participants?')); $form->addElement('checkbox', 'participant_pay_later', ts('Find Pay Later Participants?')); $form->addElement('text', 'participant_fee_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8)); $form->addElement('text', 'participant_fee_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8)); $form->addRule('participant_fee_amount_low', ts('Please enter a valid money value.'), 'money'); $form->addRule('participant_fee_amount_high', ts('Please enter a valid money value.'), 'money'); // add all the custom searchable fields require_once 'CRM/Core/BAO/CustomGroup.php'; $extends = array('Participant'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(null, true, $extends); if ($groupDetails) { require_once 'CRM/Core/BAO/CustomField.php'; $form->assign('participantGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, false, false, true); } } } $form->assign('validCiviEvent', true); }
/** * Function to build profile form * * @params object $form form object * @params array $field array field properties * @params int $mode profile mode * @params int $contactID contact id * * @return null * @static * @access public */ static function buildProfile(&$form, &$field, $mode, $contactId = NULL, $online = FALSE, $onBehalf = FALSE, $rowNumber = NULL, $prefix = '') { $defaultValues = array(); $fieldName = $field['name']; $title = $field['title']; $attributes = $field['attributes']; $rule = $field['rule']; $view = $field['is_view']; $required = $mode == CRM_Profile_Form::MODE_SEARCH ? FALSE : $field['is_required']; $search = $mode == CRM_Profile_Form::MODE_SEARCH ? TRUE : FALSE; $isShared = CRM_Utils_Array::value('is_shared', $field, 0); // do not display view fields in drupal registration form // CRM-4632 if ($view && $mode == CRM_Profile_Form::MODE_REGISTER) { return; } if ($onBehalf) { $name = "onbehalf[{$fieldName}]"; } elseif ($contactId && !$online) { $name = "field[{$contactId}][{$fieldName}]"; } elseif ($rowNumber) { $name = "field[{$rowNumber}][{$fieldName}]"; } elseif (!empty($prefix)) { $name = $prefix . "[{$fieldName}]"; } else { $name = $fieldName; } if ($fieldName == 'image_URL' && $mode == CRM_Profile_Form::MODE_EDIT) { $deleteExtra = ts('Are you sure you want to delete contact image.'); $deleteURL = array(CRM_Core_Action::DELETE => array('name' => ts('Delete Contact Image'), 'url' => 'civicrm/contact/image', 'qs' => 'reset=1&id=%%id%%&gid=%%gid%%&action=delete', 'extra' => 'onclick = "if (confirm( \'' . $deleteExtra . '\' ) ) this.href+=\'&confirmed=1\'; else return false;"')); $deleteURL = CRM_Core_Action::formLink($deleteURL, CRM_Core_Action::DELETE, array('id' => $form->get('id'), 'gid' => $form->get('gid'))); $form->assign('deleteURL', $deleteURL); } $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE); if (substr($fieldName, 0, 14) === 'state_province') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required); } elseif (substr($fieldName, 0, 7) === 'country') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required); $config = CRM_Core_Config::singleton(); if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactCountry) { $defaultValues[$name] = $config->defaultContactCountry; $form->setDefaults($defaultValues); } } elseif (substr($fieldName, 0, 6) === 'county') { if ($addressOptions['county']) { $form->add('select', $name, $title, array('' => ts('- select state -')), $required); } } elseif (substr($fieldName, 0, 9) === 'image_URL') { $form->add('file', $name, $title, $attributes, $required); $form->addUploadElement($name); } elseif (substr($fieldName, 0, 2) === 'im') { $form->add('text', $name, $title, $attributes, $required); if (!$contactId) { if ($onBehalf) { if (substr($name, -1) == ']') { $providerName = substr($name, 0, -1) . '-provider_id]'; } $form->add('select', $providerName, NULL, array('' => ts('- select -')) + CRM_Core_PseudoConstant::IMProvider(), $required); } else { $form->add('select', $name . '-provider_id', $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::IMProvider(), $required); } if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) { $form->freeze($name . '-provider_id'); } } } elseif ($fieldName === 'birth_date' || $fieldName === 'deceased_date') { $form->addDate($name, $title, $required, array('formatType' => 'birth')); } elseif (in_array($fieldName, array('membership_start_date', 'membership_end_date', 'join_date'))) { $form->addDate($name, $title, $required, array('formatType' => 'custom')); } elseif ($field['name'] == 'membership_type') { list($orgInfo, $types) = CRM_Member_BAO_MembershipType::getMembershipTypeInfo(); $sel =& $form->addElement('hierselect', $name, $title); $select = array('' => ts('- select -')); $sel->setOptions(array($select + $orgInfo, $types)); } elseif ($field['name'] == 'membership_status') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'), $required); } elseif ($fieldName === 'gender') { $genderOptions = array(); $gender = CRM_Core_PseudoConstant::gender(); foreach ($gender as $key => $var) { $genderOptions[$key] = $form->createElement('radio', NULL, ts('Gender'), $var, $key); } $form->addGroup($genderOptions, $name, $title); if ($required) { $form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required'); } } elseif ($fieldName === 'individual_prefix') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix(), $required); } elseif ($fieldName === 'individual_suffix') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix(), $required); } elseif ($fieldName === 'contact_sub_type') { $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $form->_fields[$fieldName]); if ($onBehalf) { $profileType = 'Organization'; } else { $profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : NULL; } $setSubtype = FALSE; if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { $setSubtype = $profileType; $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType); } $subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array(); if ($setSubtype) { $subtypeList = array(); $subtypeList[$setSubtype] = $subtypes[$setSubtype]; } else { $subtypeList = $subtypes; } $sel = $form->add('select', $name, $title, $subtypeList, $required); $sel->setMultiple(TRUE); } elseif (in_array($fieldName, CRM_Contact_BAO_Contact::$_greetingTypes)) { //add email greeting, postal greeting, addressee, CRM-4575 $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field); $profileType = CRM_Core_BAO_UFField::getProfileType($gId, TRUE, FALSE, TRUE); if (empty($profileType) || in_array($profileType, array('Contact', 'Contribution', 'Participant', 'Membership'))) { $profileType = 'Individual'; } if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType); } $greeting = array('contact_type' => $profileType, 'greeting_type' => $fieldName); $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($greeting), $required); // add custom greeting element $form->add('text', $fieldName . '_custom', ts('Custom %1', array(1 => ucwords(str_replace('_', ' ', $fieldName)))), NULL, FALSE); } elseif ($fieldName === 'preferred_communication_method') { $communicationFields = CRM_Core_PseudoConstant::pcm(); foreach ($communicationFields as $key => $var) { if ($key == '') { continue; } $communicationOptions[] = $form->createElement('checkbox', $key, NULL, $var); } $form->addGroup($communicationOptions, $name, $title, '<br/>'); } elseif ($fieldName === 'preferred_mail_format') { $form->add('select', $name, $title, CRM_Core_SelectValues::pmf()); } elseif ($fieldName === 'preferred_language') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::languages()); } elseif ($fieldName == 'external_identifier') { $form->add('text', $name, $title, $attributes, $required); $contID = $contactId; if (!$contID) { $contID = $form->get('id'); } $form->addRule($name, ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $contID, 'external_identifier')); } elseif ($fieldName === 'group') { CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, TRUE, $required, $title, NULL, $name); } elseif ($fieldName === 'tag') { CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::TAG, FALSE, $required, NULL, $title, $name); } elseif (substr($fieldName, 0, 4) === 'url-') { $form->addElement('text', $name, $title, array_merge(CRM_Core_DAO::getAttribute('CRM_Core_DAO_Website', 'url'), array('onfocus' => "if (!this.value) { this.value='http://';} else return false", 'onblur' => "if ( this.value == 'http://') { this.value='';} else return false"))); $form->addRule($name, ts('Enter a valid Website.'), 'url'); //Website type select if ($onBehalf) { if (substr($name, -1) == ']') { $websiteTypeName = substr($name, 0, -1) . '-website_type_id]'; } $form->addElement('select', $websiteTypeName, NULL, CRM_Core_PseudoConstant::websiteType()); } else { $form->addElement('select', $name . '-website_type_id', NULL, CRM_Core_PseudoConstant::websiteType()); } // added because note appeared as a standard text input } elseif ($fieldName == 'note') { $form->add('textarea', $name, $title, $attributes, $required); } elseif (substr($fieldName, 0, 6) === 'custom') { $customFieldID = CRM_Core_BAO_CustomField::getKeyID($fieldName); if ($customFieldID) { CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title); } } elseif (substr($fieldName, 0, 14) === 'address_custom') { list($fName, $locTypeId) = CRM_Utils_System::explode('-', $fieldName, 2); $customFieldID = CRM_Core_BAO_CustomField::getKeyID(substr($fName, 8)); if ($customFieldID) { CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title); } } elseif (in_array($fieldName, array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) { $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime')); } elseif ($fieldName == 'send_receipt') { $form->addElement('checkbox', $name, $title); } elseif ($fieldName == 'soft_credit') { CRM_Contact_Form_NewContact::buildQuickForm($form, $rowNumber, NULL, FALSE, 'soft_credit_'); } elseif ($fieldName == 'product_name') { list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo(); $sel =& $form->addElement('hierselect', $name, $title); $products = array('0' => ts('- select -')) + $products; $sel->setOptions(array($products, $options)); } elseif ($fieldName == 'payment_instrument') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required); } elseif ($fieldName == 'contribution_type') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType(), $required); } elseif ($fieldName == 'contribution_status_id') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionStatus(), $required); } elseif ($fieldName == 'currency') { $form->addCurrency($name, $title, $required); } elseif ($fieldName == 'contribution_page_id') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage(), $required, 'class="big"'); } elseif ($fieldName == 'participant_register_date') { $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime')); } elseif ($fieldName == 'activity_status_id') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::activityStatus(), $required); } elseif ($fieldName == 'activity_engagement_level') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Campaign_PseudoConstant::engagementLevel(), $required); } elseif ($fieldName == 'activity_date_time') { $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime')); } elseif ($fieldName == 'participant_status') { $cond = NULL; if ($online == TRUE) { $cond = 'visibility_id = 1'; } $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantStatus(NULL, $cond, 'label'), $required); } elseif ($fieldName == 'participant_role') { if (CRM_Utils_Array::value('is_multiple', $field)) { $form->addCheckBox($name, $title, CRM_Event_PseudoConstant::participantRole(), NULL, NULL, NULL, NULL, ' ', TRUE); } else { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantRole(), $required); } } elseif ($fieldName == 'scholarship_type_id') { $form->add('select', $name, $title, array('' => '-- Select -- ') + array_flip(CRM_Core_OptionGroup::values('scholarship_type', TRUE))); } elseif ($fieldName == 'applicant_status_id') { $form->add('select', $name, $title, array('' => '-- Select -- ') + array_flip(CRM_Core_OptionGroup::values('applicant_status', TRUE))); } elseif ($fieldName == 'highschool_gpa_id') { $form->add('select', $name, $title, array('' => '-- Select -- ') + CRM_Core_OptionGroup::values('highschool_gpa')); } elseif ($fieldName == 'world_region') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::worldRegion(), $required); } elseif ($fieldName == 'signature_html') { $form->addWysiwyg($name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName)); } elseif ($fieldName == 'signature_text') { $form->add('textarea', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName)); } elseif (substr($fieldName, -11) == 'campaign_id') { if (CRM_Campaign_BAO_Campaign::isCampaignEnable()) { $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(CRM_Utils_Array::value($contactId, $form->_componentCampaigns)); $campaign =& $form->add('select', $name, $title, array('' => ts('- select -')) + $campaigns, $required, 'class="big"'); } } elseif ($fieldName == 'activity_details') { $form->addWysiwyg($fieldName, $title, array('rows' => 4, 'cols' => 60), $required); } elseif ($fieldName == 'activity_duration') { $form->add('text', $fieldName, $title, $attributes, $required); $form->addRule($name, ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger'); } else { $processed = FALSE; if (CRM_Core_Permission::access('Quest', FALSE)) { $processed = CRM_Quest_BAO_Student::buildStudentForm($form, $fieldName, $title, $contactId); } if (!$processed) { if (substr($fieldName, 0, 3) === 'is_' or substr($fieldName, 0, 7) === 'do_not_') { $form->add('advcheckbox', $name, $title, $attributes, $required); } else { $form->add('text', $name, $title, $attributes, $required); } } } static $hiddenSubtype = FALSE; if (!$hiddenSubtype && CRM_Contact_BAO_ContactType::isaSubType($field['field_type'])) { // In registration mode params are submitted via POST and we don't have any clue // about profile-id or the profile-type (which could be a subtype) // To generalize the behavior and simplify the process, // lets always add the hidden //subtype value if there is any, and we won't have to // compute it while processing. if ($onBehalf) { $form->addElement('hidden', 'onbehalf[contact_sub_type]', $field['field_type']); } else { $form->addElement('hidden', 'contact_sub_type_hidden', $field['field_type']); } $hiddenSubtype = TRUE; } if ($view && $mode != CRM_Profile_Form::MODE_SEARCH || $isShared) { $form->freeze($name); } //add the rules if (in_array($fieldName, array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) { $form->addRule($name, ts('Please enter a valid amount.'), 'money'); } if ($rule) { if (!($rule == 'email' && $mode == CRM_Profile_Form::MODE_SEARCH)) { $form->addRule($name, ts('Please enter a valid %1', array(1 => $title)), $rule); } } }
/** * add all the elements shared between this and advnaced search * * @access public * @return void * @static */ function buildQuickFormCommon(&$form) { // Date selects for date $form->add('date', 'contribution_date_from', ts('Contribution Dates - From'), CRM_Core_SelectValues::date('relative')); $form->addRule('contribution_date_from', ts('Select a valid date.'), 'qfDate'); $form->add('date', 'contribution_date_to', ts('To'), CRM_Core_SelectValues::date('relative')); $form->addRule('contribution_date_to', ts('Select a valid date.'), 'qfDate'); $form->add('text', 'contribution_min_amount', ts('Minimum Amount'), array('size' => 8, 'maxlength' => 8)); $form->addRule('contribution_min_amount', ts('Please enter a valid money value (e.g. 9.99).'), 'money'); $form->add('text', 'contribution_max_amount', ts('Maximum Amount'), array('size' => 8, 'maxlength' => 8)); $form->addRule('contribution_max_amount', ts('Please enter a valid money value (e.g. 99.99).'), 'money'); $form->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType()); $form->add('select', 'payment_instrument_id', ts('Payment Instrument'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument()); $status = array(); $status[] = $form->createElement('radio', null, null, ts('Valid'), 'Valid'); $status[] = $form->createElement('radio', null, null, ts('Cancelled'), 'Cancelled'); $status[] = $form->createElement('radio', null, null, ts('All'), 'All'); $form->addGroup($status, 'contribution_status', ts('Contribution Status')); $form->setDefaults(array('contribution_status' => 'All')); // add null checkboxes for thank you and receipt $form->addElement('checkbox', 'contribution_thankyou_date_isnull', ts('Thank-you date not set?')); $form->addElement('checkbox', 'contribution_receipt_date_isnull', ts('Receipt date not set?')); // add all the custom searchable fields require_once 'CRM/Core/BAO/CustomGroup.php'; $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(null, true, array('Contribution')); if ($groupDetails) { require_once 'CRM/Core/BAO/CustomField.php'; $form->assign('contributeGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, false, false, true); } } } }
/** * add all the elements shared between case activity search and advanaced search * * @access public * @return void * @static */ static function buildSearchForm(&$form) { $activityOptions = CRM_Core_PseudoConstant::activityType(true, true, false, 'label', true); asort($activityOptions); foreach ($activityOptions as $activityID => $activity) { $form->_activityElement =& $form->addElement('checkbox', "activity_type_id[{$activityID}]", null, $activity, array('onClick' => 'showCustomData( this.id );')); } $form->addDate('activity_date_low', ts('Activity Dates - From'), false, array('formatType' => 'searchDate')); $form->addDate('activity_date_high', ts('To'), false, array('formatType' => 'searchDate')); $activityRoles = array(1 => ts('Created by'), 2 => ts('Assigned to')); $form->addRadio('activity_role', null, $activityRoles, null, '<br />'); $form->setDefaults(array('activity_role' => 1)); $form->addElement('text', 'activity_contact_name', ts('Contact Name'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); $activityStatus = CRM_Core_PseudoConstant::activityStatus(); foreach ($activityStatus as $activityStatusID => $activityStatusName) { $activity_status[] = HTML_QuickForm::createElement('checkbox', $activityStatusID, null, $activityStatusName); } $form->addGroup($activity_status, 'activity_status', ts('Activity Status')); $form->setDefaults(array('activity_status[1]' => 1, 'activity_status[2]' => 1)); $form->addElement('text', 'activity_subject', ts('Subject'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); $form->addElement('checkbox', 'activity_test', ts('Find Test Activities?')); require_once 'CRM/Core/BAO/Tag.php'; $activity_tags = CRM_Core_BAO_Tag::getTags('civicrm_activity'); if ($activity_tags) { foreach ($activity_tags as $tagID => $tagName) { $form->_tagElement =& $form->addElement('checkbox', "activity_tags[{$tagID}]", null, $tagName); } } require_once 'CRM/Campaign/BAO/Survey.php'; $surveys = array('' => ts('- none -')) + CRM_Campaign_BAO_Survey::getSurveyList(); $form->add('select', 'activity_survey_id', ts('Survey'), $surveys, false); require_once 'CRM/Core/BAO/CustomGroup.php'; $extends = array('Activity'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(null, true, $extends); if ($groupDetails) { require_once 'CRM/Core/BAO/CustomField.php'; $form->assign('activityGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, false, false, true); } } } }
/** * generic function to build all the form elements for a specific group tree * * @param CRM_Core_Form $form the form object * @param array $groupTree the group tree object * @param string $showName * @param string $hideName * * @return void * @access public * @static */ function buildQuickForm(&$form, &$groupTree, $showName = 'showBlocks', $hideName = 'hideBlocks') { //this is fix for calendar for date field foreach ($groupTree as $key1 => $group) { foreach ($group['fields'] as $key2 => $field) { if ($field['data_type'] == 'Date' && $field['date_parts']) { $datePart = explode(CRM_CORE_BAO_CUSTOMOPTION_VALUE_SEPERATOR, $field['date_parts']); if (count($datePart) < 3) { $groupTree[$key1]['fields'][$key2]['skip_calendar'] = true; } } } } $form->assign_by_ref('groupTree', $groupTree); $sBlocks = array(); $hBlocks = array(); // this is fix for date field $form->assign('currentYear', date('Y')); require_once 'CRM/Core/ShowHideBlocks.php'; foreach ($groupTree as $group) { CRM_Core_ShowHideBlocks::links($form, $group['title'], '', ''); $groupId = $group['id']; foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, $inactiveNeeded, $group['is_required']); } if ($group['collapse_display']) { $sBlocks[] = "'" . $group['title'] . "[show]'"; $hBlocks[] = "'" . $group['title'] . "'"; } else { $hBlocks[] = "'" . $group['title'] . "[show]'"; $sBlocks[] = "'" . $group['title'] . "'"; } } $showBlocks = implode(",", $sBlocks); $hideBlocks = implode(",", $hBlocks); $form->assign($showName, $showBlocks); $form->assign($hideName, $hideBlocks); }
/** * Add all the elements shared between, * normal voter search and voter listing (GOTV form) * * @param CRM_Core_Form $form */ public static function buildSearchForm(&$form) { $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address'); $className = CRM_Utils_System::getClassName($form); $form->add('text', 'sort_name', ts('Contact Name'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); $form->add('text', 'street_name', ts('Street Name'), $attributes['street_name']); $form->add('text', 'street_number', ts('Street Number'), $attributes['street_number']); $form->add('text', 'street_unit', ts('Street Unit'), $attributes['street_unit']); $form->add('text', 'street_address', ts('Street Address'), $attributes['street_address']); $form->add('text', 'city', ts('City'), $attributes['city']); $form->add('text', 'postal_code', ts('Postal Code'), $attributes['postal_code']); //@todo FIXME - using the CRM_Core_DAO::VALUE_SEPARATOR creates invalid html - if you can find the form // this is loaded onto then replace with something like '__' & test $separator = CRM_Core_DAO::VALUE_SEPARATOR; $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(FALSE, TRUE, $separator); $form->add('select', 'contact_type', ts('Contact Type(s)'), $contactTypes, FALSE, array('id' => 'contact_type', 'multiple' => 'multiple', 'class' => 'crm-select2')); $groups = CRM_Core_PseudoConstant::nestedGroup(); $form->add('select', 'group', ts('Groups'), $groups, FALSE, array('multiple' => 'multiple', 'class' => 'crm-select2')); $showInterviewer = FALSE; if (CRM_Core_Permission::check('administer CiviCampaign')) { $showInterviewer = TRUE; } $form->assign('showInterviewer', $showInterviewer); if ($showInterviewer || $className == 'CRM_Campaign_Form_Gotv') { $form->addEntityRef('survey_interviewer_id', ts('Interviewer'), array('class' => 'big')); $userId = NULL; if (isset($form->_interviewerId) && $form->_interviewerId) { $userId = $form->_interviewerId; } if (!$userId) { $session = CRM_Core_Session::singleton(); $userId = $session->get('userID'); } if ($userId) { $defaults = array(); $defaults['survey_interviewer_id'] = $userId; $form->setDefaults($defaults); } } //build ward and precinct custom fields. $query = ' SELECT fld.id, fld.label FROM civicrm_custom_field fld INNER JOIN civicrm_custom_group grp on fld.custom_group_id = grp.id WHERE grp.name = %1'; $dao = CRM_Core_DAO::executeQuery($query, array(1 => array('Voter_Info', 'String'))); $customSearchFields = array(); while ($dao->fetch()) { foreach (array('ward', 'precinct') as $name) { if (stripos($name, $dao->label) !== FALSE) { $fieldId = $dao->id; $fieldName = 'custom_' . $dao->id; $customSearchFields[$name] = $fieldName; CRM_Core_BAO_CustomField::addQuickFormElement($form, $fieldName, $fieldId, FALSE); break; } } } $form->assign('customSearchFields', $customSearchFields); $surveys = CRM_Campaign_BAO_Survey::getSurveys(); if (empty($surveys) && $className == 'CRM_Campaign_Form_Search') { CRM_Core_Error::statusBounce(ts('Could not find survey for %1 respondents.', array(1 => $form->get('op'))), CRM_Utils_System::url('civicrm/survey/add', 'reset=1&action=add')); } //CRM-7406 -- //If survey had associated campaign and //campaign has some contact groups, don't //allow to search the contacts those are not //in given campaign groups ( ie not in constituents ) $props = array('class' => 'crm-select2'); if ($form->get('searchVoterFor') == 'reserve') { $props['onChange'] = "buildCampaignGroups( );return false;"; } $form->add('select', 'campaign_survey_id', ts('Survey'), $surveys, TRUE, $props); }
static function buildSearchForm(&$form) { require_once 'CRM/Member/PseudoConstant.php'; foreach (CRM_Member_PseudoConstant::membershipType() as $id => $Name) { $form->_membershipType =& $form->addElement('checkbox', "member_membership_type_id[{$id}]", null, $Name); } // Option to include / exclude inherited memberships from search results (e.g. rows where owner_membership_id is NOT NULL) $primaryValues = array(1 => ts('All Members'), 2 => ts('Primary Members Only'), 3 => ts('Related Members Only')); $form->addRadio('member_is_primary', '', $primaryValues); $form->setDefaults(array('member_is_primary' => 1)); foreach (CRM_Member_PseudoConstant::membershipStatus() as $sId => $sName) { $form->_membershipStatus =& $form->addElement('checkbox', "member_status_id[{$sId}]", null, $sName); } $form->addElement('text', 'member_source', ts('Source')); $form->addDate('member_join_date_low', ts('Join Date - From'), false, array('formatType' => 'relative')); $form->addDate('member_join_date_high', ts('To'), false, array('formatType' => 'relative')); $form->addDate('member_start_date_low', ts('Start Date - From'), false, array('formatType' => 'relative')); $form->addDate('member_start_date_high', ts('To'), false, array('formatType' => 'relative')); $form->addDate('member_end_date_low', ts('End Date - From'), false, array('formatType' => 'relative')); $form->addDate('member_end_date_high', ts('To'), false, array('formatType' => 'relative')); $form->addElement('checkbox', 'member_test', ts('Find Test Memberships?')); $form->addElement('checkbox', 'member_pay_later', ts('Find Pay Later Memberships?')); // add all the custom searchable fields require_once 'CRM/Custom/Form/CustomData.php'; $extends = array('Membership'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(null, true, $extends); if ($groupDetails) { require_once 'CRM/Core/BAO/CustomField.php'; $form->assign('membershipGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, false, false, true); } } } $form->assign('validCiviMember', true); }
/** * Add all the elements shared between case activity search and advanced search. * * * @param CRM_Core_Form $form * @return void */ public static function buildSearchForm(&$form) { $activityOptions = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE); $form->addSelect('activity_type_id', array('entity' => 'activity', 'label' => 'Activity Type(s)', 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -'))); CRM_Core_Form_Date::buildDateRange($form, 'activity_date', 1, '_low', '_high', ts('From'), FALSE, FALSE); $followUpActivity = array(1 => ts('Yes'), 2 => ts('No')); $form->addRadio('parent_id', NULL, $followUpActivity, array('allowClear' => TRUE)); $form->addRadio('followup_parent_id', NULL, $followUpActivity, array('allowClear' => TRUE)); $activityRoles = array(3 => ts('With'), 2 => ts('Assigned to'), 1 => ts('Added by')); $form->addRadio('activity_role', NULL, $activityRoles, array('allowClear' => TRUE)); $form->setDefaults(array('activity_role' => 3)); $activityStatus = CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'status_id', array('flip' => 1, 'labelColumn' => 'name')); $form->addSelect('status_id', array('entity' => 'activity', 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -'))); $form->setDefaults(array('status_id' => array($activityStatus['Completed'], $activityStatus['Scheduled']))); $form->addElement('text', 'activity_subject', ts('Subject'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); $form->addYesNo('activity_test', ts('Activity is a Test?')); $activity_tags = CRM_Core_BAO_Tag::getTags('civicrm_activity'); if ($activity_tags) { foreach ($activity_tags as $tagID => $tagName) { $form->_tagElement =& $form->addElement('checkbox', "activity_tags[{$tagID}]", NULL, $tagName); } } $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_activity'); CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_activity', NULL, TRUE, TRUE); $surveys = CRM_Campaign_BAO_Survey::getSurveys(TRUE, FALSE, FALSE, TRUE); if ($surveys) { $form->add('select', 'activity_survey_id', ts('Survey / Petition'), array('' => ts('- none -')) + $surveys, FALSE, array('class' => 'crm-select2')); } $extends = array('Activity'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); if ($groupDetails) { $form->assign('activityGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'activity_campaign_id'); //add engagement level CRM-7775 $buildEngagementLevel = FALSE; $buildSurveyResult = FALSE; if (CRM_Campaign_BAO_Campaign::isCampaignEnable() && CRM_Campaign_BAO_Campaign::accessCampaign()) { $buildEngagementLevel = TRUE; $form->addSelect('activity_engagement_level', array('entity' => 'activity', 'context' => 'search')); // Add survey result field. $optionGroups = CRM_Campaign_BAO_Survey::getResultSets('name'); $resultOptions = array(); foreach ($optionGroups as $gid => $name) { if ($name) { $value = array(); $value = CRM_Core_OptionGroup::values($name); if (!empty($value)) { while (list($k, $v) = each($value)) { $resultOptions[$v] = $v; } } } } // If no survey result options have been created, don't build // the field to avoid clutter. if (count($resultOptions) > 0) { $buildSurveyResult = TRUE; asort($resultOptions); $form->add('select', 'activity_result', ts("Survey Result"), $resultOptions, FALSE, array('id' => 'activity_result', 'multiple' => 'multiple', 'class' => 'crm-select2')); } } $form->assign('buildEngagementLevel', $buildEngagementLevel); $form->assign('buildSurveyResult', $buildSurveyResult); $form->setDefaults(array('activity_test' => 0)); }
/** * add all the elements shared between grant search and advanaced search * * @access public * * @return void * @static */ static function buildSearchForm(&$form) { $grantType = CRM_Core_OptionGroup::values('grant_type'); $form->add('select', 'grant_type_id', ts('Grant Type'), array('' => ts('- any -')) + $grantType, FALSE, array('class' => 'crm-select2')); $grantStatus = CRM_Core_OptionGroup::values('grant_status'); $form->add('select', 'grant_status_id', ts('Grant Status'), array('' => ts('- any -')) + $grantStatus, FALSE, array('class' => 'crm-select2')); $form->addDate('grant_application_received_date_low', ts('App. Received Date - From'), FALSE, array('formatType' => 'searchDate')); $form->addDate('grant_application_received_date_high', ts('To'), FALSE, array('formatType' => 'searchDate')); $form->addElement('checkbox', 'grant_application_received_notset', ts(''), NULL); $form->addDate('grant_money_transfer_date_low', ts('Money Sent Date - From'), FALSE, array('formatType' => 'searchDate')); $form->addDate('grant_money_transfer_date_high', ts('To'), FALSE, array('formatType' => 'searchDate')); $form->addElement('checkbox', 'grant_money_transfer_date_notset', ts(''), NULL); $form->addDate('grant_due_date_low', ts('Report Due Date - From'), FALSE, array('formatType' => 'searchDate')); $form->addDate('grant_due_date_high', ts('To'), FALSE, array('formatType' => 'searchDate')); $form->addElement('checkbox', 'grant_due_date_notset', ts(''), NULL); $form->addDate('grant_decision_date_low', ts('Grant Decision Date - From'), FALSE, array('formatType' => 'searchDate')); $form->addDate('grant_decision_date_high', ts('To'), FALSE, array('formatType' => 'searchDate')); $form->addElement('checkbox', 'grant_decision_date_notset', ts(''), NULL); $form->addYesNo('grant_report_received', ts('Grant report received?'), TRUE); $form->add('text', 'grant_amount_low', ts('Minimum Amount'), array('size' => 8, 'maxlength' => 8)); $form->addRule('grant_amount_low', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('9.99', ' '))), 'money'); $form->add('text', 'grant_amount_high', ts('Maximum Amount'), array('size' => 8, 'maxlength' => 8)); $form->addRule('grant_amount_high', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money'); // add all the custom searchable fields $grant = array('Grant'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $grant); if ($groupDetails) { $form->assign('grantGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } $form->assign('validGrant', TRUE); }
/** * 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']); } } }
/** * Add all the elements shared between case search and advanaced search. * * * @param CRM_Core_Form $form * * @return void */ public static function buildSearchForm(&$form) { $config = CRM_Core_Config::singleton(); //validate case configuration. $configured = CRM_Case_BAO_Case::isCaseConfigured(); $form->assign('notConfigured', !$configured['configured']); $form->add('select', 'case_type_id', ts('Case Type'), CRM_Case_PseudoConstant::caseType('title', FALSE), FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple')); $form->add('select', 'case_status_id', ts('Case Status'), CRM_Case_PseudoConstant::caseStatus('label', FALSE), FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple')); CRM_Core_Form_Date::buildDateRange($form, 'case_from', 1, '_start_date_low', '_start_date_high', ts('From'), FALSE); CRM_Core_Form_Date::buildDateRange($form, 'case_to', 1, '_end_date_low', '_end_date_high', ts('From'), FALSE); $form->assign('validCiviCase', TRUE); //give options when all cases are accessible. $accessAllCases = FALSE; if (CRM_Core_Permission::check('access all cases and activities')) { $accessAllCases = TRUE; $caseOwner = array(1 => ts('Search All Cases'), 2 => ts('Only My Cases')); $form->addRadio('case_owner', ts('Cases'), $caseOwner); } $form->assign('accessAllCases', $accessAllCases); $caseTags = CRM_Core_BAO_Tag::getTags('civicrm_case'); if ($caseTags) { foreach ($caseTags as $tagID => $tagName) { $form->_tagElement =& $form->addElement('checkbox', "case_tags[{$tagID}]", NULL, $tagName); } } $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case'); CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_case', NULL, TRUE, FALSE); if (CRM_Core_Permission::check('administer CiviCRM')) { $form->addElement('checkbox', 'case_deleted', ts('Deleted Cases')); } // add all the custom searchable fields $extends = array('Case'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); if ($groupDetails) { $form->assign('caseGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } $form->setDefaults(array('case_owner' => 1)); }
/** * generic function to build all the form elements for a specific group tree * * @param CRM_Core_Form $form the form object * @param array $groupTree the group tree object * @param string $showName * @param string $hideName * * @return void * @access public * @static */ static function buildQuickForm(&$form, &$groupTree, $inactiveNeeded = false, $groupCount = 1, $prefix = '') { require_once 'CRM/Core/BAO/CustomField.php'; require_once 'CRM/Core/BAO/CustomOption.php'; $form->assign_by_ref("{$prefix}groupTree", $groupTree); $sBlocks = array(); $hBlocks = array(); // this is fix for date field $form->assign('currentYear', date('Y')); require_once 'CRM/Core/ShowHideBlocks.php'; foreach ($groupTree as $id => $group) { CRM_Core_ShowHideBlocks::links($form, $group['title'], '', ''); $groupId = CRM_Utils_Array::value('id', $group); foreach ($group['fields'] as $field) { // skip all view fields if (CRM_Utils_Array::value('is_view', $field)) { continue; } $required = CRM_Utils_Array::value('is_required', $field); //fix for CRM-1620 if ($field['data_type'] == 'File') { if (isset($field['customValue']['data'])) { $required = 0; } } $fieldId = $field['id']; $elementName = $field['element_name']; require_once "CRM/Core/BAO/CustomField.php"; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, $inactiveNeeded, $required); } } }
/** * Build the form object. * * @return void */ public function buildQuickForm() { if (is_array($this->_groupTree[$this->_groupId])) { foreach ($this->_groupTree[$this->_groupId]['fields'] as &$field) { //add the form elements CRM_Core_BAO_CustomField::addQuickFormElement($this, $field['element_name'], $field['id'], FALSE, CRM_Utils_Array::value('is_required', $field)); } $this->assign('groupTree', $this->_groupTree); } $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done with Preview'), 'isDefault' => TRUE))); }
/** * Function to actually build the form * * @param null * * @return void * @access public */ function buildQuickForm() { //this is fix for calendar for date field foreach ($this->_groupTree as $key1 => $group) { foreach ($group['fields'] as $key2 => $field) { if ($field['data_type'] == 'Date' && $field['date_parts']) { $datePart = explode(CRM_CORE_BAO_CUSTOMOPTION_VALUE_SEPERATOR, $field['date_parts']); if (count($datePart) < 3) { $this->_groupTree[$key1]['fields'][$key2]['skip_calendar'] = true; } } } } $this->assign('groupTree', $this->_groupTree); // add the form elements require_once 'CRM/Core/BAO/CustomField.php'; foreach ($this->_groupTree as $group) { $groupId = $group['id']; foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = $groupId . '_' . $fieldId . '_' . $field['name']; CRM_Core_BAO_CustomField::addQuickFormElement($this, $elementName, $fieldId, false, $field['is_required']); } } $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done with Preview'), 'isDefault' => true))); }
/** * @param $form */ public static function recurringContribution(&$form) { // Recurring contribution fields foreach (self::getRecurringFields() as $key => $label) { if ($key == 'contribution_recur_payment_made' && !empty($form->_formValues) && !CRM_Utils_System::isNull(CRM_Utils_Array::value($key, $form->_formValues))) { $form->assign('contribution_recur_pane_open', TRUE); break; } CRM_Core_Form_Date::buildDateRange($form, $key, 1, '_low', '_high'); // If data has been entered for a recurring field, tell the tpl layer to open the pane if (!empty($form->_formValues) && !empty($form->_formValues[$key . '_relative']) || !empty($form->_formValues[$key . '_low']) || !empty($form->_formValues[$key . '_high'])) { $form->assign('contribution_recur_pane_open', TRUE); break; } } // Add field to check if payment is made for recurring contribution $recurringPaymentOptions = array(1 => ts('All recurring contributions'), 2 => ts('Recurring contributions with at least one payment')); $form->addRadio('contribution_recur_payment_made', NULL, $recurringPaymentOptions, array('allowClear' => TRUE)); CRM_Core_Form_Date::buildDateRange($form, 'contribution_recur_start_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth'); CRM_Core_Form_Date::buildDateRange($form, 'contribution_recur_end_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth'); CRM_Core_Form_Date::buildDateRange($form, 'contribution_recur_modified_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth'); CRM_Core_Form_Date::buildDateRange($form, 'contribution_recur_next_sched_contribution_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth'); CRM_Core_Form_Date::buildDateRange($form, 'contribution_recur_failure_retry_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth'); CRM_Core_Form_Date::buildDateRange($form, 'contribution_recur_cancel_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth'); $form->addElement('text', 'contribution_recur_processor_id', ts('Processor ID'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionRecur', 'processor_id')); $form->addElement('text', 'contribution_recur_trxn_id', ts('Transaction ID'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionRecur', 'trxn_id')); $contributionRecur = array('ContributionRecur'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $contributionRecur); if ($groupDetails) { $form->assign('contributeRecurGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, TRUE); } } } }
/** * Function to build profile form * * @params object $form form object * @params array $field array field properties * @params int $mode profile mode * @params int $contactID contact id * * @return null * @static * @access public */ static function buildProfile(&$form, &$field, $mode, $contactId = null, $online = false) { require_once "CRM/Profile/Form.php"; require_once "CRM/Core/OptionGroup.php"; require_once 'CRM/Core/BAO/UFField.php'; require_once 'CRM/Contact/BAO/ContactType.php'; $defaultValues = array(); $fieldName = $field['name']; $title = $field['title']; $attributes = $field['attributes']; $rule = $field['rule']; $view = $field['is_view']; $required = $mode == CRM_Profile_Form::MODE_SEARCH ? false : $field['is_required']; $search = $mode == CRM_Profile_Form::MODE_SEARCH ? true : false; // do not display view fields in drupal registration form // CRM-4632 if ($view && $mode == CRM_Profile_Form::MODE_REGISTER) { return; } if ($contactId && !$online) { $name = "field[{$contactId}][{$fieldName}]"; } else { $name = $fieldName; } require_once 'CRM/Core/BAO/Preferences.php'; $addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true); if (substr($fieldName, 0, 14) === 'state_province') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required); } else { if (substr($fieldName, 0, 7) === 'country') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required); $config =& CRM_Core_Config::singleton(); if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactCountry) { $defaultValues[$name] = $config->defaultContactCountry; $form->setDefaults($defaultValues); } } else { if (substr($fieldName, 0, 6) === 'county') { if ($addressOptions['county']) { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::county(), $required); } } else { if (substr($fieldName, 0, 2) === 'im') { if (!$contactId) { $form->add('select', $name . '-provider_id', $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::IMProvider(), $required); if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) { $form->freeze($name . "-provider_id"); } } $form->add('text', $name, $title, $attributes, $required); } else { if ($fieldName === 'birth_date' || $fieldName === 'deceased_date') { $form->addDate($name, $title, $required, array('formatType' => 'birth')); } else { if (in_array($fieldName, array("membership_start_date", "membership_end_date", "join_date"))) { $form->addDate($name, $title, $required, array('formatType' => 'custom')); } else { if ($field['name'] == 'membership_type_id') { require_once 'CRM/Member/PseudoConstant.php'; $form->add('select', 'membership_type_id', $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipType(), $required); } else { if ($field['name'] == 'status_id') { require_once 'CRM/Member/PseudoConstant.php'; $form->add('select', 'status_id', $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(), $required); } else { if ($fieldName === 'gender') { $genderOptions = array(); $gender = CRM_Core_PseudoConstant::gender(); foreach ($gender as $key => $var) { $genderOptions[$key] = HTML_QuickForm::createElement('radio', null, ts('Gender'), $var, $key); } $form->addGroup($genderOptions, $name, $title); if ($required) { $form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required'); } } else { if ($fieldName === 'individual_prefix') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix(), $required); } else { if ($fieldName === 'individual_suffix') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix(), $required); } else { if ($fieldName === 'contact_sub_type') { $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $form->_fields[$fieldName]); $profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : null; $setSubtype = false; if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { $setSubtype = $profileType; $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType); } $subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array(); if ($setSubtype) { $subtypeList = array(); $subtypeList[$setSubtype] = $subtypes[$setSubtype]; } else { $subtypeList = array('' => ts('- select -')) + $subtypes; } $form->add('select', $name, $title, $subtypeList, $required); } else { if (in_array($fieldName, array('email_greeting', 'postal_greeting', 'addressee'))) { //add email greeting, postal greeting, addressee, CRM-4575 $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field); $profileType = CRM_Core_BAO_UFField::getProfileType($gId, true, false, true); if (empty($profileType) || in_array($profileType, array('Contact', 'Contribution', 'Participant', 'Membership'))) { $profileType = 'Individual'; } if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType); } if ($fieldName == 'email_greeting') { $emailGreeting = array('contact_type' => $profileType, 'greeting_type' => 'email_greeting'); $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($emailGreeting), $required); // adding custom email greeting element alongwith email greeting $form->add('text', 'email_greeting_custom', ts('Custom Email Greeting'), null, false); } else { if ($fieldName === 'postal_greeting') { $postalGreeting = array('contact_type' => $profileType, 'greeting_type' => 'postal_greeting'); $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($postalGreeting), $required); // adding custom postal greeting element alongwith postal greeting $form->add('text', 'postal_greeting_custom', ts('Custom Postal Greeting'), null, false); } else { if ($fieldName === 'addressee') { $addressee = array('contact_type' => $profileType, 'greeting_type' => 'addressee'); $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($addressee), $required); // adding custom addressee element alongwith addressee type $form->add('text', 'addressee_custom', ts('Custom Addressee'), null, false); } } } } else { if ($fieldName === 'preferred_communication_method') { $communicationFields = CRM_Core_PseudoConstant::pcm(); foreach ($communicationFields as $key => $var) { if ($key == '') { continue; } $communicationOptions[] =& HTML_QuickForm::createElement('checkbox', $key, null, $var); } $form->addGroup($communicationOptions, $name, $title, '<br/>'); } else { if ($fieldName === 'preferred_mail_format') { $form->add('select', $name, $title, CRM_Core_SelectValues::pmf()); } else { if ($fieldName == 'external_identifier') { $form->add('text', $name, $title, $attributes, $required); $contID = $contactId; if (!$contID) { $contID = $form->get('id'); } $form->addRule($name, ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $contID, 'external_identifier')); } else { if ($fieldName === 'group') { require_once 'CRM/Contact/Form/Edit/TagsAndGroups.php'; CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, true, $required, $title, null, $name); } else { if ($fieldName === 'tag') { require_once 'CRM/Contact/Form/Edit/TagsAndGroups.php'; CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::TAG, false, $required, null, $title, $name); } else { if ($fieldName === 'home_URL') { $form->addElement('text', $name, $title, array_merge(CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'home_URL'), array('onfocus' => "if (!this.value) this.value='http://'; else return false", 'onblur' => "if ( this.value == 'http://') this.value=''; else return false"))); $form->addRule($name, ts('Enter a valid Website.'), 'url'); } else { if (substr($fieldName, 0, 6) === 'custom') { $customFieldID = CRM_Core_BAO_CustomField::getKeyID($fieldName); if ($customFieldID) { CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, false, $required, $search, $title); } } else { if (in_array($fieldName, array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) { $form->addDate($name, $title, $required, array('formatType' => 'custom')); } else { if ($fieldName == 'payment_instrument') { require_once "CRM/Contribute/PseudoConstant.php"; $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required); } else { if ($fieldName == 'contribution_type') { require_once "CRM/Contribute/PseudoConstant.php"; $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType(), $required); } else { if ($fieldName == 'contribution_status_id') { require_once "CRM/Contribute/PseudoConstant.php"; $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionStatus(), $required); } else { if ($fieldName == 'participant_register_date') { $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime')); } else { if ($fieldName == 'participant_status_id') { require_once "CRM/Event/PseudoConstant.php"; $cond = null; if ($online == true) { $cond = "visibility_id = 1"; } $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantStatus(null, $cond), $required); } else { if ($fieldName == 'participant_role_id') { require_once "CRM/Event/PseudoConstant.php"; $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantRole(), $required); } else { if ($fieldName == 'scholarship_type_id') { $form->add('select', $name, $title, array("" => "-- Select -- ") + array_flip(CRM_Core_OptionGroup::values('scholarship_type', true))); } else { if ($fieldName == 'applicant_status_id') { $form->add('select', $name, $title, array("" => "-- Select -- ") + array_flip(CRM_Core_OptionGroup::values('applicant_status', true))); } else { if ($fieldName == 'highschool_gpa_id') { $form->add('select', $name, $title, array("" => "-- Select -- ") + CRM_Core_OptionGroup::values('highschool_gpa')); } else { if ($fieldName == 'world_region') { require_once "CRM/Core/PseudoConstant.php"; $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::worldRegion(), $required); } else { $processed = false; if (CRM_Core_Permission::access('Quest', false)) { require_once 'CRM/Quest/BAO/Student.php'; $processed = CRM_Quest_BAO_Student::buildStudentForm($form, $fieldName, $title, $contactId); } if (!$processed) { if (substr($fieldName, 0, 3) === 'is_' or substr($fieldName, 0, 7) === 'do_not_') { $form->add('checkbox', $name, $title, $attributes, $required); } else { $form->add('text', $name, $title, $attributes, $required); } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } static $hiddenSubtype = false; if (!$hiddenSubtype && CRM_Contact_BAO_ContactType::isaSubType($field['field_type'])) { // In registration mode params are submitted via POST and we don't have any clue // about profile-id or the profile-type (which could be a subtype) // To generalize the behavior and simplify the process, // lets always add the hidden //subtype value if there is any, and we won't have to // compute it while processing. $form->addElement('hidden', 'contact_sub_type_hidden', $field['field_type']); $hiddenSubtype = true; } if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) { $form->freeze($name); } //add the rules if (in_array($fieldName, array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) { $form->addRule($name, ts('Please enter a valid amount.'), 'money'); } if ($rule) { if (!($rule == 'email' && $mode == CRM_Profile_Form::MODE_SEARCH)) { $form->addRule($name, ts('Please enter a valid %1', array(1 => $title)), $rule); } } }
/** * @param CRM_Core_Form $form */ public static function buildSearchForm(&$form) { $dataURLEventFee = CRM_Utils_System::url('civicrm/ajax/eventFee', "reset=1", FALSE, NULL, FALSE); $form->assign('dataURLEventFee', $dataURLEventFee); $form->addEntityRef('event_id', ts('Event Name'), array('entity' => 'event', 'placeholder' => ts('- any -'), 'multiple' => 1, 'select' => array('minimumInputLength' => 0))); $form->addEntityRef('event_type_id', ts('Event Type'), array('entity' => 'option_value', 'placeholder' => ts('- any -'), 'select' => array('minimumInputLength' => 0), 'api' => array('params' => array('option_group_id' => 'event_type')))); $obj = new CRM_Report_Form_Event_ParticipantListing(); $form->add('select', 'participant_fee_id', ts('Fee Level'), $obj->getPriceLevels(), FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple', 'placeholder' => ts('- any -'))); CRM_Core_Form_Date::buildDateRange($form, 'event', 1, '_start_date_low', '_end_date_high', ts('From'), FALSE); CRM_Core_Form_Date::buildDateRange($form, 'participant', 1, '_register_date_low', '_register_date_high', ts('From'), FALSE); $form->addElement('checkbox', "event_include_repeating_events", NULL, ts('Include participants from all events in the %1 series', array(1 => '<em>%1</em>'))); $form->addSelect('participant_status_id', array('entity' => 'participant', 'label' => ts('Participant Status'), 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -'))); $form->addSelect('participant_role_id', array('entity' => 'participant', 'label' => ts('Participant Role'), 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -'))); $form->addYesNo('participant_test', ts('Participant is a Test?'), TRUE); $form->addYesNo('participant_is_pay_later', ts('Participant is Pay Later?'), TRUE); $form->addElement('text', 'participant_fee_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8)); $form->addElement('text', 'participant_fee_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8)); $form->addRule('participant_fee_amount_low', ts('Please enter a valid money value.'), 'money'); $form->addRule('participant_fee_amount_high', ts('Please enter a valid money value.'), 'money'); // add all the custom searchable fields $extends = array('Participant', 'Event'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); if ($groupDetails) { $form->assign('participantGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, TRUE); } } } CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'participant_campaign_id'); $form->assign('validCiviEvent', TRUE); $form->setDefaults(array('participant_test' => 0)); }
static function buildSearchForm(&$form) { $dataURLEvent = CRM_Utils_System::url('civicrm/ajax/event', "reset=1", FALSE, NULL, FALSE); $dataURLEventType = CRM_Utils_System::url('civicrm/ajax/eventType', "reset=1", FALSE, NULL, FALSE); $dataURLEventFee = CRM_Utils_System::url('civicrm/ajax/eventFee', "reset=1", FALSE, NULL, FALSE); $form->assign('dataURLEvent', $dataURLEvent); $form->assign('dataURLEventType', $dataURLEventType); $form->assign('dataURLEventFee', $dataURLEventFee); $eventId =& $form->add('text', 'event_name', ts('Event Name')); $eventType =& $form->add('text', 'event_type', ts('Event Type')); $participantFee =& $form->add('text', 'participant_fee_level', ts('Fee Level')); //elements for assigning value operation $eventNameId =& $form->add('hidden', 'event_id', '', array('id' => 'event_id')); $eventTypeId =& $form->add('hidden', 'event_type_id', '', array('id' => 'event_type_id')); $participantFeeId =& $form->add('hidden', 'participant_fee_id', '', array('id' => 'participant_fee_id')); CRM_Core_Form_Date::buildDateRange($form, 'event', 1, '_start_date_low', '_end_date_high', ts('From'), FALSE, FALSE); $status = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label'); asort($status); foreach ($status as $id => $Name) { $form->_participantStatus =& $form->addElement('checkbox', "participant_status_id[{$id}]", NULL, $Name); } foreach (CRM_Event_PseudoConstant::participantRole() as $rId => $rName) { $form->_participantRole =& $form->addElement('checkbox', "participant_role_id[{$rId}]", NULL, $rName); } $form->addElement('checkbox', 'participant_test', ts('Find Test Participants?')); $form->addElement('checkbox', 'participant_pay_later', ts('Find Pay Later Participants?')); $form->addElement('text', 'participant_fee_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8)); $form->addElement('text', 'participant_fee_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8)); $form->addRule('participant_fee_amount_low', ts('Please enter a valid money value.'), 'money'); $form->addRule('participant_fee_amount_high', ts('Please enter a valid money value.'), 'money'); // add all the custom searchable fields $extends = array('Participant'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); if ($groupDetails) { $form->assign('participantGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'participant_campaign_id'); $form->assign('validCiviEvent', TRUE); }