示例#1
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     require_once 'CRM/Utils/Money.php';
     $this->_first = true;
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage');
     // name
     $this->add('text', 'title', ts('Title'), $attributes['title'], true);
     $this->add('select', 'contribution_type_id', ts('Contribution Type'), CRM_Contribute_PseudoConstant::contributionType(), true);
     $this->addWysiwyg('intro_text', ts('Introductory Message'), $attributes['intro_text']);
     $this->addWysiwyg('footer_text', ts('Footer Message'), $attributes['footer_text']);
     // is on behalf of an organization ?
     $this->addElement('checkbox', 'is_organization', ts('Allow individuals to contribute and / or signup for membership on behalf of an organization?'), null, array('onclick' => "showHideByValue('is_organization',true,'for_org_text','table-row','radio',false);showHideByValue('is_organization',true,'for_org_option','table-row','radio',false);"));
     $options = array();
     $options[] = HTML_QuickForm::createElement('radio', null, null, ts('Optional'), 1);
     $options[] = HTML_QuickForm::createElement('radio', null, null, ts('Required'), 2);
     $this->addGroup($options, 'is_for_organization', ts(''));
     $this->add('textarea', 'for_organization', ts('On behalf of Label'), $attributes['for_organization']);
     // collect goal amount
     $this->add('text', 'goal_amount', ts('Goal Amount'), array('size' => 8, 'maxlength' => 12));
     $this->addRule('goal_amount', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money');
     // is this page active ?
     $this->addElement('checkbox', 'is_active', ts('Is this Online Contribution Page Active?'));
     // should the honor be enabled
     $this->addElement('checkbox', 'honor_block_is_active', ts('Honoree Section Enabled'), null, array('onclick' => "showHonor()"));
     $this->add('text', 'honor_block_title', ts('Honoree Section Title'), $attributes['honor_block_title']);
     $this->add('textarea', 'honor_block_text', ts('Honoree Introductory Message'), $attributes['honor_block_text']);
     // add optional start and end dates
     $this->addDateTime('start_date', ts('Start Date'));
     $this->addDateTime('end_date', ts('End Date'));
     $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Settings', 'formRule'));
     parent::buildQuickForm();
 }
 function __construct()
 {
     $yearsInPast = 4;
     $date = CRM_Core_SelectValues::date('custom', NULL, $yearsInPast, 0);
     $count = $date['maxYear'];
     $optionYear = array('' => ts('-- select --'));
     $this->_yearStatisticsFrom = $date['minYear'];
     $this->_yearStatisticsTo = $date['maxYear'];
     while ($date['minYear'] <= $count) {
         $optionYear[$date['minYear']] = $date['minYear'];
         $date['minYear']++;
     }
     $relationTypeOp = array();
     $relationshipTypes = CRM_Core_PseudoConstant::relationshipType();
     foreach ($relationshipTypes as $rid => $rtype) {
         if ($rtype['label_a_b'] != $rtype['label_b_a']) {
             $relationTypeOp[$rid] = "{$rtype['label_a_b']}/{$rtype['label_b_a']}";
         } else {
             $relationTypeOp[$rid] = $rtype['label_a_b'];
         }
     }
     $this->_columns = array('civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('sort_name' => array('title' => ts('Contact Name'), 'default' => TRUE, 'required' => TRUE, 'no_repeat' => TRUE), 'id' => array('no_display' => TRUE, 'default' => TRUE, 'required' => TRUE)), 'grouping' => 'contact-fields', 'filters' => array('sort_name' => array('title' => ts('Contact Name')), 'id' => array('title' => ts('Contact ID'), 'no_display' => TRUE))), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('email' => array('title' => ts('Email'), 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('phone' => array('title' => ts('Phone'), 'no_repeat' => TRUE)), 'grouping' => 'contact-fields')) + $this->addAddressFields(FALSE, FALSE, FALSE, array()) + array('civicrm_relationship' => array('dao' => 'CRM_Contact_DAO_Relationship', 'fields' => array('relationship_type_id' => array('title' => ts('Relationship Type'), 'default' => TRUE), 'contact_id_a' => array('no_display' => TRUE), 'contact_id_b' => array('no_display' => TRUE)), 'filters' => array('relationship_type_id' => array('title' => ts('Relationship Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $relationTypeOp, 'type' => CRM_Utils_Type::T_STRING)))) + array('civicrm_contribution' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'fields' => array('total_amount' => array('title' => ts('Amount Statistics'), 'default' => TRUE, 'required' => TRUE, 'no_display' => TRUE, 'statistics' => array('sum' => ts('Aggregate Amount'))), 'receive_date' => array('required' => TRUE, 'default' => TRUE, 'no_display' => TRUE)), 'grouping' => 'contri-fields', 'filters' => array('this_year' => array('title' => ts('This Year'), 'operatorType' => CRM_Report_Form::OP_SELECT, 'options' => $optionYear, 'default' => ''), 'other_year' => array('title' => ts('Other Years'), 'operatorType' => CRM_Report_Form::OP_SELECT, 'options' => $optionYear, 'default' => ''), 'receive_date' => array('operatorType' => CRM_Report_Form::OP_DATE), 'contribution_status_id' => array('title' => ts('Donation Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), 'default' => array(1)), 'contribution_type_id' => array('title' => ts('Contribution Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionType()), 'total_amount' => array('title' => ts('Donation Amount')), 'total_sum' => array('title' => ts('Aggregate Amount'), 'type' => CRM_Report_Form::OP_INT, 'dbAlias' => 'civicrm_contribution_total_amount_sum', 'having' => TRUE)))) + array('civicrm_group' => array('dao' => 'CRM_Contact_DAO_GroupContact', 'alias' => 'cgroup', 'filters' => array('gid' => array('name' => 'group_id', 'title' => ts('Group'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'group' => TRUE, 'options' => CRM_Core_PseudoConstant::group()))));
     $this->_columns['civicrm_contribution']['fields']['civicrm_upto_' . $this->_yearStatisticsFrom] = array('title' => ts('Up To %1 Donation', array(1 => $this->_yearStatisticsFrom)), 'default' => TRUE, 'type' => CRM_Utils_Type::T_MONEY, 'is_statistics' => TRUE);
     $yearConter = $this->_yearStatisticsFrom;
     $yearConter++;
     while ($yearConter <= $this->_yearStatisticsTo) {
         $this->_columns['civicrm_contribution']['fields'][$yearConter] = array('title' => ts('%1 Donation', array(1 => $yearConter)), 'default' => TRUE, 'type' => CRM_Utils_Type::T_MONEY, 'is_statistics' => TRUE);
         $yearConter++;
     }
     $this->_columns['civicrm_contribution']['fields']['aggregate_amount'] = array('title' => ts('Aggregate Amount'), 'type' => CRM_Utils_Type::T_MONEY, 'is_statistics' => TRUE);
     $this->_tagFilter = TRUE;
     parent::__construct();
 }
    function __construct()
    {
        $this->_columns = array('civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'grouping' => 'contact-fields', 'fields' => array('sort_name' => array('title' => ts('Contact Name'), 'no_repeat' => TRUE, 'default' => TRUE), 'id' => array('no_display' => TRUE, 'required' => TRUE)), 'filters' => array('percentage_change' => array('title' => ts('Percentage Change'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_INT, 'name' => 'percentage_change', 'dbAlias' => '( ( contribution_civireport2.total_amount_sum - contribution_civireport1.total_amount_sum ) * 100 / contribution_civireport1.total_amount_sum )')), 'group_bys' => array('id' => array('title' => ts('Contact'), 'default' => TRUE))), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('email' => array('title' => ts('Email'), 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('phone' => array('title' => ts('Phone'), 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_address' => array('dao' => 'CRM_Core_DAO_Address', 'grouping' => 'contact-fields', 'fields' => array('country_id' => array('title' => ts('Country')), 'state_province_id' => array('title' => ts('State/Province'))), 'group_bys' => array('country_id' => array('title' => ts('Country')), 'state_province_id' => array('title' => ts('State/Province')))), 'civicrm_contribution_type' => array('dao' => 'CRM_Contribute_DAO_ContributionType', 'fields' => array('contribution_type' => NULL), 'grouping' => 'contri-fields', 'group_bys' => array('contribution_type' => array('name' => 'id', 'title' => 'Contribution Type'))), 'civicrm_contribution' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'fields' => array('contribution_source' => NULL, 'total_amount1' => array('name' => 'total_amount', 'alias' => 'contribution1', 'title' => ts('Range One Stat'), 'type' => CRM_Utils_Type::T_MONEY, 'default' => TRUE, 'required' => TRUE, 'clause' => '
contribution_civireport1.total_amount_count as contribution1_total_amount_count, 
contribution_civireport1.total_amount_sum as contribution1_total_amount_sum'), 'total_amount2' => array('name' => 'total_amount', 'alias' => 'contribution2', 'title' => ts('Range Two Stat'), 'type' => CRM_Utils_Type::T_MONEY, 'default' => TRUE, 'required' => TRUE, 'clause' => '
contribution_civireport2.total_amount_count as contribution2_total_amount_count, 
contribution_civireport2.total_amount_sum as contribution2_total_amount_sum')), 'grouping' => 'contri-fields', 'filters' => array('receive_date1' => array('title' => ts('Date Range One'), 'default' => 'previous.year', 'type' => CRM_Utils_Type::T_DATE, 'operatorType' => CRM_Report_Form::OP_DATE, 'name' => 'receive_date'), 'receive_date2' => array('title' => ts('Date Range Two'), 'default' => 'this.year', 'type' => CRM_Utils_Type::T_DATE, 'operatorType' => CRM_Report_Form::OP_DATE, 'name' => 'receive_date'), 'total_amount1' => array('title' => ts('Range One Amount'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_INT, 'name' => 'total_amount'), 'total_amount2' => array('title' => ts('Range Two Amount'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_INT, 'name' => 'total_amount'), 'contribution_type_id' => array('title' => ts('Contribution Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionType()), 'contribution_status_id' => array('title' => ts('Contribution Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), 'default' => array('1'))), 'group_bys' => array('contribution_source' => NULL)), 'civicrm_group' => array('dao' => 'CRM_Contact_DAO_GroupContact', 'alias' => 'cgroup', 'filters' => array('gid' => array('name' => 'group_id', 'title' => ts('Group'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'group' => TRUE, 'options' => CRM_Core_PseudoConstant::group()))));
        $this->_tagFilter = TRUE;
        parent::__construct();
    }
 /**
  * Build the form
  *
  * @access public
  * @return void
  */
 public function buildQuickForm()
 {
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'title');
     $attributes['style'] = 'width: 90%';
     $this->add('text', 'title', ts('Find'), $attributes);
     $contribution_type = CRM_Contribute_PseudoConstant::contributionType();
     foreach ($contribution_type as $contributionId => $contributionName) {
         $this->addElement('checkbox', "contribution_type_id[{$contributionId}]", 'Contribution Type', $contributionName);
     }
     $this->addButtons(array(array('type' => 'refresh', 'name' => ts('Search'), 'isDefault' => true)));
 }
示例#5
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 function buildQuickForm()
 {
     $this->_first = true;
     // name
     $this->add('text', 'title', ts('Title'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'title'), true);
     $this->add('select', 'contribution_type_id', ts('Contribution Type'), CRM_Contribute_PseudoConstant::contributionType());
     // intro_text and footer_text
     $this->add('textarea', 'intro_text', ts('Introductory Message'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'intro_text'), true);
     $this->add('textarea', 'footer_text', ts('Footer Message'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'footer_text'), false);
     // is this group active ?
     $this->addElement('checkbox', 'is_active', ts('Is this Online Contribution Page Active?'));
     parent::buildQuickForm();
 }
 function __construct()
 {
     $yearsInPast = 10;
     $yearsInFuture = 1;
     $date = CRM_Core_SelectValues::date('custom', NULL, $yearsInPast, $yearsInFuture);
     $count = $date['maxYear'];
     while ($date['minYear'] <= $count) {
         $optionYear[$date['minYear']] = $date['minYear'];
         $date['minYear']++;
     }
     $this->_columns = array('civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'grouping' => 'contact-field', 'fields' => array('sort_name' => array('title' => ts('Donor Name'), 'required' => TRUE)), 'filters' => array('sort_name' => array('title' => ts('Donor Name'), 'operator' => 'like'))), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'grouping' => 'contact-field', 'fields' => array('email' => array('title' => ts('Email'), 'default' => TRUE))), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'grouping' => 'contact-field', 'fields' => array('phone' => array('title' => ts('Phone No'), 'default' => TRUE))), 'civicrm_contribution' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'fields' => array('contact_id' => array('title' => ts('contactId'), 'no_display' => TRUE, 'required' => TRUE, 'no_repeat' => TRUE), 'total_amount' => array('title' => ts('Total Amount'), 'no_display' => TRUE, 'required' => TRUE, 'no_repeat' => TRUE), 'receive_date' => array('title' => ts('Year'), 'no_display' => TRUE, 'required' => TRUE, 'no_repeat' => TRUE)), 'filters' => array('yid' => array('name' => 'receive_date', 'title' => ts('This Year'), 'operatorType' => CRM_Report_Form::OP_SELECT, 'options' => $optionYear, 'default' => date('Y')), 'contribution_type_id' => array('title' => ts('Contribution Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionType()), 'contribution_status_id' => array('title' => ts('Contribution Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), 'default' => array('1')))), 'civicrm_group' => array('dao' => 'CRM_Contact_DAO_GroupContact', 'alias' => 'cgroup', 'filters' => array('gid' => array('name' => 'group_id', 'title' => ts('Group'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'group' => TRUE, 'options' => CRM_Core_PseudoConstant::group()))));
     $this->_tagFilter = TRUE;
     parent::__construct();
 }
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 public function preProcess()
 {
     $values = $ids = array();
     $params = array('id' => $this->get('id'));
     CRM_Pledge_BAO_Pledge::getValues($params, $values, $ids);
     $values['frequencyUnit'] = ts('%1(s)', array(1 => $values['frequency_unit']));
     if (isset($values["honor_contact_id"]) && $values["honor_contact_id"]) {
         $sql = "SELECT display_name FROM civicrm_contact WHERE id = " . $values["honor_contact_id"];
         $dao = new CRM_Core_DAO();
         $dao->query($sql);
         if ($dao->fetch()) {
             $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$values['honor_contact_id']}");
             $values["honor_display"] = "<A href = {$url}>" . $dao->display_name . "</A>";
         }
         $honor = CRM_Core_PseudoConstant::honor();
         $values['honor_type'] = $honor[$values['honor_type_id']];
     }
     //handle custom data.
     $groupTree = CRM_Core_BAO_CustomGroup::getTree('Pledge', $this, $params['id']);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     if (CRM_Utils_Array::value('contribution_page_id', $values)) {
         $values['contribution_page'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $values['contribution_page_id'], 'title');
     }
     $values['contribution_type'] = CRM_Utils_Array::value($values['contribution_type_id'], CRM_Contribute_PseudoConstant::contributionType());
     if ($values['status_id']) {
         $values['pledge_status'] = CRM_Utils_Array::value($values['status_id'], CRM_Contribute_PseudoConstant::contributionStatus());
     }
     $url = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     $recentOther = array();
     if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::UPDATE)) {
         $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     }
     if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::DELETE)) {
         $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     }
     $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']);
     $this->assign('displayName', $displayName);
     $title = $displayName . ' - (' . ts('Pledged') . ' ' . CRM_Utils_Money::format($values['pledge_amount']) . ' - ' . $values['contribution_type'] . ')';
     // add Pledge to Recent Items
     CRM_Utils_Recent::add($title, $url, $values['id'], 'Pledge', $values['contact_id'], NULL, $recentOther);
     //do check for campaigns
     if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) {
         $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
         $values['campaign'] = $campaigns[$campaignId];
     }
     $this->assign($values);
 }
 function buildQuickForm()
 {
     $this->addElement('hidden', 'batch_status', true);
     $this->addElement('hidden', 'id', $_GET['id']);
     $this->add('text', 'batch_title', ts('Batch Title'), array('size' => 35, 'maxlength' => 64, 'style' => 'text-align:right'), true);
     $this->add('textarea', 'description', ts('Description'), null, false);
     $emptySelect1[''] = '- select -';
     $bankAccounts = $bankAccounts = CRM_Finance_BAO_BankAccount::getBankAccountsList($emptySelect1);
     $this->add('select', 'banking_account', ts('Bank Account'), $bankAccounts, true);
     $this->addDate('banking_date', ts('Banking Date'), true, array('formatType' => 'activityDate'));
     $this->addElement('checkbox', 'exclude_from_posting', ts('Exclude from posting'), null, null);
     $this->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType(), true);
     $this->add('select', 'payment_instrument_id', ts('Payment Method'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), true);
     $this->addFormRule(array($this, 'formRule'));
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->assign('formObject', $this);
 }
 function __construct()
 {
     $config = CRM_Core_Config::singleton();
     $campaignEnabled = in_array("CiviCampaign", $config->enableComponents);
     if ($campaignEnabled) {
         $getCampaigns = CRM_Campaign_BAO_Campaign::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
         $this->activeCampaigns = $getCampaigns['campaigns'];
         asort($this->activeCampaigns);
     }
     $this->_columns = array('civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('sort_name' => array('title' => ts('Contact Name'), 'no_repeat' => TRUE), 'postal_greeting_display' => array('title' => ts('Postal Greeting')), 'id' => array('no_display' => TRUE, 'required' => TRUE)), 'grouping' => 'contact-fields', 'group_bys' => array('id' => array('title' => ts('Contact ID')), 'sort_name' => array('title' => ts('Contact Name')))), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('email' => array('title' => ts('Email'), 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('phone' => array('title' => ts('Phone'), 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_contribution_type' => array('dao' => 'CRM_Contribute_DAO_ContributionType', 'fields' => array('contribution_type' => NULL), 'grouping' => 'contri-fields', 'group_bys' => array('contribution_type' => NULL)), 'civicrm_contribution' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'fields' => array('contribution_source' => NULL, 'total_amount' => array('title' => ts('Amount Statistics'), 'default' => TRUE, 'required' => TRUE, 'statistics' => array('sum' => ts('Aggregate Amount'), 'count' => ts('Donations'), 'avg' => ts('Average')))), 'grouping' => 'contri-fields', 'filters' => array('receive_date' => array('operatorType' => CRM_Report_Form::OP_DATE), 'contribution_status_id' => array('title' => ts('Donation Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), 'default' => array(1), 'type' => CRM_Utils_Type::T_INT), 'contribution_type_id' => array('title' => ts('Contribution Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionType(), 'type' => CRM_Utils_Type::T_INT), 'total_amount' => array('title' => ts('Donation Amount')), 'total_sum' => array('title' => ts('Aggregate Amount'), 'type' => CRM_Report_Form::OP_INT, 'dbAlias' => 'civicrm_contribution_total_amount_sum', 'having' => TRUE), 'total_count' => array('title' => ts('Donation Count'), 'type' => CRM_Report_Form::OP_INT, 'dbAlias' => 'civicrm_contribution_total_amount_count', 'having' => TRUE), 'total_avg' => array('title' => ts('Average'), 'type' => CRM_Report_Form::OP_INT, 'dbAlias' => 'civicrm_contribution_total_amount_avg', 'having' => TRUE)), 'group_bys' => array('receive_date' => array('frequency' => TRUE, 'default' => TRUE, 'chart' => TRUE), 'contribution_source' => NULL)), 'civicrm_group' => array('dao' => 'CRM_Contact_DAO_GroupContact', 'alias' => 'cgroup', 'filters' => array('gid' => array('name' => 'group_id', 'title' => ts('Group'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'group' => TRUE, 'options' => CRM_Core_PseudoConstant::group(), 'type' => CRM_Utils_Type::T_INT)))) + $this->addAddressFields();
     $this->_tagFilter = TRUE;
     if ($campaignEnabled && !empty($this->activeCampaigns)) {
         $this->_columns['civicrm_contribution']['fields']['campaign_id'] = array('title' => 'Campaign', 'default' => 'false');
         $this->_columns['civicrm_contribution']['filters']['campaign_id'] = array('title' => ts('Campaign'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->activeCampaigns);
         $this->_columns['civicrm_contribution']['grouping']['campaign_id'] = 'contri-fields';
         $this->_columns['civicrm_contribution']['group_bys']['campaign_id'] = array('title' => ts('Campaign'));
     }
     parent::__construct();
 }
示例#10
0
 /**  
  * Function to set variables up before form is built  
  *                                                            
  * @return void  
  * @access public  
  */
 public function preProcess()
 {
     require_once 'CRM/Pledge/BAO/Pledge.php';
     $values = $ids = array();
     $params = array('id' => $this->get('id'));
     CRM_Pledge_BAO_Pledge::getValues($params, $values, $ids);
     $values['frequencyUnit'] = ts('%1(s)', array(1 => $values['frequency_unit']));
     $values['eachPaymentAmount'] = floor($values['amount'] / $values['installments']);
     if (isset($values["honor_contact_id"]) && $values["honor_contact_id"]) {
         $sql = "SELECT display_name FROM civicrm_contact WHERE id = " . $values["honor_contact_id"];
         $dao =& new CRM_Core_DAO();
         $dao->query($sql);
         if ($dao->fetch()) {
             $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$values['honor_contact_id']}");
             $values["honor_display"] = "<A href = {$url}>" . $dao->display_name . "</A>";
         }
         $honor = CRM_Core_PseudoConstant::honor();
         $values['honor_type'] = $honor[$values['honor_type_id']];
     }
     //handle custom data.
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Pledge', $this, $params['id']);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     if (CRM_Utils_Array::value('contribution_page_id', $values)) {
         $values['contribution_page'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $values['contribution_page_id'], 'title');
     }
     $values['contribution_type'] = CRM_Utils_Array::value($values['contribution_type_id'], CRM_Contribute_PseudoConstant::contributionType());
     if ($values['status_id']) {
         $values['pledge_status'] = CRM_Utils_Array::value($values['status_id'], CRM_Contribute_PseudoConstant::contributionStatus());
     }
     require_once 'CRM/Utils/Recent.php';
     require_once 'CRM/Contact/BAO/Contact.php';
     $url = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     require_once 'CRM/Utils/Money.php';
     $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']);
     $this->assign('displayName', $displayName);
     $title = $displayName . ' - (' . ts('Pledged') . ' ' . CRM_Utils_Money::format($values['pledge_amount']) . ' - ' . $values['contribution_type'] . ')';
     // add Pledge to Recent Items
     CRM_Utils_Recent::add($title, $url, $values['id'], 'Pledge', $values['contact_id'], null);
     $this->assign($values);
 }
示例#11
0
 /**
  * takes an associative array and creates a pledge object
  *
  * @param array $params (reference ) an assoc array of name/value pairs
  *
  * @return object CRM_Pledge_BAO_Pledge object 
  * @access public
  * @static
  */
 static function &create(&$params)
 {
     require_once 'CRM/Utils/Date.php';
     //FIXME: a cludgy hack to fix the dates to MySQL format
     $dateFields = array('start_date', 'create_date', 'acknowledge_date', 'modified_date', 'cancel_date', 'end_date');
     foreach ($dateFields as $df) {
         if (isset($params[$df])) {
             $params[$df] = CRM_Utils_Date::isoToMysql($params[$df]);
         }
     }
     require_once 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     $paymentParams = array();
     $paymentParams['status_id'] = $params['status_id'];
     if (CRM_Utils_Array::value('installment_amount', $params)) {
         $params['amount'] = $params['installment_amount'] * $params['installments'];
     }
     //get All Payments status types.
     require_once 'CRM/Contribute/PseudoConstant.php';
     $paymentStatusTypes = CRM_Contribute_PseudoConstant::contributionStatus(null, 'name');
     //update the pledge status only if it does NOT come from form
     if (!isset($params['pledge_status_id'])) {
         if (isset($params['contribution_id'])) {
             if ($params['installments'] > 1) {
                 $params['status_id'] = array_search('In Progress', $paymentStatusTypes);
             }
         } else {
             $params['status_id'] = array_search('Pending', $paymentStatusTypes);
         }
     }
     $pledge = self::add($params);
     if (is_a($pledge, 'CRM_Core_Error')) {
         $pledge->rollback();
         return $pledge;
     }
     //handle custom data.
     if (CRM_Utils_Array::value('custom', $params) && is_array($params['custom'])) {
         require_once 'CRM/Core/BAO/CustomValueTable.php';
         CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_pledge', $pledge->id);
     }
     // skip payment stuff inedit mode
     if (!isset($params['id']) || CRM_Utils_Array::value('is_pledge_pending', $params)) {
         require_once 'CRM/Pledge/BAO/Payment.php';
         //if pledge is pending delete all payments and recreate.
         if (CRM_Utils_Array::value('is_pledge_pending', $params)) {
             CRM_Pledge_BAO_Payment::deletePayments($pledge->id);
         }
         //building payment params
         $paymentParams['pledge_id'] = $pledge->id;
         $paymentKeys = array('amount', 'installments', 'scheduled_date', 'frequency_unit', 'frequency_day', 'frequency_interval', 'contribution_id', 'installment_amount', 'actual_amount');
         foreach ($paymentKeys as $key) {
             $paymentParams[$key] = CRM_Utils_Array::value($key, $params, null);
         }
         CRM_Pledge_BAO_Payment::create($paymentParams);
     }
     $transaction->commit();
     require_once 'CRM/Utils/Recent.php';
     require_once 'CRM/Contribute/PseudoConstant.php';
     require_once 'CRM/Contact/BAO/Contact.php';
     require_once 'CRM/Core/Config.php';
     $url = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=view&reset=1&id={$pledge->id}&cid={$pledge->contact_id}&context=home");
     $recentOther = array();
     if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::UPDATE)) {
         $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=update&reset=1&id={$pledge->id}&cid={$pledge->contact_id}&context=home");
     }
     if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::DELETE)) {
         $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=delete&reset=1&id={$pledge->id}&cid={$pledge->contact_id}&context=home");
     }
     $config = CRM_Core_Config::singleton();
     require_once 'CRM/Utils/Money.php';
     $contributionTypes = CRM_Contribute_PseudoConstant::contributionType();
     $title = CRM_Contact_BAO_Contact::displayName($pledge->contact_id) . ' - (' . ts('Pledged') . ' ' . CRM_Utils_Money::format($pledge->amount) . ' - ' . $contributionTypes[$pledge->contribution_type_id] . ')';
     // add the recently created Pledge
     CRM_Utils_Recent::add($title, $url, $pledge->id, 'Pledge', $pledge->contact_id, null, $recentOther);
     return $pledge;
 }
示例#12
0
 /** 
  * Function to build the form 
  * 
  * @return None 
  * @access public 
  */
 function buildQuickForm()
 {
     $this->applyFilter('__ALL__', 'trim');
     if ($this->_action & CRM_CORE_ACTION_DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     $this->buldPremiumForm($this);
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution');
     $element =& $this->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('-select-')) + CRM_Contribute_PseudoConstant::contributionType(), true);
     if ($this->_online) {
         $element->freeze();
     }
     $element =& $this->add('select', 'payment_instrument_id', ts('Paid By'), array('' => ts('-select-')) + CRM_Contribute_PseudoConstant::paymentInstrument());
     if ($this->_online) {
         $element->freeze();
     }
     // add various dates
     $element =& $this->add('date', 'receive_date', ts('Received'), CRM_Core_SelectValues::date('manual', 3, 1), false);
     $this->addRule('receive_date', ts('Select a valid date.'), 'qfDate');
     if ($this->_online) {
         $this->assign("hideCalender", true);
         $element->freeze();
     }
     $this->addElement('date', 'receipt_date', ts('Receipt Sent'), CRM_Core_SelectValues::date('manual', 3, 1));
     $this->addRule('receipt_date', ts('Select a valid date.'), 'qfDate');
     $this->addElement('date', 'thankyou_date', ts('Thank-you Sent'), CRM_Core_SelectValues::date('manual', 3, 1));
     $this->addRule('thankyou_date', ts('Select a valid date.'), 'qfDate');
     $this->addElement('date', 'cancel_date', ts('Cancelled'), CRM_Core_SelectValues::date('manual', 3, 1));
     $this->addRule('cancel_date', ts('Select a valid date.'), 'qfDate');
     $this->add('textarea', 'cancel_reason', ts('Cancellation Reason'), $attributes['cancel_reason']);
     // add various amounts
     $element =& $this->add('text', 'non_deductible_amount', ts('Non-deductible Amount'), $attributes['non_deductible_amount']);
     $this->addRule('non_deductible_amount', ts('Please enter a valid amount.'), 'money');
     if ($this->_online) {
         $element->freeze();
     }
     $element =& $this->add('text', 'total_amount', ts('Total Amount'), $attributes['total_amount'], true);
     $this->addRule('total_amount', ts('Please enter a valid amount.'), 'money');
     if ($this->_online) {
         $element->freeze();
     }
     $element =& $this->add('text', 'fee_amount', ts('Fee Amount'), $attributes['fee_amount']);
     $this->addRule('fee_amount', ts('Please enter a valid amount.'), 'money');
     if ($this->_online) {
         $element->freeze();
     }
     $element =& $this->add('text', 'net_amount', ts('Net Amount'), $attributes['net_amount']);
     $this->addRule('net_amount', ts('Please enter a valid amount.'), 'money');
     if ($this->_online) {
         $element->freeze();
     }
     $element =& $this->add('text', 'trxn_id', ts('Transaction ID'), $attributes['trxn_id']);
     if ($this->_online) {
         $element->freeze();
     }
     $element =& $this->add('text', 'invoice_id', ts('Invoice ID'), $attributes['invoice_id']);
     if ($this->_online) {
         $element->freeze();
     }
     $element =& $this->add('text', 'source', ts('Source'), $attributes['source']);
     if ($this->_online) {
         $element->freeze();
     }
     $this->add('textarea', 'note', ts('Notes'), array("rows" => 4, "cols" => 60));
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->addFormRule(array('CRM_Contribute_Form_Contribution', 'formRule'), $this);
     if ($this->_action & CRM_CORE_ACTION_VIEW) {
         $this->freeze();
     }
 }
示例#13
0
 function contribution()
 {
     $config =& CRM_Core_Config::singleton();
     if (!in_array('CiviContribute', $config->enableComponents)) {
         return;
     }
     // process to / from date
     $this->dateQueryBuilder('civicrm_contribution', 'contribution_date', 'receive_date', 'Contribution Date');
     $qill = array();
     if (isset($this->_params['contribution_date_from'])) {
         $revDate = array_reverse($this->_params['contribution_date_from']);
         $date = CRM_Utils_Date::format($revDate);
         $format = CRM_Utils_Date::customFormat(CRM_Utils_Date::format($revDate, '-'));
         if ($date) {
             $this->_where[] = "civicrm_contribution.receive_date >= '{$date}'";
             $this->_tables['civicrm_contribution'] = $this->_whereTables['civicrm_contribution'] = 1;
             $qill[] = ts('greater than "%1"', array(1 => $format));
         }
     }
     if (isset($this->_params['contribution_date_to'])) {
         $revDate = array_reverse($this->_params['contribution_date_to']);
         $date = CRM_Utils_Date::format($revDate);
         $format = CRM_Utils_Date::customFormat(CRM_Utils_Date::format($revDate, '-'));
         if ($date) {
             $this->_where[] = " ( civicrm_contribution.receive_date <= '{$date}' ) ";
             $this->_tables['civicrm_contribution'] = $this->_whereTables['civicrm_contribution'] = 1;
             $qill[] = ts('less than "%1"', array(1 => $format));
         }
     }
     if (!empty($qill)) {
         $this->_qill[] = ts('Contribution Date - %1', array(1 => implode(' ' . ts('and') . ' ', $qill)));
     }
     // process min/max amount
     $qill = array();
     if (isset($this->_params['contribution_min_amount'])) {
         $amount = $this->_params['contribution_min_amount'];
         if ($amount > 0) {
             $this->_where[] = "civicrm_contribution.total_amount >= {$amount}";
             $this->_tables['civicrm_contribution'] = $this->_whereTables['civicrm_contribution'] = 1;
             $qill[] = ts('greater than "%1"', array(1 => $amount));
         }
     }
     if (isset($this->_params['contribution_max_amount'])) {
         $amount = $this->_params['contribution_max_amount'];
         if ($amount > 0) {
             $this->_where[] = "civicrm_contribution.total_amount <= {$amount}";
             $this->_tables['civicrm_contribution'] = $this->_whereTables['civicrm_contribution'] = 1;
             $qill[] = ts('less than "%1"', array(1 => $amount));
         }
     }
     if (!empty($qill)) {
         $this->_qill[] = ts('Contribution Amount - %1', array(1 => implode(' ' . ts('and') . ' ', $qill)));
     }
     if (CRM_Utils_Array::value('contribution_thankyou_date_isnull', $this->_params)) {
         $this->_where[] = "civicrm_contribution.thankyou_date is null";
         $this->_tables['civicrm_contribution'] = $this->_whereTables['civicrm_contribution'] = 1;
         $this->_qill[] = ts('Contribution Thank-you date is null');
     }
     if (CRM_Utils_Array::value('contribution_receipt_date_isnull', $this->_params)) {
         $this->_where[] = "civicrm_contribution.receipt_date is null";
         $this->_tables['civicrm_contribution'] = $this->_whereTables['civicrm_contribution'] = 1;
         $this->_qill[] = ts('Contribution Receipt date is null');
     }
     if (CRM_Utils_Array::value('contribution_type_id', $this->_params)) {
         require_once 'CRM/Contribute/PseudoConstant.php';
         $cType = $this->_params['contribution_type_id'];
         $types = CRM_Contribute_PseudoConstant::contributionType();
         $this->_where[] = "civicrm_contribution.contribution_type_id = {$cType}";
         $this->_tables['civicrm_contribution'] = $this->_whereTables['civicrm_contribution'] = 1;
         $this->_qill[] = ts('Contribution Type - %1', array(1 => $types[$cType]));
     }
     if (CRM_Utils_Array::value('payment_instrument_id', $this->_params)) {
         require_once 'CRM/Contribute/PseudoConstant.php';
         $pi = $this->_params['payment_instrument_id'];
         $pis = CRM_Contribute_PseudoConstant::paymentInstrument();
         $this->_where[] = "civicrm_contribution.payment_instrument_id = {$pi}";
         $this->_tables['civicrm_contribution'] = $this->_whereTables['civicrm_contribution'] = 1;
         $this->_qill[] = ts('Paid By - %1', array(1 => $pis[$pi]));
     }
     if (isset($this->_params['contribution_status'])) {
         switch ($this->_params['contribution_status']) {
             case 'Valid':
                 $this->_where[] = "civicrm_contribution.cancel_date is null";
                 $this->_tables['civicrm_contribution'] = $this->_whereTables['civicrm_contribution'] = 1;
                 $this->_qill[] = ts('Contribution Status - Valid');
                 break;
             case 'Cancelled':
                 $this->_where[] = "civicrm_contribution.cancel_date is not null";
                 $this->_tables['civicrm_contribution'] = $this->_whereTables['civicrm_contribution'] = 1;
                 $this->_qill[] = ts('Contribution Status - Cancelled');
                 break;
         }
     }
 }
示例#14
0
 /**
  * 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);
             }
         }
     }
 }
示例#15
0
 /**
  * Function to build profile form
  *
  * @params object  $form       form object
  * @params array   $field      array field properties
  * @params int     $mode       profile mode
  * @params int     $contactID  contact id
  *
  * @return null
  * @static
  * @access public
  */
 static function buildProfile(&$form, &$field, $mode, $contactId = null, $online = false)
 {
     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);
         }
     }
 }
示例#16
0
 function __construct()
 {
     $this->_columns = array('civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('display_name_creditor' => array('title' => ts('Soft Credit Name'), 'name' => 'display_name', 'alias' => 'contact_civireport', 'required' => true, 'no_repeat' => true), 'id_creditor' => array('title' => ts('Soft Credit Id'), 'name' => 'id', 'alias' => 'contact_civireport', 'no_display' => true, 'required' => true), 'display_name_constituent' => array('title' => ts('Contributor Name'), 'name' => 'display_name', 'alias' => 'constituentname', 'required' => true), 'id_constituent' => array('title' => ts('Const Id'), 'name' => 'id', 'alias' => 'constituentname', 'no_display' => true, 'required' => true)), 'grouping' => 'contact-fields'), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('email_creditor' => array('title' => ts('Soft Credit Email'), 'name' => 'email', 'alias' => 'emailcredit', 'default' => true, 'no_repeat' => true), 'email_constituent' => array('title' => ts('Contributor\'s Email'), 'name' => 'email', 'alias' => 'emailconst')), 'grouping' => 'contact-fields'), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('phone_creditor' => array('title' => ts('Soft Credit Phone'), 'name' => 'phone', 'alias' => 'pcredit', 'default' => true), 'phone_constituent' => array('title' => ts('Contributor\'s Phone'), 'name' => 'phone', 'alias' => 'pconst', 'no_repeat' => true)), 'grouping' => 'contact-fields'), 'civicrm_contribution_type' => array('dao' => 'CRM_Contribute_DAO_ContributionType', 'fields' => array('contribution_type' => null), 'filters' => array('id' => array('name' => 'id', 'title' => ts('Contribution Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionType())), 'grouping' => 'softcredit-fields'), 'civicrm_contribution' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'fields' => array('contribution_source' => null, 'total_amount' => array('title' => ts('Amount Statistics'), 'default' => true, 'statistics' => array('sum' => ts('Aggregate Amount'), 'count' => ts('Donations'), 'avg' => ts('Average')))), 'grouping' => 'softcredit-fields', 'filters' => array('receive_date' => array('operatorType' => CRM_Report_Form::OP_DATE), 'contribution_status_id' => array('title' => ts('Donation Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), 'default' => array(1)), 'total_amount' => array('title' => ts('Donation Amount')))), 'civicrm_contribution_soft' => array('dao' => 'CRM_Contribute_DAO_ContributionSoft', 'fields' => array('contribution_id' => array('title' => ts('Contribution ID'), 'no_display' => true, 'default' => true), 'id' => array('default' => true, 'no_display' => true)), 'grouping' => 'softcredit-fields'), 'civicrm_group' => array('dao' => 'CRM_Contact_DAO_GroupContact', 'alias' => 'cgroup', 'filters' => array('gid' => array('name' => 'group_id', 'title' => ts('Soft Credit Group'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'group' => true, 'options' => CRM_Core_PseudoConstant::group()))));
     parent::__construct();
 }
 /**
  * Browse all custom data groups.
  *
  * @param string $action   the action to be invoked
  *
  * @return void
  * @access public
  */
 function browse($action = NULL)
 {
     // get all custom groups sorted by weight
     $customGroup = array();
     $dao = new CRM_Core_DAO_CustomGroup();
     $dao->orderBy('weight, title');
     $dao->find();
     while ($dao->fetch()) {
         $customGroup[$dao->id] = array();
         CRM_Core_DAO::storeValues($dao, $customGroup[$dao->id]);
         // form all action links
         $action = array_sum(array_keys($this->actionLinks()));
         // update enable/disable links depending on custom_group properties.
         if ($dao->is_active) {
             $action -= CRM_Core_Action::ENABLE;
         } else {
             $action -= CRM_Core_Action::DISABLE;
         }
         $customGroup[$dao->id]['order'] = $customGroup[$dao->id]['weight'];
         $customGroup[$dao->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $dao->id));
     }
     $customGroupExtends = CRM_Core_SelectValues::customGroupExtends();
     foreach ($customGroup as $key => $array) {
         CRM_Core_DAO_CustomGroup::addDisplayEnums($customGroup[$key]);
         $customGroup[$key]['extends_display'] = $customGroupExtends[$customGroup[$key]['extends']];
     }
     //fix for Displaying subTypes
     $subTypes = array();
     $subTypes['Activity'] = CRM_Core_PseudoConstant::activityType(FALSE, TRUE, FALSE, 'label', TRUE);
     $subTypes['Contribution'] = CRM_Contribute_PseudoConstant::contributionType();
     $subTypes['Membership'] = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE);
     $subTypes['Event'] = CRM_Core_OptionGroup::values('event_type');
     $subTypes['Grant'] = CRM_Core_OptionGroup::values('grant_type');
     $subTypes['Campaign'] = CRM_Campaign_PseudoConstant::campaignType();
     $subTypes['Participant'] = array();
     $subTypes['ParticipantRole'] = CRM_Core_OptionGroup::values('participant_role');
     $subTypes['ParticipantEventName'] = CRM_Event_PseudoConstant::event();
     $subTypes['ParticipantEventType'] = CRM_Core_OptionGroup::values('event_type');
     $subTypes['Individual'] = CRM_Contact_BAO_ContactType::subTypePairs('Individual', FALSE, NULL);
     $subTypes['Household'] = CRM_Contact_BAO_ContactType::subTypePairs('Household', FALSE, NULL);
     $subTypes['Organization'] = CRM_Contact_BAO_ContactType::subTypePairs('Organization', FALSE, NULL);
     $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Individual');
     $relTypeOrg = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Organization');
     $relTypeHou = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Household');
     $allRelationshipType = array();
     $allRelationshipType = array_merge($relTypeInd, $relTypeOrg);
     $allRelationshipType = array_merge($allRelationshipType, $relTypeHou);
     //adding subtype specific relationships CRM-5256
     $relSubType = CRM_Contact_BAO_ContactType::subTypeInfo();
     foreach ($relSubType as $subType => $val) {
         $subTypeRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $val['parent'], FALSE, 'label', TRUE, $subType);
         $allRelationshipType = array_merge($allRelationshipType, $subTypeRelationshipTypes);
     }
     $subTypes['Relationship'] = $allRelationshipType;
     $cSubTypes = CRM_Core_Component::contactSubTypes();
     $contactSubTypes = array();
     foreach ($cSubTypes as $key => $value) {
         $contactSubTypes[$key] = $key;
     }
     $subTypes['Contact'] = $contactSubTypes;
     CRM_Core_BAO_CustomGroup::getExtendedObjectTypes($subTypes);
     foreach ($customGroup as $key => $values) {
         $subValue = CRM_Utils_Array::value('extends_entity_column_value', $customGroup[$key]);
         $subName = CRM_Utils_Array::value('extends_entity_column_id', $customGroup[$key]);
         $type = CRM_Utils_Array::value('extends', $customGroup[$key]);
         if ($subValue) {
             $subValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($subValue, 1, -1));
             $colValue = NULL;
             foreach ($subValue as $sub) {
                 if ($sub) {
                     if ($type == 'Participant') {
                         if ($subName == 1) {
                             $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantRole'][$sub] : $subTypes['ParticipantRole'][$sub];
                         } elseif ($subName == 2) {
                             $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantEventName'][$sub] : $subTypes['ParticipantEventName'][$sub];
                         } elseif ($subName == 3) {
                             $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantEventType'][$sub] : $subTypes['ParticipantEventType'][$sub];
                         }
                     } elseif ($type == 'Relationship') {
                         $colValue = $colValue ? $colValue . ', ' . $subTypes[$type][$sub . '_a_b'] : $subTypes[$type][$sub . '_a_b'];
                         if (isset($subTypes[$type][$sub . '_b_a'])) {
                             $colValue = $colValue ? $colValue . ', ' . $subTypes[$type][$sub . '_b_a'] : $subTypes[$type][$sub . '_b_a'];
                         }
                     } else {
                         $colValue = $colValue ? $colValue . (isset($subTypes[$type][$sub]) ? ', ' . $subTypes[$type][$sub] : '') : (isset($subTypes[$type][$sub]) ? $subTypes[$type][$sub] : '');
                     }
                 }
             }
             $customGroup[$key]["extends_entity_column_value"] = $colValue;
         } else {
             if (is_array(CRM_Utils_Array::value($type, $subTypes))) {
                 $customGroup[$key]["extends_entity_column_value"] = ts("Any");
             }
         }
     }
     $returnURL = CRM_Utils_System::url('civicrm/admin/custom/group', "reset=1&action=browse");
     CRM_Utils_Weight::addOrder($customGroup, 'CRM_Core_DAO_CustomGroup', 'id', $returnURL);
     $this->assign('rows', $customGroup);
 }
示例#18
0
文件: Field.php 项目: bhirsch/voipdev
 function validate()
 {
     if (CRM_Utils_System::isNull($this->_value)) {
         return true;
     }
     switch ($this->_name) {
         case 'contact_id':
             // note: we validate extistence of the contact in API, upon
             // insert (it would be too costlty to do a db call here)
             return CRM_Utils_Rule::integer($this->_value);
             break;
         case 'receive_date':
         case 'cancel_date':
         case 'receipt_date':
         case 'thankyou_date':
             return CRM_Utils_Rule::date($this->_value);
             break;
         case 'non_deductible_amount':
         case 'total_amount':
         case 'fee_amount':
         case 'net_amount':
             return CRM_Utils_Rule::money($this->_value);
             break;
         case 'trxn_id':
             static $seenTrxnIds = array();
             if (in_array($this->_value, $seenTrxnIds)) {
                 return false;
             } elseif ($this->_value) {
                 $seenTrxnIds[] = $this->_value;
                 return true;
             } else {
                 $this->_value = null;
                 return true;
             }
             break;
         case 'currency':
             return CRM_Utils_Rule::currencyCode($this->_value);
             break;
         case 'contribution_type':
             static $contributionTypes = null;
             if (!$contributionTypes) {
                 $contributionTypes =& CRM_Contribute_PseudoConstant::contributionType();
             }
             if (in_array($this->_value, $contributionTypes)) {
                 return true;
             } else {
                 return false;
             }
             break;
         case 'payment_instrument':
             static $paymentInstruments = null;
             if (!$paymentInstruments) {
                 $paymentInstruments =& CRM_Contribute_PseudoConstant::paymentInstrument();
             }
             if (in_array($this->_value, $paymentInstruments)) {
                 return true;
             } else {
                 return false;
             }
             break;
         default:
             break;
     }
     // check whether that's a valid custom field id
     // and if so, check the contents' validity
     if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($this->_name)) {
         static $customFields = null;
         if (!$customFields) {
             $customFields =& CRM_Core_BAO_CustomField::getFields('Contribution');
         }
         if (!array_key_exists($customFieldID, $customFields)) {
             return false;
         }
         return CRM_Core_BAO_CustomValue::typecheck($customFields[$customFieldID]['data_type'], $this->_value);
     }
     return true;
 }
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     $this->add('text', 'name', ts('Name'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'name'), TRUE);
     $this->addRule('name', ts('A membership type with this name already exists. Please select another name.'), 'objectExists', array('CRM_Member_DAO_MembershipType', $this->_id));
     $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'description'));
     $this->add('text', 'minimum_fee', ts('Minimum Fee'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'minimum_fee'));
     $this->addRule('minimum_fee', ts('Please enter a monetary value for the Minimum Fee.'), 'money');
     $this->addElement('select', 'duration_unit', ts('Duration') . ' ', CRM_Core_SelectValues::unitList('duration'), array('onchange' => 'showHidePeriodSettings()'));
     //period type
     $this->addElement('select', 'period_type', ts('Period Type'), CRM_Core_SelectValues::periodType(), array('onchange' => 'showHidePeriodSettings()'));
     $this->add('text', 'duration_interval', ts('Duration Interval'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'duration_interval'));
     $memberOrg =& $this->add('text', 'member_org', ts('Membership Organization'), 'size=30 maxlength=120');
     //start day
     $this->add('date', 'fixed_period_start_day', ts('Fixed Period Start Day'), CRM_Core_SelectValues::date(NULL, 'M d'), FALSE);
     $msgTemplates = CRM_Core_BAO_MessageTemplates::getMessageTemplates(FALSE);
     $hasMsgTemplates = FALSE;
     if (!empty($msgTemplates)) {
         $hasMsgTemplates = TRUE;
     }
     //Auto-renew Option
     $paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'is_recur = 1');
     $isAuthorize = FALSE;
     $options = array();
     $allowAutoRenewMsg = FALSE;
     if (is_array($paymentProcessor) && !empty($paymentProcessor)) {
         $isAuthorize = TRUE;
         $options = array(ts('No auto-renew option'), ts('Give option, but not required'), ts('Auto-renew required '));
         if ($hasMsgTemplates) {
             $allowAutoRenewMsg = TRUE;
             $autoRenewReminderMsg = $this->add('select', 'autorenewal_msg_id', ts('Auto-renew Reminder Message'), array('' => ts('- select -')) + $msgTemplates);
         }
     }
     $this->addRadio('auto_renew', ts('Auto-renew Option'), $options, array('onclick' => "setReminder(this.value);"));
     $this->assign('authorize', $isAuthorize);
     $this->assign('allowAutoRenewMsg', $allowAutoRenewMsg);
     //rollover day
     $this->add('date', 'fixed_period_rollover_day', ts('Fixed Period Rollover Day'), CRM_Core_SelectValues::date(NULL, 'M d'), FALSE);
     // required in form rule
     $this->add('hidden', 'action', $this->_action);
     $this->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType());
     $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, NULL, TRUE);
     if (is_array($relTypeInd)) {
         asort($relTypeInd);
     }
     $memberRel =& $this->add('select', 'relationship_type_id', ts('Relationship Type'), array('' => ts('- select -')) + $relTypeInd);
     $memberRel->setMultiple(TRUE);
     $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::memberVisibility());
     $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'weight'));
     $this->add('checkbox', 'is_active', ts('Enabled?'));
     if ($hasMsgTemplates) {
         $reminderMsg = $this->add('select', 'renewal_msg_id', ts('Renewal Reminder Message'), array('' => ts('- select -')) + $msgTemplates);
     }
     $this->assign('hasMsgTemplates', $hasMsgTemplates);
     $reminderDay =& $this->add('text', 'renewal_reminder_day', ts('Renewal Reminder Day'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'renewal_reminder_day'));
     $searchRows = $this->get('searchRows');
     $searchCount = $this->get('searchCount');
     $searchDone = $this->get('searchDone');
     if ($searchRows) {
         $checkBoxes = array();
         $chekFlag = 0;
         foreach ($searchRows as $id => $row) {
             $checked = '';
             if (!$chekFlag) {
                 $checked = array('checked' => NULL);
                 $chekFlag++;
             }
             $checkBoxes[$id] = $this->createElement('radio', NULL, NULL, NULL, $id, $checked);
         }
         $this->addGroup($checkBoxes, 'contact_check');
         $this->assign('searchRows', $searchRows);
     }
     $this->assign('searchCount', $searchCount);
     $this->assign('searchDone', $searchDone);
     if ($searchDone) {
         $searchBtn = ts('Search Again');
     } elseif ($this->_action & CRM_Core_Action::UPDATE) {
         $searchBtn = ts('Change');
     } else {
         $searchBtn = ts('Search');
     }
     $membershipRecords = FALSE;
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $membershipType = new CRM_Member_BAO_Membership();
         $membershipType->membership_type_id = $this->_id;
         if ($membershipType->find(TRUE)) {
             $membershipRecords = TRUE;
             $memberRel->freeze();
         }
         $memberOrg->freeze();
         if ($searchDone) {
             $memberOrg->unfreeze();
         }
     }
     $this->assign('membershipRecordsExists', $membershipRecords);
     if ($this->_action & CRM_Core_Action::UPDATE && $reminderDay) {
         $renewMessage = array();
         $returnProperties = array('renewal_msg_id', 'renewal_reminder_day');
         CRM_Core_DAO::commonRetrieveAll('CRM_Member_DAO_MembershipType', 'id', $this->_id, $renewMessage, $returnProperties);
         if (CRM_Utils_Array::value('renewal_msg_id', $renewMessage[$this->_id]) && CRM_Utils_Array::value('renewal_reminder_day', $renewMessage[$this->_id]) && $membershipRecords) {
             $reminderMsg = $this->add('select', 'renewal_msg_id', ts('Renewal Reminder Message'), array('' => ts('- select -')) + $msgTemplates);
             $reminderDay->freeze();
         }
     }
     $this->addElement('submit', $this->getButtonName('refresh'), $searchBtn, array('class' => 'form-submit'));
     $this->addFormRule(array('CRM_Member_Form_MembershipType', 'formRule'));
     $this->assign('membershipTypeId', $this->_id);
 }
示例#20
0
 function alterComponentDisplay(&$componentRows)
 {
     // custom code to alter rows
     require_once 'CRM/Core/PseudoConstant.php';
     $activityTypes = CRM_Core_PseudoConstant::activityType(true, false);
     $activityStatus = CRM_Core_PseudoConstant::activityStatus();
     $entryFound = false;
     foreach ($componentRows as $contactID => $components) {
         foreach ($components as $component => $rows) {
             foreach ($rows as $rowNum => $row) {
                 // handle contribution
                 if ($component == 'contribution_civireport') {
                     require_once 'CRM/Contribute/PseudoConstant.php';
                     if ($val = CRM_Utils_Array::value('civicrm_contribution_contribution_type_id', $row)) {
                         $componentRows[$contactID][$component][$rowNum]['civicrm_contribution_contribution_type_id'] = CRM_Contribute_PseudoConstant::contributionType($val, false);
                     }
                     if ($val = CRM_Utils_Array::value('civicrm_contribution_contribution_status_id', $row)) {
                         $componentRows[$contactID][$component][$rowNum]['civicrm_contribution_contribution_status_id'] = CRM_Contribute_PseudoConstant::contributionStatus($val);
                     }
                     $entryFound = true;
                 }
                 if ($component == 'membership_civireport') {
                     require_once 'CRM/Member/PseudoConstant.php';
                     if ($val = CRM_Utils_Array::value('civicrm_membership_membership_type_id', $row)) {
                         $componentRows[$contactID][$component][$rowNum]['civicrm_membership_membership_type_id'] = CRM_Member_PseudoConstant::membershipType($val, false);
                     }
                     if ($val = CRM_Utils_Array::value('civicrm_membership_status_id', $row)) {
                         $componentRows[$contactID][$component][$rowNum]['civicrm_membership_status_id'] = CRM_Member_PseudoConstant::membershipStatus($val, false);
                     }
                     $entryFound = true;
                 }
                 if ($component == 'participant_civireport') {
                     require_once 'CRM/Event/PseudoConstant.php';
                     if ($val = CRM_Utils_Array::value('civicrm_participant_event_id', $row)) {
                         $componentRows[$contactID][$component][$rowNum]['civicrm_participant_event_id'] = CRM_Event_PseudoConstant::event($val, false);
                         $url = CRM_Report_Utils_Report::getNextUrl('event/income', 'reset=1&force=1&id_op=in&id_value=' . $val, $this->_absoluteUrl, $this->_id);
                         $componentRows[$contactID][$component][$rowNum]['civicrm_participant_event_id_link'] = $url;
                         $componentRows[$contactID][$component][$rowNum]['civicrm_participant_event_id_hover'] = ts("View Event Income details for this Event.");
                         $entryFound = true;
                     }
                     if ($val = CRM_Utils_Array::value('civicrm_participant_participant_status_id', $row)) {
                         $componentRows[$contactID][$component][$rowNum]['civicrm_participant_participant_status_id'] = CRM_Event_PseudoConstant::participantStatus($val, false);
                     }
                     if ($val = CRM_Utils_Array::value('civicrm_participant_role_id', $row)) {
                         $componentRows[$contactID][$component][$rowNum]['civicrm_participant_role_id'] = CRM_Event_PseudoConstant::participantRole($val, false);
                     }
                     $entryFound = true;
                 }
                 if ($component == 'activity_civireport') {
                     if ($val = CRM_Utils_Array::value('civicrm_activity_activity_type_id', $row)) {
                         $componentRows[$contactID][$component][$rowNum]['civicrm_activity_activity_type_id'] = $activityTypes[$val];
                     }
                     if ($val = CRM_Utils_Array::value('civicrm_activity_activity_status_id', $row)) {
                         $componentRows[$contactID][$component][$rowNum]['civicrm_activity_activity_status_id'] = $activityStatus[$val];
                     }
                     $entryFound = true;
                 }
                 // skip looking further in rows, if first row itself doesn't
                 // have the column we need
                 if (!$entryFound) {
                     break;
                 }
             }
         }
     }
 }
示例#21
0
文件: Pledge.php 项目: ksecor/civicrm
 /** 
  * Function to build the form 
  * 
  * @return None 
  * @access public 
  */
 public function buildQuickForm()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if ($this->_context == 'standalone') {
         require_once 'CRM/Contact/Form/NewContact.php';
         CRM_Contact_Form_NewContact::buildQuickForm($this);
     }
     $showAdditionalInfo = false;
     $this->_formType = CRM_Utils_Array::value('formType', $_GET);
     //fix to load honoree pane on edit.
     $defaults = array();
     if ($this->_honorID) {
         $defaults['hidden_Honoree'] = 1;
     }
     $paneNames = array('Honoree Information' => 'Honoree', 'Payment Reminders' => 'PaymentReminders');
     foreach ($paneNames as $name => $type) {
         $urlParams = "snippet=4&formType={$type}";
         $allPanes[$name] = array('url' => CRM_Utils_System::url('civicrm/contact/view/pledge', $urlParams), 'open' => 'false', 'id' => $type);
         //see if we need to include this paneName in the current form
         if ($this->_formType == $type || CRM_Utils_Array::value("hidden_{$type}", $_POST) || CRM_Utils_Array::value("hidden_{$type}", $defaults)) {
             $showAdditionalInfo = true;
             $allPanes[$name]['open'] = 'true';
         }
         eval('CRM_Contribute_Form_AdditionalInfo::build' . $type . '( $this );');
     }
     $this->assign('allPanes', $allPanes);
     $this->assign('showAdditionalInfo', $showAdditionalInfo);
     if ($this->_formType) {
         $this->assign('formType', $this->_formType);
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     //pledge fields.
     $attributes = CRM_Core_DAO::getAttribute('CRM_Pledge_DAO_Pledge');
     $this->assign('isPending', $this->_isPending);
     $js = array('onblur' => "calculatedPaymentAmount( );", 'onkeyup' => "calculatedPaymentAmount( );");
     $element =& $this->add('text', 'amount', ts('Total Pledge Amount'), array_merge($attributes['pledge_amount'], $js), true);
     $this->addRule('amount', ts('Please enter a valid monetary amount.'), 'money');
     if ($this->_id && !$this->_isPending) {
         $element->freeze();
     }
     $element =& $this->add('text', 'installments', ts('To be paid in'), array_merge($attributes['installments'], $js), true);
     $this->addRule('installments', ts('Please enter a valid number of installments.'), 'positiveInteger');
     if ($this->_id && !$this->_isPending) {
         $element->freeze();
     }
     $element =& $this->add('text', 'frequency_interval', ts('every'), $attributes['frequency_interval'], true);
     $this->addRule('frequency_interval', ts('Please enter a number for frequency (e.g. every "3" months).'), 'positiveInteger');
     if ($this->_id && !$this->_isPending) {
         $element->freeze();
     }
     // Fix frequency unit display for use with frequency_interval
     $freqUnitsDisplay = array();
     foreach ($this->_freqUnits as $val => $label) {
         $freqUnitsDisplay[$val] = ts('%1(s)', array(1 => $val));
     }
     $element =& $this->add('select', 'frequency_unit', ts('Frequency'), array('' => ts('- select -')) + $freqUnitsDisplay, true);
     if ($this->_id && !$this->_isPending) {
         $element->freeze();
     }
     $element =& $this->add('text', 'frequency_day', ts('Payments are due on the'), $attributes['frequency_day'], true);
     $this->addRule('frequency_day', ts('Please enter a valid payment due day.'), 'positiveInteger');
     if ($this->_id && !$this->_isPending) {
         $element->freeze();
     }
     $this->add('text', 'eachPaymentAmount', ts('each'), array('size' => 10, 'style' => "background-color:#EBECE4", 'READONLY'));
     //add various dates
     if (!$this->_id || $this->_isPending) {
         $this->addDate('create_date', ts('Pledge Made'));
         $this->addDate('start_date', ts('Payments Start'));
     }
     if ($this->_id && !$this->_isPending) {
         $eachPaymentAmount = floor($this->_values['amount'] / $this->_values['installments']);
         $this->assign("eachPaymentAmount", $eachPaymentAmount);
         $this->assign("hideCalender", true);
     }
     if (CRM_Utils_Array::value('status_id', $this->_values) != array_search('Cancelled', CRM_Contribute_PseudoConstant::contributionStatus())) {
         $this->addElement('checkbox', 'is_acknowledge', ts('Send Acknowledgment?'), null, array('onclick' => "return showHideByValue('is_acknowledge','','acknowledgeDate','table-row','radio',true);"));
     }
     $this->addDate('acknowledge_date', ts('Acknowledgment Date'));
     $this->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType(), true);
     $pageIds = array();
     CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_PledgeBlock', 'entity_table', 'civicrm_contribution_page', $pageIds, array('entity_id'));
     $pages = CRM_Contribute_PseudoConstant::contributionPage();
     $pledgePages = array();
     foreach ($pageIds as $key => $value) {
         $pledgePages[$value['entity_id']] = $pages[$value['entity_id']];
     }
     $ele = $this->add('select', 'contribution_page_id', ts('Self-service Payments Page'), array('' => ts('- select -')) + $pledgePages);
     require_once "CRM/Core/BAO/Preferences.php";
     $mailingInfo =& CRM_Core_BAO_Preferences::mailingPreferences();
     $this->assign('outBound_option', $mailingInfo['outBound_option']);
     //build custom data
     CRM_Custom_Form_Customdata::buildQuickForm($this);
     // make this form an upload since we dont know if the custom data injected dynamically
     // is of type file etc $uploadNames = $this->get( 'uploadNames' );
     $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'js' => array('onclick' => "return verify( );"), 'isDefault' => true), array('type' => 'upload', 'name' => ts('Save and New'), 'js' => array('onclick' => "return verify( );"), 'subName' => 'new'), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->addFormRule(array('CRM_Pledge_Form_Pledge', 'formRule'), $this);
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
     }
 }
示例#22
0
文件: Query.php 项目: bhirsch/voipdev
 /**
  * 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);
 }
示例#23
0
文件: utils.php 项目: ksecor/civicrm
/**
 * take the input parameter list as specified in the data model and 
 * convert it into the same format that we use in QF and BAO object
 *
 * @param array  $params       Associative array of property name/value
 *                             pairs to insert in new contact.
 * @param array  $values       The reformatted properties that we can use internally
 *                            '
 * @return array|CRM_Error
 * @access public
 */
function _crm_format_contrib_params(&$params, &$values, $create = false)
{
    // copy all the contribution fields as is
    $fields =& CRM_Contribute_DAO_Contribution::fields();
    _crm_store_values($fields, $params, $values);
    foreach ($params as $key => $value) {
        // ignore empty values or empty arrays etc
        if (CRM_Utils_System::isNull($value)) {
            continue;
        }
        switch ($key) {
            case 'contribution_contact_id':
                if (!CRM_Utils_Rule::integer($value)) {
                    return _crm_error("contact_id not valid: {$value}");
                }
                $dao =& new CRM_Core_DAO();
                $qParams = array();
                $svq = $dao->singleValueQuery("SELECT id FROM civicrm_contact WHERE id = {$value}", $qParams);
                if (!$svq) {
                    return _crm_error("Invalid Contact ID: There is no contact record with contact_id = {$value}.");
                }
                $values['contact_id'] = $values['contribution_contact_id'];
                unset($values['contribution_contact_id']);
                break;
            case 'receive_date':
            case 'cancel_date':
            case 'receipt_date':
            case 'thankyou_date':
                if (!CRM_Utils_Rule::date($value)) {
                    return _crm_error("{$key} not a valid date: {$value}");
                }
                break;
            case 'non_deductible_amount':
            case 'total_amount':
            case 'fee_amount':
            case 'net_amount':
                if (!CRM_Utils_Rule::money($value)) {
                    return _crm_error("{$key} not a valid amount: {$value}");
                }
                break;
            case 'currency':
                if (!CRM_Utils_Rule::currencyCode($value)) {
                    return _crm_error("currency not a valid code: {$value}");
                }
                break;
            case 'contribution_type':
                require_once 'CRM/Contribute/PseudoConstant.php';
                $values['contribution_type_id'] = CRM_Utils_Array::key(ucfirst($value), CRM_Contribute_PseudoConstant::contributionType());
                break;
            case 'payment_instrument':
                require_once 'CRM/Core/OptionGroup.php';
                $values['payment_instrument_id'] = CRM_Core_OptionGroup::getValue('payment_instrument', $value);
                break;
            case 'contribution_status_id':
                require_once 'CRM/Core/OptionGroup.php';
                $values['contribution_status_id'] = CRM_Core_OptionGroup::getValue('contribution_status', $value);
                break;
            default:
                break;
        }
    }
    if (array_key_exists('note', $params)) {
        $values['note'] = $params['note'];
    }
    _crm_format_custom_params($params, $values, 'Contribution');
    if ($create) {
        // CRM_Contribute_BAO_Contribution::add() handles contribution_source
        // So, if $values contains contribution_source, convert it to source
        $changes = array('contribution_source' => 'source');
        foreach ($changes as $orgVal => $changeVal) {
            if (isset($values[$orgVal])) {
                $values[$changeVal] = $values[$orgVal];
                unset($values[$orgVal]);
            }
        }
    }
    return null;
}
/**
 * take the input parameter list as specified in the data model and
 * convert it into the same format that we use in QF and BAO object
 *
 * @param array  $params       Associative array of property name/value
 *                             pairs to insert in new contact.
 * @param array  $values       The reformatted properties that we can use internally
 *                            '
 *
 * @return array|CRM_Error
 * @access public
 */
function _civicrm_pledge_format_params(&$params, &$values, $create = FALSE)
{
    // based on contribution apis - copy all the pledge fields - this function filters out non -valid fields but unfortunately
    // means we have to put them back where there are 2 names for the field (name in table & unique name)
    // since there is no clear std to use one or the other. Generally either works ? but not for create date
    // perhaps we should just copy $params across rather than run it through the 'filter'?
    // but at least the filter forces anomalies into the open. In several cases it turned out the unique names wouldn't work
    // even though they are 'generally' what is returned in the GET - implying they should
    $fields = CRM_Pledge_DAO_Pledge::fields();
    _civicrm_store_values($fields, $params, $values);
    //add back the fields we know of that got dropped by the previous function
    if ($params['pledge_create_date']) {
        //pledge_create_date will not be formatted by the format params function so change back to create_date
        $values['create_date'] = $params['pledge_create_date'];
    }
    if ($params['create_date']) {
        //create_date may have been dropped by the $fields function so retrieve it
        $values['create_date'] = $params['create_date'];
    }
    if (array_key_exists('installment_amount', $params)) {
        //field has been renamed - don't lose it! Note that this must be called
        // installment amount not pledge_installment_amount, pledge_original_installment_amount
        // or original_installment_amount to avoid error
        // Division by zero in CRM\Pledge\BAO\PledgePayment.php:162
        // but we should accept the variant because they are all 'logical assumptions' based on the
        // 'standards'
        $values['installment_amount'] = $params['installment_amount'];
    }
    if (array_key_exists('original_installment_amount', $params)) {
        $values['installment_amount'] = $params['original_installment_amount'];
    }
    if (array_key_exists('pledge_original_installment_amount', $params)) {
        $values['installment_amount'] = $params['pledge_original_installment_amount'];
    }
    if (array_key_exists('status_id', $params)) {
        $values['pledge_status_id'] = $params['status_id'];
    }
    if ($params['contact_id']) {
        //this is validity checked further down to make sure the contact exists
        $values['pledge_contact_id'] = $params['contact_id'];
    }
    if (array_key_exists('id', $params)) {
        //retrieve the id key dropped from params. Note we can't use pledge_id because it
        //causes an error in CRM_Pledge_BAO_PledgePayment - approx line 302
        $values['id'] = $params['id'];
    }
    if (array_key_exists('pledge_id', $params)) {
        //retrieve the id key dropped from params. Note we can't use pledge_id because it
        //causes an error in CRM_Pledge_BAO_PledgePayment - approx line 302
        $values['id'] = $params['pledge_id'];
        unset($values['pledge_id']);
    }
    if (array_key_exists('status_id', $params)) {
        $values['pledge_status_id'] = $params['status_id'];
    }
    if (empty($values['id'])) {
        //at this point both should be the same so unset both if not set - passing in empty
        //value causes crash rather creating new - do it before next section as null values ignored in 'switch'
        unset($values['id']);
    }
    if (!empty($params['scheduled_date'])) {
        //scheduled date is required to set next payment date - defaults to start date
        $values['scheduled_date'] = $params['scheduled_date'];
    } elseif (array_key_exists('start_date', $params)) {
        $values['scheduled_date'] = $params['start_date'];
    }
    if (CRM_Utils_Array::value('contribution_type_id', $params)) {
        $values['contribution_type_id'] = $params['contribution_type_id'];
    }
    foreach ($values as $key => $value) {
        // ignore empty values or empty arrays etc
        if (CRM_Utils_System::isNull($value)) {
            continue;
        }
        switch ($key) {
            case 'pledge_contact_id':
                if (!CRM_Utils_Rule::integer($value)) {
                    return civicrm_create_error("contact_id not valid: {$value}");
                }
                $dao = new CRM_Core_DAO();
                $qParams = array();
                $svq = $dao->singleValueQuery("SELECT id FROM civicrm_contact WHERE id = {$value}", $qParams);
                if (!$svq) {
                    return civicrm_create_error("Invalid Contact ID: There is no contact record with contact_id = {$value}.");
                }
                $values['contact_id'] = $values['pledge_contact_id'];
                unset($values['pledge_contact_id']);
                break;
            case 'pledge_id':
                if (!CRM_Utils_Rule::integer($value)) {
                    return civicrm_create_error("contact_id not valid: {$value}");
                }
                $dao = new CRM_Core_DAO();
                $qParams = array();
                $svq = $dao->singleValueQuery("SELECT id FROM civicrm_pledge WHERE id = {$value}", $qParams);
                if (!$svq) {
                    return civicrm_create_error("Invalid Contact ID: There is no contact record with contact_id = {$value}.");
                }
                break;
            case 'create_date':
            case 'scheduled_date':
            case 'start_date':
                if (!CRM_Utils_Rule::datetime($value)) {
                    return civicrm_create_error("{$key} not a valid date: {$value}");
                }
                break;
            case 'installment_amount':
            case 'amount':
                if (!CRM_Utils_Rule::money($value)) {
                    return civicrm_create_error("{$key} not a valid amount: {$value}");
                }
                break;
            case 'currency':
                if (!CRM_Utils_Rule::currencyCode($value)) {
                    return civicrm_create_error("currency not a valid code: {$value}");
                }
                break;
            case 'contribution_type_id':
                require_once 'CRM/Contribute/PseudoConstant.php';
                $typeId = CRM_Contribute_PseudoConstant::contributionType($value);
                if (!CRM_Utils_Rule::integer($value) || !$typeId) {
                    return civicrm_create_error("contribution type id is not valid: {$value}");
                }
            default:
                break;
        }
    }
    //format the parameters
    _civicrm_custom_format_params($params, $values, 'Pledge');
    return array();
}
示例#25
0
 static function _fillCommonParams(&$params, $type = 'paypal')
 {
     if (array_key_exists('transaction', $params)) {
         $transaction =& $params['transaction'];
     } else {
         $transaction =& $params;
     }
     $params['contact_type'] = 'Individual';
     $billingLocTypeId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_LocationType', 'Billing', 'id', 'name');
     if (!$billingLocTypeId) {
         $billingLocTypeId = 1;
     }
     if (!CRM_Utils_System::isNull($params['address'])) {
         $params['address'][1]['is_primary'] = 1;
         $params['address'][1]['location_type_id'] = $billingLocTypeId;
     }
     if (!CRM_Utils_System::isNull($params['email'])) {
         $params['email'] = array(1 => array('email' => $params['email'], 'location_type_id' => $billingLocTypeId));
     }
     if (isset($transaction['trxn_id'])) {
         // set error message if transaction has already been processed.
         require_once 'CRM/Contribute/DAO/Contribution.php';
         $contribution = new CRM_Contribute_DAO_Contribution();
         $contribution->trxn_id = $transaction['trxn_id'];
         if ($contribution->find(true)) {
             $params['error'][] = ts('transaction already processed.');
         }
     } else {
         // generate a new transaction id, if not already exist
         $transaction['trxn_id'] = md5(uniqid(rand(), true));
     }
     if (!isset($transaction['contribution_type_id'])) {
         require_once 'CRM/Contribute/PseudoConstant.php';
         $contributionTypes = array_keys(CRM_Contribute_PseudoConstant::contributionType());
         $transaction['contribution_type_id'] = $contributionTypes[0];
     }
     if ($type == 'paypal' && !isset($transaction['net_amount'])) {
         $transaction['net_amount'] = $transaction['total_amount'] - CRM_Utils_Array::value('fee_amount', $transaction, 0);
     }
     if (!isset($transaction['invoice_id'])) {
         $transaction['invoice_id'] = $transaction['trxn_id'];
     }
     $source = ts('ContributionProcessor: %1 API', array(1 => ucfirst($type)));
     if (isset($transaction['source'])) {
         $transaction['source'] = $source . ':: ' . $transaction['source'];
     } else {
         $transaction['source'] = $source;
     }
     return true;
 }
 function alterDisplay(&$rows)
 {
     // custom code to alter rows
     $entryFound = FALSE;
     $checkList = array();
     $contributionTypes = CRM_Contribute_PseudoConstant::contributionType();
     $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus();
     $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument();
     foreach ($rows as $rowNum => $row) {
         if (!empty($this->_noRepeats) && $this->_outputMode != 'csv') {
             // not repeat contact display names if it matches with the one
             // in previous row
             $repeatFound = FALSE;
             foreach ($row as $colName => $colVal) {
                 if (CRM_Utils_Array::value($colName, $checkList) && is_array($checkList[$colName]) && in_array($colVal, $checkList[$colName])) {
                     $rows[$rowNum][$colName] = "";
                     $repeatFound = TRUE;
                 }
                 if (in_array($colName, $this->_noRepeats)) {
                     $checkList[$colName][] = $colVal;
                 }
             }
         }
         if (array_key_exists('civicrm_membership_membership_type_id', $row)) {
             if ($value = $row['civicrm_membership_membership_type_id']) {
                 $rows[$rowNum]['civicrm_membership_membership_type_id'] = CRM_Member_PseudoConstant::membershipType($value, FALSE);
             }
             $entryFound = TRUE;
         }
         if (array_key_exists('civicrm_address_state_province_id', $row)) {
             if ($value = $row['civicrm_address_state_province_id']) {
                 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value, FALSE);
             }
             $entryFound = TRUE;
         }
         if (array_key_exists('civicrm_address_country_id', $row)) {
             if ($value = $row['civicrm_address_country_id']) {
                 $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value, FALSE);
             }
             $entryFound = TRUE;
         }
         if (array_key_exists('civicrm_contact_sort_name', $row) && $rows[$rowNum]['civicrm_contact_sort_name'] && array_key_exists('civicrm_contact_id', $row)) {
             $url = CRM_Utils_System::url("civicrm/contact/view", 'reset=1&cid=' . $row['civicrm_contact_id'], $this->_absoluteUrl);
             $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
             $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact Summary for this Contact.");
             $entryFound = TRUE;
         }
         if ($value = CRM_Utils_Array::value('civicrm_contribution_contribution_type_id', $row)) {
             $rows[$rowNum]['civicrm_contribution_contribution_type_id'] = $contributionTypes[$value];
             $entryFound = TRUE;
         }
         if ($value = CRM_Utils_Array::value('civicrm_contribution_contribution_status_id', $row)) {
             $rows[$rowNum]['civicrm_contribution_contribution_status_id'] = $contributionStatus[$value];
             $entryFound = TRUE;
         }
         if ($value = CRM_Utils_Array::value('civicrm_contribution_payment_instrument_id', $row)) {
             $rows[$rowNum]['civicrm_contribution_payment_instrument_id'] = $paymentInstruments[$value];
             $entryFound = TRUE;
         }
         if (!$entryFound) {
             break;
         }
     }
 }
示例#27
0
 function alterDisplay(&$rows)
 {
     // custom code to alter rows
     $checkList = array();
     $entryFound = false;
     $display_flag = $prev_cid = $cid = 0;
     $contributionTypes = CRM_Contribute_PseudoConstant::contributionType();
     foreach ($rows as $rowNum => $row) {
         if (!empty($this->_noRepeats) && $this->_outputMode != 'csv') {
             // don't repeat contact details if its same as the previous row
             if (array_key_exists('civicrm_contact_id', $row)) {
                 if ($cid = $row['civicrm_contact_id']) {
                     if ($rowNum == 0) {
                         $prev_cid = $cid;
                     } else {
                         if ($prev_cid == $cid) {
                             $display_flag = 1;
                             $prev_cid = $cid;
                         } else {
                             $display_flag = 0;
                             $prev_cid = $cid;
                         }
                     }
                     if ($display_flag) {
                         foreach ($row as $colName => $colVal) {
                             if (in_array($colName, $this->_noRepeats)) {
                                 unset($rows[$rowNum][$colName]);
                             }
                         }
                     }
                     $entryFound = true;
                 }
             }
         }
         // handle state province
         if (array_key_exists('civicrm_address_state_province_id', $row)) {
             if ($value = $row['civicrm_address_state_province_id']) {
                 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value, false);
                 $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail', "reset=1&force=1&" . "state_province_id_op=in&state_province_id_value={$value}", $this->_absoluteUrl, $this->_id);
                 $rows[$rowNum]['civicrm_address_state_province_id_link'] = $url;
                 $rows[$rowNum]['civicrm_address_state_province_id_hover'] = ts("List all contribution(s) for this State.");
             }
             $entryFound = true;
         }
         // handle country
         if (array_key_exists('civicrm_address_country_id', $row)) {
             if ($value = $row['civicrm_address_country_id']) {
                 $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value, false);
                 $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail', "reset=1&force=1&" . "country_id_op=in&country_id_value={$value}", $this->_absoluteUrl, $this->_id);
                 $rows[$rowNum]['civicrm_address_country_id_link'] = $url;
                 $rows[$rowNum]['civicrm_address_country_id_hover'] = ts("List all contribution(s) for this Country.");
             }
             $entryFound = true;
         }
         // convert display name to links
         if (array_key_exists('civicrm_contact_display_name', $row) && CRM_Utils_Array::value('civicrm_contact_display_name', $rows[$rowNum]) && array_key_exists('civicrm_contact_id', $row)) {
             $url = CRM_Utils_System::url("civicrm/contact/view", 'reset=1&cid=' . $row['civicrm_contact_id'], $this->_absoluteUrl);
             $rows[$rowNum]['civicrm_contact_display_name_link'] = $url;
             $rows[$rowNum]['civicrm_contact_display_name_hover'] = ts("View Contact Summary for this Contact.");
         }
         if ($value = CRM_Utils_Array::value('civicrm_contribution_contribution_type_id', $row)) {
             $rows[$rowNum]['civicrm_contribution_contribution_type_id'] = $contributionTypes[$value];
             $entryFound = true;
         }
         // skip looking further in rows, if first row itself doesn't
         // have the column we need
         if (!$entryFound) {
             break;
         }
         $lastKey = $rowNum;
     }
 }
    /**
     * Function to build the form
     *
     * @return None
     * @access public
     */
    public function buildQuickForm()
    {
        if ($this->_cdType) {
            return CRM_Custom_Form_CustomData::buildQuickForm($this);
        }
        // build price set form.
        $buildPriceSet = FALSE;
        if ($this->_priceSetId || CRM_Utils_Array::value('price_set_id', $_POST)) {
            if (CRM_Utils_Array::value('price_set_id', $_POST)) {
                $buildPriceSet = TRUE;
            }
            $getOnlyPriceSetElements = TRUE;
            if (!$this->_priceSetId) {
                $this->_priceSetId = $_POST['price_set_id'];
                $getOnlyPriceSetElements = FALSE;
            }
            $this->set('priceSetId', $this->_priceSetId);
            CRM_Price_BAO_Set::buildPriceSet($this);
            $optionsMembershipTypes = array();
            foreach ($this->_priceSet['fields'] as $pField) {
                if (empty($pField['options'])) {
                    continue;
                }
                foreach ($pField['options'] as $opId => $opValues) {
                    $optionsMembershipTypes[$opId] = CRM_Utils_Array::value('membership_type_id', $opValues, 0);
                }
            }
            $this->assign('autoRenewOption', CRM_Price_BAO_Set::checkAutoRenewForPriceSet($this->_priceSetId));
            $this->assign('optionsMembershipTypes', $optionsMembershipTypes);
            $this->assign('contributionType', CRM_Utils_Array::value('contribution_type_id', $this->_priceSet));
            // get only price set form elements.
            if ($getOnlyPriceSetElements) {
                return;
            }
        }
        // use to build form during form rule.
        $this->assign('buildPriceSet', $buildPriceSet);
        if ($this->_action & CRM_Core_Action::ADD) {
            $buildPriceSet = FALSE;
            $priceSets = CRM_Price_BAO_Set::getAssoc(FALSE, 'CiviMember');
            if (!empty($priceSets)) {
                $buildPriceSet = TRUE;
            }
            if ($buildPriceSet) {
                $this->add('select', 'price_set_id', ts('Choose price set'), array('' => ts('Choose price set')) + $priceSets, NULL, array('onchange' => "buildAmount( this.value );"));
            }
            $this->assign('hasPriceSets', $buildPriceSet);
        }
        //need to assign custom data type and subtype to the template
        $this->assign('customDataType', 'Membership');
        $this->assign('customDataSubType', $this->_memType);
        $this->assign('entityID', $this->_id);
        if ($this->_action & CRM_Core_Action::DELETE) {
            $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
            return;
        }
        if ($this->_context == 'standalone') {
            CRM_Contact_Form_NewContact::buildQuickForm($this);
        }
        $selOrgMemType[0][0] = $selMemTypeOrg[0] = ts('- select -');
        $dao = new CRM_Member_DAO_MembershipType();
        $dao->domain_id = CRM_Core_Config::domainID();
        $dao->find();
        // retrieve all memberships
        $allMemberships = CRM_Member_BAO_Membership::buildMembershipTypeValues($this);
        $allMembershipInfo = $membershipType = array();
        foreach ($allMemberships as $key => $values) {
            if (CRM_Utils_Array::value('is_active', $values)) {
                $membershipType[$key] = CRM_Utils_Array::value('name', $values);
                if ($this->_mode && !CRM_Utils_Array::value('minimum_fee', $values)) {
                    continue;
                } else {
                    $memberOfContactId = CRM_Utils_Array::value('member_of_contact_id', $values);
                    if (!CRM_Utils_Array::value($memberOfContactId, $selMemTypeOrg)) {
                        $selMemTypeOrg[$memberOfContactId] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $memberOfContactId, 'display_name', 'id');
                        $selOrgMemType[$memberOfContactId][0] = ts('- select -');
                    }
                    if (!CRM_Utils_Array::value($key, $selOrgMemType[$memberOfContactId])) {
                        $selOrgMemType[$memberOfContactId][$key] = CRM_Utils_Array::value('name', $values);
                    }
                }
                // build membership info array, which is used to set the payment information block when
                // membership type is selected.
                $allMembershipInfo[$key] = array('contribution_type_id' => CRM_Utils_Array::value('contribution_type_id', $values), 'total_amount' => CRM_Utils_Money::format($values['minimum_fee'], NULL, '%a'), 'auto_renew' => CRM_Utils_Array::value('auto_renew', $values));
            }
        }
        $this->assign('allMembershipInfo', json_encode($allMembershipInfo));
        // show organization by default, if only one organization in
        // the list
        if (count($selMemTypeOrg) == 2) {
            unset($selMemTypeOrg[0], $selOrgMemType[0][0]);
        }
        //sort membership organization and type, CRM-6099
        natcasesort($selMemTypeOrg);
        foreach ($selOrgMemType as $index => $orgMembershipType) {
            natcasesort($orgMembershipType);
            $selOrgMemType[$index] = $orgMembershipType;
        }
        $memTypeJs = array('onChange' => "buildCustomData( 'Membership', this.value );");
        //build the form for auto renew.
        $recurProcessor = $autoRenew = array();
        if ($this->_mode || $this->_action & CRM_Core_Action::UPDATE) {
            $autoRenewElement = $this->addElement('checkbox', 'auto_renew', ts('Membership renewed automatically'), NULL, array('onclick' => "buildReceiptANDNotice( );"));
            if ($this->_mode) {
                //get the valid recurring processors.
                $recurring = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'is_recur = 1');
                $recurProcessor = array_intersect_assoc($this->_processors, $recurring);
                $autoRenew = array();
                if (!empty($recurProcessor)) {
                    if (!empty($membershipType)) {
                        $sql = '
SELECT  id,
        auto_renew,
        duration_unit,
        duration_interval
 FROM   civicrm_membership_type
WHERE   id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )';
                        $recurMembershipTypes = CRM_Core_DAO::executeQuery($sql);
                        while ($recurMembershipTypes->fetch()) {
                            $autoRenew[$recurMembershipTypes->id] = $recurMembershipTypes->auto_renew;
                            foreach (array('id', 'auto_renew', 'duration_unit', 'duration_interval') as $fld) {
                                $this->_recurMembershipTypes[$recurMembershipTypes->id][$fld] = $recurMembershipTypes->{$fld};
                            }
                        }
                    }
                    $memTypeJs = array('onChange' => "buildCustomData( 'Membership', this.value ); buildAutoRenew(this.value, null );");
                }
            }
        }
        $allowAutoRenew = FALSE;
        if ($this->_mode && !empty($recurProcessor)) {
            $allowAutoRenew = TRUE;
        }
        $this->assign('allowAutoRenew', $allowAutoRenew);
        $this->assign('autoRenewOptions', json_encode($autoRenew));
        $this->assign('recurProcessor', json_encode($recurProcessor));
        $sel =& $this->addElement('hierselect', 'membership_type_id', ts('Membership Organization and Type'), $memTypeJs);
        $sel->setOptions(array($selMemTypeOrg, $selOrgMemType));
        $elements = array();
        if ($sel) {
            $elements[] = $sel;
        }
        $this->applyFilter('__ALL__', 'trim');
        $this->addDate('join_date', ts('Member Since'), FALSE, array('formatType' => 'activityDate'));
        $this->addDate('start_date', ts('Start Date'), FALSE, array('formatType' => 'activityDate'));
        $endDate = $this->addDate('end_date', ts('End Date'), FALSE, array('formatType' => 'activityDate'));
        if ($endDate) {
            $elements[] = $endDate;
        }
        $this->add('text', 'source', ts('Source'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_Membership', 'source'));
        //CRM-7362 --add campaigns.
        $campaignId = NULL;
        if ($this->_id) {
            $campaignId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'campaign_id');
        }
        CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId);
        if (!$this->_mode) {
            $this->add('select', 'status_id', ts('Membership Status'), array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'));
            $statusOverride = $this->addElement('checkbox', 'is_override', ts('Status Override?'), NULL, array('onClick' => 'showHideMemberStatus()'));
            if ($statusOverride) {
                $elements[] = $statusOverride;
            }
            $this->addElement('checkbox', 'record_contribution', ts('Record Membership Payment?'));
            $this->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType());
            $this->add('text', 'total_amount', ts('Amount'));
            $this->addRule('total_amount', ts('Please enter a valid amount.'), 'money');
            $this->addDate('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDate'));
            $this->add('select', 'payment_instrument_id', ts('Paid By'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), FALSE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);"));
            $this->add('text', 'trxn_id', ts('Transaction ID'));
            $this->addRule('trxn_id', ts('Transaction ID already exists in Database.'), 'objectExists', array('CRM_Contribute_DAO_Contribution', $this->_id, 'trxn_id'));
            $allowStatuses = array();
            $statuses = CRM_Contribute_PseudoConstant::contributionStatus();
            if ($this->_onlinePendingContributionId) {
                $statusNames = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
                foreach ($statusNames as $val => $name) {
                    if (in_array($name, array('In Progress', 'Overdue'))) {
                        continue;
                    }
                    $allowStatuses[$val] = $statuses[$val];
                }
            } else {
                $allowStatuses = $statuses;
            }
            $this->add('select', 'contribution_status_id', ts('Payment Status'), $allowStatuses);
            $this->add('text', 'check_number', ts('Check Number'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'check_number'));
        } else {
            //add field for amount to allow an amount to be entered that differs from minimum
            $this->add('text', 'total_amount', ts('Amount'));
        }
        if ($this->_context != 'standalone') {
            //CRM-10223 - allow contribution to be recorded against different contact
            // causes a conflict in standalone mode so skip in standalone for now
            $this->addElement('checkbox', 'is_different_contribution_contact', ts('Record Payment from a Different Contact?'));
            $this->add('select', 'honor_type_id', ts('Membership payment is : '), array('' => ts('-')) + CRM_Core_PseudoConstant::honor());
            CRM_Contact_Form_NewContact::buildQuickForm($this, 1, null, false, 'contribution_');
        }
        $this->addElement('checkbox', 'send_receipt', ts('Send Confirmation and Receipt?'), NULL, array('onclick' => "showHideByValue( 'send_receipt', '', 'notice', 'table-row', 'radio', false); showHideByValue( 'send_receipt', '', 'fromEmail', 'table-row', 'radio', false);"));
        $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails);
        $this->add('textarea', 'receipt_text_signup', ts('Receipt Message'));
        if ($this->_mode) {
            $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, TRUE, array('onChange' => "buildAutoRenew( null, this.value );"));
            CRM_Core_Payment_Form::buildCreditCard($this, TRUE);
        }
        // Retrieve the name and email of the contact - this will be the TO for receipt email
        if ($this->_contactID) {
            list($this->_memberDisplayName, $this->_memberEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
            $this->assign('emailExists', $this->_memberEmail);
            $this->assign('displayName', $this->_memberDisplayName);
        }
        $isRecur = FALSE;
        if ($this->_action & CRM_Core_Action::UPDATE) {
            $recurContributionId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'contribution_recur_id');
            if ($recurContributionId && !CRM_Member_BAO_Membership::isSubscriptionCancelled($this->_id)) {
                $isRecur = TRUE;
                if (CRM_Member_BAO_Membership::isCancelSubscriptionSupported($this->_id)) {
                    $this->assign('cancelAutoRenew', CRM_Utils_System::url('civicrm/contribute/unsubscribe', "reset=1&mid={$this->_id}"));
                }
                foreach ($elements as $elem) {
                    $elem->freeze();
                }
            }
        }
        $this->assign('isRecur', $isRecur);
        $this->addFormRule(array('CRM_Member_Form_Membership', 'formRule'), $this);
        $mailingInfo = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend');
        $this->assign('outBound_option', $mailingInfo['outBound_option']);
        parent::buildQuickForm();
    }
示例#29
0
 /**
  * Get the values for pseudoconstants for name->value and reverse.
  *
  * @param array   $defaults (reference) the default values, some of which need to be resolved.
  * @param boolean $reverse  true if we want to resolve the values in the reverse direction (value -> name)
  *
  * @return void
  * @access public
  * @static
  */
 static function resolveDefaults(&$defaults, $reverse = false)
 {
     require_once 'CRM/Contribute/PseudoConstant.php';
     self::lookupValue($defaults, 'contribution_type', CRM_Contribute_PseudoConstant::contributionType(), $reverse);
     self::lookupValue($defaults, 'payment_instrument', CRM_Contribute_PseudoConstant::paymentInstrument(), $reverse);
     self::lookupValue($defaults, 'contribution_status', CRM_Contribute_PseudoConstant::contributionStatus(), $reverse);
     self::lookupValue($defaults, 'pcp', CRM_Contribute_PseudoConstant::pcPage(), $reverse);
 }
示例#30
0
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     $this->add('text', 'name', ts('Name'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'name'), true);
     $this->addRule('name', ts('A membership type with this name already exists. Please select another name.'), 'objectExists', array('CRM_Member_DAO_MembershipType', $this->_id));
     $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'description'));
     $this->add('text', 'minimum_fee', ts('Minimum Fee'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'minimum_fee'));
     $this->addRule('minimum_fee', ts('Please enter a monetary value for the Minimum Fee.'), 'money');
     $this->addElement('select', 'duration_unit', ts('Duration') . ' ', CRM_Core_SelectValues::unitList('duration'), array('onchange' => 'showHidePeriodSettings()'));
     //period type
     $this->addElement('select', 'period_type', ts('Period Type'), CRM_Core_SelectValues::periodType(), array('onchange' => 'showHidePeriodSettings()'));
     $this->add('text', 'duration_interval', ts('Duration Interval'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'duration_interval'));
     $memberOrg =& $this->add('text', 'member_org', ts('Membership Organization'), 'size=30 maxlength=120');
     //start day
     $this->add('date', 'fixed_period_start_day', ts('Fixed Period Start Day'), CRM_Core_SelectValues::date('custom', 3, 1, "Md"), false);
     //rollover day
     $this->add('date', 'fixed_period_rollover_day', ts('Fixed Period Rollover Day'), CRM_Core_SelectValues::date('custom', 3, 1, "Md"), false);
     $this->add('hidden', 'action', $this->_action);
     //required in form rule
     require_once 'CRM/Contribute/PseudoConstant.php';
     $this->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType());
     require_once 'CRM/Contact/BAO/Relationship.php';
     $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, null, null, null, true);
     if (is_array($relTypeInd)) {
         asort($relTypeInd);
     }
     $memberRel =& $this->add('select', 'relationship_type_id', ts('Relationship Type'), array('' => ts('- select -')) + $relTypeInd);
     $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::memberVisibility());
     $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'weight'));
     $this->add('checkbox', 'is_active', ts('Enabled?'));
     require_once "CRM/Core/BAO/MessageTemplates.php";
     $msgTemplates = CRM_Core_BAO_MessageTemplates::getMessageTemplates();
     if (!empty($msgTemplates)) {
         $reminderMsg = $this->add('select', 'renewal_msg_id', ts('Renewal Reminder Message'), array('' => ts('- select -')) + $msgTemplates);
     } else {
         $this->assign('noMsgTemplates', true);
     }
     $reminderDay =& $this->add('text', 'renewal_reminder_day', ts('Renewal Reminder Day'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'renewal_reminder_day'));
     $searchRows = $this->get('searchRows');
     $searchCount = $this->get('searchCount');
     $searchDone = $this->get('searchDone');
     if ($searchRows) {
         $checkBoxes = array();
         $chekFlag = 0;
         foreach ($searchRows as $id => $row) {
             $checked = '';
             if (!$chekFlag) {
                 $checked = array('checked' => null);
                 $chekFlag++;
             }
             $checkBoxes[$id] = $this->createElement('radio', null, null, null, $id, $checked);
         }
         $this->addGroup($checkBoxes, 'contact_check');
         $this->assign('searchRows', $searchRows);
     }
     $this->assign('searchCount', $searchCount);
     $this->assign('searchDone', $searchDone);
     if ($searchDone) {
         $searchBtn = ts('Search Again');
     } elseif ($this->_action & CRM_Core_Action::UPDATE) {
         $searchBtn = ts('Change');
     } else {
         $searchBtn = ts('Search');
     }
     $membershipRecords = false;
     if ($this->_action & CRM_Core_Action::UPDATE) {
         require_once 'CRM/Member/BAO/Membership.php';
         $membershipType = new CRM_Member_BAO_Membership();
         $membershipType->membership_type_id = $this->_id;
         if ($membershipType->find(true)) {
             $membershipRecords = true;
             $memberRel->freeze();
         }
         $memberOrg->freeze();
         if ($searchDone) {
             $memberOrg->unfreeze();
         }
     }
     if ($this->_action & CRM_Core_Action::UPDATE && $reminderDay) {
         $renewMessage = array();
         $returnProperties = array('renewal_msg_id', 'renewal_reminder_day');
         CRM_Core_DAO::commonRetrieveAll('CRM_Member_DAO_MembershipType', 'id', $this->_id, $renewMessage, $returnProperties);
         if (CRM_Utils_Array::value('renewal_msg_id', $renewMessage[$this->_id]) && CRM_Utils_Array::value('renewal_reminder_day', $renewMessage[$this->_id]) && $membershipRecords) {
             $reminderMsg = $this->add('select', 'renewal_msg_id', ts('Renewal Reminder Message'), array('' => ts('- select -')) + $msgTemplates);
             $reminderDay->freeze();
             $reminderMsg->freeze();
         }
     }
     $this->addElement('submit', $this->getButtonName('refresh'), $searchBtn, array('class' => 'form-submit'));
     $this->addFormRule(array('CRM_Member_Form_MembershipType', 'formRule'));
     $this->assign('membershipTypeId', $this->_id);
 }