Example #1
0
 /**
  * @param CRM_Core_Form $form
  */
 public function buildForm(&$form)
 {
     /**
      * You can define a custom title for the search form
      */
     $this->setTitle('Find Totals for Events');
     /**
      * Define the search form fields here
      */
     $form->addElement('checkbox', 'paid_online', ts('Only show Credit Card Payments'));
     $form->addElement('checkbox', 'show_payees', ts('Show payees'));
     $event_type = CRM_Core_OptionGroup::values('event_type', FALSE);
     foreach ($event_type as $eventId => $eventName) {
         $form->addElement('checkbox', "event_type_id[{$eventId}]", 'Event Type', $eventName);
     }
     $events = CRM_Event_BAO_Event::getEvents(1);
     $form->add('select', 'event_id', ts('Event Name'), array('' => ts('- select -')) + $events);
     $form->addDate('start_date', ts('Payments Date From'), FALSE, array('formatType' => 'custom'));
     $form->addDate('end_date', ts('...through'), FALSE, array('formatType' => 'custom'));
     /**
      * If you are using the sample template, this array tells the template fields to render
      * for the search form.
      */
     $form->assign('elements', array('paid_online', 'start_date', 'end_date', 'show_payees', 'event_type_id', 'event_id'));
 }
 /**
  * Prepare a set of search fields
  *
  * @param CRM_Core_Form $form modifiable
  * @return void
  */
 function buildForm(&$form)
 {
     CRM_Utils_System::setTitle(ts('Custom Search Group Contact'));
     $aElements = array();
     #get all groups
     $aGroups = CRM_Core_PseudoConstant::group();
     $form->addElement('advmultiselect', 'group_contact', ts('Group(s)') . ' ', $aGroups, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect'));
     #assign to element
     $aElements[] = 'group_contact';
     #date range
     $form->addDate('start_date', 'From :', FALSE, array('formatType' => 'searchDate'));
     $form->addDate('end_date', 'To :', FALSE, array('formatType' => 'searchDate'));
     $aElements[] = 'start_date';
     $aElements[] = 'end_date';
     #to get all status
     /*$oGroupContact  = new CRM_Contact_DAO_GroupContact;
       $aGroupFields   = $oGroupContact->fields();
       $sStatus        = $aGroupFields['status']['enumValues'];
       $aStatus        = explode(', ', $sStatus);*/
     $aStatus = CRM_Core_SelectValues::groupContactStatus();
     foreach ($aStatus as $status) {
         //$form->addElement('checkbox',  "status[{$status}]",$status,    '', array('class' => 'group_status'));
         $form->addElement('checkbox', $status, ts("{$status}"), '', array('class' => 'group_status'));
         //$form->addElement('checkbox', "status[{$status}]" ,  $status, '', array('class' => 'group_status'));
         $aElements[] = $status;
     }
     /**
      * if you are using the standard template, this array tells the template what elements
      * are part of the search criteria
      */
     $this->_elements = $aElements;
     $form->assign('elements', $aElements);
 }
 /**
  * @param CRM_Core_Form $form
  */
 public function buildForm(&$form)
 {
     /**
      * You can define a custom title for the search form
      */
     $this->setTitle('Find Contributors by Aggregate Totals');
     /**
      * Define the search form fields here
      */
     $form->add('text', 'min_amount', ts('Aggregate Total Between $'));
     $form->addRule('min_amount', ts('Please enter a valid amount (numbers and decimal point only).'), 'money');
     $form->add('text', 'max_amount', ts('...and $'));
     $form->addRule('max_amount', ts('Please enter a valid amount (numbers and decimal point only).'), 'money');
     $form->addDate('start_date', ts('Contribution Date From'), FALSE, array('formatType' => 'custom'));
     $form->addDate('end_date', ts('...through'), FALSE, array('formatType' => 'custom'));
     $financial_types = CRM_Contribute_PseudoConstant::financialType();
     foreach ($financial_types as $financial_type_id => $financial_type) {
         $form->addElement('checkbox', "financial_type_id[{$financial_type_id}]", 'Financial Type', $financial_type);
     }
     /**
      * If you are using the sample template, this array tells the template fields to render
      * for the search form.
      */
     $form->assign('elements', array('min_amount', 'max_amount', 'start_date', 'end_date', 'financial_type_id'));
 }
 /**
  * build the form elements for Demographics object
  *
  * @param CRM_Core_Form $form       reference to the form object
  *
  * @return void
  * @access public
  * @static
  */
 static function buildQuickForm(&$form)
 {
     // radio button for gender
     $genderOptions = array();
     $gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id', array('localize' => TRUE));
     foreach ($gender as $key => $var) {
         $genderOptions[$key] = $form->createElement('radio', NULL, ts('Gender'), $var, $key, array('id' => "civicrm_gender_{$var}_{$key}"));
     }
     $form->addGroup($genderOptions, 'gender_id', ts('Gender'))->setAttribute('unselectable', TRUE);
     $form->addDate('birth_date', ts('Date of Birth'), FALSE, array('formatType' => 'birth'));
     $form->addElement('checkbox', 'is_deceased', NULL, ts('Contact is deceased'), array('onclick' => "showDeceasedDate()"));
     $form->addDate('deceased_date', ts('Deceased date'), FALSE, array('formatType' => 'birth'));
 }
 /**
  * build the form elements for Demographics object
  *
  * @param CRM_Core_Form $form       reference to the form object
  *
  * @return void
  * @access public
  * @static
  */
 static function buildQuickForm(&$form)
 {
     // radio button for gender
     $genderOptions = array();
     $gender = CRM_Core_PseudoConstant::gender();
     foreach ($gender as $key => $var) {
         $genderOptions[$key] = HTML_QuickForm::createElement('radio', null, ts('Gender'), $var, $key);
     }
     $form->addGroup($genderOptions, 'gender_id', ts('Gender'));
     $form->addDate('birth_date', ts('Date of birth'), false, array('formatType' => 'birth'));
     $form->addElement('checkbox', 'is_deceased', null, ts('Contact is deceased'), array('onclick' => "showDeceasedDate()"));
     $form->addDate('deceased_date', ts('Deceased date'), false, array('formatType' => 'birth'));
 }
 /**
  * Prepare a set of search fields
  *
  * @param CRM_Core_Form $form modifiable
  * @return void
  */
 function buildForm(&$form)
 {
     $config = CRM_Earmarking_Config::singleton();
     CRM_Utils_System::setTitle($config->translate('Search for Contacts with Recurring Contributions'));
     $paymentTypeList = $this->getPaymentTypeList();
     $earmarkingList = $this->getEarmarkingList();
     $contibutionStatusList = $this->getContributionStatusList();
     $form->add('select', 'earmarking_id', $config->translate('Earmarking'), $earmarkingList);
     $form->add('select', 'payment_type_id', $config->translate('Payment Type'), $paymentTypeList);
     $form->add('select', 'status_id', ts('Contribution Status'), $contibutionStatusList);
     $form->addDate('start_date', ts('Start Date'), FALSE, array('formatType' => 'custom'));
     $form->addDate('end_date', ts('End Date'), FALSE, array('formatType' => 'custom'));
     $form->assign('elements', array('earmarking_id', 'payment_type_id', 'status_id', 'start_date', 'end_date'));
 }
Example #7
0
 /**
  * @param CRM_Core_Form $form
  */
 public function buildForm(&$form)
 {
     /**
      * You can define a custom title for the search form
      */
     $this->setTitle('Find Latest Activities');
     /**
      * Define the search form fields here
      */
     // Allow user to choose which type of contact to limit search on
     $form->add('select', 'contact_type', ts('Find...'), CRM_Core_SelectValues::contactType());
     // Text box for Activity Subject
     $form->add('text', 'activity_subject', ts('Activity Subject'));
     // Select box for Activity Type
     $activityType = array('' => ' - select activity - ') + CRM_Core_PseudoConstant::activityType();
     $form->add('select', 'activity_type_id', ts('Activity Type'), $activityType, FALSE);
     // textbox for Activity Status
     $activityStatus = array('' => ' - select status - ') + CRM_Core_PseudoConstant::activityStatus();
     $form->add('select', 'activity_status_id', ts('Activity Status'), $activityStatus, FALSE);
     // Activity Date range
     $form->addDate('start_date', ts('Activity Date From'), FALSE, array('formatType' => 'custom'));
     $form->addDate('end_date', ts('...through'), FALSE, array('formatType' => 'custom'));
     // Contact Name field
     $form->add('text', 'sort_name', ts('Contact Name'));
     /**
      * If you are using the sample template, this array tells the template fields to render
      * for the search form.
      */
     $form->assign('elements', array('contact_type', 'activity_subject', 'activity_type_id', 'activity_status_id', 'start_date', 'end_date', 'sort_name'));
 }
 /**
  * @param CRM_Core_Form $form
  */
 public function buildForm(&$form)
 {
     /**
      * You can define a custom title for the search form
      */
     $this->setTitle('Find Contribution Amounts by Tag');
     /**
      * Define the search form fields here
      */
     $form->addDate('start_date', ts('Contribution Date From'), FALSE, array('formatType' => 'custom'));
     $form->addDate('end_date', ts('...through'), FALSE, array('formatType' => 'custom'));
     $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
     $form->addElement('select', 'tag', ts('Tagged'), $tag);
     /**
      * If you are using the sample template, this array tells the template fields to render
      * for the search form.
      */
     $form->assign('elements', array('start_date', 'end_date', 'tag'));
 }
Example #9
0
 /**
  * @param CRM_Core_Form $form
  */
 public function buildForm(&$form)
 {
     $form->addDate('start_date', ts('Start Date'), FALSE, array('formatType' => 'custom'));
     $form->addDate('end_date', ts('End Date'), FALSE, array('formatType' => 'custom'));
     $groups = CRM_Core_PseudoConstant::nestedGroup();
     $select2style = array('multiple' => TRUE, 'style' => 'width: 100%; max-width: 60em;', 'class' => 'crm-select2', 'placeholder' => ts('- select -'));
     $form->add('select', 'includeGroups', ts('Include Group(s)'), $groups, FALSE, $select2style);
     $form->add('select', 'excludeGroups', ts('Exclude Group(s)'), $groups, FALSE, $select2style);
     $this->setTitle('Search by date added to CiviCRM');
     //redirect if group not available for search criteria
     if (count($groups) == 0) {
         CRM_Core_Error::statusBounce(ts("Atleast one Group must be present for search."), CRM_Utils_System::url('civicrm/contact/search/custom/list', 'reset=1'));
     }
     /**
      * if you are using the standard template, this array tells the template what elements
      * are part of the search criteria
      */
     $form->assign('elements', array('start_date', 'end_date', 'includeGroups', 'excludeGroups'));
 }
 /**
  * @param CRM_Core_Form $form
  */
 public function buildForm(&$form)
 {
     /**
      * You can define a custom title for the search form
      */
     $this->setTitle('Find Contributors by Aggregate Totals');
     /**
      * Define the search form fields here
      */
     $form->add('text', 'min_amount', ts('Aggregate Total Between $'));
     $form->addRule('min_amount', ts('Please enter a valid amount (numbers and decimal point only).'), 'money');
     $form->add('text', 'max_amount', ts('...and $'));
     $form->addRule('max_amount', ts('Please enter a valid amount (numbers and decimal point only).'), 'money');
     $form->addDate('start_date', ts('Contribution Date From'), FALSE, array('formatType' => 'custom'));
     $form->addDate('end_date', ts('...through'), FALSE, array('formatType' => 'custom'));
     $form->addSelect('financial_type_id', array('entity' => 'contribution', 'multiple' => 'multiple', 'context' => 'search'));
     /**
      * If you are using the sample template, this array tells the template fields to render
      * for the search form.
      */
     $form->assign('elements', array('min_amount', 'max_amount', 'start_date', 'end_date'));
 }
 /**
  * @param CRM_Core_Form $form
  */
 public function buildForm(&$form)
 {
     foreach ($this->_amounts as $name => $title) {
         $form->add('text', $name, $title);
     }
     foreach ($this->_dates as $name => $title) {
         $form->addDate($name, $title, FALSE, array('formatType' => 'custom'));
     }
     foreach ($this->_checkboxes as $name => $title) {
         $form->add('checkbox', $name, $title);
     }
     $this->setTitle('Contributions made in Year X and not Year Y');
     // @TODO: Decide on better names for "Exclusion"
     // @TODO: Add rule to ensure that exclusion dates are not in the inclusion range
 }
 /**
  * @param CRM_Core_Form $form
  */
 public function buildForm(&$form)
 {
     /**
      * You can define a custom title for the search form
      */
     $this->setTitle('Recurring Contribution Changes');
     /**
      * Define the search form fields here
      */
     $form->addDate('start_date', ts('Changes Since'), FALSE, array('formatType' => 'custom'));
     /**
      * If you are using the sample template, this array tells the template fields to render
      * for the search form.
      */
     $form->assign('elements', array('start_date'));
 }
 /**
  * Build the form object for Premium Information.
  *
  * Called from the CRM_Contribute_Form_Contribute function and seemingly nowhere else.
  *
  * Probably this should be on the form that uses it since it is not used on multiple forms.
  *
  * Putting it on this class doesn't seem to reduce complexity.
  *
  * @param CRM_Core_Form $form
  */
 public static function buildPremium(&$form)
 {
     //premium section
     $form->add('hidden', 'hidden_Premium', 1);
     $sel1 = $sel2 = array();
     $dao = new CRM_Contribute_DAO_Product();
     $dao->is_active = 1;
     $dao->find();
     $min_amount = array();
     $sel1[0] = ts('-select product-');
     while ($dao->fetch()) {
         $sel1[$dao->id] = $dao->name . " ( " . $dao->sku . " )";
         $min_amount[$dao->id] = $dao->min_contribution;
         $options = explode(',', $dao->options);
         foreach ($options as $k => $v) {
             $options[$k] = trim($v);
         }
         if ($options[0] != '') {
             $sel2[$dao->id] = $options;
         }
         $form->assign('premiums', TRUE);
     }
     $form->_options = $sel2;
     $form->assign('mincontribution', $min_amount);
     $sel =& $form->addElement('hierselect', "product_name", ts('Premium'), 'onclick="showMinContrib();"');
     $js = "<script type='text/javascript'>\n";
     $formName = 'document.forms.' . $form->getName();
     for ($k = 1; $k < 2; $k++) {
         if (!isset($defaults['product_name'][$k]) || !$defaults['product_name'][$k]) {
             $js .= "{$formName}['product_name[{$k}]'].style.display = 'none';\n";
         }
     }
     $sel->setOptions(array($sel1, $sel2));
     $js .= "</script>\n";
     $form->assign('initHideBoxes', $js);
     $form->addDate('fulfilled_date', ts('Fulfilled'), FALSE, array('formatType' => 'activityDate'));
     $form->addElement('text', 'min_amount', ts('Minimum Contribution Amount'));
 }
 /**
  * @param CRM_Core_Form $form
  */
 public function buildForm(&$form)
 {
     /**
      * You can define a custom title for the search form
      */
     $this->setTitle('Recurring Contribution Aggregate');
     // Get default curreny
     $config = CRM_Core_Config::singleton();
     $currencySymbol = $config->defaultCurrencySymbol;
     /**
      * Define the search form fields here
      */
     $form->addDate('start_date', ts('Start Date'), FALSE, array('formatType' => 'custom'));
     $form->add('text', 'min_amount', ts('Aggregate Total Between ' . $currencySymbol));
     $form->addRule('min_amount', ts('Please enter a valid amount (numbers and decimal point only).'), 'money');
     $form->add('text', 'max_amount', ts('...and ' . $currencySymbol));
     $form->addRule('max_amount', ts('Please enter a valid amount (numbers and decimal point only).'), 'money');
     /**
      * If you are using the sample template, this array tells the template fields to render
      * for the search form.
      */
     $form->assign('elements', array('start_date', 'min_amount', 'max_amount'));
 }
 /**
  * Prepare a set of search fields
  *
  * @param CRM_Core_Form $form modifiable
  * @return void
  */
 function buildForm(&$form)
 {
     $this->setTitle('Potential spam entries and names for fixing');
     /**
      * Define the search form fields here
      */
     $spam_options = array('1' => ts('First name equals last name'), '2' => ts('Names contain numbers'), '6' => ts('MiXEd cAsE LAsT namE'), '7' => ts('Non-Numeric Postcode (and address not known to be overseas)'), '8' => ts('Long or short Postcode'), '9' => ts('Long or short Phone Number'), '10' => ts('Unexpected Punctuation in Name'));
     $form->addRadio('spam_options', ts('Search options'), $spam_options, array(), '<br />', TRUE);
     // Text box for phone number length to test
     $form->add('text', 'min_length', ts('Shortest length of postcodes (default: 4) or phone numbers (default: 10)'));
     // Text box for phone number length to test
     $form->add('text', 'max_length', ts('Longest length of postcodes (default: 4) or phone numbers (default: 14)'));
     // Date for records added since
     $form->addDate('start_date', ts('Contact records added since'), FALSE, array('formatType' => 'custom'));
     // Filter on Minimum Contact ID
     $form->add('text', 'min_contact_id', ts('Only show contact records with ID greater than:'));
     // Filter out blank names
     $form->add('checkbox', 'blank_names', ts("Check to not display contacts whose first and last name are both blank"));
     /**
      * If you are using the sample template, this array tells the template fields to render
      * for the search form.
      */
     $form->assign('elements', array('spam_options', 'min_contact_id', 'blank_names', 'min_length', 'max_length'));
 }
 /**
  * @param CRM_Core_Form $form
  */
 public function buildForm(&$form)
 {
     /**
      * You can define a custom title for the search form
      */
     $this->setTitle('Late Recurring Contributions');
     // Get default curreny
     $config = CRM_Core_Config::singleton();
     $currencySymbol = $config->defaultCurrencySymbol;
     /**
      * Define the search form fields here
      */
     $form->addDate('start_date', ts('Before Date'), FALSE, array('formatType' => 'custom'));
     /**
      * If you are using the sample template, this array tells the template fields to render
      * for the search form.
      */
     $form->assign('elements', array('start_date'));
 }
Example #17
0
 /**
  * Build the activity selector/datatable
  * @param CRM_Core_Form $form
  */
 static function activityForm($form)
 {
     $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($form->_contactID, $form->_caseID);
     //build reporter select
     $reporters = array("" => ts(' - any reporter - '));
     foreach ($caseRelationships as $key => &$value) {
         $reporters[$value['cid']] = $value['name'] . " ( {$value['relation']} )";
     }
     $form->add('select', 'reporter_id', ts('Reporter/Role'), $reporters, FALSE, array('id' => 'reporter_id_' . $form->_caseID));
     // take all case activity types for search filter, CRM-7187
     $aTypesFilter = array();
     $allCaseActTypes = CRM_Case_PseudoConstant::caseActivityType();
     foreach ($allCaseActTypes as $typeDetails) {
         if (!in_array($typeDetails['name'], array('Open Case'))) {
             $aTypesFilter[$typeDetails['id']] = CRM_Utils_Array::value('label', $typeDetails);
         }
     }
     asort($aTypesFilter);
     $form->add('select', 'activity_type_filter_id', ts('Activity Type'), array('' => ts('- select activity type -')) + $aTypesFilter, FALSE, array('id' => 'activity_type_filter_id_' . $form->_caseID));
     $activityStatus = CRM_Core_PseudoConstant::activityStatus();
     $form->add('select', 'status_id', ts('Status'), array("" => ts(' - any status - ')) + $activityStatus, FALSE, array('id' => 'status_id_' . $form->_caseID));
     // activity dates
     $form->addDate('activity_date_low_' . $form->_caseID, ts('Activity Dates - From'), FALSE, array('formatType' => 'searchDate'));
     $form->addDate('activity_date_high_' . $form->_caseID, ts('To'), FALSE, array('formatType' => 'searchDate'));
     if (CRM_Core_Permission::check('administer CiviCRM')) {
         $form->add('checkbox', 'activity_deleted', ts('Deleted Activities'), '', FALSE, array('id' => 'activity_deleted_' . $form->_caseID));
     }
 }
/**
 * Implements hook_civicrm_buildForm().
 *
 * @param string $formName
 * @param CRM_Core_Form $form
 */
function pledgeonlypage_civicrm_buildForm($formName, &$form)
{
    if ($formName == 'CRM_Contribute_Form_Contribution_Main') {
        if ($form->get('id') == 2) {
            $defaults['is_pledge'] = 1;
            $defaults['pledge_installments'] = 1;
            $defaults['pledge_frequency_interval'] = 1;
            $form->setDefaults($defaults);
            $form->addDate('pledge_start_date', ts('First payment date'), FALSE, array('formatType' => 'activityDate'));
            CRM_Core_Region::instance('contribution-main-pledge-block')->update('default', array('disabled' => TRUE));
            CRM_Core_Region::instance('contribution-main-pledge-block')->add(array('template' => 'pledgeOnlyBlock.tpl'));
        }
    }
}
Example #19
0
 /**
  * Add all the elements shared between grant search and advanaced search.
  *
  *
  * @param CRM_Core_Form $form
  *
  * @return void
  */
 public static function buildSearchForm(&$form)
 {
     $grantType = CRM_Core_OptionGroup::values('grant_type');
     $form->add('select', 'grant_type_id', ts('Grant Type'), $grantType, FALSE, array('id' => 'grant_type_id', 'multiple' => 'multiple', 'class' => 'crm-select2'));
     $grantStatus = CRM_Core_OptionGroup::values('grant_status');
     $form->add('select', 'grant_status_id', ts('Grant Status'), $grantStatus, FALSE, array('id' => 'grant_status_id', 'multiple' => 'multiple', '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', '', 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', '', 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', '', 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', '', 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);
 }
 protected function buildExtraDataDefaultQuickForm(CRM_Core_Form $form)
 {
     require_once 'CRM/Finance/BAO/BatchType.php';
     require_once 'CRM/Finance/BAO/BankAccount.php';
     require_once 'CRM/Contribute/PseudoConstant.php';
     $form->add('text', 'batch_title', ts('Batch Title'), null, true);
     $form->add('textarea', 'description', ts('Description'), null, false);
     $emptySelect1[''] = '- select -';
     $bankAccounts = CRM_Finance_BAO_BankAccount::getBankAccountsList($emptySelect1);
     $form->add('select', 'banking_account', ts('Bank Account'), $bankAccounts, true);
     //TODO: how to get this in civicrm default format?
     $current = CRM_Utils_Date::getToday(null, 'm/d/Y');
     $form->addDate('banking_date', ts('Banking Date'), true, array('formatType' => 'activityDate', 'value' => $current));
     $form->addElement('checkbox', 'exclude_from_posting', ts('Exclude from posting'), null, null);
     $emptySelect[''] = '- select -';
     $contributionTypes = CRM_Finance_BAO_BatchType::getContributionTypesList($emptySelect);
     $form->add('select', 'contribution_type_id', ts('Contribution Type'), $contributionTypes, true);
     $el = $form->add('select', 'payment_instrument_id', ts('Payment Method'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), true);
     $el->setValue($this->getDefaultPaymentMethodId());
     if (!in_array('campaign_id', $this->hideDefaultFields)) {
         $form->add('text', 'campaign_name', ts('Default Campaign Code'), array('class' => 'form text huge'), true);
         $form->add('hidden', 'campaign_id');
     }
     if (!in_array('received_date', $this->hideDefaultFields)) {
         $form->addDate('received_date', ts('Received date'), true, array('formatType' => 'activityDate', 'value' => $current));
     }
     //$form->add('select', 'contribution_type_id', ts('Contribution Type ID'), array(''=>ts( '- select -' )) + CRM_Contribute_PseudoConstant::contributionType( ), true );
     //matusz: http://support.vedaconsulting.co.uk/issues/81
     //$form->addDate( 'expected_posting_date', ts('Expected posting date'), true, array('formatType' => 'activityDate') );
     $form->addFormRule(array($this, 'extraDataQuickFormRule'));
 }
Example #21
0
 /**
  * Add profile field to a form.
  *
  * @param CRM_Core_Form $form
  * @param array $field
  *   Properties.
  * @param int $mode
  *   Profile mode.
  * @param int $contactId
  * @param bool $online
  * @param string $usedFor
  *   For building up prefixed fieldname for special cases (e.g. onBehalf, Honor).
  * @param int $rowNumber
  * @param string $prefix
  *
  * @return null
  */
 public static function buildProfile(&$form, &$field, $mode, $contactId = NULL, $online = FALSE, $usedFor = NULL, $rowNumber = NULL, $prefix = '')
 {
     $defaultValues = array();
     $fieldName = $field['name'];
     $title = $field['title'];
     $attributes = $field['attributes'];
     $rule = $field['rule'];
     $view = $field['is_view'];
     $required = $mode == CRM_Profile_Form::MODE_SEARCH ? FALSE : $field['is_required'];
     $search = $mode == CRM_Profile_Form::MODE_SEARCH ? TRUE : FALSE;
     $isShared = CRM_Utils_Array::value('is_shared', $field, 0);
     // do not display view fields in drupal registration form
     // CRM-4632
     if ($view && $mode == CRM_Profile_Form::MODE_REGISTER) {
         return NULL;
     }
     if ($usedFor == 'onbehalf') {
         $name = "onbehalf[{$fieldName}]";
     } elseif ($usedFor == 'honor') {
         $name = "honor[{$fieldName}]";
     } elseif ($contactId && !$online) {
         $name = "field[{$contactId}][{$fieldName}]";
     } elseif ($rowNumber) {
         $name = "field[{$rowNumber}][{$fieldName}]";
     } elseif (!empty($prefix)) {
         $name = $prefix . "[{$fieldName}]";
     } else {
         $name = $fieldName;
     }
     $selectAttributes = array('class' => 'crm-select2', 'placeholder' => TRUE);
     if ($fieldName == 'image_URL' && $mode == CRM_Profile_Form::MODE_EDIT) {
         $deleteExtra = json_encode(ts('Are you sure you want to delete contact image.'));
         $deleteURL = array(CRM_Core_Action::DELETE => array('name' => ts('Delete Contact Image'), 'url' => 'civicrm/contact/image', 'qs' => 'reset=1&id=%%id%%&gid=%%gid%%&action=delete', 'extra' => 'onclick = "' . htmlspecialchars("if (confirm({$deleteExtra})) this.href+='&confirmed=1'; else return false;") . '"'));
         $deleteURL = CRM_Core_Action::formLink($deleteURL, CRM_Core_Action::DELETE, array('id' => $form->get('id'), 'gid' => $form->get('gid')), ts('more'), FALSE, 'contact.profileimage.delete', 'Contact', $form->get('id'));
         $form->assign('deleteURL', $deleteURL);
     }
     $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE);
     if (substr($fieldName, 0, 14) === 'state_province') {
         $form->addChainSelect($name, array('label' => $title, 'required' => $required));
         $config = CRM_Core_Config::singleton();
         if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactStateProvince) {
             $defaultValues[$name] = $config->defaultContactStateProvince;
             $form->setDefaults($defaultValues);
         }
     } elseif (substr($fieldName, 0, 7) === 'country') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required, $selectAttributes);
         $config = CRM_Core_Config::singleton();
         if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactCountry) {
             $defaultValues[$name] = $config->defaultContactCountry;
             $form->setDefaults($defaultValues);
         }
     } elseif (substr($fieldName, 0, 6) === 'county') {
         if ($addressOptions['county']) {
             $form->addChainSelect($name, array('label' => $title, 'required' => $required));
         }
     } elseif (substr($fieldName, 0, 9) === 'image_URL') {
         $form->add('file', $name, $title, $attributes, $required);
         $form->addUploadElement($name);
     } elseif (substr($fieldName, 0, 2) === 'im') {
         $form->add('text', $name, $title, $attributes, $required);
         if (!$contactId) {
             if ($usedFor) {
                 if (substr($name, -1) == ']') {
                     $providerName = substr($name, 0, -1) . '-provider_id]';
                 }
                 $form->add('select', $providerName, NULL, array('' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $required);
             } else {
                 $form->add('select', $name . '-provider_id', $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $required);
             }
             if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) {
                 $form->freeze($name . '-provider_id');
             }
         }
     } elseif ($fieldName === 'birth_date' || $fieldName === 'deceased_date') {
         $form->addDate($name, $title, $required, array('formatType' => 'birth'));
     } elseif (in_array($fieldName, array('membership_start_date', 'membership_end_date', 'join_date'))) {
         $form->addDate($name, $title, $required, array('formatType' => 'activityDate'));
     } elseif (CRM_Utils_Array::value('name', $field) == 'membership_type') {
         list($orgInfo, $types) = CRM_Member_BAO_MembershipType::getMembershipTypeInfo();
         $sel =& $form->addElement('hierselect', $name, $title);
         $select = array('' => ts('- select -'));
         if (count($orgInfo) == 1 && $field['is_required']) {
             // we only have one org - so we should default to it. Not sure about defaulting to first type
             // as it could be missed - so adding a select
             // however, possibly that is more similar to the membership form
             if (count($types[1]) > 1) {
                 $types[1] = $select + $types[1];
             }
         } else {
             $orgInfo = $select + $orgInfo;
         }
         $sel->setOptions(array($orgInfo, $types));
     } elseif (CRM_Utils_Array::value('name', $field) == 'membership_status') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'), $required);
     } elseif (in_array($fieldName, array('gender_id', 'communication_style_id'))) {
         $options = array();
         $pseudoValues = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', $fieldName);
         foreach ($pseudoValues as $key => $var) {
             $options[$key] = $form->createElement('radio', NULL, ts($title), $var, $key);
         }
         $group = $form->addGroup($options, $name, $title);
         if ($required) {
             $form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required');
         } else {
             $group->setAttribute('allowClear', TRUE);
         }
     } elseif ($fieldName === 'prefix_id' || $fieldName === 'suffix_id') {
         $form->addSelect($name, array('label' => $title, 'entity' => 'contact', 'field' => $fieldName, 'class' => 'six', 'placeholder' => ''), $required);
     } elseif ($fieldName === 'contact_sub_type') {
         $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
         if ($usedFor == 'onbehalf') {
             $profileType = 'Organization';
         } elseif ($usedFor == 'honor') {
             $profileType = CRM_Core_BAO_UFField::getProfileType($form->_params['honoree_profile_id']);
         } else {
             $profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : NULL;
             if ($profileType == 'Contact') {
                 $profileType = 'Individual';
             }
         }
         $setSubtype = FALSE;
         if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
             $setSubtype = $profileType;
             $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
         }
         $subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array();
         if ($setSubtype) {
             $subtypeList = array();
             $subtypeList[$setSubtype] = $subtypes[$setSubtype];
         } else {
             $subtypeList = $subtypes;
         }
         $form->add('select', $name, $title, $subtypeList, $required, array('class' => 'crm-select2', 'multiple' => TRUE));
     } elseif (in_array($fieldName, CRM_Contact_BAO_Contact::$_greetingTypes)) {
         //add email greeting, postal greeting, addressee, CRM-4575
         $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
         $profileType = CRM_Core_BAO_UFField::getProfileType($gId, TRUE, FALSE, TRUE);
         if (empty($profileType) || in_array($profileType, array('Contact', 'Contribution', 'Participant', 'Membership'))) {
             $profileType = 'Individual';
         }
         if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
             $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
         }
         $greeting = array('contact_type' => $profileType, 'greeting_type' => $fieldName);
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($greeting), $required);
         // add custom greeting element
         $form->add('text', $fieldName . '_custom', ts('Custom %1', array(1 => ucwords(str_replace('_', ' ', $fieldName)))), NULL, FALSE);
     } elseif ($fieldName === 'preferred_communication_method') {
         $communicationFields = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
         foreach ($communicationFields as $key => $var) {
             if ($key == '') {
                 continue;
             }
             $communicationOptions[] = $form->createElement('checkbox', $key, NULL, $var);
         }
         $form->addGroup($communicationOptions, $name, $title, '<br/>');
     } elseif ($fieldName === 'preferred_mail_format') {
         $form->add('select', $name, $title, CRM_Core_SelectValues::pmf());
     } elseif ($fieldName === 'preferred_language') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contact_BAO_Contact::buildOptions('preferred_language'));
     } elseif ($fieldName == 'external_identifier') {
         $form->add('text', $name, $title, $attributes, $required);
         $contID = $contactId;
         if (!$contID) {
             $contID = $form->get('id');
         }
         $form->addRule($name, ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $contID, 'external_identifier'));
     } elseif ($fieldName === 'group') {
         CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, TRUE, $required, $title, NULL, $name);
     } elseif ($fieldName === 'tag') {
         CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::TAG, FALSE, $required, NULL, $title, $name);
     } elseif (substr($fieldName, 0, 4) === 'url-') {
         $form->add('text', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Website', 'url'), $required);
         $form->addRule($name, ts('Enter a valid web address beginning with \'http://\' or \'https://\'.'), 'url');
     } elseif (substr($fieldName, -4) == 'note') {
         $form->add('textarea', $name, $title, $attributes, $required);
     } elseif (substr($fieldName, 0, 6) === 'custom') {
         $customFieldID = CRM_Core_BAO_CustomField::getKeyID($fieldName);
         if ($customFieldID) {
             CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title);
         }
     } elseif (substr($fieldName, 0, 14) === 'address_custom') {
         list($fName, $locTypeId) = CRM_Utils_System::explode('-', $fieldName, 2);
         $customFieldID = CRM_Core_BAO_CustomField::getKeyID(substr($fName, 8));
         if ($customFieldID) {
             CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title);
         }
     } elseif (in_array($fieldName, array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) {
         $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
     } elseif ($fieldName == 'send_receipt') {
         $form->addElement('checkbox', $name, $title);
     } elseif ($fieldName == 'soft_credit') {
         $form->addEntityRef("soft_credit_contact_id[{$rowNumber}]", ts('Soft Credit To'), array('create' => TRUE));
         $form->addMoney("soft_credit_amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE);
     } elseif ($fieldName == 'product_name') {
         list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo();
         $sel =& $form->addElement('hierselect', $name, $title);
         $products = array('0' => ts('- select -')) + $products;
         $sel->setOptions(array($products, $options));
     } elseif ($fieldName == 'payment_instrument') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required);
     } elseif ($fieldName == 'financial_type') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType(), $required);
     } elseif ($fieldName == 'contribution_status_id') {
         $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus();
         $statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
         foreach (array('In Progress', 'Overdue', 'Refunded') as $suppress) {
             unset($contributionStatuses[CRM_Utils_Array::key($suppress, $statusName)]);
         }
         $form->add('select', $name, $title, array('' => ts('- select -')) + $contributionStatuses, $required);
     } elseif ($fieldName == 'soft_credit_type') {
         $name = "soft_credit_type[{$rowNumber}]";
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_OptionGroup::values("soft_credit_type"));
         //CRM-15350: choose SCT field default value as 'Gift' for membership use
         //else (for contribution), use configured SCT default value
         $SCTDefaultValue = CRM_Core_OptionGroup::getDefaultValue("soft_credit_type");
         if ($field['field_type'] == 'Membership') {
             $SCTDefaultValue = CRM_Core_OptionGroup::getValue('soft_credit_type', 'Gift', 'name');
         }
         $form->addElement('hidden', 'sct_default_id', $SCTDefaultValue, array('id' => 'sct_default_id'));
     } elseif ($fieldName == 'currency') {
         $form->addCurrency($name, $title, $required);
     } elseif ($fieldName == 'contribution_page_id') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage(), $required, 'class="big"');
     } elseif ($fieldName == 'participant_register_date') {
         $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
     } elseif ($fieldName == 'activity_status_id') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::activityStatus(), $required);
     } elseif ($fieldName == 'activity_engagement_level') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Campaign_PseudoConstant::engagementLevel(), $required);
     } elseif ($fieldName == 'activity_date_time') {
         $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
     } elseif ($fieldName == 'participant_status') {
         $cond = NULL;
         if ($online == TRUE) {
             $cond = 'visibility_id = 1';
         }
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantStatus(NULL, $cond, 'label'), $required);
     } elseif ($fieldName == 'participant_role') {
         if (!empty($field['is_multiple'])) {
             $form->addCheckBox($name, $title, CRM_Event_PseudoConstant::participantRole(), NULL, NULL, NULL, NULL, '&nbsp', TRUE);
         } else {
             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantRole(), $required);
         }
     } elseif ($fieldName == 'world_region') {
         $form->add('select', $name, $title, CRM_Core_PseudoConstant::worldRegion(), $required, $selectAttributes);
     } elseif ($fieldName == 'signature_html') {
         $form->add('wysiwyg', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName));
     } elseif ($fieldName == 'signature_text') {
         $form->add('textarea', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName));
     } elseif (substr($fieldName, -11) == 'campaign_id') {
         if (CRM_Campaign_BAO_Campaign::isCampaignEnable()) {
             $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(CRM_Utils_Array::value($contactId, $form->_componentCampaigns));
             $form->add('select', $name, $title, array('' => ts('- select -')) + $campaigns, $required, 'class="crm-select2 big"');
         }
     } elseif ($fieldName == 'activity_details') {
         $form->add('wysiwyg', $fieldName, $title, array('rows' => 4, 'cols' => 60), $required);
     } elseif ($fieldName == 'activity_duration') {
         $form->add('text', $name, $title, $attributes, $required);
         $form->addRule($name, ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger');
     } else {
         if (substr($fieldName, 0, 3) === 'is_' or substr($fieldName, 0, 7) === 'do_not_') {
             $form->add('advcheckbox', $name, $title, $attributes, $required);
         } else {
             $form->add('text', $name, $title, $attributes, $required);
         }
     }
     static $hiddenSubtype = FALSE;
     if (!$hiddenSubtype && CRM_Contact_BAO_ContactType::isaSubType($field['field_type'])) {
         // In registration mode params are submitted via POST and we don't have any clue
         // about profile-id or the profile-type (which could be a subtype)
         // To generalize the  behavior and simplify the process,
         // lets always add the hidden
         //subtype value if there is any, and we won't have to
         // compute it while processing.
         if ($usedFor) {
             $form->addElement('hidden', $usedFor . '[contact_sub_type]', $field['field_type']);
         } else {
             $form->addElement('hidden', 'contact_sub_type_hidden', $field['field_type']);
         }
         $hiddenSubtype = TRUE;
     }
     if ($view && $mode != CRM_Profile_Form::MODE_SEARCH || $isShared) {
         $form->freeze($name);
     }
     //add the rules
     if (in_array($fieldName, array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) {
         $form->addRule($name, ts('Please enter a valid amount.'), 'money');
     }
     if ($rule) {
         if (!($rule == 'email' && $mode == CRM_Profile_Form::MODE_SEARCH)) {
             $form->addRule($name, ts('Please enter a valid %1', array(1 => $title)), $rule);
         }
     }
 }
Example #22
0
 /**
  * Build Pledge Block in Contribution Pages.
  *
  * @param CRM_Core_Form $form
  */
 public static function buildPledgeBlock($form)
 {
     //build pledge payment fields.
     if (!empty($form->_values['pledge_id'])) {
         //get all payments required details.
         $allPayments = array();
         $returnProperties = array('status_id', 'scheduled_date', 'scheduled_amount', 'currency', 'pledge_start_date');
         CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_PledgePayment', 'pledge_id', $form->_values['pledge_id'], $allPayments, $returnProperties);
         // get all status
         $allStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
         $nextPayment = array();
         $isNextPayment = FALSE;
         $overduePayments = array();
         foreach ($allPayments as $payID => $value) {
             if ($allStatus[$value['status_id']] == 'Overdue') {
                 $overduePayments[$payID] = array('id' => $payID, 'scheduled_amount' => CRM_Utils_Rule::cleanMoney($value['scheduled_amount']), 'scheduled_amount_currency' => $value['currency'], 'scheduled_date' => CRM_Utils_Date::customFormat($value['scheduled_date'], '%B %d'));
             } elseif (!$isNextPayment && $allStatus[$value['status_id']] == 'Pending') {
                 // get the next payment.
                 $nextPayment = array('id' => $payID, 'scheduled_amount' => CRM_Utils_Rule::cleanMoney($value['scheduled_amount']), 'scheduled_amount_currency' => $value['currency'], 'scheduled_date' => CRM_Utils_Date::customFormat($value['scheduled_date'], '%B %d'));
                 $isNextPayment = TRUE;
             }
         }
         // build check box array for payments.
         $payments = array();
         if (!empty($overduePayments)) {
             foreach ($overduePayments as $id => $payment) {
                 $label = ts("%1 - due on %2 (overdue)", array(1 => CRM_Utils_Money::format(CRM_Utils_Array::value('scheduled_amount', $payment), CRM_Utils_Array::value('scheduled_amount_currency', $payment)), 2 => CRM_Utils_Array::value('scheduled_date', $payment)));
                 $paymentID = CRM_Utils_Array::value('id', $payment);
                 $payments[] = $form->createElement('checkbox', $paymentID, NULL, $label, array('amount' => CRM_Utils_Array::value('scheduled_amount', $payment)));
             }
         }
         if (!empty($nextPayment)) {
             $label = ts("%1 - due on %2", array(1 => CRM_Utils_Money::format(CRM_Utils_Array::value('scheduled_amount', $nextPayment), CRM_Utils_Array::value('scheduled_amount_currency', $nextPayment)), 2 => CRM_Utils_Array::value('scheduled_date', $nextPayment)));
             $paymentID = CRM_Utils_Array::value('id', $nextPayment);
             $payments[] = $form->createElement('checkbox', $paymentID, NULL, $label, array('amount' => CRM_Utils_Array::value('scheduled_amount', $nextPayment)));
         }
         // give error if empty or build form for payment.
         if (empty($payments)) {
             CRM_Core_Error::fatal(ts("Oops. It looks like there is no valid payment status for online payment."));
         } else {
             $form->assign('is_pledge_payment', TRUE);
             $form->addGroup($payments, 'pledge_amount', ts('Make Pledge Payment(s):'), '<br />');
         }
     } else {
         $pledgeBlock = self::getPledgeBlock($form->_id);
         // build form for pledge creation.
         $pledgeOptions = array('0' => ts('I want to make a one-time contribution'), '1' => ts('I pledge to contribute this amount every'));
         $form->addRadio('is_pledge', ts('Pledge Frequency Interval'), $pledgeOptions, NULL, array('<br/>'));
         $form->addElement('text', 'pledge_installments', ts('Installments'), array('size' => 3));
         if (!empty($pledgeBlock['is_pledge_interval'])) {
             $form->assign('is_pledge_interval', CRM_Utils_Array::value('is_pledge_interval', $pledgeBlock));
             $form->addElement('text', 'pledge_frequency_interval', NULL, array('size' => 3));
         } else {
             $form->add('hidden', 'pledge_frequency_interval', 1);
         }
         // Frequency unit drop-down label suffixes switch from *ly to *(s)
         $freqUnitVals = explode(CRM_Core_DAO::VALUE_SEPARATOR, $pledgeBlock['pledge_frequency_unit']);
         $freqUnits = array();
         $frequencyUnits = CRM_Core_OptionGroup::values('recur_frequency_units');
         foreach ($freqUnitVals as $key => $val) {
             if (array_key_exists($val, $frequencyUnits)) {
                 $freqUnits[$val] = !empty($pledgeBlock['is_pledge_interval']) ? "{$frequencyUnits[$val]}(s)" : $frequencyUnits[$val];
             }
         }
         $form->addElement('select', 'pledge_frequency_unit', NULL, $freqUnits);
         // CRM-18854
         if (CRM_Utils_Array::value('is_pledge_start_date_visible', $pledgeBlock)) {
             if (CRM_Utils_Array::value('pledge_start_date', $pledgeBlock)) {
                 $defaults = array();
                 $date = (array) json_decode($pledgeBlock['pledge_start_date']);
                 list($field, $value) = each($date);
                 switch ($field) {
                     case 'contribution_date':
                         $form->addDate('start_date', ts('First installment payment'));
                         $paymentDate = $value = date('d/m/Y');
                         list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults($value);
                         $form->assign('is_date', TRUE);
                         break;
                     case 'calendar_date':
                         $form->addDate('start_date', ts('First installment payment'));
                         list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults($value);
                         $form->assign('is_date', TRUE);
                         $paymentDate = $value;
                         break;
                     case 'calendar_month':
                         $month = CRM_Utils_Date::getCalendarDayOfMonth();
                         $form->add('select', 'start_date', ts('Day of month installments paid'), $month);
                         $paymentDate = CRM_Pledge_BAO_Pledge::getPaymentDate($value);
                         list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults($paymentDate);
                         break;
                     default:
                         break;
                 }
                 $form->setDefaults($defaults);
                 $form->assign('start_date_display', $paymentDate);
                 $form->assign('start_date_editable', FALSE);
                 if (CRM_Utils_Array::value('is_pledge_start_date_editable', $pledgeBlock)) {
                     $form->assign('start_date_editable', TRUE);
                     if ($field == 'calendar_month') {
                         $form->assign('is_date', FALSE);
                         $form->setDefaults(array('start_date' => $value));
                     }
                 }
             }
         }
     }
 }
 /**
  * @param CRM_Core_Form $form
  */
 public static function buildQuickForm(&$form)
 {
     $form->removeElement('status_id');
     $form->removeElement('priority_id');
     $caseId = CRM_Utils_Array::first($form->_caseId);
     $currentStartDate = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $caseId, 'start_date');
     $form->assign('current_start_date', $currentStartDate);
     $form->addDate('start_date', ts('New Start Date'), FALSE, array('formatType' => 'activityDateTime'));
 }
 /**
  * Build form.
  *
  * @param CRM_Core_Form $form
  */
 public static function buildQuickForm(&$form)
 {
     // FIXME: this is using the following as keys rather than the standard numeric keys returned by CRM_Utils_Date
     $dayOfTheWeek = array();
     $dayKeys = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday');
     foreach (CRM_Utils_Date::getAbbrWeekdayNames() as $k => $label) {
         $dayOfTheWeek[$dayKeys[$k]] = $label;
     }
     $form->add('select', 'repetition_frequency_unit', ts('Repeats every'), CRM_Core_SelectValues::getRecurringFrequencyUnits(), FALSE, array('class' => 'required'));
     $numericOptions = CRM_Core_SelectValues::getNumericOptions(1, 30);
     $form->add('select', 'repetition_frequency_interval', NULL, $numericOptions, FALSE, array('class' => 'required'));
     $form->addDateTime('repetition_start_date', ts('Repetition Start Date'), FALSE, array('formatType' => 'activityDateTime'));
     foreach ($dayOfTheWeek as $key => $val) {
         $startActionCondition[] = $form->createElement('checkbox', $key, NULL, $val);
     }
     $form->addGroup($startActionCondition, 'start_action_condition', ts('Repeats on'));
     $roptionTypes = array('1' => ts('day of the month'), '2' => ts('day of the week'));
     $form->addRadio('repeats_by', ts("Repeats by"), $roptionTypes, array('required' => TRUE), NULL);
     $form->add('select', 'limit_to', '', CRM_Core_SelectValues::getNumericOptions(1, 31));
     $dayOfTheWeekNo = array('first' => ts('First'), 'second' => ts('Second'), 'third' => ts('Third'), 'fourth' => ts('Fourth'), 'last' => ts('Last'));
     $form->add('select', 'entity_status_1', '', $dayOfTheWeekNo);
     $form->add('select', 'entity_status_2', '', $dayOfTheWeek);
     $eoptionTypes = array('1' => ts('After'), '2' => ts('On'));
     $form->addRadio('ends', ts("Ends"), $eoptionTypes, array('class' => 'required'), NULL);
     // Offset options gets key=>val pairs like 1=>2 because the BAO wants to know the number of
     // children while it makes more sense to the user to see the total number including the parent.
     $offsetOptions = range(1, 30);
     unset($offsetOptions[0]);
     $form->add('select', 'start_action_offset', NULL, $offsetOptions, FALSE);
     $form->addFormRule(array('CRM_Core_Form_RecurringEntity', 'formRule'));
     $form->addDate('repeat_absolute_date', ts('On'), FALSE, array('formatType' => 'mailing'));
     $form->add('text', 'exclude_date_list', ts('Exclude Dates'), array('class' => 'twenty'));
     $form->addElement('hidden', 'allowRepeatConfigToSubmit', '', array('id' => 'allowRepeatConfigToSubmit'));
     $form->addButtons(array(array('type' => 'submit', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
     // For client-side pluralization
     $form->assign('recurringFrequencyOptions', array('single' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::getRecurringFrequencyUnits()), 'plural' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::getRecurringFrequencyUnits(2))));
 }
 /**
  * This function for building custom fields.
  *
  * @param CRM_Core_Form $qf
  *   Form object (reference).
  * @param string $elementName
  *   Name of the custom field.
  * @param int $fieldId
  * @param bool $inactiveNeeded
  *   -deprecated.
  * @param bool $useRequired
  *   True if required else false.
  * @param bool $search
  *   True if used for search else false.
  * @param string $label
  *   Label for custom field.
  *
  */
 public static function addQuickFormElement(&$qf, $elementName, $fieldId, $inactiveNeeded = FALSE, $useRequired = TRUE, $search = FALSE, $label = NULL)
 {
     $field = self::getFieldObject($fieldId);
     $widget = $field->html_type;
     // Custom field HTML should indicate group+field name
     $groupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $field->custom_group_id);
     $dataCrmCustomVal = $groupName . ':' . $field->name;
     $dataCrmCustomAttr = 'data-crm-custom="' . $dataCrmCustomVal . '"';
     $field->attributes .= $dataCrmCustomAttr;
     // Fixed for Issue CRM-2183
     if ($widget == 'TextArea' && $search) {
         $widget = 'Text';
     }
     $placeholder = $search ? ts('- any -') : ($useRequired ? ts('- select -') : ts('- none -'));
     // FIXME: Why are select state/country separate widget types?
     $isSelect = in_array($widget, array('Select', 'Multi-Select', 'Select State/Province', 'Multi-Select State/Province', 'Select Country', 'Multi-Select Country', 'AdvMulti-Select', 'CheckBox', 'Radio'));
     if ($isSelect) {
         $options = CRM_Utils_Array::value('values', civicrm_api3('contact', 'getoptions', array('field' => "custom_{$fieldId}", 'context' => $search ? 'search' : 'create'), array()));
         // Consolidate widget types to simplify the below switch statement
         if ($search || $widget !== 'AdvMulti-Select' && strpos($widget, 'Select') !== FALSE) {
             $widget = 'Select';
         }
         $selectAttributes = array('data-crm-custom' => $dataCrmCustomVal, 'class' => 'crm-select2');
         // Search field is always multi-select
         if ($search || strpos($field->html_type, 'Multi') !== FALSE) {
             $selectAttributes['class'] .= ' huge';
             $selectAttributes['multiple'] = 'multiple';
             $selectAttributes['placeholder'] = $placeholder;
         }
         // Add data for popup link. Normally this is handled by CRM_Core_Form->addSelect
         if ($field->option_group_id && !$search && $widget == 'Select' && CRM_Core_Permission::check('administer CiviCRM')) {
             $selectAttributes += array('data-api-entity' => 'contact', 'data-api-field' => 'custom_' . $field->id, 'data-option-edit-path' => 'civicrm/admin/options/' . CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $field->option_group_id));
         }
     }
     if (!isset($label)) {
         $label = $field->label;
     }
     /**
      * at some point in time we might want to split the below into small functions
      **/
     switch ($widget) {
         case 'Text':
         case 'Link':
             if ($field->is_search_range && $search) {
                 $qf->add('text', $elementName . '_from', $label . ' ' . ts('From'), $field->attributes);
                 $qf->add('text', $elementName . '_to', ts('To'), $field->attributes);
             } else {
                 $element =& $qf->add('text', $elementName, $label, $field->attributes, $useRequired && !$search);
             }
             break;
         case 'TextArea':
             $attributes = $dataCrmCustomAttr;
             if ($field->note_rows) {
                 $attributes .= 'rows=' . $field->note_rows;
             } else {
                 $attributes .= 'rows=4';
             }
             if ($field->note_columns) {
                 $attributes .= ' cols=' . $field->note_columns;
             } else {
                 $attributes .= ' cols=60';
             }
             if ($field->text_length) {
                 $attributes .= ' maxlength=' . $field->text_length;
             }
             $element =& $qf->add('textarea', $elementName, $label, $attributes, $useRequired && !$search);
             break;
         case 'Select Date':
             if ($field->is_search_range && $search) {
                 $qf->addDate($elementName . '_from', $label . ' - ' . ts('From'), FALSE, array('format' => $field->date_format, 'timeFormat' => $field->time_format, 'startOffset' => $field->start_date_years, 'endOffset' => $field->end_date_years, 'data-crm-custom' => $dataCrmCustomVal));
                 $qf->addDate($elementName . '_to', ts('To'), FALSE, array('format' => $field->date_format, 'timeFormat' => $field->time_format, 'startOffset' => $field->start_date_years, 'endOffset' => $field->end_date_years, 'data-crm-custom' => $dataCrmCustomVal));
             } else {
                 $required = $useRequired && !$search;
                 $qf->addDate($elementName, $label, $required, array('format' => $field->date_format, 'timeFormat' => $field->time_format, 'startOffset' => $field->start_date_years, 'endOffset' => $field->end_date_years, 'data-crm-custom' => $dataCrmCustomVal));
             }
             break;
         case 'Radio':
             $choice = array();
             foreach ($options as $v => $l) {
                 $choice[] = $qf->createElement('radio', NULL, '', $l, (string) $v, $field->attributes);
             }
             $group = $qf->addGroup($choice, $elementName, $label);
             if ($useRequired && !$search) {
                 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
             } else {
                 $group->setAttribute('allowClear', TRUE);
             }
             break;
             // For all select elements
         // For all select elements
         case 'Select':
             if (empty($selectAttributes['multiple'])) {
                 $options = array('' => $placeholder) + $options;
             }
             $qf->add('select', $elementName, $label, $options, $useRequired && !$search, $selectAttributes);
             // Add and/or option for fields that store multiple values
             if ($search && self::isSerialized($field)) {
                 $operators = array($qf->createElement('radio', NULL, '', ts('Any'), 'or', array('title' => ts('Results may contain any of the selected options'))), $qf->createElement('radio', NULL, '', ts('All'), 'and', array('title' => ts('Results must have all of the selected options'))));
                 $qf->addGroup($operators, $elementName . '_operator');
                 $qf->setDefaults(array($elementName . '_operator' => 'or'));
             }
             break;
         case 'AdvMulti-Select':
             $include =& $qf->addElement('advmultiselect', $elementName, $label, $options, array('size' => 5, 'style' => '', 'class' => 'advmultiselect', 'data-crm-custom' => $dataCrmCustomVal));
             $include->setButtonAttributes('add', array('value' => ts('Add >>')));
             $include->setButtonAttributes('remove', array('value' => ts('<< Remove')));
             if ($useRequired && !$search) {
                 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
             }
             break;
         case 'CheckBox':
             $check = array();
             foreach ($options as $v => $l) {
                 $check[] =& $qf->addElement('advcheckbox', $v, NULL, $l, array('data-crm-custom' => $dataCrmCustomVal));
             }
             $qf->addGroup($check, $elementName, $label);
             if ($useRequired && !$search) {
                 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
             }
             break;
         case 'File':
             // we should not build upload file in search mode
             if ($search) {
                 return;
             }
             $qf->add(strtolower($field->html_type), $elementName, $label, $field->attributes, $useRequired && !$search);
             $qf->addUploadElement($elementName);
             break;
         case 'RichTextEditor':
             $attributes = array('rows' => $field->note_rows, 'cols' => $field->note_columns, 'data-crm-custom' => $dataCrmCustomVal);
             if ($field->text_length) {
                 $attributes['maxlength'] = $field->text_length;
             }
             $qf->addWysiwyg($elementName, $label, $attributes, $search);
             break;
         case 'Autocomplete-Select':
             static $customUrls = array();
             // Fixme: why is this a string in the first place??
             $attributes = array();
             if ($field->attributes) {
                 foreach (explode(' ', $field->attributes) as $at) {
                     if (strpos($at, '=')) {
                         list($k, $v) = explode('=', $at);
                         $attributes[$k] = trim($v, ' "');
                     }
                 }
             }
             if ($field->data_type == 'ContactReference') {
                 $attributes['class'] = (isset($attributes['class']) ? $attributes['class'] . ' ' : '') . 'crm-form-contact-reference huge';
                 $attributes['data-api-entity'] = 'contact';
                 $qf->add('text', $elementName, $label, $attributes, $useRequired && !$search);
                 $urlParams = "context=customfield&id={$field->id}";
                 $customUrls[$elementName] = CRM_Utils_System::url('civicrm/ajax/contactref', $urlParams, FALSE, NULL, FALSE);
             } else {
                 // FIXME: This won't work with customFieldOptions hook
                 $attributes += array('entity' => 'option_value', 'placeholder' => $placeholder, 'multiple' => $search, 'api' => array('params' => array('option_group_id' => $field->option_group_id)));
                 $qf->addEntityRef($elementName, $label, $attributes, $useRequired && !$search);
             }
             $qf->assign('customUrls', $customUrls);
             break;
     }
     switch ($field->data_type) {
         case 'Int':
             // integers will have numeric rule applied to them.
             if ($field->is_search_range && $search) {
                 $qf->addRule($elementName . '_from', ts('%1 From must be an integer (whole number).', array(1 => $label)), 'integer');
                 $qf->addRule($elementName . '_to', ts('%1 To must be an integer (whole number).', array(1 => $label)), 'integer');
             } elseif ($widget == 'Text') {
                 $qf->addRule($elementName, ts('%1 must be an integer (whole number).', array(1 => $label)), 'integer');
             }
             break;
         case 'Float':
             if ($field->is_search_range && $search) {
                 $qf->addRule($elementName . '_from', ts('%1 From must be a number (with or without decimal point).', array(1 => $label)), 'numeric');
                 $qf->addRule($elementName . '_to', ts('%1 To must be a number (with or without decimal point).', array(1 => $label)), 'numeric');
             } elseif ($widget == 'Text') {
                 $qf->addRule($elementName, ts('%1 must be a number (with or without decimal point).', array(1 => $label)), 'numeric');
             }
             break;
         case 'Money':
             if ($field->is_search_range && $search) {
                 $qf->addRule($elementName . '_from', ts('%1 From must in proper money format. (decimal point/comma/space is allowed).', array(1 => $label)), 'money');
                 $qf->addRule($elementName . '_to', ts('%1 To must in proper money format. (decimal point/comma/space is allowed).', array(1 => $label)), 'money');
             } elseif ($widget == 'Text') {
                 $qf->addRule($elementName, ts('%1 must be in proper money format. (decimal point/comma/space is allowed).', array(1 => $label)), 'money');
             }
             break;
         case 'Link':
             $element->setAttribute('onfocus', "if (!this.value) {this.value='http://';}");
             $element->setAttribute('onblur', "if (this.value == 'http://') {this.value='';}");
             $element->setAttribute('class', "url");
             $qf->addRule($elementName, ts('Enter a valid Website.'), 'wikiURL');
             break;
     }
     if ($field->is_view && !$search) {
         $qf->freeze($elementName);
     }
 }
 /**
  * @param CRM_Core_Form $form
  */
 public function buildForm(&$form)
 {
     /**
      * You can define a custom title for the search form
      */
     $this->setTitle('Expected Recurring Contribution Income');
     /**
      * Define the search form fields here
      */
     $form->addDate('start_date', ts('Start Date'), TRUE, array('formatType' => 'custom'));
     $form->addDate('end_date', ts('End Date'), TRUE, array('formatType' => 'custom'));
     /**
      * If you are using the sample template, this array tells the template fields to render
      * for the search form.
      */
     $form->assign('elements', array('start_date', 'end_date'));
     $form->addFormRule(array('CRM_Recurringcontributioncustomsearches_Form_Search_ExpectedRecurringContributionIncome', 'formRule'), $form);
 }