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
54 * the id of the auction for this item
62 * the id of the person donating this item
70 * set variables up before form is built
74 */ function preProcess() {
75 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add');
77 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
78 $this->_aid
= CRM_Utils_Request
::retrieve('aid', 'Positive', $this, TRUE);
80 if (($this->_action
& CRM_Core_Action
::VIEW ||
81 $this->_action
& CRM_Core_Action
::UPDATE ||
82 $this->_action
& CRM_Core_Action
::DELETE
86 CRM_Core_Error
::fatal("I am not sure which item you looking for.");
89 require_once 'CRM/Auction/BAO/Auction.php';
90 $params = array('id' => $this->_aid
);
91 $this->_auctionValues
= array();
92 CRM_Auction_BAO_Auction
::retrieve($params, $this->_auctionValues
);
94 $this->assign('auctionTitle', $this->_auctionValues
['auction_title']);
97 $session = CRM_Core_Session
::singleton();
98 $this->_donorID
= $this->get('donorID');
100 $this->assign('donorName',
101 CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
107 // also set user context
108 $session->pushUserContext(CRM_Utils_System
::url('civicrm/auction/item',
109 "reset=1&aid={$this->_aid}"
114 * Set default values for the form.
115 * the default values are retrieved from the database
121 function setDefaultValues() {
122 require_once 'CRM/Auction/BAO/Item.php';
126 if (isset($this->_id
)) {
127 $params = array('id' => $this->_id
);
128 CRM_Auction_BAO_Item
::retrieve($params, $defaults);
131 $defaults['is_active'] = 1;
132 $defaults['auction_type_id'] = 1;
139 * Build the form object
144 public function buildQuickForm() {
145 $this->applyFilter('__ALL__', 'trim');
147 $attributes = CRM_Core_DAO
::getAttribute('CRM_Auction_DAO_Item');
151 $attributes['title'],
155 $this->addWysiwyg('description',
156 ts('Complete Description'),
157 $attributes['description']
160 $auctionTypes = CRM_Core_OptionGroup
::values('auction_item_type');
161 $this->add('select', 'auction_item_type_id', ts('Item Type'),
162 array('' => ts('- select -')) +
$auctionTypes
165 $this->add('text', 'url', ts('Item URL'),
166 array_merge($attributes['description'],
167 array('onfocus' => "if (!this.value) { this.value='http://';} else return false",
168 'onblur' => "if ( this.value == 'http://') { this.value='';} else return false",
174 $this->_checkboxes
= array('is_active' => ts('Is Active?'),
175 'is_group' => ts('Does this item have other items associated with it?'),
177 foreach ($this->_checkboxes
as $name => $title) {
178 $this->addElement('checkbox',
184 $this->_numbers
= array('quantity' => ts('Number of units available'),
185 'retail_value' => ts('Retail value of item'),
186 'min_bid_value' => ts('Minimum bid accepted'),
187 'min_bid_increment' => ts('Minimum bid increment'),
188 'buy_now_value' => ts('Buy it now value'),
191 foreach ($this->_numbers
as $name => $title) {
192 $this->addElement('text',
197 if ($name == 'quantity') {
198 $this->addRule($name,
199 ts('%1 should be a postive number',
206 $this->addRule($name,
207 ts('%1 should be a valid money value',
216 require_once 'CRM/Core/BAO/File.php';
217 CRM_Core_BAO_File
::buildAttachment($this, 'civicrm_pcp', $this->_pageId
, $maxAttachments);
220 if ($this->_action
& CRM_Core_Action
::VIEW
) {
221 $buttons = array(array('type' => 'upload',
222 'name' => ts('Done'),
223 'spacing' => ' ',
228 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
230 $buttons = array(array('type' => 'upload',
231 'name' => ts('Delete'),
232 'spacing' => ' ',
235 array('type' => 'cancel',
236 'name' => ts('Cancel'),
241 $buttons = array(array('type' => 'upload',
242 'name' => ts('Save'),
243 'spacing' => ' ',
247 $session = CRM_Core_Session
::singleton();
248 if ($session->get('userID')) {
249 $buttons[] = array('type' => 'next',
250 'name' => ts('Save and New'),
254 $buttons[] = array('type' => 'cancel',
255 'name' => ts('Cancel'),
258 $this->addButtons($buttons);
260 $this->addFormRule(array('CRM_Auction_Form_Item', 'formRule'), $this);
266 * @param array $fields the input form values
267 * @param array $files the uploaded files if any
271 * @return true if no errors, else array of errors
276 function formRule($fields, $files, $self) {
279 if (isset($files['attachFile_1'])) {
280 list($width, $height) = getimagesize($files['attachFile_1']['tmp_name']);
281 if ($width > 360 ||
$height > 360) {
282 $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.";
286 return empty($errors) ?
TRUE : $errors;
290 * Process the form submission
296 public function postProcess() {
297 if ($this->_action
& CRM_Core_Action
::VIEW
) {
300 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
301 CRM_Auction_BAO_Item
::del($this->_id
);
305 $params = $this->controller
->exportValues($this->_name
);
307 $params['id'] = $this->_id
;
308 $params['auction_id'] = $this->_aid
;
310 $params['donor_id'] = $this->_donorID
;
312 if ($this->_action
== CRM_Core_Action
::ADD
) {
313 $params['creator_id'] = $this->_donorID
;
314 $params['created_date'] = date('YmdHis');
318 foreach ($this->_checkboxes
as $name => $title) {
319 $params[$name] = CRM_Utils_Array
::value($name, $params, FALSE);
322 // does this auction require approval
323 $params['is_approved'] = $this->_auctionValues
['is_approval_needed'] ?
0 : 1;
325 CRM_Auction_BAO_Item
::add($params);
327 if ($this->controller
->getButtonName() == $this->getButtonName('next', 'new')) {
328 $session = CRM_Core_Session
::singleton();
329 //CRM_Core_Session::setStatus(ts(' You can add another profile field.'));
330 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/auction/item',
331 "reset=1&action=add&aid={$this->_aid}"