3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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.
52 * the id of the item we are processing
59 public function preProcess() {
60 $session = CRM_Core_Session
::singleton();
61 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add');
62 $this->_aid
= CRM_Utils_Request
::retrieve('aid', 'Positive', $this);
64 if ($session->get('userID')) {
65 $this->_donorID
= $session->get('userID');
69 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE);
70 $this->_aid
= CRM_Core_DAO
::getFieldValue('CRM_Auction_DAO_Item', $this->_id
, 'auction_id');
73 // we do not want to display recently viewed items, so turn off
74 $this->assign('displayRecent', FALSE);
78 * This virtual function is used to set the default values of
79 * various form elements
83 * @return array reference to the array of default values
86 function setDefaultValues() {
87 if (!$this->_donorID
) {
91 foreach ($this->_fields
as $name => $dontcare) {
95 require_once "CRM/Core/BAO/UFGroup.php";
96 CRM_Core_BAO_UFGroup
::setProfileDefaults($this->_donorID
, $fields, $this->_defaults
);
98 //set custom field defaults
99 require_once "CRM/Core/BAO/CustomField.php";
100 foreach ($this->_fields
as $name => $field) {
101 if ($customFieldID = CRM_Core_BAO_CustomField
::getKeyID($name)) {
102 if (!isset($this->_defaults
[$name])) {
103 CRM_Core_BAO_CustomField
::setProfileDefaults($customFieldID, $name, $this->_defaults
,
104 NULL, CRM_Profile_Form
::MODE_REGISTER
110 return $this->_defaults
;
114 * Function to build the form
119 public function buildQuickForm() {
120 $profileID = CRM_Core_DAO
::getFieldValue('CRM_Auction_DAO_Auction',
121 $this->_aid
, 'donor_profile_id'
124 CRM_Core_Error
::fatal('Profile not configured for this auction.');
127 require_once 'CRM/Auction/BAO/Item.php';
128 if (CRM_Auction_BAO_Item
::isEmailInProfile($profileID)) {
129 $this->assign('profileDisplay', TRUE);
133 require_once "CRM/Core/BAO/UFGroup.php";
134 if ($this->_donorID
) {
135 if (CRM_Core_BAO_UFGroup
::filterUFGroups($profileID, $this->_donorID
)) {
136 $fields = CRM_Core_BAO_UFGroup
::getFields($profileID, FALSE, CRM_Core_Action
::ADD
);
138 $this->addFormRule(array('CRM_Auction_Form_ItemAccount', 'formRule'), $this);
141 require_once 'CRM/Core/BAO/CMSUser.php';
142 CRM_Core_BAO_CMSUser
::buildForm($this, $profileID, TRUE);
144 $fields = CRM_Core_BAO_UFGroup
::getFields($profileID, FALSE, CRM_Core_Action
::ADD
);
148 $this->assign('fields', $fields);
150 foreach ($fields as $key => $field) {
151 if (isset($field['data_type']) && $field['data_type'] == 'File') {
152 // ignore file upload fields
155 require_once "CRM/Core/BAO/UFGroup.php";
156 require_once "CRM/Profile/Form.php";
157 CRM_Core_BAO_UFGroup
::buildProfile($this, $field, CRM_Profile_Form
::MODE_CREATE
);
158 $this->_fields
[$key] = $field;
159 if ($field['add_captcha']) {
165 require_once 'CRM/Utils/ReCAPTCHA.php';
166 $captcha = &CRM_Utils_ReCAPTCHA
::singleton();
167 $captcha->add($this);
168 $this->assign("isCaptcha", TRUE);
172 $button[] = array('type' => 'next',
173 'name' => ts('Continue >>'),
174 'spacing' => ' ',
178 $this->addButtons($button);
184 * @param array $fields the input form values
185 * @param array $files the uploaded files if any
188 * @internal param array $options additional user data
190 * @return true if no errors, else array of errors
195 function formRule($fields, $files, $self) {
197 require_once "CRM/Utils/Rule.php";
198 foreach ($fields as $key => $value) {
199 if (strpos($key, 'email-') !== FALSE) {
200 $ufContactId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFMatch', $value, 'contact_id', 'uf_name');
201 if ($ufContactId && $ufContactId != $self->_donorID
) {
202 $errors[$key] = ts('There is already an user associated with this email address. Please enter different email address.');
206 return empty($errors) ?
TRUE : $errors;
210 * Function to process the form
216 public function postProcess() {
217 $params = $this->controller
->exportValues($this->getName());
218 if (!$this->_donorID
) {
219 foreach ($params as $key => $value) {
220 if (substr($key, 0, 5) == 'email' && !empty($value)) {
221 $params['email'] = $value;
225 $donorID = &CRM_Contact_BAO_Contact
::createProfileContact($params, $this->_fields
,
226 $this->_donorID
, $addToGroups
228 $this->set('donorID', $donorID);
230 require_once "CRM/Contribute/BAO/Contribution/Utils.php";
231 CRM_Contribute_BAO_Contribution_Utils
::createCMSUser($params, $donorID, 'email');