]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Employees/Employee.php
Release 6.5.16
[Github/sugarcrm.git] / modules / Employees / Employee.php
1 <?php
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.
6  * 
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.
13  * 
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
17  * details.
18  * 
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
22  * 02110-1301 USA.
23  * 
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.
26  * 
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.
30  * 
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  ********************************************************************************/
37
38 /*********************************************************************************
39
40  * Description: TODO:  To be written.
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42  * All Rights Reserved.
43  * Contributor(s): ______________________________________..
44  ********************************************************************************/
45
46
47 require_once('include/SugarObjects/templates/person/Person.php');
48
49 // Employee is used to store customer information.
50 class Employee extends Person {
51         // Stored fields
52         var $name = '';
53         var $id;
54         var $is_admin;
55         var $first_name;
56         var $last_name;
57         var $full_name;
58         var $user_name;
59         var $title;
60         var $description;
61         var $department;
62         var $reports_to_id;
63         var $reports_to_name;
64         var $phone_home;
65         var $phone_mobile;
66         var $phone_work;
67         var $phone_other;
68         var $phone_fax;
69         var $email1;
70         var $email2;
71         var $address_street;
72         var $address_city;
73         var $address_state;
74         var $address_postalcode;
75         var $address_country;
76         var $date_entered;
77         var $date_modified;
78         var $modified_user_id;
79         var $created_by;
80         var $created_by_name;
81         var $modified_by_name;
82         var $status;
83         var $messenger_id;
84         var $messenger_type;
85         var $employee_status;
86         var $error_string;
87     public $person_id;
88
89         var $module_dir = "Employees";
90
91
92         var $table_name = "users";
93
94         var $object_name = "Employee";
95         var $user_preferences;
96
97         var $encodeFields = Array("first_name", "last_name", "description");
98
99         // This is used to retrieve related fields from form posts.
100         var $additional_column_fields = Array('reports_to_name');
101
102
103
104         var $new_schema = true;
105
106         function Employee() {
107                 parent::Person();
108                 $this->setupCustomFields('Users');
109                 $this->emailAddress = new SugarEmailAddress();
110         }
111
112
113         function get_summary_text() {
114         $this->_create_proper_name_field();
115         return $this->name;
116     }
117
118
119         function fill_in_additional_list_fields() {
120                 $this->fill_in_additional_detail_fields();
121         }
122
123         function fill_in_additional_detail_fields()
124         {
125                 global $locale;
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") ;
128
129                 $row = $this->db->fetchByAssoc($result);
130
131                 if($row != null)
132                 {
133                         $this->reports_to_name = stripslashes($locale->getLocaleFormattedName($row['first_name'], $row['last_name']));
134                 }
135                 else
136                 {
137                         $this->reports_to_name = '';
138                 }
139         }
140
141         function retrieve_employee_id($employee_name)
142         {
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);
146                 return $row['id'];
147         }
148
149         /**
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): ______________________________________..
154          */
155         function verify_data()
156         {
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.
159                 return TRUE;
160         }
161
162         function get_list_view_data(){
163
164         $user_fields = parent::get_list_view_data();
165
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;
172
173         return $user_fields;
174         }
175
176         function list_view_parse_additional_sections(&$list_form, $xTemplateSection){
177                 return $list_form;
178         }
179
180
181         function create_export_query($order_by, $where) {
182                 include('modules/Employees/field_arrays.php');
183
184                 $cols = '';
185                 foreach($fields_array['Employee']['export_fields'] as $field) {
186                         $cols .= (empty($cols)) ? '' : ', ';
187                         $cols .= $field;
188                 }
189
190                 $query = "SELECT {$cols} FROM users ";
191
192                 $where_auto = " users.deleted = 0";
193
194                 if($where != "")
195                         $query .= " WHERE $where AND " . $where_auto;
196                 else
197                         $query .= " WHERE " . $where_auto;
198
199                 if($order_by != "")
200                         $query .= " ORDER BY $order_by";
201                 else
202                         $query .= " ORDER BY users.user_name";
203
204                 return $query;
205         }
206
207         //use parent class
208         /**
209          * Generate the name field from the first_name and last_name fields.
210          */
211         /*
212         function _create_proper_name_field() {
213         global $locale;
214         $full_name = $locale->getLocaleFormattedName($this->first_name, $this->last_name);
215         $this->name = $full_name;
216         $this->full_name = $full_name;
217         }
218         */
219
220         function preprocess_fields_on_save(){
221                 parent::preprocess_fields_on_save();
222
223         }
224
225
226     /**
227      * create_new_list_query
228      *
229      * Return the list query used by the list views and export button. Next generation of create_new_list_query function.
230      *
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
232      *
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.
243      */
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)
245     {
246         //create the filter for portal only users, as they should not be showing up in query results
247         if(empty($where)){
248             $where = ' users.portal_only = 0 ';
249         }else{
250             $where .= ' and users.portal_only = 0 ';
251         }
252
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);
255     }
256
257     /*
258      * Overwrite Sugar bean which returns the current objects custom fields.  Lets return User custom fields instead
259      */
260     function hasCustomFields()
261     {
262
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;
271                     break;
272                 }
273
274             }
275         }
276
277         //return result of search for custom fields
278         return $userCustomfields;
279     }
280 }
281
282 ?>