function build_price_options($event)
 {
     $price_fields_for_event = array();
     $base_field_name = "event_{$event->id}_amount";
     $price_set_id = CRM_Price_BAO_Set::getFor('civicrm_event', $event->id);
     if ($price_set_id) {
         $price_sets = CRM_Price_BAO_Set::getSetDetail($price_set_id, TRUE, TRUE);
         $price_set = $price_sets[$price_set_id];
         $index = -1;
         foreach ($price_set['fields'] as $field) {
             $index++;
             $field_name = "event_{$event->id}_price_{$field['id']}";
             CRM_Price_BAO_Field::addQuickFormElement($this, $field_name, $field['id'], FALSE);
             $price_fields_for_event[] = $field_name;
         }
     }
     return $price_fields_for_event;
 }
예제 #2
0
 /**
  * process membership records
  *
  * @param array $params associated array of submitted values
  *
  * @access public
  *
  * @return None
  */
 private function processMembership(&$params)
 {
     $dateTypes = array('join_date' => 'joinDate', 'membership_start_date' => 'startDate', 'membership_end_date' => 'endDate');
     $dates = array('join_date', 'start_date', 'end_date', 'reminder_date');
     // get the price set associated with offline memebership
     $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', 'default_membership_type_amount', 'id', 'name');
     $this->_priceSet = $priceSets = current(CRM_Price_BAO_Set::getSetDetail($priceSetId));
     if (isset($params['field'])) {
         $customFields = array();
         foreach ($params['field'] as $key => $value) {
             // if contact is not selected we should skip the row
             if (!CRM_Utils_Array::value($key, $params['primary_contact_select_id'])) {
                 continue;
             }
             $value['contact_id'] = CRM_Utils_Array::value($key, $params['primary_contact_select_id']);
             // update contact information
             $this->updateContactInfo($value);
             $membershipTypeId = $value['membership_type_id'] = $value['membership_type'][1];
             foreach ($dateTypes as $dateField => $dateVariable) {
                 ${$dateVariable} = CRM_Utils_Date::processDate($value[$dateField]);
             }
             $calcDates = array();
             $calcDates[$membershipTypeId] = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membershipTypeId, $joinDate, $startDate, $endDate);
             foreach ($calcDates as $memType => $calcDate) {
                 foreach ($dates as $d) {
                     //first give priority to form values then calDates.
                     $date = CRM_Utils_Array::value($d, $value);
                     if (!$date) {
                         $date = CRM_Utils_Array::value($d, $calcDate);
                     }
                     $value[$d] = CRM_Utils_Date::processDate($date);
                 }
             }
             if (CRM_Utils_Array::value('send_receipt', $value)) {
                 $value['receipt_date'] = date('Y-m-d His');
             }
             if (CRM_Utils_Array::value('membership_source', $value)) {
                 $value['source'] = $value['membership_source'];
             }
             unset($value['membership_source']);
             //Get the membership status
             if (CRM_Utils_Array::value('membership_status', $value)) {
                 $value['status_id'] = $value['membership_status'];
                 unset($value['membership_status']);
             }
             if (empty($customFields)) {
                 // membership type custom data
                 $customFields = CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, $membershipTypeId);
                 $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, NULL, NULL, TRUE));
             }
             //check for custom data
             $value['custom'] = CRM_Core_BAO_CustomField::postProcess($params['field'][$key], $customFields, $key, 'Membership', $membershipTypeId);
             if (CRM_Utils_Array::value('contribution_type', $value)) {
                 $value['contribution_type_id'] = $value['contribution_type'];
             }
             if (CRM_Utils_Array::value('payment_instrument', $value)) {
                 $value['payment_instrument_id'] = $value['payment_instrument'];
             }
             // handle soft credit
             if (CRM_Utils_Array::value('soft_credit_contact_select_id', $params) && CRM_Utils_Array::value($key, $params['soft_credit_contact_select_id'])) {
                 $value['soft_credit_to'] = $params['soft_credit_contact_select_id'][$key];
             }
             if (CRM_Utils_Array::value('receive_date', $value)) {
                 $value['receive_date'] = CRM_Utils_Date::processDate($value['receive_date'], $value['receive_date_time'], TRUE);
             }
             $params['actualBatchTotal'] += $value['total_amount'];
             unset($value['contribution_type']);
             unset($value['payment_instrument']);
             $value['batch_id'] = $this->_batchId;
             $value['skipRecentView'] = TRUE;
             // make entry in line item for contribution
             $editedFieldParams = array('price_set_id' => $priceSetId, 'name' => $value['membership_type'][0]);
             $editedResults = array();
             CRM_Price_BAO_Field::retrieve($editedFieldParams, $editedResults);
             if (!empty($editedResults)) {
                 unset($this->_priceSet['fields']);
                 $this->_priceSet['fields'][$editedResults['id']] = $priceSets['fields'][$editedResults['id']];
                 unset($this->_priceSet['fields'][$editedResults['id']]['options']);
                 $fid = $editedResults['id'];
                 $editedFieldParams = array('price_field_id' => $editedResults['id'], 'membership_type_id' => $value['membership_type_id']);
                 $editedResults = array();
                 CRM_Price_BAO_FieldValue::retrieve($editedFieldParams, $editedResults);
                 $this->_priceSet['fields'][$fid]['options'][$editedResults['id']] = $priceSets['fields'][$fid]['options'][$editedResults['id']];
                 if (CRM_Utils_Array::value('total_amount', $value)) {
                     $this->_priceSet['fields'][$fid]['options'][$editedResults['id']]['amount'] = $value['total_amount'];
                 }
                 $fieldID = key($this->_priceSet['fields']);
                 $value['price_' . $fieldID] = $editedResults['id'];
                 $lineItem = array();
                 CRM_Price_BAO_Set::processAmount($this->_priceSet['fields'], $value, $lineItem[$priceSetId]);
                 $value['lineItems'] = $lineItem;
                 $value['processPriceSet'] = TRUE;
             }
             // end of contribution related section
             unset($value['membership_type']);
             unset($value['membership_start_date']);
             unset($value['membership_end_date']);
             $value['is_renew'] = false;
             if (CRM_Utils_Array::value('member_option', $params) && CRM_Utils_Array::value($key, $params['member_option']) == 2) {
                 $this->_params = $params;
                 $value['is_renew'] = true;
                 $membership = CRM_Member_BAO_Membership::renewMembership($value['contact_id'], $value['membership_type_id'], FALSE, $this, NULL, NULL, $value['custom']);
                 // make contribution entry
                 CRM_Member_BAO_Membership::recordMembershipContribution($value, CRM_Core_DAO::$_nullArray, $membership->id);
             } else {
                 $membership = CRM_Member_BAO_Membership::create($value, CRM_Core_DAO::$_nullArray);
             }
             //process premiums
             if (CRM_Utils_Array::value('product_name', $value)) {
                 if ($value['product_name'][0] > 0) {
                     list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo();
                     $value['hidden_Premium'] = 1;
                     $value['product_option'] = CRM_Utils_Array::value($value['product_name'][1], $options[$value['product_name'][0]]);
                     $premiumParams = array('product_id' => $value['product_name'][0], 'contribution_id' => $value['contribution_id'], 'product_option' => $value['product_option'], 'quantity' => 1);
                     CRM_Contribute_BAO_Contribution::addPremium($premiumParams);
                 }
             }
             // end of premium
             //send receipt mail.
             if ($membership->id && CRM_Utils_Array::value('send_receipt', $value)) {
                 // add the domain email id
                 $domainEmail = CRM_Core_BAO_Domain::getNameAndEmail();
                 $domainEmail = "{$domainEmail['0']} <{$domainEmail['1']}>";
                 $value['from_email_address'] = $domainEmail;
                 $value['membership_id'] = $membership->id;
                 CRM_Member_Form_Membership::emailReceipt($this, $value, $membership);
             }
         }
     }
 }
예제 #3
0
 /**
  * Process the form
  *
  * @param null
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $params = $this->controller->exportValues('Field');
     $params['name'] = CRM_Utils_String::titleToVar($params['label']);
     $params['is_display_amounts'] = CRM_Utils_Array::value('is_display_amounts', $params, FALSE);
     $params['is_required'] = CRM_Utils_Array::value('is_required', $params, FALSE);
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
     if (isset($params['active_on'])) {
         $params['active_on'] = CRM_Utils_Date::processDate($params['active_on'], CRM_Utils_Array::value('active_on_time', $params), TRUE);
     }
     if (isset($params['expire_on'])) {
         $params['expire_on'] = CRM_Utils_Date::processDate($params['expire_on'], CRM_Utils_Array::value('expire_on_time', $params), TRUE);
     }
     $params['visibility_id'] = CRM_Utils_Array::value('visibility_id', $params, FALSE);
     $params['count'] = CRM_Utils_Array::value('count', $params, FALSE);
     // need the FKEY - price set id
     $params['price_set_id'] = $this->_sid;
     if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) {
         $fieldValues = array('price_set_id' => $this->_sid);
         $oldWeight = NULL;
         if ($this->_fid) {
             $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $this->_fid, 'weight', 'id');
         }
         $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_Field', $oldWeight, $params['weight'], $fieldValues);
     }
     // make value <=> name consistency.
     if (isset($params['option_name'])) {
         $params['option_value'] = $params['option_name'];
     }
     $params['is_enter_qty'] = CRM_Utils_Array::value('is_enter_qty', $params, FALSE);
     if ($params['html_type'] == 'Text') {
         // if html type is Text, force is_enter_qty on
         $params['is_enter_qty'] = 1;
         // modify params values as per the option group and option
         // value
         $params['option_amount'] = array(1 => $params['price']);
         $params['option_label'] = array(1 => $params['label']);
         $params['option_count'] = array(1 => $params['count']);
         $params['option_max_value'] = array(1 => CRM_Utils_Array::value('max_value', $params));
         //$params['option_description']  = array( 1 => $params['description'] );
         $params['option_weight'] = array(1 => $params['weight']);
         $params['is_active'] = array(1 => 1);
     }
     if ($this->_fid) {
         $params['id'] = $this->_fid;
     }
     $priceField = CRM_Price_BAO_Field::create($params);
     if (!is_a($priceField, 'CRM_Core_Error')) {
         CRM_Core_Session::setStatus(ts('Price Field \'%1\' has been saved.', array(1 => $priceField->label)));
     }
     $buttonName = $this->controller->getButtonName();
     $session = CRM_Core_Session::singleton();
     if ($buttonName == $this->getButtonName('next', 'new')) {
         CRM_Core_Session::setStatus(ts(' You can add another price set field.'));
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=add&sid=' . $this->_sid));
     } else {
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid));
     }
 }
 /**
  * Process the form when submitted
  *
  * @param null
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     if (CRM_Price_BAO_Field::deleteField($this->_fid)) {
         CRM_Core_Session::setStatus(ts('The Price Field \'%1\' has been deleted.', array(1 => $this->_title)));
     }
 }
예제 #5
0
 /**
  * Function to actually build the form
  * 
  * @param null
  * 
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     $this->assign('groupTree', $this->_groupTree);
     // add the form elements
     require_once 'CRM/Price/BAO/Field.php';
     foreach ($this->_groupTree as $group) {
         if (is_array($group['fields']) && !empty($group['fields'])) {
             foreach ($group['fields'] as $field) {
                 $fieldId = $field['id'];
                 $elementName = 'price_' . $fieldId;
                 CRM_Price_BAO_Field::addQuickFormElement($this, $elementName, $fieldId, false, $field['is_required']);
             }
         }
     }
     $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done with Preview'), 'isDefault' => true)));
 }
예제 #6
0
파일: Set.php 프로젝트: bhirsch/voipdev
 /** 
  * Function to build the price set form.
  * 
  * @return None 
  * @access public 
  */
 static function buildPriceSet(&$form)
 {
     $priceSetId = $form->get('priceSetId');
     if (!$priceSetId) {
         return;
     }
     $priceSet = self::getSetDetail($priceSetId, true);
     $form->_priceSet = CRM_Utils_Array::value($priceSetId, $priceSet);
     $form->assign('priceSet', $form->_priceSet);
     foreach ($form->_priceSet['fields'] as $field) {
         CRM_Price_BAO_Field::addQuickFormElement($form, 'price_' . $field['id'], $field['id'], false, CRM_Utils_Array::value('is_required', $field, false));
     }
 }
예제 #7
0
 /**
  * Process the form
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $params = array();
     $eventTitle = '';
     $params = $this->exportValues();
     $this->set('discountSection', 0);
     if (CRM_Utils_Array::value('_qf_Fee_submit', $_POST)) {
         $this->buildAmountLabel();
         $this->set('discountSection', 2);
         return;
     }
     if (array_key_exists('payment_processor', $params) && !CRM_Utils_System::isNull($params['payment_processor'])) {
         $params['payment_processor'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['payment_processor']));
     } else {
         $params['payment_processor'] = 'null';
     }
     $params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, 0);
     if ($this->_id) {
         // delete all the prior label values or discounts in the custom options table
         // and delete a price set if one exists
         if (CRM_Price_BAO_Set::removeFrom('civicrm_event', $this->_id)) {
             CRM_Core_BAO_Discount::del($this->_id, 'civicrm_event');
         }
     }
     if ($params['is_monetary']) {
         if (CRM_Utils_Array::value('price_set_id', $params)) {
             CRM_Price_BAO_Set::addTo('civicrm_event', $this->_id, $params['price_set_id']);
             if (CRM_Utils_Array::value('price_field_id', $params)) {
                 $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $params['price_field_id'], 'price_set_id');
                 CRM_Price_BAO_Set::setIsQuickConfig($priceSetID, 0);
             }
         } else {
             // if there are label / values, create custom options for them
             $labels = CRM_Utils_Array::value('label', $params);
             $values = CRM_Utils_Array::value('value', $params);
             $default = CRM_Utils_Array::value('default', $params);
             $options = array();
             if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) {
                 for ($i = 1; $i < self::NUM_OPTION; $i++) {
                     if (!empty($labels[$i]) && !CRM_Utils_System::isNull($values[$i])) {
                         $options[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i);
                     }
                 }
                 if (!empty($options)) {
                     $params['default_fee_id'] = NULL;
                     if (!CRM_Utils_Array::value('price_set_id', $params)) {
                         if (!CRM_Utils_Array::value('price_field_id', $params)) {
                             $eventTitle = $this->_isTemplate ? $this->_defaultValues['template_title'] : $this->_defaultValues['title'];
                             if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $eventTitle, 'id', 'title')) {
                                 $setParams['name'] = $setParams['title'] = $eventTitle;
                             } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $eventTitle . '_' . $this->_id, 'id', 'title')) {
                                 $setParams['name'] = $setParams['title'] = $eventTitle . '_' . $this->_id;
                             } else {
                                 $timeSec = explode(".", microtime(true));
                                 $setParams['name'] = $setParams['title'] = $eventTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
                             }
                             $setParams['is_quick_config'] = 1;
                             $setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent');
                             $priceSet = CRM_Price_BAO_Set::create($setParams);
                             $fieldParams['name'] = $fieldParams['label'] = $params['fee_label'];
                             $fieldParams['price_set_id'] = $priceSet->id;
                         } else {
                             foreach ($params['price_field_value'] as $arrayID => $fieldValueID) {
                                 if (empty($params['label'][$arrayID]) && empty($params['value'][$arrayID]) && !empty($fieldValueID)) {
                                     CRM_Price_BAO_FieldValue::setIsActive($fieldValueID, '0');
                                     unset($params['price_field_value'][$arrayID]);
                                 }
                             }
                             $fieldParams['id'] = CRM_Utils_Array::value('price_field_id', $params);
                             $fieldParams['option_id'] = $params['price_field_value'];
                             $priceSet->id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', CRM_Utils_Array::value('price_field_id', $params), 'price_set_id');
                         }
                         $fieldParams['html_type'] = 'Radio';
                         CRM_Price_BAO_Set::addTo('civicrm_event', $this->_id, $priceSet->id);
                         $fieldParams['option_label'] = $params['label'];
                         $fieldParams['option_amount'] = $params['value'];
                         foreach ($options as $value) {
                             $fieldParams['option_weight'][$value['weight']] = $value['weight'];
                         }
                         $fieldParams['default_option'] = $params['default'];
                         $priceField = CRM_Price_BAO_Field::create($fieldParams);
                     }
                 }
             }
             $discountPriceSets = CRM_Utils_Array::value('discount_price_set', $this->_defaultValues) ? $this->_defaultValues['discount_price_set'] : array();
             $discountFieldIDs = CRM_Utils_Array::value('discount_option_id', $this->_defaultValues) ? $this->_defaultValues['discount_option_id'] : array();
             if (CRM_Utils_Array::value('is_discount', $params) == 1) {
                 // if there are discounted set of label / values,
                 // create custom options for them
                 $labels = CRM_Utils_Array::value('discounted_label', $params);
                 $values = CRM_Utils_Array::value('discounted_value', $params);
                 $default = CRM_Utils_Array::value('discounted_default', $params);
                 if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) {
                     for ($j = 1; $j <= self::NUM_DISCOUNT; $j++) {
                         $discountOptions = array();
                         for ($i = 1; $i < self::NUM_OPTION; $i++) {
                             if (!empty($labels[$i]) && !empty($values[$i][$j])) {
                                 $discountOptions[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i][$j])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i);
                             }
                         }
                         if (!empty($discountOptions)) {
                             $fieldParams = array();
                             $params['default_discount_fee_id'] = NULL;
                             $keyCheck = $j - 1;
                             if (!CRM_Utils_Array::value($keyCheck, $discountPriceSets)) {
                                 if (!$eventTitle) {
                                     $eventTitle = strtolower(CRM_Utils_String::munge($this->_defaultValues['title'], '_', 200));
                                 }
                                 $setParams['title'] = $params['discount_name'][$j];
                                 if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $eventTitle . '_' . $params['discount_name'][$j], 'id', 'name')) {
                                     $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j];
                                 } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $eventTitle . '_' . $params['discount_name'][$j] . '_' . $this->_id, 'id', 'name')) {
                                     $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j] . '_' . $this->_id;
                                 } else {
                                     $timeSec = explode(".", microtime(true));
                                     $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j] . '_' . date('is', $timeSec[0]) . $timeSec[1];
                                 }
                                 $setParams['is_quick_config'] = 1;
                                 $setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent');
                                 $priceSet = CRM_Price_BAO_Set::create($setParams);
                                 $priceSetID = $priceSet->id;
                             } else {
                                 $priceSetID = $discountPriceSets[$j - 1];
                                 unset($discountPriceSets[$j - 1]);
                                 $fieldParams['id'] = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Field', $priceSetID, 'id', 'price_set_id');
                             }
                             $fieldParams['name'] = $fieldParams['label'] = $params['fee_label'];
                             $fieldParams['is_required'] = 1;
                             $fieldParams['price_set_id'] = $priceSetID;
                             $fieldParams['html_type'] = 'Radio';
                             foreach ($discountOptions as $value) {
                                 $fieldParams['option_label'][$value['weight']] = $value['label'];
                                 $fieldParams['option_amount'][$value['weight']] = $value['value'];
                                 $fieldParams['option_weight'][$value['weight']] = $value['weight'];
                                 if (CRM_Utils_Array::value('is_default', $value)) {
                                     $fieldParams['default_option'] = $value['weight'];
                                 }
                                 if (CRM_Utils_Array::value($j, $discountFieldIDs) && CRM_Utils_Array::value($value['weight'] - 1, $discountFieldIDs[$j])) {
                                     $fieldParams['option_id'][$value['weight']] = $discountFieldIDs[$j][$value['weight'] - 1];
                                     unset($discountFieldIDs[$j][$value['weight'] - 1]);
                                 }
                             }
                             //create discount priceset
                             $priceField = CRM_Price_BAO_Field::create($fieldParams);
                             if (!empty($discountFieldIDs)) {
                                 foreach ($discountFieldIDs as $fID) {
                                     CRM_Price_BAO_FieldValue::setIsActive($fID, '0');
                                 }
                             }
                             $discountParams = array('entity_table' => 'civicrm_event', 'entity_id' => $this->_id, 'option_group_id' => $priceSetID, 'start_date' => CRM_Utils_Date::processDate($params["discount_start_date"][$j]), 'end_date' => CRM_Utils_Date::processDate($params["discount_end_date"][$j]));
                             CRM_Core_BAO_Discount::add($discountParams);
                         }
                     }
                 }
             }
             if (!empty($discountPriceSets)) {
                 foreach ($discountPriceSets as $setId) {
                     CRM_Price_BAO_Set::setIsQuickConfig($setId, 0);
                 }
             }
         }
     } else {
         if (CRM_Utils_Array::value('price_field_id', $params)) {
             $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $params['price_field_id'], 'price_set_id');
             CRM_Price_BAO_Set::setIsQuickConfig($priceSetID, 0);
         }
         $params['contribution_type_id'] = '';
     }
     //update events table
     $params['id'] = $this->_id;
     CRM_Event_BAO_Event::add($params);
     parent::endPostProcess();
 }
예제 #8
0
 /**
  * This function for building custom fields
  * 
  * @param object  $qf             form object (reference)
  * @param string  $elementName    name of the custom field
  * @param boolean $inactiveNeeded 
  * @param boolean $useRequired    true if required else false
  * @param boolean $search         true if used for search else false
  * @param string  $label          label for custom field        
  *
  * @access public
  * @static
  */
 public static function addQuickFormElement(&$qf, $elementName, $fieldId, $inactiveNeeded, $useRequired = true, $label = null, $fieldOptions = null, $feezeOptions = array())
 {
     require_once 'CRM/Utils/Money.php';
     $field = new CRM_Price_DAO_Field();
     $field->id = $fieldId;
     if (!$field->find(true)) {
         /* FIXME: failure! */
         return null;
     }
     $config = CRM_Core_Config::singleton();
     $qf->assign('currencySymbol', CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Currency', $config->defaultCurrency, 'symbol', 'name'));
     if (!isset($label)) {
         $label = $field->label;
     }
     if (isset($qf->_online) && $qf->_online) {
         $useRequired = false;
     }
     $customOption = $fieldOptions;
     if (!is_array($customOption)) {
         $customOption = CRM_Price_BAO_Field::getOptions($field->id, $inactiveNeeded);
     }
     //use value field.
     $valueFieldName = 'amount';
     $seperator = '|';
     switch ($field->html_type) {
         case 'Text':
             $optionKey = key($customOption);
             $count = CRM_Utils_Array::value('count', $customOption[$optionKey], '');
             $max_value = CRM_Utils_Array::value('max_value', $customOption[$optionKey], '');
             $priceVal = implode($seperator, array($customOption[$optionKey][$valueFieldName], $count, $max_value));
             //check for label.
             if (CRM_Utils_Array::value('label', $fieldOptions[$optionKey])) {
                 $label = $fieldOptions[$optionKey]['label'];
             }
             if ($field->is_display_amounts) {
                 $label .= '&nbsp;-&nbsp;';
                 $label .= CRM_Utils_Money::format(CRM_Utils_Array::value($valueFieldName, $customOption[$optionKey]));
             }
             $element =& $qf->add('text', $elementName, $label, array_merge(array('size' => "4"), array('price' => json_encode(array($optionKey, $priceVal)))), $useRequired && $field->is_required);
             // CRM-6902
             if (in_array($optionKey, $feezeOptions)) {
                 $element->freeze();
             }
             // integers will have numeric rule applied to them.
             $qf->addRule($elementName, ts('%1 must be an integer (whole number).', array(1 => $label)), 'positiveInteger');
             break;
         case 'Radio':
             $choice = array();
             foreach ($customOption as $opId => $opt) {
                 if ($field->is_display_amounts) {
                     $opt['label'] .= '&nbsp;-&nbsp;';
                     $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]);
                 }
                 $count = CRM_Utils_Array::value('count', $opt, '');
                 $max_value = CRM_Utils_Array::value('max_value', $opt, '');
                 $priceVal = implode($seperator, array($opt[$valueFieldName], $count, $max_value));
                 $choice[$opId] = $qf->createElement('radio', null, '', $opt['label'], $opt['id'], array('price' => json_encode(array($elementName, $priceVal))));
                 // CRM-6902
                 if (in_array($opId, $feezeOptions)) {
                     $choice[$opId]->freeze();
                 }
             }
             if (!$field->is_required) {
                 // add "none" option
                 $choice[] = $qf->createElement('radio', null, '', '-none-', '0', array('price' => json_encode(array($elementName, "0"))));
             }
             $element =& $qf->addGroup($choice, $elementName, $label);
             if ($useRequired && $field->is_required) {
                 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
             }
             break;
         case 'Select':
             $selectOption = $allowedOptions = $priceVal = array();
             foreach ($customOption as $opt) {
                 $count = CRM_Utils_Array::value('count', $opt, '');
                 $max_value = CRM_Utils_Array::value('max_value', $opt, '');
                 $priceVal[$opt['id']] = implode($seperator, array($opt[$valueFieldName], $count, $max_value));
                 if ($field->is_display_amounts) {
                     $opt['label'] .= '&nbsp;-&nbsp;';
                     $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]);
                 }
                 $selectOption[$opt['id']] = $opt['label'];
                 if (!in_array($opt['id'], $feezeOptions)) {
                     $allowedOptions[] = $opt['id'];
                 }
             }
             $element =& $qf->add('select', $elementName, $label, array('' => ts('- select -')) + $selectOption, $useRequired && $field->is_required, array('price' => json_encode($priceVal)));
             // CRM-6902
             $button = substr($qf->controller->getButtonName(), -4);
             if (!empty($feezeOptions) && $button != 'skip') {
                 $qf->addRule($elementName, ts('Participant count for this option is full.'), 'regex', "/" . implode('|', $allowedOptions) . "/");
             }
             break;
         case 'CheckBox':
             $check = array();
             foreach ($customOption as $opId => $opt) {
                 $count = CRM_Utils_Array::value('count', $opt, '');
                 $max_value = CRM_Utils_Array::value('max_value', $opt, '');
                 $priceVal = implode($seperator, array($opt[$valueFieldName], $count, $max_value));
                 if ($field->is_display_amounts) {
                     $opt['label'] .= '&nbsp;-&nbsp;';
                     $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]);
                 }
                 $check[$opId] =& $qf->createElement('checkbox', $opt['id'], null, $opt['label'], array('price' => json_encode(array($opt['id'], $priceVal))));
                 // CRM-6902
                 if (in_array($opId, $feezeOptions)) {
                     $check[$opId]->freeze();
                 }
             }
             $element =& $qf->addGroup($check, $elementName, $label);
             if ($useRequired && $field->is_required) {
                 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
             }
             break;
     }
     if (isset($qf->_online) && $qf->_online) {
         $element->freeze();
     }
 }
 /**
  * (Queue Task Callback)
  *
  * Find any contribution records and create corresponding line-item
  * records.
  *
  * @param $startId int, the first/lowest contribution ID to convert
  * @param $endId int, the last/highest contribution ID to convert
  */
 static function task_4_2_alpha1_convertContributions(CRM_Queue_TaskContext $ctx, $startId, $endId)
 {
     $upgrade = new CRM_Upgrade_Form();
     $query = "\n INSERT INTO civicrm_line_item(`entity_table` ,`entity_id` ,`price_field_id` ,`label` , `qty` ,`unit_price` ,`line_total` ,`participant_count` ,`price_field_value_id`)\n SELECT 'civicrm_contribution',cc.id, cpf.id as price_field_id, cpfv.label, 1, cc.total_amount, cc.total_amount line_total, 0, cpfv.id as price_field_value\n FROM civicrm_membership_payment cmp\n LEFT JOIN `civicrm_contribution` cc ON cc.id = cmp.contribution_id\n LEFT JOIN civicrm_line_item cli ON cc.id=cli.entity_id and cli.entity_table = 'civicrm_contribution'\n LEFT JOIN civicrm_membership cm ON cm.id=cmp.membership_id\n LEFT JOIN civicrm_membership_type cmt ON cmt.id = cm.membership_type_id\n LEFT JOIN civicrm_price_field cpf ON BINARY cpf.name = cmt.member_of_contact_id\n LEFT JOIN civicrm_price_field_value cpfv ON cpfv.membership_type_id = cm.membership_type_id AND cpf.id = cpfv.price_field_id\n WHERE (cc.id BETWEEN %1 AND %2) AND cli.entity_id IS NULL ;\n ";
     $sqlParams = array(1 => array($startId, 'Integer'), 2 => array($endId, 'Integer'));
     CRM_Core_DAO::executeQuery($query, $sqlParams);
     // create lineitems for contribution done for membership
     $sql = "\nSELECT    cc.id, cmp.membership_id, cpse.price_set_id, cc.total_amount\nFROM      civicrm_contribution cc\nLEFT JOIN civicrm_line_item cli ON cc.id=cli.entity_id AND cli.entity_table = 'civicrm_contribution'\nLEFT JOIN civicrm_membership_payment cmp ON cc.id = cmp.contribution_id\nLEFT JOIN civicrm_participant_payment cpp ON cc.id = cpp.contribution_id\nLEFT JOIN civicrm_price_set_entity cpse on cpse.entity_table = 'civicrm_contribution_page' AND cpse.entity_id = cc.contribution_page_id\nWHERE     (cc.id BETWEEN %1 AND %2)\nAND       cli.entity_id IS NULL AND cc.contribution_page_id IS NOT NULL AND cpp.contribution_id IS NULL\nGROUP BY  cc.id\n";
     $result = CRM_Core_DAO::executeQuery($sql, $sqlParams);
     while ($result->fetch()) {
         $sql = "\nSELECT    cpf.id, cpfv.id as price_field_value_id, cpfv.label, cpfv.amount, cpfv.count\nFROM      civicrm_price_field cpf\nLEFT JOIN civicrm_price_field_value cpfv ON cpf.id = cpfv.price_field_id\nWHERE     cpf.price_set_id = %1\n";
         $lineParams = array('entity_table' => 'civicrm_contribution', 'entity_id' => $result->id);
         if ($result->membership_id) {
             $sql .= " AND cpf.name = %2 AND cpfv.membership_type_id = %3 ";
             $params = array('1' => array($result->price_set_id, 'Integer'), '2' => array('membership_amount', 'String'), '3' => array(CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $result->membership_id, 'membership_type_id'), 'Integer'));
             $res = CRM_Core_DAO::executeQuery($sql, $params);
             if ($res->fetch()) {
                 $lineParams += array('price_field_id' => $res->id, 'label' => $res->label, 'qty' => 1, 'unit_price' => $res->amount, 'line_total' => $res->amount, 'participant_count' => $res->count ? $res->count : 0, 'price_field_value_id' => $res->price_field_value_id);
             } else {
                 $lineParams['price_field_id'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $result->price_set_id, 'id', 'price_set_id');
                 $lineParams['label'] = 'Membership Amount';
                 $lineParams['qty'] = 1;
                 $lineParams['unit_price'] = $lineParams['line_total'] = $result->total_amount;
                 $lineParams['participant_count'] = 0;
             }
         } else {
             $sql .= "AND cpfv.amount = %2";
             $params = array('1' => array($result->price_set_id, 'Integer'), '2' => array($result->total_amount, 'String'));
             $res = CRM_Core_DAO::executeQuery($sql, $params);
             if ($res->fetch()) {
                 $lineParams += array('price_field_id' => $res->id, 'label' => $res->label, 'qty' => 1, 'unit_price' => $res->amount, 'line_total' => $res->amount, 'participant_count' => $res->count ? $res->count : 0, 'price_field_value_id' => $res->price_field_value_id);
             } else {
                 $params = array('price_set_id' => $result->price_set_id, 'name' => 'other_amount');
                 $defaults = array();
                 CRM_Price_BAO_Field::retrieve($params, $defaults);
                 if (!empty($defaults)) {
                     $lineParams['price_field_id'] = $defaults['id'];
                     $lineParams['label'] = $defaults['label'];
                     $lineParams['price_field_value_id'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_FieldValue', $defaults['id'], 'id', 'price_field_id');
                 } else {
                     $lineParams['price_field_id'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $result->price_set_id, 'id', 'price_set_id');
                     $lineParams['label'] = 'Contribution Amount';
                 }
                 $lineParams['qty'] = 1;
                 $lineParams['participant_count'] = 0;
                 $lineParams['unit_price'] = $lineParams['line_total'] = $result->total_amount;
             }
         }
         CRM_Price_BAO_LineItem::create($lineParams);
     }
     return TRUE;
 }
 /**
  * global form rule
  *
  * @param array $fields  the input form values
  * @param array $files   the uploaded files if any
  * @param array $options additional user data
  *
  * @return true if no errors, else array of errors
  * @access public
  * @static
  */
 static function formRule($fields, $files, $self)
 {
     $errors = array();
     //check if contact is selected in standalone mode
     if (isset($fields['contact_select_id'][1]) && !$fields['contact_select_id'][1]) {
         $errors['contact[1]'] = ts('Please select a contact or create new contact');
     }
     if (isset($fields['honor_type_id'])) {
         if (!(CRM_Utils_Array::value('honor_first_name', $fields) && CRM_Utils_Array::value('honor_last_name', $fields) || CRM_Utils_Array::value('honor_email', $fields))) {
             $errors['honor_first_name'] = ts('Honor First Name and Last Name OR an email should be set.');
         }
     }
     //check for Credit Card Contribution.
     if ($self->_mode) {
         if (empty($fields['payment_processor_id'])) {
             $errors['payment_processor_id'] = ts('Payment Processor is a required field.');
         }
     }
     // do the amount validations.
     if (!CRM_Utils_Array::value('total_amount', $fields) && empty($self->_lineItems)) {
         if ($priceSetId = CRM_Utils_Array::value('price_set_id', $fields)) {
             CRM_Price_BAO_Field::priceSetValidation($priceSetId, $fields, $errors);
         }
     }
     // if honor roll fields are populated but no PCP is selected
     if (!CRM_Utils_Array::value('pcp_made_through_id', $fields)) {
         if (CRM_Utils_Array::value('pcp_display_in_roll', $fields) || CRM_Utils_Array::value('pcp_roll_nickname', $fields) || CRM_Utils_Array::value('pcp_personal_note', $fields)) {
             $errors['pcp_made_through'] = ts('Please select a Personal Campaign Page, OR uncheck Display in Honor Roll and clear both the Honor Roll Name and the Personal Note field.');
         }
     }
     return $errors;
 }
 /**
  * Process the form
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
     $deletePriceSet = 0;
     if ($params['membership_type']) {
         // we do this in case the user has hit the forward/back button
         $dao = new CRM_Member_DAO_MembershipBlock();
         $dao->entity_table = 'civicrm_contribution_page';
         $dao->entity_id = $this->_id;
         $dao->find(TRUE);
         $membershipID = $dao->id;
         if ($membershipID) {
             $params['id'] = $membershipID;
         }
         $membershipTypes = array();
         if (is_array($params['membership_type'])) {
             foreach ($params['membership_type'] as $k => $v) {
                 if ($v) {
                     $membershipTypes[$k] = CRM_Utils_Array::value("auto_renew_{$k}", $params);
                 }
             }
         }
         // check for price set.
         $priceSetID = CRM_Utils_Array::value('member_price_set_id', $params);
         if (CRM_Utils_Array::value('member_is_active', $params) && is_array($membershipTypes) && !$priceSetID) {
             $usedPriceSetId = CRM_Price_BAO_Set::getFor('civicrm_contribution_page', $this->_id, 2);
             if (!CRM_Utils_Array::value('mem_price_field_id', $params) && !$usedPriceSetId) {
                 $pageTitle = strtolower(CRM_Utils_String::munge($this->_values['title'], '_', 245));
                 $setParams['title'] = $this->_values['title'];
                 if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $pageTitle, 'id', 'name')) {
                     $setParams['name'] = $pageTitle;
                 } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $pageTitle . '_' . $this->_id, 'id', 'name')) {
                     $setParams['name'] = $pageTitle . '_' . $this->_id;
                 } else {
                     $timeSec = explode(".", microtime(true));
                     $setParams['name'] = $pageTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
                 }
                 $setParams['is_quick_config'] = 1;
                 $setParams['extends'] = CRM_Core_Component::getComponentID('CiviMember');
                 $setParams['contribution_type_id'] = CRM_Utils_Array::value('contribution_type_id', $this->_values);
                 $priceSet = CRM_Price_BAO_Set::create($setParams);
                 $priceSetID = $priceSet->id;
                 $fieldParams['price_set_id'] = $priceSet->id;
             } elseif ($usedPriceSetId) {
                 $setParams['extends'] = CRM_Core_Component::getComponentID('CiviMember');
                 $setParams['contribution_type_id'] = CRM_Utils_Array::value('contribution_type_id', $this->_values);
                 $setParams['id'] = $usedPriceSetId;
                 $priceSet = CRM_Price_BAO_Set::create($setParams);
                 $priceSetID = $priceSet->id;
                 $fieldParams['price_set_id'] = $priceSet->id;
             } else {
                 $fieldParams['id'] = CRM_Utils_Array::value('mem_price_field_id', $params);
                 $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', CRM_Utils_Array::value('mem_price_field_id', $params), 'price_set_id');
             }
             $editedFieldParams = array('price_set_id' => $priceSetID, 'name' => 'membership_amount');
             $editedResults = array();
             CRM_Price_BAO_Field::retrieve($editedFieldParams, $editedResults);
             if (!CRM_Utils_Array::value('id', $editedResults)) {
                 $fieldParams['name'] = strtolower(CRM_Utils_String::munge('Membership Amount', '_', 245));
                 $fieldParams['label'] = CRM_Utils_Array::value('new_title', $params) ? $params['new_title'] : 'Membership Amount';
                 if (!CRM_Utils_Array::value('mem_price_field_id', $params)) {
                     CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_Field', 0, 1, array('price_set_id' => $priceSetID));
                 }
                 $fieldParams['weight'] = 1;
             } else {
                 $fieldParams['id'] = CRM_Utils_Array::value('id', $editedResults);
             }
             $fieldParams['is_active'] = 1;
             $fieldParams['html_type'] = 'Radio';
             $fieldParams['is_required'] = CRM_Utils_Array::value('is_required', $params) ? 1 : 0;
             $fieldParams['is_display_amounts'] = CRM_Utils_Array::value('display_min_fee', $params) ? 1 : 0;
             $rowCount = 1;
             $options = array();
             if (CRM_Utils_Array::value('id', $fieldParams)) {
                 CRM_Core_PseudoConstant::populate($options, 'CRM_Price_DAO_FieldValue', TRUE, 'membership_type_id', NULL, " price_field_id = {$fieldParams['id']} ");
             }
             foreach ($membershipTypes as $memType => $memAutoRenew) {
                 if ($priceFieldID = CRM_Utils_Array::key($memType, $options)) {
                     $fieldParams['option_id'][$rowCount] = $priceFieldID;
                     unset($options[$priceFieldID]);
                 }
                 $membetype = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($memType);
                 $fieldParams['option_label'][$rowCount] = CRM_Utils_Array::value('name', $membetype);
                 $fieldParams['option_amount'][$rowCount] = CRM_Utils_Array::value('minimum_fee', $membetype, 0);
                 $fieldParams['option_weight'][$rowCount] = CRM_Utils_Array::value('weight', $membetype);
                 $fieldParams['option_description'][$rowCount] = CRM_Utils_Array::value('description', $membetype);
                 $fieldParams['default_option'] = CRM_Utils_Array::value('membership_type_default', $params);
                 $fieldParams['membership_type_id'][$rowCount] = $memType;
                 // [$rowCount] = $membetype[''];
                 $rowCount++;
             }
             foreach ($options as $priceFieldID => $memType) {
                 CRM_Price_BAO_FieldValue::setIsActive($priceFieldID, '0');
             }
             $priceField = CRM_Price_BAO_Field::create($fieldParams);
         } elseif (!$priceSetID) {
             $deletePriceSet = 1;
         }
         $params['is_required'] = CRM_Utils_Array::value('is_required', $params, FALSE);
         $params['is_active'] = CRM_Utils_Array::value('member_is_active', $params, FALSE);
         if ($priceSetID) {
             $params['membership_types'] = 'null';
             $params['membership_type_default'] = CRM_Utils_Array::value('membership_type_default', $params, 'null');
             $params['membership_types'] = serialize($membershipTypes);
             $params['display_min_fee'] = CRM_Utils_Array::value('display_min_fee', $params, FALSE);
             $params['is_separate_payment'] = CRM_Utils_Array::value('is_separate_payment', $params, FALSE);
         }
         $params['entity_table'] = 'civicrm_contribution_page';
         $params['entity_id'] = $this->_id;
         $dao = new CRM_Member_DAO_MembershipBlock();
         $dao->copyValues($params);
         $dao->save();
         if ($priceSetID && $params['is_active']) {
             CRM_Price_BAO_Set::addTo('civicrm_contribution_page', $this->_id, $priceSetID);
         }
         if ($deletePriceSet || !CRM_Utils_Array::value('member_is_active', $params, FALSE)) {
             if ($this->_memPriceSetId) {
                 $pFIDs = array();
                 $conditionParams = array('price_set_id' => $this->_memPriceSetId, 'html_type' => 'radio', 'name' => 'contribution_amount');
                 CRM_Core_DAO::commonRetrieve('CRM_Price_DAO_Field', $conditionParams, $pFIDs);
                 if (!CRM_Utils_Array::value('id', $pFIDs)) {
                     CRM_Price_BAO_Set::removeFrom('civicrm_contribution_page', $this->_id);
                     CRM_Price_BAO_Set::setIsQuickConfig($this->_memPriceSetId, '0');
                 } else {
                     CRM_Price_BAO_Field::setIsActive($params['mem_price_field_id'], '0');
                 }
             }
         }
     }
     parent::endPostProcess();
 }
 /**
  * Function to record line items for default membership
  *
  * @param $qf object
  *
  * @param $membershipType array with membership type and organization
  *
  * @param$ priceSetId priceset id
  * @access public
  * @static
  */
 static function createLineItems(&$qf, $membershipType, &$priceSetId)
 {
     $qf->_priceSetId = $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', 'default_membership_type_amount', 'id', 'name');
     if ($priceSetId) {
         $qf->_priceSet = $priceSets = current(CRM_Price_BAO_Set::getSetDetail($priceSetId));
     }
     $editedFieldParams = array('price_set_id' => $priceSetId, 'name' => $membershipType[0]);
     $editedResults = array();
     CRM_Price_BAO_Field::retrieve($editedFieldParams, $editedResults);
     if (!empty($editedResults)) {
         unset($qf->_priceSet['fields']);
         $qf->_priceSet['fields'][$editedResults['id']] = $priceSets['fields'][$editedResults['id']];
         unset($qf->_priceSet['fields'][$editedResults['id']]['options']);
         $fid = $editedResults['id'];
         $editedFieldParams = array('price_field_id' => $editedResults['id'], 'membership_type_id' => $membershipType[1]);
         $editedResults = array();
         CRM_Price_BAO_FieldValue::retrieve($editedFieldParams, $editedResults);
         $qf->_priceSet['fields'][$fid]['options'][$editedResults['id']] = $priceSets['fields'][$fid]['options'][$editedResults['id']];
         if (CRM_Utils_Array::value('total_amount', $qf->_params)) {
             $qf->_priceSet['fields'][$fid]['options'][$editedResults['id']]['amount'] = $qf->_params['total_amount'];
         }
     }
     $fieldID = key($qf->_priceSet['fields']);
     $qf->_params['price_' . $fieldID] = $editedResults['id'];
 }
예제 #13
0
 /**  
  * global form rule  
  *  
  * @param array $fields  the input form values  
  * @param array $files   the uploaded files if any  
  * @param array $options additional user data  
  *  
  * @return true if no errors, else array of errors  
  * @access public  
  * @static  
  */
 static function formRule(&$fields, &$files, $self)
 {
     $errors = array();
     //check if contact is selected in standalone mode
     if (isset($fields['contact_select_id']) && !$fields['contact_select_id']) {
         $errors['contact'] = ts('Please select a contact or create new contact');
     }
     if (isset($fields["honor_type_id"])) {
         if (!(CRM_Utils_Array::value('honor_first_name', $fields) && CRM_Utils_Array::value('honor_last_name', $fields) || CRM_Utils_Array::value('honor_email', $fields))) {
             $errors['honor_first_name'] = ts('Honor First Name and Last Name OR an email should be set.');
         }
     }
     //check for Credit Card Contribution.
     if ($self->_mode) {
         if (empty($fields['payment_processor_id'])) {
             $errors['payment_processor_id'] = ts('Payment Processor is a required field.');
         }
     }
     // do the amount validations.
     if (!CRM_Utils_Array::value('total_amount', $fields) && empty($self->_lineItems)) {
         if ($priceSetId = CRM_Utils_Array::value('price_set_id', $fields)) {
             require_once 'CRM/Price/BAO/Field.php';
             CRM_Price_BAO_Field::priceSetValidation($priceSetId, $fields, $errors);
         } else {
             $errors['total_amount'] = ts('Please enter a valid amount.');
         }
     }
     return $errors;
 }
예제 #14
0
파일: Option.php 프로젝트: ksecor/civicrm
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the  
  * type of action and executes that action. 
  * 
  * @param null
  * 
  * @return void
  * @access public
  */
 function run()
 {
     require_once 'CRM/Price/BAO/Field.php';
     // get the field id
     $this->_fid = CRM_Utils_Request::retrieve('fid', 'Positive', $this, false, 0);
     //get the price set id
     if (!$this->_sid) {
         $this->_sid = CRM_Utils_Request::retrieve('sid', 'Positive', $this);
     }
     //as url contain $sid so append breadcrumb dynamically.
     $breadcrumb = array(array('title' => ts('Price Fields'), 'url' => CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&sid=' . $this->_sid)));
     CRM_Utils_System::appendBreadCrumb($breadcrumb);
     if ($this->_fid) {
         $fieldTitle = CRM_Price_BAO_Field::getTitle($this->_fid);
         $this->assign('fid', $this->_fid);
         $this->assign('fieldTitle', $fieldTitle);
         CRM_Utils_System::setTitle(ts('%1 - Price Options', array(1 => $fieldTitle)));
         $htmlType = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Field', $this->_fid, 'html_type');
         $this->assign('addMoreFields', true);
         //for text price field only single option present
         if ($htmlType == 'Text') {
             $this->assign('addMoreFields', false);
         }
     }
     // get the requested action
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'browse');
     // default to 'browse'
     // assign vars to templates
     $this->assign('action', $action);
     $oid = CRM_Utils_Request::retrieve('oid', 'Positive', $this, false, 0);
     // what action to take ?
     if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::VIEW | CRM_Core_Action::DELETE)) {
         $this->edit($action);
         // no browse for edit/update/view
     } else {
         require_once 'CRM/Core/BAO/OptionValue.php';
         $this->browse();
     }
     // Call the parents run method
     parent::run();
 }
예제 #15
0
 /** 
  * Function to build the price set form.
  * 
  * @return None 
  * @access public 
  */
 static function buildPriceSet(&$form)
 {
     $priceSetId = $form->get('priceSetId');
     if (!$priceSetId) {
         return;
     }
     $priceSet = self::getSetDetail($priceSetId, true);
     $form->_priceSet = CRM_Utils_Array::value($priceSetId, $priceSet);
     $form->assign('priceSet', $form->_priceSet);
     require_once 'CRM/Core/PseudoConstant.php';
     $className = CRM_Utils_System::getClassName($form);
     if ($className == 'CRM_Contribute_Form_Contribution_Main') {
         $feeBlock =& $form->_values['fee'];
     } else {
         $feeBlock =& $form->_priceSet['fields'];
     }
     // call the hook.
     require_once 'CRM/Utils/Hook.php';
     CRM_Utils_Hook::buildAmount('contribution', $form, $feeBlock);
     foreach ($feeBlock as $field) {
         if (CRM_Utils_Array::value('visibility', $field) == 'public' || $className == 'CRM_Contribute_Form_Contribution') {
             $options = CRM_Utils_Array::value('options', $field);
             if (!is_array($options)) {
                 continue;
             }
             CRM_Price_BAO_Field::addQuickFormElement($form, 'price_' . $field['id'], $field['id'], false, CRM_Utils_Array::value('is_required', $field, false), null, $options);
         }
     }
 }
예제 #16
0
파일: Field.php 프로젝트: bhirsch/voipdev
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the  
  * type of action and executes that action. 
  * 
  * @param null
  * 
  * @return void
  * @access public
  */
 function run()
 {
     require_once 'CRM/Price/BAO/Set.php';
     // get the group id
     $this->_sid = CRM_Utils_Request::retrieve('sid', 'Positive', $this);
     $fid = CRM_Utils_Request::retrieve('fid', 'Positive', $this, false, 0);
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'browse');
     // default to 'browse'
     if ($this->_sid) {
         require_once 'CRM/Price/BAO/Set.php';
         CRM_Price_BAO_Set::checkPermission($this->_sid);
     }
     if ($action & CRM_Core_Action::DELETE) {
         require_once 'CRM/Price/BAO/Set.php';
         $usedBy =& CRM_Price_BAO_Set::getUsedBy($this->_sid);
         if (empty($usedBy)) {
             // prompt to delete
             $session =& CRM_Core_Session::singleton();
             $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid));
             $controller =& new CRM_Core_Controller_Simple('CRM_Price_Form_DeleteField', "Delete Price Field", '');
             $controller->set('fid', $fid);
             $controller->setEmbedded(true);
             $controller->process();
             $controller->run();
         } else {
             // add breadcrumb
             require_once 'CRM/Price/BAO/Field.php';
             $url = CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1');
             CRM_Utils_System::appendBreadCrumb(ts('Price'), $url);
             $this->assign('usedPriceSetTitle', CRM_Price_BAO_Field::getTitle($fid));
             $this->assign('usedBy', $usedBy);
             $comps = array("Event" => "civicrm_event", "Contribution" => "civicrm_contribution_page");
             $priceSetContexts = array();
             foreach ($comps as $name => $table) {
                 if (array_key_exists($table, $usedBy)) {
                     $priceSetContexts[] = $name;
                 }
             }
             $this->assign('contexts', $priceSetContexts);
         }
     }
     if ($this->_sid) {
         $groupTitle = CRM_Price_BAO_Set::getTitle($this->_sid);
         $this->assign('sid', $this->_sid);
         $this->assign('groupTitle', $groupTitle);
         CRM_Utils_System::setTitle(ts('%1 - Price Fields', array(1 => $groupTitle)));
     }
     // assign vars to templates
     $this->assign('action', $action);
     // what action to take ?
     if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) {
         $this->edit($action);
         // no browse for edit/update/view
     } else {
         if ($action & CRM_Core_Action::PREVIEW) {
             $this->preview($fid);
         } else {
             require_once 'CRM/Price/BAO/Field.php';
             $this->browse();
         }
     }
     // Call the parents run method
     parent::run();
 }
예제 #17
0
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the
  * type of action and executes that action.
  *
  * @param null
  *
  * @return void
  * @access public
  */
 function run()
 {
     // get the group id
     $this->_sid = CRM_Utils_Request::retrieve('sid', 'Positive', $this);
     $fid = CRM_Utils_Request::retrieve('fid', 'Positive', $this, FALSE, 0);
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
     if ($this->_sid) {
         $usedBy = CRM_Price_BAO_Set::getUsedBy($this->_sid);
         $this->assign('usedBy', $usedBy);
         $this->_isSetReserved = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $this->_sid, 'is_reserved');
         $this->assign('isReserved', $this->_isSetReserved);
         CRM_Price_BAO_Set::checkPermission($this->_sid);
         $comps = array('Event' => 'civicrm_event', 'Contribution' => 'civicrm_contribution_page');
         $priceSetContexts = array();
         foreach ($comps as $name => $table) {
             if (array_key_exists($table, $usedBy)) {
                 $priceSetContexts[] = $name;
             }
         }
         $this->assign('contexts', $priceSetContexts);
     }
     if ($action & CRM_Core_Action::DELETE && !$this->_isSetReserved) {
         if (empty($usedBy)) {
             // prompt to delete
             $session = CRM_Core_Session::singleton();
             $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid));
             $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_DeleteField', 'Delete Price Field', '');
             $controller->set('fid', $fid);
             $controller->setEmbedded(TRUE);
             $controller->process();
             $controller->run();
         } else {
             // add breadcrumb
             $url = CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1');
             CRM_Utils_System::appendBreadCrumb(ts('Price'), $url);
             $this->assign('usedPriceSetTitle', CRM_Price_BAO_Field::getTitle($fid));
         }
     }
     if ($this->_sid) {
         $groupTitle = CRM_Price_BAO_Set::getTitle($this->_sid);
         $this->assign('sid', $this->_sid);
         $this->assign('groupTitle', $groupTitle);
         CRM_Utils_System::setTitle(ts('%1 - Price Fields', array(1 => $groupTitle)));
     }
     // assign vars to templates
     $this->assign('action', $action);
     // what action to take ?
     if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD) && !$this->_isSetReserved) {
         // no browse for edit/update/view
         $this->edit($action);
     } elseif ($action & CRM_Core_Action::PREVIEW) {
         $this->preview($fid);
     } else {
         $this->browse();
     }
     // Call the parents run method
     return parent::run();
 }
 /**
  * build the radio/text form elements for the amount field
  *
  * @param object   $form form object
  * @param boolean  $required  true if you want to add formRule
  * @param int      $discountId discount id for the event
  *
  * @return void
  * @access public
  * @static
  */
 public static function buildAmount(&$form, $required = TRUE, $discountId = NULL)
 {
     //if payment done, no need to build the fee block.
     if (isset($form->_paymentId) && $form->_paymentId) {
         //fix to diaplay line item in update mode.
         $form->assign('priceSet', isset($form->_priceSet) ? $form->_priceSet : NULL);
         return;
     }
     $feeFields = CRM_Utils_Array::value('fee', $form->_values);
     if (is_array($feeFields)) {
         $form->_feeBlock =& $form->_values['fee'];
     }
     //check for discount.
     $discountedFee = CRM_Utils_Array::value('discount', $form->_values);
     if (is_array($discountedFee) && !empty($discountedFee)) {
         if (!$discountId) {
             $form->_discountId = $discountId = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event');
         }
         if ($discountId) {
             $form->_feeBlock =& $form->_values['discount'][$discountId];
         }
     }
     if (!is_array($form->_feeBlock)) {
         $form->_feeBlock = array();
     }
     //its time to call the hook.
     CRM_Utils_Hook::buildAmount('event', $form, $form->_feeBlock);
     //reset required if participant is skipped.
     $button = substr($form->controller->getButtonName(), -4);
     if ($required && $button == 'skip') {
         $required = FALSE;
     }
     $className = CRM_Utils_System::getClassName($form);
     //build the priceset fields.
     if (isset($form->_priceSetId) && $form->_priceSetId) {
         //format price set fields across option full.
         self::formatFieldsForOptionFull($form);
         $form->add('hidden', 'priceSetId', $form->_priceSetId);
         foreach ($form->_feeBlock as $field) {
             if (CRM_Utils_Array::value('visibility', $field) == 'public' || $className == 'CRM_Event_Form_Participant') {
                 $fieldId = $field['id'];
                 $elementName = 'price_' . $fieldId;
                 $isRequire = CRM_Utils_Array::value('is_required', $field);
                 if ($button == 'skip') {
                     $isRequire = FALSE;
                 }
                 //user might modified w/ hook.
                 $options = CRM_Utils_Array::value('options', $field);
                 if (!is_array($options)) {
                     continue;
                 }
                 $optionFullIds = CRM_Utils_Array::value('option_full_ids', $field, array());
                 //soft suppress required rule when option is full.
                 if (!empty($optionFullIds) && count($options) == count($optionFullIds)) {
                     $isRequire = FALSE;
                 }
                 //build the element.
                 CRM_Price_BAO_Field::addQuickFormElement($form, $elementName, $fieldId, FALSE, $isRequire, NULL, $options, $optionFullIds);
             }
         }
         $form->assign('priceSet', $form->_priceSet);
     } else {
         $eventFeeBlockValues = array();
         foreach ($form->_feeBlock as $fee) {
             if (is_array($fee)) {
                 //CRM-7632, CRM-6201
                 $totalAmountJs = NULL;
                 if ($className == 'CRM_Event_Form_Participant') {
                     $totalAmountJs = array('onClick' => "fillTotalAmount(" . $fee['value'] . ")");
                 }
                 $eventFeeBlockValues['amount_id_' . $fee['amount_id']] = $fee['value'];
                 $elements[] =& $form->createElement('radio', NULL, '', CRM_Utils_Money::format($fee['value']) . ' ' . $fee['label'], $fee['amount_id'], $totalAmountJs);
             }
         }
         $form->assign('eventFeeBlockValues', json_encode($eventFeeBlockValues));
         $form->_defaults['amount'] = CRM_Utils_Array::value('default_fee_id', $form->_values['event']);
         $element =& $form->addGroup($elements, 'amount', ts('Event Fee(s)'), '<br />');
         if (isset($form->_online) && $form->_online) {
             $element->freeze();
         }
         if ($required) {
             $form->addRule('amount', ts('Fee Level is a required field.'), 'required');
         }
     }
 }
예제 #19
0
파일: Field.php 프로젝트: bhirsch/voipdev
 /**
  * This function for building custom fields
  * 
  * @param object  $qf             form object (reference)
  * @param string  $elementName    name of the custom field
  * @param boolean $inactiveNeeded 
  * @param boolean $useRequired    true if required else false
  * @param boolean $search         true if used for search else false
  * @param string  $label          label for custom field        
  *
  * @access public
  * @static
  */
 public static function addQuickFormElement(&$qf, $elementName, $fieldId, $inactiveNeeded, $useRequired = true, $label = null)
 {
     require_once 'CRM/Utils/Money.php';
     $field =& new CRM_Price_DAO_Field();
     $field->id = $fieldId;
     if (!$field->find(true)) {
         /* FIXME: failure! */
         return null;
     }
     $config =& CRM_Core_Config::singleton();
     $qf->assign('currencySymbol', CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Currency', $config->defaultCurrency, 'symbol', 'name'));
     if (!isset($label)) {
         $label = $field->label;
     }
     if (isset($qf->_online) && $qf->_online) {
         $useRequired = false;
     }
     //use value field.
     $valueFieldName = 'value';
     switch ($field->html_type) {
         case 'Text':
             $customOption = CRM_Price_BAO_Field::getOptions($field->id, $inactiveNeeded);
             // text fields only have one option
             $optionKey = key($customOption);
             if ($field->is_display_amounts) {
                 $label .= '&nbsp;-&nbsp;';
                 $label .= CRM_Utils_Money::format(CRM_Utils_Array::value($valueFieldName, $customOption[$optionKey]));
             }
             $element =& $qf->add('text', $elementName, $label, array_merge(array('size' => "4"), array('price' => json_encode(array($optionKey, $customOption[$optionKey][$valueFieldName])))), $useRequired && $field->is_required);
             // integers will have numeric rule applied to them.
             $qf->addRule($elementName, ts('%1 must be an integer (whole number).', array(1 => $label)), 'positiveInteger');
             break;
         case 'Radio':
             $choice = array();
             $customOption = CRM_Price_BAO_Field::getOptions($field->id, $inactiveNeeded);
             if (!$field->is_required) {
                 // add "none" option
                 $choice[] = $qf->createElement('radio', null, '', '-none-', '0', array('price' => json_encode(array($elementName, "0"))));
             }
             foreach ($customOption as $opt) {
                 if ($field->is_display_amounts) {
                     $opt['label'] .= '&nbsp;-&nbsp;';
                     $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]);
                 }
                 $choice[] = $qf->createElement('radio', null, '', $opt['label'], $opt['id'], array('price' => json_encode(array($elementName, $opt[$valueFieldName]))));
             }
             $element =& $qf->addGroup($choice, $elementName, $label);
             if ($useRequired && $field->is_required) {
                 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
             }
             break;
         case 'Select':
             $customOption = CRM_Price_BAO_Field::getOptions($field->id, $inactiveNeeded);
             $selectOption = array();
             foreach ($customOption as $opt) {
                 $amount[$opt['id']] = $opt[$valueFieldName];
                 if ($field->is_display_amounts) {
                     $opt['label'] .= '&nbsp;-&nbsp;';
                     $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]);
                 }
                 $selectOption[$opt['id']] = $opt['label'];
             }
             $element =& $qf->add('select', $elementName, $label, array('' => ts('- select -')) + $selectOption, $useRequired && $field->is_required, array('price' => json_encode($amount)));
             break;
         case 'CheckBox':
             $customOption = CRM_Price_BAO_Field::getOptions($field->id, $inactiveNeeded);
             $check = array();
             foreach ($customOption as $opt) {
                 if ($field->is_display_amounts) {
                     $opt['label'] .= '&nbsp;-&nbsp;';
                     $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]);
                 }
                 $check[] =& $qf->createElement('checkbox', $opt['id'], null, $opt['label'], array('price' => json_encode(array($opt['id'], $opt[$valueFieldName]))));
             }
             $element =& $qf->addGroup($check, $elementName, $label);
             if ($useRequired && $field->is_required) {
                 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
             }
             break;
     }
     if (isset($qf->_online) && $qf->_online) {
         $element->freeze();
     }
 }
예제 #20
0
 /**
  * global validation rules for the form
  *
  * @param array $fields posted values of the form
  *
  * @return array list of errors to be posted back to the form
  * @static
  * @access public
  */
 static function formRule($values, $files, $self)
 {
     // If $values['_qf_Participant_next'] is Delete or
     // $values['event_id'] is empty, then return
     // instead of proceeding further.
     if (CRM_Utils_Array::value('_qf_Participant_next', $values) == 'Delete' || !$values['event_id']) {
         return true;
     }
     //check if contact is selected in standalone mode
     if (isset($values['contact_select_id'][1]) && !$values['contact_select_id'][1]) {
         $errorMsg['contact[1]'] = ts('Please select a contact or create new contact');
     }
     if (CRM_Utils_Array::value('payment_processor_id', $values)) {
         // make sure that credit card number and cvv are valid
         require_once 'CRM/Utils/Rule.php';
         if (CRM_Utils_Array::value('credit_card_type', $values)) {
             if (CRM_Utils_Array::value('credit_card_number', $values) && !CRM_Utils_Rule::creditCardNumber($values['credit_card_number'], $values['credit_card_type'])) {
                 $errorMsg['credit_card_number'] = ts("Please enter a valid Credit Card Number");
             }
             if (CRM_Utils_Array::value('cvv2', $values) && !CRM_Utils_Rule::cvv($values['cvv2'], $values['credit_card_type'])) {
                 $errorMsg['cvv2'] = ts("Please enter a valid Credit Card Verification Number");
             }
         }
     }
     if (CRM_Utils_Array::value('record_contribution', $values) && !CRM_Utils_Array::value('contribution_type_id', $values)) {
         $errorMsg['contribution_type_id'] = ts("Please enter the associated Contribution Type");
     }
     // validate contribution status for 'Failed'.
     if ($self->_onlinePendingContributionId && CRM_Utils_Array::value('record_contribution', $values) && CRM_Utils_Array::value('contribution_status_id', $values) == array_search('Failed', CRM_Contribute_PseudoConstant::contributionStatus(null, 'name'))) {
         $errorMsg['contribution_status_id'] = ts("Please select a valid payment status before updating.");
     }
     // do the amount validations.
     //skip for update mode since amount is freeze, CRM-6052
     if (!$self->_id && !CRM_Utils_Array::value('total_amount', $values) && empty($self->_values['line_items']) || $self->_id && !$self->_paymentId && is_array($self->_values['line_items'])) {
         if ($priceSetId = CRM_Utils_Array::value('priceSetId', $values)) {
             require_once 'CRM/Price/BAO/Field.php';
             CRM_Price_BAO_Field::priceSetValidation($priceSetId, $values, $errorMsg);
         }
     }
     return CRM_Utils_Array::crmIsEmptyArray($errorMsg) ? true : $errorMsg;
 }
예제 #21
0
 /**
  * This function for building custom fields
  *
  * @param object  $qf             form object (reference)
  * @param string  $elementName    name of the custom field
  * @param boolean $inactiveNeeded
  * @param boolean $useRequired    true if required else false
  * @param boolean $search         true if used for search else false
  * @param string  $label          label for custom field
  *
  * @access public
  * @static
  */
 public static function addQuickFormElement(&$qf, $elementName, $fieldId, $inactiveNeeded, $useRequired = TRUE, $label = NULL, $fieldOptions = NULL, $feezeOptions = array())
 {
     $field = new CRM_Price_DAO_Field();
     $field->id = $fieldId;
     if (!$field->find(TRUE)) {
         /* FIXME: failure! */
         return NULL;
     }
     $otherAmount = $qf->get('values');
     $config = CRM_Core_Config::singleton();
     $qf->assign('currencySymbol', CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Currency', $config->defaultCurrency, 'symbol', 'name'));
     // get currency name for price field and option attributes
     $currencyName = $config->defaultCurrency;
     if (!isset($label)) {
         $label = property_exists($qf, '_membershipBlock') && CRM_Utils_Array::value('is_separate_payment', $qf->_membershipBlock) && $field->name == 'contribution_amount' && !CRM_Utils_Array::value('is_allow_other_amount', $otherAmount) ? ts('Additional Contribution') : $field->label;
     }
     if ($field->name == 'contribution_amount') {
         $qf->_contributionAmount = 1;
     }
     if (isset($qf->_online) && $qf->_online) {
         $useRequired = FALSE;
     }
     $customOption = $fieldOptions;
     if (!is_array($customOption)) {
         $customOption = CRM_Price_BAO_Field::getOptions($field->id, $inactiveNeeded);
     }
     //use value field.
     $valueFieldName = 'amount';
     $seperator = '|';
     switch ($field->html_type) {
         case 'Text':
             $optionKey = key($customOption);
             $count = CRM_Utils_Array::value('count', $customOption[$optionKey], '');
             $max_value = CRM_Utils_Array::value('max_value', $customOption[$optionKey], '');
             $priceVal = implode($seperator, array($customOption[$optionKey][$valueFieldName], $count, $max_value));
             $extra = array();
             if (property_exists($qf, '_quickConfig') && $qf->_quickConfig && property_exists($qf, '_contributionAmount') && $qf->_contributionAmount) {
                 $qf->assign('priceset', $elementName);
                 $extra = array('onclick' => 'useAmountOther();');
             }
             // if seperate membership payment is used with quick config priceset then change the other amount label
             if (property_exists($qf, '_membershipBlock') && CRM_Utils_Array::value('is_separate_payment', $qf->_membershipBlock) && $qf->_quickConfig && $field->name == 'other_amount' && !property_exists($qf, '_contributionAmount')) {
                 $label = ts('Additional Contribution');
                 $useRequired = 0;
             } elseif (CRM_Utils_Array::value('label', $fieldOptions[$optionKey])) {
                 //check for label.
                 $label = $fieldOptions[$optionKey]['label'];
             }
             if ($field->is_display_amounts) {
                 $label .= '&nbsp;-&nbsp;';
                 $label .= CRM_Utils_Money::format(CRM_Utils_Array::value($valueFieldName, $customOption[$optionKey]));
             }
             $element =& $qf->add('text', $elementName, $label, array_merge($extra, array('price' => json_encode(array($optionKey, $priceVal)), 'size' => '4')), $useRequired && $field->is_required);
             // CRM-6902
             if (in_array($optionKey, $feezeOptions)) {
                 $element->freeze();
             }
             //CRM-10117
             if (property_exists($qf, '_quickConfig') && $qf->_quickConfig) {
                 $message = ts("Please enter a valid amount.");
                 $type = "money";
             } else {
                 $message = ts('%1 must be an integer (whole number).', array(1 => $label));
                 $type = "positiveInteger";
             }
             // integers will have numeric rule applied to them.
             $qf->addRule($elementName, $message, $type);
             break;
         case 'Radio':
             $choice = array();
             if (property_exists($qf, '_quickConfig') && $qf->_quickConfig && property_exists($qf, '_contributionAmount') && $qf->_contributionAmount) {
                 $qf->assign('contriPriceset', $elementName);
             }
             foreach ($customOption as $opId => $opt) {
                 if ($field->is_display_amounts) {
                     $opt['label'] = CRM_Utils_Array::value('label', $opt) ? $opt['label'] . '&nbsp;-&nbsp;' : '';
                     $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]);
                 }
                 $count = CRM_Utils_Array::value('count', $opt, '');
                 $max_value = CRM_Utils_Array::value('max_value', $opt, '');
                 $priceVal = implode($seperator, array($opt[$valueFieldName], $count, $max_value));
                 $extra = array('price' => json_encode(array($elementName, $priceVal)), 'data-amount' => $opt[$valueFieldName], 'data-currency' => $currencyName);
                 if (property_exists($qf, '_quickConfig') && $qf->_quickConfig && $field->name == 'contribution_amount') {
                     $extra += array('onclick' => 'clearAmountOther();');
                 } elseif (property_exists($qf, '_quickConfig') && $qf->_quickConfig && $field->name == 'membership_amount') {
                     $extra += array('onclick' => "return showHideAutoRenew({$opt['membership_type_id']});", 'membership-type' => $opt['membership_type_id']);
                     $qf->assign('membershipFieldID', $field->id);
                 }
                 $choice[$opId] = $qf->createElement('radio', NULL, '', $opt['label'], $opt['id'], $extra);
                 // CRM-6902
                 if (in_array($opId, $feezeOptions)) {
                     $choice[$opId]->freeze();
                 }
             }
             if (property_exists($qf, '_membershipBlock') && CRM_Utils_Array::value('is_separate_payment', $qf->_membershipBlock) && $field->name == 'contribution_amount') {
                 $choice[] = $qf->createElement('radio', NULL, '', 'No thank you', '-1', array('onclick' => 'clearAmountOther();'));
             }
             if (!$field->is_required) {
                 // add "none" option
                 if (CRM_Utils_Array::value('is_allow_other_amount', $otherAmount) && $field->name == 'contribution_amount') {
                     $none = ts('Other Amount');
                 } elseif (property_exists($qf, '_membershipBlock') && !CRM_Utils_Array::value('is_required', $qf->_membershipBlock) && $field->name == 'membership_amount') {
                     $none = ts('No thank you');
                 } else {
                     $none = ts('-none-');
                 }
                 $choice[] = $qf->createElement('radio', NULL, '', $none, '0', array('price' => json_encode(array($elementName, "0"))));
             }
             $element =& $qf->addGroup($choice, $elementName, $label);
             // make contribution field required for quick config when membership block is enabled
             if (($field->name == 'contribution_amount' || $field->name == 'membership_amount') && property_exists($qf, '_membershipBlock') && !empty($qf->_membershipBlock) && !$field->is_required) {
                 $useRequired = $field->is_required = TRUE;
             }
             if ($useRequired && $field->is_required) {
                 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
             }
             break;
         case 'Select':
             $selectOption = $allowedOptions = $priceVal = array();
             foreach ($customOption as $opt) {
                 $count = CRM_Utils_Array::value('count', $opt, '');
                 $max_value = CRM_Utils_Array::value('max_value', $opt, '');
                 $priceVal[$opt['id']] = implode($seperator, array($opt[$valueFieldName], $count, $max_value));
                 if ($field->is_display_amounts) {
                     $opt['label'] .= '&nbsp;-&nbsp;';
                     $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]);
                 }
                 $selectOption[$opt['id']] = $opt['label'];
                 if (!in_array($opt['id'], $feezeOptions)) {
                     $allowedOptions[] = $opt['id'];
                 }
             }
             $element =& $qf->add('select', $elementName, $label, array('' => ts('- select -')) + $selectOption, $useRequired && $field->is_required, array('price' => json_encode($priceVal)));
             // CRM-6902
             $button = substr($qf->controller->getButtonName(), -4);
             if (!empty($feezeOptions) && $button != 'skip') {
                 $qf->addRule($elementName, ts('Sorry, this option is currently sold out.'), 'regex', "/" . implode('|', $allowedOptions) . "/");
             }
             break;
         case 'CheckBox':
             $check = array();
             foreach ($customOption as $opId => $opt) {
                 $count = CRM_Utils_Array::value('count', $opt, '');
                 $max_value = CRM_Utils_Array::value('max_value', $opt, '');
                 $priceVal = implode($seperator, array($opt[$valueFieldName], $count, $max_value));
                 if ($field->is_display_amounts) {
                     $opt['label'] .= '&nbsp;-&nbsp;';
                     $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]);
                 }
                 $check[$opId] =& $qf->createElement('checkbox', $opt['id'], NULL, $opt['label'], array('price' => json_encode(array($opt['id'], $priceVal)), 'data-amount' => $opt[$valueFieldName], 'data-currency' => $currencyName));
                 // CRM-6902
                 if (in_array($opId, $feezeOptions)) {
                     $check[$opId]->freeze();
                 }
             }
             $element =& $qf->addGroup($check, $elementName, $label);
             if ($useRequired && $field->is_required) {
                 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
             }
             break;
     }
     if (isset($qf->_online) && $qf->_online) {
         $element->freeze();
     }
 }
 /**
  * Function for validation
  *
  * @param array $params (ref.) an assoc array of name/value pairs
  *
  * @return mixed true or array of errors
  * @access public
  * @static
  */
 public function formRule($params, $files, $self)
 {
     $errors = array();
     $priceSetId = CRM_Utils_Array::value('price_set_id', $params);
     if ($priceSetId) {
         CRM_Price_BAO_Field::priceSetValidation($priceSetId, $params, $errors);
         $priceFieldIDS = array();
         foreach ($self->_priceSet['fields'] as $priceIds => $dontCare) {
             if (!empty($params['price_' . $priceIds])) {
                 if (is_array($params['price_' . $priceIds])) {
                     foreach ($params['price_' . $priceIds] as $priceFldVal => $isSet) {
                         if ($isSet) {
                             $priceFieldIDS[] = $priceFldVal;
                         }
                     }
                 } else {
                     $priceFieldIDS[] = $params['price_' . $priceIds];
                 }
             }
         }
         if (!empty($priceFieldIDS)) {
             $ids = implode(',', $priceFieldIDS);
             $count = CRM_Price_BAO_Set::getMembershipCount($ids);
             foreach ($count as $id => $occurance) {
                 if ($occurance > 1) {
                     $errors['_qf_default'] = ts('Select at most one option associated with the same membership type.');
                 }
             }
             foreach ($priceFieldIDS as $priceFieldId) {
                 if ($id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_FieldValue', $priceFieldId, 'membership_type_id')) {
                     $self->_memTypeSelected[$id] = $id;
                 }
             }
         }
     } elseif (!CRM_Utils_Array::value(1, $params['membership_type_id'])) {
         $errors['membership_type_id'] = ts('Please select a membership type.');
     } else {
         $self->_memTypeSelected[] = $params['membership_type_id'][1];
     }
     // Return error if empty $self->_memTypeSelected
     if ($priceSetId && empty($errors) && empty($self->_memTypeSelected)) {
         $errors['_qf_default'] = ts('Select at least one membership option.');
     }
     if (!empty($errors) && count($self->_memTypeSelected) > 1) {
         $memberOfContacts = CRM_Member_BAO_MembershipType::getMemberOfContactByMemTypes($self->_memTypeSelected);
         $duplicateMemberOfContacts = array_count_values($memberOfContacts);
         foreach ($duplicateMemberOfContacts as $countDuplicate) {
             if ($countDuplicate > 1) {
                 $errors['_qf_default'] = ts('Please do not select more than one membership associated with the same organization.');
             }
         }
     }
     //check if contact is selected in standalone mode
     if (isset($params['contact_select_id'][1]) && !$params['contact_select_id'][1]) {
         $errors['contact[1]'] = ts('Please select a contact or create new contact');
     }
     if (!empty($errors)) {
         return $errors;
     }
     if ($priceSetId && !$self->_mode && !CRM_Utils_Array::value('record_contribution', $params)) {
         $errors['record_contribution'] = ts('Record Membership Payment is required when you using price set.');
     }
     if (CRM_Utils_Array::value('payment_processor_id', $params)) {
         // make sure that credit card number and cvv are valid
         if (CRM_Utils_Array::value('credit_card_type', $params)) {
             if (CRM_Utils_Array::value('credit_card_number', $params) && !CRM_Utils_Rule::creditCardNumber($params['credit_card_number'], $params['credit_card_type'])) {
                 $errors['credit_card_number'] = ts("Please enter a valid Credit Card Number");
             }
             if (CRM_Utils_Array::value('cvv2', $params) && !CRM_Utils_Rule::cvv($params['cvv2'], $params['credit_card_type'])) {
                 $errors['cvv2'] = ts("Please enter a valid Credit Card Verification Number");
             }
         }
     }
     $joinDate = NULL;
     if (CRM_Utils_Array::value('join_date', $params)) {
         $joinDate = CRM_Utils_Date::processDate($params['join_date']);
         foreach ($self->_memTypeSelected as $memType) {
             $startDate = NULL;
             if (CRM_Utils_Array::value('start_date', $params)) {
                 $startDate = CRM_Utils_Date::processDate($params['start_date']);
             }
             // if end date is set, ensure that start date is also set
             // and that end date is later than start date
             // If selected membership type has duration unit as 'lifetime'
             // and end date is set, then give error
             $endDate = NULL;
             if (CRM_Utils_Array::value('end_date', $params)) {
                 $endDate = CRM_Utils_Date::processDate($params['end_date']);
             }
             $membershipDetails = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($memType);
             if ($startDate && CRM_Utils_Array::value('period_type', $membershipDetails) == 'rolling') {
                 if ($startDate < $joinDate) {
                     $errors['start_date'] = ts('Start date must be the same or later than Member since.');
                 }
             }
             if ($endDate) {
                 if ($membershipDetails['duration_unit'] == 'lifetime') {
                     $errors['end_date'] = ts('The selected Membership Type has a lifetime duration. You cannot specify an End Date for lifetime memberships. Please clear the End Date OR select a different Membership Type.');
                 } else {
                     if (!$startDate) {
                         $errors['start_date'] = ts('Start date must be set if end date is set.');
                     }
                     if ($endDate < $startDate) {
                         $errors['end_date'] = ts('End date must be the same or later than start date.');
                     }
                 }
             }
             //  Default values for start and end dates if not supplied
             //  on the form
             $defaultDates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($memType, $joinDate, $startDate, $endDate);
             if (!$startDate) {
                 $startDate = CRM_Utils_Array::value('start_date', $defaultDates);
             }
             if (!$endDate) {
                 $endDate = CRM_Utils_Array::value('end_date', $defaultDates);
             }
             //CRM-3724, check for availability of valid membership status.
             if (!CRM_Utils_Array::value('is_override', $params) && !isset($errors['_qf_default'])) {
                 $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($startDate, $endDate, $joinDate, 'today', TRUE);
                 if (empty($calcStatus)) {
                     $url = CRM_Utils_System::url('civicrm/admin/member/membershipStatus', 'reset=1&action=browse');
                     $errors['_qf_default'] = ts('There is no valid Membership Status available for selected membership dates.');
                     $status = ts('Oops, it looks like there is no valid membership status available for the given membership dates. You can <a href="%1">Configure Membership Status Rules</a>.', array(1 => $url));
                     if (!$self->_mode) {
                         $status .= ' ' . ts('OR You can sign up by setting Status Override? to true.');
                     }
                     CRM_Core_Session::setStatus($status);
                 }
             }
         }
     } else {
         $errors['join_date'] = ts('Please enter the Member Since.');
     }
     if (isset($params['is_override']) && $params['is_override'] && !CRM_Utils_Array::value('status_id', $params)) {
         $errors['status_id'] = ts('Please enter the status.');
     }
     //total amount condition arise when membership type having no
     //minimum fee
     if (isset($params['record_contribution'])) {
         if (!$params['contribution_type_id']) {
             $errors['contribution_type_id'] = ts('Please enter the contribution Type.');
         }
         if (CRM_Utils_System::isNull($params['total_amount'])) {
             $errors['total_amount'] = ts('Please enter the contribution.');
         }
     }
     // validate contribution status for 'Failed'.
     if ($self->_onlinePendingContributionId && CRM_Utils_Array::value('record_contribution', $params) && CRM_Utils_Array::value('contribution_status_id', $params) == array_search('Failed', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'))) {
         $errors['contribution_status_id'] = ts("Please select a valid payment status before updating.");
     }
     return empty($errors) ? TRUE : $errors;
 }
예제 #23
0
 /**
  * build the radio/text form elements for the amount field
  * 
  * @param object   $form form object
  * @param boolean  $required  true if you want to add formRule
  * @param int      $discountId discount id for the event
  *
  * @return void
  * @access public
  * @static
  */
 public static function buildAmount(&$form, $required = true, $discountId = null)
 {
     //get the button name.
     $button = substr($form->controller->getButtonName(), -4);
     if ($button == 'skip') {
         $required = false;
     }
     $elements = array();
     if (isset($form->_priceSetId)) {
         $form->addGroup($elements, 'amount', ts('Event Fee(s)'), '<br />');
         $form->add('hidden', 'priceSetId', $form->_priceSetId);
         $form->assign('priceSet', $form->_priceSet);
         require_once 'CRM/Price/BAO/Field.php';
         foreach ($form->_values['fee']['fields'] as $field) {
             $fieldId = $field['id'];
             $elementName = 'price_' . $fieldId;
             if ($button == 'skip') {
                 $isRequire = false;
             } else {
                 $isRequire = CRM_Utils_Array::value('is_required', $field);
             }
             CRM_Price_BAO_Field::addQuickFormElement($form, $elementName, $fieldId, false, $isRequire);
         }
     } else {
         if (!empty($form->_values['fee'])) {
             $form->_feeBlock =& $form->_values['fee'];
             if (isset($form->_values['discount'])) {
                 if (!isset($discountId) && $form->_action != CRM_Core_Action::UPDATE) {
                     require_once 'CRM/Core/BAO/Discount.php';
                     $form->_discountId = $discountId = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event');
                 }
                 if ($discountId) {
                     $form->_feeBlock =& $form->_values['discount'][$discountId];
                 }
             }
             require_once 'CRM/Utils/Hook.php';
             CRM_Utils_Hook::buildAmount('event', $form, $form->_feeBlock);
             if ($form->_action != CRM_Core_Action::UPDATE) {
                 require_once 'CRM/Utils/Money.php';
                 foreach ($form->_feeBlock as $fee) {
                     if (is_array($fee)) {
                         $elements[] =& $form->createElement('radio', null, '', CRM_Utils_Money::format($fee['value']) . ' ' . $fee['label'], $fee['amount_id']);
                     }
                 }
                 $form->_defaults['amount'] = CRM_Utils_Array::value('default_fee_id', $form->_values['event']);
                 $element =& $form->addGroup($elements, 'amount', ts('Event Fee(s)'), '<br />');
                 if (isset($form->_online) && $form->_online) {
                     $element->freeze();
                 }
                 if ($required) {
                     $form->addRule('amount', ts('Fee Level is a required field.'), 'required');
                 }
             }
         }
     }
 }
예제 #24
0
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the
  * type of action and executes that action.
  *
  * @param null
  *
  * @return void
  * @access public
  */
 function run()
 {
     // get the field id
     $this->_fid = CRM_Utils_Request::retrieve('fid', 'Positive', $this, FALSE, 0);
     //get the price set id
     if (!$this->_sid) {
         $this->_sid = CRM_Utils_Request::retrieve('sid', 'Positive', $this);
     }
     if ($this->_sid) {
         CRM_Price_BAO_Set::checkPermission($this->_sid);
         $this->_isSetReserved = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $this->_sid, 'is_reserved');
         $this->assign('isReserved', $this->_isSetReserved);
     }
     //as url contain $sid so append breadcrumb dynamically.
     $breadcrumb = array(array('title' => ts('Price Fields'), 'url' => CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&sid=' . $this->_sid)));
     CRM_Utils_System::appendBreadCrumb($breadcrumb);
     if ($this->_fid) {
         $fieldTitle = CRM_Price_BAO_Field::getTitle($this->_fid);
         $this->assign('fid', $this->_fid);
         $this->assign('fieldTitle', $fieldTitle);
         CRM_Utils_System::setTitle(ts('%1 - Price Options', array(1 => $fieldTitle)));
         $htmlType = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Field', $this->_fid, 'html_type');
         $this->assign('addMoreFields', TRUE);
         //for text price field only single option present
         if ($htmlType == 'Text') {
             $this->assign('addMoreFields', FALSE);
         }
     }
     // get the requested action
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
     // assign vars to templates
     $this->assign('action', $action);
     $oid = CRM_Utils_Request::retrieve('oid', 'Positive', $this, FALSE, 0);
     // what action to take ?
     if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::VIEW | CRM_Core_Action::DELETE) && !$this->_isSetReserved) {
         // no browse for edit/update/view
         $this->edit($action);
     } else {
         $this->browse();
     }
     // Call the parents run method
     return parent::run();
 }
 function createMembershipPriceField($params, $ids, $previousID, $membershipTypeId)
 {
     $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', 'default_membership_type_amount', 'id', 'name');
     if (CRM_Utils_Array::value('memberOfContact', $ids)) {
         $fieldName = $ids['memberOfContact'];
     } else {
         $fieldName = $previousID;
     }
     $fieldLabel = 'Membership Amount';
     $optionsIds = NULL;
     $fieldParams = array('price_set_id ' => $priceSetId, 'name' => $fieldName);
     $results = array();
     CRM_Price_BAO_Field::retrieve($fieldParams, $results);
     if (empty($results)) {
         $fieldParams = array();
         $fieldParams['label'] = $fieldLabel;
         $fieldParams['name'] = $fieldName;
         $fieldParams['price_set_id'] = $priceSetId;
         $fieldParams['html_type'] = 'Radio';
         $fieldParams['is_display_amounts'] = $fieldParams['is_required'] = 0;
         $fieldParams['weight'] = $fieldParams['option_weight'][1] = 1;
         $fieldParams['option_label'][1] = $params['name'];
         $fieldParams['membership_type_id'][1] = $membershipTypeId;
         $fieldParams['option_amount'][1] = empty($params['minimum_fee']) ? 0 : $params['minimum_fee'];
         if ($previousID) {
             CRM_Member_Form_MembershipType::checkPreviousPriceField($previousID, $priceSetId, $membershipTypeId, $optionsIds);
             $fieldParams['option_id'] = CRM_Utils_Array::value('option_id', $optionsIds);
         }
         $priceField = CRM_Price_BAO_Field::create($fieldParams);
     } else {
         $fieldID = $results['id'];
         $fieldValueParams = array('price_field_id' => $fieldID, 'membership_type_id' => $membershipTypeId);
         $results = array();
         CRM_Price_BAO_FieldValue::retrieve($fieldValueParams, $results);
         if (!empty($results)) {
             $results['label'] = $results['name'] = $params['name'];
             $results['amount'] = empty($params['minimum_fee']) ? 0 : $params['minimum_fee'];
             $optionsIds['id'] = $results['id'];
         } else {
             $results = array('price_field_id' => $fieldID, 'name' => $params['name'], 'label' => $params['name'], 'amount' => empty($params['minimum_fee']) ? 0 : $params['minimum_fee'], 'membership_type_id' => $membershipTypeId, 'is_active' => 1);
         }
         if ($previousID) {
             CRM_Member_Form_MembershipType::checkPreviousPriceField($previousID, $priceSetId, $membershipTypeId, $optionsIds);
             if (CRM_Utils_Array::value('option_id', $optionsIds)) {
                 $optionsIds['id'] = current(CRM_Utils_Array::value('option_id', $optionsIds));
             }
         }
         CRM_Price_BAO_FieldValue::add($results, $optionsIds);
     }
 }
 function checkPreviousPriceField($previousID, $priceSetId, $membershipTypeId, &$optionsIds)
 {
     if ($previousID) {
         $editedFieldParams = array('price_set_id ' => $priceSetId, 'name' => $previousID);
         $editedResults = array();
         CRM_Price_BAO_Field::retrieve($editedFieldParams, $editedResults);
         if (!empty($editedResults)) {
             $editedFieldParams = array('price_field_id' => $editedResults['id'], 'membership_type_id' => $membershipTypeId);
             $editedResults = array();
             CRM_Price_BAO_FieldValue::retrieve($editedFieldParams, $editedResults);
             $optionsIds['option_id'][1] = CRM_Utils_Array::value('id', $editedResults);
         }
     }
 }
예제 #27
0
 /**
  * Function to build the price set form.
  *
  * @return None
  * @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);
     $form->_quickConfig = $quickConfig = 0;
     if (CRM_Core_DAO::getFieldValue('CRM_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_Price_BAO_Field::addQuickFormElement($form, 'price_' . $field['id'], $field['id'], FALSE, CRM_Utils_Array::value('is_required', $field, FALSE), NULL, $options);
         }
     }
 }
예제 #28
0
 /**
  * Process the form
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
     if (array_key_exists('payment_processor', $params)) {
         if (array_key_exists(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_PaymentProcessor', 'AuthNet', 'id', 'payment_processor_type'), CRM_Utils_Array::value('payment_processor', $params))) {
             CRM_Core_Session::setStatus(ts(' Please note that the Authorize.net payment processor only allows recurring contributions and auto-renew memberships with payment intervals from 7-365 days or 1-12 months (i.e. not greater than 1 year).'));
         }
     }
     // check for price set.
     $priceSetID = CRM_Utils_Array::value('price_set_id', $params);
     // get required fields.
     $fields = array('id' => $this->_id, 'is_recur' => FALSE, 'min_amount' => "null", 'max_amount' => "null", 'is_monetary' => FALSE, 'is_pay_later' => FALSE, 'is_recur_interval' => FALSE, 'recur_frequency_unit' => "null", 'default_amount_id' => "null", 'is_allow_other_amount' => FALSE, 'amount_block_is_active' => FALSE);
     $resetFields = array();
     if ($priceSetID) {
         $resetFields = array('min_amount', 'max_amount', 'is_allow_other_amount');
     }
     if (!CRM_Utils_Array::value('is_recur', $params)) {
         $resetFields = array_merge($resetFields, array('is_recur_interval', 'recur_frequency_unit'));
     }
     foreach ($fields as $field => $defaultVal) {
         $val = CRM_Utils_Array::value($field, $params, $defaultVal);
         if (in_array($field, $resetFields)) {
             $val = $defaultVal;
         }
         if (in_array($field, array('min_amount', 'max_amount'))) {
             $val = CRM_Utils_Rule::cleanMoney($val);
         }
         $params[$field] = $val;
     }
     if ($params['is_recur']) {
         $params['recur_frequency_unit'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['recur_frequency_unit']));
         $params['is_recur_interval'] = CRM_Utils_Array::value('is_recur_interval', $params, FALSE);
     }
     if (array_key_exists('payment_processor', $params) && !CRM_Utils_System::isNull($params['payment_processor'])) {
         $params['payment_processor'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['payment_processor']));
     } else {
         $params['payment_processor'] = 'null';
     }
     $contributionPage = CRM_Contribute_BAO_ContributionPage::create($params);
     $contributionPageID = $contributionPage->id;
     // prepare for data cleanup.
     $deleteAmountBlk = $deletePledgeBlk = $deletePriceSet = FALSE;
     if ($this->_priceSetID) {
         $deletePriceSet = TRUE;
     }
     if ($this->_pledgeBlockID) {
         $deletePledgeBlk = TRUE;
     }
     if (!empty($this->_amountBlock)) {
         $deleteAmountBlk = TRUE;
     }
     if ($contributionPageID) {
         if (CRM_Utils_Array::value('amount_block_is_active', $params)) {
             // handle price set.
             if ($priceSetID) {
                 // add/update price set.
                 $deletePriceSet = FALSE;
                 if (CRM_Utils_Array::value('price_field_id', $params) || CRM_Utils_Array::value('price_field_other', $params)) {
                     $deleteAmountBlk = TRUE;
                 }
                 CRM_Price_BAO_Set::addTo('civicrm_contribution_page', $contributionPageID, $priceSetID);
             } else {
                 $deletePriceSet = FALSE;
                 // process contribution amount block
                 $deleteAmountBlk = FALSE;
                 $labels = CRM_Utils_Array::value('label', $params);
                 $values = CRM_Utils_Array::value('value', $params);
                 $default = CRM_Utils_Array::value('default', $params);
                 $options = array();
                 for ($i = 1; $i < self::NUM_OPTION; $i++) {
                     if (isset($values[$i]) && strlen(trim($values[$i])) > 0) {
                         $options[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i);
                     }
                 }
                 /* || CRM_Utils_Array::value( 'price_field_value', $params )|| CRM_Utils_Array::value( 'price_field_other', $params )*/
                 if (!empty($options) || CRM_Utils_Array::value('is_allow_other_amount', $params)) {
                     $fieldParams['is_quick_config'] = 1;
                     $noContriAmount = NULL;
                     $usedPriceSetId = CRM_Price_BAO_Set::getFor('civicrm_contribution_page', $this->_id, 3);
                     if (!(CRM_Utils_Array::value('price_field_id', $params) || CRM_Utils_Array::value('price_field_other', $params)) && !$usedPriceSetId) {
                         $pageTitle = strtolower(CRM_Utils_String::munge($this->_values['title'], '_', 245));
                         $setParams['title'] = $this->_values['title'];
                         if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $pageTitle, 'id', 'name')) {
                             $setParams['name'] = $pageTitle;
                         } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $pageTitle . '_' . $this->_id, 'id', 'name')) {
                             $setParams['name'] = $pageTitle . '_' . $this->_id;
                         } else {
                             $timeSec = explode(".", microtime(true));
                             $setParams['name'] = $pageTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
                         }
                         $setParams['is_quick_config'] = 1;
                         $setParams['extends'] = CRM_Core_Component::getComponentID('CiviContribute');
                         $priceSet = CRM_Price_BAO_Set::create($setParams);
                         $priceSetId = $priceSet->id;
                     } elseif ($usedPriceSetId && !CRM_Utils_Array::value('price_field_id', $params)) {
                         $priceSetId = $usedPriceSetId;
                     } else {
                         if ($priceFieldId = CRM_Utils_Array::value('price_field_id', $params)) {
                             foreach ($params['price_field_value'] as $arrayID => $fieldValueID) {
                                 if (empty($params['label'][$arrayID]) && empty($params['value'][$arrayID]) && !empty($fieldValueID)) {
                                     CRM_Price_BAO_FieldValue::setIsActive($fieldValueID, '0');
                                     unset($params['price_field_value'][$arrayID]);
                                 }
                             }
                             if (implode('', $params['price_field_value'])) {
                                 $fieldParams['id'] = CRM_Utils_Array::value('price_field_id', $params);
                                 $fieldParams['option_id'] = $params['price_field_value'];
                             } else {
                                 $noContriAmount = 0;
                                 CRM_Price_BAO_Field::setIsActive($priceFieldId, '0');
                             }
                         } else {
                             $priceFieldId = CRM_Utils_Array::value('price_field_other', $params);
                         }
                         $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $priceFieldId, 'price_set_id');
                     }
                     CRM_Price_BAO_Set::addTo('civicrm_contribution_page', $this->_id, $priceSetId);
                     if (!empty($options)) {
                         $editedFieldParams = array('price_set_id' => $priceSetId, 'name' => 'contribution_amount');
                         $editedResults = array();
                         $noContriAmount = 1;
                         CRM_Price_BAO_Field::retrieve($editedFieldParams, $editedResults);
                         if (!CRM_Utils_Array::value('id', $editedResults)) {
                             $fieldParams['name'] = strtolower(CRM_Utils_String::munge("Contribution Amount", '_', 245));
                             $fieldParams['label'] = "Contribution Amount";
                         } else {
                             $fieldParams['id'] = CRM_Utils_Array::value('id', $editedResults);
                         }
                         $fieldParams['price_set_id'] = $priceSetId;
                         $fieldParams['is_active'] = 1;
                         $fieldParams['weight'] = 2;
                         if (CRM_Utils_Array::value('is_allow_other_amount', $params)) {
                             $fieldParams['is_required'] = 0;
                         } else {
                             $fieldParams['is_required'] = 1;
                         }
                         $fieldParams['html_type'] = 'Radio';
                         $fieldParams['option_label'] = $params['label'];
                         $fieldParams['option_amount'] = $params['value'];
                         foreach ($options as $value) {
                             $fieldParams['option_weight'][$value['weight']] = $value['weight'];
                         }
                         $fieldParams['default_option'] = $params['default'];
                         $priceField = CRM_Price_BAO_Field::create($fieldParams);
                     }
                     if (CRM_Utils_Array::value('is_allow_other_amount', $params) && !CRM_Utils_Array::value('price_field_other', $params)) {
                         $editedFieldParams = array('price_set_id' => $priceSetId, 'name' => 'other_amount');
                         $editedResults = array();
                         CRM_Price_BAO_Field::retrieve($editedFieldParams, $editedResults);
                         if (!($priceFieldID = CRM_Utils_Array::value('id', $editedResults))) {
                             $fieldParams = array('name' => 'other_amount', 'label' => 'Other Amount', 'price_set_id' => $priceSetId, 'html_type' => 'Text', 'is_display_amounts' => 0, 'weight' => 3);
                             $fieldParams['option_weight'][1] = 1;
                             $fieldParams['option_amount'][1] = 1;
                             if (!$noContriAmount) {
                                 $fieldParams['is_required'] = 1;
                                 $fieldParams['option_label'][1] = 'Contribution Amount';
                             } else {
                                 $fieldParams['is_required'] = 0;
                                 $fieldParams['option_label'][1] = 'Other Amount';
                             }
                             $priceField = CRM_Price_BAO_Field::create($fieldParams);
                         } else {
                             if (!CRM_Utils_Array::value('is_active', $editedResults)) {
                                 CRM_Price_BAO_Field::setIsActive($priceFieldID, '1');
                             }
                         }
                     } elseif (!CRM_Utils_Array::value('is_allow_other_amount', $params) && CRM_Utils_Array::value('price_field_other', $params)) {
                         CRM_Price_BAO_Field::setIsActive($params['price_field_other'], '0');
                     } elseif ($priceFieldID = CRM_Utils_Array::value('price_field_other', $params)) {
                         $priceFieldValueID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_FieldValue', $priceFieldID, 'id', 'price_field_id');
                         if (!$noContriAmount) {
                             CRM_Core_DAO::setFieldValue('CRM_Price_DAO_Field', $priceFieldID, 'is_required', 1);
                             CRM_Core_DAO::setFieldValue('CRM_Price_DAO_FieldValue', $priceFieldValueID, 'label', 'Contribution Amount');
                         } else {
                             CRM_Core_DAO::setFieldValue('CRM_Price_DAO_Field', $priceFieldID, 'is_required', 0);
                             CRM_Core_DAO::setFieldValue('CRM_Price_DAO_FieldValue', $priceFieldValueID, 'label', 'Other Amount');
                         }
                     }
                 }
                 if (CRM_Utils_Array::value('is_pledge_active', $params)) {
                     $deletePledgeBlk = FALSE;
                     $pledgeBlockParams = array('entity_id' => $contributionPageID, 'entity_table' => ts('civicrm_contribution_page'));
                     if ($this->_pledgeBlockID) {
                         $pledgeBlockParams['id'] = $this->_pledgeBlockID;
                     }
                     $pledgeBlock = array('pledge_frequency_unit', 'max_reminders', 'initial_reminder_day', 'additional_reminder_day');
                     foreach ($pledgeBlock as $key) {
                         $pledgeBlockParams[$key] = CRM_Utils_Array::value($key, $params);
                     }
                     $pledgeBlockParams['is_pledge_interval'] = CRM_Utils_Array::value('is_pledge_interval', $params, FALSE);
                     // create pledge block.
                     CRM_Pledge_BAO_PledgeBlock::create($pledgeBlockParams);
                 }
             }
         } else {
             if (CRM_Utils_Array::value('price_field_id', $params) || CRM_Utils_Array::value('price_field_other', $params)) {
                 $usedPriceSetId = CRM_Price_BAO_Set::getFor('civicrm_contribution_page', $this->_id, 3);
                 if ($usedPriceSetId) {
                     if (CRM_Utils_Array::value('price_field_id', $params)) {
                         CRM_Price_BAO_Field::setIsActive($params['price_field_id'], '0');
                     }
                     if (CRM_Utils_Array::value('price_field_other', $params)) {
                         CRM_Price_BAO_Field::setIsActive($params['price_field_other'], '0');
                     }
                 } else {
                     $deleteAmountBlk = TRUE;
                     $deletePriceSet = TRUE;
                 }
             }
         }
         // delete pledge block.
         if ($deletePledgeBlk) {
             CRM_Pledge_BAO_PledgeBlock::deletePledgeBlock($this->_pledgeBlockID);
         }
         // delete previous price set.
         if ($deletePriceSet) {
             CRM_Price_BAO_Set::removeFrom('civicrm_contribution_page', $contributionPageID);
         }
         if ($deleteAmountBlk) {
             $priceField = CRM_Utils_Array::value('price_field_id', $params) ? $params['price_field_id'] : CRM_Utils_Array::value('price_field_other', $params);
             if ($priceField) {
                 $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $priceField, 'price_set_id');
                 CRM_Price_BAO_Set::setIsQuickConfig($priceSetID, 0);
             }
         }
     }
     parent::endPostProcess();
 }
예제 #29
0
 /**
  * fixEventLevel() method (Setting ',' values), resolveDefaults(assinging value to array) method
  */
 function testfixEventLevel()
 {
     require_once 'CRM/Utils/String.php';
     require_once 'CRM/Utils/Array.php';
     $paramsSet['title'] = 'Price Set';
     $paramsSet['name'] = CRM_Utils_String::titleToVar('Price Set');
     $paramsSet['is_active'] = CRM_Utils_Array::value('is_active', $params, false);
     require_once 'CRM/Price/BAO/Set.php';
     $priceset = CRM_Price_BAO_Set::create($paramsSet);
     //Checking for priceset added in the table.
     $this->assertDBCompareValue('CRM_Price_BAO_Set', $priceset->id, 'title', 'id', $paramsSet['title'], 'Check DB for created priceset');
     $paramsField = array('label' => 'Price Field', 'name' => CRM_Utils_String::titleToVar('Price Field'), 'html_type' => 'Text', 'price' => 10, 'option_label' => array('1' => 'Price Field'), 'option_value' => array('1' => 10), 'is_display_amounts' => 1, 'weight' => 1, 'options_per_line' => 1, 'is_active' => array('1' => 1), 'price_set_id' => $priceset->id, 'is_enter_qty' => 1);
     $ids = array();
     require_once 'CRM/Price/BAO/Field.php';
     $pricefield = CRM_Price_BAO_Field::create($paramsField, $ids);
     //Checking for priceset added in the table.
     $this->assertDBCompareValue('CRM_Price_BAO_Field', $pricefield->id, 'label', 'id', $paramsField['label'], 'Check DB for created pricefield');
     $eventId = $this->_eventId;
     $participantParams = array('send_receipt' => 1, 'is_test' => 0, 'is_pay_later' => 0, 'event_id' => $eventId, 'register_date' => date('Y-m-d') . " 00:00:00", 'role_id' => 1, 'status_id' => 1, 'source' => 'Event_' . $eventId, 'contact_id' => $this->_contactId, 'note' => 'Note added for Event_' . $eventId, 'fee_level' => 'Price_Field - 55');
     $participant = CRM_Event_BAO_Participant::add($participantParams);
     //Checking for participant added in the table.
     $this->assertDBCompareValue('CRM_Event_BAO_Participant', $this->_contactId, 'id', 'contact_id', $participant->id, 'Check DB for created participant');
     $values = array();
     $ids = array();
     $params = array('id' => $participant->id);
     CRM_Event_BAO_Participant::getValues($params, $values, $ids);
     $this->assertNotEquals(count($values), 0, 'Checking for empty array.');
     CRM_Event_BAO_Participant::resolveDefaults($values[$participant->id]);
     if ($values[$participant->id]['fee_level']) {
         CRM_Event_BAO_Participant::fixEventLevel($values[$participant->id]['fee_level']);
     }
     $deletePricefield = CRM_Price_BAO_Field::deleteField($pricefield->id);
     $this->assertDBNull('CRM_Price_BAO_Field', $pricefield->id, 'name', 'id', 'Check DB for non-existence of Price Field.');
     $deletePriceset = CRM_Price_BAO_Set::deleteSet($priceset->id);
     $this->assertDBNull('CRM_Price_BAO_Set', $priceset->id, 'title', 'id', 'Check DB for non-existence of Price Set.');
     Participant::delete($participant->id);
     Contact::delete($this->_contactId);
     Event::delete($eventId);
 }