forked from Wavyzz/dolibarr
Work on browser notification
This commit is contained in:
@@ -46,8 +46,8 @@ 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 = (int) GETPOST('time', 'int'); // Use the time parameter that is always increased by time_update, even if call is late
|
||||||
//$time=dol_now();
|
$time=dol_now();
|
||||||
$action = GETPOST('action', 'aZ09');
|
$action = GETPOST('action', 'aZ09');
|
||||||
$listofreminderids = GETPOST('listofreminderids', 'aZ09');
|
$listofreminderids = GETPOST('listofreminderids', 'aZ09');
|
||||||
|
|
||||||
@@ -58,18 +58,20 @@ $listofreminderids = GETPOST('listofreminderids', 'aZ09');
|
|||||||
|
|
||||||
if ($action == 'stopreminder') {
|
if ($action == 'stopreminder') {
|
||||||
dol_syslog("Clear notification for listofreminderids=".$listofreminderids);
|
dol_syslog("Clear notification for listofreminderids=".$listofreminderids);
|
||||||
$listofreminderidsarray = explode('-', GETPOST('listofreminderids', 'aZ09'));
|
$listofreminderid = GETPOST('listofreminderids', 'intcomma');
|
||||||
|
|
||||||
// Set the reminder as done
|
// Set the reminder as done
|
||||||
foreach ($listofreminderidsarray as $listofreminderid) {
|
foreach ($listofreminderidsarray as $listofreminderid) {
|
||||||
if (empty($listofreminderid)) continue;
|
if (empty($listofreminderid)) continue;
|
||||||
//$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'action_reminder WHERE rowid = '.$listofreminderid.' AND fk_user = '.$user->id;
|
//$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 = '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;
|
$sql .= ' WHERE status = 0 AND rowid IN ('.$db->sanitize($db->escape($listofreminderid)).')';
|
||||||
$resql = $db->query($sql);
|
$sql .= ' AND fk_user = '.$user->id.' AND entity = '.$conf->entity;
|
||||||
|
/* $resql = $db->query($sql);
|
||||||
if (!$resql) {
|
if (!$resql) {
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
|
include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
|
||||||
@@ -90,7 +92,7 @@ if ($action == 'stopreminder') {
|
|||||||
* View
|
* View
|
||||||
*/
|
*/
|
||||||
|
|
||||||
top_httphead('text/html'); // TODO Use a json mime type
|
top_httphead('application/json');
|
||||||
|
|
||||||
global $user, $db, $langs, $conf;
|
global $user, $db, $langs, $conf;
|
||||||
|
|
||||||
@@ -102,9 +104,9 @@ $eventfound = array();
|
|||||||
|
|
||||||
// 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.
|
// 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.
|
// This need to extend period to be sure to not miss and save in session what we notified to avoid duplicate.
|
||||||
if ($time >= $_SESSION['auto_check_events_not_before'] || GETPOST('forcechecknow', 'int'))
|
if (empty($_SESSION['auto_check_events_not_before']) || $time >= $_SESSION['auto_check_events_not_before'] || GETPOST('forcechecknow', 'int'))
|
||||||
{
|
{
|
||||||
$time_update = (int) $conf->global->MAIN_BROWSER_NOTIFICATION_FREQUENCY; // Always defined
|
/*$time_update = (int) $conf->global->MAIN_BROWSER_NOTIFICATION_FREQUENCY; // Always defined
|
||||||
if (!empty($_SESSION['auto_check_events_not_before']))
|
if (!empty($_SESSION['auto_check_events_not_before']))
|
||||||
{
|
{
|
||||||
// We start scan from the not before so if two tabs were opend at differents seconds and we close one (so the js timer),
|
// We start scan from the not before so if two tabs were opend at differents seconds and we close one (so the js timer),
|
||||||
@@ -121,6 +123,7 @@ if ($time >= $_SESSION['auto_check_events_not_before'] || GETPOST('forcechecknow
|
|||||||
}
|
}
|
||||||
|
|
||||||
$_SESSION['auto_check_events_not_before'] = $time + $time_update;
|
$_SESSION['auto_check_events_not_before'] = $time + $time_update;
|
||||||
|
*/
|
||||||
|
|
||||||
// Force save of the session change we did.
|
// Force save of the session change we did.
|
||||||
// WARNING: Any change in sessions after that will not be saved !
|
// WARNING: Any change in sessions after that will not be saved !
|
||||||
@@ -131,19 +134,20 @@ 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.datep, a.label, a.location, ar.rowid as id_reminder, ar.dateremind, ar.fk_user as id_user_reminder';
|
$sql = 'SELECT a.id as id_agenda, 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;
|
||||||
$sql .= ' WHERE a.code <> "AC_OTH_AUTO"';
|
$sql .= ' WHERE a.code <> "AC_OTH_AUTO"';
|
||||||
$sql .= ' AND (';
|
$sql .= ' AND (';
|
||||||
$sql .= " (ar.typeremind = 'browser' AND ar.dateremind < '".$db->idate(dol_now())."' AND ar.status = 0 AND ar.entity = ".$conf->entity;
|
$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 .= " OR (a.datep BETWEEN '".$db->idate($starttime)."' AND '".$db->idate($time + $time_update - 1)."')";
|
||||||
$sql .= ' )';
|
$sql .= ' )';
|
||||||
} else {
|
} else {
|
||||||
$sql .= ' JOIN '.MAIN_DB_PREFIX.'actioncomm_reminder as ar ON a.id = ar.fk_actioncomm AND ar.fk_user = '.$user->id;
|
$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 .= " AND ar.typeremind = 'browser' AND ar.dateremind < '".$db->idate(dol_now())."' AND ar.status = 0 AND ar.entity = ".$conf->entity;
|
||||||
}
|
}
|
||||||
|
$sql .= $db->order('datep', 'ASC');
|
||||||
$sql .= ' LIMIT 10'; // Avoid too many notification at once
|
$sql .= ' LIMIT 10'; // Avoid too many notification at once
|
||||||
|
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
@@ -162,11 +166,11 @@ if ($time >= $_SESSION['auto_check_events_not_before'] || GETPOST('forcechecknow
|
|||||||
$event['reminder_date_formated'] = dol_print_date($db->jdate($obj->dateremind), 'standard');
|
$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');
|
$event['event_date_start_formated'] = dol_print_date($db->jdate($obj->datep), 'standard');
|
||||||
|
|
||||||
$eventfound[] = $event;
|
$eventfound[$obj->id] = $event;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dol_syslog("Error sql = ".$db->lasterror(), LOG_ERR);
|
dol_syslog("Error sql = ".$db->lasterror(), LOG_ERR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print json_encode($eventfound);
|
print json_encode(array('pastreminders'=>$eventfound, 'nextreminder'=>''));
|
||||||
|
|||||||
@@ -74,10 +74,12 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP
|
|||||||
$.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,
|
||||||
data: { time_js_next_test: time_js_next_test },
|
data: { time_js_next_test: time_js_next_test, forcechecknow: 1, token: 'notrequired' },
|
||||||
|
dataType: "json",
|
||||||
success: function (result) {
|
success: function (result) {
|
||||||
var arr = JSON.parse(result);
|
console.log(result);
|
||||||
if (arr.length > 0) {
|
var arrayofpastreminders = Object.values(result.pastreminders);
|
||||||
|
if (arrayofpastreminders && arrayofpastreminders.length > 0) {
|
||||||
var audio = null;
|
var audio = null;
|
||||||
<?php
|
<?php
|
||||||
if (!empty($conf->global->AGENDA_REMINDER_BROWSER_SOUND)) {
|
if (!empty($conf->global->AGENDA_REMINDER_BROWSER_SOUND)) {
|
||||||
@@ -86,27 +88,29 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP
|
|||||||
?>
|
?>
|
||||||
var listofreminderids = '';
|
var listofreminderids = '';
|
||||||
|
|
||||||
$.each(arr, function (index, value) {
|
$.each(arrayofpastreminders, function (index, value) {
|
||||||
|
console.log(index);
|
||||||
|
console.log(value);
|
||||||
var url = "notdefined";
|
var url = "notdefined";
|
||||||
var title = "Not defined";
|
var title = "Not defined";
|
||||||
var body = value['type'] + ': ' + value['label'];
|
var body = 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['event_date_start_formated'] != null || event_date_start_formated['event_date_start'] != '')) {
|
if (value.type == 'agenda' && (value.event_date_start_formated != null || value.event_date_start_formated['event_date_start'] != '')) {
|
||||||
body += '\n' + value['event_date_start_formated'];
|
body += '\n' + value.event_date_start_formated;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value['type'] == 'agenda')
|
if (value.type == 'agenda')
|
||||||
{
|
{
|
||||||
url = '<?php echo DOL_URL_ROOT.'/comm/action/card.php?id='; ?>' + value['id'];
|
url = '<?php echo DOL_URL_ROOT.'/comm/action/card.php?id='; ?>' + value.id;
|
||||||
title = '<?php print $langs->trans('Agenda') ?>';
|
title = '<?php print $langs->trans('AgendaReminder') ?>';
|
||||||
}
|
}
|
||||||
var extra = {
|
var extra = {
|
||||||
icon: '<?php print DOL_URL_ROOT.'/theme/common/bell.png'; ?>',
|
icon: '<?php print DOL_URL_ROOT.'/theme/common/bell.png'; ?>',
|
||||||
body: body,
|
body: body,
|
||||||
tag: value['id']
|
tag: value.id
|
||||||
};
|
};
|
||||||
|
|
||||||
// We release the notify
|
// We release the notify
|
||||||
@@ -126,7 +130,7 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP
|
|||||||
noti.close();
|
noti.close();
|
||||||
};
|
};
|
||||||
|
|
||||||
listofreminderids = listofreminderids + '-' + value['id_reminder']
|
listofreminderids = (listofreminderids == '' ? '' : listofreminderids + ',') + value.id_reminder
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -135,8 +139,10 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP
|
|||||||
$.ajax("<?php print DOL_URL_ROOT.'/core/ajax/check_notifications.php?action=stopreminder&listofreminderids='; ?>"+listofreminderids, {
|
$.ajax("<?php print DOL_URL_ROOT.'/core/ajax/check_notifications.php?action=stopreminder&listofreminderids='; ?>"+listofreminderids, {
|
||||||
type: "post", // Usually post or get
|
type: "post", // Usually post or get
|
||||||
async: true,
|
async: true,
|
||||||
data: { time_js_next_test: time_js_next_test }
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user