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