Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
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 | |
8c9251b3 | 31 | * @copyright CiviCRM LLC (c) 2004-2018 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
5a409b50 | 35 | * Auxiliary class to provide support to the Contact Form class. |
6a488035 | 36 | * |
5a409b50 | 37 | * Does this by implementing a small set of static methods. |
6a488035 TO |
38 | */ |
39 | class CRM_Contact_Form_Edit_Individual { | |
40 | ||
41 | /** | |
5a409b50 | 42 | * This function provides the HTML form elements that are specific to the Individual Contact Type. |
6a488035 | 43 | * |
77c5b619 TO |
44 | * @param CRM_Core_Form $form |
45 | * Form object. | |
46 | * @param int $inlineEditMode | |
47 | * ( 1 for contact summary. | |
6a488035 | 48 | * top bar form and 2 for display name edit ) |
6a488035 TO |
49 | */ |
50 | public static function buildQuickForm(&$form, $inlineEditMode = NULL) { | |
51 | $form->applyFilter('__ALL__', 'trim'); | |
52 | ||
481a74f4 | 53 | if (!$inlineEditMode || $inlineEditMode == 1) { |
8b49cb50 OB |
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' | |
57 | ); | |
2e5791e9 WDC |
58 | |
59 | // Use names instead of labels to build form. | |
60 | $nameFields = array_keys($nameFields); | |
61 | ||
030be0ce CW |
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') { | |
66 | // God, why god? | |
67 | $fix .= '_id'; | |
68 | } | |
8b49cb50 | 69 | } |
6a488035 | 70 | |
030be0ce CW |
71 | foreach ($nameFields as $name) { |
72 | $props = array(); | |
73 | if ($name == 'prefix_id' || $name == 'suffix_id') { | |
0c4b273e | 74 | //override prefix/suffix label name as Prefix/Suffix respectively and adjust select size |
030be0ce CW |
75 | $props = array('class' => 'eight', 'placeholder' => ' ', 'label' => $name == 'prefix_id' ? ts('Prefix') : ts('Suffix')); |
76 | } | |
77 | $form->addField($name, $props); | |
6a488035 TO |
78 | } |
79 | } | |
80 | ||
481a74f4 | 81 | if (!$inlineEditMode || $inlineEditMode == 2) { |
6a488035 | 82 | // nick_name |
95457d69 | 83 | $form->addField('nick_name'); |
6a488035 TO |
84 | |
85 | // job title | |
86 | // override the size for UI to look better | |
95457d69 | 87 | $form->addField('job_title', array('size' => '30')); |
030be0ce | 88 | |
6a488035 | 89 | //Current Employer Element |
66aa3a9f CW |
90 | $props = array( |
91 | 'api' => array('params' => array('contact_type' => 'Organization')), | |
92 | 'create' => TRUE, | |
93 | ); | |
b58770ea TM |
94 | $form->addField('employer_id', $props); |
95 | $form->addField('contact_source', array('class' => 'big')); | |
6a488035 TO |
96 | } |
97 | ||
481a74f4 | 98 | if (!$inlineEditMode) { |
6a488035 | 99 | //External Identifier Element |
95457d69 | 100 | $form->addField('external_identifier', array('label' => 'External ID')); |
6a488035 TO |
101 | |
102 | $form->addRule('external_identifier', | |
103 | ts('External ID already exists in Database.'), | |
104 | 'objectExists', | |
105 | array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier') | |
106 | ); | |
6a488035 TO |
107 | CRM_Core_ShowHideBlocks::links($form, 'demographics', '', ''); |
108 | } | |
109 | } | |
110 | ||
111 | /** | |
fe482240 | 112 | * Global form rule. |
6a488035 | 113 | * |
77c5b619 TO |
114 | * @param array $fields |
115 | * The input form values. | |
116 | * @param array $files | |
117 | * The uploaded files if any. | |
100fef9d | 118 | * @param int $contactID |
77b97be7 | 119 | * |
4eeb9a5b TO |
120 | * @return bool |
121 | * TRUE if no errors, else array of errors. | |
6a488035 | 122 | */ |
00be9182 | 123 | public static function formRule($fields, $files, $contactID = NULL) { |
6a488035 | 124 | $errors = array(); |
d6def514 | 125 | $primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID, 'Individual'); |
6a488035 TO |
126 | |
127 | // make sure that firstName and lastName or a primary OpenID is set | |
8cc574cf | 128 | if (!$primaryID && (empty($fields['first_name']) || empty($fields['last_name']))) { |
6a488035 TO |
129 | $errors['_qf_default'] = ts('First Name and Last Name OR an email OR an OpenID in the Primary Location should be set.'); |
130 | } | |
131 | ||
6a488035 TO |
132 | return empty($errors) ? TRUE : $errors; |
133 | } | |
96025800 | 134 | |
6a488035 | 135 | } |