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.
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.
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
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
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.
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.
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 ********************************************************************************/
43 require_once("include/upload_file.php");
45 require_once('include/utils/db_utils.php');
47 global $currentModule;
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');
58 // history_list is the means of passing data to a SubPanelView.
59 $bean = $beanList[$_REQUEST['module_name']];
60 require_once($beanFiles[$bean]);
70 function Popup_Picker() {
76 function process_page() {
80 global $app_list_strings;
81 global $currentModule;
88 $history_list = array();
90 if(!empty($_REQUEST['record'])) {
91 $result = $focus->retrieve($_REQUEST['record']);
94 sugar_die($app_strings['ERROR_NO_RECORD']);
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";
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)))
109 $varname = "focus_" . $relTable . "_list";
110 $$varname = sugarArrayMerge($$varname, $focus->get_linked_beans($field,$activitiesRels[$relTable]));
116 foreach ($focus_tasks_list as $task) {
118 if (empty($task->date_due) || $task->date_due == '0000-00-00') {
122 $date_due = $task->date_due;
125 if ($task->status != "Not Started" && $task->status != "In Progress" && $task->status != "Pending Input") {
127 if(!empty($task->fetched_row['date_due'])) {
128 //tasks can have an empty date due field
129 $ts = $timedate->fromDb($task->fetched_row['date_due'])->ts;
131 $history_list[] = array('name' => $task->name,
136 'status' => $task->status,
137 'parent_id' => $task->parent_id,
138 'parent_type' => $task->parent_type,
139 'parent_name' => $task->parent_name,
140 'contact_id' => $task->contact_id,
141 'contact_name' => $task->contact_name,
142 'date_modified' => $date_due,
143 'description' => $this->getTaskDetails($task),
144 'date_type' => $app_strings['DATA_TYPE_DUE'],
148 $open_activity_list[] = array('name' => $task->name,
153 'status' => $task->status,
154 'parent_id' => $task->parent_id,
155 'parent_type' => $task->parent_type,
156 'parent_name' => $task->parent_name,
157 'contact_id' => $task->contact_id,
158 'contact_name' => $task->contact_name,
159 'date_due' => $date_due,
160 'description' => $this->getTaskDetails($task),
161 'date_type' => $app_strings['DATA_TYPE_DUE']
166 foreach ($focus_meetings_list as $meeting) {
168 if (empty($meeting->contact_id) && empty($meeting->contact_name)) {
169 $meeting_contacts = $meeting->get_linked_beans('contacts','Contact');
170 if (!empty($meeting_contacts[0]->id) && !empty($meeting_contacts[0]->name)) {
171 $meeting->contact_id = $meeting_contacts[0]->id;
172 $meeting->contact_name = $meeting_contacts[0]->name;
175 if ($meeting->status != "Planned") {
176 $history_list[] = array('name' => $meeting->name,
177 'id' => $meeting->id,
180 'module' => "Meetings",
181 'status' => $meeting->status,
182 'parent_id' => $meeting->parent_id,
183 'parent_type' => $meeting->parent_type,
184 'parent_name' => $meeting->parent_name,
185 'contact_id' => $meeting->contact_id,
186 'contact_name' => $meeting->contact_name,
187 'date_modified' => $meeting->date_start,
188 'description' => $this->formatDescription($meeting->description),
189 'date_type' => $app_strings['DATA_TYPE_START'],
190 'sort_value' => $timedate->fromDb($meeting->fetched_row['date_start'])->ts,
193 $open_activity_list[] = array('name' => $meeting->name,
194 'id' => $meeting->id,
197 'module' => "Meetings",
198 'status' => $meeting->status,
199 'parent_id' => $meeting->parent_id,
200 'parent_type' => $meeting->parent_type,
201 'parent_name' => $meeting->parent_name,
202 'contact_id' => $meeting->contact_id,
203 'contact_name' => $meeting->contact_name,
204 'date_due' => $meeting->date_start,
205 'description' => $this->formatDescription($meeting->description),
206 'date_type' => $app_strings['DATA_TYPE_START']
211 foreach ($focus_calls_list as $call) {
213 if (empty($call->contact_id) && empty($call->contact_name)) {
214 $call_contacts = $call->get_linked_beans('contacts','Contact');
215 if (!empty($call_contacts[0]->id) && !empty($call_contacts[0]->name)) {
216 $call->contact_id = $call_contacts[0]->id;
217 $call->contact_name = $call_contacts[0]->name;
221 if ($call->status != "Planned") {
222 $history_list[] = array('name' => $call->name,
225 'direction' => $call->direction,
227 'status' => $call->status,
228 'parent_id' => $call->parent_id,
229 'parent_type' => $call->parent_type,
230 'parent_name' => $call->parent_name,
231 'contact_id' => $call->contact_id,
232 'contact_name' => $call->contact_name,
233 'date_modified' => $call->date_start,
234 'description' => $this->formatDescription($call->description),
235 'date_type' => $app_strings['DATA_TYPE_START'],
236 'sort_value' => $timedate->fromDb($call->fetched_row['date_start'])->ts,
239 $open_activity_list[] = array('name' => $call->name,
241 'direction' => $call->direction,
244 'status' => $call->status,
245 'parent_id' => $call->parent_id,
246 'parent_type' => $call->parent_type,
247 'parent_name' => $call->parent_name,
248 'contact_id' => $call->contact_id,
249 'contact_name' => $call->contact_name,
250 'date_due' => $call->date_start,
251 'description' => $this->formatDescription($call->description),
252 'date_type' => $app_strings['DATA_TYPE_START']
257 foreach ($focus_emails_list as $email) {
259 if (empty($email->contact_id) && empty($email->contact_name)) {
260 $email_contacts = $email->get_linked_beans('contacts','Contact');
261 if (!empty($email_contacts[0]->id) && !empty($email_contacts[0]->name)) {
262 $email->contact_id = $email_contacts[0]->id;
263 $email->contact_name = $email_contacts[0]->name;
266 $history_list[] = array('name' => $email->name,
270 'module' => "Emails",
272 'parent_id' => $email->parent_id,
273 'parent_type' => $email->parent_type,
274 'parent_name' => $email->parent_name,
275 'contact_id' => $email->contact_id,
276 'contact_name' => $email->contact_name,
277 'date_modified' => $email->date_start." ".$email->time_start,
278 'description' => $this->getEmailDetails($email),
279 'date_type' => $app_strings['DATA_TYPE_SENT'],
280 'sort_value' => $timedate->fromDb($email->fetched_row['date_sent'])->ts,
284 // Bug 46439 'No email archived when clicking on View Summary' (All condition)
285 if (method_exists($focus,'get_unlinked_email_query'))
287 $queryArray = $focus->get_unlinked_email_query(array('return_as_array'=>'true'));
288 $query = $queryArray['select'];
289 $query .= $queryArray['from'];
290 if (!empty($queryArray['join_tables']))
292 foreach ($queryArray['join_tables'] as $join_table)
294 if ($join_table != '')
296 $query .= ', '.$join_table.' ';
300 $query .= $queryArray['join'];
301 $query .= $queryArray['where'];
302 $emails = new Email();
303 $focus_unlinked_emails_list = $emails->process_list_query($query, 0);
304 $focus_unlinked_emails_list = $focus_unlinked_emails_list['list'];
305 foreach ($focus_unlinked_emails_list as $email)
307 $email->retrieve($email->id);
308 $history_list[] = array(
309 'name' => $email->name,
313 'module' => "Emails",
315 'parent_id' => $email->parent_id,
316 'parent_type' => $email->parent_type,
317 'parent_name' => $email->parent_name,
318 'contact_id' => $email->contact_id,
319 'contact_name' => $email->contact_name,
320 'date_modified' => $email->date_start." ".$email->time_start,
321 'description' => $this->getEmailDetails($email),
322 'date_type' => $app_strings['DATA_TYPE_SENT'],
323 'sort_value' => strtotime($email->fetched_row['date_sent'].' GMT'),
326 } //end Unlinked Emails
328 foreach ($focus_notes_list as $note)
330 if ($note->ACLAccess('view'))
332 $history_list[] = array('name' => $note->name,
338 'parent_id' => $note->parent_id,
339 'parent_type' => $note->parent_type,
340 'parent_name' => $note->parent_name,
341 'contact_id' => $note->contact_id,
342 'contact_name' => $note->contact_name,
343 'date_modified' => $note->date_modified,
344 'description' => $this->formatDescription($note->description),
345 'date_type' => $app_strings['DATA_TYPE_MODIFIED'],
346 'sort_value' => strtotime($note->fetched_row['date_modified'].' GMT'),
348 if(!empty($note->filename))
350 $count = count($history_list);
352 $history_list[$count]['filename'] = $note->filename;
353 $history_list[$count]['fileurl'] = UploadFile::get_url($note->filename,$note->id);
359 $xtpl=new XTemplate ('modules/Activities/Popup_picker.html');
361 $xtpl->assign('MOD', $mod_strings);
362 $xtpl->assign('APP', $app_strings);
363 insert_popup_header();
366 echo "<table width='100%' cellpadding='0' cellspacing='0'><tr><td>";
367 echo getClassicModuleTitle($focus->module_dir, array(translate('LBL_MODULE_NAME', $focus->module_dir),$focus->name), false);
368 echo "</td><td align='right' class='moduleTitle'>";
369 echo "<A href='javascript:print();' class='utilsLink'>" . SugarThemeRegistry::current()->getImage('print', "border='0' align='absmiddle'", 13, 13, ".gif", $app_strings['LNK_PRINT']) . "</a> <A href='javascript:print();' class='utilsLink'>".$app_strings['LNK_PRINT']."</A>\n";
370 echo "</td></tr></table>";
373 if (count($history_list) > 0) $history_list = array_csort($history_list, 'sort_value', SORT_DESC);
374 foreach($history_list as $activity)
376 $activity_fields = array(
377 'ID' => $activity['id'],
378 'NAME' => $activity['name'],
379 'MODULE' => $activity['module'],
380 'CONTACT_NAME' => $activity['contact_name'],
381 'CONTACT_ID' => $activity['contact_id'],
382 'PARENT_TYPE' => $activity['parent_type'],
383 'PARENT_NAME' => $activity['parent_name'],
384 'PARENT_ID' => $activity['parent_id'],
385 'DATE' => $activity['date_modified'],
386 'DESCRIPTION' => $activity['description'],
387 'DATE_TYPE' => $activity['date_type']
389 if (empty($activity['direction'])) {
390 $activity_fields['TYPE'] = $app_list_strings['activity_dom'][$activity['type']];
393 $activity_fields['TYPE'] = $app_list_strings['call_direction_dom'][$activity['direction']].' '.$app_list_strings['activity_dom'][$activity['type']];
396 switch ($activity['type']) {
398 $activity_fields['STATUS'] = $app_list_strings['call_status_dom'][$activity['status']];
401 $activity_fields['STATUS'] = $app_list_strings['meeting_status_dom'][$activity['status']];
404 $activity_fields['STATUS'] = $app_list_strings['task_status_dom'][$activity['status']];
408 if (isset($activity['location'])) $activity_fields['LOCATION'] = $activity['location'];
409 if (isset($activity['filename'])) {
410 $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>";
413 if (isset($activity['parent_type'])) $activity_fields['PARENT_MODULE'] = $activity['parent_type'];
415 $xtpl->assign("ACTIVITY", $activity_fields);
416 $xtpl->assign("ACTIVITY_MODULE_PNG", SugarThemeRegistry::current()->getImage($activity_fields['MODULE'].'','border="0"', null,null,'.gif',$activity_fields['NAME']));
420 //todo move to themes
421 $xtpl->assign("ROW_COLOR", 'oddListRow');
422 $xtpl->assign("BG_COLOR", $odd_bg);
426 //todo move to themes
427 $xtpl->assign("ROW_COLOR", 'evenListRow');
428 $xtpl->assign("BG_COLOR", $even_bg);
431 if(!empty($activity_fields['DESCRIPTION'])) {
432 $xtpl->parse("history.row.description");
434 $xtpl->parse("history.row");
437 $xtpl->parse("history");
438 $xtpl->out("history");
439 insert_popup_footer();
442 function getEmailDetails($email){
445 if(!empty($email->to_addrs)){
446 $details .= "To: ".$email->to_addrs."<br>";
448 if(!empty($email->from_addr)){
449 $details .= "From: ".$email->from_addr."<br>";
451 if(!empty($email->cc_addrs)){
452 $details .= "CC: ".$email->cc_addrs."<br>";
454 if(!empty($email->from_addr) || !empty($email->cc_addrs) || !empty($email->to_addrs)){
458 // cn: bug 8433 - history does not distinguish b/t text/html emails
459 $details .= empty($email->description_html)
460 ? $this->formatDescription($email->description)
461 : $this->formatDescription(strip_tags(br2nl(from_html($email->description_html))));
466 function getTaskDetails($task){
470 if (!empty($task->date_start) && $task->date_start != '0000-00-00') {
471 $details .= $app_strings['DATA_TYPE_START'].$task->date_start."<br>";
474 $details .= $this->formatDescription($task->description);
479 function formatDescription($description){
480 return nl2br($description);
482 } // end of class Popup_Picker