phpcs - Fix error, "Expected 1 newline at end of file; XXX found".
[civicrm-core.git] / CRM / Contact / Form / Edit / Individual.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
32 * $Id$
33 *
34 */
35
36 /**
37 * Auxilary class to provide support to the Contact Form class. Does this by implementing
38 * a small set of static methods
39 *
40 */
41 class CRM_Contact_Form_Edit_Individual {
42
43 /**
44 * This function provides the HTML form elements that are specific
45 * to the Individual Contact Type
46 *
47 * @param CRM_Core_Form $form form object
48 * @param int $inlineEditMode ( 1 for contact summary
49 * top bar form and 2 for display name edit )
50 *
51 * @return void
52 */
53 public static function buildQuickForm(&$form, $inlineEditMode = NULL) {
54 $form->applyFilter('__ALL__', 'trim');
55
56 if ( !$inlineEditMode || $inlineEditMode == 1 ) {
57 $nameFields = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
58 'contact_edit_options', TRUE, NULL,
59 FALSE, 'name', TRUE, 'AND v.filter = 2'
60 );
61
62 //prefix
63 $prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id');
64 if (isset($nameFields['Prefix']) && !empty($prefix)) {
65 $form->addSelect('prefix_id', array('class' => 'eight', 'placeholder' => ' ', 'label' => ts('Prefix')));
66 }
67
68 $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact');
69
70 if (isset($nameFields['Formal Title'])) {
71 $form->addElement('text', 'formal_title', ts('Title'), $attributes['formal_title']);
72 }
73
74 // first_name
75 if (isset($nameFields['First Name'])) {
76 $form->addElement('text', 'first_name', ts('First Name'), $attributes['first_name']);
77 }
78
79 //middle_name
80 if (isset($nameFields['Middle Name'])) {
81 $form->addElement('text', 'middle_name', ts('Middle Name'), $attributes['middle_name']);
82 }
83
84 // last_name
85 if (isset($nameFields['Last Name'])) {
86 $form->addElement('text', 'last_name', ts('Last Name'), $attributes['last_name']);
87 }
88
89 // suffix
90 $suffix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id');
91 if (isset($nameFields['Suffix']) && $suffix) {
92 $form->addSelect('suffix_id', array('class' => 'eight', 'placeholder' => ' ', 'label' => ts('Suffix')));
93 }
94 }
95
96 if ( !$inlineEditMode || $inlineEditMode == 2 ) {
97 // nick_name
98 $form->addElement('text', 'nick_name', ts('Nickname'),
99 CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'nick_name')
100 );
101
102 // job title
103 // override the size for UI to look better
104 $attributes['job_title']['size'] = 30;
105 $form->addElement('text', 'job_title', ts('Job Title'), $attributes['job_title'], 'size="30"');
106
107 //Current Employer Element
108 $props = array(
109 'api' => array('params' => array('contact_type' => 'Organization')),
110 'create' => TRUE,
111 );
112 $form->addEntityRef('employer_id', ts('Current Employer'), $props);
113 $attributes['source']['class'] = 'big';
114 $form->addElement('text', 'contact_source', ts('Source'), CRM_Utils_Array::value('source', $attributes));
115 }
116
117 if ( !$inlineEditMode ) {
118 $checkSimilar = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
119 'contact_ajax_check_similar',
120 NULL,
121 TRUE
122 );
123
124 if ( $checkSimilar == null ) {
125 $checkSimilar = 0;
126 }
127 $form->assign('checkSimilar', $checkSimilar);
128
129 //External Identifier Element
130 $form->add('text', 'external_identifier', ts('External ID'),
131 CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'external_identifier'), FALSE
132 );
133
134 $form->addRule('external_identifier',
135 ts('External ID already exists in Database.'),
136 'objectExists',
137 array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier')
138 );
139 $config = CRM_Core_Config::singleton();
140 CRM_Core_ShowHideBlocks::links($form, 'demographics', '', '');
141 }
142 }
143
144 /**
145 * Global form rule
146 *
147 * @param array $fields the input form values
148 * @param array $files the uploaded files if any
149 * @param int $contactID
150 *
151 * @return true if no errors, else array of errors
152 * @static
153 */
154 public static function formRule($fields, $files, $contactID = NULL) {
155 $errors = array();
156 $primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID);
157
158 // make sure that firstName and lastName or a primary OpenID is set
159 if (!$primaryID && (empty($fields['first_name']) || empty($fields['last_name']))) {
160 $errors['_qf_default'] = ts('First Name and Last Name OR an email OR an OpenID in the Primary Location should be set.');
161 }
162
163 //check for duplicate - dedupe rules
164 CRM_Contact_Form_Contact::checkDuplicateContacts($fields, $errors, $contactID, 'Individual');
165
166 return empty($errors) ? TRUE : $errors;
167 }
168 }