]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/javascript/jsAlerts.php
Release 6.2.0
[Github/sugarcrm.git] / include / javascript / jsAlerts.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-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 = $timedate->getNow()->modify("+{$app_list_strings['reminder_max_time']} seconds")->asDb();
78                 $dateTimeNow = $timedate->nowDb();
79
80                 global $db;
81                 // Prep Meetings Query
82                 if ($db->dbType == 'mysql') {
83                         $selectMeetings = "
84                                 SELECT meetings.id, name,reminder_time, description,location, date_start, assigned_user_id
85                                 FROM meetings LEFT JOIN meetings_users ON meetings.id = meetings_users.meeting_id
86                                 WHERE meetings_users.user_id ='".$current_user->id."'
87                                         AND meetings_users.accept_status != 'decline'
88                                         AND meetings.reminder_time != -1
89                                         AND meetings_users.deleted != 1
90                                         AND meetings.status != 'Held'
91                                     AND date_start >= '$dateTimeNow'
92                                     AND date_start <= '$dateTimeMax'";
93                 }
94                 elseif ($db->dbType == 'oci8')
95                 {
96                 }elseif($db->dbType == 'mssql') {
97                         $selectMeetings = "
98                                 SELECT meetings.id, name,reminder_time, CAST(description AS varchar(8000)),location, date_start, assigned_user_id
99                                 FROM meetings LEFT JOIN meetings_users ON meetings.id = meetings_users.meeting_id
100                                 WHERE meetings_users.user_id ='".$current_user->id."'
101                                         AND meetings_users.accept_status != 'decline'
102                                         AND meetings.reminder_time != -1
103                                         AND meetings_users.deleted != 1
104                                         AND meetings.status != 'Held'
105                                     AND date_start >= '$dateTimeNow'
106                                     AND date_start <= '$dateTimeMax'";
107                 }
108
109                 $result = $db->query($selectMeetings);
110
111                 ///////////////////////////////////////////////////////////////////////
112                 ////    MEETING INTEGRATION
113                 $meetingIntegration = null;
114                 if(isset($sugar_config['meeting_integration']) && !empty($sugar_config['meeting_integration'])) {
115                         if(!class_exists($sugar_config['meeting_integration'])) {
116                                 require_once("modules/{$sugar_config['meeting_integration']}/{$sugar_config['meeting_integration']}.php");
117                         }
118                         $meetingIntegration = new $sugar_config['meeting_integration']();
119                 }
120                 ////    END MEETING INTEGRATION
121                 ///////////////////////////////////////////////////////////////////////
122
123                 while($row = $db->fetchByAssoc($result)) {
124                         // need to concatenate since GMT times can bridge two local days
125                         $timeStart = strtotime($row['date_start']);
126                         $timeRemind = $row['reminder_time'];
127                         $timeStart -= $timeRemind;
128
129                         $url = 'index.php?action=DetailView&module=Meetings&record=' . $row['id'];
130                         $instructions = $app_strings['MSG_JS_ALERT_MTG_REMINDER_MEETING_MSG'];
131
132                         ///////////////////////////////////////////////////////////////////
133                         ////    MEETING INTEGRATION
134                         if(!empty($meetingIntegration) && $meetingIntegration->isIntegratedMeeting($row['id'])) {
135                                 $url = $meetingIntegration->miUrlGetJsAlert($row);
136                                 $instructions = $meetingIntegration->miGetJsAlertInstructions();
137                         }
138                         ////    END MEETING INTEGRATION
139                         ///////////////////////////////////////////////////////////////////
140
141                         // sanitize topic
142                         $meetingName = '';
143                         if(!empty($row['name'])) {
144                                 $meetingName = from_html($row['name']);
145                                 // addAlert() uses double-quotes to pass to popup - escape double-quotes
146                                 //$meetingName = str_replace('"', '\"', $meetingName);
147                         }
148
149                         // sanitize agenda
150                         $desc = '';
151                         if(!empty($row['description'])) {
152                                 $desc = from_html($row['description']);
153                                 // addAlert() uses double-quotes to pass to popup - escape double-quotes
154                                 //$desc = str_replace('"', '\"', $desc);
155                         }
156
157                         $description = empty($desc) ? '' : $app_strings['MSG_JS_ALERT_MTG_REMINDER_AGENDA'].$desc."\n";
158
159
160                         // standard functionality
161                         $this->addAlert($app_strings['MSG_JS_ALERT_MTG_REMINDER_MEETING'], $meetingName,
162                                 $app_strings['MSG_JS_ALERT_MTG_REMINDER_TIME'].$timedate->to_display_date_time($row['date_start']),
163                                 $app_strings['MSG_JS_ALERT_MTG_REMINDER_LOC'].$row['location'].
164                                 $description.
165                                 $instructions,
166                                 $timeStart - strtotime($dateTimeNow),
167                                 $url
168                         );
169                 }
170
171                 // Prep Calls Query
172                 if ($db->dbType == 'mysql') {
173
174                         $selectCalls = "
175                                 SELECT calls.id, name, reminder_time, description, date_start
176                                 FROM calls LEFT JOIN calls_users ON calls.id = calls_users.call_id
177                                 WHERE calls_users.user_id ='".$current_user->id."'
178                                     AND calls_users.accept_status != 'decline'
179                                     AND calls.reminder_time != -1
180                                         AND calls_users.deleted != 1
181                                         AND calls.status != 'Held'
182                                     AND date_start >= '$dateTimeNow'
183                                     AND date_start <= '$dateTimeMax'";
184                 }elseif ($db->dbType == 'oci8')
185                 {
186                 }elseif ($db->dbType == 'mssql') {
187
188                         $selectCalls = "
189                                 SELECT calls.id, name, reminder_time, CAST(description AS varchar(8000)), date_start
190                                 FROM calls LEFT JOIN calls_users ON calls.id = calls_users.call_id
191                                 WHERE calls_users.user_id ='".$current_user->id."'
192                     AND calls_users.accept_status != 'decline'
193                                     AND calls.reminder_time != -1
194                                         AND calls_users.deleted != 1
195                                         AND calls.status != 'Held'
196                                     AND date_start >= '$dateTimeNow'
197                                     AND date_start <= '$dateTimeMax'";
198                 }
199
200                 global $db;
201                 $result = $db->query($selectCalls);
202
203                 while($row = $db->fetchByAssoc($result)){
204                         // need to concatenate since GMT times can bridge two local days
205                         $timeStart = strtotime($row['date_start']);
206                         $timeRemind = $row['reminder_time'];
207                         $timeStart -= $timeRemind;
208                         $row['description'] = (isset($row['description'])) ? $row['description'] : '';
209
210
211                         $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_CALL_MSG'] , $timeStart - strtotime($dateTimeNow), 'index.php?action=DetailView&module=Calls&record=' . $row['id']);
212                 }
213         }
214
215
216 }
217
218 ?>