Introduce new `communication_style` field for Contacts
[civicrm-core.git] / CRM / Contact / Form / NewContact.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2013
32 * $Id$
33 *
34 */
35
36 /**
37 * This class build form elements for select exitsing or create new contact widget
38 */
39 class CRM_Contact_Form_NewContact {
40
41 /**
42 * Function used to build form element for new contact or select contact widget
43 *
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
48 *
49 * @access public
50 *
51 * @return void
52 */
53 static function buildQuickForm(&$form, $blockNo = 1, $extraProfiles = NULL, $required = FALSE, $prefix = '', $label = NULL) {
54 // call to build contact autocomplete
55 $attributes = array('width' => '200px');
56
57 if (!$label) {
58 $label = ts('Select Contact');
59 }
60
61 $selectContacts = $form->add('text', "{$prefix}contact[{$blockNo}]", $label, $attributes, $required);
62
63 // use submitted values to set default if form submit fails dues to form rules
64 if ($selectContacts->getValue()) {
65 $form->assign("selectedContacts", $selectContacts->getValue());
66 }
67
68 $form->addElement('hidden', "{$prefix}contact_select_id[{$blockNo}]");
69
70 if (CRM_Core_Permission::check('edit all contacts') || CRM_Core_Permission::check('add contacts')) {
71 // build select for new contact
72 $contactProfiles = CRM_Core_BAO_UFGroup::getReservedProfiles('Contact', $extraProfiles);
73 $form->add('select', "{$prefix}profiles[{$blockNo}]", ts('Create New Contact'), array(
74 '' => ts('- create new contact -'),
75 ) + $contactProfiles, FALSE, array(
76 'onChange' => "if (this.value) { newContact{$prefix}{$blockNo}( this.value, {$blockNo}, '{$prefix}' );}",
77 ));
78 }
79
80 $form->assign('blockNo', $blockNo);
81 $form->assign('prefix', $prefix);
82 }
83 }
84