CRM-14264 : start using xml for gender / suffix / prefix
[civicrm-core.git] / CRM / Contact / Form / NewContact.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
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 */
39class 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 = '') {
54 // call to build contact autocomplete
55 $attributes = array('width' => '200px');
56
57 $selectContacts = $form->add('text', "{$prefix}contact[{$blockNo}]", ts('Select Contact'), $attributes, $required);
58
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());
62 }
63
64 $form->addElement('hidden', "{$prefix}contact_select_id[{$blockNo}]");
65
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}' );}",
73 ));
74 }
75
76 $form->assign('blockNo', $blockNo);
77 $form->assign('prefix', $prefix);
78 }
79}
80