2
0
forked from Wavyzz/dolibarr

New: Trigger now have a priority to define sort execution order.

This commit is contained in:
Laurent Destailleur
2012-01-31 20:32:26 +01:00
parent 7d0a41f3cf
commit 0011b1dadd
17 changed files with 113 additions and 2562 deletions

View File

@@ -107,7 +107,7 @@ Source: "C:\Program Files\Wamp\bin\mysql\mysql5.0.45\*.*"; DestDir: "{app}\bin\m
; Mysql data files (does not overwrite if exists) ; Mysql data files (does not overwrite if exists)
Source: "build\exe\doliwamp\mysql\*.*"; DestDir: "{app}\bin\mysql\data\mysql"; Flags: onlyifdoesntexist ignoreversion recursesubdirs; Excludes: ".cvsignore,.project,CVS\*,Thumbs.db" Source: "build\exe\doliwamp\mysql\*.*"; DestDir: "{app}\bin\mysql\data\mysql"; Flags: onlyifdoesntexist ignoreversion recursesubdirs; Excludes: ".cvsignore,.project,CVS\*,Thumbs.db"
; Dolibarr ; Dolibarr
Source: "htdocs\*.*"; DestDir: "{app}\www\dolibarr\htdocs"; Flags: ignoreversion recursesubdirs; Excludes: ".cvsignore,.project,CVS\*,Thumbs.db,custom\*,custom2\*,telephonie\*,*\conf.php,*\conf.php.mysql,*\conf.php.old,*\conf.php.postgres,*\install.forced.php,*\modBookmark4u.class.php,*\modDocument.class.php,*\modDroitPret.class.php,*\modEditeur.class.php,*\modPostnuke.class.php,*\modTelephonie.class.php,*\interface_modEditeur_Editeur.class.php*,*\bureau2crea,*\rodolphe" Source: "htdocs\*.*"; DestDir: "{app}\www\dolibarr\htdocs"; Flags: ignoreversion recursesubdirs; Excludes: ".cvsignore,.project,CVS\*,Thumbs.db,custom\*,custom2\*,telephonie\*,*\conf.php,*\conf.php.mysql,*\conf.php.old,*\conf.php.postgres,*\install.forced.php"
Source: "dev\*.*"; DestDir: "{app}\www\dolibarr\dev"; Flags: ignoreversion recursesubdirs; Excludes: ".cvsignore,.project,CVS\*,Thumbs.db,dbmodel\*,fpdf\*,initdata\*,iso-normes\*,licence\*,phpcheckstyle\*,phpunit\*,samples\*,test\*,uml\*,xdebug\*" Source: "dev\*.*"; DestDir: "{app}\www\dolibarr\dev"; Flags: ignoreversion recursesubdirs; Excludes: ".cvsignore,.project,CVS\*,Thumbs.db,dbmodel\*,fpdf\*,initdata\*,iso-normes\*,licence\*,phpcheckstyle\*,phpunit\*,samples\*,test\*,uml\*,xdebug\*"
Source: "doc\*.*"; DestDir: "{app}\www\dolibarr\doc"; Flags: ignoreversion recursesubdirs; Excludes: ".cvsignore,.project,CVS\*,Thumbs.db,wiki\*,plaquette\*,dev\*,images\dolibarr_screenshot2.png,images\dolibarr_screenshot3.png,images\dolibarr_screenshot4.png,images\dolibarr_screenshot5.png,images\dolibarr_screenshot6.png,images\dolibarr_screenshot7.png,images\dolibarr_screenshot8.png,images\dolibarr_screenshot9.png,images\dolibarr_screenshot10.png,images\dolibarr_screenshot11.png,images\dolibarr_screenshot12.png" Source: "doc\*.*"; DestDir: "{app}\www\dolibarr\doc"; Flags: ignoreversion recursesubdirs; Excludes: ".cvsignore,.project,CVS\*,Thumbs.db,wiki\*,plaquette\*,dev\*,images\dolibarr_screenshot2.png,images\dolibarr_screenshot3.png,images\dolibarr_screenshot4.png,images\dolibarr_screenshot5.png,images\dolibarr_screenshot6.png,images\dolibarr_screenshot7.png,images\dolibarr_screenshot8.png,images\dolibarr_screenshot9.png,images\dolibarr_screenshot10.png,images\dolibarr_screenshot11.png,images\dolibarr_screenshot12.png"
Source: "scripts\*.*"; DestDir: "{app}\www\dolibarr\scripts"; Flags: ignoreversion recursesubdirs; Excludes: ".cvsignore,.project,CVS\*,Thumbs.db,product\materiel.net.php,product\import-product.php" Source: "scripts\*.*"; DestDir: "{app}\www\dolibarr\scripts"; Flags: ignoreversion recursesubdirs; Excludes: ".cvsignore,.project,CVS\*,Thumbs.db,product\materiel.net.php,product\import-product.php"

View File

@@ -3,13 +3,13 @@
# Goal: Goal of module # Goal: Goal of module
# Version: 1.0 # Version: 1.0
# Author: Copyright 2008 - Author name here # Author: Copyright 2008 - Author name here
# Licence: Not yet defined # Licence: GPL
# Install: Just unpack content of module package in Dolibarr directory. # Install: Just unpack content of module package in Dolibarr directory.
# Setup: Go on Dolibarr setup - modules page to enable module. # Setup: Go on Dolibarr setup - modules to enable module.
# #
# Files in module # Files in module
htdocs/core/modules/modMyModule.class.php htdocs/mymodule/core/modules/modMyModule.class.php
htdocs/core/triggers/interface_mymodule.class.php htdocs/mymodule/core/triggers/interface_mymodule.class.php
htdocs/mymodule/page1.php htdocs/mymodule/page1.php
htdocs/mymodule/page2.php htdocs/mymodule/page2.php
htdocs/mymodule/sql/script1.sql htdocs/mymodule/sql/script1.sql

View File

@@ -31,15 +31,6 @@ htdocs/conf/conf.php.mysql
htdocs/conf/conf.php.old htdocs/conf/conf.php.old
htdocs/conf/conf.php.postgres htdocs/conf/conf.php.postgres
htdocs/avoir htdocs/avoir
htdocs/core/modules/modBookmark4u.class.php
htdocs/core/modules/modDocument.class.php
htdocs/core/modules/modDroitPret.class.php
htdocs/core/modules/modEditeur.class.php
htdocs/core/modules/modPostnuke.class.php
htdocs/core/modules/modTelephonie.class.php
htdocs/core/triggers/interface_user.class.php
htdocs/core/triggers/interface_contractfrombill.class.php-NORUN
htdocs/core/triggers/interface_modEditeur_Editeur.class.php-NORUN
htdocs/custom htdocs/custom
htdocs/custom2 htdocs/custom2
htdocs/customleave htdocs/customleave

View File

@@ -27,15 +27,6 @@
*/htdocs/conf/conf.php.mysql */htdocs/conf/conf.php.mysql
*/htdocs/conf/conf.php.old */htdocs/conf/conf.php.old
*/htdocs/conf/conf.php.postgres */htdocs/conf/conf.php.postgres
*/htdocs/core/modules/modBookmark4u.class.php
*/htdocs/core/modules/modClickToDial.class.php
*/htdocs/core/modules/modDocument.class.php
*/htdocs/core/modules/modDomain.class.php
*/htdocs/core/modules/modDroitPret.class.php
*/htdocs/core/modules/modEditeur.class.php
*/htdocs/core/modules/modPostnuke.class.php
*/htdocs/core/triggers/interface_user.class.php
*/htdocs/core/triggers/interface_contractfrombill.class.php-NORUN
*/htdocs/custom/* */htdocs/custom/*
*/htdocs/custom2/* */htdocs/custom2/*
*/htdocs/document/* */htdocs/document/*

View File

@@ -24,7 +24,7 @@
require("../main.inc.php"); require("../main.inc.php");
require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php"); require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php");
require_once(DOL_DOCUMENT_ROOT."/core/triggers/interface_modNotification_Notification.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/triggers/interface_50_modNotification_Notification.class.php");
$langs->load("admin"); $langs->load("admin");
$langs->load("other"); $langs->load("other");

View File

@@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2005-2007 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -17,7 +17,7 @@
/** /**
* \file htdocs/admin/triggers.php * \file htdocs/admin/triggers.php
* \brief Page de configuration et activation des triggers * \brief Page to view triggers
*/ */
require("../main.inc.php"); require("../main.inc.php");
@@ -25,13 +25,13 @@ require_once(DOL_DOCUMENT_ROOT."/core/class/interfaces.class.php");
$langs->load("admin"); $langs->load("admin");
if (!$user->admin) if (!$user->admin) accessforbidden();
accessforbidden();
/* /*
* Action * Action
*/ */
// None
/* /*
@@ -50,9 +50,11 @@ print "<br>\n";
$template_dir = DOL_DOCUMENT_ROOT.'/core/tpl/'; $template_dir = DOL_DOCUMENT_ROOT.'/core/tpl/';
$interfaces = new Interfaces($db); $interfaces = new Interfaces($db);
$triggers = $interfaces->getTriggersList(0); $triggers = $interfaces->getTriggersList(0,'priority');
include($template_dir.'triggers.tpl.php'); include($template_dir.'triggers.tpl.php');
llxFooter(); llxFooter();
$db->close();
?> ?>

View File

@@ -67,6 +67,13 @@ class Interfaces
dol_syslog(get_class($this).'::run_triggers was called with wrong parameters action='.$action.' object='.is_object($object).' user='.is_object($user).' langs='.is_object($langs).' conf='.is_object($conf), LOG_WARNING); dol_syslog(get_class($this).'::run_triggers was called with wrong parameters action='.$action.' object='.is_object($object).' user='.is_object($user).' langs='.is_object($langs).' conf='.is_object($conf), LOG_WARNING);
} }
$nbfile = $nbtotal = $nbok = $nbko = 0;
$files = array();
$modules = array();
$orders = array();
$i=0;
foreach($conf->triggers_modules as $reldir) foreach($conf->triggers_modules as $reldir)
{ {
$dir=dol_buildpath($reldir,0); $dir=dol_buildpath($reldir,0);
@@ -76,61 +83,71 @@ class Interfaces
if (!is_dir($dir)) continue; if (!is_dir($dir)) continue;
$handle=opendir($dir); $handle=opendir($dir);
$modules = array();
$nbfile = $nbtotal = $nbok = $nbko = 0;
if (is_resource($handle)) if (is_resource($handle))
{ {
while (($file = readdir($handle))!==false) while (($file = readdir($handle))!==false)
{ {
if (is_readable($dir."/".$file) && preg_match('/^interface_([^_]+)_(.+)\.class\.php$/i',$file,$reg)) if (is_readable($dir."/".$file) && preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php$/i',$file,$reg))
{ {
$part1=$reg[1];
$part2=$reg[2];
$part3=$reg[3];
$nbfile++; $nbfile++;
$modName = "Interface".ucfirst($reg[2]); $modName = "Interface".ucfirst($reg[3]);
//print "file=$file"; print "modName=$modName"; exit; //print "file=$file"; print "modName=$modName"; exit;
if (in_array($modName,$modules)) if (in_array($modName,$modules))
{ {
$langs->load("errors"); $langs->load("errors");
dol_syslog("Interface::run_triggers action=".$action." ".$langs->trans("ErrorDuplicateTrigger",$modName,"/htdocs/core/triggers/"),LOG_ERR); dol_syslog(get_class($this)."::run_triggers action=".$action." ".$langs->trans("ErrorDuplicateTrigger",$modName,"/htdocs/core/triggers/"),LOG_ERR);
continue; continue;
} }
else
{
include_once($dir.'/'.$file);
}
// Check if trigger file is disabled by name // Check if trigger file is disabled by name
if (preg_match('/NORUN$/i',$file)) if (preg_match('/NORUN$/i',$file)) continue;
{
continue;
}
// Check if trigger file is for a particular module // Check if trigger file is for a particular module
$qualified=true; $qualified=true;
if (strtolower($reg[1]) != 'all') if (strtolower($reg[2]) != 'all')
{ {
$module=preg_replace('/^mod/i','',$reg[1]); $module=preg_replace('/^mod/i','',$reg[2]);
$constparam='MAIN_MODULE_'.strtoupper($module); $constparam='MAIN_MODULE_'.strtoupper($module);
if (empty($conf->global->$constparam)) $qualified=false; if (empty($conf->global->$constparam)) $qualified=false;
} }
if (! $qualified) if (! $qualified)
{ {
dol_syslog("Interfaces::run_triggers action=".$action." Triggers for file '".$file."' need module to be enabled",LOG_INFO); dol_syslog(get_class($this)."::run_triggers action=".$action." Triggers for file '".$file."' need module to be enabled",LOG_INFO);
continue; continue;
} }
include_once($dir."/".$file);
$objMod = new $modName($this->db);
$i=0;
if ($objMod)
{
// Bypass if workflow module is enabled and if the trigger asked to be disable in such case
if (! empty($conf->workflow->enabled) && ! empty($objMod->disabled_if_workflow))
{
dol_syslog("Interfaces::run_triggers action=".$action." Bypass triggers for file '".$file."'",LOG_INFO);
continue;
}
dol_syslog("Interfaces::run_triggers action=".$action." Launch triggers for file '".$file."'",LOG_INFO);
$modules[$i] = $modName; $modules[$i] = $modName;
//dol_syslog("Interfaces::run_triggers Launch triggers for file '".$file."'",LOG_INFO); $files[$i] = $file;
$orders[$i] = $part1.'_'.$part2.'_'.$part3; // Set sort criteria value
$i++;
}
}
}
}
asort($orders);
// Loop on each trigger
foreach ($orders as $key => $value)
{
$modName = $modules[$key];
if (empty($modName)) continue;
$objMod = new $modName($this->db);
if ($objMod)
{
dol_syslog(get_class($this)."::run_triggers action=".$action." Launch triggers for file '".$files[$key]."'",LOG_INFO);
$result=$objMod->run_trigger($action,$object,$user,$langs,$conf); $result=$objMod->run_trigger($action,$object,$user,$langs,$conf);
if ($result > 0) if ($result > 0)
{ {
@@ -150,37 +167,32 @@ class Interfaces
$nbko++; $nbko++;
$this->errors[]=$objMod->error; $this->errors[]=$objMod->error;
} }
$i++;
} }
else else
{ {
dol_syslog("Interfaces::run_triggers action=".$action." Failed to instantiate trigger for file '".$file."'",LOG_ERR); dol_syslog(get_class($this)."::run_triggers action=".$action." Failed to instantiate trigger for file '".$files[$key]."'",LOG_ERR);
}
}
}
closedir($handle);
} }
} }
if ($nbko) if ($nbko)
{ {
dol_syslog("Interfaces::run_triggers action=".$action." Files found: ".$nbfile.", Files launched: ".$nbtotal.", Done: ".$nbok.", Failed: ".$nbko, LOG_ERR); dol_syslog(get_class($this)."::run_triggers action=".$action." Files found: ".$nbfile.", Files launched: ".$nbtotal.", Done: ".$nbok.", Failed: ".$nbko, LOG_ERR);
return -$nbko; return -$nbko;
} }
else else
{ {
//dol_syslog("Interfaces::run_triggers Files found: ".$nbfile.", Files launched: ".$nbtotal.", Done: ".$nbok.", Failed: ".$nbko, LOG_DEBUG); //dol_syslog(get_class($this)."::run_triggers Files found: ".$nbfile.", Files launched: ".$nbtotal.", Done: ".$nbok.", Failed: ".$nbko, LOG_DEBUG);
return $nbok; return $nbok;
} }
} }
/** /**
* Return list of triggers. Function used by admin page htdoc/admin/triggers * Return list of triggers. Function used by admin page htdoc/admin/triggers.
* List is sorted by trigger filename so by priority to run.
* *
* @param int $workflow 0=Return all triggers, 1=Return only triggers not disabled if workflow module activated
* @return array Array list of triggers * @return array Array list of triggers
*/ */
function getTriggersList($workflow=0) function getTriggersList()
{ {
global $conf, $langs; global $conf, $langs;
@@ -204,31 +216,29 @@ class Interfaces
{ {
while (($file = readdir($handle))!==false) while (($file = readdir($handle))!==false)
{ {
if (is_readable($dir.'/'.$file) && preg_match('/^interface_([^_]+)_(.+)\.class\.php/',$file,$reg)) if (is_readable($dir.'/'.$file) && preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php/',$file,$reg))
{ {
$modName = 'Interface'.ucfirst($reg[2]); $part1=$reg[1];
$part2=$reg[2];
$part3=$reg[3];
$modName = 'Interface'.ucfirst($reg[3]);
//print "file=$file"; print "modName=$modName"; exit; //print "file=$file"; print "modName=$modName"; exit;
if (in_array($modName,$modules)) if (in_array($modName,$modules))
{ {
$langs->load("errors"); $langs->load("errors");
print '<div class="error">'.$langs->trans("Error").' : '.$langs->trans("ErrorDuplicateTrigger",$modName,"/htdocs/core/triggers/").'</div>'; print '<div class="error">'.$langs->trans("Error").' : '.$langs->trans("ErrorDuplicateTrigger",$modName,"/htdocs/core/triggers/").'</div>';
$objMod = new $modName($this->db);
$modules[$i] = $modName;
$files[$i] = $file;
$orders[$i] = $objMod->family; // Tri par famille
$i++;
} }
else else
{ {
include_once($dir.'/'.$file); include_once($dir.'/'.$file);
$objMod = new $modName($this->db);
$modules[$i] = $modName;
$files[$i] = $file;
$orders[$i] = $objMod->family; // Tri par famille
$i++;
} }
$files[$i] = $file;
$modules[$i] = $modName;
$orders[$i] = $part1.'_'.$part2.'_'.$part3; // Set sort criteria value
$i++;
} }
} }
closedir($handle); closedir($handle);
@@ -244,27 +254,27 @@ class Interfaces
foreach ($orders as $key => $value) foreach ($orders as $key => $value)
{ {
$modName = $modules[$key]; $modName = $modules[$key];
if ($modName) if (empty($modName)) continue;
{
$objMod = new $modName($this->db); $objMod = new $modName($this->db);
// Bypass if workflow module is enabled and if the trigger is compatible
if ($workflow && ! empty($objMod->disabled_if_workflow)) continue;
}
// Define disabledbyname and disabledbymodule // Define disabledbyname and disabledbymodule
$disabledbyname=0; $disabledbyname=0;
$disabledbymodule=1; $disabledbymodule=1;
$module=''; $module='';
// Check if trigger file is disabled by name
if (preg_match('/NORUN$/i',$files[$key])) $disabledbyname=1; if (preg_match('/NORUN$/i',$files[$key])) $disabledbyname=1;
if (preg_match('/^interface_([^_]+)_(.+)\.class\.php/i',$files[$key],$reg))
{
// Check if trigger file is for a particular module // Check if trigger file is for a particular module
$module=preg_replace('/^mod/i','',$reg[1]); if (preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php/i',$files[$key],$reg))
{
$module=preg_replace('/^mod/i','',$reg[2]);
$constparam='MAIN_MODULE_'.strtoupper($module); $constparam='MAIN_MODULE_'.strtoupper($module);
if (strtolower($reg[1]) == 'all') $disabledbymodule=0; if (strtolower($reg[2]) == 'all') $disabledbymodule=0;
else if (empty($conf->global->$constparam)) $disabledbymodule=2; else if (empty($conf->global->$constparam)) $disabledbymodule=2;
} }
// We set info of modules
$triggers[$j]['picto'] = $objMod->picto?img_object('',$objMod->picto):img_object('','generic'); $triggers[$j]['picto'] = $objMod->picto?img_object('',$objMod->picto):img_object('','generic');
$triggers[$j]['file'] = $files[$key]; $triggers[$j]['file'] = $files[$key];
$triggers[$j]['version'] = $objMod->getVersion(); $triggers[$j]['version'] = $objMod->getVersion();

View File

@@ -1,526 +0,0 @@
<?php
/* Copyright (C) 2005-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
*
* 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 2 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/>.
*/
/**
* \file htdocs/core/triggers/interface_all_Demo.class.php
* \ingroup core
* \brief Fichier de demo de personalisation des actions du workflow
* \remarks Son propre fichier d'actions peut etre cree par recopie de celui-ci:
* - Le nom du fichier doit etre: interface_modMymodule_Mytrigger.class.php
* ou: interface_all_Mytrigger.class.php
* - Le fichier doit rester stocke dans core/triggers
* - Le nom de la classe doit etre InterfaceMytrigger
* - Le nom de la methode constructeur doit etre InterfaceMytrigger
* - Le nom de la propriete name doit etre Mytrigger
*/
/**
* \class InterfaceDemo
* \brief Class of triggers for demo module
*/
class InterfaceDemo
{
var $db;
/**
* Constructor.
* @param DB Database handler
*/
function InterfaceDemo($DB)
{
$this->db = $DB ;
$this->name = preg_replace('/^Interface/i','',get_class($this));
$this->family = "demo";
$this->description = "Triggers of this module are empty functions. They have no effect. They are provided for tutorial purpose only.";
$this->version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' or version
$this->picto = 'technic';
}
/**
* Return name of trigger file
* @return string Name of trigger file
*/
function getName()
{
return $this->name;
}
/**
* Return description of trigger file
* @return string Description of trigger file
*/
function getDesc()
{
return $this->description;
}
/**
* Return version of trigger file
* @return string Version of trigger file
*/
function getVersion()
{
global $langs;
$langs->load("admin");
if ($this->version == 'development') return $langs->trans("Development");
elseif ($this->version == 'experimental') return $langs->trans("Experimental");
elseif ($this->version == 'dolibarr') return DOL_VERSION;
elseif ($this->version) return $this->version;
else return $langs->trans("Unknown");
}
/**
* Function called when a Dolibarrr business event is done.
* All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers
* @param action Code de l'evenement
* @param object Objet concerne
* @param user Objet user
* @param langs Objet langs
* @param conf Objet conf
* @return int <0 if KO, 0 if no triggered ran, >0 if OK
*/
function run_trigger($action,$object,$user,$langs,$conf)
{
// Put here code you want to execute when a Dolibarr business events occurs.
// Data and type of action are stored into $object and $action
// Users
if ($action == 'USER_LOGIN')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'USER_UPDATE_SESSION')
{
// Warning: To increase performances, this action is triggered only if
// constant MAIN_ACTIVATE_UPDATESESSIONTRIGGER is set to 1.
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'USER_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'USER_CREATE_FROM_CONTACT')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'USER_MODIFY')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'USER_NEW_PASSWORD')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'USER_ENABLEDISABLE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'USER_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'USER_LOGOUT')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'USER_SETINGROUP')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'USER_REMOVEFROMGROUP')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
// Groups
elseif ($action == 'GROUP_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'GROUP_MODIFY')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'GROUP_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
// Companies
elseif ($action == 'COMPANY_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'COMPANY_MODIFY')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'COMPANY_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
// Contacts
elseif ($action == 'CONTACT_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'CONTACT_MODIFY')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'CONTACT_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
// Products
elseif ($action == 'PRODUCT_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'PRODUCT_MODIFY')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'PRODUCT_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
// Customer orders
elseif ($action == 'ORDER_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'ORDER_CLONE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'ORDER_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'ORDER_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'ORDER_BUILDDOC')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'ORDER_SENTBYMAIL')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'LINEORDER_INSERT')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'LINEORDER_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
// Supplier orders
elseif ($action == 'ORDER_SUPPLIER_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'ORDER_SUPPLIER_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'ORDER_SUPPLIER_SENTBYMAIL')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
// Proposals
elseif ($action == 'PROPAL_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'PROPAL_CLONE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'PROPAL_MODIFY')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'PROPAL_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'PROPAL_BUILDDOC')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'PROPAL_SENTBYMAIL')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'PROPAL_CLOSE_SIGNED')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'PROPAL_CLOSE_REFUSED')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'PROPAL_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'LINEPROPAL_INSERT')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'LINEPROPAL_MODIFY')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'LINEPROPAL_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
// Contracts
elseif ($action == 'CONTRACT_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'CONTRACT_MODIFY')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'CONTRACT_ACTIVATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'CONTRACT_CANCEL')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'CONTRACT_CLOSE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'CONTRACT_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
// Bills
elseif ($action == 'BILL_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'BILL_CLONE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'BILL_MODIFY')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'BILL_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'BILL_BUILDDOC')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'BILL_SENTBYMAIL')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'BILL_CANCEL')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'BILL_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'LINEBILL_INSERT')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'LINEBILL_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
// Payments
elseif ($action == 'PAYMENT_CUSTOMER_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'PAYMENT_SUPPLIER_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'PAYMENT_ADD_TO_BANK')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'PAYMENT_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
// Interventions
elseif ($action == 'FICHEINTER_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
// Members
elseif ($action == 'MEMBER_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'MEMBER_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'MEMBER_SUBSCRIPTION')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'MEMBER_MODIFY')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'MEMBER_NEW_PASSWORD')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'MEMBER_RESILIATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'MEMBER_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
// Categories
elseif ($action == 'CATEGORY_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'CATEGORY_MODIFY')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'CATEGORY_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
// Projects
elseif ($action == 'PROJECT_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'PROJECT_MODIFY')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'PROJECT_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
// Project tasks
elseif ($action == 'TASK_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'TASK_MODIFY')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'TASK_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
// Task time spent
elseif ($action == 'TASK_TIMESPENT_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'TASK_TIMESPENT_MODIFY')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'TASK_TIMESPENT_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
// Shipping
elseif ($action == 'SHIPPING_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'SHIPPING_MODIFY')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'SHIPPING_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'SHIPPING_SENTBYMAIL')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'SHIPPING_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'SHIPPING_BUILDDOC')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
// File
elseif ($action == 'FILE_UPLOAD')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'FILE_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
return 0;
}
}
?>

View File

@@ -1,255 +0,0 @@
<?php
/* Copyright (C) 2005-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2009 Regis Houssin <regis@dolibarr.fr>
*
* 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 2 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/>.
*/
/**
* \file htdocs/core/triggers/interface_all_Logevents.class.php
* \ingroup core
* \brief Trigger file for
*/
/**
* \class InterfaceLogevents
* \brief Class of triggers for security events
*/
class InterfaceLogevents
{
var $db;
var $error;
var $date;
var $duree;
var $texte;
var $desc;
/**
* Constructor.
* @param DB Database handler
*/
function InterfaceLogevents($DB)
{
$this->db = $DB ;
$this->name = preg_replace('/^Interface/i','',get_class($this));
$this->family = "core";
$this->description = "Triggers of this module allows to add security event records inside Dolibarr.";
$this->version = 'dolibarr'; // 'experimental' or 'dolibarr' or version
$this->picto = 'technic';
}
/**
* Return name of trigger file
* @return string Name of trigger file
*/
function getName()
{
return $this->name;
}
/**
* Return description of trigger file
* @return string Description of trigger file
*/
function getDesc()
{
return $this->description;
}
/**
* Return version of trigger file
* @return string Version of trigger file
*/
function getVersion()
{
global $langs;
$langs->load("admin");
if ($this->version == 'experimental') return $langs->trans("Experimental");
elseif ($this->version == 'dolibarr') return DOL_VERSION;
elseif ($this->version) return $this->version;
else return $langs->trans("Unknown");
}
/**
* Function called when a Dolibarrr business event is done.
* All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers
* @param action Code de l'evenement
* @param object Objet concerne
* @param user Objet user
* @param langs Objet langs
* @param conf Objet conf
* @param entity Value for instance of data (Always 1 except if module MultiCompany is installed)
* @return int <0 if KO, 0 if no triggered ran, >0 if OK
*/
function run_trigger($action,$object,$user,$langs,$conf,$entity=1)
{
if (! empty($conf->global->MAIN_LOGEVENTS_DISABLE_ALL)) return 0; // Log events is disabled (hidden features)
$key='MAIN_LOGEVENTS_'.$action;
//dol_syslog("xxxxxxxxxxx".$key);
if (empty($conf->global->$key)) return 0; // Log events not enabled for this action
if (empty($conf->entity)) $conf->entity = $entity; // forcing of the entity if it's not defined (ex: in login form)
$this->date=gmmktime();
$this->duree=0;
// Actions
if ($action == 'USER_LOGIN')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
// Initialisation donnees (date,duree,texte,desc)
$this->texte="(UserLogged,".$object->login.")";
$this->desc="(UserLogged,".$object->login.")";
}
if ($action == 'USER_LOGIN_FAILED')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
// Initialisation donnees (date,duree,texte,desc)
$this->texte=$object->trigger_mesg; // Message direct
$this->desc=$object->trigger_mesg; // Message direct
}
if ($action == 'USER_LOGOUT')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
// Initialisation donnees (date,duree,texte,desc)
$this->texte="(UserLogoff,".$object->login.")";
$this->desc="(UserLogoff,".$object->login.")";
}
if ($action == 'USER_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("users");
// Initialisation donnees (date,duree,texte,desc)
$this->texte=$langs->transnoentities("NewUserCreated",$object->login);
$this->desc=$langs->transnoentities("NewUserCreated",$object->login);
}
elseif ($action == 'USER_MODIFY')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("users");
// Initialisation donnees (date,duree,texte,desc)
$this->texte=$langs->transnoentities("EventUserModified",$object->login);
$this->desc=$langs->transnoentities("EventUserModified",$object->login);
}
elseif ($action == 'USER_NEW_PASSWORD')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("users");
// Initialisation donnees (date,duree,texte,desc)
$this->texte=$langs->transnoentities("NewUserPassword",$object->login);
$this->desc=$langs->transnoentities("NewUserPassword",$object->login);
}
elseif ($action == 'USER_ENABLEDISABLE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("users");
// Initialisation donnees (date,duree,texte,desc)
if ($object->statut == 0)
{
$this->texte=$langs->transnoentities("UserEnabled",$object->login);
$this->desc=$langs->transnoentities("UserEnabled",$object->login);
}
if ($object->statut == 1)
{
$this->texte=$langs->transnoentities("UserDisabled",$object->login);
$this->desc=$langs->transnoentities("UserDisabled",$object->login);
}
}
elseif ($action == 'USER_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("users");
// Initialisation donnees (date,duree,texte,desc)
$this->texte=$langs->transnoentities("UserDeleted",$object->login);
$this->desc=$langs->transnoentities("UserDeleted",$object->login);
}
// Groupes
elseif ($action == 'GROUP_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("users");
// Initialisation donnees (date,duree,texte,desc)
$this->texte=$langs->transnoentities("NewGroupCreated",$object->nom);
$this->desc=$langs->transnoentities("NewGroupCreated",$object->nom);
}
elseif ($action == 'GROUP_MODIFY')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("users");
// Initialisation donnees (date,duree,texte,desc)
$this->texte=$langs->transnoentities("GroupModified",$object->nom);
$this->desc=$langs->transnoentities("GroupModified",$object->nom);
}
elseif ($action == 'GROUP_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("users");
// Initialisation donnees (date,duree,texte,desc)
$this->texte=$langs->transnoentities("GroupDeleted",$object->nom);
$this->desc=$langs->transnoentities("GroupDeleted",$object->nom);
}
// If not found
/*
else
{
dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action.");
return 0;
}
*/
// Add entry in event table
if ($this->date)
{
include_once(DOL_DOCUMENT_ROOT.'/core/class/events.class.php');
$event=new Events($this->db);
$event->type=$action;
$event->dateevent=$this->date;
$event->label=$this->texte;
$event->description=$this->desc;
$event->user_agent=$_SERVER["HTTP_USER_AGENT"];
$result=$event->create($user);
if ($result > 0)
{
return 1;
}
else
{
$error ="Failed to insert security event: ".$event->error;
$this->error=$error;
dol_syslog("interface_all_Logevents.class.php: ".$this->error, LOG_ERR);
return -1;
}
}
return 0;
}
}
?>

View File

@@ -1,598 +0,0 @@
<?php
/* Copyright (C) 2005-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2009-2011 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2011 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 2 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/>.
*/
/**
* \file htdocs/core/triggers/interface_modAgenda_ActionsAuto.class.php
* \ingroup agenda
* \brief Trigger file for agenda module
*/
/**
* \class InterfaceActionsAuto
* \brief Class of triggered functions for agenda module
*/
class InterfaceActionsAuto
{
var $db;
var $error;
var $date;
var $duree;
var $texte;
var $desc;
/**
* Constructor.
* @param DB Database handler
*/
function InterfaceActionsAuto($DB)
{
$this->db = $DB ;
$this->name = preg_replace('/^Interface/i','',get_class($this));
$this->family = "agenda";
$this->description = "Triggers of this module add actions in agenda according to setup made in agenda setup.";
$this->version = 'dolibarr'; // 'experimental' or 'dolibarr' or version
$this->picto = 'action';
}
/**
* Return name of trigger file
* @return string Name of trigger file
*/
function getName()
{
return $this->name;
}
/**
* Return description of trigger file
* @return string Description of trigger file
*/
function getDesc()
{
return $this->description;
}
/**
* Return version of trigger file
* @return string Version of trigger file
*/
function getVersion()
{
global $langs;
$langs->load("admin");
if ($this->version == 'experimental') return $langs->trans("Experimental");
elseif ($this->version == 'dolibarr') return DOL_VERSION;
elseif ($this->version) return $this->version;
else return $langs->trans("Unknown");
}
/**
* Function called when a Dolibarrr business event is done.
* All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers
*
* Following properties must be filled:
* $object->actiontypecode (translation action code: AC_OTH, ...)
* $object->actionmsg (note, long text)
* $object->actionmsg2 (label, short text)
* $object->sendtoid (id of contact)
* $object->socid
* Optionnal:
* $object->fk_element
* $object->elementtype
*
* @param action Event code (COMPANY_CREATE, PROPAL_VALIDATE, ...)
* @param object Object action is done on
* @param user Object user
* @param langs Object langs
* @param conf Object conf
* @return int <0 if KO, 0 if no action are done, >0 if OK
*/
function run_trigger($action,$object,$user,$langs,$conf)
{
$key='MAIN_AGENDA_ACTIONAUTO_'.$action;
//dol_syslog("xxxxxxxxxxx".$key);
if (empty($conf->agenda->enabled)) return 0; // Module not active, we do nothing
if (empty($conf->global->$key)) return 0; // Log events not enabled for this action
$ok=0;
// Actions
if ($action == 'COMPANY_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("other");
$langs->load("agenda");
$object->actiontypecode='AC_OTH';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("NewCompanyToDolibarr",$object->nom);
$object->actionmsg=$langs->transnoentities("NewCompanyToDolibarr",$object->nom);
if ($object->prefix) $object->actionmsg.=" (".$object->prefix.")";
//$this->desc.="\n".$langs->transnoentities("Customer").': '.yn($object->client);
//$this->desc.="\n".$langs->transnoentities("Supplier").': '.yn($object->fournisseur);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
$object->socid=$object->id;
$ok=1;
}
elseif ($action == 'CONTRACT_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("other");
$langs->load("contracts");
$langs->load("agenda");
$object->actiontypecode='AC_OTH';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ContractValidatedInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("ContractValidatedInDolibarr",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
$ok=1;
}
elseif ($action == 'PROPAL_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("propal");
$langs->load("agenda");
$object->actiontypecode='AC_OTH';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalValidatedInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("PropalValidatedInDolibarr",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
$ok=1;
}
elseif ($action == 'PROPAL_SENTBYMAIL')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("propal");
$langs->load("agenda");
$object->actiontypecode='AC_EMAIL';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ProposalSentByEMail",$object->ref);
if (empty($object->actionmsg))
{
$object->actionmsg=$langs->transnoentities("ProposalSentByEMail",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
}
// Parameters $object->sendtoid defined by caller
//$object->sendtoid=0;
$ok=1;
}
elseif ($action == 'PROPAL_CLOSE_SIGNED')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("propal");
$langs->load("agenda");
$object->actiontypecode='AC_OTH';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
$ok=1;
}
elseif ($action == 'PROPAL_CLOSE_REFUSED')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("propal");
$langs->load("agenda");
$object->actiontypecode='AC_OTH';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
$ok=1;
}
elseif ($action == 'ORDER_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("orders");
$langs->load("agenda");
$object->actiontypecode='AC_OTH';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderValidatedInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("OrderValidatedInDolibarr",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
$ok=1;
}
elseif ($action == 'ORDER_SENTBYMAIL')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("orders");
$langs->load("agenda");
$object->actiontypecode='AC_EMAIL';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderSentByEMail",$object->ref);
if (empty($object->actionmsg))
{
$object->actionmsg=$langs->transnoentities("OrderSentByEMail",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
}
// Parameters $object->sendtoid defined by caller
//$object->sendtoid=0;
$ok=1;
}
elseif ($action == 'BILL_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("other");
$langs->load("bills");
$langs->load("agenda");
$object->actiontypecode='AC_OTH';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceValidatedInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("InvoiceValidatedInDolibarr",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
$ok=1;
}
elseif ($action == 'BILL_SENTBYMAIL')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("other");
$langs->load("bills");
$langs->load("agenda");
$object->actiontypecode='AC_EMAIL';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceSentByEMail",$object->ref);
if (empty($object->actionmsg))
{
$object->actionmsg=$langs->transnoentities("InvoiceSentByEMail",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
}
// Parameters $object->sendtoid defined by caller
//$object->sendtoid=0;
$ok=1;
}
elseif ($action == 'BILL_PAYED')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("other");
$langs->load("bills");
$langs->load("agenda");
$object->actiontypecode='AC_OTH';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
$ok=1;
}
elseif ($action == 'BILL_CANCEL')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("other");
$langs->load("bills");
$langs->load("agenda");
$object->actiontypecode='AC_OTH';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
$ok=1;
}
elseif ($action == 'FICHEINTER_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("other");
$langs->load("interventions");
$langs->load("agenda");
$object->actiontypecode='AC_OTH';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionValidatedInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("InterventionValidatedInDolibarr",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
$object->fk_element=0;
$object->elementtype='';
$ok=1;
}
elseif ($action == 'FICHEINTER_SENTBYMAIL')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("other");
$langs->load("interventions");
$langs->load("agenda");
$object->actiontypecode='AC_EMAIL';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionSentByEMail",$object->ref);
$object->actionmsg=$langs->transnoentities("InterventionSentByEMail",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
// Parameters $object->sendotid defined by caller
//$object->sendtoid=0;
$ok=1;
}
elseif ($action == 'SHIPPING_SENTBYMAIL')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("other");
$langs->load("sendings");
$langs->load("agenda");
$object->actiontypecode='AC_SHIP';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ShippingSentByEMail",$object->ref);
if (empty($object->actionmsg))
{
$object->actionmsg=$langs->transnoentities("ShippingSentByEMail",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
}
// Parameters $object->sendtoid defined by caller
//$object->sendtoid=0;
$ok=1;
}
elseif ($action == 'ORDER_SUPPLIER_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("orders");
$langs->load("agenda");
$object->actiontypecode='AC_OTH';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderValidatedInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("OrderValidatedInDolibarr",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
$ok=1;
}
elseif ($action == 'ORDER_SUPPLIER_SENTBYMAIL')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("other");
$langs->load("bills");
$langs->load("agenda");
$langs->load("orders");
$object->actiontypecode='AC_EMAIL';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("SupplierOrderSentByEMail",$object->ref);
if (empty($object->actionmsg))
{
$object->actionmsg=$langs->transnoentities("SupplierOrderSentByEMail",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
}
// Parameters $object->sendotid defined by caller
//$object->sendtoid=0;
$ok=1;
}
elseif ($action == 'BILL_SUPPLIER_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("other");
$langs->load("bills");
$langs->load("agenda");
$object->actiontypecode='AC_OTH';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceValidatedInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("InvoiceValidatedInDolibarr",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
$ok=1;
}
elseif ($action == 'BILL_SUPPLIER_SENTBYMAIL')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("other");
$langs->load("bills");
$langs->load("agenda");
$langs->load("orders");
$object->actiontypecode='AC_EMAIL';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("SupplierInvoiceSentByEMail",$object->ref);
if (empty($object->actionmsg))
{
$object->actionmsg=$langs->transnoentities("SupplierInvoiceSentByEMail",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
}
// Parameters $object->sendtoid defined by caller
//$object->sendtoid=0;
$ok=1;
}
elseif ($action == 'BILL_SUPPLIER_PAYED')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("other");
$langs->load("bills");
$langs->load("agenda");
$object->actiontypecode='AC_OTH';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
$ok=1;
}
elseif ($action == 'BILL_SUPPLIER_CANCELED')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("other");
$langs->load("bills");
$langs->load("agenda");
$object->actiontypecode='AC_OTH';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
$ok=1;
}
// Members
elseif ($action == 'MEMBER_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("other");
$langs->load("members");
$langs->load("agenda");
$object->actiontypecode='AC_OTH';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberValidatedInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("MemberValidatedInDolibarr",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
$object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type;
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
$ok=1;
}
elseif ($action == 'MEMBER_SUBSCRIPTION')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("other");
$langs->load("members");
$langs->load("agenda");
$object->actiontypecode='AC_OTH';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberSubscriptionAddedInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("MemberSubscriptionAddedInDolibarr",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
$object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type;
$object->actionmsg.="\n".$langs->transnoentities("Amount").': '.$object->last_subscription_amount;
$object->actionmsg.="\n".$langs->transnoentities("Period").': '.dol_print_date($object->last_subscription_date_start,'day').' - '.dol_print_date($object->last_subscription_date_end,'day');
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
$ok=1;
}
elseif ($action == 'MEMBER_MODIFY')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'MEMBER_RESILIATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("other");
$langs->load("members");
$langs->load("agenda");
$object->actiontypecode='AC_OTH';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberResiliatedInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("MemberResiliatedInDolibarr",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
$object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type;
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
$ok=1;
}
elseif ($action == 'MEMBER_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("other");
$langs->load("members");
$langs->load("agenda");
$object->actiontypecode='AC_OTH';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberDeletedInDolibarr",$object->ref);
$object->actionmsg=$langs->transnoentities("MemberDeletedInDolibarr",$object->ref);
$object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
$object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type;
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0;
$ok=1;
}
// If not found
/*
else
{
dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action.");
return 0;
}
*/
// Add entry in event table
if ($ok)
{
$now=dol_now();
require_once(DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php');
require_once(DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php');
$contactforaction=new Contact($this->db);
$societeforaction=new Societe($this->db);
if ($object->sendtoid > 0) $contactforaction->fetch($object->sendtoid);
if ($object->socid > 0) $societeforaction->fetch($object->socid);
// Insertion action
require_once(DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php');
$actioncomm = new ActionComm($this->db);
$actioncomm->type_code = $object->actiontypecode;
$actioncomm->label = $object->actionmsg2;
$actioncomm->note = $object->actionmsg;
$actioncomm->datep = $now;
$actioncomm->datef = $now;
$actioncomm->durationp = 0;
$actioncomm->punctual = 1;
$actioncomm->percentage = -1; // Not applicable
$actioncomm->contact = $contactforaction;
$actioncomm->societe = $societeforaction;
$actioncomm->author = $user; // User saving action
//$actioncomm->usertodo = $user; // User affected to action
$actioncomm->userdone = $user; // User doing action
$actioncomm->fk_element = $object->id;
$actioncomm->elementtype = $object->element;
$ret=$actioncomm->add($user); // User qui saisit l'action
if ($ret > 0)
{
return 1;
}
else
{
$error ="Failed to insert : ".$actioncomm->error." ";
$this->error=$error;
dol_syslog("interface_modAgenda_ActionsAuto.class.php: ".$this->error, LOG_ERR);
return -1;
}
}
return 0;
}
}
?>

View File

@@ -1,536 +0,0 @@
<?php
/* Copyright (C) 2005-2007 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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 2 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/>.
*/
/**
* \file htdocs/core/triggers/interface_modLdap_Ldapsynchro.class.php
* \ingroup core
* \brief Fichier de gestion des triggers LDAP
*/
require_once (DOL_DOCUMENT_ROOT."/core/class/ldap.class.php");
/**
* \class InterfaceLdapsynchro
* \brief Class of triggers for ldap module
*/
class InterfaceLdapsynchro
{
var $db;
var $error;
/**
* Constructor.
* @param DB Database handler
*/
function InterfaceLdapsynchro($DB)
{
$this->db = $DB ;
$this->name = preg_replace('/^Interface/i','',get_class($this));
$this->family = "ldap";
$this->description = "Triggers of this module allows to synchronize Dolibarr toward a LDAP database.";
$this->version = 'dolibarr'; // 'experimental' or 'dolibarr' or version
$this->picto = 'technic';
}
/**
* Return name of trigger file
* @return string Name of trigger file
*/
function getName()
{
return $this->name;
}
/**
* Return description of trigger file
* @return string Description of trigger file
*/
function getDesc()
{
return $this->description;
}
/**
* Return version of trigger file
* @return string Version of trigger file
*/
function getVersion()
{
global $langs;
$langs->load("admin");
if ($this->version == 'experimental') return $langs->trans("Experimental");
elseif ($this->version == 'dolibarr') return DOL_VERSION;
elseif ($this->version) return $this->version;
else return $langs->trans("Unknown");
}
/**
* Function called when a Dolibarrr business event is done.
* All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers
* @param action Event code (COMPANY_CREATE, PROPAL_VALIDATE, ...)
* @param object Object action is done on
* @param user Object user
* @param langs Object langs
* @param conf Object conf
* @return int <0 if KO, 0 if no action are done, >0 if OK
*/
function run_trigger($action,$object,$user,$langs,$conf)
{
if (empty($conf->ldap->enabled)) return 0; // Module not active, we do nothing
if (! function_exists('ldap_connect'))
{
dol_syslog("Warning, module LDAP is enabled but LDAP functions not available in this PHP", LOG_WARNING);
return 0;
}
// Users
if ($action == 'USER_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
{
$ldap=new Ldap();
$ldap->connect_bind();
$info=$object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info);
$result=$ldap->add($dn,$info,$user);
if ($result < 0)
{
$this->error="ErrorLDAP"." ".$ldap->error;
}
return $result;
}
}
elseif ($action == 'USER_MODIFY')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
{
$ldap=new Ldap();
$ldap->connect_bind();
$oldinfo=$object->oldcopy->_load_ldap_info();
$olddn=$object->oldcopy->_load_ldap_dn($oldinfo);
// Verify if entry exist
$container=$object->oldcopy->_load_ldap_dn($oldinfo,1);
$search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")";
$records=$ldap->search($container,$search);
if (count($records) && $records['count'] == 0)
{
$olddn = '';
}
$info=$object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info);
$result=$ldap->update($dn,$info,$user,$olddn);
if ($result < 0)
{
$this->error="ErrorLDAP"." ".$ldap->error;
}
return $result;
}
}
elseif ($action == 'USER_NEW_PASSWORD')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
{
$ldap=new Ldap();
$ldap->connect_bind();
$oldinfo=$object->oldcopy->_load_ldap_info();
$olddn=$object->oldcopy->_load_ldap_dn($oldinfo);
// Verify if entry exist
$container=$object->oldcopy->_load_ldap_dn($oldinfo,1);
$search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")";
$records=$ldap->search($container,$search);
if (count($records) && $records['count'] == 0)
{
$olddn = '';
}
$info=$object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info);
$result=$ldap->update($dn,$info,$user,$olddn);
if ($result < 0)
{
$this->error="ErrorLDAP"." ".$ldap->error;
}
return $result;
}
}
elseif ($action == 'USER_ENABLEDISABLE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'USER_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
{
$ldap=new Ldap();
$ldap->connect_bind();
$info=$object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info);
$result=$ldap->delete($dn,$info,$user);
if ($result < 0)
{
$this->error="ErrorLDAP"." ".$ldap->error;
}
return $result;
}
}
// Groupes
elseif ($action == 'GROUP_CREATE')
{
if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
{
$ldap=new Ldap();
$ldap->connect_bind();
$info=$object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info);
// Get a gid number for objectclass PosixGroup
if(in_array('posixGroup',$info['objectclass']))
$info['gidNumber'] = $ldap->getNextGroupGid();
$result=$ldap->add($dn,$info,$user);
if ($result < 0)
{
$this->error="ErrorLDAP"." ".$ldap->error;
}
return $result;
}
}
elseif ($action == 'GROUP_MODIFY')
{
if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
{
$ldap=new Ldap();
$ldap->connect_bind();
$oldinfo=$object->oldcopy->_load_ldap_info();
$olddn=$object->oldcopy->_load_ldap_dn($oldinfo);
// Verify if entry exist
$container=$object->oldcopy->_load_ldap_dn($oldinfo,1);
$search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")";
$records=$ldap->search($container,$search);
if (count($records) && $records['count'] == 0)
{
$olddn = '';
}
$info=$object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info);
$result=$ldap->update($dn,$info,$user,$olddn);
if ($result < 0)
{
$this->error="ErrorLDAP"." ".$ldap->error;
}
return $result;
}
}
elseif ($action == 'GROUP_DELETE')
{
if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
{
$ldap=new Ldap();
$ldap->connect_bind();
$info=$object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info);
$result=$ldap->delete($dn,$info,$user);
if ($result < 0)
{
$this->error="ErrorLDAP"." ".$ldap->error;
}
return $result;
}
}
// Contacts
elseif ($action == 'CONTACT_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if ($conf->ldap->enabled && $conf->global->LDAP_CONTACT_ACTIVE)
{
$ldap=new Ldap();
$ldap->connect_bind();
$info=$object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info);
$result=$ldap->add($dn,$info,$user);
if ($result < 0)
{
$this->error="ErrorLDAP"." ".$ldap->error;
}
return $result;
}
}
elseif ($action == 'CONTACT_MODIFY')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if ($conf->ldap->enabled && $conf->global->LDAP_CONTACT_ACTIVE)
{
$ldap=new Ldap();
$ldap->connect_bind();
$oldinfo=$object->oldcopy->_load_ldap_info();
$olddn=$object->oldcopy->_load_ldap_dn($oldinfo);
// Verify if entry exist
$container=$object->oldcopy->_load_ldap_dn($oldinfo,1);
$search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")";
$records=$ldap->search($container,$search);
if (count($records) && $records['count'] == 0)
{
$olddn = '';
}
$info=$object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info);
$result=$ldap->update($dn,$info,$user,$olddn);
if ($result < 0)
{
$this->error="ErrorLDAP"." ".$ldap->error;
}
return $result;
}
}
elseif ($action == 'CONTACT_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if ($conf->ldap->enabled && $conf->global->LDAP_CONTACT_ACTIVE)
{
$ldap=new Ldap();
$ldap->connect_bind();
$info=$object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info);
$result=$ldap->delete($dn,$info,$user);
if ($result < 0)
{
$this->error="ErrorLDAP"." ".$ldap->error;
}
return $result;
}
}
// Members
elseif ($action == 'MEMBER_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if ($conf->ldap->enabled && $conf->global->LDAP_MEMBER_ACTIVE)
{
$ldap=new Ldap();
$ldap->connect_bind();
$info=$object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info);
$result=$ldap->add($dn,$info,$user);
if ($result < 0)
{
$this->error="ErrorLDAP"." ".$ldap->error;
}
return $result;
}
}
elseif ($action == 'MEMBER_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if ($conf->ldap->enabled && $conf->global->LDAP_MEMBER_ACTIVE)
{
// If status field is setup to be synchronized
if ($conf->global->LDAP_FIELD_MEMBER_STATUS)
{
$ldap=new Ldap();
$ldap->connect_bind();
$info=$object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info);
$olddn=$dn; // We know olddn=dn as we change only status
$result=$ldap->update($dn,$info,$user,$olddn);
if ($result < 0)
{
$this->error="ErrorLDAP"." ".$ldap->error;
}
return $result;
}
}
}
elseif ($action == 'MEMBER_SUBSCRIPTION')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if ($conf->ldap->enabled && $conf->global->LDAP_MEMBER_ACTIVE)
{
// If subscriptions fields are setup to be synchronized
if ($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE
|| $conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT
|| $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE
|| $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT
|| $conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION)
{
$ldap=new Ldap();
$ldap->connect_bind();
$info=$object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info);
$olddn=$dn; // We know olddn=dn as we change only subscriptions
$result=$ldap->update($dn,$info,$user,$olddn);
if ($result < 0)
{
$this->error="ErrorLDAP"." ".$ldap->error;
}
return $result;
}
}
}
elseif ($action == 'MEMBER_MODIFY')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if ($conf->ldap->enabled && $conf->global->LDAP_MEMBER_ACTIVE)
{
$ldap=new Ldap();
$ldap->connect_bind();
$oldinfo=$object->oldcopy->_load_ldap_info();
$olddn=$object->oldcopy->_load_ldap_dn($oldinfo);
// Verify if entry exist
$container=$object->oldcopy->_load_ldap_dn($oldinfo,1);
$search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")";
$records=$ldap->search($container,$search);
if (count($records) && $records['count'] == 0)
{
$olddn = '';
}
$info=$object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info);
$result=$ldap->update($dn,$info,$user,$olddn);
if ($result < 0)
{
$this->error="ErrorLDAP"." ".$ldap->error;
}
return $result;
}
}
elseif ($action == 'MEMBER_NEW_PASSWORD')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if ($conf->ldap->enabled && $conf->global->LDAP_MEMBER_ACTIVE)
{
// If password field is setup to be synchronized
if ($conf->global->LDAP_FIELD_PASSWORD || $conf->global->LDAP_FIELD_PASSWORD_CRYPTED)
{
$ldap=new Ldap();
$ldap->connect_bind();
$info=$object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info);
$olddn=$dn; // We know olddn=dn as we change only password
$result=$ldap->update($dn,$info,$user,$olddn);
if ($result < 0)
{
$this->error="ErrorLDAP"." ".$ldap->error;
}
return $result;
}
}
}
elseif ($action == 'MEMBER_RESILIATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if ($conf->ldap->enabled && $conf->global->LDAP_MEMBER_ACTIVE)
{
// If status field is setup to be synchronized
if ($conf->global->LDAP_FIELD_MEMBER_STATUS)
{
$ldap=new Ldap();
$ldap->connect_bind();
$info=$object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info);
$olddn=$dn; // We know olddn=dn as we change only status
$result=$ldap->update($dn,$info,$user,$olddn);
if ($result < 0)
{
$this->error="ErrorLDAP"." ".$ldap->error;
}
return $result;
}
}
}
elseif ($action == 'MEMBER_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if ($conf->ldap->enabled && $conf->global->LDAP_MEMBER_ACTIVE)
{
$ldap=new Ldap();
$ldap->connect_bind();
$info=$object->_load_ldap_info();
$dn=$object->_load_ldap_dn($info);
$result=$ldap->delete($dn,$info,$user);
if ($result < 0)
{
$this->error="ErrorLDAP"." ".$ldap->error;
}
return $result;
}
}
// If not found
/*
else
{
dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action.");
return -1;
}
*/
return 0;
}
}
?>

View File

@@ -1,256 +0,0 @@
<?php
/* Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2011 Regis Houssin <regis@dolibarr.fr>
*
* 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 2 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/>.
*/
/**
* \file htdocs/core/triggers/interface_modNotification_Notification.class.php
* \ingroup notification
* \brief File of class of triggers for notification module
*/
/**
* \class InterfaceNotification
* \brief Class of triggers for notification module
*/
class InterfaceNotification
{
var $db;
var $listofmanagedevents=array('BILL_VALIDATE','ORDER_VALIDATE','PROPAL_VALIDATE',
'FICHEINTER_VALIDATE','ORDER_SUPPLIER_APPROVE','ORDER_SUPPLIER_REFUSE');
/**
* Constructor.
* @param DB Database handler
*/
function InterfaceNotification($DB)
{
$this->db = $DB ;
$this->name = preg_replace('/^Interface/i','',get_class($this));
$this->family = "notification";
$this->description = "Triggers of this module send email notifications according to Notification module setup.";
$this->version = 'dolibarr'; // 'experimental' or 'dolibarr' or version
$this->picto = 'email';
}
/**
* Return name of trigger file
* @return string Name of trigger file
*/
function getName()
{
return $this->name;
}
/**
* Return description of trigger file
* @return string Description of trigger file
*/
function getDesc()
{
return $this->description;
}
/**
* Return version of trigger file
* @return string Version of trigger file
*/
function getVersion()
{
global $langs;
$langs->load("admin");
if ($this->version == 'experimental') return $langs->trans("Experimental");
elseif ($this->version == 'dolibarr') return DOL_VERSION;
elseif ($this->version) return $this->version;
else return $langs->trans("Unknown");
}
/**
* Function called when a Dolibarrr business event is done.
* All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers
* @param action Event code (COMPANY_CREATE, PROPAL_VALIDATE, ...)
* @param object Object action is done on
* @param user Object user
* @param langs Object langs
* @param conf Object conf
* @return int <0 if KO, 0 if no action are done, >0 if OK
*/
function run_trigger($action,$object,$user,$langs,$conf)
{
if (empty($conf->notification->enabled)) return 0; // Module not active, we do nothing
require_once(DOL_DOCUMENT_ROOT .'/core/class/notify.class.php');
if ($action == 'BILL_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$ref = dol_sanitizeFileName($object->ref);
$filepdf = $conf->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf';
if (! file_exists($filepdf)) $filepdf='';
$filepdf=''; // We can't add PDF as it is not generated yet.
$langs->load("other");
$mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$object->ref);
$notify = new Notify($this->db);
$notify->send($action, $object->socid, $mesg, 'facture', $object->id, $filepdf);
}
elseif ($action == 'ORDER_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$ref = dol_sanitizeFileName($object->ref);
$filepdf = $conf->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf';
if (! file_exists($filepdf)) $filepdf='';
$filepdf=''; // We can't add PDF as it is not generated yet.
$langs->load("other");
$mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated",$object->ref);
$notify = new Notify($this->db);
$notify->send($action, $object->socid, $mesg, 'order', $object->id, $filepdf);
}
elseif ($action == 'PROPAL_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$ref = dol_sanitizeFileName($object->ref);
$filepdf = $conf->propale->dir_output . '/' . $ref . '/' . $ref . '.pdf';
if (! file_exists($filepdf)) $filepdf='';
$filepdf=''; // We can't add PDF as it is not generated yet.
$langs->load("other");
$mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$object->ref);
$notify = new Notify($this->db);
$notify->send($action, $object->socid, $mesg, 'propal', $object->id, $filepdf);
}
elseif ($action == 'FICHEINTER_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$ref = dol_sanitizeFileName($object->ref);
$filepdf = $conf->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf';
if (! file_exists($filepdf)) $filepdf='';
$filepdf=''; // We can't add PDF as it is not generated yet.
$langs->load("other");
$mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$object->ref);
$notify = new Notify($this->db);
$notify->send($action, $object->socid, $mesg, 'ficheinter', $object->id, $filepdf);
}
elseif ($action == 'ORDER_SUPPLIER_APPROVE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$ref = dol_sanitizeFileName($object->ref);
$filepdf = $conf->fournisseur->dir_output . '/commande/' . $ref . '/' . $ref . '.pdf';
if (! file_exists($filepdf)) $filepdf='';
$mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$object->ref,$user->getFullName($langs));
$mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
$notify = new Notify($this->db);
$notify->send($action, $object->socid, $mesg, 'order_supplier', $object->id, $filepdf);
}
elseif ($action == 'ORDER_SUPPLIER_REFUSE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$ref = dol_sanitizeFileName($object->ref);
$filepdf = $conf->fournisseur->dir_output . '/commande/' . $ref . '/' . $ref . '.pdf';
if (! file_exists($filepdf)) $filepdf='';
$mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$object->ref,$user->getFullName($langs));
$mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
$notify = new Notify($this->db);
$notify->send($action, $object->socid, $mesg, 'order_supplier', $object->id, $filepdf);
}
// If not found
/*
else
{
dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action.");
return -1;
}
*/
return 0;
}
/**
* Return list of events managed by notification module
* @return array Array of events managed by notification module
*/
function getListOfManagedEvents()
{
global $conf,$langs;
$ret=array();
$sql = "SELECT rowid, code, label, description, elementtype";
$sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger";
$sql.= $this->db->order("elementtype, code");
dol_syslog("Get list of notifications sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
$num=$this->db->num_rows($resql);
$i=0;
while ($i < $num)
{
$obj=$this->db->fetch_object($resql);
$qualified=0;
// Check is this event is supported by notification module
if (in_array($obj->code,$this->listofmanagedevents)) $qualified=1;
// Check if module for this event is active
if ($qualified)
{
//print 'xx'.$obj->code;
$element=$obj->elementtype;
if ($element == 'order_supplier' && empty($conf->fournisseur->enabled)) $qualified=0;
elseif ($element == 'invoice_supplier' && empty($conf->fournisseur->enabled)) $qualified=0;
elseif ($element == 'withdraw' && empty($conf->prelevement->enabled)) $qualified=0;
elseif ($element == 'shipping' && empty($conf->expedition->enabled)) $qualified=0;
elseif ($element == 'member' && empty($conf->adherent->enabled)) $qualified=0;
elseif (! in_array($element,array('order_supplier','invoice_supplier','withdraw','shipping','member'))
&& empty($conf->$element->enabled)) $qualified=0;
}
if ($qualified)
{
$ret[]=array('rowid'=>$obj->rowid,'code'=>$obj->code,'label'=>$obj->label,'description'=>$obj->description,'elementtype'=>$obj->elementtype);
}
$i++;
}
}
else dol_print_error($this->db);
return $ret;
}
}
?>

View File

@@ -1,138 +0,0 @@
<?php
/* Copyright (C) 2011 Regis Houssin <regis@dolibarr.fr>
*
* 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 2 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/>.
*/
/**
* \file /htdocs/core/triggers/interface_modPaypal_PaypalWorkflow.class.php
* \ingroup paypal
* \brief Trigger file for paypal workflow
*/
/**
* \class InterfacePaypalWorkflow
* \brief Class of triggers for paypal module
*/
class InterfacePaypalWorkflow
{
var $db;
/**
* Constructor
* @param DB Database handler
*/
function InterfacePaypalWorkflow($DB)
{
$this->db = $DB ;
$this->name = preg_replace('/^Interface/i','',get_class($this));
$this->family = "paypal";
$this->description = "Triggers of this module allows to manage paypal workflow";
$this->version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' or version
$this->picto = 'paypal@paypal';
}
/**
* \brief Renvoi nom du lot de triggers
* \return string Nom du lot de triggers
*/
function getName()
{
return $this->name;
}
/**
* \brief Renvoi descriptif du lot de triggers
* \return string Descriptif du lot de triggers
*/
function getDesc()
{
return $this->description;
}
/**
* \brief Renvoi version du lot de triggers
* \return string Version du lot de triggers
*/
function getVersion()
{
global $langs;
$langs->load("admin");
if ($this->version == 'development') return $langs->trans("Development");
elseif ($this->version == 'experimental') return $langs->trans("Experimental");
elseif ($this->version == 'dolibarr') return DOL_VERSION;
elseif ($this->version) return $this->version;
else return $langs->trans("Unknown");
}
/**
* Fonction appelee lors du declenchement d'un evenement Dolibarr.
* D'autres fonctions run_trigger peuvent etre presentes dans core/triggers
*
* @param string $action Code de l'evenement
* @param CommonObject $object Objet concerne
* @param User $user Objet user
* @param Translate $lang Objet lang
* @param Conf $conf Objet conf
* @return int <0 if fatal error, 0 si nothing done, >0 if ok
*/
function run_trigger($action,$object,$user,$langs,$conf)
{
// Mettre ici le code a executer en reaction de l'action
// Les donnees de l'action sont stockees dans $object
if ($action == 'PAYPAL_PAYMENT_OK')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". source=".$object->source." ref=".$object->ref);
require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php");
$soc = new Societe($this->db);
// Parse element/subelement (ex: project_task)
$element = $path = $filename = $object->source;
if (preg_match('/^([^_]+)_([^_]+)/i',$object->source,$regs))
{
$element = $path = $regs[1];
$filename = $regs[2];
}
// For compatibility
if ($element == 'order') { $path = $filename = 'commande'; }
if ($element == 'invoice') { $path = 'compta/facture'; $filename = 'facture'; }
dol_include_once('/'.$path.'/class/'.$filename.'.class.php');
$classname = ucfirst($filename);
$obj = new $classname($this->db);
$ret = $obj->fetch('',$object->ref);
if ($ret < 0) return -1;
// Add payer id
$soc->setValueFrom('ref_int', $object->payerID, 'societe', $obj->socid);
// Add transaction id
$obj->setValueFrom('ref_int',$object->resArray["TRANSACTIONID"]);
}
return 0;
}
}
?>

View File

@@ -1,134 +0,0 @@
<?php
/* Copyright (C) 2010 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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 2 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/>.
*/
/**
* \file htdocs/core/triggers/interface_modWorkflow_WorkflowManager.class.php
* \ingroup core
* \brief Trigger file for workflows
*/
/**
* \class InterfaceWorkflowManager
* \brief Class of triggers for workflow module
*/
class InterfaceWorkflowManager
{
var $db;
/**
* Constructor.
* @param DB Database handler
*/
function InterfaceWorkflowManager($DB)
{
$this->db = $DB ;
$this->name = preg_replace('/^Interface/i','',get_class($this));
$this->family = "core";
$this->description = "Triggers of this module allows to manage workflows";
$this->version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' or version
$this->picto = 'technic';
}
/**
* Return name of trigger file
* @return string Name of trigger file
*/
function getName()
{
return $this->name;
}
/**
* Return description of trigger file
* @return string Description of trigger file
*/
function getDesc()
{
return $this->description;
}
/**
* Return version of trigger file
* @return string Version of trigger file
*/
function getVersion()
{
global $langs;
$langs->load("admin");
if ($this->version == 'development') return $langs->trans("Development");
elseif ($this->version == 'experimental') return $langs->trans("Experimental");
elseif ($this->version == 'dolibarr') return DOL_VERSION;
elseif ($this->version) return $this->version;
else return $langs->trans("Unknown");
}
/**
* Function called when a Dolibarrr business event is done.
* All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers
*
* @param action Event code (COMPANY_CREATE, PROPAL_VALIDATE, ...)
* @param object Object action is done on
* @param user Object user
* @param langs Object langs
* @param conf Object conf
* @return int <0 if KO, 0 if no action are done, >0 if OK
*/
function run_trigger($action,$object,$user,$langs,$conf)
{
if (empty($conf->workflow->enabled)) return 0; // Module not active, we do nothing
// Proposals to order
if ($action == 'PROPAL_CLOSE_SIGNED')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if (! empty($conf->commande->enabled) && ! empty($conf->global->WORKFLOW_PROPAL_AUTOCREATE_ORDER))
{
include_once(DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php');
$newobject = new Commande($this->db);
$ret=$newobject->createFromProposal($object);
if ($ret < 0) { $this->error=$newobject->error; $this->errors[]=$newobject->error; }
return $ret;
}
}
// Order to invoice
if ($action == 'ORDER_CLOSE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if (! empty($conf->facture->enabled) && ! empty($conf->global->WORKFLOW_ORDER_AUTOCREATE_INVOICE))
{
include_once(DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php');
$newobject = new Facture($this->db);
$ret=$newobject->createFromOrder($object);
if ($ret < 0) { $this->error=$newobject->error; $this->errors[]=$newobject->error; }
return $ret;
}
}
return 0;
}
}
?>

View File

@@ -18,7 +18,7 @@
-- ======================================================================== -- ========================================================================
-- This table logs all dolibarr security events -- This table logs all dolibarr security events
-- Content of this table is not managed by users but by Dolibarr -- Content of this table is not managed by users but by Dolibarr
-- trigger interface_all_LogEvent. -- trigger interface_20_all_Logevents.
-- ======================================================================== -- ========================================================================
create table llx_events create table llx_events

View File

@@ -26,7 +26,7 @@
require("../../main.inc.php"); require("../../main.inc.php");
require_once(DOL_DOCUMENT_ROOT."/core/lib/company.lib.php"); require_once(DOL_DOCUMENT_ROOT."/core/lib/company.lib.php");
require_once(DOL_DOCUMENT_ROOT."/contact/class/contact.class.php"); require_once(DOL_DOCUMENT_ROOT."/contact/class/contact.class.php");
require_once(DOL_DOCUMENT_ROOT."/core/triggers/interface_modNotification_Notification.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/triggers/interface_50_modNotification_Notification.class.php");
$langs->load("companies"); $langs->load("companies");
$langs->load("mails"); $langs->load("mails");

View File

@@ -383,7 +383,7 @@ a.tmenu:link, a.tmenu:visited, a.tmenu:hover, a.tmenu:active {
padding: 0px 5px 0px 5px; padding: 0px 5px 0px 5px;
margin: 0px 1px 2px 1px; margin: 0px 1px 2px 1px;
white-space: nowrap; white-space: nowrap;
text-shadow: 1px 2px 3px #AFAFAF; text-shadow: 1px 2px 4px #BFBFBF;
} }
a.tmenu:hover, a.tmenu:active { a.tmenu:hover, a.tmenu:active {
margin: 0px 0px 0px 0px; margin: 0px 0px 0px 0px;
@@ -394,7 +394,7 @@ a.tmenu:hover, a.tmenu:active {
} }
a.tmenu:hover, a.tmenu:active { a.tmenu:hover, a.tmenu:active {
background: #F4F4F4; background: #F4F4F4;
text-shadow: 1px 2px 3px #AFAFAF; text-shadow: 1px 2px 4px #BFBFBF;
} }
a.tmenusel:link, a.tmenusel:visited, a.tmenusel:hover, a.tmenusel:active { a.tmenusel:link, a.tmenusel:visited, a.tmenusel:hover, a.tmenusel:active {
@@ -408,7 +408,7 @@ a.tmenusel:link, a.tmenusel:visited, a.tmenusel:hover, a.tmenusel:active {
border-<?php print $left; ?>: 1px solid #D8D8D8; border-<?php print $left; ?>: 1px solid #D8D8D8;
border-bottom: 2px solid #F4F4F4; border-bottom: 2px solid #F4F4F4;
white-space: nowrap; white-space: nowrap;
text-shadow: 1px 2px 3px #AFAFAF; text-shadow: 1px 2px 4px #BFBFBF;
} }
@@ -1693,7 +1693,7 @@ div.titre {
font-weight: bold; font-weight: bold;
color: rgb(<?php print $colortext; ?>); color: rgb(<?php print $colortext; ?>);
text-decoration: none; text-decoration: none;
text-shadow: 1px 2px 3px #AFAFAF; text-shadow: 2px 2px 4px #BFBFBF;
} }