3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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 and the CiviCRM Licensing Exception. |
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. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
32 * @copyright CiviCRM LLC (c) 2004-2014
37 require_once 'CRM/Core/Form.php';
40 * This class manages the auction form
43 class CRM_Auction_Form_Auction
extends CRM_Core_Form
{
46 * the id of the auction we are proceessing
54 protected $_checkboxes;
59 * set variables up before form is built
63 */ function preProcess() {
64 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE);
66 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
68 if (!CRM_Core_Permission
::checkActionPermission('CiviAuction', $this->_action
)) {
69 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
72 if (($this->_action
& CRM_Core_Action
::VIEW ||
73 $this->_action
& CRM_Core_Action
::UPDATE ||
74 $this->_action
& CRM_Core_Action
::DELETE
78 CRM_Core_Error
::fatal();
83 * Set default values for the form.
84 * the default values are retrieved from the database
90 function setDefaultValues() {
91 require_once 'CRM/Auction/BAO/Auction.php';
95 if (isset($this->_id
)) {
96 $params = array('id' => $this->_id
);
97 CRM_Auction_BAO_Auction
::retrieve($params, $defaults);
100 $defaults['is_active'] = 1;
107 * Build the form object
112 public function buildQuickForm() {
113 $this->applyFilter('__ALL__', 'trim');
115 $attributes = CRM_Core_DAO
::getAttribute('CRM_Auction_DAO_Auction');
119 $attributes['auction_title'],
123 $this->addWysiwyg('description',
124 ts('Complete Description'),
125 $attributes['description']
128 $this->_dates
= array('start_date' => ts('Auction Start Date'),
129 'end_date' => ts('Auction End Date'),
130 'item_start_date' => ts('Upload Item Start Date'),
131 'item_end_date' => ts('Upload Item End Date'),
133 foreach ($this->_dates
as $name => $title) {
137 CRM_Core_SelectValues
::date('datetime')
139 $this->addRule($name, ts('Please select a valid date.'), 'qfDate');
142 $this->_checkboxes
= array('is_active' => ts('Is Active?'),
143 'is_approval_needed' => ts('Do items need to be approved?'),
144 'is_item_groups' => ts('Can items be grouped?'),
147 foreach ($this->_checkboxes
as $name => $title) {
148 $this->addElement('checkbox',
154 $this->_numbers
= array('max_items_user' => ts('Maximum number of items per user'),
155 'max_items' => ts('Maximum number of items for the auction'),
157 foreach ($this->_numbers
as $name => $title) {
158 $this->addElement('text',
163 $this->addRule($name,
164 ts('%1 should be a postive number',
171 if ($this->_action
& CRM_Core_Action
::VIEW
) {
172 $buttons = array(array('type' => 'upload',
173 'name' => ts('Done'),
174 'spacing' => ' ',
179 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
181 $buttons = array(array('type' => 'upload',
182 'name' => ts('Delete'),
183 'spacing' => ' ',
186 array('type' => 'cancel',
187 'name' => ts('Cancel'),
192 $buttons = array(array('type' => 'upload',
193 'name' => ts('Save'),
194 'spacing' => ' ',
197 array('type' => 'cancel',
198 'name' => ts('Cancel'),
202 $this->addButtons($buttons);
204 $this->addFormRule(array('CRM_Auction_Form_Auction', 'formRule'), $this);
210 * @param array $fields the input form values
211 * @param array $files the uploaded files if any
215 * @return true if no errors, else array of errors
220 function formRule($fields, $files, $self) {
223 // add rules to validate dates and overlap
224 return empty($errors) ?
TRUE : $errors;
228 * Process the form submission
234 public function postProcess() {
235 if ($this->_action
& CRM_Core_Action
::VIEW
) {
238 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
239 CRM_Auction_BAO_Auction
::del($this->_id
);
243 $params = $this->controller
->exportValues($this->_name
);
245 $params['id'] = $this->_id
;
247 // format date params
248 foreach ($this->_dates
as $name => $title) {
249 $params[$name] = CRM_Utils_Date
::format($params[$name]);
253 foreach ($this->_checkboxes
as $name => $title) {
254 $params[$name] = CRM_Utils_Array
::value($name, $params, FALSE);
257 CRM_Auction_BAO_Auction
::add($params);