Fix: mutualize code

This commit is contained in:
Regis Houssin 2010-04-02 11:32:34 +00:00
parent 488479de5e
commit 9793a8f13a
2 changed files with 8 additions and 39 deletions

View File

@ -58,47 +58,15 @@ print "</tr>\n";
// Define dir directory // Define dir directory
$interfaces=new Interfaces($db); $interfaces=new Interfaces($db);
$dir = $interfaces->dir; $interfaces->getModulesTriggers();
$handle=opendir($dir); $handle=opendir($dir);
$files = array(); $files = array();
$modules = array(); $modules = array();
$orders = array(); $orders = array();
$i = 0; $i = 0;
while (($file = readdir($handle))!==false)
{
if (is_readable($dir.'/'.$file) && preg_match('/^interface_([^_]+)_(.+)\.class\.php/',$file,$reg))
{
$modName = 'Interface'.ucfirst($reg[2]);
//print "file=$file"; print "modName=$modName"; exit;
if (in_array($modName,$modules))
{
$langs->load("errors");
print '<div class="error">'.$langs->trans("Error").' : '.$langs->trans("ErrorDuplicateTrigger",$modName,"/htdocs/includes/triggers/").'</div>';
$objMod = new $modName($db);
$modules[$i] = $modName; foreach($interfaces->dir as $dir)
$files[$i] = $file;
$orders[$i] = $objMod->family; // Tri par famille
$i++;
}
else
{
include_once($dir.'/'.$file);
$objMod = new $modName($db);
$modules[$i] = $modName;
$files[$i] = $file;
$orders[$i] = $objMod->family; // Tri par famille
$i++;
}
}
}
closedir($handle);
// Find external module triggers
$interfaces->getModulesTriggers();
foreach($interfaces->pathoftriggers as $dir)
{ {
$handle=opendir($dir); $handle=opendir($dir);

View File

@ -33,9 +33,8 @@
class Interfaces class Interfaces
{ {
var $dir; // Directory with all core trigger files var $dir; // Directory with all core and external triggers files
var $errors = array(); // Array for errors var $errors = array(); // Array for errors
var $pathoftriggers = array(); // Array for path of triggers
/** /**
* \brief Constructeur. * \brief Constructeur.
@ -44,7 +43,6 @@ class Interfaces
function Interfaces($DB) function Interfaces($DB)
{ {
$this->db = $DB ; $this->db = $DB ;
$this->dir = DOL_DOCUMENT_ROOT . "/includes/triggers";
} }
/** /**
@ -155,6 +153,9 @@ class Interfaces
{ {
global $conf; global $conf;
// Directory of core triggers
$this->dir[] = DOL_DOCUMENT_ROOT . "/includes/triggers";
foreach($conf->global as $key => $value) foreach($conf->global as $key => $value)
{ {
if (preg_match('/^MAIN_TRIGGER_/',$key)) if (preg_match('/^MAIN_TRIGGER_/',$key))
@ -165,7 +166,7 @@ class Interfaces
{ {
$modulename = strtolower($regs[1]); $modulename = strtolower($regs[1]);
$pathoftrigger = DOL_DOCUMENT_ROOT.'/'.$modulename.'/inc/triggers/'; $pathoftrigger = DOL_DOCUMENT_ROOT.'/'.$modulename.'/inc/triggers/';
$this->pathoftriggers[] = $pathoftrigger; $this->dir[] = $pathoftrigger;
} }
} }
} }