22 if (!defined(
'NOREQUIREUSER')) {
 
   23   define(
'NOREQUIREUSER', 
'1');
 
   25 if (!defined(
'NOREQUIRESOC')) {
 
   26   define(
'NOREQUIRESOC', 
'1');
 
   28 if (!defined(
'NOCSRFCHECK')) {
 
   29   define(
'NOCSRFCHECK', 1);
 
   31 if (!defined(
'NOTOKENRENEWAL')) {
 
   32   define(
'NOTOKENRENEWAL', 1);
 
   34 if (!defined(
'NOLOGIN')) {
 
   37 if (!defined(
'NOREQUIREMENU')) {
 
   38   define(
'NOREQUIREMENU', 1);
 
   40 if (!defined(
'NOREQUIREHTML')) {
 
   41   define(
'NOREQUIREHTML', 1);
 
   44 session_cache_limiter(
'public');
 
   46 require_once 
'../../main.inc.php';
 
   55 if (empty($dolibarr_nocache)) {
 
   56   header(
'Cache-Control: max-age=10800, public, must-revalidate');
 
   58   header(
'Cache-Control: no-cache');
 
   62 print 
"jQuery(document).ready(function () {\n";
 
   66 print 
' var nowtime = Date.now();';
 
   67 print 
' var time_auto_update = '.max(1, 
getDolGlobalInt(
'MAIN_BROWSER_NOTIFICATION_FREQUENCY')).
';'.
"\n"; 
 
   68 print 
' var time_js_next_test;'.
"\n";
 
   72 if (
"Notification" in window) {
 
   74   if (Notification.permission !== 
"granted") {
 
   75     console.log(
"Ask Notification.permission");
 
   76     Notification.requestPermission()
 
   83   var time_first_execution = <?php echo max(3, empty($conf->global->MAIN_BROWSER_NOTIFICATION_CHECK_FIRST_EXECUTION) ? 0 : $conf->global->MAIN_BROWSER_NOTIFICATION_CHECK_FIRST_EXECUTION); ?>;
 
   85   setTimeout(first_execution, time_first_execution * 1000);
 
   86   time_js_next_test = nowtime + time_first_execution;
 
   87   console.log(
"Launch browser notif check: setTimeout is set to launch 'first_execution' function after a wait of time_first_execution="+time_first_execution+
". nowtime (time php page generation) = "+nowtime+
" time_js_next_check = "+time_js_next_test);
 
   89   console.log(
"This browser in this context does not support Notification.");
 
   93 function first_execution() {
 
   94   console.log(
"Call first_execution then set repeat time to time_auto_update = MAIN_BROWSER_NOTIFICATION_FREQUENCY = "+time_auto_update);
 
   96   setInterval(check_events, time_auto_update * 1000); 
 
   99 function check_events() {
 
  100   if (Notification.permission === 
"granted")
 
  103     const allMeta = document.getElementsByTagName(
"meta");
 
  104     for (let i = 0; i < allMeta.length; i++) {
 
  105       if (allMeta[i].getAttribute(
"name") == 
'anti-csrf-token') {
 
  106         newToken = allMeta[i].getAttribute(
'content');
 
  107         console.log(
"newToken in page = "+
newToken);
 
  110     time_js_next_test += time_auto_update;
 
  111     console.log(
"Call ajax to check events with time_js_next_test = "+time_js_next_test);
 
  113     $.ajax(
"<?php print DOL_URL_ROOT.'/core/ajax/check_notifications.php'; ?>", {
 
  116       data: { time_js_next_test: time_js_next_test, forcechecknow: 1, token: 
newToken },
 
  118       success: 
function (result) {
 
  120         var arrayofpastreminders = Object.values(result.pastreminders);
 
  121         if (arrayofpastreminders && arrayofpastreminders.length > 0) {
 
  122           console.log(
"Retrieved "+arrayofpastreminders.length+
" reminders to do.");
 
  125           if (!empty($conf->global->AGENDA_REMINDER_BROWSER_SOUND)) {
 
  126             print 
'audio = new Audio(\''.DOL_URL_ROOT.
'/theme/common/sound/notification_agenda.wav\');';
 
  129           var listofreminderids = 
'';
 
  132           $.each(arrayofpastreminders, 
function (index, value) {
 
  134             var url = 
"notdefined";
 
  135             var title = 
"Not defined";
 
  136             var body = value.label;
 
  137             if (value.type == 
'agenda' && value.location != 
null && value.location != 
'') {
 
  138               body += 
'\n' + value.location;
 
  141             if (value.type == 
'agenda' && (value.event_date_start_formated != 
null || value.event_date_start_formated[
'event_date_start'] != 
'')) {
 
  142               body += 
'\n' + value.event_date_start_formated;
 
  145             if (value.type == 
'agenda')
 
  147               url = 
'<?php print DOL_URL_ROOT.'/comm/action/card.php?id=
'; ?>' + value.id_agenda;
 
  148               title = 
'<?php print dol_escape_js($langs->transnoentities('EventReminder
')) ?>';
 
  151               icon: 
'<?php print DOL_URL_ROOT.'/theme/common/bell.png
'; ?>',
 
  154               tag: value.id_agenda,
 
  155               requireInteraction: true
 
  159             console.log(
"Send notification on browser");
 
  160             noti[index] = 
new Notification(title, extra);
 
  161             if (index==0 && audio)
 
  167               noti[index].onclick = 
function (event) {
 
  168                 console.log(
"A click on notification on browser has been done");
 
  169                 event.preventDefault(); 
 
  171                 window.open(url, 
'_blank');
 
  175               listofreminderids = (listofreminderids == 
'' ? 
'' : listofreminderids + 
',') + value.id_reminder
 
  180           console.log(
"Flag notification as done for listofreminderids="+listofreminderids);
 
  181           $.ajax(
"<?php print DOL_URL_ROOT.'/core/ajax/check_notifications.php?action=stopreminder&listofreminderids='; ?>"+listofreminderids, {
 
  184             data: { time_js_next_test: time_js_next_test, token: 
newToken }
 
  187           console.log(
"No reminder to do found, next search at "+time_js_next_test);
 
  194     console.log(
"Cancel check_events. Useless because javascript Notification.permission is "+Notification.permission+
" (blocked manualy or web site is not https).");
 
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type