diff --git a/htdocs/admin/agenda_other.php b/htdocs/admin/agenda_other.php
index 2835d17e2fe..9bf3a4ddc16 100644
--- a/htdocs/admin/agenda_other.php
+++ b/htdocs/admin/agenda_other.php
@@ -408,31 +408,34 @@ print $form->selectarray('AGENDA_DEFAULT_VIEW', $tmplist, $conf->global->AGENDA_
print ''."\n";
// AGENDA NOTIFICATION
-$var=!$var;
-print '
'."\n";
-print '| '.$langs->trans('AGENDA_NOTIFICATION').' | '."\n";
-print ' | '."\n";
-print ''."\n";
-
-if (empty($conf->global->AGENDA_NOTIFICATION)) {
- print ''.img_picto($langs->trans('Disabled'),'switch_off').'';
- print ' |
'."\n";
-} else {
- print ''.img_picto($langs->trans('Enabled'),'switch_on').'';
- print ''."\n";
- $var=!$var;
+if ($conf->global->MAIN_FEATURES_LEVEL > 0)
+{
+ $var=!$var;
print ''."\n";
- print '| '.$langs->trans('AGENDA_NOTIFICATION_SOUND').' | '."\n";
+ print ''.$langs->trans('AGENDA_NOTIFICATION').' | '."\n";
print ' | '."\n";
print ''."\n";
-
- if (empty($conf->global->AGENDA_NOTIFICATION_SOUND)) {
- print ''.img_picto($langs->trans('Disabled'),'switch_off').'';
+
+ if (empty($conf->global->AGENDA_NOTIFICATION)) {
+ print ''.img_picto($langs->trans('Disabled'),'switch_off').'';
+ print ' |
'."\n";
} else {
- print ''.img_picto($langs->trans('Enabled'),'switch_on').'';
+ print ''.img_picto($langs->trans('Enabled'),'switch_on').'';
+ print ''."\n";
+ $var=!$var;
+ print ''."\n";
+ print '| '.$langs->trans('AGENDA_NOTIFICATION_SOUND').' | '."\n";
+ print ' | '."\n";
+ print ''."\n";
+
+ if (empty($conf->global->AGENDA_NOTIFICATION_SOUND)) {
+ print ''.img_picto($langs->trans('Disabled'),'switch_off').'';
+ } else {
+ print ''.img_picto($langs->trans('Enabled'),'switch_on').'';
+ }
+
+ print ' |
'."\n";
}
-
- print ''."\n";
}
print '';
diff --git a/htdocs/core/ajax/check_events.php b/htdocs/core/ajax/check_events.php
deleted file mode 100644
index 03787c92f52..00000000000
--- a/htdocs/core/ajax/check_events.php
+++ /dev/null
@@ -1,70 +0,0 @@
-
- * Copyright (C) 2017 Juanjo Menent
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-
-require '../../main.inc.php';
-require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
-
-global $user, $db, $langs, $conf;
-
-$time = GETPOST('time');
-
-session_start();
-
-//TODO Configure how long the upgrade will take
-$time_update = 60;
-
-if (! empty($conf->global->AGENDA_NOTIFICATION)) {
- if ($_SESSION['auto_check_events'] <= (int) $time) {
- $_SESSION['auto_check_events'] = $time + $time_update;
-
- $eventos = array();
-
- $sql = 'SELECT id';
- $sql .= ' FROM ' . MAIN_DB_PREFIX . 'actioncomm a, ' . MAIN_DB_PREFIX . 'actioncomm_resources ar';
- $sql .= ' WHERE datep BETWEEN ' . $db->idate($time + 1) . ' AND ' . $db->idate($time + $time_update);
- $sql .= ' AND a.id = ar.fk_actioncomm';
- $sql .= ' AND a.code <> "AC_OTH_AUTO"';
- $sql .= ' AND ar.element_type = "user"';
- $sql .= ' AND ar.fk_element = ' . $user->id;
-
- $resql = $db->query($sql);
-
- if ($resql) {
-
- $actionmod = new ActionComm($db);
-
- while ($obj = $db->fetch_object($resql)) {
-
- $event = array();
-
- $actionmod->fetch($obj->id);
-
- $event['id'] = $actionmod->id;
- $event['tipo'] = $langs->transnoentities('Action' . $actionmod->code);
- $event['titulo'] = $actionmod->label;
- $event['location'] = $actionmod->location;
- $eventos[] = $event;
- $actionmod->initAsSpecimen();
-
- }
- }
-
- print json_encode($eventos);
- }
-}
\ No newline at end of file
diff --git a/htdocs/core/ajax/check_notifications.php b/htdocs/core/ajax/check_notifications.php
new file mode 100644
index 00000000000..af56cb23700
--- /dev/null
+++ b/htdocs/core/ajax/check_notifications.php
@@ -0,0 +1,80 @@
+
+ * Copyright (C) 2017 Juanjo Menent
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal
+if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
+if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
+if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
+if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
+if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
+
+require '../../main.inc.php';
+require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
+
+global $user, $db, $langs, $conf;
+
+$time = GETPOST('time');
+//$time=dol_now();
+
+session_start();
+
+$time_update = (empty($conf->global->MAIN_BROWSER_NOTIFICATION_FREQUENCY)?'3':(int) $conf->global->MAIN_BROWSER_NOTIFICATION_FREQUENCY);
+
+$eventos = array();
+//$eventos[]=array('type'=>'agenda', 'id'=>1, 'tipo'=>'eee', 'location'=>'aaa');
+
+// TODO Remove test on session. Timer should be managed by a javascript timer
+if ($_SESSION['auto_check_events'] <= (int) $time)
+{
+ $_SESSION['auto_check_events'] = $time + $time_update;
+
+ $sql = 'SELECT id';
+ $sql .= ' FROM ' . MAIN_DB_PREFIX . 'actioncomm a, ' . MAIN_DB_PREFIX . 'actioncomm_resources ar';
+ $sql .= ' WHERE a.id = ar.fk_actioncomm';
+ // TODO Try to make a solution with only a javascript timer that is easier. Difficulty is to avoid notification twice when.
+ // This need to extend period to be sure to not miss and save what we notified to avoid duplicate (save is not done yet).
+ $sql .= " AND datep BETWEEN '" . $db->idate($time + 1) . "' AND '" . $db->idate($time + $time_update) . "'";
+ $sql .= ' AND a.code <> "AC_OTH_AUTO"';
+ $sql .= ' AND ar.element_type = "user"';
+ $sql .= ' AND ar.fk_element = ' . $user->id;
+ $sql .= ' LIMIT 10'; // Avoid too many notification at once
+
+ $resql = $db->query($sql);
+ if ($resql) {
+
+ $actionmod = new ActionComm($db);
+
+ while ($obj = $db->fetch_object($resql)) {
+
+ $actionmod->fetch($obj->id);
+
+ $event = array();
+ $event['type'] = 'agenda';
+ $event['id'] = $actionmod->id;
+ $event['tipo'] = $langs->transnoentities('Action' . $actionmod->code);
+ $event['titulo'] = $actionmod->label;
+ $event['location'] = $actionmod->location;
+
+ $eventos[] = $event;
+ }
+ }
+
+}
+
+print json_encode($eventos);
+
diff --git a/htdocs/core/js/agenda_notification.js.php b/htdocs/core/js/lib_notification.js.php
similarity index 56%
rename from htdocs/core/js/agenda_notification.js.php
rename to htdocs/core/js/lib_notification.js.php
index ad4b8cf1bdf..a870066c775 100644
--- a/htdocs/core/js/agenda_notification.js.php
+++ b/htdocs/core/js/lib_notification.js.php
@@ -14,8 +14,10 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
- *
-*/
+ *
+ * Library javascript to enable Browser notifications
+ */
+
if (!defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1');
if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', 1);
@@ -24,110 +26,113 @@ if (!defined('NOLOGIN')) define('NOLOGIN', 1);
if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', 1);
if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', 1);
-session_cache_limiter(FALSE);
-
require_once '../../main.inc.php';
-if(!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root . '/' || $_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root . '/index.php')){
-
+if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root . '/' || $_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root . '/index.php'))
+{
global $langs, $conf;
- $langs->load('agenda');
-
// Define javascript type
header('Content-type: text/javascript; charset=UTF-8');
+
+ // TODO Try to make a solution with only a javascript timer that is easier. Difficulty is to avoid notification twice when.
+ session_cache_limiter(FALSE);
header('Cache-Control: no-cache');
-
- // Check notification permissions API HTML5
- print 'if (Notification.permission !== "granted") {
- Notification.requestPermission()
- }' . PHP_EOL;
-
session_start();
if (!isset($_SESSION['auto_check_events'])) {
-
// Round to eliminate the second part
$_SESSION['auto_check_events'] = floor(time() / 60) * 60;
- print 'var time_session = ' . $_SESSION['auto_check_events'] . ';' . PHP_EOL;
- print 'var now = ' . $_SESSION['auto_check_events'] . ';' . PHP_EOL;
+ print 'var time_session = ' . $_SESSION['auto_check_events'] . ';'."\n";
+ print 'var now = ' . $_SESSION['auto_check_events'] . ';' . "\n";
} else {
-
- print 'var time_session = ' . $_SESSION['auto_check_events'] . ';' . PHP_EOL;
- print 'var now = ' . time() . ';' . PHP_EOL;
+ print 'var time_session = ' . $_SESSION['auto_check_events'] . ';' . "\n";
+ print 'var now = ' . time() . ';' . "\n";
}
-
- //TODO provisionally set to be checked every 60 seconds, the 1000 is because it needs to be in milliseconds
- print 'var time_auto_update = 60;' . "\n";
+ print 'var time_auto_update = '.(empty($conf->global->MAIN_BROWSER_NOTIFICATION_FREQUENCY)?'3':(int) $conf->global->MAIN_BROWSER_NOTIFICATION_FREQUENCY).';' . "\n";
?>
-
+
+ /* Check if permission ok */
+ if (Notification.permission !== "granted") {
+ Notification.requestPermission()
+ }
if (now > (time_session + time_auto_update) || now == time_session) {
first_execution(); //firts run auto check
} else {
- var time_first_execution = (time_auto_update - (now - time_session)) * 1000;
+ var time_first_execution = (time_auto_update - (now - time_session)) * 1000; //need milliseconds
- setTimeout(first_execution, time_first_execution); //firts run auto check
+ setTimeout(first_execution, time_first_execution); //first run auto check
}
function first_execution() {
+ console.log("Call first_execution");
check_events();
setInterval(check_events, time_auto_update * 1000); //program time for run check events
}
function check_events() {
-
- $.ajax("", {
- type: "post", // Usually post o get
- async: true,
- data: {time: time_session},
- success: function (result) {
-
- var arr = JSON.parse(result);
-
- if (arr.length > 0) {
- if (Notification.permission === "granted") {
-
+ if (Notification.permission === "granted")
+ {
+ console.log("Call check_events");
+ $.ajax("", {
+ type: "post", // Usually post o get
+ async: true,
+ data: {time: time_session},
+ success: function (result) {
+ var arr = JSON.parse(result);
+ if (arr.length > 0) {
global->AGENDA_NOTIFICATION_SOUND){
- print 'var audio = new Audio(\''.dol_buildpath('/comm/action/sound/notification.mp3', 1).'\');';
+ if (! empty($conf->global->AGENDA_NOTIFICATION_SOUND)) {
+ print 'var audio = new Audio(\''.DOL_URL_ROOT.'/theme/common/sound/notification_agenda.wav'.'\');';
}
?>
-
+
$.each(arr, function (index, value) {
+ var url="notdefined";
+ var title="Not defined";
var body = value['tipo'] + ': ' + value['titulo'];
- if (value['location'] != null) {
+ if (value['type'] == 'agenda' && value['location'] != null && value['location'] != '') {
body += '\n transnoentities('Location')?>: ' + value['location'];
}
-
-
- var title = "trans('Agenda') ?>";
+
+ if (value['type'] == 'agenda')
+ {
+ url = '' + value['id'];
+ title = 'trans('Agenda') ?>';
+ }
var extra = {
- icon: "",
+ icon: '',
body: body,
tag: value['id']
};
-
+
// We release the notify
var noti = new Notification(title, extra);
- global->AGENDA_NOTIFICATION_SOUND){
- print 'if(index==0)audio.play();'."\n";
+ if (index==0 && audio)
+ {
+ audio.play();
}
- ?>
noti.onclick = function (event) {
+ console.log("An event to notify on browser was received");
event.preventDefault(); // prevent the browser from focusing the Notification's tab
window.focus();
- window.open("" + value['id'], '_blank');
+ window.open(url, '_blank');
noti.close();
};
});
}
}
- }
- });
+ });
+ }
+ else
+ {
+ console.log("Cancel check_events. Useless because Notification.permission is "+Notification.permission);
+ }
+
time_session += time_auto_update;
}
-langfiles = array("companies");
// Module parts
- $this->module_parts = array('js' => array('/core/js/agenda_notification.js.php'));
+ $this->module_parts = array();
// Constants
//-----------
diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang
index fcb4df82669..f88736e93d1 100644
--- a/htdocs/langs/en_US/admin.lang
+++ b/htdocs/langs/en_US/admin.lang
@@ -1475,8 +1475,8 @@ AGENDA_USE_EVENT_TYPE_DEFAULT=Set automatically this default value for type of e
AGENDA_DEFAULT_FILTER_TYPE=Set automatically this type of event into search filter of agenda view
AGENDA_DEFAULT_FILTER_STATUS=Set automatically this status for events into search filter of agenda view
AGENDA_DEFAULT_VIEW=Which tab do you want to open by default when selecting menu Agenda
-AGENDA_NOTIFICATION=Enable events notification
-AGENDA_NOTIFICATION_SOUND=Enable sound on notifications
+AGENDA_NOTIFICATION=Enable event notification on user browsers when event date is reached (each user is able to refuse this from the browser confirmation question)
+AGENDA_NOTIFICATION_SOUND=Enable sound notification
##### ClickToDial #####
ClickToDialDesc=This module allows to make phone numbers clickable. A click on this icon will call make your phone to call the phone number. This can be used to call a call center system from Dolibarr that can call the phone number on a SIP system for example.
ClickToDialUseTelLink=Use just a link "tel:" on phone numbers
diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php
index 8aba2e428f2..80c6b1b3dca 100644
--- a/htdocs/main.inc.php
+++ b/htdocs/main.inc.php
@@ -1303,7 +1303,16 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs
print ''."\n";
print ''."\n";
}
-
+
+ // Browser notifications
+ $enablebrowsernotif=false;
+ if (! empty($conf->agenda->enabled) && ! empty($conf->global->AGENDA_NOTIFICATION) && ! empty($conf->global->AGENDA_NOTIFICATION_SOUND)) $enablebrowsernotif=true;
+ if ($enablebrowsernotif)
+ {
+ print ''."\n";
+ print ''."\n";
+ }
+
// Global js function
print ''."\n";
print ''."\n";
diff --git a/htdocs/comm/action/sound/notification.mp3 b/htdocs/theme/common/sound/notification.mp3
similarity index 100%
rename from htdocs/comm/action/sound/notification.mp3
rename to htdocs/theme/common/sound/notification.mp3
diff --git a/htdocs/theme/common/sound/notification_agenda.wav b/htdocs/theme/common/sound/notification_agenda.wav
new file mode 100644
index 00000000000..09e203c30f1
Binary files /dev/null and b/htdocs/theme/common/sound/notification_agenda.wav differ