Can use several root directories.

This commit is contained in:
Laurent Destailleur 2008-12-07 19:19:32 +00:00
parent bc3710d874
commit 8b263e4b16
13 changed files with 262 additions and 198 deletions

View File

@ -65,7 +65,7 @@ if ($_GET["action"] == 'reset' && $user->admin)
*/
function Activate($value,$withdeps=1)
{
global $db, $modules, $langs;
global $db, $modules, $langs, $conf;
$modName = $value;
@ -75,8 +75,13 @@ function Activate($value,$withdeps=1)
if ($modName)
{
$file = $modName . ".class.php";
$res=@include_once(DOL_DOCUMENT_ROOT."/includes/modules/".$file);
if (defined('DOL_DOCUMENT_ROOT_BIS') && ! $res) include_once(DOL_DOCUMENT_ROOT_BIS."/includes/modules/".$file);
// Loop on each directory
foreach ($conf->dol_document_root as $dol_document_root)
{
$found=@include_once($dol_document_root."/includes/modules/".$file);
if ($found) break;
}
$objMod = new $modName($db);
@ -136,10 +141,15 @@ function UnActivate($value,$requiredby=1)
if ($modName)
{
$file = $modName . ".class.php";
$res=@include_once(DOL_DOCUMENT_ROOT."/includes/modules/".$file);
if (defined('DOL_DOCUMENT_ROOT_BIS') && ! $res) include_once(DOL_DOCUMENT_ROOT_BIS."/includes/modules/".$file);
if ($res)
// Loop on each directory
foreach ($conf->dol_document_root as $dol_document_root)
{
$found=@include_once($dol_document_root."/includes/modules/".$file);
if ($found) break;
}
if ($found)
{
$objMod = new $modName($db);
$result=$objMod->remove();
@ -180,10 +190,6 @@ print_fiche_titre($langs->trans("ModulesSetup"),'','setup');
// Search modules
$dirlist=array();
$dirlist[]=DOL_DOCUMENT_ROOT;
if (defined('DOL_DOCUMENT_ROOT_BIS')) $dirlist[]=DOL_DOCUMENT_ROOT_BIS;
$filename = array();
$modules = array();
$orders = array();
@ -191,7 +197,7 @@ $categ = array();
$dirmod = array();
$i = 0; // is a sequencer of modules found
$j = 0; // j is module number. Automatically affeted if module number not defined.
foreach ($dirlist as $dirroot)
foreach ($conf->dol_document_root as $dirroot)
{
$dir = $dirroot . "/includes/modules/";

View File

@ -76,7 +76,7 @@ print "<tr ".$bc[$var]."><td width=\"300\">".$langs->trans("LanguageParameter","
$var=!$var;
print "<tr ".$bc[$var].'><td width="300">=> price2num(1234.56)</td><td>'.price2num(1233.56+1,'2')."</td></tr>";
$var=!$var;
print "<tr ".$bc[$var].'><td width="300">=> dolibarr_print_date(0,"daytext")</td><td>'.dolibarr_print_date(0,"daytext")."</td>";
print "<tr ".$bc[$var].'><td width="300">=> dolibarr_print_date(0,"dayhourtext")</td><td>'.dolibarr_print_date(0,"dayhourtext")."</td>";
// Thousands
$var=!$var;
$thousand=$langs->trans("SeparatorThousand");

View File

@ -33,7 +33,7 @@ if (! $user->rights->mailing->lire || $user->societe_id > 0)
$dirmod=DOL_DOCUMENT_ROOT."/includes/modules/mailings";
if (defined('DOL_DOCUMENT_ROOT_BIS')) $dirmod2=DOL_DOCUMENT_ROOT_BIS."/includes/modules/mailings";
$mesg = '';
@ -193,14 +193,12 @@ if ($mil->fetch($_REQUEST["id"]) >= 0)
print "</tr>\n";
clearstatcache();
$listdir=array();
$listdir[]=$dirmod;
if (! empty($dirmod2)) $listdir[]=$dirmod2;
$var=true;
foreach ($listdir as $dir)
$var=true;
foreach ($conf->dol_document_root as $dirroot)
{
$dir=$dirroot."/includes/modules/mailings/";
if (is_dir($dir))
{
$handle=opendir($dir);
@ -216,7 +214,7 @@ if ($mil->fetch($_REQUEST["id"]) >= 0)
if ($modulename == 'example') continue;
// Chargement de la classe
$file = $dir."/".$modulename.".modules.php";
$file = $dir.$modulename.".modules.php";
$classname = "mailing_".$modulename;
require_once($file);

View File

@ -42,32 +42,13 @@ class Conf
//! Charset for HTML output
var $character_set_client; // UTF8, ISO-8859-1
var $externalrss;
var $commande;
var $ficheinter;
var $commercial;
var $societe;
var $expedition;
var $compta;
var $banque;
var $don;
var $caisse;
var $fournisseur;
var $adherent;
var $produit;
var $service;
var $stock;
var $boutique;
var $projet;
var $postnuke;
var $webcal;
var $mantis;
var $propal;
var $categorie;
var $oscommerce2;
var $monnaie;
var $css;
var $dol_document_root;
var $monnaie; // Used to store current currency
var $css; // Used to store current css (from theme)
var $css_modules=array();
var $tabs_modules=array();
/**
@ -108,6 +89,14 @@ class Conf
{
$this->css_modules[]=$value;
}
// If this is constant for a new tab page activated by a module
if (eregi('^MAIN_MODULE_([A-Z_]+)_TABS_',$key) && $value)
{
$params=split(':',$value,2);
$this->tabs_modules[$params[0]][]=$value;
//print 'xxx'.$params[0].'-'.$value;
}
// If this is a module constant
if (eregi('^MAIN_MODULE_([A-Z]+)$',$key,$reg) && $value)
{
$module=strtolower($reg[1]);

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2008 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
@ -18,10 +18,10 @@
*/
/**
\file htdocs/includes/boxes/box_produits.php
\ingroup produits,services
\brief Module de g<EFBFBD>n<EFBFBD>ration de l'affichage de la box produits
\version $Id$
* \file htdocs/includes/boxes/box_produits.php
* \ingroup produits,services
* \brief Module de generation de l'affichage de la box produits
* \version $Id$
*/
include_once(DOL_DOCUMENT_ROOT."/includes/boxes/modules_boxes.php");
@ -126,7 +126,7 @@ class box_produits extends ModeleBoxes {
$this->info_box_contents[$i][2] = array('td' => 'align="right"',
'text' => $price);
$this->info_box_contents[$i][3] = array('td' => 'align="center" width="20"',
$this->info_box_contents[$i][3] = array('td' => 'align="center" width="20" nowrap="nowrap"',
'text' => $price_base_type);
$this->info_box_contents[$i][4] = array('td' => 'align="right"',

View File

@ -21,15 +21,15 @@
*/
/**
\file htdocs/includes/modules/DolibarrModules.class.php
\brief Fichier de description et activation des modules Dolibarr
\version $Id$
* \file htdocs/includes/modules/DolibarrModules.class.php
* \brief Fichier de description et activation des modules Dolibarr
* \version $Id$
*/
/**
\class DolibarrModules
\brief Classe mere des classes de description et activation des modules Dolibarr
* \class DolibarrModules
* \brief Classe mere des classes de description et activation des modules Dolibarr
*/
class DolibarrModules
{
@ -85,6 +85,9 @@ class DolibarrModules
// Insere le nom de la feuille de style
if (! $err) $err+=$this->insert_style_sheet();
// Insert new pages for tabs into llx_const
if (! $err) $err+=$this->insert_tabs();
// Insere les constantes associees au module dans llx_const
if (! $err) $err+=$this->insert_const();
@ -182,6 +185,9 @@ class DolibarrModules
// Supprime les boites de la liste des boites disponibles
$err+=$this->delete_style_sheet();
// Supprime les liens de pages en onglets issus de modules
$err+=$this->delete_tabs();
// Supprime les boites de la liste des boites disponibles
$err+=$this->delete_boxes();
@ -533,9 +539,9 @@ class DolibarrModules
}
/**
\brief Desactive feuille de style du module par suppression ligne dans llx_const
\return int Nombre d'erreurs (0 si ok)
*/
* \brief Desactive feuille de style du module par suppression ligne dans llx_const
* \return int Nombre d'erreurs (0 si ok)
*/
function delete_style_sheet()
{
$err=0;
@ -555,8 +561,27 @@ class DolibarrModules
}
/**
\brief Active la feuille de style associee au module par insertion ligne dans llx_const
\return int Nombre d'erreurs (0 si ok)
* \brief Remove links to new module page present in llx_const
* \return int Nombre d'erreurs (0 si ok)
*/
function delete_tabs()
{
$err=0;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE name like '".$this->const_name."_TABS_%'";
dolibarr_syslog("DolibarrModules::delete_tabs sql=".$sql);
if (! $this->db->query($sql))
{
$err++;
}
return $err;
}
/**
* \brief Active la feuille de style associee au module par insertion ligne dans llx_const
* \return int Nombre d'erreurs (0 si ok)
*/
function insert_style_sheet()
{
@ -580,8 +605,40 @@ class DolibarrModules
}
/**
\brief Insere les constantes associees au module dans llx_const
\return int Nombre d'erreurs (0 si ok)
* \brief Add links of new pages from modules in llx_const
* \return int Number of errors (0 if ok)
*/
function insert_tabs()
{
$err=0;
if (! empty($this->tabs))
{
$i=0;
foreach ($this->tabs as $key => $value)
{
if ($value)
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,type,value,note,visible)";
$sql.= " VALUES ('".$this->const_name."_TABS_".$i."','chaine','".$value."',null,'0')";
dolibarr_syslog("DolibarrModules::insert_tabs sql=".$sql);
$resql=$this->db->query($sql);
/* Allow duplicate key
if (! $resql)
{
$err++;
}
*/
}
$i++;
}
}
return $err;
}
/**
* \brief Insere les constantes associees au module dans llx_const
* \return int Nombre d'erreurs (0 si ok)
*/
function insert_const()
{

View File

@ -36,7 +36,7 @@ include_once DOL_DOCUMENT_ROOT.'/includes/modules/mailings/modules_mailings.php'
class mailing_poire extends MailingTargets
{
var $name='ContactCompanies'; // Identifiant du module mailing
var $desc='Contacts des sociétés'; // Libellé utilisé si aucune traduction pour MailingModuleDescXXX ou XXX=name trouvée
var $desc='Contacts des societes'; // Libellé utilisé si aucune traduction pour MailingModuleDescXXX ou XXX=name trouvée
var $require_module=array("commercial"); // Module mailing actif si modules require_module actifs
var $require_admin=0; // Module mailing actif pour user admin ou non
var $picto='contact';

View File

@ -108,22 +108,36 @@ function product_prepare_head($product, $user)
{
if ($conf->stock->enabled)
{
$head[$h][0] = DOL_URL_ROOT."/product/stock/product.php?id=".$product->id;
$head[$h][1] = $langs->trans("Stock");
$head[$h][2] = 'stock';
$h++;
$head[$h][0] = DOL_URL_ROOT."/product/stock/product.php?id=".$product->id;
$head[$h][1] = $langs->trans("Stock");
$head[$h][2] = 'stock';
$h++;
}
}
/*
* Onglets additionnels pour les canvas
*/
if(is_array($product->onglets))
// More tabs from modules
if (is_array($conf->tabs_modules['product']))
{
$i=0;
foreach ($conf->tabs_modules['product'] as $value)
{
$values=split(':',$value);
if ($values[2]) $langs->load($values[2]);
$head[$h][0] = eregi_replace('__ID__',$product->id,$values[3]);
$head[$h][1] = $langs->trans($values[1]);
$head[$h][2] = 'module'.$i;
$h++;
}
}
// More tabs from canvas
if (is_array($product->onglets))
{
foreach ($product->onglets as $onglet)
{
$head[$h] = $onglet;
$h++;
$head[$h] = $onglet;
$h++;
}
}

View File

@ -470,7 +470,7 @@ if (! empty($_GET["lang"]))
}
// Remplace conf->css par valeur personnalise
// Replace conf->css by personalized value
if (isset($user->conf->MAIN_THEME) && $user->conf->MAIN_THEME)
{
$conf->theme=$user->conf->MAIN_THEME;

View File

@ -90,9 +90,6 @@ $pos = strstr ($uri, '/'); // $pos contient alors url sans nom domaine
if ($pos == '/') $pos = ''; // si $pos vaut /, on le met a ''
define('DOL_URL_ROOT', $pos); // URL racine relative
// Special code for alternate dev directories (Used on dev env only)
if (! empty($dolibarr_main_document_root_bis)) define('DOL_DOCUMENT_ROOT_BIS', $dolibarr_main_document_root_bis);
/*
* Controle validite fichier conf
@ -106,7 +103,7 @@ if (! file_exists(DOL_DOCUMENT_ROOT ."/lib/functions.lib.php"))
/*
* Creation objet $conf
* Create $conf object
*/
// on décode le mot de passe de la base si besoin
@ -145,6 +142,18 @@ $charset='UTF-8'; // If not output format found in any conf file
if (empty($character_set_client)) $character_set_client=$charset;
$conf->character_set_client=strtoupper($character_set_client);
// Define array of document root directories
$conf->dol_document_root=array(DOL_DOCUMENT_ROOT);
if (! empty($dolibarr_main_document_root_alt))
{
// dolibarr_main_document_root_alt contains several directories
$values=split(';',$dolibarr_main_document_root_alt);
foreach($values as $value)
{
$conf->dol_document_root[]=$value;
}
}
// Defini prefix
if (isset($_SERVER["LLX_DBNAME"])) $dolibarr_main_db_prefix=$_SERVER["LLX_DBNAME"];
define('MAIN_DB_PREFIX',$dolibarr_main_db_prefix);

View File

@ -103,9 +103,7 @@ llxHeaderVierge($langs->trans("DolibarrDemo"));
// Search modules
$dirlist=array();
$dirlist[]=DOL_DOCUMENT_ROOT;
if (defined('DOL_DOCUMENT_ROOT_BIS')) $dirlist[]=DOL_DOCUMENT_ROOT_BIS;
$dirlist=$conf->dol_document_root;
$filename = array();
$modules = array();

View File

@ -33,8 +33,7 @@
*/
class Translate {
var $dir; // Directory with translation files
var $dir_bis; // Second directory with translation files (for development on two workspaces)
var $dir; // Directories with translation files
var $defaultlang; // Langue courante en vigueur de l'utilisateur
@ -59,9 +58,8 @@ class Translate {
{
$this->charset_output=$conf->character_set_client;
}
$this->dir=(! $dir ? DOL_DOCUMENT_ROOT ."/langs" : $dir);
// For developpement purpose
$this->dir_bis=(defined('DOL_DOCUMENT_ROOT_BIS') ? DOL_DOCUMENT_ROOT_BIS ."/langs" : "");
if ($dir) $this->dir=array($dir);
else $this->dir=$conf->dol_document_root;
}
@ -183,118 +181,113 @@ class Translate {
// Check cache
if (! empty($this->tab_loaded[$domain])) { return; } // Le fichier de ce domaine est deja charge
$searchdir=$this->dir;
// If $domain is @xxx instead of xxx then we look for module lang file htdocs/xxx/langs/code_CODE/xxx.lang
// instead of global lang file htdocs/langs/code_CODE/xxx.lang
if (eregi('@',$domain)) // It's a language file of a module, we look in dir of this module.
{
$domain=eregi_replace('@','',$domain);
$searchdir=DOL_DOCUMENT_ROOT ."/".$domain."/langs";
}
// Directory of translation files
$scandir = $searchdir."/".$this->defaultlang;
$file_lang = $scandir . "/".$domain.".lang";
$filelangexists=is_file($file_lang);
// If development with 2 workspaces (for development purpose only)
if (! $filelangexists && $this->dir_bis)
{
$scandir = $this->dir_bis."/".$this->defaultlang;
foreach($this->dir as $searchdir)
{
// If $domain is @xxx instead of xxx then we look for module lang file htdocs/xxx/langs/code_CODE/xxx.lang
// instead of global lang file htdocs/langs/code_CODE/xxx.lang
if (eregi('@',$domain)) // It's a language file of a module, we look in dir of this module.
{
$domain=eregi_replace('@','',$domain);
$searchdir=$searchdir ."/".$domain."/langs";
}
else $searchdir=$searchdir."/langs";
//print 'rrr'.$searchdir;
// Directory of translation files
$scandir = $searchdir."/".$this->defaultlang;
$file_lang = $scandir . "/".$domain.".lang";
$filelangexists=is_file($file_lang);
}
// Check in "always available" alternate file if not found or if asked
if ($alt || ! $filelangexists)
{
// Dir of always available alternate file (en_US or fr_FR)
if ($this->defaultlang == "en_US") $scandiralt = $searchdir."/fr_FR";
elseif (eregi('^fr',$this->defaultlang) && $this->defaultlang != 'fr_FR') $scandiralt = $searchdir."/fr_FR";
elseif (eregi('^en',$this->defaultlang) && $this->defaultlang != 'en_US') $scandiralt = $searchdir."/en_US";
elseif (eregi('^es',$this->defaultlang) && $this->defaultlang != 'es_ES') $scandiralt = $searchdir."/es_ES";
else $scandiralt = $searchdir."/en_US";
$file_lang = $scandiralt . "/".$domain.".lang";
$filelangexists=is_file($file_lang);
$alt=1;
}
if ($filelangexists)
{
// Enable cache of lang file in session (faster but need more memory)
// Speed gain: 40ms - Memory overusage: 200ko (Size of session cache file)
$enablelangcacheinsession=false;
if ($enablelangcacheinsession && isset($_SESSION['lang_'.$domain]))
{
foreach($_SESSION['lang_'.$domain] as $key => $value)
// Check in "always available" alternate file if not found or if asked
if ($alt || ! $filelangexists)
{
// Dir of always available alternate file (en_US or fr_FR)
if ($this->defaultlang == "en_US") $scandiralt = $searchdir."/fr_FR";
elseif (eregi('^fr',$this->defaultlang) && $this->defaultlang != 'fr_FR') $scandiralt = $searchdir."/fr_FR";
elseif (eregi('^en',$this->defaultlang) && $this->defaultlang != 'en_US') $scandiralt = $searchdir."/en_US";
elseif (eregi('^es',$this->defaultlang) && $this->defaultlang != 'es_ES') $scandiralt = $searchdir."/es_ES";
else $scandiralt = $searchdir."/en_US";
$file_lang = $scandiralt . "/".$domain.".lang";
$filelangexists=is_file($file_lang);
$alt=1;
}
if ($filelangexists)
{
// Enable cache of lang file in session (faster but need more memory)
// Speed gain: 40ms - Memory overusage: 200ko (Size of session cache file)
$enablelangcacheinsession=false;
if ($enablelangcacheinsession && isset($_SESSION['lang_'.$domain]))
{
$this->tab_translate[$key]=$value;
$this->tab_loaded[$domain]=3; // Marque ce fichier comme charge depuis cache session
foreach($_SESSION['lang_'.$domain] as $key => $value)
{
$this->tab_translate[$key]=$value;
$this->tab_loaded[$domain]=3; // Marque ce fichier comme charge depuis cache session
}
}
}
else
{
if ($fp = @fopen($file_lang,"rt"))
{
if ($enablelangcacheinsession) $tabtranslatedomain=array(); // To save lang in session
$finded = 0;
while (($ligne = fgets($fp,4096)) && ($finded == 0))
{
if ($ligne[0] != "\n" && $ligne[0] != " " && $ligne[0] != "#")
{
$tab=split('=',$ligne,2);
$key=trim($tab[0]); $value='';
//print "Domain=$domain, found a string for $tab[0] with value $tab[1]<br>";
//if (! $this->getTransFromTab($key))
if (empty($this->tab_translate[$key]) && isset($tab[1]))
{
$value=trim(ereg_replace('\\\n',"\n",$tab[1]));
if (eregi('^CHARSET$',$key))
{
// On est tombe sur une balise qui declare le format du fichier lu
$this->charset_inputfile=strtoupper($value);
//print 'File '.$file_lang.' has format '.$this->charset_inputfile.'<br>';
}
else
{
// On stocke toujours dans le tableau Tab en UTF-8
//if ($this->charset_inputfile == 'UTF-8') $value=utf8_decode($value);
if ($this->charset_inputfile == 'ISO-8859-1') $value=utf8_encode($value);
// We do not load Separator values for alternate files
if (! $alt || (! eregi('^Separator',$key)))
else
{
if ($fp = @fopen($file_lang,"rt"))
{
if ($enablelangcacheinsession) $tabtranslatedomain=array(); // To save lang in session
$finded = 0;
while (($ligne = fgets($fp,4096)) && ($finded == 0))
{
if ($ligne[0] != "\n" && $ligne[0] != " " && $ligne[0] != "#")
{
$tab=split('=',$ligne,2);
$key=trim($tab[0]); $value='';
//print "Domain=$domain, found a string for $tab[0] with value $tab[1]<br>";
//if (! $this->getTransFromTab($key))
if (empty($this->tab_translate[$key]) && isset($tab[1]))
{
$value=trim(ereg_replace('\\\n',"\n",$tab[1]));
if (eregi('^CHARSET$',$key))
{
$this->tab_translate[$key]=$value;
// On est tombe sur une balise qui declare le format du fichier lu
$this->charset_inputfile=strtoupper($value);
//print 'File '.$file_lang.' has format '.$this->charset_inputfile.'<br>';
}
if ($enablelangcacheinsession) $tabtranslatedomain[$key]=$value; // To save lang in session
}
}
}
}
fclose($fp);
// Pour les langues aux fichiers parfois incomplets, on charge la langue alternative
if (! $alt && $this->defaultlang != "fr_FR" && $this->defaultlang != "en_US")
{
dolibarr_syslog("Translate::Load loading alternate translation file (to complete ".$this->defaultlang."/".$domain.".lang file)", LOG_DEBUG);
$this->load($domain,1);
}
$this->tab_loaded[$domain]=1; // Marque ce fichier comme charge
// To save lang in session
if ($enablelangcacheinsession && sizeof($tabtranslatedomain)) $_SESSION['lang_'.$domain]=$tabtranslatedomain;
}
}
}
else
{
$this->tab_loaded[$domain]=2; // Marque ce fichier comme non trouve
}
else
{
// On stocke toujours dans le tableau Tab en UTF-8
//if ($this->charset_inputfile == 'UTF-8') $value=utf8_decode($value);
if ($this->charset_inputfile == 'ISO-8859-1') $value=utf8_encode($value);
// We do not load Separator values for alternate files
if (! $alt || (! eregi('^Separator',$key)))
{
$this->tab_translate[$key]=$value;
}
if ($enablelangcacheinsession) $tabtranslatedomain[$key]=$value; // To save lang in session
}
}
}
}
fclose($fp);
// Pour les langues aux fichiers parfois incomplets, on charge la langue alternative
if (! $alt && $this->defaultlang != "fr_FR" && $this->defaultlang != "en_US")
{
dolibarr_syslog("Translate::Load loading alternate translation file (to complete ".$this->defaultlang."/".$domain.".lang file)", LOG_DEBUG);
$this->load($domain,1);
}
$this->tab_loaded[$domain]=1; // Marque ce fichier comme charge
// To save lang in session
if ($enablelangcacheinsession && sizeof($tabtranslatedomain)) $_SESSION['lang_'.$domain]=$tabtranslatedomain;
break; // Break loop on each root dir
}
}
}
}
if (empty($this->tab_loaded[$domain])) $this->tab_loaded[$domain]=2; // Marque ce fichier comme non trouve
return 1;
}

View File

@ -101,11 +101,11 @@ $db->begin();
// Charge les modules soumis a permissions
$modules = array();
$listdir=array();
$listdir[]=DOL_DOCUMENT_ROOT . "/includes/modules/";
if (defined('DOL_DOCUMENT_ROOT_BIS') && DOL_DOCUMENT_ROOT_BIS) $listdir[]=DOL_DOCUMENT_ROOT_BIS . "/includes/modules/";
foreach($listdir as $dir)
$listdir=$conf->dol_document_root;
foreach($listdir as $dirroot)
{
$dir=$dirroot."/includes/modules/";
$handle=opendir($dir);
while (($file = readdir($handle))!==false)
{