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_Item
extends CRM_Core_Form
{
46 * the id of the item we are processing
53 * the id of the auction for this item
60 * the id of the person donating this item
67 * set variables up before form is built
71 */ function preProcess() {
72 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add');
74 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
75 $this->_aid
= CRM_Utils_Request
::retrieve('aid', 'Positive', $this, TRUE);
77 if (($this->_action
& CRM_Core_Action
::VIEW ||
78 $this->_action
& CRM_Core_Action
::UPDATE ||
79 $this->_action
& CRM_Core_Action
::DELETE
83 CRM_Core_Error
::fatal("I am not sure which item you looking for.");
86 require_once 'CRM/Auction/BAO/Auction.php';
87 $params = array('id' => $this->_aid
);
88 $this->_auctionValues
= array();
89 CRM_Auction_BAO_Auction
::retrieve($params, $this->_auctionValues
);
91 $this->assign('auctionTitle', $this->_auctionValues
['auction_title']);
94 $session = CRM_Core_Session
::singleton();
95 $this->_donorID
= $this->get('donorID');
97 $this->assign('donorName',
98 CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
104 // also set user context
105 $session->pushUserContext(CRM_Utils_System
::url('civicrm/auction/item',
106 "reset=1&aid={$this->_aid}"
111 * Set default values for the form.
112 * the default values are retrieved from the database
118 function setDefaultValues() {
119 require_once 'CRM/Auction/BAO/Item.php';
123 if (isset($this->_id
)) {
124 $params = array('id' => $this->_id
);
125 CRM_Auction_BAO_Item
::retrieve($params, $defaults);
128 $defaults['is_active'] = 1;
129 $defaults['auction_type_id'] = 1;
136 * Build the form object
141 public function buildQuickForm() {
142 $this->applyFilter('__ALL__', 'trim');
144 $attributes = CRM_Core_DAO
::getAttribute('CRM_Auction_DAO_Item');
148 $attributes['title'],
152 $this->addWysiwyg('description',
153 ts('Complete Description'),
154 $attributes['description']
157 $auctionTypes = CRM_Core_OptionGroup
::values('auction_item_type');
158 $this->add('select', 'auction_item_type_id', ts('Item Type'),
159 array('' => ts('- select -')) +
$auctionTypes
162 $this->add('text', 'url', ts('Item URL'),
163 array_merge($attributes['description'],
164 array('onfocus' => "if (!this.value) { this.value='http://';} else return false",
165 'onblur' => "if ( this.value == 'http://') { this.value='';} else return false",
171 $this->_checkboxes
= array('is_active' => ts('Is Active?'),
172 'is_group' => ts('Does this item have other items associated with it?'),
174 foreach ($this->_checkboxes
as $name => $title) {
175 $this->addElement('checkbox',
181 $this->_numbers
= array('quantity' => ts('Number of units available'),
182 'retail_value' => ts('Retail value of item'),
183 'min_bid_value' => ts('Minimum bid accepted'),
184 'min_bid_increment' => ts('Minimum bid increment'),
185 'buy_now_value' => ts('Buy it now value'),
188 foreach ($this->_numbers
as $name => $title) {
189 $this->addElement('text',
194 if ($name == 'quantity') {
195 $this->addRule($name,
196 ts('%1 should be a postive number',
203 $this->addRule($name,
204 ts('%1 should be a valid money value',
213 require_once 'CRM/Core/BAO/File.php';
214 CRM_Core_BAO_File
::buildAttachment($this, 'civicrm_pcp', $this->_pageId
, $maxAttachments);
217 if ($this->_action
& CRM_Core_Action
::VIEW
) {
218 $buttons = array(array('type' => 'upload',
219 'name' => ts('Done'),
220 'spacing' => ' ',
225 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
227 $buttons = array(array('type' => 'upload',
228 'name' => ts('Delete'),
229 'spacing' => ' ',
232 array('type' => 'cancel',
233 'name' => ts('Cancel'),
238 $buttons = array(array('type' => 'upload',
239 'name' => ts('Save'),
240 'spacing' => ' ',
244 $session = CRM_Core_Session
::singleton();
245 if ($session->get('userID')) {
246 $buttons[] = array('type' => 'next',
247 'name' => ts('Save and New'),
251 $buttons[] = array('type' => 'cancel',
252 'name' => ts('Cancel'),
255 $this->addButtons($buttons);
257 $this->addFormRule(array('CRM_Auction_Form_Item', 'formRule'), $this);
263 * @param array $fields the input form values
264 * @param array $files the uploaded files if any
268 * @return true if no errors, else array of errors
273 function formRule($fields, $files, $self) {
276 if (isset($files['attachFile_1'])) {
277 list($width, $height) = getimagesize($files['attachFile_1']['tmp_name']);
278 if ($width > 360 ||
$height > 360) {
279 $errors['attachFile_1'] = "Your picture or image file can not be larger than 360 x 360 pixels in size." . " The dimensions of the image you've selected is " . $width . " x " . $height . ". Please shrink or crop the file or find another smaller image and try again.";
283 return empty($errors) ?
TRUE : $errors;
287 * Process the form submission
293 public function postProcess() {
294 if ($this->_action
& CRM_Core_Action
::VIEW
) {
297 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
298 CRM_Auction_BAO_Item
::del($this->_id
);
302 $params = $this->controller
->exportValues($this->_name
);
304 $params['id'] = $this->_id
;
305 $params['auction_id'] = $this->_aid
;
307 $params['donor_id'] = $this->_donorID
;
309 if ($this->_action
== CRM_Core_Action
::ADD
) {
310 $params['creator_id'] = $this->_donorID
;
311 $params['created_date'] = date('YmdHis');
315 foreach ($this->_checkboxes
as $name => $title) {
316 $params[$name] = CRM_Utils_Array
::value($name, $params, FALSE);
319 // does this auction require approval
320 $params['is_approved'] = $this->_auctionValues
['is_approval_needed'] ?
0 : 1;
322 CRM_Auction_BAO_Item
::add($params);
324 if ($this->controller
->getButtonName() == $this->getButtonName('next', 'new')) {
325 $session = CRM_Core_Session
::singleton();
326 //CRM_Core_Session::setStatus(ts(' You can add another profile field.'));
327 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/auction/item',
328 "reset=1&action=add&aid={$this->_aid}"