]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/javascript/jsAlerts.php
Release 6.5.16
[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-2013 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 (!alertsTimeoutId) {
48                     checkAlerts();
49                 }
50
51 EOQ;
52                 $this->addActivities();
53                 if(!empty($GLOBALS['sugar_config']['enable_timeout_alerts'])){
54                         $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 );
55                         $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');
56                 }
57         }
58         function addAlert($type, $name, $subtitle, $description, $countdown, $redirect='')
59     {
60         $this->script .= 'addAlert(' . json_encode($type) .',' . json_encode($name). ',' . json_encode($subtitle). ','. json_encode(str_replace(array("\r", "\n"), array('','<br>'),$description)) . ',' . $countdown . ','.json_encode($redirect).')' . "\n";
61         }
62
63     function getScript()
64     {
65         return "<script>secondsSinceLoad = 0; alertList = [];" . $this->script . "</script>";
66     }
67
68     /*
69      * To return the name of parent bean.
70      * @param $parentType string parent type
71      * @param $parentId string parent id
72      */
73     function getRelatedName($parentType, $parentId)
74     {
75         if (!empty($parentType) && !empty($parentId)) {
76             $parentBean = BeanFactory::getBean($parentType, $parentId);
77             if (($parentBean instanceof SugarBean) && isset($parentBean->name)) {
78                 return $parentBean->name;
79             }
80         }
81         return '';
82     }
83
84     function addActivities(){
85                 global $app_list_strings, $timedate, $current_user, $app_strings;
86                 global $sugar_config;
87
88                 if (empty($current_user->id)) {
89             return;
90                 }
91
92         //Create separate variable to hold timedate value
93         $alertDateTimeNow = $timedate->nowDb();
94
95                 // cn: get a boundary limiter
96                 $dateTimeMax = $timedate->getNow()->modify("+{$app_list_strings['reminder_max_time']} seconds")->asDb();
97                 $dateTimeNow = $timedate->nowDb();
98
99                 global $db;
100                 $dateTimeNow = $db->convert($db->quoted($dateTimeNow), 'datetime');
101                 $dateTimeMax = $db->convert($db->quoted($dateTimeMax), 'datetime');
102                 $desc = $db->convert("description", "text2char");
103                 if($desc != "description") {
104                     $desc .= " description";
105                 }
106
107                 // Prep Meetings Query
108         $selectMeetings = "SELECT meetings.id, name,reminder_time, $desc,location, status, parent_type, parent_id, date_start, assigned_user_id
109                         FROM meetings LEFT JOIN meetings_users ON meetings.id = meetings_users.meeting_id
110                         WHERE meetings_users.user_id ='".$current_user->id."'
111                                 AND meetings_users.accept_status != 'decline'
112                                 AND meetings.reminder_time != -1
113                                 AND meetings_users.deleted != 1
114                                 AND meetings.status = 'Planned'
115                             AND date_start >= $dateTimeNow
116                             AND date_start <= $dateTimeMax";
117                 $result = $db->query($selectMeetings);
118
119                 ///////////////////////////////////////////////////////////////////////
120                 ////    MEETING INTEGRATION
121                 $meetingIntegration = null;
122                 if(isset($sugar_config['meeting_integration']) && !empty($sugar_config['meeting_integration'])) {
123                         if(!class_exists($sugar_config['meeting_integration'])) {
124                                 require_once("modules/{$sugar_config['meeting_integration']}/{$sugar_config['meeting_integration']}.php");
125                         }
126                         $meetingIntegration = new $sugar_config['meeting_integration']();
127                 }
128                 ////    END MEETING INTEGRATION
129                 ///////////////////////////////////////////////////////////////////////
130
131                 while($row = $db->fetchByAssoc($result)) {
132                         // need to concatenate since GMT times can bridge two local days
133                         $timeStart = strtotime($db->fromConvert($row['date_start'], 'datetime'));
134                         $timeRemind = $row['reminder_time'];
135                         $timeStart -= $timeRemind;
136
137                         $url = 'index.php?action=DetailView&module=Meetings&record=' . $row['id'];
138                         $instructions = $app_strings['MSG_JS_ALERT_MTG_REMINDER_MEETING_MSG'];
139
140                         ///////////////////////////////////////////////////////////////////
141                         ////    MEETING INTEGRATION
142                         if(!empty($meetingIntegration) && $meetingIntegration->isIntegratedMeeting($row['id'])) {
143                                 $url = $meetingIntegration->miUrlGetJsAlert($row);
144                                 $instructions = $meetingIntegration->miGetJsAlertInstructions();
145                         }
146                         ////    END MEETING INTEGRATION
147                         ///////////////////////////////////////////////////////////////////
148
149                         $meetingName = from_html($row['name']);
150                         $desc1 = from_html($row['description']);
151                         $location = from_html($row['location']);
152
153             $relatedToMeeting = $this->getRelatedName($row['parent_type'], $row['parent_id']);
154
155                         $description = empty($desc1) ? '' : $app_strings['MSG_JS_ALERT_MTG_REMINDER_AGENDA'].$desc1."\n";
156             $description = $description  ."\n" .$app_strings['MSG_JS_ALERT_MTG_REMINDER_STATUS'] . $row['status'] ."\n". $app_strings['MSG_JS_ALERT_MTG_REMINDER_RELATED_TO']. $relatedToMeeting;
157
158
159                         // standard functionality
160                         $this->addAlert($app_strings['MSG_JS_ALERT_MTG_REMINDER_MEETING'], $meetingName,
161                                 $app_strings['MSG_JS_ALERT_MTG_REMINDER_TIME'].$timedate->to_display_date_time($db->fromConvert($row['date_start'], 'datetime')),
162                                 $app_strings['MSG_JS_ALERT_MTG_REMINDER_LOC'].$location.
163                                 $description.
164                                 $instructions,
165                                 $timeStart - strtotime($alertDateTimeNow),
166                                 $url
167                         );
168                 }
169
170                 // Prep Calls Query
171                 $selectCalls = "
172                                 SELECT calls.id, name, reminder_time, $desc, date_start, status, parent_type, parent_id
173                                 FROM calls LEFT JOIN calls_users ON calls.id = calls_users.call_id
174                                 WHERE calls_users.user_id ='".$current_user->id."'
175                                     AND calls_users.accept_status != 'decline'
176                                     AND calls.reminder_time != -1
177                                         AND calls_users.deleted != 1
178                                         AND calls.status = 'Planned'
179                                     AND date_start >= $dateTimeNow
180                                     AND date_start <= $dateTimeMax";
181
182                 $result = $db->query($selectCalls);
183
184                 while($row = $db->fetchByAssoc($result)){
185                         // need to concatenate since GMT times can bridge two local days
186                         $timeStart = strtotime($db->fromConvert($row['date_start'], 'datetime'));
187                         $timeRemind = $row['reminder_time'];
188                         $timeStart -= $timeRemind;
189                         $row['description'] = (isset($row['description'])) ? $row['description'] : '';
190
191             $relatedToCall = $this->getRelatedName($row['parent_type'], $row['parent_id']);
192
193             $callDescription = $row['description'] ."\n" .$app_strings['MSG_JS_ALERT_MTG_REMINDER_STATUS'] . $row['status'] ."\n". $app_strings['MSG_JS_ALERT_MTG_REMINDER_RELATED_TO']. $relatedToCall;
194
195
196             $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'].$callDescription. $app_strings['MSG_JS_ALERT_MTG_REMINDER_CALL_MSG'] , $timeStart - strtotime($alertDateTimeNow), 'index.php?action=DetailView&module=Calls&record=' . $row['id']);
197                 }
198         }
199
200
201 }