mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-09 19:18:22 +01:00
Debug notifications on browser
This commit is contained in:
@@ -46,6 +46,45 @@ if (!defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1');
|
|||||||
|
|
||||||
require '../../main.inc.php';
|
require '../../main.inc.php';
|
||||||
|
|
||||||
|
$time = (int) GETPOST('time', 'int'); // Use the time parameter that is always increased by time_update, even if call is late
|
||||||
|
//$time=dol_now();
|
||||||
|
$action = GETPOST('action', 'aZ09');
|
||||||
|
$listofreminderids = GETPOST('listofreminderids', 'aZ09');
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Actions
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ($action == 'stopreminder') {
|
||||||
|
dol_syslog("Clear notification for listofreminderids=".$listofreminderids);
|
||||||
|
$listofreminderidsarray = explode('-', GETPOST('listofreminderids', 'aZ09'));
|
||||||
|
|
||||||
|
// Set the reminder as done
|
||||||
|
foreach($listofreminderidsarray as $listofreminderid) {
|
||||||
|
if (empty($listofreminderid)) continue;
|
||||||
|
//$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'action_reminder WHERE rowid = '.$listofreminderid.' AND fk_user = '.$user->id;
|
||||||
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'actioncomm_reminder SET status = 1';
|
||||||
|
$sql .= ' WHERE status = 0 AND rowid = '.$listofreminderid.' AND fk_user = '.$user->id.' AND entity = '.$conf->entity;
|
||||||
|
$resql = $db->query($sql);
|
||||||
|
if (!$resql) {
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
include_once(DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php');
|
||||||
|
|
||||||
|
// Clean database
|
||||||
|
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'actioncomm_reminder';
|
||||||
|
$sql .= " WHERE dateremind < '".$db->idate(dol_time_plus_duree(dol_now(), -1, 'm'))."'";
|
||||||
|
$resql = $db->query($sql);
|
||||||
|
if (!$resql) {
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* View
|
* View
|
||||||
@@ -55,10 +94,6 @@ top_httphead('text/html'); // TODO Use a json mime type
|
|||||||
|
|
||||||
global $user, $db, $langs, $conf;
|
global $user, $db, $langs, $conf;
|
||||||
|
|
||||||
$time = (int) GETPOST('time', 'int'); // Use the time parameter that is always increased by time_update, even if call is late
|
|
||||||
//$time=dol_now();
|
|
||||||
|
|
||||||
|
|
||||||
$eventfound = array();
|
$eventfound = array();
|
||||||
//Uncomment this to force a test
|
//Uncomment this to force a test
|
||||||
//$eventfound[]=array('type'=>'agenda', 'id'=>1, 'tipo'=>'eee', 'location'=>'aaa');
|
//$eventfound[]=array('type'=>'agenda', 'id'=>1, 'tipo'=>'eee', 'location'=>'aaa');
|
||||||
@@ -96,7 +131,7 @@ if ($time >= $_SESSION['auto_check_events_not_before'] || GETPOST('forcechecknow
|
|||||||
|
|
||||||
dol_syslog('NEW $_SESSION[auto_check_events_not_before]='.$_SESSION['auto_check_events_not_before']);
|
dol_syslog('NEW $_SESSION[auto_check_events_not_before]='.$_SESSION['auto_check_events_not_before']);
|
||||||
|
|
||||||
$sql = 'SELECT a.id, a.code, a.label, a.location, ar.rowid as id_reminder, ar.dateremind, ar.fk_user';
|
$sql = 'SELECT a.id, a.code, a.datep, a.label, a.location, ar.rowid as id_reminder, ar.dateremind, ar.fk_user as id_user_reminder';
|
||||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'actioncomm as a';
|
$sql .= ' FROM '.MAIN_DB_PREFIX.'actioncomm as a';
|
||||||
if (!empty($user->conf->MAIN_USER_WANT_ALL_EVENTS_NOTIFICATIONS)) {
|
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 .= ' LEFT JOIN '.MAIN_DB_PREFIX.'actioncomm_reminder as ar ON a.id = ar.fk_actioncomm AND ar.fk_user = '.$user->id;
|
||||||
@@ -120,10 +155,12 @@ if ($time >= $_SESSION['auto_check_events_not_before'] || GETPOST('forcechecknow
|
|||||||
$event['type'] = 'agenda';
|
$event['type'] = 'agenda';
|
||||||
$event['id'] = $obj->id;
|
$event['id'] = $obj->id;
|
||||||
$event['id_reminder'] = $obj->id_reminder;
|
$event['id_reminder'] = $obj->id_reminder;
|
||||||
|
$event['id_user'] = $obj->id_user_reminder;
|
||||||
$event['code'] = $obj->code;
|
$event['code'] = $obj->code;
|
||||||
$event['label'] = $obj->label;
|
$event['label'] = $obj->label;
|
||||||
$event['location'] = $obj->location;
|
$event['location'] = $obj->location;
|
||||||
$event['date'] = $db->jdate($obj->dateremind);
|
$event['reminder_date_formated'] = dol_print_date($db->jdate($obj->dateremind), 'standard');
|
||||||
|
$event['event_date_start_formated'] = dol_print_date($db->jdate($obj->datep), 'standard');
|
||||||
|
|
||||||
$eventfound[] = $event;
|
$eventfound[] = $event;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP
|
|||||||
|
|
||||||
/* Check if permission ok */
|
/* Check if permission ok */
|
||||||
if (Notification.permission !== "granted") {
|
if (Notification.permission !== "granted") {
|
||||||
|
console.log("Ask Notification.permission");
|
||||||
Notification.requestPermission()
|
Notification.requestPermission()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +66,7 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP
|
|||||||
function check_events() {
|
function check_events() {
|
||||||
if (Notification.permission === "granted")
|
if (Notification.permission === "granted")
|
||||||
{
|
{
|
||||||
console.log("Call check_events time_js_next_test = date we are looking for event after ="+time_js_next_test);
|
console.log("Call check_events time_js_next_test = date we are looking for event after this date = "+time_js_next_test);
|
||||||
$.ajax("<?php print DOL_URL_ROOT.'/core/ajax/check_notifications.php'; ?>", {
|
$.ajax("<?php print DOL_URL_ROOT.'/core/ajax/check_notifications.php'; ?>", {
|
||||||
type: "post", // Usually post or get
|
type: "post", // Usually post or get
|
||||||
async: true,
|
async: true,
|
||||||
@@ -84,13 +85,13 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP
|
|||||||
$.each(arr, function (index, value) {
|
$.each(arr, function (index, value) {
|
||||||
var url = "notdefined";
|
var url = "notdefined";
|
||||||
var title = "Not defined";
|
var title = "Not defined";
|
||||||
var body = value['tipo'] + ': ' + value['titulo'];
|
var body = value['type'] + ': ' + value['label'];
|
||||||
if (value['type'] == 'agenda' && value['location'] != null && value['location'] != '') {
|
if (value['type'] == 'agenda' && value['location'] != null && value['location'] != '') {
|
||||||
body += '\n' + value['location'];
|
body += '\n' + value['location'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(value['type'] == 'agenda' && (value['date'] != null || value['date'] != '')) {
|
if(value['type'] == 'agenda' && (value['event_date_start_formated'] != null || event_date_start_formated['event_date_start'] != '')) {
|
||||||
body += '\n' + value['date'];
|
body += '\n' + value['event_date_start_formated'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value['type'] == 'agenda')
|
if (value['type'] == 'agenda')
|
||||||
@@ -105,6 +106,7 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP
|
|||||||
};
|
};
|
||||||
|
|
||||||
// We release the notify
|
// We release the notify
|
||||||
|
console.log("Send notification on browser");
|
||||||
var noti = new Notification(title, extra);
|
var noti = new Notification(title, extra);
|
||||||
if (index==0 && audio)
|
if (index==0 && audio)
|
||||||
{
|
{
|
||||||
@@ -113,19 +115,20 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP
|
|||||||
|
|
||||||
if (noti) {
|
if (noti) {
|
||||||
noti.onclick = function (event) {
|
noti.onclick = function (event) {
|
||||||
console.log("An event to notify on browser was received");
|
console.log("A click on notification on browser has been done");
|
||||||
event.preventDefault(); // prevent the browser from focusing the Notification's tab
|
event.preventDefault(); // prevent the browser from focusing the Notification's tab
|
||||||
window.focus();
|
window.focus();
|
||||||
window.open(url, '_blank');
|
window.open(url, '_blank');
|
||||||
noti.close();
|
noti.close();
|
||||||
};
|
};
|
||||||
|
|
||||||
listofreminderids = listofreminderids + ',' + value['id']
|
listofreminderids = listofreminderids + '-' + value['id_reminder']
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update status of all notifications we sent on browser (listofreminderids)
|
// Update status of all notifications we sent on browser (listofreminderids)
|
||||||
$.ajax("<?php print DOL_URL_ROOT.'/core/ajax/check_notifications.php?action=stopreminder&listofreminderis='; ?>"+listofreminderids, {
|
console.log("Flag notification as done for listofreminderids="+listofreminderids);
|
||||||
|
$.ajax("<?php print DOL_URL_ROOT.'/core/ajax/check_notifications.php?action=stopreminder&listofreminderids='; ?>"+listofreminderids, {
|
||||||
type: "get", // Usually post or get
|
type: "get", // Usually post or get
|
||||||
async: true,
|
async: true,
|
||||||
data: {time: time_js_next_test}
|
data: {time: time_js_next_test}
|
||||||
@@ -136,7 +139,7 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
console.log("Cancel check_events. Useless because Notification.permission is "+Notification.permission);
|
console.log("Cancel check_events. Useless because javascript Notification.permission is "+Notification.permission+".");
|
||||||
}
|
}
|
||||||
|
|
||||||
time_js_next_test += time_auto_update;
|
time_js_next_test += time_auto_update;
|
||||||
|
|||||||
Reference in New Issue
Block a user