3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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
55 protected $_checkboxes;
60 * Function to set variables up before form is built
64 */ function preProcess() {
65 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE);
67 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
69 if (!CRM_Core_Permission
::checkActionPermission('CiviAuction', $this->_action
)) {
70 CRM_Core_Error
::fatal(ts('You do not have permission to access this page'));
73 if (($this->_action
& CRM_Core_Action
::VIEW ||
74 $this->_action
& CRM_Core_Action
::UPDATE ||
75 $this->_action
& CRM_Core_Action
::DELETE
79 CRM_Core_Error
::fatal();
84 * This function sets the default values for the form.
85 * the default values are retrieved from the database
91 function setDefaultValues() {
92 require_once 'CRM/Auction/BAO/Auction.php';
96 if (isset($this->_id
)) {
97 $params = array('id' => $this->_id
);
98 CRM_Auction_BAO_Auction
::retrieve($params, $defaults);
101 $defaults['is_active'] = 1;
108 * Function to build the form
113 public function buildQuickForm() {
114 $this->applyFilter('__ALL__', 'trim');
116 $attributes = CRM_Core_DAO
::getAttribute('CRM_Auction_DAO_Auction');
120 $attributes['auction_title'],
124 $this->addWysiwyg('description',
125 ts('Complete Description'),
126 $attributes['description']
129 $this->_dates
= array('start_date' => ts('Auction Start Date'),
130 'end_date' => ts('Auction End Date'),
131 'item_start_date' => ts('Upload Item Start Date'),
132 'item_end_date' => ts('Upload Item End Date'),
134 foreach ($this->_dates
as $name => $title) {
138 CRM_Core_SelectValues
::date('datetime')
140 $this->addRule($name, ts('Please select a valid date.'), 'qfDate');
143 $this->_checkboxes
= array('is_active' => ts('Is Active?'),
144 'is_approval_needed' => ts('Do items need to be approved?'),
145 'is_item_groups' => ts('Can items be grouped?'),
148 foreach ($this->_checkboxes
as $name => $title) {
149 $this->addElement('checkbox',
155 $this->_numbers
= array('max_items_user' => ts('Maximum number of items per user'),
156 'max_items' => ts('Maximum number of items for the auction'),
158 foreach ($this->_numbers
as $name => $title) {
159 $this->addElement('text',
164 $this->addRule($name,
165 ts('%1 should be a postive number',
172 if ($this->_action
& CRM_Core_Action
::VIEW
) {
173 $buttons = array(array('type' => 'upload',
174 'name' => ts('Done'),
175 'spacing' => ' ',
180 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
182 $buttons = array(array('type' => 'upload',
183 'name' => ts('Delete'),
184 'spacing' => ' ',
187 array('type' => 'cancel',
188 'name' => ts('Cancel'),
193 $buttons = array(array('type' => 'upload',
194 'name' => ts('Save'),
195 'spacing' => ' ',
198 array('type' => 'cancel',
199 'name' => ts('Cancel'),
203 $this->addButtons($buttons);
205 $this->addFormRule(array('CRM_Auction_Form_Auction', 'formRule'), $this);
211 * @param array $fields the input form values
212 * @param array $files the uploaded files if any
215 * @internal param array $options additional user data
217 * @return true if no errors, else array of errors
222 function formRule($fields, $files, $self) {
225 // add rules to validate dates and overlap
226 return empty($errors) ?
TRUE : $errors;
230 * Function to process the form
236 public function postProcess() {
237 if ($this->_action
& CRM_Core_Action
::VIEW
) {
240 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
241 CRM_Auction_BAO_Auction
::del($this->_id
);
245 $params = $this->controller
->exportValues($this->_name
);
247 $params['id'] = $this->_id
;
249 // format date params
250 foreach ($this->_dates
as $name => $title) {
251 $params[$name] = CRM_Utils_Date
::format($params[$name]);
255 foreach ($this->_checkboxes
as $name => $title) {
256 $params[$name] = CRM_Utils_Array
::value($name, $params, FALSE);
259 CRM_Auction_BAO_Auction
::add($params);