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
78 * @return array reference to the array of default values
80 function setDefaultValues() {
81 if (!$this->_donorID
) {
85 foreach ($this->_fields
as $name => $dontcare) {
89 require_once "CRM/Core/BAO/UFGroup.php";
90 CRM_Core_BAO_UFGroup
::setProfileDefaults($this->_donorID
, $fields, $this->_defaults
);
92 //set custom field defaults
93 require_once "CRM/Core/BAO/CustomField.php";
94 foreach ($this->_fields
as $name => $field) {
95 if ($customFieldID = CRM_Core_BAO_CustomField
::getKeyID($name)) {
96 if (!isset($this->_defaults
[$name])) {
97 CRM_Core_BAO_CustomField
::setProfileDefaults($customFieldID, $name, $this->_defaults
,
98 NULL, CRM_Profile_Form
::MODE_REGISTER
104 return $this->_defaults
;
108 * Build the form object
110 public function buildQuickForm() {
111 $profileID = CRM_Core_DAO
::getFieldValue('CRM_Auction_DAO_Auction',
112 $this->_aid
, 'donor_profile_id'
115 CRM_Core_Error
::fatal('Profile not configured for this auction.');
118 require_once 'CRM/Auction/BAO/Item.php';
119 if (CRM_Auction_BAO_Item
::isEmailInProfile($profileID)) {
120 $this->assign('profileDisplay', TRUE);
124 require_once "CRM/Core/BAO/UFGroup.php";
125 if ($this->_donorID
) {
126 if (CRM_Core_BAO_UFGroup
::filterUFGroups($profileID, $this->_donorID
)) {
127 $fields = CRM_Core_BAO_UFGroup
::getFields($profileID, FALSE, CRM_Core_Action
::ADD
);
129 $this->addFormRule(array('CRM_Auction_Form_ItemAccount', 'formRule'), $this);
132 require_once 'CRM/Core/BAO/CMSUser.php';
133 CRM_Core_BAO_CMSUser
::buildForm($this, $profileID, TRUE);
135 $fields = CRM_Core_BAO_UFGroup
::getFields($profileID, FALSE, CRM_Core_Action
::ADD
);
139 $this->assign('fields', $fields);
141 foreach ($fields as $key => $field) {
142 if (isset($field['data_type']) && $field['data_type'] == 'File') {
143 // ignore file upload fields
146 require_once "CRM/Core/BAO/UFGroup.php";
147 require_once "CRM/Profile/Form.php";
148 CRM_Core_BAO_UFGroup
::buildProfile($this, $field, CRM_Profile_Form
::MODE_CREATE
);
149 $this->_fields
[$key] = $field;
150 if ($field['add_captcha']) {
156 require_once 'CRM/Utils/ReCAPTCHA.php';
157 $captcha = &CRM_Utils_ReCAPTCHA
::singleton();
158 $captcha->add($this);
159 $this->assign("isCaptcha", TRUE);
163 $button[] = array('type' => 'next',
164 'name' => ts('Continue >>'),
165 'spacing' => ' ',
169 $this->addButtons($button);
175 * @param array $fields the input form values
176 * @param array $files the uploaded files if any
181 static function formRule($fields, $files, $self) {
183 foreach ($fields as $key => $value) {
184 if (strpos($key, 'email-') !== FALSE) {
185 $ufContactId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFMatch', $value, 'contact_id', 'uf_name');
186 if ($ufContactId && $ufContactId != $self->_donorID
) {
187 $errors[$key] = ts('There is already an user associated with this email address. Please enter different email address.');
191 return empty($errors) ?
TRUE : $errors;
195 * Process the form submission
197 public function postProcess() {
198 $params = $this->controller
->exportValues($this->getName());
199 if (!$this->_donorID
) {
200 foreach ($params as $key => $value) {
201 if (substr($key, 0, 5) == 'email' && !empty($value)) {
202 $params['email'] = $value;
206 $donorID = &CRM_Contact_BAO_Contact
::createProfileContact($params, $this->_fields
,
207 $this->_donorID
, $addToGroups
209 $this->set('donorID', $donorID);
211 require_once "CRM/Contribute/BAO/Contribution/Utils.php";
212 CRM_Contribute_BAO_Contribution_Utils
::createCMSUser($params, $donorID, 'email');