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.
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 ********************************************************************************/
39 require_once("include/utils/db_utils.php");
46 $this->script .= <<<EOQ
47 if(window.addEventListener){
48 window.addEventListener("load", checkAlerts, false);
50 window.attachEvent("onload", checkAlerts);
54 $this->addActivities();
55 if(!empty($GLOBALS['sugar_config']['enable_timeout_alerts'])){
56 $this->addAlert($app_strings['ERROR_JS_ALERT_SYSTEM_CLASS'], $app_strings['ERROR_JS_ALERT_TIMEOUT_TITLE'],'', $app_strings['ERROR_JS_ALERT_TIMEOUT_MSG_1'], (session_cache_expire() - 2) * 60 );
57 $this->addAlert($app_strings['ERROR_JS_ALERT_SYSTEM_CLASS'], $app_strings['ERROR_JS_ALERT_TIMEOUT_TITLE'],'', $app_strings['ERROR_JS_ALERT_TIMEOUT_MSG_2'], (session_cache_expire()) * 60 , 'index.php');
60 function addAlert($type, $name, $subtitle, $description, $countdown, $redirect=''){
61 $this->script .= 'addAlert("' . addslashes($type) .'", "' . addslashes($name). '","' . addslashes($subtitle). '", "'. addslashes(str_replace(array("\r", "\n"), array('','<br>'),$description)) . '",' . $countdown . ',"'.addslashes($redirect).'")' . "\n";
65 return "<script>" . $this->script . "</script>";
68 function addActivities(){
69 global $app_list_strings, $timedate, $current_user, $app_strings;
72 if (empty($current_user->id)) {
76 // cn: get a boundary limiter
77 $dateTimeMax = gmdate($GLOBALS['timedate']->get_db_date_time_format(), time() + $app_list_strings['reminder_max_time']);
78 $dateTimeNow = gmdate($GLOBALS['timedate']->get_db_date_time_format());
79 $dateMax = gmdate($GLOBALS['timedate']->dbDayFormat, time() + $app_list_strings['reminder_max_time']);
80 $todayGMT = gmdate($GLOBALS['timedate']->dbDayFormat);
83 // Prep Meetings Query
84 if ($db->dbType == 'mysql') {
86 SELECT meetings.id, name,reminder_time, description,location, date_start, assigned_user_id
87 FROM meetings LEFT JOIN meetings_users ON meetings.id = meetings_users.meeting_id
88 WHERE meetings_users.user_id ='".$current_user->id."'
89 AND meetings_users.accept_status != 'decline'
90 AND meetings.reminder_time != -1
91 AND meetings_users.deleted != 1
92 AND meetings.status != 'Held'
93 AND date_start >= '".$dateTimeNow."'";
95 // if we're looking at bridging into the next day as
96 if($dateMax == $todayGMT) {
97 $selectMeetings .= " AND date_start <= '".$dateTimeMax."'";
101 elseif ($db->dbType == 'oci8')
103 }elseif($db->dbType == 'mssql')
106 SELECT meetings.id, name,reminder_time, CAST(description AS varchar(8000)),location, date_start, assigned_user_id
107 FROM meetings LEFT JOIN meetings_users ON meetings.id = meetings_users.meeting_id
108 WHERE meetings_users.user_id ='".$current_user->id."'
109 AND meetings_users.accept_status != 'decline'
110 AND meetings.reminder_time != -1
111 AND meetings_users.deleted != 1
112 AND meetings.status != 'Held'
113 AND date_start >= '".$dateTimeNow."'";
115 // if we're looking at bridging into the next day as
116 if($dateMax == $todayGMT)
118 $selectMeetings .= " AND date_start <= '".$dateTimeMax."'";
122 $result = $db->query($selectMeetings);
124 ///////////////////////////////////////////////////////////////////////
125 //// MEETING INTEGRATION
126 $meetingIntegration = null;
127 if(isset($sugar_config['meeting_integration']) && !empty($sugar_config['meeting_integration'])) {
128 if(!class_exists($sugar_config['meeting_integration'])) {
129 require_once("modules/{$sugar_config['meeting_integration']}/{$sugar_config['meeting_integration']}.php");
131 $meetingIntegration = new $sugar_config['meeting_integration']();
133 //// END MEETING INTEGRATION
134 ///////////////////////////////////////////////////////////////////////
136 while($row = $db->fetchByAssoc($result)) {
137 // need to concatenate since GMT times can bridge two local days
138 $timeStart = strtotime($row['date_start']);
139 $timeRemind = $row['reminder_time'];
140 $timeStart -= $timeRemind;
142 $url = 'index.php?action=DetailView&module=Meetings&record=' . $row['id'];
143 $instructions = $app_strings['MSG_JS_ALERT_MTG_REMINDER_MSG'];
145 ///////////////////////////////////////////////////////////////////
146 //// MEETING INTEGRATION
147 if(!empty($meetingIntegration) && $meetingIntegration->isIntegratedMeeting($row['id'])) {
148 $url = $meetingIntegration->miUrlGetJsAlert($row);
149 $instructions = $meetingIntegration->miGetJsAlertInstructions();
151 //// END MEETING INTEGRATION
152 ///////////////////////////////////////////////////////////////////
156 if(!empty($row['name'])) {
157 $meetingName = from_html($row['name']);
158 // addAlert() uses double-quotes to pass to popup - escape double-quotes
159 //$meetingName = str_replace('"', '\"', $meetingName);
164 if(!empty($row['description'])) {
165 $desc = from_html($row['description']);
166 // addAlert() uses double-quotes to pass to popup - escape double-quotes
167 //$desc = str_replace('"', '\"', $desc);
170 $description = empty($desc) ? '' : $app_strings['MSG_JS_ALERT_MTG_REMINDER_AGENDA'].$desc."\n";
173 // standard functionality
174 $this->addAlert($app_strings['MSG_JS_ALERT_MTG_REMINDER_MEETING'], $meetingName,
175 $app_strings['MSG_JS_ALERT_MTG_REMINDER_TIME'].$timedate->to_display_date_time($row['date_start']),
176 $app_strings['MSG_JS_ALERT_MTG_REMINDER_LOC'].$row['location'].
179 $timeStart - strtotime($dateTimeNow),
185 if ($db->dbType == 'mysql') {
188 SELECT calls.id, name, reminder_time, description, date_start
189 FROM calls LEFT JOIN calls_users ON calls.id = calls_users.call_id
190 WHERE calls_users.user_id ='".$current_user->id."'
191 AND calls_users.accept_status != 'decline'
192 AND calls.reminder_time != -1
193 AND calls_users.deleted != 1
194 AND calls.status != 'Held'
195 and date_start >= '".$dateTimeNow."'";
197 if($dateMax == $todayGMT) {
198 $selectCalls .= " AND date_start <= '".$dateTimeMax."'";
200 }elseif ($db->dbType == 'oci8')
202 }elseif ($db->dbType == 'mssql')
206 SELECT calls.id, name, reminder_time, CAST(description AS varchar(8000)), date_start
207 FROM calls LEFT JOIN calls_users ON calls.id = calls_users.call_id
208 WHERE calls_users.user_id ='".$current_user->id."'
209 AND calls_users.accept_status != 'decline'
210 AND calls.reminder_time != -1
211 AND calls_users.deleted != 1
212 AND calls.status != 'Held'
213 AND date_start >= '".$dateTimeNow."'";
215 if($dateMax == $todayGMT) {
216 $selectCalls .= " AND date_start <= '".$dateTimeMax."'";
222 $result = $db->query($selectCalls);
224 while($row = $db->fetchByAssoc($result)){
225 // need to concatenate since GMT times can bridge two local days
226 $timeStart = strtotime($row['date_start']);
227 $timeRemind = $row['reminder_time'];
228 $timeStart -= $timeRemind;
229 $row['description'] = (isset($row['description'])) ? $row['description'] : '';
232 $this->addAlert($app_strings['MSG_JS_ALERT_MTG_REMINDER_CALL'], $row['name'], $app_strings['MSG_JS_ALERT_MTG_REMINDER_TIME'].$timedate->to_display_date_time($row['date_start']) , $app_strings['MSG_JS_ALERT_MTG_REMINDER_DESC'].$row['description']. $app_strings['MSG_JS_ALERT_MTG_REMINDER_MSG'] , $timeStart - strtotime($dateTimeNow), 'index.php?action=DetailView&module=Calls&record=' . $row['id']);