diff --git a/htdocs/admin/agenda_other.php b/htdocs/admin/agenda_other.php index 9406f8ecc5d..2835d17e2fe 100644 --- a/htdocs/admin/agenda_other.php +++ b/htdocs/admin/agenda_other.php @@ -1,7 +1,7 @@ * Copyright (C) 2011 Regis Houssin - * Copyright (C) 2011-2013 Juanjo Menent + * Copyright (C) 2011-2017 Juanjo Menent * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2016 Charlie Benke * @@ -407,6 +407,34 @@ $tmplist=array('show_month'=>$langs->trans("ViewCal"), 'show_week'=>$langs->tran print $form->selectarray('AGENDA_DEFAULT_VIEW', $tmplist, $conf->global->AGENDA_DEFAULT_VIEW); print ''."\n"; +// AGENDA NOTIFICATION +$var=!$var; +print ''."\n"; +print ''.$langs->trans('AGENDA_NOTIFICATION').''."\n"; +print ' '."\n"; +print ''."\n"; + +if (empty($conf->global->AGENDA_NOTIFICATION)) { + print ''.img_picto($langs->trans('Disabled'),'switch_off').''; + print ''."\n"; +} else { + print ''.img_picto($langs->trans('Enabled'),'switch_on').''; + print ''."\n"; + $var=!$var; + print ''."\n"; + print ''.$langs->trans('AGENDA_NOTIFICATION_SOUND').''."\n"; + print ' '."\n"; + print ''."\n"; + + if (empty($conf->global->AGENDA_NOTIFICATION_SOUND)) { + print ''.img_picto($langs->trans('Disabled'),'switch_off').''; + } else { + print ''.img_picto($langs->trans('Enabled'),'switch_on').''; + } + + print ''."\n"; +} + print ''; dol_fiche_end(); @@ -415,7 +443,6 @@ print '
'; - print "
"; llxFooter(); diff --git a/htdocs/comm/action/sound/notification.mp3 b/htdocs/comm/action/sound/notification.mp3 new file mode 100644 index 00000000000..c58e664fd9e Binary files /dev/null and b/htdocs/comm/action/sound/notification.mp3 differ diff --git a/htdocs/core/ajax/check_events.php b/htdocs/core/ajax/check_events.php new file mode 100644 index 00000000000..03787c92f52 --- /dev/null +++ b/htdocs/core/ajax/check_events.php @@ -0,0 +1,70 @@ + + * Copyright (C) 2017 Juanjo Menent + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; + +global $user, $db, $langs, $conf; + +$time = GETPOST('time'); + +session_start(); + +//TODO Configure how long the upgrade will take +$time_update = 60; + +if (! empty($conf->global->AGENDA_NOTIFICATION)) { + if ($_SESSION['auto_check_events'] <= (int) $time) { + $_SESSION['auto_check_events'] = $time + $time_update; + + $eventos = array(); + + $sql = 'SELECT id'; + $sql .= ' FROM ' . MAIN_DB_PREFIX . 'actioncomm a, ' . MAIN_DB_PREFIX . 'actioncomm_resources ar'; + $sql .= ' WHERE datep BETWEEN ' . $db->idate($time + 1) . ' AND ' . $db->idate($time + $time_update); + $sql .= ' AND a.id = ar.fk_actioncomm'; + $sql .= ' AND a.code <> "AC_OTH_AUTO"'; + $sql .= ' AND ar.element_type = "user"'; + $sql .= ' AND ar.fk_element = ' . $user->id; + + $resql = $db->query($sql); + + if ($resql) { + + $actionmod = new ActionComm($db); + + while ($obj = $db->fetch_object($resql)) { + + $event = array(); + + $actionmod->fetch($obj->id); + + $event['id'] = $actionmod->id; + $event['tipo'] = $langs->transnoentities('Action' . $actionmod->code); + $event['titulo'] = $actionmod->label; + $event['location'] = $actionmod->location; + $eventos[] = $event; + $actionmod->initAsSpecimen(); + + } + } + + print json_encode($eventos); + } +} \ No newline at end of file diff --git a/htdocs/core/js/agenda_notification.js.php b/htdocs/core/js/agenda_notification.js.php new file mode 100644 index 00000000000..ad4b8cf1bdf --- /dev/null +++ b/htdocs/core/js/agenda_notification.js.php @@ -0,0 +1,133 @@ + + * Copyright (C) 2017 Juanjo Menent + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * +*/ +if (!defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); +if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); +if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', 1); +if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1); +if (!defined('NOLOGIN')) define('NOLOGIN', 1); +if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', 1); +if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', 1); + +session_cache_limiter(FALSE); + +require_once '../../main.inc.php'; + +if(!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root . '/' || $_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root . '/index.php')){ + + global $langs, $conf; + + $langs->load('agenda'); + + // Define javascript type + header('Content-type: text/javascript; charset=UTF-8'); + header('Cache-Control: no-cache'); + + // Check notification permissions API HTML5 + print 'if (Notification.permission !== "granted") { + Notification.requestPermission() + }' . PHP_EOL; + + session_start(); + if (!isset($_SESSION['auto_check_events'])) { + + // Round to eliminate the second part + $_SESSION['auto_check_events'] = floor(time() / 60) * 60; + print 'var time_session = ' . $_SESSION['auto_check_events'] . ';' . PHP_EOL; + print 'var now = ' . $_SESSION['auto_check_events'] . ';' . PHP_EOL; + } else { + + print 'var time_session = ' . $_SESSION['auto_check_events'] . ';' . PHP_EOL; + print 'var now = ' . time() . ';' . PHP_EOL; + } + + //TODO provisionally set to be checked every 60 seconds, the 1000 is because it needs to be in milliseconds + print 'var time_auto_update = 60;' . "\n"; + ?> + + + if (now > (time_session + time_auto_update) || now == time_session) { + + first_execution(); //firts run auto check + } else { + + var time_first_execution = (time_auto_update - (now - time_session)) * 1000; + + setTimeout(first_execution, time_first_execution); //firts run auto check + } + + + function first_execution() { + check_events(); + setInterval(check_events, time_auto_update * 1000); //program time for run check events + } + + function check_events() { + + $.ajax("", { + type: "post", // Usually post o get + async: true, + data: {time: time_session}, + success: function (result) { + + var arr = JSON.parse(result); + + if (arr.length > 0) { + if (Notification.permission === "granted") { + + global->AGENDA_NOTIFICATION_SOUND){ + print 'var audio = new Audio(\''.dol_buildpath('/comm/action/sound/notification.mp3', 1).'\');'; + } + ?> + + $.each(arr, function (index, value) { + var body = value['tipo'] + ': ' + value['titulo']; + if (value['location'] != null) { + body += '\n transnoentities('Location')?>: ' + value['location']; + } + + + var title = "trans('Agenda') ?>"; + var extra = { + icon: "", + body: body, + tag: value['id'] + }; + + // We release the notify + var noti = new Notification(title, extra); + global->AGENDA_NOTIFICATION_SOUND){ + print 'if(index==0)audio.play();'."\n"; + } + ?> + noti.onclick = function (event) { + event.preventDefault(); // prevent the browser from focusing the Notification's tab + window.focus(); + window.open("" + value['id'], '_blank'); + noti.close(); + }; + }); + } + } + } + }); + time_session += time_auto_update; + } + * Copyright (C) 2013 Cedric Gross * Copyright (C) 2015 Bahfir Abbes + * Copyright (C) 2017 Juanjo Menent * * 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 @@ -73,6 +74,9 @@ class modAgenda extends DolibarrModules $this->requiredby = array(); $this->langfiles = array("companies"); + // Module parts + $this->module_parts = array('js' => array('/core/js/agenda_notification.js.php')); + // Constants //----------- $this->const = array(); diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index d64c0be57c1..fcb4df82669 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1475,6 +1475,8 @@ AGENDA_USE_EVENT_TYPE_DEFAULT=Set automatically this default value for type of e AGENDA_DEFAULT_FILTER_TYPE=Set automatically this type of event into search filter of agenda view AGENDA_DEFAULT_FILTER_STATUS=Set automatically this status for events into search filter of agenda view AGENDA_DEFAULT_VIEW=Which tab do you want to open by default when selecting menu Agenda +AGENDA_NOTIFICATION=Enable events notification +AGENDA_NOTIFICATION_SOUND=Enable sound on notifications ##### ClickToDial ##### ClickToDialDesc=This module allows to make phone numbers clickable. A click on this icon will call make your phone to call the phone number. This can be used to call a call center system from Dolibarr that can call the phone number on a SIP system for example. ClickToDialUseTelLink=Use just a link "tel:" on phone numbers diff --git a/htdocs/theme/common/bell.png b/htdocs/theme/common/bell.png new file mode 100644 index 00000000000..2397118a68a Binary files /dev/null and b/htdocs/theme/common/bell.png differ