3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2018
35 * Auxiliary class to provide support to the Contact Form class.
37 * Does this by implementing a small set of static methods.
39 class CRM_Contact_Form_Edit_Individual
{
42 * This function provides the HTML form elements that are specific to the Individual Contact Type.
44 * @param CRM_Core_Form $form
46 * @param int $inlineEditMode
47 * ( 1 for contact summary.
48 * top bar form and 2 for display name edit )
50 public static function buildQuickForm(&$form, $inlineEditMode = NULL) {
51 $form->applyFilter('__ALL__', 'trim');
53 if (!$inlineEditMode ||
$inlineEditMode == 1) {
54 $nameFields = CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
55 'contact_edit_options', TRUE, NULL,
56 FALSE, 'name', TRUE, 'AND v.filter = 2'
59 // Use names instead of labels to build form.
60 $nameFields = array_keys($nameFields);
62 // Fixme: dear god why? these come out in a format that is NOT the name of the fields.
63 foreach ($nameFields as &$fix) {
64 $fix = str_replace(' ', '_', strtolower($fix));
65 if ($fix == 'prefix' ||
$fix == 'suffix') {
71 foreach ($nameFields as $name) {
73 if ($name == 'prefix_id' ||
$name == 'suffix_id') {
74 //override prefix/suffix label name as Prefix/Suffix respectively and adjust select size
75 $props = array('class' => 'eight', 'placeholder' => ' ', 'label' => $name == 'prefix_id' ?
ts('Prefix') : ts('Suffix'));
77 $form->addField($name, $props);
81 if (!$inlineEditMode ||
$inlineEditMode == 2) {
83 $form->addField('nick_name');
86 // override the size for UI to look better
87 $form->addField('job_title', array('size' => '30'));
89 //Current Employer Element
91 'api' => array('params' => array('contact_type' => 'Organization')),
94 $form->addField('employer_id', $props);
95 $form->addField('contact_source', array('class' => 'big'));
98 if (!$inlineEditMode) {
99 $checkSimilar = Civi
::settings()->get('contact_ajax_check_similar');
101 if ($checkSimilar == NULL) {
104 $form->assign('checkSimilar', $checkSimilar);
106 //External Identifier Element
107 $form->addField('external_identifier', array('label' => 'External ID'));
109 $form->addRule('external_identifier',
110 ts('External ID already exists in Database.'),
112 array('CRM_Contact_DAO_Contact', $form->_contactId
, 'external_identifier')
114 CRM_Core_ShowHideBlocks
::links($form, 'demographics', '', '');
121 * @param array $fields
122 * The input form values.
123 * @param array $files
124 * The uploaded files if any.
125 * @param int $contactID
128 * TRUE if no errors, else array of errors.
130 public static function formRule($fields, $files, $contactID = NULL) {
132 $primaryID = CRM_Contact_Form_Contact
::formRule($fields, $errors, $contactID);
134 // make sure that firstName and lastName or a primary OpenID is set
135 if (!$primaryID && (empty($fields['first_name']) ||
empty($fields['last_name']))) {
136 $errors['_qf_default'] = ts('First Name and Last Name OR an email OR an OpenID in the Primary Location should be set.');
139 //check for duplicate - dedupe rules
140 CRM_Contact_Form_Contact
::checkDuplicateContacts($fields, $errors, $contactID, 'Individual');
142 return empty($errors) ?
TRUE : $errors;