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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
35 require_once 'CRM/Core/Form.php';
38 * This class generates form components for adding an account if not already exists
41 class CRM_Auction_Form_ItemAccount
extends CRM_Core_Form
{
44 * the id of the auction for which item needs to be updated/added.
51 * the id of the item we are processing
57 public function preProcess() {
58 $session = CRM_Core_Session
::singleton();
59 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add');
60 $this->_aid
= CRM_Utils_Request
::retrieve('aid', 'Positive', $this);
62 if ($session->get('userID')) {
63 $this->_donorID
= $session->get('userID');
67 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE);
68 $this->_aid
= CRM_Core_DAO
::getFieldValue('CRM_Auction_DAO_Item', $this->_id
, 'auction_id');
71 // we do not want to display recently viewed items, so turn off
72 $this->assign('displayRecent', FALSE);
76 * This virtual function is used to set the default values of
77 * various form elements
81 * @return array reference to the array of default values
84 function setDefaultValues() {
85 if (!$this->_donorID
) {
89 foreach ($this->_fields
as $name => $dontcare) {
93 require_once "CRM/Core/BAO/UFGroup.php";
94 CRM_Core_BAO_UFGroup
::setProfileDefaults($this->_donorID
, $fields, $this->_defaults
);
96 //set custom field defaults
97 require_once "CRM/Core/BAO/CustomField.php";
98 foreach ($this->_fields
as $name => $field) {
99 if ($customFieldID = CRM_Core_BAO_CustomField
::getKeyID($name)) {
100 if (!isset($this->_defaults
[$name])) {
101 CRM_Core_BAO_CustomField
::setProfileDefaults($customFieldID, $name, $this->_defaults
,
102 NULL, CRM_Profile_Form
::MODE_REGISTER
108 return $this->_defaults
;
112 * Build the form object
117 public function buildQuickForm() {
118 $profileID = CRM_Core_DAO
::getFieldValue('CRM_Auction_DAO_Auction',
119 $this->_aid
, 'donor_profile_id'
122 CRM_Core_Error
::fatal('Profile not configured for this auction.');
125 require_once 'CRM/Auction/BAO/Item.php';
126 if (CRM_Auction_BAO_Item
::isEmailInProfile($profileID)) {
127 $this->assign('profileDisplay', TRUE);
131 require_once "CRM/Core/BAO/UFGroup.php";
132 if ($this->_donorID
) {
133 if (CRM_Core_BAO_UFGroup
::filterUFGroups($profileID, $this->_donorID
)) {
134 $fields = CRM_Core_BAO_UFGroup
::getFields($profileID, FALSE, CRM_Core_Action
::ADD
);
136 $this->addFormRule(array('CRM_Auction_Form_ItemAccount', 'formRule'), $this);
139 require_once 'CRM/Core/BAO/CMSUser.php';
140 CRM_Core_BAO_CMSUser
::buildForm($this, $profileID, TRUE);
142 $fields = CRM_Core_BAO_UFGroup
::getFields($profileID, FALSE, CRM_Core_Action
::ADD
);
146 $this->assign('fields', $fields);
148 foreach ($fields as $key => $field) {
149 if (isset($field['data_type']) && $field['data_type'] == 'File') {
150 // ignore file upload fields
153 require_once "CRM/Core/BAO/UFGroup.php";
154 require_once "CRM/Profile/Form.php";
155 CRM_Core_BAO_UFGroup
::buildProfile($this, $field, CRM_Profile_Form
::MODE_CREATE
);
156 $this->_fields
[$key] = $field;
157 if ($field['add_captcha']) {
163 require_once 'CRM/Utils/ReCAPTCHA.php';
164 $captcha = &CRM_Utils_ReCAPTCHA
::singleton();
165 $captcha->add($this);
166 $this->assign("isCaptcha", TRUE);
170 $button[] = array('type' => 'next',
171 'name' => ts('Continue >>'),
172 'spacing' => ' ',
176 $this->addButtons($button);
182 * @param array $fields the input form values
183 * @param array $files the uploaded files if any
187 * @return true if no errors, else array of errors
192 function formRule($fields, $files, $self) {
194 require_once "CRM/Utils/Rule.php";
195 foreach ($fields as $key => $value) {
196 if (strpos($key, 'email-') !== FALSE) {
197 $ufContactId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFMatch', $value, 'contact_id', 'uf_name');
198 if ($ufContactId && $ufContactId != $self->_donorID
) {
199 $errors[$key] = ts('There is already an user associated with this email address. Please enter different email address.');
203 return empty($errors) ?
TRUE : $errors;
207 * Process the form submission
213 public function postProcess() {
214 $params = $this->controller
->exportValues($this->getName());
215 if (!$this->_donorID
) {
216 foreach ($params as $key => $value) {
217 if (substr($key, 0, 5) == 'email' && !empty($value)) {
218 $params['email'] = $value;
222 $donorID = &CRM_Contact_BAO_Contact
::createProfileContact($params, $this->_fields
,
223 $this->_donorID
, $addToGroups
225 $this->set('donorID', $donorID);
227 require_once "CRM/Contribute/BAO/Contribution/Utils.php";
228 CRM_Contribute_BAO_Contribution_Utils
::createCMSUser($params, $donorID, 'email');