/**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     $this->setPageTitle(ts('Premium Product'));
     if ($this->_action & CRM_Core_Action::PREVIEW) {
         CRM_Contribute_BAO_Premium::buildPremiumPreviewBlock($this, $this->_id);
         return;
     }
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     $this->add('text', 'name', ts('Name'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'name'), TRUE);
     $this->addRule('name', ts('A product with this name already exists. Please select another name.'), 'objectExists', array('CRM_Contribute_DAO_Product', $this->_id));
     $this->add('text', 'sku', ts('SKU'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'sku'));
     $this->add('textarea', 'description', ts('Description'), 'rows=3, cols=60');
     $image['image'] = $this->createElement('radio', NULL, NULL, ts('Upload from my computer'), 'image', 'onclick="add_upload_file_block(\'image\');');
     $image['thumbnail'] = $this->createElement('radio', NULL, NULL, ts('Display image and thumbnail from these locations on the web:'), 'thumbnail', 'onclick="add_upload_file_block(\'thumbnail\');');
     $image['default_image'] = $this->createElement('radio', NULL, NULL, ts('Use default image'), 'default_image', 'onclick="add_upload_file_block(\'default\');');
     $image['noImage'] = $this->createElement('radio', NULL, NULL, ts('Do not display an image'), 'noImage', 'onclick="add_upload_file_block(\'noImage\');');
     $this->addGroup($image, 'imageOption', ts('Premium Image'));
     $this->addRule('imageOption', ts('Please select an option for the premium image.'), 'required');
     $this->addElement('text', 'imageUrl', ts('Image URL'));
     $this->addElement('text', 'thumbnailUrl', ts('Thumbnail URL'));
     $this->add('file', 'uploadFile', ts('Image File Name'), 'onChange="select_option();"');
     $this->add('text', 'price', ts('Market Value'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'price'), TRUE);
     $this->addRule('price', ts('Please enter the Market Value for this product.'), 'money');
     $this->add('text', 'cost', ts('Actual Cost of Product'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'cost'));
     $this->addRule('price', ts('Please enter the Actual Cost of Product.'), 'money');
     $this->add('text', 'min_contribution', ts('Minimum Contribution Amount'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'min_contribution'), TRUE);
     $this->addRule('min_contribution', ts('Please enter a monetary value for the Minimum Contribution Amount.'), 'money');
     $this->add('textarea', 'options', ts('Options'), 'rows=3, cols=60');
     $this->add('select', 'period_type', ts('Period Type'), array('' => '- select -', 'rolling' => 'Rolling', 'fixed' => 'Fixed'));
     $this->add('text', 'fixed_period_start_day', ts('Fixed Period Start Day'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'fixed_period_start_day'));
     $this->add('Select', 'duration_unit', ts('Duration Unit'), array('' => '- select period -') + CRM_Core_SelectValues::getPremiumUnits());
     $this->add('text', 'duration_interval', ts('Duration'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'duration_interval'));
     $this->add('Select', 'frequency_unit', ts('Frequency Unit'), array('' => '- select period -') + CRM_Core_SelectValues::getPremiumUnits());
     $this->add('text', 'frequency_interval', ts('Frequency'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'frequency_interval'));
     //Financial Type CRM-11106
     $financialType = CRM_Contribute_PseudoConstant::financialType();
     $premiumFinancialType = array();
     CRM_Core_PseudoConstant::populate($premiumFinancialType, 'CRM_Financial_DAO_EntityFinancialAccount', $all = TRUE, $retrieve = 'entity_id', $filter = NULL, 'account_relationship = 8');
     $costFinancialType = array();
     CRM_Core_PseudoConstant::populate($costFinancialType, 'CRM_Financial_DAO_EntityFinancialAccount', $all = TRUE, $retrieve = 'entity_id', $filter = NULL, 'account_relationship = 7');
     $productFinancialType = array_intersect($costFinancialType, $premiumFinancialType);
     foreach ($financialType as $key => $financialTypeName) {
         if (!in_array($key, $productFinancialType)) {
             unset($financialType[$key]);
         }
     }
     if (count($financialType)) {
         $this->assign('financialType', $financialType);
     }
     $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + $financialType);
     $this->add('checkbox', 'is_active', ts('Enabled?'));
     $this->addFormRule(array('CRM_Contribute_Form_ManagePremiums', 'formRule'));
     $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->assign('productId', $this->_id);
 }
Beispiel #2
0
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     $urlParams = 'civicrm/admin/contribute/premium';
     if ($this->_action & CRM_Core_Action::DELETE) {
         $session = CRM_Core_Session::singleton();
         $url = CRM_Utils_System::url($urlParams, 'reset=1&action=update&id=' . $this->_id);
         $session->pushUserContext($url);
         if (CRM_Utils_Request::retrieve('confirmed', 'Boolean', CRM_Core_DAO::$_nullObject, '', '', 'GET')) {
             $dao = new CRM_Contribute_DAO_PremiumsProduct();
             $dao->id = $this->_pid;
             $dao->delete();
             CRM_Core_Session::setStatus(ts('Selected Premium Product has been removed from this Contribution Page.'), ts('Saved'), 'success');
             CRM_Utils_System::redirect($url);
         }
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => '    ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if ($this->_action & CRM_Core_Action::PREVIEW) {
         CRM_Contribute_BAO_Premium::buildPremiumPreviewBlock($this, NULL, $this->_pid);
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Done with Preview'), 'isDefault' => TRUE)));
         return;
     }
     $session = CRM_Core_Session::singleton();
     $url = CRM_Utils_System::url($urlParams, 'reset=1&action=update&id=' . $this->_id);
     $session->pushUserContext($url);
     $this->add('select', 'product_id', ts('Select the Product') . ' ', $this->_products, TRUE);
     $this->addElement('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_PremiumsProduct', 'weight'));
     $financialType = CRM_Contribute_PseudoConstant::financialType();
     $premiumFinancialType = array();
     CRM_Core_PseudoConstant::populate($premiumFinancialType, 'CRM_Financial_DAO_EntityFinancialAccount', $all = TRUE, $retrieve = 'entity_id', $filter = NULL, 'account_relationship = 8');
     $costFinancialType = array();
     CRM_Core_PseudoConstant::populate($costFinancialType, 'CRM_Financial_DAO_EntityFinancialAccount', $all = TRUE, $retrieve = 'entity_id', $filter = NULL, 'account_relationship = 7');
     $productFinancialType = array_intersect($costFinancialType, $premiumFinancialType);
     foreach ($financialType as $key => $financialTypeName) {
         if (!in_array($key, $productFinancialType)) {
             unset($financialType[$key]);
         }
     }
     if (count($financialType)) {
         $this->assign('financialType', $financialType);
     }
     $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + $financialType);
     $this->addRule('weight', ts('Please enter integer value for weight'), 'integer');
     $session->pushUserContext(CRM_Utils_System::url($urlParams, 'action=update&reset=1&id=' . $this->_id));
     if ($this->_single) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => '    ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
     } else {
         parent::buildQuickForm();
     }
 }
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     $urlParams = 'civicrm/admin/contribute/premium';
     if ($this->_action & CRM_Core_Action::DELETE) {
         $session = CRM_Core_Session::singleton();
         $url = CRM_Utils_System::url($urlParams, 'reset=1&action=update&id=' . $this->_id);
         $session->pushUserContext($url);
         if (CRM_Utils_Request::retrieve('confirmed', 'Boolean', CRM_Core_DAO::$_nullObject, '', '', 'GET')) {
             $dao = new CRM_Contribute_DAO_PremiumsProduct();
             $dao->id = $this->_pid;
             $dao->delete();
             CRM_Core_Session::setStatus(ts('Selected Premium Product has been removed from this Contribution Page.'));
             CRM_Utils_System::redirect($url);
         }
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => '    ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if ($this->_action & CRM_Core_Action::PREVIEW) {
         CRM_Contribute_BAO_Premium::buildPremiumPreviewBlock($this, NULL, $this->_pid);
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Done with Preview'), 'isDefault' => TRUE)));
         return;
     }
     $session = CRM_Core_Session::singleton();
     $url = CRM_Utils_System::url($urlParams, 'reset=1&action=update&id=' . $this->_id);
     $session->pushUserContext($url);
     $this->add('select', 'product_id', ts('Select the Product') . ' ', $this->_products, TRUE);
     $this->addElement('text', 'weight', ts('Weight'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_PremiumsProduct', 'weight'));
     $this->addRule('weight', ts('Please enter integer value for weight'), 'integer');
     $session->pushUserContext(CRM_Utils_System::url($urlParams, 'action=update&reset=1&id=' . $this->_id));
     if ($this->_single) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => '    ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
     } else {
         parent::buildQuickForm();
     }
 }
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     //parent::buildQuickForm( );
     if ($this->_action & CRM_Core_Action::PREVIEW) {
         require_once 'CRM/Contribute/BAO/Premium.php';
         CRM_Contribute_BAO_Premium::buildPremiumPreviewBlock($this, $this->_id);
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Done with Preview'), 'isDefault' => true)));
         return;
     }
     if ($this->_action & CRM_Core_Action::DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     $this->add('text', 'name', ts('Name'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'name'), true);
     $this->addRule('name', ts('A product with this name already exists. Please select another name.'), 'objectExists', array('CRM_Contribute_DAO_Product', $this->_id));
     $this->add('text', 'sku', ts('SKU'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'sku'));
     $this->add('textarea', 'description', ts('Description'), 'rows=3, cols=60');
     $image['image'] = $this->createElement('radio', null, null, ts('Upload from my computer'), 'image', 'onclick="add_upload_file_block(\'image\');');
     $image['thumbnail'] = $this->createElement('radio', null, null, ts('Display image and thumbnail from these locations on the web:'), 'thumbnail', 'onclick="add_upload_file_block(\'thumbnail\');');
     $image['default_image'] = $this->createElement('radio', null, null, ts('Use default image'), 'default_image', 'onclick="add_upload_file_block(\'default\');');
     $image['noImage'] = $this->createElement('radio', null, null, ts('Do not display an image'), 'noImage', 'onclick="add_upload_file_block(\'noImage\');');
     $this->addGroup($image, 'imageOption', ts('Premium Image'));
     $this->addRule('imageOption', ts('Please select an option for the premium image.'), 'required');
     $this->addElement('text', 'imageUrl', ts('Image URL'));
     $this->addRule('imageUrl', 'Please enter the valid URL to display this image.', 'url');
     $this->addElement('text', 'thumbnailUrl', ts('Thumbnail URL'));
     $this->addRule('thumbnailUrl', 'Please enter the valid URL to display a thumbnail of this image.', 'url');
     $this->add('file', 'uploadFile', ts('Image File Name'), 'onChange="select_option();"');
     $this->add('text', 'price', ts('Market Value'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'price'), true);
     $this->addRule('price', ts('Please enter the Market Value for this product.'), 'money');
     $this->add('text', 'cost', ts('Actual Cost of Product'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'cost'));
     $this->addRule('price', ts('Please enter the Actual Cost of Product.'), 'money');
     $this->add('text', 'min_contribution', ts('Minimum Contribution Amount'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'min_contribution'), true);
     $this->addRule('min_contribution', ts('Please enter a monetary value for the Minimum Contribution Amount.'), 'money');
     $this->add('textarea', 'options', ts('Options'), 'rows=3, cols=60');
     $this->add('select', 'period_type', ts('Period Type'), array('' => '- select -', 'rolling' => 'Rolling', 'fixed' => 'Fixed'));
     $this->add('text', 'fixed_period_start_day', ts('Fixed Period Start Day'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'fixed_period_start_day'));
     $this->add('Select', 'duration_unit', ts('Duration Unit'), array('' => '- select period -', 'day' => 'Day', 'week' => 'Week', 'month' => 'Month', 'year' => 'Year'));
     $this->add('text', 'duration_interval', ts('Duration'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'duration_interval'));
     $this->add('Select', 'frequency_unit', ts('Frequency Unit'), array('' => '- select period -', 'day' => 'Day', 'week' => 'Week', 'month' => 'Month', 'year' => 'Year'));
     $this->add('text', 'frequency_interval', ts('Frequency'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'frequency_interval'));
     $this->add('checkbox', 'is_active', ts('Enabled?'));
     $this->addFormRule(array('CRM_Contribute_Form_ManagePremiums', 'formRule'));
     $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->assign('productId', $this->_id);
 }
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 function buildQuickForm()
 {
     if ($this->_action & CRM_CORE_ACTION_DELETE) {
         $session =& CRM_Core_Session::singleton();
         $url = CRM_Utils_System::url('/civicrm/admin/contribute', 'reset=1&action=update&id=' . $this->_id . '&subPage=Premium');
         $session->pushUserContext($url);
         if (CRM_Utils_Request::retrieve('confirmed', $form, '', '', 'GET')) {
             require_once 'CRM/Contribute/DAO/PremiumsProduct.php';
             $dao =& new CRM_Contribute_DAO_PremiumsProduct();
             $dao->id = $this->_pid;
             $dao->delete();
             CRM_Core_Session::setStatus(ts('Selected Premium Product has been removed from this Contribution Page.'));
             CRM_Utils_System::redirect($url);
         }
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => '    ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if ($this->_action & CRM_CORE_ACTION_PREVIEW) {
         require_once 'CRM/Contribute/BAO/Premium.php';
         CRM_Contribute_BAO_Premium::buildPremiumPreviewBlock($this, null, $this->_pid);
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Done With Preview'), 'isDefault' => true)));
         return;
     }
     $session =& CRM_Core_Session::singleton();
     $url = CRM_Utils_System::url('/civicrm/admin/contribute', 'reset=1&action=update&id=' . $this->_id . '&subPage=Premium');
     $session->pushUserContext($url);
     $this->addElement('select', 'product_id', ts('Select the Product') . ' ', $this->_products);
     $this->addRule('product_id', ts('Select the Product') . ' ', 'required');
     $this->addElement('text', 'sort_position', ts('Weight'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_PremiumsProduct', 'sort_position'));
     $this->addRule('sort_position', ts('Please enter integer value for weight'), 'integer');
     $session =& CRM_Core_Session::singleton();
     $single = $session->get('singleForm');
     $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/contribute', 'action=update&reset=1&id=' . $this->_id . '&subPage=Premium'));
     if ($single) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => '    ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
     } else {
         parent::buildQuickForm();
     }
 }