Process greeting templates with Smarty
[civicrm-core.git] / CRM / Contact / Form / Edit / Individual.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
232624b1 4 | CiviCRM version 4.4 |
6a488035
TO
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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 */
41class 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 *
47 * @param object $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 ) {
58 //prefix
e6c4755b 59 $prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id');
6a488035
TO
60 if (!empty($prefix)) {
61 $form->addElement('select', 'prefix_id', ts('Prefix'), array('' => '') + $prefix);
62 }
63
64 $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact');
65
66 // first_name
67 $form->addElement('text', 'first_name', ts('First Name'), $attributes['first_name']);
68
69 //middle_name
70 $form->addElement('text', 'middle_name', ts('Middle Name'), $attributes['middle_name']);
71
72 // last_name
73 $form->addElement('text', 'last_name', ts('Last Name'), $attributes['last_name']);
74
75 // suffix
e6c4755b 76 $suffix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id');
6a488035
TO
77 if ($suffix) {
78 $form->addElement('select', 'suffix_id', ts('Suffix'), array('' => '') + $suffix);
79 }
80 }
81
82 if ( !$inlineEditMode || $inlineEditMode == 2 ) {
83 // nick_name
84 $form->addElement('text', 'nick_name', ts('Nickname'),
85 CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'nick_name')
86 );
87
88 // job title
89 // override the size for UI to look better
90 $attributes['job_title']['size'] = 30;
91 $form->addElement('text', 'job_title', ts('Job Title'), $attributes['job_title'], 'size="30"');
92
93 //Current Employer Element
94 $employerDataURL = CRM_Utils_System::url('civicrm/ajax/rest', 'className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=contact&org=1&employee_id=' . $form->_contactId, FALSE, NULL, FALSE);
95 $form->assign('employerDataURL', $employerDataURL);
96
97 $form->addElement('text', 'current_employer', ts('Current Employer'), '');
98 $form->addElement('hidden', 'current_employer_id', '', array('id' => 'current_employer_id'));
99 $form->addElement('text', 'contact_source', ts('Source'), CRM_Utils_Array::value('source', $attributes));
100 }
101
102 if ( !$inlineEditMode ) {
103 $checkSimilar = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
104 'contact_ajax_check_similar',
105 NULL,
106 TRUE
107 );
108
109 if ( $checkSimilar == null ) {
110 $checkSimilar = 0;
111 }
112 $form->assign('checkSimilar', $checkSimilar);
113
114 //External Identifier Element
115 $form->add('text', 'external_identifier', ts('External Id'),
116 CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'external_identifier'), FALSE
117 );
118
119 $form->addRule('external_identifier',
120 ts('External ID already exists in Database.'),
121 'objectExists',
122 array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier')
123 );
124 $config = CRM_Core_Config::singleton();
125 CRM_Core_ShowHideBlocks::links($form, 'demographics', '', '');
126 }
127 }
128
129 /**
130 * global form rule
131 *
132 * @param array $fields the input form values
133 * @param array $files the uploaded files if any
134 * @param array $options additional user data
135 *
136 * @return true if no errors, else array of errors
137 * @access public
138 * @static
139 */
140 static function formRule($fields, $files, $contactID = NULL) {
141 $errors = array();
142 $primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID);
143
144 // make sure that firstName and lastName or a primary OpenID is set
145 if (!$primaryID && (!CRM_Utils_Array::value('first_name', $fields) ||
146 !CRM_Utils_Array::value('last_name', $fields)
147 )) {
148 $errors['_qf_default'] = ts('First Name and Last Name OR an email OR an OpenID in the Primary Location should be set.');
149 }
150
151 //check for duplicate - dedupe rules
152 CRM_Contact_Form_Contact::checkDuplicateContacts($fields, $errors, $contactID, 'Individual');
153
154 return empty($errors) ? TRUE : $errors;
155 }
156}
157