]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/javascript/jsAlerts.php
Release 6.1.4
[Github/sugarcrm.git] / include / javascript / jsAlerts.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 require_once("include/utils/db_utils.php");
40
41 class jsAlerts{
42         var $script;
43         
44         function jsAlerts(){
45                 global $app_strings;
46                 $this->script .= <<<EOQ
47                 if(window.addEventListener){
48                         window.addEventListener("load", checkAlerts, false);
49                 }else{
50                         window.attachEvent("onload", checkAlerts);
51                 }
52                 
53 EOQ;
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');
58                 }
59         }
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";
62         }
63         
64         function getScript(){
65                 return "<script>" . $this->script . "</script>";        
66         }
67         
68         function addActivities(){
69                 global $app_list_strings, $timedate, $current_user, $app_strings;
70                 global $sugar_config;
71
72                 if (empty($current_user->id)) {
73             return;
74                 }
75                         
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);
81                 
82                 global $db;
83                 // Prep Meetings Query
84                 if ($db->dbType == 'mysql') {
85                         $selectMeetings = "
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."'"; 
94                         
95                         // if we're looking at bridging into the next day as 
96                         if($dateMax == $todayGMT) {
97                                 $selectMeetings .= " AND date_start <= '".$dateTimeMax."'";
98                         }
99                 } 
100
101                 elseif ($db->dbType == 'oci8')
102                 {       
103                 }elseif($db->dbType == 'mssql')
104                 {
105                         $selectMeetings = "
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."'";
114                         
115                         // if we're looking at bridging into the next day as 
116                         if($dateMax == $todayGMT) 
117                         {
118                                 $selectMeetings .= " AND date_start  <= '".$dateTimeMax."'";
119                         }
120                 }
121
122                 $result = $db->query($selectMeetings);
123
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");
130                         }
131                         $meetingIntegration = new $sugar_config['meeting_integration']();
132                 }
133                 ////    END MEETING INTEGRATION
134                 ///////////////////////////////////////////////////////////////////////
135                 
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;
141                         
142                         $url = 'index.php?action=DetailView&module=Meetings&record=' . $row['id'];
143                         $instructions = $app_strings['MSG_JS_ALERT_MTG_REMINDER_MSG'];
144                 
145                         ///////////////////////////////////////////////////////////////////
146                         ////    MEETING INTEGRATION
147                         if(!empty($meetingIntegration) && $meetingIntegration->isIntegratedMeeting($row['id'])) {
148                                 $url = $meetingIntegration->miUrlGetJsAlert($row);
149                                 $instructions = $meetingIntegration->miGetJsAlertInstructions();
150                         }
151                         ////    END MEETING INTEGRATION
152                         ///////////////////////////////////////////////////////////////////
153                         
154                         // sanitize topic
155                         $meetingName = '';
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);
160                         }
161                         
162                         // sanitize agenda
163                         $desc = '';
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);
168                         }
169
170                         $description = empty($desc) ? '' : $app_strings['MSG_JS_ALERT_MTG_REMINDER_AGENDA'].$desc."\n";
171                         
172                         
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']. 
177                                 $description. 
178                                 $instructions, 
179                                 $timeStart - strtotime($dateTimeNow), 
180                                 $url
181                         );
182                 }
183
184                 // Prep Calls Query
185                 if ($db->dbType == 'mysql') {
186         
187                         $selectCalls = "
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."'"; 
196         
197                         if($dateMax == $todayGMT) {
198                                 $selectCalls .= " AND date_start <= '".$dateTimeMax."'";
199                         }
200                 }elseif ($db->dbType == 'oci8') 
201                 {
202                 }elseif ($db->dbType == 'mssql')  
203                 {
204                         
205                         $selectCalls = "
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."'"; 
214                                                         
215                         if($dateMax == $todayGMT) {
216                                 $selectCalls .= " AND date_start  <= '".$dateTimeMax."'";
217                         }
218                 }
219                 
220
221                 global $db;
222                 $result = $db->query($selectCalls);
223
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'] : '';
230                         
231                         
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']);
233                 }
234         }
235         
236         
237 }
238
239 ?>