diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index a88f673405c..2df88f51c0d 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -62,13 +62,11 @@ class Notify */ public $fk_project; - // Les codes actions sont definis dans la table llx_notify_def - - // codes actions supported are - // @todo defined also into interface_50_modNotification_Notification.class.php - public $arrayofnotifsupported = array( + // This codes actions are defined into table llx_notify_def + static public $arrayofnotifsupported = array( 'BILL_VALIDATE', 'BILL_PAYED', + 'ORDER_CREATE', 'ORDER_VALIDATE', 'PROPAL_VALIDATE', 'PROPAL_CLOSE_SIGNED', diff --git a/htdocs/core/js/lib_notification.js.php b/htdocs/core/js/lib_notification.js.php index ee41555119a..f4a4e59526a 100644 --- a/htdocs/core/js/lib_notification.js.php +++ b/htdocs/core/js/lib_notification.js.php @@ -68,22 +68,27 @@ print ' var time_auto_update = '.$conf->global->MAIN_BROWSER_NOTIFICATION_FREQUE print ' var time_js_next_test;'."\n"; ?> -/* Check if permission ok */ -if (Notification.permission !== "granted") { - console.log("Ask Notification.permission"); - Notification.requestPermission() +/* Check if Notification is supported */ +if ("Notification" in window) { + /* Check if permission ok */ + if (Notification.permission !== "granted") { + console.log("Ask Notification.permission"); + Notification.requestPermission() + } + + /* Launch timer */ + + // We set a delay before launching first test so next check will arrive after the time_auto_update compared to previous one. + //var time_first_execution = (time_auto_update + (time_js_next_test - nowtime)) * 1000; //need milliseconds + var time_first_execution = global->MAIN_BROWSER_NOTIFICATION_CHECK_FIRST_EXECUTION) ? 0 : $conf->global->MAIN_BROWSER_NOTIFICATION_CHECK_FIRST_EXECUTION); ?>; + + setTimeout(first_execution, time_first_execution * 1000); + time_js_next_test = nowtime + time_first_execution; + console.log("Launch browser notif check: setTimeout is set to launch 'first_execution' function after a wait of time_first_execution="+time_first_execution+". nowtime (time php page generation) = "+nowtime+" time_js_next_check = "+time_js_next_test); +} else { + console.log("This browser in this context does not support Notification."); } -/* Launch timer */ - -// We set a delay before launching first test so next check will arrive after the time_auto_update compared to previous one. -//var time_first_execution = (time_auto_update + (time_js_next_test - nowtime)) * 1000; //need milliseconds -var time_first_execution = global->MAIN_BROWSER_NOTIFICATION_CHECK_FIRST_EXECUTION) ? 0 : $conf->global->MAIN_BROWSER_NOTIFICATION_CHECK_FIRST_EXECUTION); ?>; - -setTimeout(first_execution, time_first_execution * 1000); -time_js_next_test = nowtime + time_first_execution; -console.log("Launch browser notif check: setTimeout is set to launch 'first_execution' function after a wait of time_first_execution="+time_first_execution+". nowtime (time php page generation) = "+nowtime+" time_js_next_check = "+time_js_next_test); - function first_execution() { console.log("Call first_execution then set repeat time to time_auto_update = MAIN_BROWSER_NOTIFICATION_FREQUENCY = "+time_auto_update); diff --git a/htdocs/core/triggers/interface_50_modNotification_Notification.class.php b/htdocs/core/triggers/interface_50_modNotification_Notification.class.php index e2b359809dd..fe89a05ab20 100644 --- a/htdocs/core/triggers/interface_50_modNotification_Notification.class.php +++ b/htdocs/core/triggers/interface_50_modNotification_Notification.class.php @@ -23,6 +23,7 @@ * \brief File of class of triggers for notification module */ require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php'; +include_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php'; /** @@ -30,26 +31,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php'; */ class InterfaceNotification extends DolibarrTriggers { - // @todo Defined also into notify.class.php - public $listofmanagedevents = array( - 'BILL_VALIDATE', - 'BILL_PAYED', - 'ORDER_CREATE', - 'ORDER_VALIDATE', - 'PROPAL_VALIDATE', - 'PROPAL_CLOSE_SIGNED', - 'FICHINTER_VALIDATE', - 'FICHINTER_ADD_CONTACT', - 'ORDER_SUPPLIER_VALIDATE', - 'ORDER_SUPPLIER_APPROVE', - 'ORDER_SUPPLIER_REFUSE', - 'SHIPPING_VALIDATE', - 'EXPENSE_REPORT_VALIDATE', - 'EXPENSE_REPORT_APPROVE', - 'HOLIDAY_VALIDATE', - 'HOLIDAY_APPROVE', - 'ACTION_CREATE' - ); + public $listofmanagedevents = array(); /** * Constructor @@ -66,6 +48,8 @@ class InterfaceNotification extends DolibarrTriggers // 'development', 'experimental', 'dolibarr' or version $this->version = self::VERSION_DOLIBARR; $this->picto = 'email'; + + $this->listofmanagedevents = Notify::$arrayofnotifsupported; } /** @@ -85,15 +69,13 @@ class InterfaceNotification extends DolibarrTriggers return 0; // Module not active, we do nothing } - require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php'; - $notify = new Notify($this->db); - - if (!in_array($action, $notify->arrayofnotifsupported)) { + if (!in_array($action, $this->listofmanagedevents)) { return 0; } dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $notify = new Notify($this->db); $notify->send($action, $object); return 1; @@ -114,6 +96,7 @@ class InterfaceNotification extends DolibarrTriggers $sql = "SELECT rowid, code, label, description, elementtype"; $sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger"; $sql .= $this->db->order("rang, elementtype, code"); + dol_syslog("getListOfManagedEvents Get list of notifications", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) {