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-2013 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;
89 var $module_dir = "Employees";
92 var $table_name = "users";
94 var $object_name = "Employee";
95 var $user_preferences;
97 var $encodeFields = Array("first_name", "last_name", "description");
99 // This is used to retrieve related fields from form posts.
100 var $additional_column_fields = Array('reports_to_name');
104 var $new_schema = true;
106 function Employee() {
108 $this->setupCustomFields('Users');
109 $this->emailAddress = new SugarEmailAddress();
113 function get_summary_text() {
114 $this->_create_proper_name_field();
119 function fill_in_additional_list_fields() {
120 $this->fill_in_additional_detail_fields();
123 function fill_in_additional_detail_fields()
126 $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";
127 $result =$this->db->query($query, true, "Error filling in additional detail fields") ;
129 $row = $this->db->fetchByAssoc($result);
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 $user_fields = parent::get_list_view_data();
166 // Copy over the reports_to_name
167 if ( isset($GLOBALS['app_list_strings']['messenger_type_dom'][$this->messenger_type]) )
168 $user_fields['MESSENGER_TYPE'] = $GLOBALS['app_list_strings']['messenger_type_dom'][$this->messenger_type];
169 if ( isset($GLOBALS['app_list_strings']['employee_status_dom'][$this->employee_status]) )
170 $user_fields['EMPLOYEE_STATUS'] = $GLOBALS['app_list_strings']['employee_status_dom'][$this->employee_status];
171 $user_fields['REPORTS_TO_NAME'] = $this->reports_to_name;
176 function list_view_parse_additional_sections(&$list_form, $xTemplateSection){
181 function create_export_query($order_by, $where) {
182 include('modules/Employees/field_arrays.php');
185 foreach($fields_array['Employee']['export_fields'] as $field) {
186 $cols .= (empty($cols)) ? '' : ', ';
190 $query = "SELECT {$cols} FROM users ";
192 $where_auto = " users.deleted = 0";
195 $query .= " WHERE $where AND " . $where_auto;
197 $query .= " WHERE " . $where_auto;
200 $query .= " ORDER BY $order_by";
202 $query .= " ORDER BY users.user_name";
209 * Generate the name field from the first_name and last_name fields.
212 function _create_proper_name_field() {
214 $full_name = $locale->getLocaleFormattedName($this->first_name, $this->last_name);
215 $this->name = $full_name;
216 $this->full_name = $full_name;
220 function preprocess_fields_on_save(){
221 parent::preprocess_fields_on_save();
227 * create_new_list_query
229 * Return the list query used by the list views and export button. Next generation of create_new_list_query function.
231 * We overrode this function in the Employees module to add the additional filter check so that we do not retrieve portal users for the Employees list view queries
233 * @param string $order_by custom order by clause
234 * @param string $where custom where clause
235 * @param array $filter Optioanal
236 * @param array $params Optional *
237 * @param int $show_deleted Optional, default 0, show deleted records is set to 1.
238 * @param string $join_type
239 * @param boolean $return_array Optional, default false, response as array
240 * @param object $parentbean creating a subquery for this bean.
241 * @param boolean $singleSelect Optional, default false.
242 * @return String select query string, optionally an array value will be returned if $return_array= true.
244 function create_new_list_query($order_by, $where, $filter=array(), $params=array(), $show_deleted=0, $join_type='', $return_array=false, $parentbean=null, $singleSelect=false)
246 //create the filter for portal only users, as they should not be showing up in query results
248 $where = ' users.portal_only = 0 ';
250 $where .= ' and users.portal_only = 0 ';
253 //return parent method, specifying for array to be returned
254 return parent::create_new_list_query($order_by, $where, $filter,$params, $show_deleted, $join_type, $return_array, $parentbean, $singleSelect);
258 * Overwrite Sugar bean which returns the current objects custom fields. Lets return User custom fields instead
260 function hasCustomFields()
263 //Check to see if there are custom user fields that we should report on, first check the custom_fields array
264 $userCustomfields = !empty($GLOBALS['dictionary']['Employee']['custom_fields']);
265 if(!$userCustomfields){
266 //custom Fields not set, so traverse employee fields to see if any custom fields exist
267 foreach ($GLOBALS['dictionary']['Employee']['fields'] as $k=>$v){
268 if(!empty($v['source']) && $v['source'] == 'custom_fields'){
269 //custom field has been found, set flag to true and break
270 $userCustomfields = true;
277 //return result of search for custom fields
278 return $userCustomfields;