/**
  * @param CRM_Core_Form $form
  *
  * @return array
  */
 public static function process(&$form)
 {
     if ($form->getVar('_surveyId') <= 0) {
         return NULL;
     }
     $tabs = array('main' => array('title' => ts('Main Information'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'questions' => array('title' => ts('Questions'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'results' => array('title' => ts('Results'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE));
     $surveyID = $form->getVar('_surveyId');
     $class = $form->getVar('_name');
     $class = CRM_Utils_String::getClassName($class);
     $class = strtolower($class);
     if (array_key_exists($class, $tabs)) {
         $tabs[$class]['current'] = TRUE;
         $qfKey = $form->get('qfKey');
         if ($qfKey) {
             $tabs[$class]['qfKey'] = "&qfKey={$qfKey}";
         }
     }
     if ($surveyID) {
         $reset = !empty($_GET['reset']) ? 'reset=1&' : '';
         foreach ($tabs as $key => $value) {
             if (!isset($tabs[$key]['qfKey'])) {
                 $tabs[$key]['qfKey'] = NULL;
             }
             $tabs[$key]['link'] = CRM_Utils_System::url("civicrm/survey/configure/{$key}", "{$reset}action=update&id={$surveyID}{$tabs[$key]['qfKey']}");
             $tabs[$key]['active'] = $tabs[$key]['valid'] = TRUE;
         }
     }
     return $tabs;
 }
Esempio n. 2
0
 /**
  * @param CRM_Core_Form $form
  *
  * @return array
  */
 public static function process(&$form)
 {
     if ($form->getVar('_id') <= 0) {
         return NULL;
     }
     $tabs = array('settings' => array('title' => ts('Title'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'amount' => array('title' => ts('Amounts'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'membership' => array('title' => ts('Memberships'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'thankyou' => array('title' => ts('Receipt'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'friend' => array('title' => ts('Tell a Friend'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'custom' => array('title' => ts('Profiles'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'premium' => array('title' => ts('Premiums'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'widget' => array('title' => ts('Widgets'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'pcp' => array('title' => ts('Personal Campaigns'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE));
     $contribPageId = $form->getVar('_id');
     CRM_Utils_Hook::tabset('civicrm/admin/contribute', $tabs, array('contribution_page_id' => $contribPageId));
     $fullName = $form->getVar('_name');
     $className = CRM_Utils_String::getClassName($fullName);
     // Hack for special cases.
     switch ($className) {
         case 'Contribute':
             $attributes = $form->getVar('_attributes');
             $class = strtolower(basename(CRM_Utils_Array::value('action', $attributes)));
             break;
         case 'MembershipBlock':
             $class = 'membership';
             break;
         default:
             $class = strtolower($className);
             break;
     }
     if (array_key_exists($class, $tabs)) {
         $tabs[$class]['current'] = TRUE;
         $qfKey = $form->get('qfKey');
         if ($qfKey) {
             $tabs[$class]['qfKey'] = "&qfKey={$qfKey}";
         }
     }
     if ($contribPageId) {
         $reset = !empty($_GET['reset']) ? 'reset=1&' : '';
         foreach ($tabs as $key => $value) {
             if (!isset($tabs[$key]['qfKey'])) {
                 $tabs[$key]['qfKey'] = NULL;
             }
             $tabs[$key]['link'] = CRM_Utils_System::url("civicrm/admin/contribute/{$key}", "{$reset}action=update&id={$contribPageId}{$tabs[$key]['qfKey']}");
             $tabs[$key]['active'] = $tabs[$key]['valid'] = TRUE;
         }
         //get all section info.
         $contriPageInfo = CRM_Contribute_BAO_ContributionPage::getSectionInfo(array($contribPageId));
         foreach ($contriPageInfo[$contribPageId] as $section => $info) {
             if (!$info) {
                 $tabs[$section]['valid'] = FALSE;
             }
         }
     }
     return $tabs;
 }
/**
 * Delegated implementation of hook_civicrm_buildForm
 *
 * Customizes the UI for adding custom fields to allow the user to specify whether
 * a multi-select field should use the slider widget or not
 */
function _volunteer_civicrm_buildForm_CRM_Custom_Form_Field($formName, CRM_Core_Form &$form)
{
    // set default value for the checkbox
    $field_id = $form->getVar('_id');
    $widgetized_fields = _volunteer_get_slider_fields();
    $form->_defaultValues['is_slider_widget'] = in_array($field_id, $widgetized_fields);
    // add checkbox to the form object
    $form->add('checkbox', 'is_slider_widget', ts('Use Slider Selector?'));
    // add checkbox to the display
    CRM_Core_Region::instance('page-body')->add(array('template' => 'Slider/CRM/Custom/Form/Field.tpl'));
    // reposition and show/hide checkbox
    CRM_Core_Resources::singleton()->addScriptFile('org.civicrm.volunteer', 'js/CRM_Custom_Form_Field.js');
}
/**
 * Delegated implementation of hook_civicrm_buildForm
 *
 * Customizes the UI for adding custom fields to allow the user to specify whether
 * this field should be handled by the secure file extension
 */
function _securefiles_civicrm_buildForm_CRM_Custom_Form_Field($formName, CRM_Core_Form &$form)
{
    // set default value for the checkbox
    $field_id = $form->getVar('_id');
    $enabled_fields = _securefiles_get_secure_enabled_fields();
    $form->_defaultValues['use_securefiles'] = in_array($field_id, $enabled_fields);
    // add checkbox to the form object
    $form->add('checkbox', 'use_securefiles', ts('Store using SecureFiles'));
    // add checkbox/settings form to the display
    CRM_Core_Region::instance('page-body')->add(array('template' => 'CRM/Securefiles/Form/CustomField.tpl'));
    $secureFileElements = array();
    //Let the Backend service add fields if it wants/needs to
    $backendService = CRM_Securefiles_Backend::getBackendService();
    if ($backendService) {
        $backendService->buildFieldSettingsForm($form, $secureFileElements);
    }
    //Assign our custom field names to the form so the template can render them.
    $form->assign("secureFileElements", $secureFileElements);
    // reposition and show/hide checkbox
    CRM_Core_Resources::singleton()->addScriptFile('com.ginkgostreet.securefiles', 'js/CRM_Custom_Form_Field.js');
}
/**
 * Implements hook_civicrm_buildForm().
 *
 * Set a default value for an event price set field.
 *
 * @param string $formName
 * @param CRM_Core_Form $form
 */
function menufontawesome_civicrm_buildForm($formName, &$form)
{
    if ($formName == 'CRM_Admin_Form_Navigation') {
        CRM_Core_Resources::singleton()->addStyleFile('com.opetmar.menufontawesome', 'resources/plugins/bootstrap/css/bootstrap.css', 0, 'html-header');
        CRM_Core_Resources::singleton()->addStyleFile('com.opetmar.menufontawesome', 'resources/plugins/fontawesome-iconpicker/css/fontawesome-iconpicker.min.css', 0, 'html-header');
        CRM_Core_Resources::singleton()->addScriptFile('com.opetmar.menufontawesome', 'resources/plugins/jquery-1.11.3.min.js', 0);
        CRM_Core_Resources::singleton()->addScriptFile('com.opetmar.menufontawesome', 'resources/plugins/bootstrap/js/bootstrap.min.js', 1);
        CRM_Core_Resources::singleton()->addScriptFile('com.opetmar.menufontawesome', 'resources/plugins/fontawesome-iconpicker/js/fontawesome-iconpicker.min.js', 2);
        CRM_Core_Resources::singleton()->addScriptFile('com.opetmar.menufontawesome', 'resources/main.js', 3);
        // Add the field element in the form
        if ($form->getAction() == CRM_Core_Action::UPDATE) {
            $id = $form->getVar('_id');
            $fa_icon = CRM_Menufontawesome_BAO_Navigation::getIcon($id);
            $form->add('text', 'fa_icon', ts('Icon'), array('value' => $fa_icon));
        } else {
            $form->add('text', 'fa_icon', ts('Icon'), array('value' => ''));
        }
        $templatePath = realpath(dirname(__FILE__) . "/templates/CRM/Menufontawesome/Page");
        // dynamically insert a template block in the page
        CRM_Core_Region::instance('page-body')->add(array('template' => "{$templatePath}/fa_icon.tpl"));
    }
}
Esempio n. 6
0
 /**
  * Post process function.
  *
  * @param CRM_Core_Form $form
  * @param bool $redirect
  */
 public static function postProcess(&$form, $redirect = TRUE)
 {
     $params = $form->getVar('_params');
     $instanceID = $form->getVar('_id');
     if ($isNew = $form->getVar('_createNew')) {
         // set the report_id since base template is going to be same, and we going to unset $instanceID
         // which will make it difficult later on, to compute report_id
         $params['report_id'] = CRM_Report_Utils_Report::getValueFromUrl($instanceID);
         // Unset $instanceID so a new copy would be created.
         $instanceID = NULL;
     }
     $params['instance_id'] = $instanceID;
     if (!empty($params['is_navigation'])) {
         $params['navigation'] = $form->_navigation;
     } elseif ($instanceID) {
         // Delete navigation if exists.
         $navId = CRM_Core_DAO::getFieldValue('CRM_Report_DAO_ReportInstance', $instanceID, 'navigation_id', 'id');
         if ($navId) {
             CRM_Core_BAO_Navigation::processDelete($navId);
             CRM_Core_BAO_Navigation::resetNavigation();
         }
     }
     // make a copy of params
     $formValues = $params;
     // unset params from $formValues that doesn't match with DB columns of instance tables, and also not required in form-values for sure
     $unsetFields = array('title', 'to_emails', 'cc_emails', 'header', 'footer', 'qfKey', 'id', '_qf_default', 'report_header', 'report_footer', 'grouprole');
     foreach ($unsetFields as $field) {
         unset($formValues[$field]);
     }
     $view_mode = $formValues['view_mode'];
     // pass form_values as string
     $params['form_values'] = serialize($formValues);
     $instance = CRM_Report_BAO_ReportInstance::create($params);
     $form->set('id', $instance->id);
     if ($instanceID && !$isNew) {
         // updating existing instance
         $statusMsg = ts('"%1" report has been updated.', array(1 => $instance->title));
     } elseif ($form->getVar('_id') && $isNew) {
         $statusMsg = ts('Your report has been successfully copied as "%1". You are currently viewing the new copy.', array(1 => $instance->title));
     } else {
         $statusMsg = ts('"%1" report has been successfully created. You are currently viewing the new report instance.', array(1 => $instance->title));
     }
     CRM_Core_Session::setStatus($statusMsg);
     if ($redirect) {
         $urlParams = array('reset' => 1);
         if ($view_mode == 'view') {
             $urlParams['force'] = 1;
         } else {
             $urlParams['output'] = 'criteria';
         }
         CRM_Utils_System::redirect(CRM_Utils_System::url("civicrm/report/instance/{$instance->id}", $urlParams));
     }
 }
/**
 * Implementation of hook_civicrm_buildAmount()
 *
 * If the event id of the form being loaded has a discount code, calculate the
 * the discount and update the price and label. Apply the initial autodiscount
 * based on a users membership.
 *
 * Check all priceset items and only apply the discount to the discounted items.
 *
 * @param string $pageType
 * @param CRM_Core_Form $form
 * @param $amounts
 */
function cividiscount_civicrm_buildAmount($pagetype, &$form, &$amounts)
{
    if ((!$form->getVar('_action') || $form->getVar('_action') & CRM_Core_Action::PREVIEW || $form->getVar('_action') & CRM_Core_Action::ADD || $form->getVar('_action') & CRM_Core_Action::UPDATE) && !empty($amounts) && is_array($amounts) && ($pagetype == 'event' || $pagetype == 'membership')) {
        if (!$pagetype == 'membership' && in_array(get_class($form), array('CRM_Contribute_Form_Contribution', 'CRM_Contribute_Form_Contribution_Main'))) {
            return;
        }
        // // Don't provide Discount if the logged in user already subscribed to any membership types in the form
        $currentMemberships = $form->_currentMemberships;
        //if logged in
        if (!empty($currentMemberships)) {
            $new_member = FALSE;
        } else {
            // if not logged in
            $new_member = validate_email_for_discount($form);
        }
        /*
        Check if a payment type is set for discounts
        */
        $payids = array();
        $payids = _cividiscount_get_discounted_paymentProcessor_type_ids();
        $selectedProcessorValue = $form->_paymentProcessor['payment_processor_type_id'];
        $contact_id = _cividiscount_get_form_contact_id($form);
        $autodiscount = FALSE;
        $eid = $form->getVar('_eventId');
        $psid = $form->get('priceSetId');
        $ps = $form->get('priceSet');
        $v = $form->getVar('_values');
        $code = trim(CRM_Utils_Request::retrieve('discountcode', 'String', $form, false, null, 'REQUEST'));
        if (!array_key_exists('discountcode', $form->_submitValues) && ($pid = $form->getVar('_participantId')) && $form->getVar('_action') & CRM_Core_Action::UPDATE) {
            $code = _cividiscount_get_item_by_track('civicrm_participant', $pid, $contact_id, TRUE);
        }
        if (!empty($v['currency'])) {
            $currency = $v['currency'];
        } elseif (!empty($v['event']['currency'])) {
            $currency = $v['event']['currency'];
        } else {
            $currency = CRM_Core_Config::singleton()->defaultCurrency;
        }
        // If additional participants are not allowed to receive a discount we need
        // to interrupt the form processing on build and POST.
        // This is a potential landmine if the form processing ever changes in Civi.
        if (!_cividiscount_allow_multiple()) {
            // POST from participant form to confirm page
            if ($form->getVar('_lastParticipant') == 1) {
                return;
            }
            // On build participant form
            $keys = array_keys($_GET);
            foreach ($keys as $key) {
                if (substr($key, 0, 16) == "_qf_Participant_") {
                    // We can somewhat safely assume we're in the additional participant
                    // registration form.
                    // @todo what is the effect of this?
                    if ($_GET[$key] == 'true') {
                        return;
                    }
                }
            }
        }
        if (!$new_member && !empty($code)) {
            echo "Sorry! Discount is not applicable for renewal!";
            return;
        }
        if (!empty($payids) && !empty($code)) {
            if (!in_array($selectedProcessorValue, $payids)) {
                echo "Sorry! Discount is only applicable for Direct Debit!";
                return;
            }
        }
        $form->set('_discountInfo', NULL);
        $dicountCalculater = new CRM_CiviDiscount_DiscountCalculator($pagetype, $eid, $contact_id, $code, FALSE);
        $discounts = $dicountCalculater->getDiscounts();
        if (!empty($code)) {
            if (empty($discounts)) {
                $form->set('discountCodeErrorMsg', ts('The discount code you entered is invalid.'));
            } else {
                /*gets discounts info, even if a discount code is not applicable 
                  for the membership types in the current form */
                // Check if a discount code is applicable to any of the membership types in the form
                $membership_ids_in_form = membership_type_ids_in_form($form);
                $membership_ids_in_dicount_info = array();
                foreach ($discounts as $code => $discount) {
                    $membership_ids_in_dicount_info = $discount['memberships'];
                }
                if (count(array_intersect($membership_ids_in_dicount_info, $membership_ids_in_form)) == 0) {
                    $form->set('discountCodeErrorMsg', ts('The discount code you entered is invalid.'));
                }
            }
        }
        if (empty($discounts)) {
            // Check if a discount is available
            if ($pagetype == 'event') {
                $discounts = _cividiscount_get_discounts();
                foreach ($discounts as $code => $discount) {
                    if (isset($discount['events']) && array_key_exists($eid, $discount['events']) && $discount['discount_msg_enabled']) {
                        // Display discount available message
                        CRM_Core_Session::setStatus(html_entity_decode($discount['discount_msg']), '', 'no-popup');
                    }
                }
            }
            return;
        }
        // here we check if discount is configured for events or for membership types.
        // There are two scenarios:
        // 1. Discount is configure for the event or membership type, in that case we should apply discount only
        //    if default fee / membership type is configured. ( i.e price set with quick config true )
        // 2. Discount is configure at price field level, in this case discount should be applied only for
        //    that particular price set field.
        // here we need to check if selected price set is quick config
        $isQuickConfigPriceSet = CRM_CiviDiscount_Utils::checkForQuickConfigPriceSet($psid);
        $keys = array_keys($discounts);
        $key = array_shift($keys);
        // in this case discount is specified for event id or membership type id, so we need to get info of
        // associated price set fields. For events discount we already have the list, but for memberships we
        // need to filter at membership type level
        //retrieve price set field associated with this priceset
        $priceSetInfo = CRM_CiviDiscount_Utils::getPriceSetsInfo($psid);
        $originalAmounts = $amounts;
        //$discount = array_shift($discounts);
        foreach ($discounts as $done_care => $discount) {
            if (!empty($dicountCalculater->autoDiscounts) && array_key_exists($done_care, $dicountCalculater->autoDiscounts)) {
                $autodiscount = TRUE;
            } else {
                $autodiscount = FALSE;
            }
            $priceFields = isset($discount['pricesets']) ? $discount['pricesets'] : array();
            if (empty($priceFields) && (!empty($code) || $autodiscount)) {
                // apply discount to all the price fields for quickconfig pricesets
                if ($pagetype == 'event' && $isQuickConfigPriceSet) {
                    $applyToAllLineItems = TRUE;
                    if (!empty($key)) {
                        $discounts[$key]['pricesets'] = array_keys($priceSetInfo);
                    }
                } else {
                    // filter only valid membership types that have discount
                    foreach ($priceSetInfo as $pfID => $priceFieldValues) {
                        if (!empty($priceFieldValues['membership_type_id']) && in_array($priceFieldValues['membership_type_id'], CRM_Utils_Array::value('memberships', $discount, array()))) {
                            $priceFields[$pfID] = $pfID;
                        }
                    }
                }
            }
            $apcount = _cividiscount_checkEventDiscountMultipleParticipants($pagetype, $form, $discount);
            if (empty($apcount)) {
                //this was set to return but that doesn't make sense as there might be another discount
                continue;
            }
            $discountApplied = FALSE;
            if (!empty($autodiscount) || !empty($code)) {
                foreach ($amounts as $fee_id => &$fee) {
                    if (!is_array($fee['options'])) {
                        continue;
                    }
                    foreach ($fee['options'] as $option_id => &$option) {
                        if (!empty($applyToAllLineItems) || CRM_Utils_Array::value($option['id'], $priceFields)) {
                            $originalLabel = $originalAmounts[$fee_id]['options'][$option_id]['label'];
                            $originalAmount = CRM_Utils_Rule::cleanMoney($originalAmounts[$fee_id]['options'][$option_id]['amount']);
                            list($amount, $label) = _cividiscount_calc_discount($originalAmount, $originalLabel, $discount, $autodiscount, $currency);
                            $discountAmount = $originalAmounts[$fee_id]['options'][$option_id]['amount'] - $amount;
                            if ($discountAmount > CRM_Utils_Array::value('discount_applied', $option)) {
                                $option['amount'] = $amount;
                                $option['label'] = $label;
                                $option['discount_applied'] = $discountAmount;
                            }
                            $discountApplied = TRUE;
                        }
                    }
                }
            }
        }
        // this seems to incorrectly set to only the last discount but it seems not to matter in the way it is used
        if (isset($discountApplied) && $discountApplied) {
            if (!empty($ps['fields'])) {
                $ps['fields'] = $amounts;
                $form->setVar('_priceSet', $ps);
            }
            $form->set('_discountInfo', array('discount' => $discount, 'autodiscount' => $autodiscount, 'contact_id' => $contact_id));
        }
    }
}
Esempio n. 8
0
 /**
  * Initiate price set such that various non-BAO things are set on the form.
  *
  * This function is not really a BAO function so the location is misleading.
  *
  * @param CRM_Core_Form $form
  * @param int $id
  *   Form entity id.
  * @param string $entityTable
  * @param bool $validOnly
  * @param int $priceSetId
  *   Price Set ID
  *
  * @return bool|false|int|null
  */
 public static function initSet(&$form, $id, $entityTable = 'civicrm_event', $validOnly = FALSE, $priceSetId = NULL)
 {
     if (!$priceSetId) {
         $priceSetId = self::getFor($entityTable, $id);
     }
     //check if priceset is is_config
     if (is_numeric($priceSetId)) {
         if (CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config') && $form->getVar('_name') != 'Participant') {
             $form->assign('quickConfig', 1);
         }
     }
     // get price info
     if ($priceSetId) {
         if ($form->_action & CRM_Core_Action::UPDATE) {
             $entityId = $entity = NULL;
             switch ($entityTable) {
                 case 'civicrm_event':
                     $entity = 'participant';
                     if (CRM_Utils_System::getClassName($form) == 'CRM_Event_Form_Participant') {
                         $entityId = $form->_id;
                     } else {
                         $entityId = $form->_participantId;
                     }
                     break;
                 case 'civicrm_contribution_page':
                 case 'civicrm_contribution':
                     $entity = 'contribution';
                     $entityId = $form->_id;
                     break;
             }
             if ($entityId && $entity) {
                 $form->_values['line_items'] = CRM_Price_BAO_LineItem::getLineItems($entityId, $entity);
             }
             $required = FALSE;
         } else {
             $required = TRUE;
         }
         $form->_priceSetId = $priceSetId;
         $priceSet = self::getSetDetail($priceSetId, $required, $validOnly);
         $form->_priceSet = CRM_Utils_Array::value($priceSetId, $priceSet);
         $form->_values['fee'] = CRM_Utils_Array::value('fields', $form->_priceSet);
         //get the price set fields participant count.
         if ($entityTable == 'civicrm_event') {
             //get option count info.
             $form->_priceSet['optionsCountTotal'] = self::getPricesetCount($priceSetId);
             if ($form->_priceSet['optionsCountTotal']) {
                 $optionsCountDeails = array();
                 if (!empty($form->_priceSet['fields'])) {
                     foreach ($form->_priceSet['fields'] as $field) {
                         foreach ($field['options'] as $option) {
                             $count = CRM_Utils_Array::value('count', $option, 0);
                             $optionsCountDeails['fields'][$field['id']]['options'][$option['id']] = $count;
                         }
                     }
                 }
                 $form->_priceSet['optionsCountDetails'] = $optionsCountDeails;
             }
             //get option max value info.
             $optionsMaxValueTotal = 0;
             $optionsMaxValueDetails = array();
             if (!empty($form->_priceSet['fields'])) {
                 foreach ($form->_priceSet['fields'] as $field) {
                     foreach ($field['options'] as $option) {
                         $maxVal = CRM_Utils_Array::value('max_value', $option, 0);
                         $optionsMaxValueDetails['fields'][$field['id']]['options'][$option['id']] = $maxVal;
                         $optionsMaxValueTotal += $maxVal;
                     }
                 }
             }
             $form->_priceSet['optionsMaxValueTotal'] = $optionsMaxValueTotal;
             if ($optionsMaxValueTotal) {
                 $form->_priceSet['optionsMaxValueDetails'] = $optionsMaxValueDetails;
             }
         }
         $form->set('priceSetId', $form->_priceSetId);
         $form->set('priceSet', $form->_priceSet);
         return $priceSetId;
     }
     return FALSE;
 }
Esempio n. 9
0
 /**
  * Build the payment processor form.
  *
  * @param CRM_Core_Form $form
  */
 public static function buildQuickform(&$form)
 {
     //@todo document why this addHidden is here
     //CRM-15743 - we should not set/create hidden element for pay later
     // because payment processor is not selected
     $processorId = $form->getVar('_paymentProcessorID');
     $billing_profile_id = CRM_Utils_Request::retrieve('billing_profile_id', 'String');
     if (!empty($form->_values) && !empty($form->_values['is_billing_required'])) {
         $billing_profile_id = 'billing';
     }
     if (!empty($processorId)) {
         $form->addElement('hidden', 'hidden_processor', 1);
     }
     CRM_Core_Payment_Form::buildPaymentForm($form, $form->_paymentProcessor, $billing_profile_id, FALSE);
 }
Esempio n. 10
0
 /**
  * Build the price set form.
  *
  * @param CRM_Core_Form $form
  *
  * @return void
  */
 public static function buildPriceSet(&$form)
 {
     $priceSetId = $form->get('priceSetId');
     $userid = $form->getVar('_userID');
     if (!$priceSetId) {
         return;
     }
     $validFieldsOnly = TRUE;
     $className = CRM_Utils_System::getClassName($form);
     if (in_array($className, array('CRM_Contribute_Form_Contribution', 'CRM_Member_Form_Membership'))) {
         $validFieldsOnly = FALSE;
     }
     $priceSet = self::getSetDetail($priceSetId, TRUE, $validFieldsOnly);
     $form->_priceSet = CRM_Utils_Array::value($priceSetId, $priceSet);
     $form->_quickConfig = $quickConfig = 0;
     if (CRM_Core_DAO::getFieldValue('CRM_Upgrade_Snapshot_V4p2_Price_DAO_Set', $priceSetId, 'is_quick_config')) {
         $quickConfig = 1;
     }
     $form->assign('quickConfig', $quickConfig);
     if ($className == "CRM_Contribute_Form_Contribution_Main") {
         $form->_quickConfig = $quickConfig;
     }
     $form->assign('priceSet', $form->_priceSet);
     $component = 'contribution';
     if ($className == 'CRM_Member_Form_Membership') {
         $component = 'membership';
     }
     if ($className == 'CRM_Contribute_Form_Contribution_Main') {
         $feeBlock =& $form->_values['fee'];
         if (!empty($form->_useForMember)) {
             $component = 'membership';
         }
     } else {
         $feeBlock =& $form->_priceSet['fields'];
     }
     // call the hook.
     CRM_Utils_Hook::buildAmount($component, $form, $feeBlock);
     foreach ($feeBlock as $field) {
         if (CRM_Utils_Array::value('visibility', $field) == 'public' || !$validFieldsOnly) {
             $options = CRM_Utils_Array::value('options', $field);
             if ($className == 'CRM_Contribute_Form_Contribution_Main' && ($component = 'membership')) {
                 $checklifetime = self::checkCurrentMembership($options, $userid);
                 if ($checklifetime) {
                     $form->assign('ispricelifetime', TRUE);
                 }
             }
             if (!is_array($options)) {
                 continue;
             }
             CRM_Upgrade_Snapshot_V4p2_Price_BAO_Field::addQuickFormElement($form, 'price_' . $field['id'], $field['id'], FALSE, CRM_Utils_Array::value('is_required', $field, FALSE), NULL, $options);
         }
     }
 }
Esempio n. 11
0
 /**
  * Function to build the price set form.
  *
  * @param CRM_Core_Form $form
  *
  * @return void
  * @access public
  */
 static function buildPriceSet(&$form)
 {
     $priceSetId = $form->get('priceSetId');
     $userid = $form->getVar('_userID');
     if (!$priceSetId) {
         return;
     }
     $validFieldsOnly = TRUE;
     $className = CRM_Utils_System::getClassName($form);
     if (in_array($className, array('CRM_Contribute_Form_Contribution', 'CRM_Member_Form_Membership'))) {
         $validFieldsOnly = FALSE;
     }
     $priceSet = self::getSetDetail($priceSetId, TRUE, $validFieldsOnly);
     $form->_priceSet = CRM_Utils_Array::value($priceSetId, $priceSet);
     $validPriceFieldIds = array_keys($form->_priceSet['fields']);
     $form->_quickConfig = $quickConfig = 0;
     if (CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config')) {
         $quickConfig = 1;
     }
     $form->assign('quickConfig', $quickConfig);
     if ($className == 'CRM_Contribute_Form_Contribution_Main') {
         $form->_quickConfig = $quickConfig;
     }
     $form->assign('priceSet', $form->_priceSet);
     $component = 'contribution';
     if ($className == 'CRM_Member_Form_Membership') {
         $component = 'membership';
     }
     if ($className == 'CRM_Contribute_Form_Contribution_Main') {
         $feeBlock =& $form->_values['fee'];
         if (!empty($form->_useForMember)) {
             $component = 'membership';
         }
     } else {
         $feeBlock =& $form->_priceSet['fields'];
     }
     // call the hook.
     CRM_Utils_Hook::buildAmount($component, $form, $feeBlock);
     // CRM-14492 Admin price fields should show up on event registration if user has 'administer CiviCRM' permissions
     $adminFieldVisible = false;
     if (CRM_Core_Permission::check('administer CiviCRM')) {
         $adminFieldVisible = true;
     }
     foreach ($feeBlock as $id => $field) {
         if (CRM_Utils_Array::value('visibility', $field) == 'public' || CRM_Utils_Array::value('visibility', $field) == 'admin' && $adminFieldVisible == true || !$validFieldsOnly) {
             $options = CRM_Utils_Array::value('options', $field);
             if ($className == 'CRM_Contribute_Form_Contribution_Main' && ($component = 'membership')) {
                 $checklifetime = self::checkCurrentMembership($options, $userid);
                 if ($checklifetime) {
                     $form->assign('ispricelifetime', TRUE);
                 }
             }
             if (!is_array($options) || !in_array($id, $validPriceFieldIds)) {
                 continue;
             }
             CRM_Price_BAO_PriceField::addQuickFormElement($form, 'price_' . $field['id'], $field['id'], FALSE, CRM_Utils_Array::value('is_required', $field, FALSE), NULL, $options);
         }
     }
 }
Esempio n. 12
0
 /**
  * Build the payment processor form.
  *
  * @param CRM_Core_Form $form
  */
 public static function buildQuickform(&$form)
 {
     //@todo document why this addHidden is here
     //CRM-15743 - we should not set/create hidden element for pay later
     // because payment processor is not selected
     $processorId = $form->getVar('_paymentProcessorID');
     $isBillingAddressRequiredForPayLater = $form->_isBillingAddressRequiredForPayLater;
     if (!empty($processorId)) {
         $isBillingAddressRequiredForPayLater = FALSE;
         $form->addElement('hidden', 'hidden_processor', 1);
     }
     CRM_Core_Payment_Form::buildPaymentForm($form, $form->_paymentProcessor, empty($isBillingAddressRequiredForPayLater), FALSE);
 }