]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Activities/Popup_picker.php
Release 6.1.4
[Github/sugarcrm.git] / modules / Activities / Popup_picker.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
41
42
43 require_once("include/upload_file.php");
44
45 require_once('include/utils/db_utils.php');
46
47 global $currentModule;
48
49 global $focus;
50 global $action;
51
52 global $app_strings;
53 global $app_list_strings;
54 //we don't want the parent module's string file, but rather the string file specifc to this subpanel
55 global $current_language,$beanList,$beanFiles;
56 $current_module_strings = return_module_language($current_language, 'Activities');
57
58 // history_list is the means of passing data to a SubPanelView.
59 $bean = $beanList[$_REQUEST['module_name']];
60 require_once($beanFiles[$bean]);
61 $focus = new $bean;
62
63 class Popup_Picker
64 {
65
66
67         /**
68          * sole constructor
69          */
70         function Popup_Picker() {
71         }
72
73         /**
74          *
75          */
76         function process_page() {
77                 global $focus;
78                 global $mod_strings;
79                 global $app_strings;
80                 global $app_list_strings;
81                 global $currentModule;
82                 global $odd_bg;
83                 global $even_bg;
84                 
85                 global $timedate;
86                 
87
88                 $history_list = array();
89
90                 if(!empty($_REQUEST['record'])) {
91                         $result = $focus->retrieve($_REQUEST['record']);
92                 if($result == null)
93                 {
94                         sugar_die($app_strings['ERROR_NO_RECORD']);
95                 }
96                 }
97
98                 $activitiesRels = array('tasks' => 'Task', 'meetings' => 'Meeting', 'calls' => 'Call', 'emails' => 'Email', 'notes' => 'Note');
99                 //Setup the arrays to store the linked records.
100                 foreach($activitiesRels as $relMod => $beanName) {
101                 $varname = "focus_" . $relMod . "_list";
102                 $$varname = array();
103             }
104                 foreach($focus->get_linked_fields() as $field => $def) {
105                         if ($focus->load_relationship($field)) {
106                                 $relTable = $focus->$field->getRelatedTableName();
107                         if (in_array($relTable, array_keys($activitiesRels))) 
108                         {
109                                 $varname = "focus_" . $relTable . "_list";
110                                 $$varname = sugarArrayMerge($$varname, $focus->get_linked_beans($field,$activitiesRels[$relTable]));
111                         }
112                         
113                         }
114                 }
115
116                 foreach ($focus_tasks_list as $task) {
117                         $sort_date_time='';
118                         if (empty($task->date_due) || $task->date_due == '0000-00-00') {
119                                 $date_due = '';
120                         }
121                         else {
122                                 $date_due = $task->date_due;
123                         }
124
125                         if ($task->status != "Not Started" && $task->status != "In Progress" && $task->status != "Pending Input") {
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' => strtotime($task->fetched_row['date_due'].' GMT'),
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' => strtotime($meeting->fetched_row['date_start'].' GMT'),
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                         if ($call->status != "Planned") {
216                                 $history_list[] = array('name' => $call->name,
217                                                                          'id' => $call->id,
218                                                                          'type' => "Call",
219                                                                          'direction' => $call->direction,
220                                                                          'module' => "Calls",
221                                                                          'status' => $call->status,
222                                                                          'parent_id' => $call->parent_id,
223                                                                          'parent_type' => $call->parent_type,
224                                                                          'parent_name' => $call->parent_name,
225                                                                          'contact_id' => $call->contact_id,
226                                                                          'contact_name' => $call->contact_name,
227                                                                          'date_modified' => $call->date_start,
228                                                                          'description' => $this->formatDescription($call->description),
229                                                                          'date_type' => $app_strings['DATA_TYPE_START'],
230                                                                          'sort_value' => strtotime($call->fetched_row['date_start'].' GMT'),
231                                                                          );
232                         } else {
233                                 $open_activity_list[] = array('name' => $call->name,
234                                                                          'id' => $call->id,
235                                                                          'direction' => $call->direction,
236                                                                          'type' => "Call",
237                                                                          'module' => "Calls",
238                                                                          'status' => $call->status,
239                                                                          'parent_id' => $call->parent_id,
240                                                                          'parent_type' => $call->parent_type,
241                                                                          'parent_name' => $call->parent_name,
242                                                                          'contact_id' => $call->contact_id,
243                                                                          'contact_name' => $call->contact_name,
244                                                                          'date_due' => $call->date_start,
245                                                                          'description' => $this->formatDescription($call->description),
246                                                                          'date_type' => $app_strings['DATA_TYPE_START']
247                                                                          );
248                         }
249                 } // end Calls
250
251                 foreach ($focus_emails_list as $email) {
252                         
253                         if (empty($email->contact_id) && empty($email->contact_name)) {
254                                 $email_contacts = $email->get_linked_beans('contacts','Contact');
255                                 if (!empty($email_contacts[0]->id) && !empty($email_contacts[0]->name)) {
256                                         $email->contact_id = $email_contacts[0]->id;
257                                         $email->contact_name = $email_contacts[0]->name;
258                                 }
259                         }
260                         $history_list[] = array('name' => $email->name,
261                                                                          'id' => $email->id,
262                                                                          'type' => "Email",
263                                                                          'direction' => '',
264                                                                          'module' => "Emails",
265                                                                          'status' => '',
266                                                                          'parent_id' => $email->parent_id,
267                                                                          'parent_type' => $email->parent_type,
268                                                                          'parent_name' => $email->parent_name,
269                                                                          'contact_id' => $email->contact_id,
270                                                                          'contact_name' => $email->contact_name,
271                                                                          'date_modified' => $email->date_start." ".$email->time_start,
272                                                                          'description' => $this->getEmailDetails($email),
273                                                                          'date_type' => $app_strings['DATA_TYPE_SENT'],
274                                                                          'sort_value' => strtotime($email->fetched_row['date_sent'].' GMT'),
275                                                                          );
276                 } //end Emails
277
278                 foreach ($focus_notes_list as $note) {
279                         
280                         $history_list[] = array('name' => $note->name,
281                                                                          'id' => $note->id,
282                                                                          'type' => "Note",
283                                                                          'direction' => '',
284                                                                          'module' => "Notes",
285                                                                          'status' => '',
286                                                                          'parent_id' => $note->parent_id,
287                                                                          'parent_type' => $note->parent_type,
288                                                                          'parent_name' => $note->parent_name,
289                                                                          'contact_id' => $note->contact_id,
290                                                                          'contact_name' => $note->contact_name,
291                                                                          'date_modified' => $note->date_modified,
292                                                                          'description' => $this->formatDescription($note->description),
293                                                                          'date_type' => $app_strings['DATA_TYPE_MODIFIED'],
294                                                                          'sort_value' => strtotime($note->fetched_row['date_modified'].' GMT'),
295                                                                          );
296                         if(!empty($note->filename)) {
297                                 $count = count($history_list);
298                                 $count--;
299                                 $history_list[$count]['filename'] = $note->filename;
300                                 $history_list[$count]['fileurl'] = UploadFile::get_url($note->filename,$note->id);
301                         }
302                 } // end Notes
303
304                 $xtpl=new XTemplate ('modules/Activities/Popup_picker.html');
305                 
306                 $xtpl->assign('MOD', $mod_strings);
307                 $xtpl->assign('APP', $app_strings);
308                 insert_popup_header();
309
310                 //output header
311                 echo "<table width='100%' cellpadding='0' cellspacing='0'><tr><td>";
312                 echo get_module_title($focus->module_dir, translate('LBL_MODULE_NAME', $focus->module_dir).": ".$focus->name, false);
313                 echo "</td><td align='right' class='moduleTitle'>";
314                 echo "<A href='javascript:print();' class='utilsLink'><img src='".SugarThemeRegistry::current()->getImageURL("print.gif")."' width='13' height='13' alt='".$app_strings['LNK_PRINT']."' border='0' align='absmiddle'></a>&nbsp;<A href='javascript:print();' class='utilsLink'>".$app_strings['LNK_PRINT']."</A>\n";
315                 echo "</td></tr></table>";
316
317                 $oddRow = true;
318                 if (count($history_list) > 0) $history_list = array_csort($history_list, 'sort_value', SORT_DESC);
319                 foreach($history_list as $activity)
320                 {
321                         $activity_fields = array(
322                                 'ID' => $activity['id'],
323                                 'NAME' => $activity['name'],
324                                 'MODULE' => $activity['module'],
325                                 'CONTACT_NAME' => $activity['contact_name'],
326                                 'CONTACT_ID' => $activity['contact_id'],
327                                 'PARENT_TYPE' => $activity['parent_type'],
328                                 'PARENT_NAME' => $activity['parent_name'],
329                                 'PARENT_ID' => $activity['parent_id'],
330                                 'DATE' => $activity['date_modified'],
331                                 'DESCRIPTION' => $activity['description'],
332                                 'DATE_TYPE' => $activity['date_type']
333                         );
334                         if (empty($activity['direction'])) {
335                                 $activity_fields['TYPE'] = $app_list_strings['activity_dom'][$activity['type']];
336                         }
337                         else {
338                                 $activity_fields['TYPE'] = $app_list_strings['call_direction_dom'][$activity['direction']].' '.$app_list_strings['activity_dom'][$activity['type']];
339                         }
340
341                         switch ($activity['type']) {
342                                 case 'Call':
343                                         $activity_fields['STATUS'] = $app_list_strings['call_status_dom'][$activity['status']];
344                                         break;
345                                 case 'Meeting':
346                                         $activity_fields['STATUS'] = $app_list_strings['meeting_status_dom'][$activity['status']];
347                                         break;
348                                 case 'Task':
349                                         $activity_fields['STATUS'] = $app_list_strings['task_status_dom'][$activity['status']];
350                                         break;
351                         }
352
353                         if (isset($activity['location'])) $activity_fields['LOCATION'] = $activity['location'];
354                         if (isset($activity['filename'])) {
355                                 $activity_fields['ATTACHMENT'] = "<a href='index.php?entryPoint=download&id=".$activity['id']."&type=Notes' target='_blank'>".SugarThemeRegistry::current()->getImage("attachment","alt='".$activity['filename']."' border='0' align='absmiddle'")."</a>";
356                         }
357
358                         if (isset($activity['parent_type'])) $activity_fields['PARENT_MODULE'] = $activity['parent_type'];
359
360                         $xtpl->assign("ACTIVITY", $activity_fields);
361                         $xtpl->assign("ACTIVITY_MODULE_PNG", SugarThemeRegistry::current()->getImage($activity_fields['MODULE'].'','border="0" alt="'.$activity_fields['NAME'].'"'));
362
363                         if($oddRow)
364                         {
365                         //todo move to themes
366                                 $xtpl->assign("ROW_COLOR", 'oddListRow');
367                                 $xtpl->assign("BG_COLOR", $odd_bg);
368                 }
369                 else
370                 {
371                         //todo move to themes
372                                 $xtpl->assign("ROW_COLOR", 'evenListRow');
373                                 $xtpl->assign("BG_COLOR", $even_bg);
374                 }
375                         $oddRow = !$oddRow;
376
377                         $xtpl->parse("history.row");
378                 // Put the rows in.
379 }
380
381                 $xtpl->parse("history");
382                 $xtpl->out("history");
383                 insert_popup_footer();
384         }
385
386         function getEmailDetails($email){
387                 $details = "";
388
389                 if(!empty($email->to_addrs)){
390                         $details .= "To: ".$email->to_addrs."<br>";
391                 }
392                 if(!empty($email->from_addr)){
393                         $details .= "From: ".$email->from_addr."<br>";
394                 }
395                 if(!empty($email->cc_addrs)){
396                         $details .= "CC: ".$email->cc_addrs."<br>";
397                 }
398                 if(!empty($email->from_addr) || !empty($email->cc_addrs) || !empty($email->to_addrs)){
399                         $details .= "<br>";
400                 }
401
402                 // cn: bug 8433 - history does not distinguish b/t text/html emails
403                 $details .= empty($email->description_html)
404                         ? $this->formatDescription($email->description)
405                         : $this->formatDescription(strip_tags(br2nl(from_html($email->description_html))));
406
407                 return $details;
408         }
409
410         function getTaskDetails($task){
411                 global $app_strings;
412
413                 $details = "";
414                 if (!empty($task->date_start) && $task->date_start != '0000-00-00') {
415                         $details .= $app_strings['DATA_TYPE_START'].$task->date_start."<br>";
416                         $details .= "<br>";
417                 }
418                 $details .= $this->formatDescription($task->description);
419
420                 return $details;
421         }
422
423         function formatDescription($description){
424                 return nl2br($description);
425         }
426 } // end of class Popup_Picker
427 ?>