Files
dolibarr/htdocs/interfaces.class.php
Laurent Destailleur d7edb59b09 Fix: Echec des triggers quand il y a 2 triggers avec meme nom
Fix: Mauvais triggers appelé quand creation user.
2006-12-24 15:11:56 +00:00

105 lines
2.8 KiB
PHP

<?php
/* Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*
*/
/**
\file htdocs/interfaces.class.php
\ingroup core
\brief Fichier de la classe de gestion des triggers
*/
/**
\class Interfaces
\brief Classe de la gestion des triggers
*/
class Interfaces
{
var $dir; // Repertoire contenant les fichiers triggers
/**
* \brief Constructeur.
* \param DB handler d'accès base
*/
function Interfaces($DB)
{
$this->db = $DB ;
$this->dir = DOL_DOCUMENT_ROOT . "/includes/triggers";
}
/**
* \brief Fonction appelée lors du déclenchement d'un évènement Dolibarr.
* Cette fonction déclenche tous les triggers trouvés
* \param action Code de l'evenement
* \param object Objet concern
* \param user Objet user
* \param lang Objet lang
* \param conf Objet conf
* \return int Nbre de triggers déclenchés si pas d'erreurs. Nb en erreur sinon.
*/
function run_triggers($action,$object,$user,$lang,$conf)
{
$handle=opendir($this->dir);
$modules = array();
$nbok = $nbko = 0;
while (($file = readdir($handle))!==false)
{
if (is_readable($this->dir."/".$file) && eregi('interface_(.*).class.php$',$file,$reg))
{
$modName = "Interface".ucfirst($reg[1]);
//print "file=$file"; print "modName=$modName"; exit;
if ($modName)
{
if (in_array($modName,$modules))
{
dolibarr_syslog("Error: Trigger file with name '$modName' already launched. Remove duplicate file.");
}
else
{
include_once($this->dir."/".$file);
$objMod = new $modName($this->db);
if ($objMod)
{
$modules[$i] = $modName;
if ($objMod->run_trigger($action,$object,$user,$lang,$conf) > 0)
{
$nbok++;
}
else
{
$nbko++;
}
$i++;
}
}
}
}
}
if ($nbko) return $nbko;
return $nbok;
}
}
?>