3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
37 * This class build form elements for select exitsing or create new contact widget
39 class CRM_Contact_Form_NewContact
{
42 * Function used to build form element for new contact or select contact widget
44 * @param object $form form object
45 * @param int $blocNo by default it is one, except for address block where it is
46 * build for each block
47 * @param array $extrProfiles extra profiles that should be included besides reserved
53 static function buildQuickForm(&$form, $blockNo = 1, $extraProfiles = NULL, $required = FALSE, $prefix = '') {
54 // call to build contact autocomplete
55 $attributes = array('width' => '200px');
57 $selectContacts = $form->add('text', "{$prefix}contact[{$blockNo}]", ts('Select Contact'), $attributes, $required);
59 // use submitted values to set default if form submit fails dues to form rules
60 if ($selectContacts->getValue()) {
61 $form->assign("selectedContacts", $selectContacts->getValue());
64 $form->addElement('hidden', "{$prefix}contact_select_id[{$blockNo}]");
66 if (CRM_Core_Permission
::check('edit all contacts') || CRM_Core_Permission
::check('add contacts')) {
67 // build select for new contact
68 $contactProfiles = CRM_Core_BAO_UFGroup
::getReservedProfiles('Contact', $extraProfiles);
69 $form->add('select', "{$prefix}profiles[{$blockNo}]", ts('Create New Contact'), array(
70 '' => ts('- create new contact -'),
71 ) +
$contactProfiles, FALSE, array(
72 'onChange' => "if (this.value) { newContact{$prefix}{$blockNo}( this.value, {$blockNo}, '{$prefix}' );}",
76 $form->assign('blockNo', $blockNo);
77 $form->assign('prefix', $prefix);