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