/** * This function is the main function that is called when the page loads, it decides the which action has to be taken for the page. * * return null * @access public */ function run() { $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this); $this->assign('action', $this->_action); $this->assign('context', $this->_context); $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this); CRM_Pledge_Page_Tab::setContext(); if ($this->_action & CRM_Core_Action::UPDATE) { $this->edit(); // set page title CRM_Contact_Page_View::setTitle($this->_contactId); } else { $pledgeId = CRM_Utils_Request::retrieve('pledgeId', 'Positive', $this); $paymentDetails = CRM_Pledge_BAO_PledgePayment::getPledgePayments($pledgeId); $this->assign('rows', $paymentDetails); $this->assign('pledgeId', $pledgeId); $this->assign('contactId', $this->_contactId); // check if we can process credit card contribs $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, "billing_mode IN ( 1, 3 )"); if (count($processors) > 0) { $this->assign('newCredit', TRUE); } else { $this->assign('newCredit', FALSE); } // check is the user has view/edit signer permission $permission = 'view'; if (CRM_Core_Permission::check('edit pledges')) { $permission = 'edit'; } $this->assign('permission', $permission); } return parent::run(); }
/** * Function to actually build the form * * @return void * @access public */ public function buildQuickForm() { require_once 'CRM/Utils/Money.php'; // do u want to allow a free form text field for amount $this->addElement('checkbox', 'is_allow_other_amount', ts('Allow other amounts'), null, array('onclick' => "minMax(this);showHideAmountBlock( this, 'is_allow_other_amount' );")); $this->add('text', 'min_amount', ts('Minimum Amount'), array('size' => 8, 'maxlength' => 8)); $this->addRule('min_amount', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('9.99', ' '))), 'money'); $this->add('text', 'max_amount', ts('Maximum Amount'), array('size' => 8, 'maxlength' => 8)); $this->addRule('max_amount', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money'); $default = array(); for ($i = 1; $i <= self::NUM_OPTION; $i++) { // label $this->add('text', "label[{$i}]", ts('Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'label')); // value $this->add('text', "value[{$i}]", ts('Value'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'value')); $this->addRule("value[{$i}]", ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money'); // default $default[] = $this->createElement('radio', null, null, null, $i); } $this->addGroup($default, 'default'); $this->addElement('checkbox', 'amount_block_is_active', ts('Contribution Amounts section enabled'), null, array('onclick' => "showHideAmountBlock( this, 'amount_block_is_active' );")); $this->addElement('checkbox', 'is_monetary', ts('Execute real-time monetary transactions')); $paymentProcessor =& CRM_Core_PseudoConstant::paymentProcessor(); if (count($paymentProcessor)) { $this->assign('paymentProcessor', $paymentProcessor); } $this->add('select', 'payment_processor_id', ts('Payment Processor'), array('' => ts('- select -')) + $paymentProcessor); require_once "CRM/Contribute/BAO/ContributionPage.php"; //check if selected payment processor supports recurring payment if (CRM_Contribute_BAO_ContributionPage::checkRecurPaymentProcessor($this->_id)) { $this->addElement('checkbox', 'is_recur', ts('Recurring contributions'), null, array('onclick' => "return showHideByValue('is_recur',true,'recurFields','table-row','radio',false);")); require_once 'CRM/Core/OptionGroup.php'; $this->addCheckBox('recur_frequency_unit', ts('Supported recurring units'), CRM_Core_OptionGroup::values('recur_frequency_units', false, false, false, null, 'name'), null, null, null, null, array(' ', ' ', ' ', '<br/>')); $this->addElement('checkbox', 'is_recur_interval', ts('Support recurring intervals')); } // add pay later options $this->addElement('checkbox', 'is_pay_later', ts('Pay later option'), null, array('onclick' => "payLater(this);")); $this->addElement('textarea', 'pay_later_text', ts('Pay later label'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'pay_later_text'), false); $this->addElement('textarea', 'pay_later_receipt', ts('Pay later instructions'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'pay_later_receipt'), false); // add price set fields require_once 'CRM/Price/BAO/Set.php'; $this->add('select', 'price_set_id', ts('Price Set'), array('' => ts('- none -')) + CRM_Price_BAO_Set::getAssoc(false, 'Contribution'), null, array('onchange' => "showHideAmountBlock( this.value, 'price_set_id' );")); //CiviPledge fields. $config =& CRM_Core_Config::singleton(); if (in_array('CiviPledge', $config->enableComponents)) { $this->assign('civiPledge', true); require_once 'CRM/Core/OptionGroup.php'; $this->addElement('checkbox', 'is_pledge_active', ts('Pledges'), null, array('onclick' => "showHideAmountBlock( this, 'is_pledge_active' ); return showHideByValue('is_pledge_active',true,'pledgeFields','table-row','radio',false);")); $this->addCheckBox('pledge_frequency_unit', ts('Supported pledge frequencies'), CRM_Core_OptionGroup::values("recur_frequency_units", false, false, false, null, 'name'), null, null, null, null, array(' ', ' ', ' ', '<br/>')); $this->addElement('checkbox', 'is_pledge_interval', ts('Allow frequency intervals')); $this->addElement('text', 'initial_reminder_day', ts('Send payment reminder'), array('size' => 3)); $this->addElement('text', 'max_reminders', ts('Send up to'), array('size' => 3)); $this->addElement('text', 'additional_reminder_day', ts('Send additional reminders'), array('size' => 3)); } $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Amount', 'formRule'), $this); parent::buildQuickForm(); }
/** * This function is the main function that is called when the page loads, it decides the which action has to be taken for the page. * * return null * @access public */ function run() { $this->preProcess(); // check if we can process credit card membership $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, "billing_mode IN ( 1, 3 )"); if (count($processors) > 0) { $this->assign('newCredit', TRUE); $this->_isPaymentProcessor = TRUE; } else { $this->assign('newCredit', FALSE); $this->_isPaymentProcessor = FALSE; } // Only show credit card membership signup if user has CiviContribute permission if (CRM_Core_Permission::access('CiviContribute')) { $this->_accessContribution = TRUE; $this->assign('accessContribution', TRUE); } else { $this->_accessContribution = FALSE; $this->assign('accessContribution', FALSE); } if ($this->_action & CRM_Core_Action::VIEW) { $this->view(); } elseif ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE | CRM_Core_Action::RENEW)) { $this->setContext(); $this->edit(); } else { $this->setContext(); $this->browse(); } return parent::run(); }
public function preProcess() { //custom data related code $this->_cdType = CRM_Utils_Array::value('type', $_GET); $this->assign('cdType', false); if ($this->_cdType) { $this->assign('cdType', true); return CRM_Custom_Form_CustomData::preProcess($this); } // action $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'add'); $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this); // check for edit permission if (!CRM_Core_Permission::checkActionPermission('CiviMember', $this->_action)) { CRM_Core_Error::fatal(ts('You do not have permission to access this page')); } $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this); $this->assign('context', $this->_context); if ($this->_id) { $this->_memType = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $this->_id, "membership_type_id"); } $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this); if ($this->_mode) { $this->assign('membershipMode', $this->_mode); $this->_paymentProcessor = array('billing_mode' => 1); $validProcessors = array(); $processors = CRM_Core_PseudoConstant::paymentProcessor(false, false, "billing_mode IN ( 1, 3 )"); foreach ($processors as $ppID => $label) { require_once 'CRM/Core/BAO/PaymentProcessor.php'; require_once 'CRM/Core/Payment.php'; $paymentProcessor =& CRM_Core_BAO_PaymentProcessor::getPayment($ppID, $this->_mode); if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) { continue; } else { if ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode == 'live') { continue; } else { $paymentObject =& CRM_Core_Payment::singleton($this->_mode, 'Contribute', $paymentProcessor, $this); $error = $paymentObject->checkConfig(); if (empty($error)) { $validProcessors[$ppID] = $label; } $paymentObject = null; } } } if (empty($validProcessors)) { CRM_Core_Error::fatal(ts('Could not find valid payment processor for this page')); } else { $this->_processors = $validProcessors; } // also check for billing information // get the billing location type $locationTypes =& CRM_Core_PseudoConstant::locationType(); $this->_bltID = array_search('Billing', $locationTypes); if (!$this->_bltID) { CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing'))); } $this->set('bltID', $this->_bltID); $this->assign('bltID', $this->_bltID); $this->_fields = array(); require_once 'CRM/Core/Payment/Form.php'; CRM_Core_Payment_Form::setCreditCardFields($this); // this required to show billing block $this->assign_by_ref('paymentProcessor', $paymentProcessor); $this->assign('hidePayPalExpress', true); } //check whether membership status present or not if ($this->_action & CRM_Core_Action::ADD) { CRM_Member_BAO_Membership::statusAvilability($this->_contactID); } // when custom data is included in this page if (CRM_Utils_Array::value("hidden_custom", $_POST)) { CRM_Custom_Form_Customdata::preProcess($this); CRM_Custom_Form_Customdata::buildQuickForm($this); CRM_Custom_Form_Customdata::setDefaultValues($this); } // CRM-4395, get the online pending contribution id. $this->_onlinePendingContributionId = null; if (!$this->_mode && $this->_id && $this->_action & CRM_Core_Action::UPDATE) { require_once 'CRM/Contribute/BAO/Contribution.php'; $this->_onlinePendingContributionId = CRM_Contribute_BAO_Contribution::checkOnlinePendingContribution($this->_id, 'Membership'); } $this->assign('onlinePendingContributionId', $this->_onlinePendingContributionId); parent::preProcess(); }
/** * Build Membership Block in Contribution Pages. * * @param CRM_Core_Form $form * Form object. * @param int $pageID * Unused?. * @param int $cid * Contact checked for having a current membership for a particular membership. * @param bool $formItems * @param int $selectedMembershipTypeID * Selected membership id. * @param bool $thankPage * Thank you page. * @param null $isTest * * @return bool * Is this a separate membership payment * */ public static function buildMembershipBlock(&$form, $pageID, $cid, $formItems = FALSE, $selectedMembershipTypeID = NULL, $thankPage = FALSE, $isTest = NULL) { $separateMembershipPayment = FALSE; if ($form->_membershipBlock) { $form->_currentMemberships = array(); $membershipBlock = $form->_membershipBlock; $membershipTypeIds = $membershipTypes = $radio = array(); $membershipPriceset = !empty($form->_priceSetId) && $form->_useForMember ? TRUE : FALSE; $allowAutoRenewMembership = $autoRenewOption = FALSE; $autoRenewMembershipTypeOptions = array(); $paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'is_recur = 1'); $separateMembershipPayment = CRM_Utils_Array::value('is_separate_payment', $membershipBlock); if ($membershipPriceset) { foreach ($form->_priceSet['fields'] as $pField) { if (empty($pField['options'])) { continue; } foreach ($pField['options'] as $opId => $opValues) { if (empty($opValues['membership_type_id'])) { continue; } $membershipTypeIds[$opValues['membership_type_id']] = $opValues['membership_type_id']; } } } elseif (!empty($membershipBlock['membership_types'])) { $membershipTypeIds = explode(',', $membershipBlock['membership_types']); } if (!empty($membershipTypeIds)) { //set status message if wrong membershipType is included in membershipBlock if (isset($form->_mid) && !$membershipPriceset) { $membershipTypeID = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $form->_mid, 'membership_type_id'); if (!in_array($membershipTypeID, $membershipTypeIds)) { CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership."), ts('Invalid Membership'), 'error'); } } $membershipTypeValues = self::buildMembershipTypeValues($form, $membershipTypeIds); $form->_membershipTypeValues = $membershipTypeValues; $endDate = NULL; foreach ($membershipTypeIds as $value) { $memType = $membershipTypeValues[$value]; if ($selectedMembershipTypeID != NULL) { if ($memType['id'] == $selectedMembershipTypeID) { $form->assign('minimum_fee', CRM_Utils_Array::value('minimum_fee', $memType)); $form->assign('membership_name', $memType['name']); if (!$thankPage && $cid) { $membership = new CRM_Member_DAO_Membership(); $membership->contact_id = $cid; $membership->membership_type_id = $memType['id']; if ($membership->find(TRUE)) { $form->assign('renewal_mode', TRUE); $memType['current_membership'] = $membership->end_date; $form->_currentMemberships[$membership->membership_type_id] = $membership->membership_type_id; } } $membershipTypes[] = $memType; } } elseif ($memType['is_active']) { $javascriptMethod = NULL; $allowAutoRenewOpt = (int) $memType['auto_renew']; if (is_array($form->_paymentProcessors)) { foreach ($form->_paymentProcessors as $id => $val) { if (!$val['is_recur']) { $allowAutoRenewOpt = 0; continue; } } } $javascriptMethod = array('onclick' => "return showHideAutoRenew( this.value );"); $autoRenewMembershipTypeOptions["autoRenewMembershipType_{$value}"] = (int) $allowAutoRenewOpt * CRM_Utils_Array::value($value, CRM_Utils_Array::value('auto_renew', $form->_membershipBlock)); if ($allowAutoRenewOpt) { $allowAutoRenewMembership = TRUE; } //add membership type. $radio[$memType['id']] = $form->createElement('radio', NULL, NULL, NULL, $memType['id'], $javascriptMethod); if ($cid) { $membership = new CRM_Member_DAO_Membership(); $membership->contact_id = $cid; $membership->membership_type_id = $memType['id']; //show current membership, skip pending and cancelled membership records, //because we take first membership record id for renewal $membership->whereAdd('status_id != 5 AND status_id !=6'); if (!is_null($isTest)) { $membership->is_test = $isTest; } //CRM-4297 $membership->orderBy('end_date DESC'); if ($membership->find(TRUE)) { if (!$membership->end_date) { unset($radio[$memType['id']]); $form->assign('islifetime', TRUE); continue; } $form->assign('renewal_mode', TRUE); $form->_currentMemberships[$membership->membership_type_id] = $membership->membership_type_id; $memType['current_membership'] = $membership->end_date; if (!$endDate) { $endDate = $memType['current_membership']; $form->_defaultMemTypeId = $memType['id']; } if ($memType['current_membership'] < $endDate) { $endDate = $memType['current_membership']; $form->_defaultMemTypeId = $memType['id']; } } } $membershipTypes[] = $memType; } } } $form->assign('showRadio', $formItems); if ($formItems) { if (!$membershipPriceset) { if (!$membershipBlock['is_required']) { $form->assign('showRadioNoThanks', TRUE); $radio[''] = $form->createElement('radio', NULL, NULL, NULL, 'no_thanks', NULL); $form->addGroup($radio, 'selectMembership', NULL); } elseif ($membershipBlock['is_required'] && count($radio) == 1) { $temp = array_keys($radio); $form->add('hidden', 'selectMembership', $temp[0], array('id' => 'selectMembership')); $form->assign('singleMembership', TRUE); $form->assign('showRadio', FALSE); } else { $form->addGroup($radio, 'selectMembership', NULL); } $form->addRule('selectMembership', ts('Please select one of the memberships.'), 'required'); } else { $autoRenewOption = CRM_Price_BAO_PriceSet::checkAutoRenewForPriceSet($form->_priceSetId); $form->assign('autoRenewOption', $autoRenewOption); } if (!$form->_values['is_pay_later'] && is_array($form->_paymentProcessors) && ($allowAutoRenewMembership || $autoRenewOption)) { $form->addElement('checkbox', 'auto_renew', ts('Please renew my membership automatically.')); } } $form->assign('membershipBlock', $membershipBlock); $form->assign('membershipTypes', $membershipTypes); $form->assign('allowAutoRenewMembership', $allowAutoRenewMembership); $form->assign('autoRenewMembershipTypeOptions', json_encode($autoRenewMembershipTypeOptions)); //give preference to user submitted auto_renew value. $takeUserSubmittedAutoRenew = !empty($_POST) || $form->isSubmitted() ? TRUE : FALSE; $form->assign('takeUserSubmittedAutoRenew', $takeUserSubmittedAutoRenew); } return $separateMembershipPayment; }
/** * 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); }
/** * This function is the main function that is called when the page loads, it decides the which action has to be taken for the page. * * return null * @access public */ function run() { $this->preProcess(); // check if we can process credit card registration $processors = CRM_Core_PseudoConstant::paymentProcessor(false, false, "billing_mode IN ( 1, 3 )"); if (count($processors) > 0) { $this->assign('newCredit', true); } else { $this->assign('newCredit', false); } $this->setContext(); if ($this->_action & CRM_Core_Action::VIEW) { $this->view(); } else { if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) { $this->edit(); } else { if ($this->_action & CRM_Core_Action::DETACH) { require_once 'CRM/Pledge/BAO/Payment.php'; require_once 'CRM/Contribute/PseudoConstant.php'; CRM_Pledge_BAO_Payment::updatePledgePaymentStatus($this->_id, null, null, array_search('Cancelled', CRM_Contribute_PseudoConstant::contributionStatus())); $session =& CRM_Core_Session::singleton(); $session->setStatus(ts('Pledge has been Cancelled and all scheduled (not completed) payments have been cancelled.<br />')); CRM_Utils_System::redirect($session->popUserContext()); } else { $this->browse(); } } } return parent::run(); }
/** * Process the form submission. */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { CRM_Pledge_BAO_Pledge::deletePledge($this->_id); return; } // get the submitted form values. $formValues = $this->controller->exportValues($this->_name); // set the contact, when contact is selected if (!empty($formValues['contact_id'])) { $this->_contactID = $formValues['contact_id']; } $session = CRM_Core_Session::singleton(); // get All Payments status types. $paymentStatusTypes = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); $fields = array('frequency_unit', 'frequency_interval', 'frequency_day', 'installments', 'financial_type_id', 'initial_reminder_day', 'max_reminders', 'additional_reminder_day', 'contribution_page_id', 'campaign_id'); foreach ($fields as $f) { $params[$f] = CRM_Utils_Array::value($f, $formValues); } // defaults status is "Pending". // if update get status. if ($this->_id) { $params['pledge_status_id'] = $params['status_id'] = $this->_values['status_id']; } else { $params['pledge_status_id'] = $params['status_id'] = array_search('Pending', $paymentStatusTypes); } // format amount $params['amount'] = CRM_Utils_Rule::cleanMoney(CRM_Utils_Array::value('amount', $formValues)); $params['currency'] = CRM_Utils_Array::value('currency', $formValues); $params['original_installment_amount'] = $params['amount'] / $params['installments']; $dates = array('create_date', 'start_date', 'acknowledge_date', 'cancel_date'); foreach ($dates as $d) { if ($this->_id && !$this->_isPending && !empty($this->_values[$d])) { if ($d == 'start_date') { $params['scheduled_date'] = CRM_Utils_Date::processDate($this->_values[$d]); } $params[$d] = CRM_Utils_Date::processDate($this->_values[$d]); } elseif (!empty($formValues[$d]) && !CRM_Utils_System::isNull($formValues[$d])) { if ($d == 'start_date') { $params['scheduled_date'] = CRM_Utils_Date::processDate($formValues[$d]); } $params[$d] = CRM_Utils_Date::processDate($formValues[$d]); } else { $params[$d] = 'null'; } } if (!empty($formValues['is_acknowledge'])) { $params['acknowledge_date'] = date('Y-m-d'); } // assign id only in update mode if ($this->_action & CRM_Core_Action::UPDATE) { $params['id'] = $this->_id; } $params['contact_id'] = $this->_contactID; // format custom data if (!empty($formValues['hidden_custom'])) { $params['hidden_custom'] = 1; $customFields = CRM_Core_BAO_CustomField::getFields('Pledge'); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($formValues, $this->_id, 'Pledge'); } // handle pending pledge. $params['is_pledge_pending'] = $this->_isPending; // create pledge record. $pledge = CRM_Pledge_BAO_Pledge::create($params); $statusMsg = NULL; if ($pledge->id) { // set the status msg. if ($this->_action & CRM_Core_Action::ADD) { $statusMsg = ts('Pledge has been recorded and the payment schedule has been created.<br />'); } elseif ($this->_action & CRM_Core_Action::UPDATE) { $statusMsg = ts('Pledge has been updated.<br />'); } } // handle Acknowledgment. if (!empty($formValues['is_acknowledge']) && $pledge->id) { // calculate scheduled amount. $params['scheduled_amount'] = round($params['amount'] / $params['installments']); $params['total_pledge_amount'] = $params['amount']; // get some required pledge values in params. $params['id'] = $pledge->id; $params['acknowledge_date'] = $pledge->acknowledge_date; $params['is_test'] = $pledge->is_test; $params['currency'] = $pledge->currency; // retrieve 'from email id' for acknowledgement $params['from_email_id'] = $formValues['from_email_address']; $this->paymentId = NULL; // send Acknowledgment mail. CRM_Pledge_BAO_Pledge::sendAcknowledgment($this, $params); if (!isset($this->userEmail)) { list($this->userDisplayName, $this->userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID); } $statusMsg .= ' ' . ts("An acknowledgment email has been sent to %1.<br />", array(1 => $this->userEmail)); // build the payment urls. if ($this->paymentId) { $urlParams = "reset=1&action=add&cid={$this->_contactID}&ppid={$this->paymentId}&context=pledge"; $contribURL = CRM_Utils_System::url('civicrm/contact/view/contribution', $urlParams); $urlParams .= "&mode=live"; $creditURL = CRM_Utils_System::url('civicrm/contact/view/contribution', $urlParams); // check if we can process credit card payment. $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, "billing_mode IN ( 1, 3 )"); if (count($processors) > 0) { $statusMsg .= ' ' . ts("If a payment is due now, you can record <a href='%1'>a check, EFT, or cash payment for this pledge</a> OR <a href='%2'>submit a credit card payment</a>.", array(1 => $contribURL, 2 => $creditURL)); } else { $statusMsg .= ' ' . ts("If a payment is due now, you can record <a href='%1'>a check, EFT, or cash payment for this pledge</a>.", array(1 => $contribURL)); } } } CRM_Core_Session::setStatus($statusMsg, ts('Payment Due'), 'info'); $buttonName = $this->controller->getButtonName(); if ($this->_context == 'standalone') { if ($buttonName == $this->getButtonName('upload', 'new')) { $session->replaceUserContext(CRM_Utils_System::url('civicrm/pledge/add', 'reset=1&action=add&context=standalone')); } else { $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_contactID}&selectedChild=pledge")); } } elseif ($buttonName == $this->getButtonName('upload', 'new')) { $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/pledge', "reset=1&action=add&context=pledge&cid={$this->_contactID}")); } }
/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { $this->_showFeeBlock = CRM_Utils_Array::value('eventId', $_GET); $this->assign('showFeeBlock', false); $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this); $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this); $this->_participantId = CRM_Utils_Request::retrieve('id', 'Positive', $this); $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this); $this->assign('context', $this->_context); // get the option value for custom data type $this->_roleCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantRole', 'name'); $this->_eventNameCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventName', 'name'); $this->assign('roleCustomDataTypeID', $this->_roleCustomDataTypeID); $this->assign('eventNameCustomDataTypeID', $this->_eventNameCustomDataTypeID); if ($this->_mode) { $this->assign('participantMode', $this->_mode); $this->_paymentProcessor = array('billing_mode' => 1); $validProcessors = array(); $processors = CRM_Core_PseudoConstant::paymentProcessor(false, false, "billing_mode IN ( 1, 3 )"); foreach ($processors as $ppID => $label) { require_once 'CRM/Core/BAO/PaymentProcessor.php'; require_once 'CRM/Core/Payment.php'; $paymentProcessor =& CRM_Core_BAO_PaymentProcessor::getPayment($ppID, $this->_mode); if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) { continue; } else { if ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode == 'live') { continue; } else { $paymentObject =& CRM_Core_Payment::singleton($this->_mode, 'Contribute', $paymentProcessor, $this); $error = $paymentObject->checkConfig(); if (empty($error)) { $validProcessors[$ppID] = $label; } $paymentObject = null; } } } if (empty($validProcessors)) { CRM_Core_Error::fatal(ts('Could not find valid payment processor for this page')); } else { $this->_processors = $validProcessors; } // also check for billing information // get the billing location type $locationTypes =& CRM_Core_PseudoConstant::locationType(); $this->_bltID = array_search('Billing', $locationTypes); if (!$this->_bltID) { CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing'))); } $this->set('bltID', $this->_bltID); $this->assign('bltID', $this->_bltID); $this->_fields = array(); require_once 'CRM/Core/Payment/Form.php'; CRM_Core_Payment_Form::setCreditCardFields($this); // this required to show billing block $this->assign_by_ref('paymentProcessor', $paymentProcessor); $this->assign('hidePayPalExpress', true); } if ($this->_showFeeBlock) { $this->assign('showFeeBlock', true); $this->assign('paid', true); return CRM_Event_Form_EventFees::preProcess($this); } //custom data related code $this->_cdType = CRM_Utils_Array::value('type', $_GET); $this->assign('cdType', false); if ($this->_cdType) { $this->assign('cdType', true); return CRM_Custom_Form_CustomData::preProcess($this); } //check the mode when this form is called either single or as //search task action if ($this->_participantId || $this->_contactID || $this->_context == 'standalone') { $this->_single = true; $this->assign('urlPath', 'civicrm/contact/view/participant'); if (!$this->_participantId && !$this->_contactID) { $breadCrumbs = array(array('title' => ts('CiviEvent Dashboard'), 'url' => CRM_Utils_System::url('civicrm/event', 'reset=1'))); CRM_Utils_System::appendBreadCrumb($breadCrumbs); } } else { //set the appropriate action $advanced = null; $builder = null; $session =& CRM_Core_Session::singleton(); $advanced = $session->get('isAdvanced'); $builder = $session->get('isSearchBuilder'); $searchType = "basic"; if ($advanced == 1) { $this->_action = CRM_Core_Action::ADVANCED; $searchType = "advanced"; } else { if ($advanced == 2 && ($builder = 1)) { $this->_action = CRM_Core_Action::PROFILE; $searchType = "builder"; } else { if ($advanced == 3) { $searchType = "custom"; } } } parent::preProcess(); $this->_single = false; $this->_contactID = null; //set ajax path, this used for custom data building $this->assign('urlPath', "civicrm/contact/search/{$searchType}"); $this->assign('urlPathVar', "_qf_Participant_display=true&qfKey={$this->controller->_key}"); } $this->assign('single', $this->_single); $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'add'); $this->assign('action', $this->_action); // check for edit permission if (!CRM_Core_Permission::checkActionPermission('CiviEvent', $this->_action)) { CRM_Core_Error::fatal(ts('You do not have permission to access this page')); } if ($this->_action & CRM_Core_Action::DELETE) { return; } if ($this->_participantId) { // assign participant id to the template $this->assign('participantId', $this->_participantId); $this->_roleId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Participant", $this->_participantId, 'role_id'); } // when fee amount is included in form if (CRM_Utils_Array::value('hidden_feeblock', $_POST) || CRM_Utils_Array::value('send_receipt', $_POST)) { CRM_Event_Form_EventFees::preProcess($this); CRM_Event_Form_EventFees::buildQuickForm($this); CRM_Event_Form_EventFees::setDefaultValues($this); } // when custom data is included in this page if (CRM_Utils_Array::value("hidden_custom", $_POST)) { //custom data of type participant role CRM_Custom_Form_Customdata::preProcess($this, $this->_roleCustomDataTypeID, $_POST['role_id'], 1, 'Participant', $this->_participantId); CRM_Custom_Form_Customdata::buildQuickForm($this); CRM_Custom_Form_Customdata::setDefaultValues($this); //custom data of type participant event CRM_Custom_Form_Customdata::preProcess($this, $this->_eventNameCustomDataTypeID, $_POST['event_id'], 1, 'Participant', $this->_participantId); CRM_Custom_Form_Customdata::buildQuickForm($this); CRM_Custom_Form_Customdata::setDefaultValues($this); //custom data of type participant, ( we 'null' to reset subType and subName) CRM_Custom_Form_Customdata::preProcess($this, 'null', 'null', 1, 'Participant', $this->_participantId); CRM_Custom_Form_Customdata::buildQuickForm($this); CRM_Custom_Form_Customdata::setDefaultValues($this); } // CRM-4395, get the online pending contribution id. $this->_onlinePendingContributionId = null; if (!$this->_mode && $this->_participantId && $this->_action & CRM_Core_Action::UPDATE) { require_once 'CRM/Contribute/BAO/Contribution.php'; $this->_onlinePendingContributionId = CRM_Contribute_BAO_Contribution::checkOnlinePendingContribution($this->_participantId, 'Event'); } $this->set('onlinePendingContributionId', $this->_onlinePendingContributionId); }
/** * Check for presence of type 1 or type 3 enabled processors (means we can do back-office submit credit/debit card trxns) * @public */ static function allowBackofficeCreditCard($template = NULL, $variableName = 'newCredit') { $newCredit = FALSE; $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, "billing_mode IN ( 1, 3 )"); if (count($processors) > 0) { $newCredit = TRUE; } if ($template) { $template->assign($variableName, $newCredit); } return $newCredit; }
public function preProcess() { // check for edit permission if (!CRM_Core_Permission::check('edit memberships')) { CRM_Core_Error::fatal(ts('You do not have permission to access this page')); } // action $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'add'); $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this); if ($this->_id) { $this->_memType = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $this->_id, "membership_type_id"); } $this->assign("endDate", CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $this->_id, "end_date"))); $this->assign("membershipStatus", CRM_Core_DAO::getFieldValue("CRM_Member_DAO_MembershipStatus", CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $this->_id, "status_id"), "name")); $orgId = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_MembershipType", $this->_memType, "member_of_contact_id"); $this->assign("memType", CRM_Core_DAO::getFieldValue("CRM_Member_DAO_MembershipType", $this->_memType, "name")); $this->assign("orgName", CRM_Core_DAO::getFieldValue("CRM_Contact_DAO_Contact", $orgId, "display_name")); //using credit card :: CRM-2759 $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this); if ($this->_mode) { $membershipFee = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_MembershipType", $this->_memType, 'minimum_fee'); if (!$membershipFee) { $statusMsg = ts('Membership Renewal using credit card required Membership fee, since this memebrship type have no fee, you can use normal renew mode'); CRM_Core_Session::setStatus($statusMsg); CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/membership', "reset=1&action=renew&cid={$this->_contactID}&id={$this->_id}&context=membership")); } $this->assign('membershipMode', $this->_mode); $this->_paymentProcessor = array('billing_mode' => 1); $validProcessors = array(); $processors = CRM_Core_PseudoConstant::paymentProcessor(false, false, "billing_mode IN ( 1, 3 )"); foreach ($processors as $ppID => $label) { require_once 'CRM/Core/BAO/PaymentProcessor.php'; require_once 'CRM/Core/Payment.php'; $paymentProcessor =& CRM_Core_BAO_PaymentProcessor::getPayment($ppID, $this->_mode); if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) { continue; } else { if ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode == 'live') { continue; } else { $paymentObject =& CRM_Core_Payment::singleton($this->_mode, 'Contribute', $paymentProcessor, $this); $error = $paymentObject->checkConfig(); if (empty($error)) { $validProcessors[$ppID] = $label; } $paymentObject = null; } } } if (empty($validProcessors)) { CRM_Core_Error::fatal(ts('Could not find valid payment processor for this page')); } else { $this->_processors = $validProcessors; } // also check for billing information // get the billing location type $locationTypes =& CRM_Core_PseudoConstant::locationType(); $this->_bltID = array_search('Billing', $locationTypes); if (!$this->_bltID) { CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing'))); } $this->set('bltID', $this->_bltID); $this->assign('bltID', $this->_bltID); $this->_fields = array(); require_once 'CRM/Core/Payment/Form.php'; CRM_Core_Payment_Form::setCreditCardFields($this); // this required to show billing block $this->assign_by_ref('paymentProcessor', $paymentProcessor); $this->assign('hidePayPalExpress', true); } else { $this->assign('membershipMode', false); } parent::preProcess(); }
/** * returns all the rows in the given offset and rowCount * * @param enum $action the action being performed * @param int $offset the row number to start from * @param int $rowCount the number of rows to return * @param string $sort the sql string that describes the sort order * @param enum $output what should the result set include (web/email/csv) * * @return int the total number of rows for this action */ function &getRows($action, $offset, $rowCount, $sort, $output = null) { // check if we can process credit card registration require_once 'CRM/Core/PseudoConstant.php'; $processors = CRM_Core_PseudoConstant::paymentProcessor(false, false, "billing_mode IN ( 1, 3 )"); if (count($processors) > 0) { $this->_isPaymentProcessor = true; } else { $this->_isPaymentProcessor = false; } // Only show credit card membership signup and renewal if user has CiviContribute permission if (CRM_Core_Permission::access('CiviContribute')) { $this->_accessContribution = true; } else { $this->_accessContribution = false; } $result = $this->_query->searchQuery($offset, $rowCount, $sort, false, false, false, false, false, $this->_memberClause); // process the result of the query $rows = array(); //CRM-4418 check for view, edit, delete $permissions = array(CRM_Core_Permission::VIEW); if (CRM_Core_Permission::check('edit memberships')) { $permissions[] = CRM_Core_Permission::EDIT; } if (CRM_Core_Permission::check('delete in CiviMember')) { $permissions[] = CRM_Core_Permission::DELETE; } $mask = CRM_Core_Action::mask($permissions); while ($result->fetch()) { $row = array(); // the columns we are interested in foreach (self::$_properties as $property) { $row[$property] = $result->{$property}; } if ($row['member_is_test']) { $row['membership_type'] = $row['membership_type'] . " (test)"; } $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->membership_id; if (!isset($result->owner_membership_id)) { $row['action'] = CRM_Core_Action::formLink(self::links('all', $this->_isPaymentProcessor, $this->_accessContribution), $mask, array('id' => $result->membership_id, 'cid' => $result->contact_id, 'cxt' => $this->_context)); } else { $row['action'] = CRM_Core_Action::formLink(self::links('view'), $mask, array('id' => $result->membership_id, 'cid' => $result->contact_id, 'cxt' => $this->_context)); } require_once 'CRM/Contact/BAO/Contact/Utils.php'; $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type); $rows[] = $row; } return $rows; }
/** * Check for presence of type 1 or type 3 enabled processors (means we can do back-office submit credit/debit card trxns) * @public */ static function allowBackofficeCreditCard($template = NULL, $variableName = 'newCredit') { $newCredit = FALSE; // restrict to type=1 (credit card) payment processor payment_types and only include billing mode types 1 and 3 $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, "billing_mode IN ( 1, 3 ) AND payment_type = 1"); if (count($processors) > 0) { $newCredit = TRUE; } if ($template) { $template->assign($variableName, $newCredit); } return $newCredit; }
/** * Function to actually build the form * * @return void * @access public */ public function buildQuickForm() { require_once 'CRM/Member/BAO/MembershipType.php'; $membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypes(); if (!empty($membershipTypes)) { $this->addElement('checkbox', 'is_active', ts('Membership Section Enabled?'), null, array('onclick' => "memberBlock(this);")); $this->addElement('text', 'new_title', ts('Title - New Membership'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'new_title')); $this->addWysiwyg('new_text', ts('Introductory Message - New Memberships'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'new_text')); $this->addElement('text', 'renewal_title', ts('Title - Renewals'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'renewal_title')); $this->addWysiwyg('renewal_text', ts('Introductory Message - Renewals'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'renewal_text')); $this->addElement('checkbox', 'is_required', ts('Require Membership Signup')); $this->addElement('checkbox', 'display_min_fee', ts('Display Membership Fee')); $this->addElement('checkbox', 'is_separate_payment', ts('Separate Membership Payment')); $paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor(false, false, 'is_recur = 1'); $paymentProcessorId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'payment_processor_id'); $isRecur = false; $membership = array(); $membershipDefault = array(); foreach ($membershipTypes as $k => $v) { $membership[] = HTML_QuickForm::createElement('advcheckbox', $k, null, $v); $membershipDefault[] = HTML_QuickForm::createElement('radio', null, null, null, $k); if (is_array($paymentProcessor) && CRM_Utils_Array::value($paymentProcessorId, $paymentProcessor)) { $isRecur = true; $autoRenew = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $k, 'auto_renew'); $autoRenewOptions = array(); if ($autoRenew) { $autoRenewOptions = array(ts('Not offered'), ts('Give option'), ts('Required')); $this->addElement('select', "auto_renew_{$k}", ts('Auto-renew'), $autoRenewOptions); $this->_renewOption[$k] = $autoRenew; } } else { $isRecur = false; } } $this->assign('is_recur', $isRecur); $this->assign('auto_renew', $this->_renewOption); $this->addGroup($membership, 'membership_type', ts('Membership Types')); $this->addGroup($membershipDefault, 'membership_type_default', ts('Membership Types Default')); $this->addFormRule(array('CRM_Member_Form_MembershipBlock', 'formRule'), $this->_id); } $session = CRM_Core_Session::singleton(); $single = $session->get('singleForm'); if ($single) { $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => ' ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); } else { parent::buildQuickForm(); } //$session->set('single', false ); }
/** * undocumented function * * @return void **/ public function uninstall() { if (!array_key_exists($this->ext->key, $this->paymentProcessorTypes)) { CRM_Core_Error::fatal('This payment processor type is not registered.'); } require_once 'CRM/Core/PseudoConstant.php'; $paymentProcessors = CRM_Core_PseudoConstant::paymentProcessor(TRUE); require_once "CRM/Core/DAO/PaymentProcessor.php"; foreach ($paymentProcessors as $id => $name) { $dao = new CRM_Core_DAO_PaymentProcessor(); $dao->id = $id; $dao->find(); while ($dao->fetch()) { if ($dao->payment_processor_type == $this->ext->name) { CRM_Core_Error::fatal('Cannot uninstall this extension - there is at least one payment processor using payment processor type provided by it.'); } } } require_once "CRM/Core/BAO/PaymentProcessorType.php"; CRM_Core_BAO_PaymentProcessorType::del($this->paymentProcessorTypes[$this->ext->key]); }
/** * This function is the main function that is called when the page loads, it decides the which action has to be taken for the page. * * return null * @access public */ function run() { $this->preProcess(); // check if we can process credit card registration $processors = CRM_Core_PseudoConstant::paymentProcessor(false, false, "billing_mode IN ( 1, 3 )"); if (count($processors) > 0) { $this->assign('newCredit', true); } else { $this->assign('newCredit', false); } // Only show credit card registration button if user has CiviContribute permission if (CRM_Core_Permission::access('CiviContribute')) { $this->assign('accessContribution', true); } else { $this->assign('accessContribution', false); } $this->setContext(); if ($this->_action & CRM_Core_Action::VIEW) { $this->view(); } else { if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) { $this->edit(); } else { $this->browse(); } } return parent::run(); }
/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { $this->_showFeeBlock = CRM_Utils_Array::value('eventId', $_GET); $this->assign('showFeeBlock', FALSE); $this->assign('feeBlockPaid', FALSE); $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this); $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this); $this->_eID = CRM_Utils_Request::retrieve('eid', 'Positive', $this); $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this); $this->assign('context', $this->_context); if ($this->_contactId) { $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId); $this->assign('displayName', $displayName); // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container CRM_Utils_System::setTitle(ts('Event Registration for') . ' ' . $displayName); } // check the current path, if search based, then dont get participantID // CRM-5792 $path = CRM_Utils_System::currentPath(); if (strpos($path, 'civicrm/contact/search') === 0 || strpos($path, 'civicrm/group/search') === 0) { $this->_id = NULL; } else { $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); } if ($this->_id) { $this->_paymentId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'id', 'participant_id'); // CRM-12615 - Get payment information from the primary registration if (!$this->_paymentId && $this->_action == CRM_Core_Action::UPDATE) { $registered_by_id = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'registered_by_id', 'id'); if ($registered_by_id) { $this->_paymentId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $registered_by_id, 'id', 'participant_id'); $this->assign('registeredByParticipantId', $registered_by_id); } } } // get the option value for custom data type $this->_roleCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantRole', 'name'); $this->_eventNameCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventName', 'name'); $this->_eventTypeCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventType', 'name'); $this->assign('roleCustomDataTypeID', $this->_roleCustomDataTypeID); $this->assign('eventNameCustomDataTypeID', $this->_eventNameCustomDataTypeID); $this->assign('eventTypeCustomDataTypeID', $this->_eventTypeCustomDataTypeID); if ($this->_mode) { $this->assign('participantMode', $this->_mode); $this->_paymentProcessor = array('billing_mode' => 1); $validProcessors = array(); $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, "billing_mode IN ( 1, 3 )"); foreach ($processors as $ppID => $label) { $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($ppID, $this->_mode); if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) { continue; } elseif ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode == 'live') { continue; } else { $paymentObject = CRM_Core_Payment::singleton($this->_mode, $paymentProcessor, $this); $error = $paymentObject->checkConfig(); if (empty($error)) { $validProcessors[$ppID] = $label; } $paymentObject = NULL; } } if (empty($validProcessors)) { CRM_Core_Error::fatal(ts('Could not find valid payment processor for this page')); } else { $this->_processors = $validProcessors; } // also check for billing information // get the billing location type $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate'); // CRM-8108 remove ts around Billing location type //$this->_bltID = array_search( ts('Billing'), $locationTypes ); $this->_bltID = array_search('Billing', $locationTypes); if (!$this->_bltID) { CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing'))); } $this->set('bltID', $this->_bltID); $this->assign('bltID', $this->_bltID); $this->_fields = array(); CRM_Core_Payment_Form::setCreditCardFields($this); // this required to show billing block $this->assign_by_ref('paymentProcessor', $paymentProcessor); $this->assign('hidePayPalExpress', TRUE); } if ($this->_showFeeBlock) { $this->assign('showFeeBlock', TRUE); $isMonetary = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_showFeeBlock, 'is_monetary'); if ($isMonetary) { $this->assign('feeBlockPaid', TRUE); } return CRM_Event_Form_EventFees::preProcess($this); } //custom data related code $this->_cdType = CRM_Utils_Array::value('type', $_GET); $this->assign('cdType', FALSE); if ($this->_cdType) { $this->assign('cdType', TRUE); return CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, NULL, NULL, NULL, TRUE); } //check the mode when this form is called either single or as //search task action if ($this->_id || $this->_contactId || $this->_context == 'standalone') { $this->_single = TRUE; $this->assign('urlPath', 'civicrm/contact/view/participant'); if (!$this->_id && !$this->_contactId) { $breadCrumbs = array(array('title' => ts('CiviEvent Dashboard'), 'url' => CRM_Utils_System::url('civicrm/event', 'reset=1'))); CRM_Utils_System::appendBreadCrumb($breadCrumbs); } } else { //set the appropriate action $context = $this->get('context'); $urlString = 'civicrm/contact/search'; $this->_action = CRM_Core_Action::BASIC; switch ($context) { case 'advanced': $urlString = 'civicrm/contact/search/advanced'; $this->_action = CRM_Core_Action::ADVANCED; break; case 'builder': $urlString = 'civicrm/contact/search/builder'; $this->_action = CRM_Core_Action::PROFILE; break; case 'basic': $urlString = 'civicrm/contact/search/basic'; $this->_action = CRM_Core_Action::BASIC; break; case 'custom': $urlString = 'civicrm/contact/search/custom'; $this->_action = CRM_Core_Action::COPY; break; } parent::preProcess(); $this->_single = FALSE; $this->_contactId = NULL; //set ajax path, this used for custom data building $this->assign('urlPath', $urlString); $this->assign('urlPathVar', "_qf_Participant_display=true&qfKey={$this->controller->_key}"); } $this->assign('single', $this->_single); if (!$this->_id) { $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add'); } $this->assign('action', $this->_action); // check for edit permission if (!CRM_Core_Permission::checkActionPermission('CiviEvent', $this->_action)) { CRM_Core_Error::fatal(ts('You do not have permission to access this page')); } if ($this->_action & CRM_Core_Action::DELETE) { // check delete permission for contribution if ($this->_id && $this->_paymentId && !CRM_Core_Permission::checkActionPermission('CiviContribute', $this->_action)) { CRM_Core_Error::fatal(ts("This Participant is linked to a contribution. You must have 'delete in CiviContribute' permission in order to delete this record.")); } return; } if ($this->_id) { // assign participant id to the template $this->assign('participantId', $this->_id); $this->_roleId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'role_id'); } // when fee amount is included in form if (CRM_Utils_Array::value('hidden_feeblock', $_POST) || CRM_Utils_Array::value('send_receipt', $_POST)) { CRM_Event_Form_EventFees::preProcess($this); CRM_Event_Form_EventFees::buildQuickForm($this); CRM_Event_Form_EventFees::setDefaultValues($this); } // when custom data is included in this page if (CRM_Utils_Array::value('hidden_custom', $_POST)) { //custom data of type participant role if (CRM_Utils_Array::value('role_id', $_POST)) { foreach ($_POST['role_id'] as $k => $val) { $roleID = $val; CRM_Custom_Form_CustomData::preProcess($this, $this->_roleCustomDataTypeID, $k, 1, 'Participant', $this->_id); CRM_Custom_Form_CustomData::buildQuickForm($this); CRM_Custom_Form_CustomData::setDefaultValues($this); } } //custom data of type participant event CRM_Custom_Form_CustomData::preProcess($this, $this->_eventNameCustomDataTypeID, $_POST['event_id'], 1, 'Participant', $this->_id); CRM_Custom_Form_CustomData::buildQuickForm($this); CRM_Custom_Form_CustomData::setDefaultValues($this); // custom data of type participant event type $eventTypeId = NULL; if ($eventId = CRM_Utils_Array::value('event_id', $_POST)) { $eventTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventId, 'event_type_id', 'id'); } CRM_Custom_Form_CustomData::preProcess($this, $this->_eventTypeCustomDataTypeID, $eventTypeId, 1, 'Participant', $this->_id); CRM_Custom_Form_CustomData::buildQuickForm($this); CRM_Custom_Form_CustomData::setDefaultValues($this); //custom data of type participant, ( we 'null' to reset subType and subName) CRM_Custom_Form_CustomData::preProcess($this, 'null', 'null', 1, 'Participant', $this->_id); CRM_Custom_Form_CustomData::buildQuickForm($this); CRM_Custom_Form_CustomData::setDefaultValues($this); } // CRM-4395, get the online pending contribution id. $this->_onlinePendingContributionId = NULL; if (!$this->_mode && $this->_id && $this->_action & CRM_Core_Action::UPDATE) { $this->_onlinePendingContributionId = CRM_Contribute_BAO_Contribution::checkOnlinePendingContribution($this->_id, 'Event'); } $this->set('onlinePendingContributionId', $this->_onlinePendingContributionId); $roleIds = CRM_Event_PseudoConstant::participantRole(); if (!empty($roleIds)) { $query = "\nSELECT civicrm_custom_group.name as name,\n civicrm_custom_group.id as id,\n extends_entity_column_value as value\n FROM civicrm_custom_group\n WHERE ( extends_entity_column_value REGEXP '[[:<:]]" . implode('[[:>:]]|[[:<:]]', array_keys($roleIds)) . "[[:>:]]'\n OR extends_entity_column_value IS NULL )\n AND extends_entity_column_id = '{$this->_roleCustomDataTypeID}'\n AND extends = 'Participant'\n AND is_active = 1"; $dao = CRM_Core_DAO::executeQuery($query); while ($dao->fetch()) { if ($dao->value) { $getRole = explode(CRM_Core_DAO::VALUE_SEPARATOR, $dao->value); foreach ($getRole as $r) { if (!$r) { continue; } if (isset($this->_participantRoleIds[$r])) { $this->_participantRoleIds[$r] .= ',' . $dao->name; } else { $this->_participantRoleIds[$r] = $dao->name; } } } else { if (isset($this->_participantRoleIds[0])) { $this->_participantRoleIds[0] .= ',' . $dao->name; } else { $this->_participantRoleIds[0] = $dao->name; } } } $dao->free(); } foreach ($roleIds as $k => $v) { if (!isset($this->_participantRoleIds[$k])) { $this->_participantRoleIds[$k] = ''; } } $this->assign('participantRoleIds', $this->_participantRoleIds); }
/** * Build the form object. * * @return void */ public function buildQuickForm() { if ($this->_cdType) { return CRM_Custom_Form_CustomData::buildQuickForm($this); } parent::buildQuickForm(); $defaults = parent::setDefaultValues(); $this->_memType = $defaults['membership_type_id']; $this->assign('customDataType', 'Membership'); $this->assign('customDataSubType', $this->_memType); $this->assign('entityID', $this->_id); $selOrgMemType[0][0] = $selMemTypeOrg[0] = ts('- select -'); $allMemberships = CRM_Member_BAO_Membership::buildMembershipTypeValues($this); $allMembershipInfo = $membershipType = array(); //CRM-16950 $taxRates = CRM_Core_PseudoConstant::getTaxRates(); $taxRate = CRM_Utils_Array::value($allMemberships[$defaults['membership_type_id']]['financial_type_id'], $taxRates); $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings'); // auto renew options if enabled for the membership $options = CRM_Core_SelectValues::memberAutoRenew(); foreach ($allMemberships as $key => $values) { if (!empty($values['is_active'])) { $membershipType[$key] = CRM_Utils_Array::value('name', $values); if ($this->_mode && empty($values['minimum_fee'])) { continue; } else { $memberOfContactId = CRM_Utils_Array::value('member_of_contact_id', $values); if (empty($selMemTypeOrg[$memberOfContactId])) { $selMemTypeOrg[$memberOfContactId] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $memberOfContactId, 'display_name', 'id'); $selOrgMemType[$memberOfContactId][0] = ts('- select -'); } if (empty($selOrgMemType[$memberOfContactId][$key])) { $selOrgMemType[$memberOfContactId][$key] = CRM_Utils_Array::value('name', $values); } } //CRM-16950 $taxAmount = NULL; $totalAmount = CRM_Utils_Array::value('minimum_fee', $values); if (CRM_Utils_Array::value($values['financial_type_id'], $taxRates)) { $taxAmount = $taxRate / 100 * CRM_Utils_Array::value('minimum_fee', $values); $totalAmount = $totalAmount + $taxAmount; } // build membership info array, which is used to set the payment information block when // membership type is selected. $allMembershipInfo[$key] = array('financial_type_id' => CRM_Utils_Array::value('financial_type_id', $values), 'total_amount' => CRM_Utils_Money::format($totalAmount, NULL, '%a'), 'total_amount_numeric' => $totalAmount, 'tax_message' => $taxAmount ? ts("Includes %1 amount of %2", array(1 => CRM_Utils_Array::value('tax_term', $invoiceSettings), 2 => CRM_Utils_Money::format($taxAmount))) : $taxAmount); if (!empty($values['auto_renew'])) { $allMembershipInfo[$key]['auto_renew'] = $options[$values['auto_renew']]; } } } $this->assign('allMembershipInfo', json_encode($allMembershipInfo)); if ($this->_memType) { $this->assign('orgName', $selMemTypeOrg[$allMemberships[$this->_memType]['member_of_contact_id']]); $this->assign('memType', $allMemberships[$this->_memType]['name']); } // force select of 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; } $js = array('onChange' => "setPaymentBlock( ); CRM.buildCustomData( 'Membership', this.value );"); //build the form for auto renew. $recurProcessor = array(); if ($this->_mode || $this->_action & CRM_Core_Action::UPDATE) { //get the valid recurring processors. $test = strtolower($this->_mode) == 'test' ? TRUE : FALSE; $recurring = CRM_Core_PseudoConstant::paymentProcessor(FALSE, $test, 'is_recur = 1'); $recurProcessor = array_intersect_key($this->_processors, $recurring); if (!empty($recurProcessor)) { $autoRenew = array(); 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}; } } } $js = array('onChange' => "setPaymentBlock(); CRM.buildCustomData( 'Membership', this.value );"); $this->assign('autoRenew', json_encode($autoRenew)); } $autoRenewElement = $this->addElement('checkbox', 'auto_renew', ts('Membership renewed automatically'), NULL, array('onclick' => "showHideByValue('auto_renew','','send-receipt','table-row','radio',true); showHideNotice( );")); if ($this->_action & CRM_Core_Action::UPDATE) { $autoRenewElement->freeze(); } } $this->assign('recurProcessor', json_encode($recurProcessor)); $sel =& $this->addElement('hierselect', 'membership_type_id', ts('Renewal Membership Organization and Type'), $js); $sel->setOptions(array($selMemTypeOrg, $selOrgMemType)); $elements = array(); if ($sel) { $elements[] = $sel; } $this->applyFilter('__ALL__', 'trim'); $this->addDate('renewal_date', ts('Date Renewal Entered'), FALSE, array('formatType' => 'activityDate')); $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType()); if (CRM_Core_Permission::access('CiviContribute') && !$this->_mode) { $this->addElement('checkbox', 'record_contribution', ts('Record Renewal Payment?'), NULL, array('onclick' => "checkPayment();")); $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' => 'activityDateTime')); $this->add('text', 'num_terms', ts('Extend Membership by'), array('onchange' => "setPaymentBlock();"), TRUE); $this->addRule('num_terms', ts('Please enter a whole number for how many periods to renew.'), 'integer'); $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')); $this->add('select', 'contribution_status_id', ts('Payment Status'), CRM_Contribute_PseudoConstant::contributionStatus()); $this->add('text', 'check_number', ts('Check Number'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'check_number')); } else { $this->add('text', 'total_amount', ts('Amount')); $this->addRule('total_amount', ts('Please enter a valid amount.'), 'money'); } $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_renewal', ts('Renewal Message')); // Retrieve the name and email of the contact - this will be the TO for receipt email list($this->_contributorDisplayName, $this->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID); $this->assign('email', $this->_contributorEmail); $mailingInfo = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend'); $this->assign('outBound_option', $mailingInfo['outBound_option']); if (CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'contribution_recur_id')) { if (CRM_Member_BAO_Membership::isCancelSubscriptionSupported($this->_id)) { $this->assign('cancelAutoRenew', CRM_Utils_System::url('civicrm/contribute/unsubscribe', "reset=1&mid={$this->_id}")); } } $this->addFormRule(array('CRM_Member_Form_MembershipRenewal', 'formRule')); 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', 'contribution_contact', ts('Record Payment from a Different Contact?')); $this->addSelect('soft_credit_type_id', array('entity' => 'contribution_soft')); $this->addEntityRef('soft_credit_contact_id', ts('Payment From'), array('create' => TRUE)); } }
/** * This function is the main function that is called when the page * loads, it decides the which action has to be taken for the page. * * return null * @access public */ function run() { $this->preProcess(); // check if we can process credit card contribs $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, "billing_mode IN ( 1, 3 )"); if (count($processors) > 0) { $this->assign('newCredit', TRUE); } else { $this->assign('newCredit', FALSE); } $this->setContext(); if ($this->_action & CRM_Core_Action::VIEW) { $this->view(); } elseif ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) { $this->edit(); } else { $this->browse(); } return parent::run(); }
/** * Assign $this->processors, $this->recurPaymentProcessors, and related Smarty variables */ public function assignProcessors() { //ensure that processor has a valid config //only valid processors get display to user if ($this->_mode) { list($this->_processors, $paymentProcessor) = $this->getValidProcessorsAndAssignFutureStartDate(); //get the valid recurring processors. $recurring = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'is_recur = 1'); $this->_recurPaymentProcessors = array_intersect_assoc($this->_processors, $recurring); } $this->assign('recurringPaymentProcessorIds', empty($this->_recurPaymentProcessors) ? '' : implode(',', array_keys($this->_recurPaymentProcessors))); // this required to show billing block $this->assign_by_ref('paymentProcessor', $paymentProcessor); $this->assign('hidePayPalExpress', TRUE); }
/** * Build the form object. * * @return void */ 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->addSelect('duration_unit', array(), TRUE); //period type $this->addSelect('period_type', array(), TRUE); $this->add('text', 'duration_interval', ts('Duration Interval'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'duration_interval')); $props = array('api' => array('params' => array('contact_type' => 'Organization'))); $this->addEntityRef('member_of_contact_id', ts('Membership Organization'), $props, TRUE); //start day $this->add('date', 'fixed_period_start_day', ts('Fixed Period Start Day'), CRM_Core_SelectValues::date(NULL, 'M d'), FALSE); //Auto-renew Option $paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'is_recur = 1'); $isAuthorize = FALSE; $options = array(); if (is_array($paymentProcessor) && !empty($paymentProcessor)) { $isAuthorize = TRUE; $options = CRM_Core_SelectValues::memberAutoRenew(); } $this->addRadio('auto_renew', ts('Auto-renew Option'), $options); $this->assign('authorize', $isAuthorize); //rollover day $this->add('date', 'fixed_period_rollover_day', ts('Fixed Period Rollover Day'), CRM_Core_SelectValues::date(NULL, 'M d'), FALSE); $this->add('date', 'month_fixed_period_rollover_day', ts('Fixed Period Rollover Day'), CRM_Core_SelectValues::date(NULL, 'd'), FALSE); $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, $this->_action), TRUE, array('class' => 'crm-select2')); $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'), $relTypeInd, FALSE, array('class' => 'crm-select2 huge', 'multiple' => 1)); $this->addSelect('visibility', array('placeholder' => NULL, 'option_url' => NULL)); $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'weight')); $this->add('checkbox', 'is_active', ts('Enabled?')); $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(); } } $this->assign('membershipRecordsExists', $membershipRecords); $this->add('text', 'max_related', ts('Max related'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'max_related')); $this->addFormRule(array('CRM_Member_Form_MembershipType', 'formRule')); $this->assign('membershipTypeId', $this->_id); }
/** * Function to actually build the form * * @return void * @access public */ public function buildQuickForm() { // do u want to allow a free form text field for amount $this->addElement('checkbox', 'is_allow_other_amount', ts('Allow other amounts'), NULL, array('onclick' => "minMax(this);showHideAmountBlock( this, 'is_allow_other_amount' );")); $this->add('text', 'min_amount', ts('Minimum Amount'), array('size' => 8, 'maxlength' => 8)); $this->addRule('min_amount', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('9.99', ' '))), 'money'); $this->add('text', 'max_amount', ts('Maximum Amount'), array('size' => 8, 'maxlength' => 8)); $this->addRule('max_amount', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money'); $default = array(); $this->add('hidden', "price_field_id", '', array('id' => "price_field_id")); $this->add('hidden', "price_field_other", '', array('id' => "price_field_option")); for ($i = 1; $i <= self::NUM_OPTION; $i++) { // label $this->add('text', "label[{$i}]", ts('Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'label')); $this->add('hidden', "price_field_value[{$i}]", '', array('id' => "price_field_value[{$i}]")); // value $this->add('text', "value[{$i}]", ts('Value'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'value')); $this->addRule("value[{$i}]", ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money'); // default $default[] = $this->createElement('radio', NULL, NULL, NULL, $i); } $this->addGroup($default, 'default'); $this->addElement('checkbox', 'amount_block_is_active', ts('Contribution Amounts section enabled'), NULL, array('onclick' => "showHideAmountBlock( this, 'amount_block_is_active' );")); $this->addElement('checkbox', 'is_monetary', ts('Execute real-time monetary transactions')); $paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor(); $recurringPaymentProcessor = array(); if (!empty($paymentProcessor)) { $paymentProcessorIds = implode(',', array_keys($paymentProcessor)); $query = "\nSELECT id\n FROM civicrm_payment_processor\n WHERE id IN ({$paymentProcessorIds})\n AND is_recur = 1"; $dao = CRM_Core_DAO::executeQuery($query); while ($dao->fetch()) { $recurringPaymentProcessor[] = $dao->id; } } $this->assign('recurringPaymentProcessor', $recurringPaymentProcessor); if (count($paymentProcessor)) { $this->assign('paymentProcessor', $paymentProcessor); } $this->addCheckBox('payment_processor', ts('Payment Processor'), array_flip($paymentProcessor), NULL, NULL, NULL, NULL, array(' ', ' ', ' ', '<br/>')); //check if selected payment processor supports recurring payment if (!empty($recurringPaymentProcessor)) { $this->addElement('checkbox', 'is_recur', ts('Recurring contributions'), NULL, array('onclick' => "showHideByValue('is_recur',true,'recurFields','table-row','radio',false); showRecurInterval( );")); $this->addCheckBox('recur_frequency_unit', ts('Supported recurring units'), CRM_Core_OptionGroup::values('recur_frequency_units', FALSE, FALSE, FALSE, NULL, 'name'), NULL, NULL, NULL, NULL, array(' ', ' ', ' ', '<br/>')); $this->addElement('checkbox', 'is_recur_interval', ts('Support recurring intervals')); } // add pay later options $this->addElement('checkbox', 'is_pay_later', ts('Pay later option'), NULL, array('onclick' => "payLater(this);")); $this->addElement('textarea', 'pay_later_text', ts('Pay later label'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'pay_later_text'), FALSE); $this->addElement('textarea', 'pay_later_receipt', ts('Pay later instructions'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'pay_later_receipt'), FALSE); // add price set fields $price = CRM_Price_BAO_Set::getAssoc(FALSE, 'CiviContribute'); if (CRM_Utils_System::isNull($price)) { $this->assign('price', FALSE); } else { $this->assign('price', TRUE); } $this->add('select', 'price_set_id', ts('Price Set'), array('' => ts('- none -')) + $price, NULL, array('onchange' => "showHideAmountBlock( this.value, 'price_set_id' );")); //CiviPledge fields. $config = CRM_Core_Config::singleton(); if (in_array('CiviPledge', $config->enableComponents)) { $this->assign('civiPledge', TRUE); $this->addElement('checkbox', 'is_pledge_active', ts('Pledges'), NULL, array('onclick' => "showHideAmountBlock( this, 'is_pledge_active' ); return showHideByValue('is_pledge_active',true,'pledgeFields','table-row','radio',false);")); $this->addCheckBox('pledge_frequency_unit', ts('Supported pledge frequencies'), CRM_Core_OptionGroup::values('recur_frequency_units', FALSE, FALSE, FALSE, NULL, 'name'), NULL, NULL, NULL, NULL, array(' ', ' ', ' ', '<br/>')); $this->addElement('checkbox', 'is_pledge_interval', ts('Allow frequency intervals')); $this->addElement('text', 'initial_reminder_day', ts('Send payment reminder'), array('size' => 3)); $this->addElement('text', 'max_reminders', ts('Send up to'), array('size' => 3)); $this->addElement('text', 'additional_reminder_day', ts('Send additional reminders'), array('size' => 3)); } //add currency element. $this->addCurrency('currency', ts('Currency')); $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Amount', 'formRule'), $this); parent::buildQuickForm(); }
/** * Build the form object. * * @return void */ public function buildQuickForm() { $membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypes(); if (!empty($membershipTypes)) { $this->addElement('checkbox', 'member_is_active', ts('Membership Section Enabled?')); $this->addElement('text', 'new_title', ts('Title - New Membership'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'new_title')); $this->add('wysiwyg', 'new_text', ts('Introductory Message - New Memberships'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'new_text')); $this->addElement('text', 'renewal_title', ts('Title - Renewals'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'renewal_title')); $this->add('wysiwyg', 'renewal_text', ts('Introductory Message - Renewals'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'renewal_text')); $this->addElement('checkbox', 'is_required', ts('Require Membership Signup')); $this->addElement('checkbox', 'display_min_fee', ts('Display Membership Fee')); $this->addElement('checkbox', 'is_separate_payment', ts('Separate Membership Payment')); $this->addElement('text', 'membership_type_label', ts('Membership Types Label'), array('placeholder' => ts('Membership'))); $paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'is_recur = 1'); $paymentProcessorIds = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'payment_processor'); $paymentProcessorId = explode(CRM_Core_DAO::VALUE_SEPARATOR, $paymentProcessorIds); $isRecur = TRUE; foreach ($paymentProcessorId as $dontCare => $id) { if (!array_key_exists($id, $paymentProcessor)) { $isRecur = FALSE; continue; } } $membership = $membershipDefault = $params = array(); foreach ($membershipTypes as $k => $v) { $membership[] = $this->createElement('advcheckbox', $k, NULL, $v); $membershipDefault[] = $this->createElement('radio', NULL, NULL, NULL, $k); $membershipRequired[$k] = NULL; if ($isRecur) { $autoRenew = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $k, 'auto_renew'); $membershipRequired[$k] = $autoRenew; $autoRenewOptions = array(); if ($autoRenew) { $autoRenewOptions = array(ts('Not offered'), ts('Give option'), ts('Required')); $this->addElement('select', "auto_renew_{$k}", ts('Auto-renew'), $autoRenewOptions); //CRM-15573 if ($autoRenew == 2) { $this->freeze("auto_renew_{$k}"); $params['id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipBlock', $this->_id, 'id', 'entity_id'); } $this->_renewOption[$k] = $autoRenew; } } } //CRM-15573 if (!empty($params['id'])) { $params['membership_types'] = serialize($membershipRequired); CRM_Member_BAO_MembershipBlock::create($params); } $this->add('hidden', "mem_price_field_id", '', array('id' => "mem_price_field_id")); $this->assign('is_recur', $isRecur); if (isset($this->_renewOption)) { $this->assign('auto_renew', $this->_renewOption); } $this->addGroup($membership, 'membership_type', ts('Membership Types')); $this->addGroup($membershipDefault, 'membership_type_default', ts('Membership Types Default'))->setAttribute('allowClear', TRUE); $this->addFormRule(array('CRM_Member_Form_MembershipBlock', 'formRule'), $this->_id); } $price = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviMember'); if (CRM_Utils_System::isNull($price)) { $this->assign('price', FALSE); } else { $this->assign('price', TRUE); } $this->add('select', 'member_price_set_id', ts('Membership Price Set'), array('' => ts('- none -')) + $price); $session = CRM_Core_Session::singleton(); $single = $session->get('singleForm'); if ($single) { $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); } else { parent::buildQuickForm(); } }
/** * Build the form object. * * @return void */ public function buildQuickForm() { if ($this->_cdType) { return CRM_Custom_Form_CustomData::buildQuickForm($this); } $this->assign('taxRates', json_encode(CRM_Core_PseudoConstant::getTaxRates())); $config = CRM_Core_Config::singleton(); $this->assign('currency', $config->defaultCurrencySymbol); $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings'); $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings); if (isset($invoicing)) { $this->assign('taxTerm', CRM_Utils_Array::value('tax_term', $invoiceSettings)); } // build price set form. $buildPriceSet = FALSE; if ($this->_priceSetId || !empty($_POST['price_set_id'])) { if (!empty($_POST['price_set_id'])) { $buildPriceSet = TRUE; } $getOnlyPriceSetElements = TRUE; if (!$this->_priceSetId) { $this->_priceSetId = $_POST['price_set_id']; $getOnlyPriceSetElements = FALSE; } $this->set('priceSetId', $this->_priceSetId); CRM_Price_BAO_PriceSet::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_PriceSet::checkAutoRenewForPriceSet($this->_priceSetId)); $this->assign('optionsMembershipTypes', $optionsMembershipTypes); $this->assign('contributionType', CRM_Utils_Array::value('financial_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_PriceSet::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' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } if ($this->_context == 'standalone') { $this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE, 'api' => array('extra' => array('email'))), TRUE); } $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 (!empty($values['is_active'])) { $membershipType[$key] = CRM_Utils_Array::value('name', $values); if ($this->_mode && empty($values['minimum_fee'])) { continue; } else { $memberOfContactId = CRM_Utils_Array::value('member_of_contact_id', $values); if (empty($selMemTypeOrg[$memberOfContactId])) { $selMemTypeOrg[$memberOfContactId] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $memberOfContactId, 'display_name', 'id'); $selOrgMemType[$memberOfContactId][0] = ts('- select -'); } if (empty($selOrgMemType[$memberOfContactId][$key])) { $selOrgMemType[$memberOfContactId][$key] = CRM_Utils_Array::value('name', $values); } } // build membership info array, which is used when membership type is selected to: // - set the payment information block // - set the max related block $allMembershipInfo[$key] = array('financial_type_id' => CRM_Utils_Array::value('financial_type_id', $values), 'total_amount' => CRM_Utils_Money::format($values['minimum_fee'], NULL, '%a'), 'total_amount_numeric' => CRM_Utils_Array::value('minimum_fee', $values), 'auto_renew' => CRM_Utils_Array::value('auto_renew', $values), 'has_related' => isset($values['relationship_type_id']), 'max_related' => CRM_Utils_Array::value('max_related', $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' => "CRM.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. $test = strtolower($this->_mode) == 'test' ? TRUE : FALSE; $recurring = CRM_Core_PseudoConstant::paymentProcessor(FALSE, $test, 'is_recur = 1'); $recurProcessor = array_intersect_key($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' => "CRM.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)); // for max_related: a little JS to show/hide & set default value $memTypeJs['onChange'] = "buildMaxRelated(this.value,true); " . $memTypeJs['onChange']; $this->add('text', 'max_related', ts('Max related'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_Membership', 'max_related')); $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'); if ($this->_action & CRM_Core_Action::ADD) { $this->add('text', 'num_terms', ts('Number of Terms'), array('size' => 6)); } $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('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' => 'activityDateTime')); $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')); } $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType()); //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->addSelect('soft_credit_type_id', array('entity' => 'contribution_soft')); $this->addEntityRef('soft_credit_contact_id', ts('Payment From'), array('create' => TRUE)); $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')); // 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(); }
/** * Assign $this->processors, $this->recurPaymentProcessors, and related Smarty variables */ public function assignProcessors() { //ensure that processor has a valid config //only valid processors get display to user if ($this->_mode) { $this->assign('processorSupportsFutureStartDate', CRM_Financial_BAO_PaymentProcessor::hasPaymentProcessorSupporting(array('supportsFutureRecurStartDate'))); $this->_paymentProcessors = $this->getValidProcessors(); if (!isset($this->_paymentProcessor['id'])) { // if the payment processor isn't set yet (as indicated by the presence of an id,) we'll grab the first one which should be the default $this->_paymentProcessor = reset($this->_paymentProcessors); } if (empty($this->_paymentProcessors)) { throw new CRM_Core_Exception(ts('You will need to configure the %1 settings for your Payment Processor before you can submit a credit card transactions.', array(1 => $this->_mode))); } $this->_processors = array(); foreach ($this->_paymentProcessors as $id => $processor) { $this->_processors[$id] = ts($processor['name']); if (!empty($processor['description'])) { $this->_processors[$id] .= ' : ' . ts($processor['description']); } } //get the valid recurring processors. $test = strtolower($this->_mode) == 'test' ? TRUE : FALSE; $recurring = CRM_Core_PseudoConstant::paymentProcessor(FALSE, $test, 'is_recur = 1'); $this->_recurPaymentProcessors = array_intersect_key($this->_processors, $recurring); } $this->assign('recurringPaymentProcessorIds', empty($this->_recurPaymentProcessors) ? '' : implode(',', array_keys($this->_recurPaymentProcessors))); // this required to show billing block // @todo remove this assignment the billing block is now designed to be always included but will not show fieldsets unless those sets of fields are assigned $this->assign_by_ref('paymentProcessor', $processor); }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { require_once 'CRM/Utils/Money.php'; $this->addYesNo('is_monetary', ts('Paid Event'), null, null, array('onclick' => "return showHideByValue('is_monetary','0','event-fees','block','radio',false);")); require_once 'CRM/Contribute/PseudoConstant.php'; $paymentProcessor =& CRM_Core_PseudoConstant::paymentProcessor(); $this->assign('paymentProcessor', $paymentProcessor); $this->add('select', 'payment_processor_id', ts('Payment Processor'), array('' => ts('- select -')) + $paymentProcessor); $this->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType()); // add pay later options $this->addElement('checkbox', 'is_pay_later', ts('Enable Pay Later option?'), null, array('onclick' => "return showHideByValue('is_pay_later','','payLaterOptions','block','radio',false);")); $this->addElement('textarea', 'pay_later_text', ts('Pay Later Label'), CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'pay_later_text'), false); $this->addElement('textarea', 'pay_later_receipt', ts('Pay Later Instructions'), CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'pay_later_receipt'), false); $this->add('text', 'fee_label', ts('Fee Label')); require_once 'CRM/Price/BAO/Set.php'; $this->add('select', 'price_set_id', ts('Price Set'), array('' => ts('- none -')) + CRM_Price_BAO_Set::getAssoc(false, 'Event'), null, array('onchange' => "return showHideByValue('price_set_id', '', 'map-field', 'block', 'select', false);")); $default = array(); for ($i = 1; $i <= self::NUM_OPTION; $i++) { // label $this->add('text', "label[{$i}]", ts('Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'label')); // value $this->add('text', "value[{$i}]", ts('Value'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'value')); $this->addRule("value[{$i}]", ts('Please enter a valid money value for this field (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money'); // default $default[] = $this->createElement('radio', null, null, null, $i); } $this->addGroup($default, 'default'); $this->addElement('checkbox', 'is_discount', ts('Discounts by Signup Date?'), null, array('onclick' => "warnDiscountDel(); return showHideByValue('is_discount','','discount','block','radio',false);")); $discountSection = $this->get('discountSection'); $this->assign('discountSection', $discountSection); require_once 'CRM/Core/ShowHideBlocks.php'; // form fields of Discount sets $defaultOption = array(); $_showHide =& new CRM_Core_ShowHideBlocks('', ''); for ($i = 1; $i <= self::NUM_DISCOUNT; $i++) { //the show hide blocks $showBlocks = 'discount_' . $i; if ($i > 2) { $_showHide->addHide($showBlocks); } else { $_showHide->addShow($showBlocks); } //Increment by 1 of start date of previous end date. if (is_array($this->_submitValues) && !empty($this->_submitValues['discount_name'][$i]) && !empty($this->_submitValues['discount_name'][$i + 1]) && isset($this->_submitValues['discount_end_date']) && isset($this->_submitValues['discount_end_date'][$i]) && array_values($this->_submitValues['discount_end_date'][$i]) && $i < self::NUM_DISCOUNT - 1) { $end_date = CRM_Utils_Date::format($this->_submitValues['discount_end_date'][$i], '-'); if (!empty($this->_submitValues['discount_end_date'][$i + 1]['M']) && empty($this->_submitValues['discount_start_date'][$i + 1]['M'])) { $this->_submitValues['discount_start_date'][$i + 1] = CRM_Utils_Date::unformat(date('Y-m-d', strtotime("+1 days {$end_date}"))); } } //Decrement by 1 of end date from next start date. if ($i > 1 && is_array($this->_submitValues) && !empty($this->_submitValues['discount_name'][$i]) && !empty($this->_submitValues['discount_name'][$i - 1]) && isset($this->_submitValues['discount_start_date']) && isset($this->_submitValues['discount_start_date'][$i]) && array_values($this->_submitValues['discount_start_date'][$i])) { $start_date = CRM_Utils_Date::format($this->_submitValues['discount_start_date'][$i], '-'); if (!empty($this->_submitValues['discount_start_date'][$i]['M']) && empty($this->_submitValues['discount_end_date'][$i - 1]['M'])) { $this->_submitValues['discount_end_date'][$i - 1] = CRM_Utils_Date::unformat(date('Y-m-d', strtotime("-1 days {$start_date}"))); } } //discount name $this->add('text', 'discount_name[' . $i . ']', ts('Discount Name'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'label')); //discount start date $this->add('date', 'discount_start_date[' . $i . ']', ts('Discount Start Date'), CRM_Core_SelectValues::date('activityDate')); //discount end date $this->add('date', 'discount_end_date[' . $i . ']', ts('Discount End Date'), CRM_Core_SelectValues::date('activityDate')); } $_showHide->addToTemplate(); $this->addElement('submit', $this->getButtonName('submit'), ts('Add Discount Set to Fee Table'), array('class' => 'form-submit')); $this->buildAmountLabel(); parent::buildQuickForm(); }
/** * returns all the rows in the given offset and rowCount * * @param enum $action the action being performed * @param int $offset the row number to start from * @param int $rowCount the number of rows to return * @param string $sort the sql string that describes the sort order * @param enum $output what should the result set include (web/email/csv) * * @return int the total number of rows for this action */ function &getRows($action, $offset, $rowCount, $sort, $output = NULL) { // check if we can process credit card registration $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, "billing_mode IN ( 1, 3 )"); if (count($processors) > 0) { $this->_isPaymentProcessor = TRUE; } else { $this->_isPaymentProcessor = FALSE; } // Only show credit card membership signup and renewal if user has CiviContribute permission if (CRM_Core_Permission::access('CiviContribute')) { $this->_accessContribution = TRUE; } else { $this->_accessContribution = FALSE; } //get all campaigns. $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE); $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_memberClause); // process the result of the query $rows = array(); //CRM-4418 check for view, edit, delete $permissions = array(CRM_Core_Permission::VIEW); if (CRM_Core_Permission::check('edit memberships')) { $permissions[] = CRM_Core_Permission::EDIT; } if (CRM_Core_Permission::check('delete in CiviMember')) { $permissions[] = CRM_Core_Permission::DELETE; } $mask = CRM_Core_Action::mask($permissions); while ($result->fetch()) { $row = array(); // the columns we are interested in foreach (self::$_properties as $property) { if (property_exists($result, $property)) { $row[$property] = $result->{$property}; } } //carry campaign on selectors. $row['campaign'] = CRM_Utils_Array::value($result->member_campaign_id, $allCampaigns); $row['campaign_id'] = $result->member_campaign_id; if (!empty($row['member_is_test'])) { $row['membership_type'] = $row['membership_type'] . " (test)"; } $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->membership_id; if (!isset($result->owner_membership_id)) { // unset renew and followup link for deceased membership $currentMask = $mask; if ($result->membership_status == 'Deceased') { $currentMask = $currentMask & ~CRM_Core_Action::RENEW & ~CRM_Core_Action::FOLLOWUP; } $isCancelSupported = CRM_Member_BAO_Membership::isCancelSubscriptionSupported($row['membership_id']); $row['action'] = CRM_Core_Action::formLink(self::links('all', $this->_isPaymentProcessor, $this->_accessContribution, $this->_key, $this->_context, $isCancelSupported), $currentMask, array('id' => $result->membership_id, 'cid' => $result->contact_id, 'cxt' => $this->_context), ts('more'), FALSE, 'membership.selector.row', 'Membership', $result->membership_id); } else { $row['action'] = CRM_Core_Action::formLink(self::links('view'), $mask, array('id' => $result->membership_id, 'cid' => $result->contact_id, 'cxt' => $this->_context), ts('more'), FALSE, 'membership.selector.row', 'Membership', $result->membership_id); } //does membership have auto renew CRM-7137. $autoRenew = FALSE; if (isset($result->membership_recur_id) && $result->membership_recur_id && !CRM_Member_BAO_Membership::isSubscriptionCancelled($row['membership_id'])) { $autoRenew = TRUE; } $row['auto_renew'] = $autoRenew; $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id); $rows[] = $row; } return $rows; }
/** * This function is the main function that is called when the page loads, it decides the which action has to be taken for the page. * * return null * @access public */ function run() { $contactID = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullArray); $context = CRM_Utils_Request::retrieve('context', 'String', $this); if ($context == 'standalone' && !$contactID) { $this->_action = CRM_Core_Action::ADD; $this->assign('action', $this->_action); } else { // we should call contact view, preprocess only for membership in contact summary if ($this->_action != CRM_Core_Action::VIEW) { $this->preProcess(); } } if ($this->_permission == CRM_Core_Permission::EDIT && !CRM_Core_Permission::check('edit memberships')) { $this->_permission = CRM_Core_Permission::VIEW; // demote to view since user does not have edit membership rights $this->assign('permission', 'view'); } // check if we can process credit card membership $processors = CRM_Core_PseudoConstant::paymentProcessor(false, false, "billing_mode IN ( 1, 3 )"); if (count($processors) > 0) { $this->assign('newCredit', true); $this->_isPaymentProcessor = true; } else { $this->assign('newCredit', false); $this->_isPaymentProcessor = false; } // Only show credit card membership signup if user has CiviContribute permission if (CRM_Core_Permission::access('CiviContribute')) { $this->_accessContribution = true; $this->assign('accessContribution', true); } else { $this->_accessContribution = false; $this->assign('accessContribution', false); } if ($this->_action & CRM_Core_Action::VIEW) { $this->view(); } else { if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE | CRM_Core_Action::RENEW)) { $this->setContext(); $this->edit(); } else { $this->setContext(); $this->browse(); } } return parent::run(); }
/** * Build the form object. */ public function buildQuickForm() { $this->addYesNo('is_monetary', ts('Paid Event'), NULL, NULL, array('onclick' => "return showHideByValue('is_monetary','0','event-fees','block','radio',false);")); //add currency element. $this->addCurrency('currency', ts('Currency'), FALSE); $paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor(); $this->assign('paymentProcessor', $paymentProcessor); $this->addEntityRef('payment_processor', ts('Payment Processor'), array('entity' => 'PaymentProcessor', 'multiple' => TRUE, 'select' => array('minimumInputLength' => 0))); // financial type if (!CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() || CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && CRM_Core_Permission::check('administer CiviCRM Financial Types')) { $this->addSelect('financial_type_id'); } else { CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, CRM_Core_Action::ADD); $this->addSelect('financial_type_id', array('context' => 'search', 'options' => $financialTypes)); } // add pay later options $this->addElement('checkbox', 'is_pay_later', ts('Enable Pay Later option?'), NULL, array('onclick' => "return showHideByValue('is_pay_later','','payLaterOptions','block','radio',false);")); $this->addElement('textarea', 'pay_later_text', ts('Pay Later Label'), CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'pay_later_text'), FALSE); $this->add('wysiwyg', 'pay_later_receipt', ts('Pay Later Instructions'), CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'pay_later_receipt')); $this->addElement('checkbox', 'is_billing_required', ts('Billing address required')); $this->add('text', 'fee_label', ts('Fee Label')); $price = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviEvent'); if (CRM_Utils_System::isNull($price)) { $this->assign('price', FALSE); } else { $this->assign('price', TRUE); } $this->add('select', 'price_set_id', ts('Price Set'), array('' => ts('- none -')) + $price, NULL, array('onchange' => "return showHideByValue('price_set_id', '', 'map-field', 'block', 'select', false);")); $default = array($this->createElement('radio', NULL, NULL, NULL, 0)); $this->add('hidden', 'price_field_id', '', array('id' => 'price_field_id')); for ($i = 1; $i <= self::NUM_OPTION; $i++) { // label $this->add('text', "label[{$i}]", ts('Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'label')); $this->add('hidden', "price_field_value[{$i}]", '', array('id' => "price_field_value[{$i}]")); // value $this->add('text', "value[{$i}]", ts('Value'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'value')); $this->addRule("value[{$i}]", ts('Please enter a valid money value for this field (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money'); // default $default[] = $this->createElement('radio', NULL, NULL, NULL, $i); } $this->addGroup($default, 'default'); $this->addElement('checkbox', 'is_discount', ts('Discounts by Signup Date?'), NULL, array('onclick' => "warnDiscountDel(); return showHideByValue('is_discount','','discount','block','radio',false);")); $discountSection = $this->get('discountSection'); $this->assign('discountSection', $discountSection); // form fields of Discount sets $defaultOption = array(); $_showHide = new CRM_Core_ShowHideBlocks('', ''); for ($i = 1; $i <= self::NUM_DISCOUNT; $i++) { //the show hide blocks $showBlocks = 'discount_' . $i; if ($i > 2) { $_showHide->addHide($showBlocks); } else { $_showHide->addShow($showBlocks); } //Increment by 1 of start date of previous end date. if (is_array($this->_submitValues) && !empty($this->_submitValues['discount_name'][$i]) && !empty($this->_submitValues['discount_name'][$i + 1]) && isset($this->_submitValues['discount_end_date']) && isset($this->_submitValues['discount_end_date'][$i]) && $i < self::NUM_DISCOUNT - 1) { $end_date = CRM_Utils_Date::processDate($this->_submitValues['discount_end_date'][$i]); if (!empty($this->_submitValues['discount_end_date'][$i + 1]) && empty($this->_submitValues['discount_start_date'][$i + 1])) { list($this->_submitValues['discount_start_date'][$i + 1]) = CRM_Utils_Date::setDateDefaults(date('Y-m-d', strtotime("+1 days {$end_date}"))); } } //Decrement by 1 of end date from next start date. if ($i > 1 && is_array($this->_submitValues) && !empty($this->_submitValues['discount_name'][$i]) && !empty($this->_submitValues['discount_name'][$i - 1]) && isset($this->_submitValues['discount_start_date']) && isset($this->_submitValues['discount_start_date'][$i])) { $start_date = CRM_Utils_Date::processDate($this->_submitValues['discount_start_date'][$i]); if (!empty($this->_submitValues['discount_start_date'][$i]) && empty($this->_submitValues['discount_end_date'][$i - 1])) { list($this->_submitValues['discount_end_date'][$i - 1]) = CRM_Utils_Date::setDateDefaults(date('Y-m-d', strtotime("-1 days {$start_date}"))); } } //discount name $this->add('text', 'discount_name[' . $i . ']', ts('Discount Name'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceSet', 'title')); $this->add('hidden', "discount_price_set[{$i}]", '', array('id' => "discount_price_set[{$i}]")); //discount start date $this->addDate('discount_start_date[' . $i . ']', ts('Discount Start Date'), FALSE, array('formatType' => 'activityDate')); //discount end date $this->addDate('discount_end_date[' . $i . ']', ts('Discount End Date'), FALSE, array('formatType' => 'activityDate')); } $_showHide->addToTemplate(); $this->addElement('submit', $this->getButtonName('submit'), ts('Add Discount Set to Fee Table'), array('class' => 'crm-form-submit cancel')); $this->buildAmountLabel(); parent::buildQuickForm(); }
/** * This function is the main function that is called when the page loads, it decides the which action has to be taken for the page. * * return null * @access public */ function run() { $contactID = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullArray); $context = CRM_Utils_Request::retrieve('context', 'String', $this); if ($context == 'standalone' && !$contactID) { $this->_action = CRM_Core_Action::ADD; $this->assign('action', $this->_action); } else { // we should call contact view, preprocess only for pledge in contact summary $this->preProcess(); } if ($this->_permission == CRM_Core_Permission::EDIT && !CRM_Core_Permission::check('edit pledges')) { $this->_permission = CRM_Core_Permission::VIEW; // demote to view since user does not have edit pledge rights $this->assign('permission', 'view'); } // check if we can process credit card registration $processors = CRM_Core_PseudoConstant::paymentProcessor(false, false, "billing_mode IN ( 1, 3 )"); if (count($processors) > 0) { $this->assign('newCredit', true); } else { $this->assign('newCredit', false); } $this->setContext(); if ($this->_action & CRM_Core_Action::VIEW) { $this->view(); } else { if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) { $this->edit(); } else { if ($this->_action & CRM_Core_Action::DETACH) { require_once 'CRM/Pledge/BAO/Payment.php'; require_once 'CRM/Contribute/PseudoConstant.php'; CRM_Pledge_BAO_Payment::updatePledgePaymentStatus($this->_id, null, null, array_search('Cancelled', CRM_Contribute_PseudoConstant::contributionStatus())); $session =& CRM_Core_Session::singleton(); $session->setStatus(ts('Pledge has been Cancelled and all scheduled (not completed) payments have been cancelled.<br />')); CRM_Utils_System::redirect($session->popUserContext()); } else { $this->browse(); } } } return parent::run(); }