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
39 * This class manages the auction form
42 class CRM_Auction_Form_Auction
extends CRM_Core_Form
{
45 * the id of the auction we are processsing
53 protected $_checkboxes;
58 * set variables up before form is built
62 function preProcess() {
63 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE);
65 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
67 if (!CRM_Core_Permission
::checkActionPermission('CiviAuction', $this->_action
)) {
68 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
71 if (($this->_action
& CRM_Core_Action
::VIEW ||
72 $this->_action
& CRM_Core_Action
::UPDATE ||
73 $this->_action
& CRM_Core_Action
::DELETE
77 CRM_Core_Error
::fatal();
82 * Set default values for the form.
83 * the default values are retrieved from the database
86 function setDefaultValues() {
90 if (isset($this->_id
)) {
91 $params = array('id' => $this->_id
);
92 CRM_Auction_BAO_Auction
::retrieve($params, $defaults);
95 $defaults['is_active'] = 1;
102 * Build the form object
106 public function buildQuickForm() {
107 $this->applyFilter('__ALL__', 'trim');
109 $attributes = CRM_Core_DAO
::getAttribute('CRM_Auction_DAO_Auction');
113 $attributes['auction_title'],
117 $this->addWysiwyg('description',
118 ts('Complete Description'),
119 $attributes['description']
122 $this->_dates
= array('start_date' => ts('Auction Start Date'),
123 'end_date' => ts('Auction End Date'),
124 'item_start_date' => ts('Upload Item Start Date'),
125 'item_end_date' => ts('Upload Item End Date'),
127 foreach ($this->_dates
as $name => $title) {
131 CRM_Core_SelectValues
::date('datetime')
133 $this->addRule($name, ts('Please select a valid date.'), 'qfDate');
136 $this->_checkboxes
= array('is_active' => ts('Is Active?'),
137 'is_approval_needed' => ts('Do items need to be approved?'),
138 'is_item_groups' => ts('Can items be grouped?'),
141 foreach ($this->_checkboxes
as $name => $title) {
142 $this->addElement('checkbox',
148 $this->_numbers
= array('max_items_user' => ts('Maximum number of items per user'),
149 'max_items' => ts('Maximum number of items for the auction'),
151 foreach ($this->_numbers
as $name => $title) {
152 $this->addElement('text',
157 $this->addRule($name,
158 ts('%1 should be a postive number',
165 if ($this->_action
& CRM_Core_Action
::VIEW
) {
166 $buttons = array(array('type' => 'upload',
167 'name' => ts('Done'),
168 'spacing' => ' ',
173 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
175 $buttons = array(array('type' => 'upload',
176 'name' => ts('Delete'),
177 'spacing' => ' ',
180 array('type' => 'cancel',
181 'name' => ts('Cancel'),
186 $buttons = array(array('type' => 'upload',
187 'name' => ts('Save'),
188 'spacing' => ' ',
191 array('type' => 'cancel',
192 'name' => ts('Cancel'),
196 $this->addButtons($buttons);
198 $this->addFormRule(array('CRM_Auction_Form_Auction', 'formRule'), $this);
204 * @param array $fields the input form values
205 * @param array $files the uploaded files if any
207 * @return true if no errors, else array of errors
209 static function formRule($fields, $files, $self) {
212 // add rules to validate dates and overlap
213 return empty($errors) ?
TRUE : $errors;
217 * Process the form submission
219 public function postProcess() {
220 if ($this->_action
& CRM_Core_Action
::VIEW
) {
223 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
224 CRM_Auction_BAO_Auction
::del($this->_id
);
228 $params = $this->controller
->exportValues($this->_name
);
230 $params['id'] = $this->_id
;
232 // format date params
233 foreach ($this->_dates
as $name => $title) {
234 $params[$name] = CRM_Utils_Date
::format($params[$name]);
238 foreach ($this->_checkboxes
as $name => $title) {
239 $params[$name] = CRM_Utils_Array
::value($name, $params, FALSE);
242 CRM_Auction_BAO_Auction
::add($params);