All Data Structures Functions Variables Pages
ZurmoNotificationUtil.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
41  {
42  public static function renderDesktopNotificationsScript()
43  {
44  if (UserConfigurationFormAdapter::resolveAndGetValue(Yii::app()->user->userModel, 'enableDesktopNotifications'))
45  {
46  $makeNotification = "
47  if (window.webkitNotifications.checkPermission() == 0)
48  {
49  nf = window.webkitNotifications.createNotification(image, title, body);
50  if (nf.hasOwnProperty('onshow'))
51  {
52  nf.onshow = function() {setTimeout(function () {nf.close();}, 20000);};
53  }
54  nf.show();
55  return true;
56  }
57  ";
58  }
59  else
60  {
61  $makeNotification = "";
62  }
63  // Begin Not Coding Standard
64  $script = "
65  var desktopNotifications =
66  {
67  notify:function(image, title, body)
68  {
69  " . $makeNotification . "
70  return false;
71  },
72  isSupported:function()
73  {
74  if (typeof window.webkitNotifications != 'undefined')
75  {
76  return true
77  }
78  else
79  {
80  return false
81  }
82  },
83  requestAutorization:function()
84  {
85  if (typeof window.webkitNotifications != 'undefined')
86  {
87  if (window.webkitNotifications.checkPermission() == 1)
88  {
89  window.webkitNotifications.requestPermission();
90  }
91  else if (window.webkitNotifications.checkPermission() == 2)
92  {
93  alert('" . Zurmo::t('ZurmoModule', 'You have blocked desktop notifications for this browser.') . "');
94  }
95  else
96  {
97  alert('" . Zurmo::t('ZurmoModule', 'You have already activated desktop notifications for Chrome') . "');
98  }
99  }
100  else
101  {
102  alert('" . Zurmo::t('ZurmoModule', 'This is only available in Chrome.') . "');
103  }
104  }
105  };
106  ";
107  // End Not Coding Standard
108  Yii::app()->clientScript->registerScript('AutoUpdater', $script, CClientScript::POS_HEAD);
109  }
110 
111  public static function renderAutoUpdaterScript()
112  {
113  // Begin Not Coding Standard
114  $script = "
115  var mashableInboxPlacer = $('span.unread-inbox-count'); //TODO: Make an id for this span
116  var unreadMashableInbox = mashableInboxPlacer.text();
117  var url = '" . Yii::app()->createUrl('zurmo/default/getUpdatesForRefresh') . "';
118  function startAutoUpdater()
119  {
120  if (unreadMashableInbox >= 0 && unreadMashableInbox != '')
121  {
122  $.ajax(
123  {
124  type: 'GET',
125  url: url + '?unreadMashableInbox=' + unreadMashableInbox,
126  async: true,
127  cache: false,
128  timeout: 15000,
129  success: function(data)
130  {
131  data = JSON.parse(data);
132  if (data != null)
133  {
134  if (unreadMashableInbox != data.unreadMashableInbox)
135  {
136  unreadMashableInbox = data.unreadMashableInbox;
137  mashableInboxPlacer.html(unreadMashableInbox);
138  if ($('#MashableInboxActionBarForViews').length)
139  {
140  location.reload();
141  }
142  if (desktopNotifications.isSupported())
143  {
144  desktopNotifications.notify(data.imgUrl,
145  data.title,
146  data.message);
147  }
148  }
149  }
150  setTimeout(startAutoUpdater, 10000);
151  },
152  error: function(XMLHttpRequest, textStatus, errorThrown)
153  {
154  setTimeout(startAutoUpdater, 30000);
155  }
156  });
157  }
158  }
159  setTimeout(startAutoUpdater, 10000);
160  ";
161  // End Not Coding Standard
162  Yii::app()->clientScript->registerScript('AutoUpdater', $script, CClientScript::POS_READY);
163  }
164  }
165 ?>
static resolveAndGetValue(User $user, $key, $returnBoolean=true)
Generated on Thu May 28 2020 07:10:36