Merge pull request #6272 from simnandez/develop

NEW: Event notifications in browser
This commit is contained in:
Laurent Destailleur 2017-01-20 18:14:21 +01:00 committed by GitHub
commit b602e04fc8
7 changed files with 238 additions and 2 deletions

View File

@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2008-2016 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2011 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2011-2017 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.com>
*
@ -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 '</td></tr>'."\n";
// AGENDA NOTIFICATION
$var=!$var;
print '<tr '.$bc[$var].'>'."\n";
print '<td>'.$langs->trans('AGENDA_NOTIFICATION').'</td>'."\n";
print '<td align="center">&nbsp;</td>'."\n";
print '<td align="right">'."\n";
if (empty($conf->global->AGENDA_NOTIFICATION)) {
print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_AGENDA_NOTIFICATION">'.img_picto($langs->trans('Disabled'),'switch_off').'</a>';
print '</td></tr>'."\n";
} else {
print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_AGENDA_NOTIFICATION">'.img_picto($langs->trans('Enabled'),'switch_on').'</a>';
print '</td></tr>'."\n";
$var=!$var;
print '<tr '.$bc[$var].'>'."\n";
print '<td>'.$langs->trans('AGENDA_NOTIFICATION_SOUND').'</td>'."\n";
print '<td align="center">&nbsp;</td>'."\n";
print '<td align="right">'."\n";
if (empty($conf->global->AGENDA_NOTIFICATION_SOUND)) {
print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_AGENDA_NOTIFICATION_SOUND">'.img_picto($langs->trans('Disabled'),'switch_off').'</a>';
} else {
print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_AGENDA_NOTIFICATION_SOUND">'.img_picto($langs->trans('Enabled'),'switch_on').'</a>';
}
print '</td></tr>'."\n";
}
print '</table>';
dol_fiche_end();
@ -415,7 +443,6 @@ print '<div class="center"><input class="button" type="submit" name="save" value
print '</form>';
print "<br>";
llxFooter();

Binary file not shown.

View File

@ -0,0 +1,70 @@
<?php
/* Copyright (C) 2016 Sergio Sanchis <sergiosanchis@hotmail.com>
* Copyright (C) 2017 Juanjo Menent <jmenent@2byte.es>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
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);
}
}

View File

@ -0,0 +1,133 @@
<?php
/* Copyright (C) 2016 Sergio Sanchis <sergiosanchis@hotmail.com>
* Copyright (C) 2017 Juanjo Menent <jmenent@2byte.es>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
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("<?php print dol_buildpath('/core/ajax/check_events.php', 1); ?>", {
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") {
<?php
if($conf->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 <?php print $langs->transnoentities('Location')?>: ' + value['location'];
}
var title = "<?php print $langs->trans('Agenda') ?>";
var extra = {
icon: "<?php print dol_buildpath('/theme/common/bell.png', 1); ?>",
body: body,
tag: value['id']
};
// We release the notify
var noti = new Notification(title, extra);
<?php
if($conf->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("<?php print dol_buildpath('/comm/action/card.php?id=', 1); ?>" + value['id'], '_blank');
noti.close();
};
});
}
}
}
});
time_session += time_auto_update;
}
<?php }

View File

@ -7,6 +7,7 @@
* Copyright (C) 2009-2011 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2013 Cedric Gross <c.gross@kreiz-it.fr>
* Copyright (C) 2015 Bahfir Abbes <bafbes@gmail.com>
* Copyright (C) 2017 Juanjo Menent <jmenent@2byte.es>
*
* 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();

View File

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 509 B