]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Activities/Popup_picker.php
Release 6.5.0
[Github/sugarcrm.git] / modules / Activities / Popup_picker.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-2012 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 require_once("include/upload_file.php");
40 require_once('include/utils/db_utils.php');
41
42 global $currentModule;
43
44 global $focus;
45 global $action;
46
47 global $app_strings;
48 global $app_list_strings;
49 //we don't want the parent module's string file, but rather the string file specifc to this subpanel
50 global $current_language,$beanList,$beanFiles;
51 $current_module_strings = return_module_language($current_language, 'Activities');
52
53 // history_list is the means of passing data to a SubPanelView.
54 $bean = $beanList[$_REQUEST['module_name']];
55 require_once($beanFiles[$bean]);
56 $focus = new $bean;
57
58 class Popup_Picker
59 {
60
61
62     /**
63     * sole constructor
64     */
65     function Popup_Picker() {
66     }
67
68     /**
69     *
70     */
71     function process_page() {
72         global $focus;
73         global $mod_strings;
74         global $app_strings;
75         global $app_list_strings;
76         global $currentModule;
77         global $odd_bg;
78         global $even_bg;
79
80         global $timedate;
81
82
83         $history_list = array();
84
85                 if(!empty($_REQUEST['record'])) {
86                         $result = $focus->retrieve($_REQUEST['record']);
87                 if($result == null)
88                 {
89                         sugar_die($app_strings['ERROR_NO_RECORD']);
90                 }
91                 }
92
93                 $activitiesRels = array('tasks' => 'Task', 'meetings' => 'Meeting', 'calls' => 'Call', 'emails' => 'Email', 'notes' => 'Note');
94                 //Setup the arrays to store the linked records.
95                 foreach($activitiesRels as $relMod => $beanName) {
96                 $varname = "focus_" . $relMod . "_list";
97                 $$varname = array();
98             }
99                 foreach($focus->get_linked_fields() as $field => $def) {
100                         if ($focus->load_relationship($field)) {
101                                 $relTable = $focus->$field->getRelatedTableName();
102                         if (in_array($relTable, array_keys($activitiesRels)))
103                         {
104                                 $varname = "focus_" . $relTable . "_list";
105                                 $$varname = sugarArrayMerge($$varname, $focus->get_linked_beans($field,$activitiesRels[$relTable]));
106                         }
107
108                         }
109                 }
110
111                 foreach ($focus_tasks_list as $task) {
112                         $sort_date_time='';
113                         if (empty($task->date_due) || $task->date_due == '0000-00-00') {
114                                 $date_due = '';
115                         }
116                         else {
117                                 $date_due = $task->date_due;
118                         }
119
120                         if ($task->status != "Not Started" && $task->status != "In Progress" && $task->status != "Pending Input") {
121                 $ts = '';
122                 if(!empty($task->fetched_row['date_due'])) {
123                     //tasks can have an empty date due field
124                     $ts = $timedate->fromDb($task->fetched_row['date_due'])->ts;
125                 }
126                                 $history_list[] = array('name' => $task->name,
127                                                                          'id' => $task->id,
128                                                                          'type' => "Task",
129                                                                          'direction' => '',
130                                                                          'module' => "Tasks",
131                                                                          'status' => $task->status,
132                                                                          'parent_id' => $task->parent_id,
133                                                                          'parent_type' => $task->parent_type,
134                                                                          'parent_name' => $task->parent_name,
135                                                                          'contact_id' => $task->contact_id,
136                                                                          'contact_name' => $task->contact_name,
137                                                                          'date_modified' => $date_due,
138                                                                          'description' => $this->getTaskDetails($task),
139                                                                          'date_type' => $app_strings['DATA_TYPE_DUE'],
140                                                                          'sort_value' => $ts,
141                                                                          );
142                         } else {
143                                 $open_activity_list[] = array('name' => $task->name,
144                                                                          'id' => $task->id,
145                                                                          'type' => "Task",
146                                                                          'direction' => '',
147                                                                          'module' => "Tasks",
148                                                                          'status' => $task->status,
149                                                                          'parent_id' => $task->parent_id,
150                                                                          'parent_type' => $task->parent_type,
151                                                                          'parent_name' => $task->parent_name,
152                                                                          'contact_id' => $task->contact_id,
153                                                                          'contact_name' => $task->contact_name,
154                                                                          'date_due' => $date_due,
155                                                                          'description' => $this->getTaskDetails($task),
156                                                                          'date_type' => $app_strings['DATA_TYPE_DUE']
157                                                                          );
158                         }
159                 } // end Tasks
160
161                 foreach ($focus_meetings_list as $meeting) {
162
163                         if (empty($meeting->contact_id) && empty($meeting->contact_name)) {
164                                 $meeting_contacts = $meeting->get_linked_beans('contacts','Contact');
165                                 if (!empty($meeting_contacts[0]->id) && !empty($meeting_contacts[0]->name)) {
166                                         $meeting->contact_id = $meeting_contacts[0]->id;
167                                         $meeting->contact_name = $meeting_contacts[0]->name;
168                                 }
169                         }
170                         if ($meeting->status != "Planned") {
171                                 $history_list[] = array('name' => $meeting->name,
172                                                                          'id' => $meeting->id,
173                                                                          'type' => "Meeting",
174                                                                          'direction' => '',
175                                                                          'module' => "Meetings",
176                                                                          'status' => $meeting->status,
177                                                                          'parent_id' => $meeting->parent_id,
178                                                                          'parent_type' => $meeting->parent_type,
179                                                                          'parent_name' => $meeting->parent_name,
180                                                                          'contact_id' => $meeting->contact_id,
181                                                                          'contact_name' => $meeting->contact_name,
182                                                                          'date_modified' => $meeting->date_start,
183                                                                          'description' => $this->formatDescription($meeting->description),
184                                                                          'date_type' => $app_strings['DATA_TYPE_START'],
185                                                                          'sort_value' => $timedate->fromDb($meeting->fetched_row['date_start'])->ts,
186                                                                          );
187                         } else {
188                                 $open_activity_list[] = array('name' => $meeting->name,
189                                                                          'id' => $meeting->id,
190                                                                          'type' => "Meeting",
191                                                                          'direction' => '',
192                                                                          'module' => "Meetings",
193                                                                          'status' => $meeting->status,
194                                                                          'parent_id' => $meeting->parent_id,
195                                                                          'parent_type' => $meeting->parent_type,
196                                                                          'parent_name' => $meeting->parent_name,
197                                                                          'contact_id' => $meeting->contact_id,
198                                                                          'contact_name' => $meeting->contact_name,
199                                                                          'date_due' => $meeting->date_start,
200                                                                          'description' => $this->formatDescription($meeting->description),
201                                                                          'date_type' => $app_strings['DATA_TYPE_START']
202                                                                          );
203                         }
204                 } // end Meetings
205
206                 foreach ($focus_calls_list as $call) {
207
208                         if (empty($call->contact_id) && empty($call->contact_name)) {
209                                 $call_contacts = $call->get_linked_beans('contacts','Contact');
210                                 if (!empty($call_contacts[0]->id) && !empty($call_contacts[0]->name)) {
211                                         $call->contact_id = $call_contacts[0]->id;
212                                         $call->contact_name = $call_contacts[0]->name;
213                                 }
214                         }
215
216                         if ($call->status != "Planned") {
217                                 $history_list[] = array('name' => $call->name,
218                                                                          'id' => $call->id,
219                                                                          'type' => "Call",
220                                                                          'direction' => $call->direction,
221                                                                          'module' => "Calls",
222                                                                          'status' => $call->status,
223                                                                          'parent_id' => $call->parent_id,
224                                                                          'parent_type' => $call->parent_type,
225                                                                          'parent_name' => $call->parent_name,
226                                                                          'contact_id' => $call->contact_id,
227                                                                          'contact_name' => $call->contact_name,
228                                                                          'date_modified' => $call->date_start,
229                                                                          'description' => $this->formatDescription($call->description),
230                                                                          'date_type' => $app_strings['DATA_TYPE_START'],
231                                                                          'sort_value' => $timedate->fromDb($call->fetched_row['date_start'])->ts,
232                                                                          );
233                         } else {
234                                 $open_activity_list[] = array('name' => $call->name,
235                                                                          'id' => $call->id,
236                                                                          'direction' => $call->direction,
237                                                                          'type' => "Call",
238                                                                          'module' => "Calls",
239                                                                          'status' => $call->status,
240                                                                          'parent_id' => $call->parent_id,
241                                                                          'parent_type' => $call->parent_type,
242                                                                          'parent_name' => $call->parent_name,
243                                                                          'contact_id' => $call->contact_id,
244                                                                          'contact_name' => $call->contact_name,
245                                                                          'date_due' => $call->date_start,
246                                                                          'description' => $this->formatDescription($call->description),
247                                                                          'date_type' => $app_strings['DATA_TYPE_START']
248                                                                          );
249                         }
250                 } // end Calls
251
252                 foreach ($focus_emails_list as $email) {
253
254                         if (empty($email->contact_id) && empty($email->contact_name)) {
255                                 $email_contacts = $email->get_linked_beans('contacts','Contact');
256                                 if (!empty($email_contacts[0]->id) && !empty($email_contacts[0]->name)) {
257                                         $email->contact_id = $email_contacts[0]->id;
258                                         $email->contact_name = $email_contacts[0]->name;
259                                 }
260                         }
261                         $history_list[] = array('name' => $email->name,
262                                                                          'id' => $email->id,
263                                                                          'type' => "Email",
264                                                                          'direction' => '',
265                                                                          'module' => "Emails",
266                                                                          'status' => '',
267                                                                          'parent_id' => $email->parent_id,
268                                                                          'parent_type' => $email->parent_type,
269                                                                          'parent_name' => $email->parent_name,
270                                                                          'contact_id' => $email->contact_id,
271                                                                          'contact_name' => $email->contact_name,
272                                                                          'date_modified' => $email->date_start." ".$email->time_start,
273                                                                          'description' => $this->getEmailDetails($email),
274                                                                          'date_type' => $app_strings['DATA_TYPE_SENT'],
275                                                                          'sort_value' => $timedate->fromDb($email->fetched_row['date_sent'])->ts,
276                                                                          );
277                 } //end Emails
278
279         // Bug 46439 'No email archived when clicking on View Summary' (All condition)
280         if (method_exists($focus,'get_unlinked_email_query'))
281         {
282             $queryArray = $focus->get_unlinked_email_query(array('return_as_array'=>'true'));
283             $query = $queryArray['select'];
284             $query .= $queryArray['from'];
285             if (!empty($queryArray['join_tables']))
286             {
287                 foreach ($queryArray['join_tables'] as $join_table)
288                 {
289                     if ($join_table != '')
290                     {
291                         $query .= ', '.$join_table.' ';
292                     }
293                 }
294             }
295             $query .= $queryArray['join'];
296             $query .= $queryArray['where'];
297             $emails = new Email();
298             $focus_unlinked_emails_list = $emails->process_list_query($query, 0);
299             $focus_unlinked_emails_list = $focus_unlinked_emails_list['list'];
300             foreach ($focus_unlinked_emails_list as $email)
301             {
302                 $email->retrieve($email->id);
303                 $history_list[] = array(
304                     'name' => $email->name,
305                     'id' => $email->id,
306                     'type' => "Email",
307                     'direction' => '',
308                     'module' => "Emails",
309                     'status' => '',
310                     'parent_id' => $email->parent_id,
311                     'parent_type' => $email->parent_type,
312                     'parent_name' => $email->parent_name,
313                     'contact_id' => $email->contact_id,
314                     'contact_name' => $email->contact_name,
315                     'date_modified' => $email->date_start." ".$email->time_start,
316                     'description' => $this->getEmailDetails($email),
317                     'date_type' => $app_strings['DATA_TYPE_SENT'],
318                     'sort_value' => strtotime($email->fetched_row['date_sent'].' GMT'),
319                 );
320             }
321         } //end Unlinked Emails
322
323                 foreach ($focus_notes_list as $note)
324         {
325                         if ($note->ACLAccess('view'))
326             {
327                 $history_list[] = array('name' => $note->name,
328                                          'id' => $note->id,
329                                          'type' => "Note",
330                                          'direction' => '',
331                                          'module' => "Notes",
332                                          'status' => '',
333                                          'parent_id' => $note->parent_id,
334                                          'parent_type' => $note->parent_type,
335                                          'parent_name' => $note->parent_name,
336                                          'contact_id' => $note->contact_id,
337                                          'contact_name' => $note->contact_name,
338                                          'date_modified' => $note->date_modified,
339                                          'description' => $this->formatDescription($note->description),
340                                          'date_type' => $app_strings['DATA_TYPE_MODIFIED'],
341                                          'sort_value' => strtotime($note->fetched_row['date_modified'].' GMT'),
342                                          );
343                 if(!empty($note->filename))
344                 {
345                     $count = count($history_list);
346                     $count--;
347                     $history_list[$count]['filename'] = $note->filename;
348                     $history_list[$count]['fileurl'] = UploadFile::get_url($note->filename,$note->id);
349                 }
350             }
351
352                 } // end Notes
353
354         $xtpl=new XTemplate ('modules/Activities/Popup_picker.html');
355
356         $xtpl->assign('MOD', $mod_strings);
357         $xtpl->assign('APP', $app_strings);
358         insert_popup_header();
359
360         //output header
361         echo "<table width='100%' cellpadding='0' cellspacing='0'><tr><td>";
362         echo getClassicModuleTitle($focus->module_dir, array(translate('LBL_MODULE_NAME', $focus->module_dir),$focus->name), false);
363         echo "</td><td align='right' class='moduleTitle'>";
364         echo "<A href='javascript:print();' class='utilsLink'>" . SugarThemeRegistry::current()->getImage('print', "border='0' align='absmiddle'", 13, 13, ".gif", $app_strings['LNK_PRINT']) . "</a>&nbsp;<A href='javascript:print();' class='utilsLink'>".$app_strings['LNK_PRINT']."</A>\n";
365         echo "</td></tr></table>";
366
367         $oddRow = true;
368         if (count($history_list) > 0) $history_list = array_csort($history_list, 'sort_value', SORT_DESC);
369         foreach($history_list as $activity)
370         {
371             $activity_fields = array(
372                 'ID' => $activity['id'],
373                 'NAME' => $activity['name'],
374                 'MODULE' => $activity['module'],
375                 'CONTACT_NAME' => $activity['contact_name'],
376                 'CONTACT_ID' => $activity['contact_id'],
377                 'PARENT_TYPE' => $activity['parent_type'],
378                 'PARENT_NAME' => $activity['parent_name'],
379                 'PARENT_ID' => $activity['parent_id'],
380                 'DATE' => $activity['date_modified'],
381                 'DESCRIPTION' => $activity['description'],
382                 'DATE_TYPE' => $activity['date_type']
383             );
384             if (empty($activity['direction'])) {
385                 $activity_fields['TYPE'] = $app_list_strings['activity_dom'][$activity['type']];
386             }
387             else {
388                 $activity_fields['TYPE'] = $app_list_strings['call_direction_dom'][$activity['direction']].' '.$app_list_strings['activity_dom'][$activity['type']];
389             }
390
391             switch ($activity['type']) {
392                 case 'Call':
393                     $activity_fields['STATUS'] = $app_list_strings['call_status_dom'][$activity['status']];
394                     break;
395                 case 'Meeting':
396                     $activity_fields['STATUS'] = $app_list_strings['meeting_status_dom'][$activity['status']];
397                     break;
398                 case 'Task':
399                     $activity_fields['STATUS'] = $app_list_strings['task_status_dom'][$activity['status']];
400                     break;
401             }
402
403             if (isset($activity['location'])) $activity_fields['LOCATION'] = $activity['location'];
404             if (isset($activity['filename'])) {
405                 $activity_fields['ATTACHMENT'] = "<a href='index.php?entryPoint=download&id=".$activity['id']."&type=Notes' target='_blank'>".SugarThemeRegistry::current()->getImage("attachment","border='0' align='absmiddle'",null,null,'.gif',$activity['filename'])."</a>";
406             }
407
408             if (isset($activity['parent_type'])) $activity_fields['PARENT_MODULE'] = $activity['parent_type'];
409
410             $xtpl->assign("ACTIVITY", $activity_fields);
411             $xtpl->assign("ACTIVITY_MODULE_PNG", SugarThemeRegistry::current()->getImage($activity_fields['MODULE'].'','border="0"', null,null,'.gif',$activity_fields['NAME']));
412
413             if($oddRow)
414             {
415                 //todo move to themes
416                 $xtpl->assign("ROW_COLOR", 'oddListRow');
417                 $xtpl->assign("BG_COLOR", $odd_bg);
418             }
419             else
420             {
421                 //todo move to themes
422                 $xtpl->assign("ROW_COLOR", 'evenListRow');
423                 $xtpl->assign("BG_COLOR", $even_bg);
424             }
425             $oddRow = !$oddRow;
426             if(!empty($activity_fields['DESCRIPTION'])) {
427                 $xtpl->parse("history.row.description");
428             }
429             $xtpl->parse("history.row");
430         // Put the rows in.
431 }
432                 $xtpl->parse("history");
433                 $xtpl->out("history");
434                 insert_popup_footer();
435         }
436
437         function getEmailDetails($email){
438                 $details = "";
439
440                 if(!empty($email->to_addrs)){
441                         $details .= "To: ".$email->to_addrs."<br>";
442                 }
443                 if(!empty($email->from_addr)){
444                         $details .= "From: ".$email->from_addr."<br>";
445                 }
446                 if(!empty($email->cc_addrs)){
447                         $details .= "CC: ".$email->cc_addrs."<br>";
448                 }
449                 if(!empty($email->from_addr) || !empty($email->cc_addrs) || !empty($email->to_addrs)){
450                         $details .= "<br>";
451                 }
452
453                 // cn: bug 8433 - history does not distinguish b/t text/html emails
454                 $details .= empty($email->description_html)
455                         ? $this->formatDescription($email->description)
456                         : $this->formatDescription(strip_tags(br2nl(from_html($email->description_html))));
457
458                 return $details;
459         }
460
461         function getTaskDetails($task){
462                 global $app_strings;
463
464                 $details = "";
465                 if (!empty($task->date_start) && $task->date_start != '0000-00-00') {
466                         $details .= $app_strings['DATA_TYPE_START'].$task->date_start."<br>";
467                         $details .= "<br>";
468                 }
469                 $details .= $this->formatDescription($task->description);
470
471                 return $details;
472         }
473
474         function formatDescription($description){
475                 return nl2br($description);
476         }
477 } // end of class Popup_Picker
478 ?>