2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
38 /*********************************************************************************
40 * Description: TODO: To be written.
41 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42 * All Rights Reserved.
43 * Contributor(s): ______________________________________..
44 ********************************************************************************/
47 require_once('include/SugarObjects/templates/person/Person.php');
49 // Employee is used to store customer information.
50 class Employee extends Person {
74 var $address_postalcode;
78 var $modified_user_id;
81 var $modified_by_name;
88 var $module_dir = "Employees";
91 var $table_name = "users";
93 var $object_name = "Employee";
94 var $user_preferences;
96 var $encodeFields = Array("first_name", "last_name", "description");
98 // This is used to retrieve related fields from form posts.
99 var $additional_column_fields = Array('reports_to_name');
103 var $new_schema = true;
105 function Employee() {
107 //$this->setupCustomFields('Employees');
108 $this->emailAddress = new SugarEmailAddress();
112 function get_summary_text() {
113 $this->_create_proper_name_field();
118 function fill_in_additional_list_fields() {
119 $this->fill_in_additional_detail_fields();
122 function fill_in_additional_detail_fields()
125 $query = "SELECT u1.first_name, u1.last_name from users u1, users u2 where u1.id = u2.reports_to_id AND u2.id = '$this->id' and u1.deleted=0";
126 $result =$this->db->query($query, true, "Error filling in additional detail fields") ;
128 $row = $this->db->fetchByAssoc($result);
129 $GLOBALS['log']->debug("additional detail query results: $row");
133 $this->reports_to_name = stripslashes($locale->getLocaleFormattedName($row['first_name'], $row['last_name']));
137 $this->reports_to_name = '';
141 function retrieve_employee_id($employee_name)
143 $query = "SELECT id from users where user_name='$user_name' AND deleted=0";
144 $result = $this->db->query($query, false,"Error retrieving employee ID: ");
145 $row = $this->db->fetchByAssoc($result);
150 * @return -- returns a list of all employees in the system.
151 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
152 * All Rights Reserved..
153 * Contributor(s): ______________________________________..
155 function verify_data()
157 //none of the checks from the users module are valid here since the user_name and
158 //is_admin_on fields are not editable.
162 function get_list_view_data(){
164 global $current_user;
165 $this->_create_proper_name_field(); // create proper NAME (by combining first + last)
166 $user_fields = $this->get_list_view_array();
167 // Copy over the reports_to_name
168 if ( isset($GLOBALS['app_list_strings']['messenger_type_dom'][$this->messenger_type]) )
169 $user_fields['MESSENGER_TYPE'] = $GLOBALS['app_list_strings']['messenger_type_dom'][$this->messenger_type];
170 if ( isset($GLOBALS['app_list_strings']['employee_status_dom'][$this->employee_status]) )
171 $user_fields['EMPLOYEE_STATUS'] = $GLOBALS['app_list_strings']['employee_status_dom'][$this->employee_status];
172 $user_fields['REPORTS_TO_NAME'] = $this->reports_to_name;
173 $user_fields['NAME'] = empty($this->name) ? '' : $this->name;
174 $user_fields['EMAIL1'] = $this->emailAddress->getPrimaryAddress($this,$this->id,'Users');
175 $this->email1 = $user_fields['EMAIL1'];
176 $user_fields['EMAIL1_LINK'] = $current_user->getEmailLink('email1', $this, '', '', 'ListView');
180 function list_view_parse_additional_sections(&$list_form, $xTemplateSection){
185 function create_export_query($order_by, $where) {
186 include('modules/Employees/field_arrays.php');
189 foreach($fields_array['Employee']['export_fields'] as $field) {
190 $cols .= (empty($cols)) ? '' : ', ';
194 $query = "SELECT {$cols} FROM users ";
196 $where_auto = " users.deleted = 0";
199 $query .= " WHERE $where AND " . $where_auto;
201 $query .= " WHERE " . $where_auto;
204 $query .= " ORDER BY $order_by";
206 $query .= " ORDER BY users.user_name";
213 * Generate the name field from the first_name and last_name fields.
216 function _create_proper_name_field() {
218 $full_name = $locale->getLocaleFormattedName($this->first_name, $this->last_name);
219 $this->name = $full_name;
220 $this->full_name = $full_name;
224 function preprocess_fields_on_save(){
225 parent::preprocess_fields_on_save();