diff --git a/htdocs/core/ajax/check_notifications.php b/htdocs/core/ajax/check_notifications.php index a9432f3cd6c..c2317e13800 100644 --- a/htdocs/core/ajax/check_notifications.php +++ b/htdocs/core/ajax/check_notifications.php @@ -61,18 +61,17 @@ if ($action == 'stopreminder') { $listofreminderid = GETPOST('listofreminderids', 'intcomma'); // Set the reminder as done - foreach ($listofreminderidsarray as $listofreminderid) { - if (empty($listofreminderid)) continue; + //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 IN ('.$db->sanitize($db->escape($listofreminderid)).')'; $sql .= ' AND fk_user = '.$user->id.' AND entity = '.$conf->entity; -/* $resql = $db->query($sql); + $resql = $db->query($sql); if (!$resql) { dol_print_error($db); } -*/ - } + //} include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; @@ -141,7 +140,6 @@ if (empty($_SESSION['auto_check_events_not_before']) || $time >= $_SESSION['auto $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; @@ -157,8 +155,8 @@ if (empty($_SESSION['auto_check_events_not_before']) || $time >= $_SESSION['auto // Message must be formated and translated to be used with javascript directly $event = array(); $event['type'] = 'agenda'; - $event['id'] = $obj->id; $event['id_reminder'] = $obj->id_reminder; + $event['id_agenda'] = $obj->id_agenda; $event['id_user'] = $obj->id_user_reminder; $event['code'] = $obj->code; $event['label'] = $obj->label; @@ -166,7 +164,7 @@ if (empty($_SESSION['auto_check_events_not_before']) || $time >= $_SESSION['auto $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[$obj->id] = $event; + $eventfound[$obj->id_agenda] = $event; } } else { dol_syslog("Error sql = ".$db->lasterror(), LOG_ERR); diff --git a/htdocs/core/js/lib_notification.js.php b/htdocs/core/js/lib_notification.js.php index a3547e79c3f..a95e3556405 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 success: function (result) { console.log(result); var arrayofpastreminders = Object.values(result.pastreminders); + console.log("arrayofpastreminders.length"+arrayofpastreminders.length); if (arrayofpastreminders && arrayofpastreminders.length > 0) { var audio = null; var listofreminderids = ''; + var noti = [] $.each(arrayofpastreminders, function (index, value) { - console.log(index); console.log(value); var url = "notdefined"; var title = "Not defined"; @@ -104,30 +105,32 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP if (value.type == 'agenda') { - url = '' + value.id; - title = 'trans('AgendaReminder') ?>'; + url = '' + value.id_agenda; + title = 'trans('EventReminder') ?>'; } var extra = { icon: '', + //image: '', body: body, - tag: value.id + tag: value.id_agenda, + requireInteraction: true }; // We release the notify console.log("Send notification on browser"); - var noti = new Notification(title, extra); + noti[index] = new Notification(title, extra); if (index==0 && audio) { audio.play(); } - if (noti) { - noti.onclick = function (event) { + if (noti[index]) { + noti[index].onclick = function (event) { console.log("A click on notification on browser has been done"); event.preventDefault(); // prevent the browser from focusing the Notification's tab window.focus(); window.open(url, '_blank'); - noti.close(); + noti[index].close(); }; listofreminderids = (listofreminderids == '' ? '' : listofreminderids + ',') + value.id_reminder @@ -140,7 +143,7 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP type: "post", // Usually post or get async: true, data: { time_js_next_test: time_js_next_test, token: 'notrequired' } - }); + }); } else { console.log("No past reminder found, next try at "+time_js_next_test); }