Esempio n. 1
0
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     if ($this->_action == CRM_Core_Action::UPDATE) {
         $finTypeId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $this->_oid, 'financial_type_id');
         CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, CRM_Core_Action::UPDATE);
         if (!array_key_exists($finTypeId, $financialTypes)) {
             CRM_Core_Error::fatal(ts("You do not have permission to access this page"));
         }
     }
     if ($this->_action == CRM_Core_Action::DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete')), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return NULL;
     } else {
         $attributes = CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceFieldValue');
         // lets trim all the whitespace
         $this->applyFilter('__ALL__', 'trim');
         // hidden Option Id for validation use
         $this->add('hidden', 'optionId', $this->_oid);
         // Needed for i18n dialog
         $this->assign('optionId', $this->_oid);
         //hidden field ID for validation use
         $this->add('hidden', 'fieldId', $this->_fid);
         // label
         $this->add('text', 'label', ts('Option Label'), NULL, TRUE);
         $memberComponentId = CRM_Core_Component::getComponentID('CiviMember');
         if ($this->_action == CRM_Core_Action::UPDATE) {
             $this->_sid = CRM_Utils_Request::retrieve('sid', 'Positive', $this);
         } elseif ($this->_action == CRM_Core_Action::ADD || $this->_action == CRM_Core_Action::VIEW) {
             $this->_sid = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $this->_fid, 'price_set_id', 'id');
         }
         $this->isEvent = FALSE;
         $extendComponentId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid, 'extends', 'id');
         $this->assign('showMember', FALSE);
         if ($memberComponentId == $extendComponentId) {
             $this->assign('showMember', TRUE);
             $membershipTypes = CRM_Member_PseudoConstant::membershipType();
             $this->add('select', 'membership_type_id', ts('Membership Type'), array('' => ' ') + $membershipTypes, FALSE, array('onClick' => "calculateRowValues( );"));
             $this->add('text', 'membership_num_terms', ts('Number of Terms'), $attributes['membership_num_terms']);
         } else {
             $allComponents = explode(CRM_Core_DAO::VALUE_SEPARATOR, $extendComponentId);
             $eventComponentId = CRM_Core_Component::getComponentID('CiviEvent');
             if (in_array($eventComponentId, $allComponents)) {
                 $this->isEvent = TRUE;
                 // count
                 $this->add('text', 'count', ts('Participant Count'));
                 $this->addRule('count', ts('Please enter a valid Max Participants.'), 'positiveInteger');
                 $this->add('text', 'max_value', ts('Max Participants'));
                 $this->addRule('max_value', ts('Please enter a valid Max Participants.'), 'positiveInteger');
             }
         }
         //Financial Type
         $financialType = CRM_Financial_BAO_FinancialType::getIncomeFinancialType();
         if (count($financialType)) {
             $this->assign('financialType', $financialType);
         }
         $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + $financialType, TRUE);
         //CRM_Core_DAO::getFieldValue( 'CRM_Price_DAO_PriceField', $this->_fid, 'weight', 'id' );
         // FIX ME: duplicate rule?
         /*
               $this->addRule( 'label',
               ts('Duplicate option label.'),
               'optionExists',
               array( 'CRM_Core_DAO_OptionValue', $this->_oid, $this->_ogId, 'label' ) );
         */
         // value
         $this->add('text', 'amount', ts('Option Amount'), NULL, TRUE);
         // the above value is used directly by QF, so the value has to be have a rule
         // please check with Lobo before u comment this
         $this->registerRule('amount', 'callback', 'money', 'CRM_Utils_Rule');
         $this->addRule('amount', ts('Please enter a monetary value for this field.'), 'money');
         $this->add('textarea', 'description', ts('Description'));
         $this->add('textarea', 'help_pre', ts('Pre Option Help'));
         $this->add('textarea', 'help_post', ts('Post Option Help'));
         // weight
         $this->add('text', 'weight', ts('Order'), NULL, TRUE);
         $this->addRule('weight', ts('is a numeric field'), 'numeric');
         // is active ?
         $this->add('checkbox', 'is_active', ts('Active?'));
         //is default
         $this->add('checkbox', 'is_default', ts('Default'));
         if ($this->_fid) {
             //hide the default checkbox option for text field
             $htmlType = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceField', $this->_fid, 'html_type');
             $this->assign('hideDefaultOption', FALSE);
             if ($htmlType == 'Text') {
                 $this->assign('hideDefaultOption', TRUE);
             }
         }
         // add buttons
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Save')), array('type' => 'cancel', 'name' => ts('Cancel'))));
         // if view mode pls freeze it with the done button.
         if ($this->_action & CRM_Core_Action::VIEW) {
             $this->freeze();
             $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done'), 'isDefault' => TRUE)));
         }
     }
     $this->addFormRule(array('CRM_Price_Form_Option', 'formRule'), $this);
 }
Esempio n. 2
0
 /**
  * Get options for a given field.
  * @see CRM_Core_DAO::buildOptions
  *
  * @param String $fieldName
  * @param String $context: @see CRM_Core_DAO::buildOptionsContext
  * @param Array  $props: whatever is known about this dao object
  *
  * @return array|bool
  */
 public static function buildOptions($fieldName, $context = NULL, $props = array())
 {
     $params = array();
     // Special logic for fields whose options depend on context or properties
     switch ($fieldName) {
         case 'financial_type_id':
             // Fixme - this is going to ignore context, better to get conditions, add params, and call PseudoConstant::get
             return CRM_Financial_BAO_FinancialType::getIncomeFinancialType();
             break;
     }
     return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
 }
Esempio n. 3
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     // lets trim all the whitespace
     $this->applyFilter('__ALL__', 'trim');
     // add a hidden field to remember the price set id
     // this get around the browser tab issue
     $this->add('hidden', 'sid', $this->_sid);
     $this->add('hidden', 'fid', $this->_fid);
     // label
     $this->add('text', 'label', ts('Field Label'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceField', 'label'), TRUE);
     // html_type
     $javascript = 'onchange="option_html_type(this.form)";';
     $htmlTypes = CRM_Price_BAO_PriceField::htmlTypes();
     // Text box for Participant Count for a field
     // Financial Type
     $financialType = CRM_Financial_BAO_FinancialType::getIncomeFinancialType();
     foreach ($financialType as $finTypeId => $type) {
         if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('add contributions of type ' . $type)) {
             unset($financialType[$finTypeId]);
         }
     }
     if (count($financialType)) {
         $this->assign('financialType', $financialType);
     }
     $enabledComponents = CRM_Core_Component::getEnabledComponents();
     $eventComponentId = $memberComponentId = NULL;
     if (array_key_exists('CiviEvent', $enabledComponents)) {
         $eventComponentId = CRM_Core_Component::getComponentID('CiviEvent');
     }
     if (array_key_exists('CiviMember', $enabledComponents)) {
         $memberComponentId = CRM_Core_Component::getComponentID('CiviMember');
     }
     $attributes = CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceFieldValue');
     $this->add('select', 'financial_type_id', ts('Financial Type'), array(' ' => ts('- select -')) + $financialType);
     $this->assign('useForMember', FALSE);
     if (in_array($eventComponentId, $this->_extendComponentId)) {
         $this->add('text', 'count', ts('Participant Count'), $attributes['count']);
         $this->addRule('count', ts('Participant Count should be a positive number'), 'positiveInteger');
         $this->add('text', 'max_value', ts('Max Participants'), $attributes['max_value']);
         $this->addRule('max_value', ts('Please enter a valid Max Participants.'), 'positiveInteger');
         $this->assign('useForEvent', TRUE);
     } else {
         if (in_array($memberComponentId, $this->_extendComponentId)) {
             $this->_useForMember = 1;
             $this->assign('useForMember', $this->_useForMember);
         }
         $this->assign('useForEvent', FALSE);
     }
     $sel = $this->add('select', 'html_type', ts('Input Field Type'), $htmlTypes, TRUE, $javascript);
     // price (for text inputs)
     $this->add('text', 'price', ts('Price'));
     $this->registerRule('price', 'callback', 'money', 'CRM_Utils_Rule');
     $this->addRule('price', ts('must be a monetary value'), 'money');
     if ($this->_action == CRM_Core_Action::UPDATE) {
         $this->freeze('html_type');
     }
     // form fields of Custom Option rows
     $_showHide = new CRM_Core_ShowHideBlocks('', '');
     for ($i = 1; $i <= self::NUM_OPTION; $i++) {
         //the show hide blocks
         $showBlocks = 'optionField_' . $i;
         if ($i > 2) {
             $_showHide->addHide($showBlocks);
             if ($i == self::NUM_OPTION) {
                 $_showHide->addHide('additionalOption');
             }
         } else {
             $_showHide->addShow($showBlocks);
         }
         // label
         $attributes['label']['size'] = 25;
         $this->add('text', 'option_label[' . $i . ']', ts('Label'), $attributes['label']);
         // amount
         $this->add('text', 'option_amount[' . $i . ']', ts('Amount'), $attributes['amount']);
         $this->addRule('option_amount[' . $i . ']', ts('Please enter a valid amount for this field.'), 'money');
         //Financial Type
         $this->add('select', 'option_financial_type_id[' . $i . ']', ts('Financial Type'), array('' => ts('- select -')) + $financialType);
         if (in_array($eventComponentId, $this->_extendComponentId)) {
             // count
             $this->add('text', 'option_count[' . $i . ']', ts('Participant Count'), $attributes['count']);
             $this->addRule('option_count[' . $i . ']', ts('Please enter a valid Participants Count.'), 'positiveInteger');
             // max_value
             $this->add('text', 'option_max_value[' . $i . ']', ts('Max Participants'), $attributes['max_value']);
             $this->addRule('option_max_value[' . $i . ']', ts('Please enter a valid Max Participants.'), 'positiveInteger');
             // description
             //$this->add('textArea', 'option_description['.$i.']', ts('Description'), array('rows' => 1, 'cols' => 40 ));
         } elseif (in_array($memberComponentId, $this->_extendComponentId)) {
             $membershipTypes = CRM_Member_PseudoConstant::membershipType();
             $js = array('onchange' => "calculateRowValues( {$i} );");
             $this->add('select', 'membership_type_id[' . $i . ']', ts('Membership Type'), array('' => ' ') + $membershipTypes, FALSE, $js);
             $this->add('text', 'membership_num_terms[' . $i . ']', ts('Number of Terms'), CRM_Utils_Array::value('membership_num_terms', $attributes));
         }
         // weight
         $this->add('text', 'option_weight[' . $i . ']', ts('Order'), $attributes['weight']);
         // is active ?
         $this->add('checkbox', 'option_status[' . $i . ']', ts('Active?'));
         $defaultOption[$i] = $this->createElement('radio', NULL, NULL, NULL, $i);
         //for checkbox handling of default option
         $this->add('checkbox', "default_checkbox_option[{$i}]", NULL);
     }
     //default option selection
     $this->addGroup($defaultOption, 'default_option');
     $_showHide->addToTemplate();
     // is_display_amounts
     $this->add('checkbox', 'is_display_amounts', ts('Display Amount?'));
     // weight
     $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceField', 'weight'), TRUE);
     $this->addRule('weight', ts('is a numeric field'), 'numeric');
     // checkbox / radio options per line
     $this->add('text', 'options_per_line', ts('Options Per Line'));
     $this->addRule('options_per_line', ts('must be a numeric value'), 'numeric');
     // help post, mask, attributes, javascript ?
     $this->add('textarea', 'help_post', ts('Field Help'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceField', 'help_post'));
     // active_on
     $date_options = array('format' => 'dmY His', 'minYear' => date('Y') - 1, 'maxYear' => date('Y') + 5, 'addEmptyOption' => TRUE);
     $this->addDateTime('active_on', ts('Active On'), FALSE, array('formatType' => 'activityDateTime'));
     // expire_on
     $this->addDateTime('expire_on', ts('Expire On'), FALSE, array('formatType' => 'activityDateTime'));
     // is required ?
     $this->add('checkbox', 'is_required', ts('Required?'));
     // is active ?
     $this->add('checkbox', 'is_active', ts('Active?'));
     // add buttons
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'next', 'name' => ts('Save and New'), 'subName' => 'new'), array('type' => 'cancel', 'name' => ts('Cancel'))));
     // is public?
     $this->add('select', 'visibility_id', ts('Visibility'), CRM_Core_PseudoConstant::visibility());
     // add a form rule to check default value
     $this->addFormRule(array('CRM_Price_Form_Field', 'formRule'), $this);
     // if view mode pls freeze it with the done button.
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
         $url = CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid);
         $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='{$url}'"));
     }
 }
Esempio n. 4
0
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     $this->applyFilter('__ALL__', 'trim');
     $this->assign('sid', $this->_sid);
     // title
     $this->add('text', 'title', ts('Set Name'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceSet', 'title'), TRUE);
     $this->addRule('title', ts('Name already exists in Database.'), 'objectExists', array('CRM_Price_DAO_PriceSet', $this->_sid, 'title'));
     $priceSetUsedTables = $extends = array();
     if ($this->_action == CRM_Core_Action::UPDATE && $this->_sid) {
         $priceSetUsedTables = CRM_Price_BAO_PriceSet::getUsedBy($this->_sid, 'table');
     }
     $config = CRM_Core_Config::singleton();
     $showContribution = FALSE;
     $enabledComponents = CRM_Core_Component::getEnabledComponents();
     foreach ($enabledComponents as $name => $compObj) {
         switch ($name) {
             case 'CiviEvent':
                 $option = $this->createElement('checkbox', $compObj->componentID, NULL, ts('Event'));
                 if (!empty($priceSetUsedTables)) {
                     foreach (array('civicrm_event', 'civicrm_participant') as $table) {
                         if (in_array($table, $priceSetUsedTables)) {
                             $option->freeze();
                             break;
                         }
                     }
                 }
                 $extends[] = $option;
                 break;
             case 'CiviContribute':
                 $option = $this->createElement('checkbox', $compObj->componentID, NULL, ts('Contribution'));
                 if (!empty($priceSetUsedTables)) {
                     foreach (array('civicrm_contribution', 'civicrm_contribution_page') as $table) {
                         if (in_array($table, $priceSetUsedTables)) {
                             $option->freeze();
                             break;
                         }
                     }
                 }
                 $extends[] = $option;
                 break;
             case 'CiviMember':
                 $option = $this->createElement('checkbox', $compObj->componentID, NULL, ts('Membership'));
                 if (!empty($priceSetUsedTables)) {
                     foreach (array('civicrm_membership', 'civicrm_contribution_page') as $table) {
                         if (in_array($table, $priceSetUsedTables)) {
                             $option->freeze();
                             break;
                         }
                     }
                 }
                 $extends[] = $option;
                 break;
         }
     }
     if (CRM_Utils_System::isNull($extends)) {
         $this->assign('extends', FALSE);
     } else {
         $this->assign('extends', TRUE);
     }
     $this->addGroup($extends, 'extends', ts('Used For'), '&nbsp;', TRUE);
     $this->addRule('extends', ts('%1 is a required field.', array(1 => ts('Used For'))), 'required');
     // financial type
     $financialType = CRM_Financial_BAO_FinancialType::getIncomeFinancialType();
     foreach ($financialType as $finTypeId => $type) {
         if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('add contributions of type ' . $type)) {
             unset($financialType[$finTypeId]);
         }
     }
     $this->add('select', 'financial_type_id', ts('Default Financial Type'), array('' => ts('- select -')) + $financialType, 'required');
     // help text
     $this->add('textarea', 'help_pre', ts('Pre-form Help'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceSet', 'help_pre'));
     $this->add('textarea', 'help_post', ts('Post-form Help'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceSet', 'help_post'));
     // is this set active ?
     $this->addElement('checkbox', 'is_active', ts('Is this Price Set active?'));
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->addFormRule(array('CRM_Price_Form_Set', 'formRule'));
     // views are implemented as frozen form
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
         //$this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/price?reset=1&action=browse'"));
     }
 }
Esempio n. 5
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     $this->_first = TRUE;
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage');
     // financial Type
     $financialType = CRM_Financial_BAO_FinancialType::getIncomeFinancialType();
     $this->add('select', 'financial_type_id', ts('Financial Type'), $financialType, TRUE);
     // name
     $this->add('text', 'title', ts('Title'), $attributes['title'], TRUE);
     //CRM-7362 --add campaigns.
     CRM_Campaign_BAO_Campaign::addCampaign($this, CRM_Utils_Array::value('campaign_id', $this->_values));
     $this->addWysiwyg('intro_text', ts('Introductory Message'), $attributes['intro_text']);
     $this->addWysiwyg('footer_text', ts('Footer Message'), $attributes['footer_text']);
     // is on behalf of an organization ?
     $this->addElement('checkbox', 'is_organization', ts('Allow individuals to contribute and / or signup for membership on behalf of an organization?'), NULL, array('onclick' => "showHideByValue('is_organization',true,'for_org_text','table-row','radio',false);showHideByValue('is_organization',true,'for_org_option','table-row','radio',false);"));
     $required = array('Contact', 'Organization');
     $optional = array('Contribution', 'Membership');
     $profiles = CRM_Core_BAO_UFGroup::getValidProfiles($required, $optional);
     //Check profiles for Organization subtypes
     $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
     foreach ($contactSubType as $type) {
         $required = array('Contact', $type);
         $subTypeProfiles = CRM_Core_BAO_UFGroup::getValidProfiles($required, $optional);
         foreach ($subTypeProfiles as $profileId => $profileName) {
             $profiles[$profileId] = $profileName;
         }
     }
     $requiredProfileFields = array('organization_name', 'email');
     if (!empty($profiles)) {
         foreach ($profiles as $id => $dontCare) {
             $validProfile = CRM_Core_BAO_UFGroup::checkValidProfile($id, $requiredProfileFields);
             if (!$validProfile) {
                 unset($profiles[$id]);
             }
         }
     }
     if (empty($profiles)) {
         $invalidProfiles = TRUE;
         $this->assign('invalidProfiles', $invalidProfiles);
     }
     $this->add('select', 'onbehalf_profile_id', ts('Organization Profile'), array('' => ts('- select -')) + $profiles);
     $options = array();
     $options[] = $this->createElement('radio', NULL, NULL, ts('Optional'), 1);
     $options[] = $this->createElement('radio', NULL, NULL, ts('Required'), 2);
     $this->addGroup($options, 'is_for_organization', ts(''));
     $this->add('textarea', 'for_organization', ts('On behalf of Label'), $attributes['for_organization']);
     // collect goal amount
     $this->add('text', 'goal_amount', ts('Goal Amount'), array('size' => 8, 'maxlength' => 12));
     $this->addRule('goal_amount', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money');
     // is confirmation page enabled?
     $this->addElement('checkbox', 'is_confirm_enabled', ts('Use a confirmation page?'));
     // is this page shareable through social media ?
     $this->addElement('checkbox', 'is_share', ts('Allow sharing through social media?'));
     // is this page active ?
     $this->addElement('checkbox', 'is_active', ts('Is this Online Contribution Page Active?'));
     // should the honor be enabled
     $this->addElement('checkbox', 'honor_block_is_active', ts('Honoree Section Enabled'), NULL, array('onclick' => "showHonor()"));
     $this->add('text', 'honor_block_title', ts('Honoree Section Title'), $attributes['honor_block_title']);
     $this->add('textarea', 'honor_block_text', ts('Honoree Introductory Message'), $attributes['honor_block_text']);
     // add optional start and end dates
     $this->addDateTime('start_date', ts('Start Date'));
     $this->addDateTime('end_date', ts('End Date'));
     $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Settings', 'formRule'), $this);
     parent::buildQuickForm();
 }
Esempio n. 6
0
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     $this->addYesNo('is_monetary', ts('Paid Event'), NULL, NULL, array('onclick' => "return showHideByValue('is_monetary','0','event-fees','block','radio',false);"));
     //add currency element.
     $this->addCurrency('currency', ts('Currency'), FALSE);
     $paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor();
     $this->assign('paymentProcessor', $paymentProcessor);
     $this->addCheckBox('payment_processor', ts('Payment Processor'), array_flip($paymentProcessor), NULL, NULL, NULL, NULL, array('&nbsp;&nbsp;', '&nbsp;&nbsp;', '&nbsp;&nbsp;', '<br/>'));
     // financial type
     $financialType = CRM_Financial_BAO_FinancialType::getIncomeFinancialType();
     $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + $financialType);
     // add pay later options
     $this->addElement('checkbox', 'is_pay_later', ts('Enable Pay Later option?'), NULL, array('onclick' => "return showHideByValue('is_pay_later','','payLaterOptions','block','radio',false);"));
     $this->addElement('textarea', 'pay_later_text', ts('Pay Later Label'), CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'pay_later_text'), FALSE);
     $this->addWysiwyg('pay_later_receipt', ts('Pay Later Instructions'), CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'pay_later_receipt'));
     $this->add('text', 'fee_label', ts('Fee Label'));
     $price = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviEvent');
     if (CRM_Utils_System::isNull($price)) {
         $this->assign('price', FALSE);
     } else {
         $this->assign('price', TRUE);
     }
     $this->add('select', 'price_set_id', ts('Price Set'), array('' => ts('- none -')) + $price, NULL, array('onchange' => "return showHideByValue('price_set_id', '', 'map-field', 'block', 'select', false);"));
     $default = array();
     $this->add('hidden', 'price_field_id', '', array('id' => 'price_field_id'));
     for ($i = 1; $i <= self::NUM_OPTION; $i++) {
         // label
         $this->add('text', "label[{$i}]", ts('Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'label'));
         $this->add('hidden', "price_field_value[{$i}]", '', array('id' => "price_field_value[{$i}]"));
         // value
         $this->add('text', "value[{$i}]", ts('Value'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'value'));
         $this->addRule("value[{$i}]", ts('Please enter a valid money value for this field (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money');
         // default
         $default[] = $this->createElement('radio', NULL, NULL, NULL, $i);
     }
     $this->addGroup($default, 'default');
     $this->addElement('checkbox', 'is_discount', ts('Discounts by Signup Date?'), NULL, array('onclick' => "warnDiscountDel(); return showHideByValue('is_discount','','discount','block','radio',false);"));
     $discountSection = $this->get('discountSection');
     $this->assign('discountSection', $discountSection);
     // form fields of Discount sets
     $defaultOption = array();
     $_showHide = new CRM_Core_ShowHideBlocks('', '');
     for ($i = 1; $i <= self::NUM_DISCOUNT; $i++) {
         //the show hide blocks
         $showBlocks = 'discount_' . $i;
         if ($i > 2) {
             $_showHide->addHide($showBlocks);
         } else {
             $_showHide->addShow($showBlocks);
         }
         //Increment by 1 of start date of previous end date.
         if (is_array($this->_submitValues) && !empty($this->_submitValues['discount_name'][$i]) && !empty($this->_submitValues['discount_name'][$i + 1]) && isset($this->_submitValues['discount_end_date']) && isset($this->_submitValues['discount_end_date'][$i]) && $i < self::NUM_DISCOUNT - 1) {
             $end_date = CRM_Utils_Date::processDate($this->_submitValues['discount_end_date'][$i]);
             if (!empty($this->_submitValues['discount_end_date'][$i + 1]) && empty($this->_submitValues['discount_start_date'][$i + 1])) {
                 list($this->_submitValues['discount_start_date'][$i + 1]) = CRM_Utils_Date::setDateDefaults(date('Y-m-d', strtotime("+1 days {$end_date}")));
             }
         }
         //Decrement by 1 of end date from next start date.
         if ($i > 1 && is_array($this->_submitValues) && !empty($this->_submitValues['discount_name'][$i]) && !empty($this->_submitValues['discount_name'][$i - 1]) && isset($this->_submitValues['discount_start_date']) && isset($this->_submitValues['discount_start_date'][$i])) {
             $start_date = CRM_Utils_Date::processDate($this->_submitValues['discount_start_date'][$i]);
             if (!empty($this->_submitValues['discount_start_date'][$i]) && empty($this->_submitValues['discount_end_date'][$i - 1])) {
                 list($this->_submitValues['discount_end_date'][$i - 1]) = CRM_Utils_Date::setDateDefaults(date('Y-m-d', strtotime("-1 days {$start_date}")));
             }
         }
         //discount name
         $this->add('text', 'discount_name[' . $i . ']', ts('Discount Name'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceSet', 'title'));
         $this->add('hidden', "discount_price_set[{$i}]", '', array('id' => "discount_price_set[{$i}]"));
         //discount start date
         $this->addDate('discount_start_date[' . $i . ']', ts('Discount Start Date'), FALSE, array('formatType' => 'activityDate'));
         //discount end date
         $this->addDate('discount_end_date[' . $i . ']', ts('Discount End Date'), FALSE, array('formatType' => 'activityDate'));
     }
     $_showHide->addToTemplate();
     $this->addElement('submit', $this->getButtonName('submit'), ts('Add Discount Set to Fee Table'), array('class' => 'form-submit'));
     $this->buildAmountLabel();
     parent::buildQuickForm();
 }