]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Tasks/Task.php
Release 6.1.4
[Github/sugarcrm.git] / modules / Tasks / Task.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM 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
48
49
50
51
52 // Task is used to store customer information.
53 class Task extends SugarBean {
54         var $field_name_map;
55
56         // Stored fields
57         var $id;
58         var $date_entered;
59         var $date_modified;
60         var $assigned_user_id;
61         var $modified_user_id;
62         var $created_by;
63         var $created_by_name;
64         var $modified_by_name;
65         var $description;
66         var $name;
67         var $status;
68         var $date_due_flag;
69         var $date_due;
70         var $time_due;
71         var $date_start_flag;
72         var $date_start;
73         var $time_start;
74         var $priority;
75         var $parent_type;
76         var $parent_id;
77         var $contact_id;
78
79         var $parent_name;
80         var $contact_name;
81         var $contact_phone;
82         var $contact_email;
83         var $assigned_user_name;
84
85 //bug 28138 todo
86 //      var $default_task_name_values = array('Assemble catalogs', 'Make travel arrangements', 'Send a letter', 'Send contract', 'Send fax', 'Send a follow-up letter', 'Send literature', 'Send proposal', 'Send quote', 'Call to schedule meeting', 'Setup evaluation', 'Get demo feedback', 'Arrange introduction', 'Escalate support request', 'Close out support request', 'Ship product', 'Arrange reference call', 'Schedule training', 'Send local user group information', 'Add to mailing list');
87
88         var $table_name = "tasks";
89
90         var $object_name = "Task";
91         var $module_dir = 'Tasks';
92
93         var $importable = true;
94         // This is used to retrieve related fields from form posts.
95         var $additional_column_fields = Array('assigned_user_name', 'assigned_user_id', 'contact_name', 'contact_phone', 'contact_email', 'parent_name');
96
97
98         function Task() {
99                 parent::SugarBean();
100         }
101
102         var $new_schema = true;
103
104     function save($check_notify = FALSE)
105     {
106         if (empty($this->status) ) {
107             $mod_strings = return_module_language($GLOBALS['current_language'], $this->module_dir);
108             $this->status = $mod_strings['LBL_DEFAULT_STATUS'];
109         }
110         return parent::save($check_notify);
111     }
112
113         function get_summary_text()
114         {
115                 return "$this->name";
116         }
117
118     function create_export_query(&$order_by, &$where, $relate_link_join='')
119     {
120         $custom_join = $this->custom_fields->getJOIN(true, true,$where);
121                 if($custom_join)
122                                 $custom_join['join'] .= $relate_link_join;
123                 $contact_required = stristr($where,"contacts");
124                 if($contact_required)
125                 {
126                         $query = "SELECT tasks.*, contacts.first_name, contacts.last_name";
127                         if($custom_join){
128                                                         $query .= $custom_join['select'];
129                                                 }
130                         $query .= " FROM contacts, tasks ";
131                         $where_auto = "tasks.contact_id = contacts.id AND tasks.deleted=0 AND contacts.deleted=0";
132                 }
133                 else
134                 {
135                         $query = 'SELECT tasks.*';
136                         if($custom_join){
137                                                         $query .= $custom_join['select'];
138                                                 }
139                         $query .= ' FROM tasks ';
140                         $where_auto = "tasks.deleted=0";
141                 }
142
143
144                                 if($custom_join){
145                                         $query .= $custom_join['join'];
146                                 }
147
148                 if($where != "")
149                         $query .= "where $where AND ".$where_auto;
150                 else
151                         $query .= "where ".$where_auto;
152
153                 if($order_by != "")
154                         $query .=  " ORDER BY ". $this->process_order_by($order_by, null);
155                 else
156                         $query .= " ORDER BY tasks.name";
157                 return $query;
158
159         }
160
161
162
163         function fill_in_additional_list_fields()
164         {
165
166         }
167
168         function fill_in_additional_detail_fields()
169         {
170         parent::fill_in_additional_detail_fields();
171                 global $app_strings;
172
173                 if (isset($this->contact_id)) {
174
175                         $contact = new Contact();
176                         $contact->retrieve($this->contact_id);
177
178                         if($contact->id != "") {
179                                 $this->contact_name = $contact->full_name;
180                                 $this->contact_name_owner = $contact->assigned_user_id;
181                                 $this->contact_name_mod = 'Contacts';
182                                 $this->contact_phone = $contact->phone_work;
183                                 $this->contact_email = $contact->emailAddress->getPrimaryAddress($contact);
184                         } else {
185                                 $this->contact_name_mod = '';
186                                 $this->contact_name_owner = '';
187                                 $this->contact_name='';
188                                 $this->contact_email = '';
189                                 $this->contact_id='';
190                         }
191
192                 }
193
194                 $this->fill_in_additional_parent_fields();
195         }
196
197         function fill_in_additional_parent_fields()
198         {
199
200                 $this->parent_name = '';
201                 global $app_strings, $beanFiles, $beanList, $locale;
202                 if ( ! isset($beanList[$this->parent_type]))
203                 {
204                         $this->parent_name = '';
205                         return;
206                 }
207
208             $beanType = $beanList[$this->parent_type];
209                 require_once($beanFiles[$beanType]);
210                 $parent = new $beanType();
211
212                 if (is_subclass_of($parent, 'Person')) {
213                         $query = "SELECT first_name, last_name, assigned_user_id parent_name_owner from $parent->table_name where id = '$this->parent_id'";
214                 }
215                 else if (is_subclass_of($parent, 'File')) {
216                         $query = "SELECT document_name, assigned_user_id parent_name_owner from $parent->table_name where id = '$this->parent_id'";
217                 }
218                 else {
219
220                         $query = "SELECT name ";
221                         if(isset($parent->field_defs['assigned_user_id'])){
222                                 $query .= " , assigned_user_id parent_name_owner ";
223                         }else{
224                                 $query .= " , created_by parent_name_owner ";
225                         }
226                         $query .= " from $parent->table_name where id = '$this->parent_id'";
227                 }
228                 $result = $this->db->query($query,true," Error filling in additional detail fields: ");
229
230                 // Get the id and the name.
231                 $row = $this->db->fetchByAssoc($result);
232
233                 if ($row && !empty($row['parent_name_owner'])){
234                         $this->parent_name_owner = $row['parent_name_owner'];
235                         $this->parent_name_mod = $this->parent_type;
236                 }
237                 if (is_subclass_of($parent, 'Person') and $row != null)
238                 {
239                         $this->parent_name = $locale->getLocaleFormattedName(stripslashes($row['first_name']), stripslashes($row['last_name']));
240                 }
241                 else if (is_subclass_of($parent, 'File') && $row != null) {
242                         $this->parent_name = $row['document_name'];
243                 }
244                 elseif($row != null)
245                 {
246                         $this->parent_name = stripslashes($row['name']);
247                 }
248                 else {
249                         $this->parent_name = '';
250                 }
251         }
252
253
254
255
256         function get_list_view_data(){
257                 global $action, $currentModule, $focus, $current_module_strings, $app_list_strings, $timedate;
258
259                 $today = $timedate->handle_offset(date($GLOBALS['timedate']->get_db_date_time_format(), time()), $timedate->dbDayFormat, true);
260                 $task_fields = $this->get_list_view_array();
261                 $dbtime = $timedate->to_db($task_fields['DATE_DUE']);
262         $task_fields['TIME_DUE'] = $timedate->to_display_time($dbtime);
263         $task_fields['DATE_DUE'] = $timedate->to_display_date($dbtime);
264
265         $date_due = $task_fields['DATE_DUE'];
266
267                 if (!empty($this->priority))
268                         $task_fields['PRIORITY'] = $app_list_strings['task_priority_dom'][$this->priority];
269                 if (isset($this->parent_type))
270                         $task_fields['PARENT_MODULE'] = $this->parent_type;
271                 if ($this->status != "Completed" && $this->status != "Deferred" ) 
272                 {
273                         $setCompleteUrl = "<a onclick='SUGAR.util.closeActivityPanel.show(\"{$this->module_dir}\",\"{$this->id}\",\"Completed\",\"listview\",\"1\");'>";
274                     $task_fields['SET_COMPLETE'] = $setCompleteUrl . SugarThemeRegistry::current()->getImage("close_inline","title=".translate('LBL_LIST_CLOSE','Tasks')." border='0'")."</a>";
275                 }
276
277         $dd = $timedate->to_db_date($date_due, false);
278                 if ($dd < $today){
279                         $task_fields['DATE_DUE']= "<font class='overdueTask'>".$date_due."</font>";
280                 }else if( $dd   == $today ){
281                         $task_fields['DATE_DUE'] = "<font class='todaysTask'>".$date_due."</font>";
282                 }else{
283                         $task_fields['DATE_DUE'] = "<font class='futureTask'>".$date_due."</font>";
284                 }
285
286                 $task_fields['CONTACT_NAME']= $this->contact_name;
287                 $task_fields['TITLE'] = '';
288                 if (!empty($task_fields['CONTACT_NAME'])) {
289                         $task_fields['TITLE'] .= $current_module_strings['LBL_LIST_CONTACT'].": ".$task_fields['CONTACT_NAME'];
290                 }
291                 if (!empty($this->parent_name)) {
292                         $task_fields['TITLE'] .= "\n".$app_list_strings['record_type_display_notes'][$this->parent_type].": ".$this->parent_name;
293                         $task_fields['PARENT_NAME']=$this->parent_name;
294                 }
295
296                 return $task_fields;
297         }
298
299         function set_notification_body($xtpl, $task)
300         {
301                 global $app_list_strings;
302         global $timedate;
303         $notifyUser = $task->current_notify_user;
304         $prefDate = $notifyUser->getUserDateTimePreferences();
305                 $xtpl->assign("TASK_SUBJECT", $task->name);
306                 //MFH #13507
307                 $xtpl->assign("TASK_PRIORITY", (isset($task->priority)?$app_list_strings['task_priority_dom'][$task->priority]:""));
308                 $xtpl->assign("TASK_DUEDATE", $timedate->to_display_date_time($task->date_due . " " . $task->time_due,true,true,$notifyUser)." ".$prefDate['userGmt']);
309                 $xtpl->assign("TASK_STATUS", (isset($task->status)?$app_list_strings['task_status_dom'][$task->status]:""));
310                 $xtpl->assign("TASK_DESCRIPTION", $task->description);
311
312                 return $xtpl;
313         }
314
315         function bean_implements($interface){
316                 switch($interface){
317                         case 'ACL':return true;
318                 }
319                 return false;
320         }
321         function listviewACLHelper(){
322                 $array_assign = parent::listviewACLHelper();
323                 $is_owner = false;
324                 if(!empty($this->parent_name)){
325                         if(!empty($this->parent_name_owner)){
326                                 global $current_user;
327                                 $is_owner = $current_user->id == $this->parent_name_owner;
328                         }
329                 }
330
331                         if(!ACLController::moduleSupportsACL($this->parent_type) || ACLController::checkAccess($this->parent_type, 'view', $is_owner)){
332                                 $array_assign['PARENT'] = 'a';
333                         }else{
334                                 $array_assign['PARENT'] = 'span';
335                         }
336                 $is_owner = false;
337                 if(!empty($this->contact_name)){
338                         if(!empty($this->contact_name_owner)){
339                                 global $current_user;
340                                 $is_owner = $current_user->id == $this->contact_name_owner;
341                         }
342                 }
343
344                 if( ACLController::checkAccess('Contacts', 'view', $is_owner)){
345                                 $array_assign['CONTACT'] = 'a';
346                 }else{
347                                 $array_assign['CONTACT'] = 'span';
348                 }
349
350                 return $array_assign;
351         }
352
353 }
354 ?>