PageRenderTime 66ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/CRM/Contribute/Form/ContributionPage/Settings.php

https://github.com/ksecor/civicrm
PHP | 195 lines | 87 code | 33 blank | 75 comment | 6 complexity | 080914734d3d50fb7179938906d9af96 MD5 | raw file
  1. <?php
  2. /*
  3. +--------------------------------------------------------------------+
  4. | CiviCRM version 3.1 |
  5. +--------------------------------------------------------------------+
  6. | Copyright CiviCRM LLC (c) 2004-2009 |
  7. +--------------------------------------------------------------------+
  8. | This file is a part of CiviCRM. |
  9. | |
  10. | CiviCRM is free software; you can copy, modify, and distribute it |
  11. | under the terms of the GNU Affero General Public License |
  12. | Version 3, 19 November 2007. |
  13. | |
  14. | CiviCRM is distributed in the hope that it will be useful, but |
  15. | WITHOUT ANY WARRANTY; without even the implied warranty of |
  16. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
  17. | See the GNU Affero General Public License for more details. |
  18. | |
  19. | You should have received a copy of the GNU Affero General Public |
  20. | License along with this program; if not, contact CiviCRM LLC |
  21. | at info[AT]civicrm[DOT]org. If you have questions about the |
  22. | GNU Affero General Public License or the licensing of CiviCRM, |
  23. | see the CiviCRM license FAQ at http://civicrm.org/licensing |
  24. +--------------------------------------------------------------------+
  25. */
  26. /**
  27. *
  28. * @package CRM
  29. * @copyright CiviCRM LLC (c) 2004-2009
  30. * $Id$
  31. *
  32. */
  33. require_once 'CRM/Contribute/Form/ContributionPage.php';
  34. require_once 'CRM/Contribute/PseudoConstant.php';
  35. class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_ContributionPage
  36. {
  37. /**
  38. * This function sets the default values for the form. Note that in edit/view mode
  39. * the default values are retrieved from the database
  40. *
  41. * @access public
  42. * @return void
  43. */
  44. function setDefaultValues()
  45. {
  46. if ( $this->_id ) {
  47. $title = CRM_Core_DAO::getFieldValue( 'CRM_Contribute_DAO_ContributionPage',
  48. $this->_id,
  49. 'title' );
  50. CRM_Utils_System::setTitle( ts( 'Title and Settings (%1)',
  51. array( 1 => $title ) ) );
  52. } else {
  53. CRM_Utils_System::setTitle( ts( 'Title and Settings' ) );
  54. }
  55. return parent::setDefaultValues();
  56. }
  57. /**
  58. * Function to actually build the form
  59. *
  60. * @return void
  61. * @access public
  62. */
  63. public function buildQuickForm()
  64. {
  65. require_once 'CRM/Utils/Money.php';
  66. $this->_first = true;
  67. $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage');
  68. // name
  69. $this->add('text', 'title', ts('Title'), $attributes['title'], true);
  70. $this->add('select', 'contribution_type_id',
  71. ts( 'Contribution Type' ),
  72. CRM_Contribute_PseudoConstant::contributionType( ),
  73. true );
  74. $this->addWysiwyg( 'intro_text', ts('Introductory Message'), $attributes['intro_text'] );
  75. $this->addWysiwyg( 'footer_text', ts('Footer Message'), $attributes['footer_text'] );
  76. // is on behalf of an organization ?
  77. $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);") );
  78. $options = array();
  79. $options[] = HTML_QuickForm::createElement('radio', null, null, ts('Optional'), 1 );
  80. $options[] = HTML_QuickForm::createElement('radio', null, null, ts('Required'), 2 );
  81. $this->addGroup($options, 'is_for_organization', ts('') );
  82. $this->add('textarea', 'for_organization', ts('On behalf of Label'), $attributes['for_organization'] );
  83. // collect goal amount
  84. $this->add('text', 'goal_amount', ts('Goal Amount'), array( 'size' => 8, 'maxlength' => 12 ) );
  85. $this->addRule('goal_amount', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money');
  86. // is this page active ?
  87. $this->addElement('checkbox', 'is_active', ts('Is this Online Contribution Page Active?') );
  88. // should the honor be enabled
  89. $this->addElement('checkbox', 'honor_block_is_active', ts( 'Honoree Section Enabled' ),null,array('onclick' =>"showHonor()") );
  90. $this->add('text', 'honor_block_title', ts('Honoree Section Title'), $attributes['honor_block_title'] );
  91. $this->add('textarea', 'honor_block_text', ts('Honoree Introductory Message'), $attributes['honor_block_text'] );
  92. // add optional start and end dates
  93. $this->addDateTime( 'start_date', ts('Start Date') );
  94. $this->addDateTime( 'end_date', ts('End Date') );
  95. $this->addFormRule( array( 'CRM_Contribute_Form_ContributionPage_Settings', 'formRule' ) );
  96. parent::buildQuickForm( );
  97. }
  98. /**
  99. * global validation rules for the form
  100. *
  101. * @param array $values posted values of the form
  102. *
  103. * @return array list of errors to be posted back to the form
  104. * @static
  105. * @access public
  106. */
  107. static function formRule( &$values )
  108. {
  109. $errors = array( );
  110. //CRM-4286
  111. if ( strstr( $values['title'], '/' ) ) {
  112. $errors['title'] = ts( "Please do not use '/' in Title" );
  113. }
  114. return $errors;
  115. }
  116. /**
  117. * Process the form
  118. *
  119. * @return void
  120. * @access public
  121. */
  122. public function postProcess()
  123. {
  124. // get the submitted form values.
  125. $params = $this->controller->exportValues( $this->_name );
  126. // we do this in case the user has hit the forward/back button
  127. if ( $this->_id ) {
  128. $params['id'] = $this->_id;
  129. }
  130. //new contribution page, so lets set the created_id
  131. if ( $this->_action & CRM_Core_Action::ADD ) {
  132. $session =& CRM_Core_Session::singleton( );
  133. $params['created_id'] = $session->get( 'userID' );
  134. $params['created_date'] = date('YmdHis');
  135. }
  136. $params['is_active'] = CRM_Utils_Array::value('is_active' , $params, false);
  137. $params['is_credit_card_only'] = CRM_Utils_Array::value('is_credit_card_only' , $params, false);
  138. $params['honor_block_is_active'] = CRM_Utils_Array::value('honor_block_is_active', $params, false);
  139. $params['is_for_organization'] = CRM_Utils_Array::value('is_organization', $params )
  140. ? CRM_Utils_Array::value('is_for_organization', $params, false)
  141. : 0;
  142. $params['start_date'] = CRM_Utils_Date::processDate( $params['start_date'], $params['start_date_time'] );
  143. $params['end_date' ] = CRM_Utils_Date::processDate( $params['end_date'], $params['end_date_time'] );
  144. $params['goal_amount'] = CRM_Utils_Rule::cleanMoney( $params['goal_amount'] );
  145. if( !$params['honor_block_is_active'] ) {
  146. $params['honor_block_title'] = null;
  147. $params['honor_block_text'] = null;
  148. }
  149. require_once 'CRM/Contribute/BAO/ContributionPage.php';
  150. $dao =& CRM_Contribute_BAO_ContributionPage::create( $params );
  151. $this->set( 'id', $dao->id );
  152. }
  153. /**
  154. * Return a descriptive name for the page, used in wizard header
  155. *
  156. * @return string
  157. * @access public
  158. */
  159. public function getTitle( ) {
  160. return ts( 'Title and Settings' );
  161. }
  162. }