]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Employees/Employee.php
Release 6.4.0
[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-2011 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
88         var $module_dir = "Employees";
89
90
91         var $table_name = "users";
92
93         var $object_name = "Employee";
94         var $user_preferences;
95
96         var $encodeFields = Array("first_name", "last_name", "description");
97
98         // This is used to retrieve related fields from form posts.
99         var $additional_column_fields = Array('reports_to_name');
100
101
102
103         var $new_schema = true;
104
105         function Employee() {
106                 parent::Person();
107                 $this->setupCustomFields('Users');
108                 $this->emailAddress = new SugarEmailAddress();
109         }
110
111
112         function get_summary_text() {
113         $this->_create_proper_name_field();
114         return $this->name;
115     }
116
117
118         function fill_in_additional_list_fields() {
119                 $this->fill_in_additional_detail_fields();
120         }
121
122         function fill_in_additional_detail_fields()
123         {
124                 global $locale;
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") ;
127
128                 $row = $this->db->fetchByAssoc($result);
129                 $GLOBALS['log']->debug("additional detail query results: $row");
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         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');
177                 return $user_fields;
178         }
179
180         function list_view_parse_additional_sections(&$list_form, $xTemplateSection){
181                 return $list_form;
182         }
183
184
185         function create_export_query($order_by, $where) {
186                 include('modules/Employees/field_arrays.php');
187
188                 $cols = '';
189                 foreach($fields_array['Employee']['export_fields'] as $field) {
190                         $cols .= (empty($cols)) ? '' : ', ';
191                         $cols .= $field;
192                 }
193
194                 $query = "SELECT {$cols} FROM users ";
195
196                 $where_auto = " users.deleted = 0";
197
198                 if($where != "")
199                         $query .= " WHERE $where AND " . $where_auto;
200                 else
201                         $query .= " WHERE " . $where_auto;
202
203                 if($order_by != "")
204                         $query .= " ORDER BY $order_by";
205                 else
206                         $query .= " ORDER BY users.user_name";
207
208                 return $query;
209         }
210
211         //use parent class
212         /**
213          * Generate the name field from the first_name and last_name fields.
214          */
215         /*
216         function _create_proper_name_field() {
217         global $locale;
218         $full_name = $locale->getLocaleFormattedName($this->first_name, $this->last_name);
219         $this->name = $full_name;
220         $this->full_name = $full_name;
221         }
222         */
223
224         function preprocess_fields_on_save(){
225                 parent::preprocess_fields_on_save();
226
227         }
228
229
230     /**
231      * create_new_list_query
232      *
233      * Return the list query used by the list views and export button. Next generation of create_new_list_query function.
234      *
235      * 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
236      *
237      * @param string $order_by custom order by clause
238      * @param string $where custom where clause
239      * @param array $filter Optioanal
240      * @param array $params Optional     *
241      * @param int $show_deleted Optional, default 0, show deleted records is set to 1.
242      * @param string $join_type
243      * @param boolean $return_array Optional, default false, response as array
244      * @param object $parentbean creating a subquery for this bean.
245      * @param boolean $singleSelect Optional, default false.
246      * @return String select query string, optionally an array value will be returned if $return_array= true.
247      */
248     function create_new_list_query($order_by, $where, $filter=array(), $params=array(), $show_deleted=0, $join_type='', $return_array=false, $parentbean=null, $singleSelect=false)
249     {
250         //create the filter for portal only users, as they should not be showing up in query results
251         if(empty($where)){
252             $where = ' users.portal_only = 0 ';
253         }else{
254             $where .= ' and users.portal_only = 0 ';
255         }
256
257         //return parent method, specifying for array to be returned
258         return parent::create_new_list_query($order_by, $where, $filter,$params, $show_deleted, $join_type, $return_array, $parentbean, $singleSelect);
259     }
260 }
261
262 ?>