Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
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 | /** | |
8ef12e64 | 44 | * This function provides the HTML form elements that are specific |
6a488035 TO |
45 | * to the Individual Contact Type |
46 | * | |
77c5b619 TO |
47 | * @param CRM_Core_Form $form |
48 | * Form object. | |
49 | * @param int $inlineEditMode | |
50 | * ( 1 for contact summary. | |
6a488035 TO |
51 | * top bar form and 2 for display name edit ) |
52 | * | |
8ef12e64 | 53 | * @return void |
6a488035 TO |
54 | */ |
55 | public static function buildQuickForm(&$form, $inlineEditMode = NULL) { | |
56 | $form->applyFilter('__ALL__', 'trim'); | |
57 | ||
481a74f4 | 58 | if (!$inlineEditMode || $inlineEditMode == 1) { |
8b49cb50 OB |
59 | $nameFields = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, |
60 | 'contact_edit_options', TRUE, NULL, | |
61 | FALSE, 'name', TRUE, 'AND v.filter = 2' | |
62 | ); | |
63 | ||
6a488035 | 64 | //prefix |
e6c4755b | 65 | $prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id'); |
8b49cb50 | 66 | if (isset($nameFields['Prefix']) && !empty($prefix)) { |
1ae720b3 | 67 | $form->addField('prefix_id', array('class' => 'eight', 'placeholder' => ' ', 'label' => ts('Prefix'))); |
6a488035 TO |
68 | } |
69 | ||
70 | $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact'); | |
71 | ||
8b49cb50 | 72 | if (isset($nameFields['Formal Title'])) { |
8c2d9383 | 73 | $form->addField('formal_title', $attributes['formal_title']); |
8b49cb50 | 74 | } |
e171748b | 75 | |
6a488035 | 76 | // first_name |
8b49cb50 | 77 | if (isset($nameFields['First Name'])) { |
8c2d9383 | 78 | $form->addField('first_name', $attributes['first_name']); |
8b49cb50 | 79 | } |
6a488035 TO |
80 | |
81 | //middle_name | |
8b49cb50 | 82 | if (isset($nameFields['Middle Name'])) { |
8c2d9383 | 83 | $form->addField('middle_name', $attributes['middle_name']); |
8b49cb50 | 84 | } |
6a488035 TO |
85 | |
86 | // last_name | |
8b49cb50 | 87 | if (isset($nameFields['Last Name'])) { |
8c2d9383 | 88 | $form->addField('last_name', $attributes['last_name']); |
8b49cb50 | 89 | } |
6a488035 TO |
90 | |
91 | // suffix | |
e6c4755b | 92 | $suffix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id'); |
8b49cb50 | 93 | if (isset($nameFields['Suffix']) && $suffix) { |
1ae720b3 | 94 | $form->addField('suffix_id', array('class' => 'eight', 'placeholder' => ' ', 'label' => ts('Suffix'))); |
6a488035 TO |
95 | } |
96 | } | |
97 | ||
481a74f4 | 98 | if (!$inlineEditMode || $inlineEditMode == 2) { |
6a488035 | 99 | // nick_name |
5e77c16a | 100 | $form->addField('nick_name', $attributes['nick_name']); |
6a488035 TO |
101 | |
102 | // job title | |
103 | // override the size for UI to look better | |
104 | $attributes['job_title']['size'] = 30; | |
8c2d9383 | 105 | $form->addField('job_title', array('size' => '30') + $attributes['job_title']); |
6a488035 | 106 | //Current Employer Element |
66aa3a9f CW |
107 | $props = array( |
108 | 'api' => array('params' => array('contact_type' => 'Organization')), | |
109 | 'create' => TRUE, | |
110 | ); | |
111 | $form->addEntityRef('employer_id', ts('Current Employer'), $props); | |
112 | $attributes['source']['class'] = 'big'; | |
6a488035 TO |
113 | $form->addElement('text', 'contact_source', ts('Source'), CRM_Utils_Array::value('source', $attributes)); |
114 | } | |
115 | ||
481a74f4 | 116 | if (!$inlineEditMode) { |
6a488035 TO |
117 | $checkSimilar = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, |
118 | 'contact_ajax_check_similar', | |
119 | NULL, | |
120 | TRUE | |
121 | ); | |
122 | ||
e60f24eb | 123 | if ($checkSimilar == NULL) { |
6a488035 TO |
124 | $checkSimilar = 0; |
125 | } | |
126 | $form->assign('checkSimilar', $checkSimilar); | |
127 | ||
128 | //External Identifier Element | |
7b99ead3 | 129 | $form->add('text', 'external_identifier', ts('External ID'), |
6a488035 TO |
130 | CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'external_identifier'), FALSE |
131 | ); | |
132 | ||
133 | $form->addRule('external_identifier', | |
134 | ts('External ID already exists in Database.'), | |
135 | 'objectExists', | |
136 | array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier') | |
137 | ); | |
138 | $config = CRM_Core_Config::singleton(); | |
139 | CRM_Core_ShowHideBlocks::links($form, 'demographics', '', ''); | |
140 | } | |
141 | } | |
142 | ||
143 | /** | |
fe482240 | 144 | * Global form rule. |
6a488035 | 145 | * |
77c5b619 TO |
146 | * @param array $fields |
147 | * The input form values. | |
148 | * @param array $files | |
149 | * The uploaded files if any. | |
100fef9d | 150 | * @param int $contactID |
77b97be7 | 151 | * |
4eeb9a5b TO |
152 | * @return bool |
153 | * TRUE if no errors, else array of errors. | |
6a488035 | 154 | */ |
00be9182 | 155 | public static function formRule($fields, $files, $contactID = NULL) { |
6a488035 TO |
156 | $errors = array(); |
157 | $primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID); | |
158 | ||
159 | // make sure that firstName and lastName or a primary OpenID is set | |
8cc574cf | 160 | if (!$primaryID && (empty($fields['first_name']) || empty($fields['last_name']))) { |
6a488035 TO |
161 | $errors['_qf_default'] = ts('First Name and Last Name OR an email OR an OpenID in the Primary Location should be set.'); |
162 | } | |
163 | ||
164 | //check for duplicate - dedupe rules | |
165 | CRM_Contact_Form_Contact::checkDuplicateContacts($fields, $errors, $contactID, 'Individual'); | |
166 | ||
167 | return empty($errors) ? TRUE : $errors; | |
168 | } | |
96025800 | 169 | |
6a488035 | 170 | } |