';
//$newtitle=$langs->trans($title);
diff --git a/htdocs/core/ajax/check_notifications.php b/htdocs/core/ajax/check_notifications.php
index 98d7d00a8dc..10172628805 100644
--- a/htdocs/core/ajax/check_notifications.php
+++ b/htdocs/core/ajax/check_notifications.php
@@ -1,7 +1,7 @@
* Copyright (C) 2017 Juanjo Menent
- * Copyright (C) 2019 Frédéric France
+ * Copyright (C) 2019 Frédéric France
*
* 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
@@ -18,11 +18,31 @@
*/
if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1');
-if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Disables token renewal
+if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
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');
+
+//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user
+//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc
+//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs
+//if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters
+//if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters
+//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); // Do not check CSRF attack (test on referer + on token if option MAIN_SECURITY_CSRF_WITH_TOKEN is on).
+//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
+//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data
+//if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
+//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
+//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
+//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
+//if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session)
+//if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT', 'auto'); // Force lang to a particular value
+//if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler
+//if (! defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN', '1'); // The main.inc.php does not make a redirect if not logged, instead show simple error message
+//if (! defined("XFRAMEOPTIONS_ALLOWALL")) define('XFRAMEOPTIONS_ALLOWALL', '1'); // Do not add the HTTP header 'X-Frame-Options: SAMEORIGIN' but 'X-Frame-Options: ALLOWALL'
+
require '../../main.inc.php';
@@ -46,7 +66,8 @@ $eventfound = array();
//dol_syslog('time='.$time.' $_SESSION[auto_ck_events_not_before]='.$_SESSION['auto_check_events_not_before']);
// TODO Try to make a solution with only a javascript timer that is easier. Difficulty is to avoid notification twice when several tabs are opened.
-if ($time >= $_SESSION['auto_check_events_not_before'])
+// This need to extend period to be sure to not miss and save in session what we notified to avoid duplicate (save is not done yet).
+if ($time >= $_SESSION['auto_check_events_not_before'] || GETPOST('forcechecknow', 'int'))
{
$time_update = (int) $conf->global->MAIN_BROWSER_NOTIFICATION_FREQUENCY; // Always defined
if (!empty($_SESSION['auto_check_events_not_before']))
@@ -66,7 +87,7 @@ if ($time >= $_SESSION['auto_check_events_not_before'])
$_SESSION['auto_check_events_not_before'] = $time + $time_update;
- // Force save of session change we did.
+ // Force save of the session change we did.
// WARNING: Any change in sessions after that will not be saved !
session_write_close();
@@ -75,35 +96,34 @@ if ($time >= $_SESSION['auto_check_events_not_before'])
dol_syslog('NEW $_SESSION[auto_check_events_not_before]='.$_SESSION['auto_check_events_not_before']);
- $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 several tabs are opened.
- // This need to extend period to be sure to not miss and save in session what we notified to avoid duplicate (save is not done yet).
- $sql .= " AND datep BETWEEN '".$db->idate($starttime)."' AND '".$db->idate($time + $time_update - 1)."'";
- $sql .= ' AND a.code <> "AC_OTH_AUTO"';
- $sql .= ' AND ar.element_type = "user"';
- $sql .= ' AND ar.fk_element = '.$user->id;
+ $sql = 'SELECT a.id, a.code, a.label, a.location, ar.rowid as id_reminder, ar.dateremind, ar.fk_user';
+ $sql .= ' FROM '.MAIN_DB_PREFIX.'actioncomm as a';
+ if (!empty($user->conf->MAIN_USER_WANT_ALL_EVENTS_NOTIFICATIONS)) {
+ $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'actioncomm_reminder as ar ON a.id = ar.fk_actioncomm AND ar.fk_user = '.$user->id;
+ $sql .= ' WHERE a.code <> "AC_OTH_AUTO"';
+ $sql .= ' AND (';
+ $sql .= " (ar.typeremind = 'browser' AND ar.dateremind < '".$db->idate(dol_now())."' AND ar.status = 0 AND ar.entity = ".$conf->entity;
+ $sql .= " OR (a.datep BETWEEN '".$db->idate($starttime)."' AND '".$db->idate($time + $time_update - 1)."')";
+ $sql .= ' )';
+ } else {
+ $sql .= ' JOIN '.MAIN_DB_PREFIX.'actioncomm_reminder as ar ON a.id = ar.fk_actioncomm AND ar.fk_user = '.$user->id;
+ $sql .= " AND ar.typeremind = 'browser' AND ar.dateremind < '".$db->idate(dol_now())."' AND ar.status = 0 AND ar.entity = ".$conf->entity;
+ }
$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))
{
- // Load translation files required by the page
- $langs->loadLangs(array('agenda', 'commercial'));
-
- $actionmod->fetch($obj->id);
-
// Message must be formated and translated to be used with javascript directly
$event = array();
$event['type'] = 'agenda';
- $event['id'] = $actionmod->id;
- $event['tipo'] = $langs->transnoentities('Action'.$actionmod->code);
- $event['titulo'] = $actionmod->label;
- $event['location'] = $langs->transnoentities('Location').': '.$actionmod->location;
+ $event['id'] = $obj->id;
+ $event['id_reminder'] = $obj->id_reminder;
+ $event['code'] = $obj->code;
+ $event['label'] = $obj->label;
+ $event['location'] = $obj->location;
+ $event['date'] = $db->jdate($obj->dateremind);
$eventfound[] = $event;
}
diff --git a/htdocs/core/js/lib_notification.js.php b/htdocs/core/js/lib_notification.js.php
index 250eb0231a6..fc3fd3512ad 100644
--- a/htdocs/core/js/lib_notification.js.php
+++ b/htdocs/core/js/lib_notification.js.php
@@ -79,6 +79,7 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP
print 'audio = new Audio(\''.DOL_URL_ROOT.'/theme/common/sound/notification_agenda.wav\');';
}
?>
+ var listofreminderids = '';
$.each(arr, function (index, value) {
var url="notdefined";
@@ -88,6 +89,10 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP
body += '\n' + value['location'];
}
+ if(value['type'] == 'agenda' && (value['date'] != null || value['date'] != '')) {
+ body += '\n' + value['date'];
+ }
+
if (value['type'] == 'agenda')
{
url = '' + value['id'];
@@ -105,14 +110,26 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP
{
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(url, '_blank');
- noti.close();
- };
+
+ if (noti) {
+ 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(url, '_blank');
+ noti.close();
+ };
+
+ listofreminderids = listofreminderids + ',' + value['id']
+ }
});
+
+ // Update status of all notifications we sent on browser (listofreminderids)
+ $.ajax(""+listofreminderids, {
+ type: "get", // Usually post or get
+ async: true,
+ data: {time: time_js_next_test}
+ });
}
}
});
diff --git a/htdocs/core/lib/usergroups.lib.php b/htdocs/core/lib/usergroups.lib.php
index 86a26c8f830..f917f32f21a 100644
--- a/htdocs/core/lib/usergroups.lib.php
+++ b/htdocs/core/lib/usergroups.lib.php
@@ -130,7 +130,7 @@ function user_prepare_head($object)
}
$head[$h][0] = DOL_URL_ROOT.'/user/notify/card.php?id='.$object->id;
- $head[$h][1] = $langs->trans("Notifications");
+ $head[$h][1] = $langs->trans("NotificationsAuto");
if ($nbNote > 0) $head[$h][1] .= ''.$nbNote.'';
$head[$h][2] = 'notify';
$h++;
diff --git a/htdocs/langs/en_US/mails.lang b/htdocs/langs/en_US/mails.lang
index a5139813014..c8b2da9e860 100644
--- a/htdocs/langs/en_US/mails.lang
+++ b/htdocs/langs/en_US/mails.lang
@@ -125,12 +125,13 @@ TagMailtoEmail=Recipient Email (including html "mailto:" link)
NoEmailSentBadSenderOrRecipientEmail=No email sent. Bad sender or recipient email. Verify user profile.
# Module Notifications
Notifications=Notifications
-NoNotificationsWillBeSent=No email notifications are planned for this event and company
-ANotificationsWillBeSent=1 notification will be sent by email
-SomeNotificationsWillBeSent=%s notifications will be sent by email
-AddNewNotification=Activate a new email notification target/event
-ListOfActiveNotifications=List all active targets/events for email notification
-ListOfNotificationsDone=List all email notifications sent
+NotificationsAuto=Notifications (Auto)
+NoNotificationsWillBeSent=No automtic email notifications are planned for this event type and company
+ANotificationsWillBeSent=1 automatic notification will be sent by email
+SomeNotificationsWillBeSent=%s automatic notifications will be sent by email
+AddNewNotification=Activate a new automatic email notification target/event
+ListOfActiveNotifications=List all active targets/events for automatic email notification
+ListOfNotificationsDone=List all automatic email notifications sent
MailSendSetupIs=Configuration of email sending has been setup to '%s'. This mode can't be used to send mass emailing.
MailSendSetupIs2=You must first go, with an admin account, into menu %sHome - Setup - EMails%s to change parameter '%s' to use mode '%s'. With this mode, you can enter setup of the SMTP server provided by your Internet Service Provider and use Mass emailing feature.
MailSendSetupIs3=If you have any questions on how to setup your SMTP server, you can ask to %s.