mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-06 09:38:23 +01:00
Prepare notif using the notif table
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
/* Copyright (C) 2016 Sergio Sanchis <sergiosanchis@hotmail.com>
|
||||
* Copyright (C) 2017 Juanjo Menent <jmenent@2byte.es>
|
||||
* Copyright (C) 2020 Destailleur Laurent <eldy@users.sourceforge.net>
|
||||
*
|
||||
* 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
|
||||
@@ -35,26 +36,9 @@ if (! ($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root . '/' || $_SERVER['H
|
||||
|
||||
top_httphead('text/javascript; charset=UTF-8');
|
||||
|
||||
$nowtime = time();
|
||||
//$nowtimeprevious = floor($nowtime / 60) * 60; // auto_check_events_not_before is rounded to previous minute
|
||||
|
||||
// TODO Try to make a solution with only a javascript timer that is easier. Difficulty is to avoid notification twice when.
|
||||
/* session already started into main
|
||||
session_cache_limiter('public');
|
||||
header('Cache-Control: no-cache');
|
||||
session_set_cookie_params(0, '/', null, false, true); // Add tag httponly on session cookie
|
||||
session_start();*/
|
||||
if (! isset($_SESSION['auto_check_events_not_before']))
|
||||
{
|
||||
print 'console.log("_SESSION[auto_check_events_not_before] is not set");'."\n";
|
||||
// Round to eliminate the seconds
|
||||
$_SESSION['auto_check_events_not_before'] = $nowtime;
|
||||
}
|
||||
print 'var nowtime = ' . $nowtime . ';' . "\n";
|
||||
print 'var login = \'' . $_SESSION['dol_login'] . '\';' . "\n";
|
||||
print 'var auto_check_events_not_before = '.$_SESSION['auto_check_events_not_before']. ';'."\n";
|
||||
print 'var time_js_next_test = Math.max(nowtime, auto_check_events_not_before);'."\n";
|
||||
print 'var time_auto_update = '.$conf->global->MAIN_BROWSER_NOTIFICATION_FREQUENCY.';'."\n"; // Always defined
|
||||
print 'var time_js_next_test = (Date.now() + time_auto_update);'."\n";
|
||||
?>
|
||||
|
||||
/* Check if permission ok */
|
||||
@@ -66,7 +50,7 @@ if (! ($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root . '/' || $_SERVER['H
|
||||
// We set a delay before launching first test so next check will arrive after the time_auto_update compared to previous one.
|
||||
var time_first_execution = (time_auto_update - (nowtime - time_js_next_test)) * 1000; //need milliseconds
|
||||
if (login != '') {
|
||||
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+" auto_check_events_not_before (val in session)= "+auto_check_events_not_before+" time_js_next_test (max now,auto_check_events_not_before) = "+time_js_next_test+" time_auto_update="+time_auto_update);
|
||||
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_test = "+time_js_next_test+" time_auto_update="+time_auto_update);
|
||||
setTimeout(first_execution, time_first_execution);
|
||||
} //first run auto check
|
||||
|
||||
|
||||
Reference in New Issue
Block a user