';
- print 'Vous avez demandé la création du login Dolibarr "'.$dolibarr_main_db_user.'", mais pour cela, ';
- print 'Dolibarr doit se connecter sur le serveur "'.$dolibarr_main_db_host.'" via le super utilisateur "'.$userroot.'". ';
- print 'La connexion ayant échoué, les paramètres du serveur ou du super utilisateur sont peut-etre incorrects. ';
+ print $langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect",$dolibarr_main_db_user,$dolibarr_main_db_host,$userroot);
+ print ' ';
+ print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'
Vous avez demandé la création de la base Dolibarr "'.$dolibarr_main_db_name.'", mais pour cela, ';
- print 'Dolibarr doit se connecter sur le serveur "'.$dolibarr_main_db_host.'" via le super utilisateur "'.$userroot.'". ';
- print 'La connexion ayant échoué, les paramètres du serveur ou du super utilisateur sont peut-etre incorrects. ';
+ print '
';
diff --git a/htdocs/install/inc.php b/htdocs/install/inc.php
index 0aa484776c1..d8307654a6e 100644
--- a/htdocs/install/inc.php
+++ b/htdocs/install/inc.php
@@ -87,7 +87,7 @@ if (get_magic_quotes_gpc())
// Defini objet langs
-$langs = new Translate('../langs');
+$langs = new Translate('../langs',$conf);
$langs->setDefaultLang('auto');
$langs->setPhpLang();
diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php
index 4f27a70a0a5..adc34fbe03a 100644
--- a/htdocs/install/upgrade2.php
+++ b/htdocs/install/upgrade2.php
@@ -177,7 +177,9 @@ if (isset($_POST['action']) && $_POST['action'] == 'upgrade')
migrate_delete_old_files($db,$langs,$conf);
// Script pour V2.1 -> V2.2
- migrate_paiements_orphelins($db,$langs,$conf);
+ migrate_paiements_orphelins_1($db,$langs,$conf);
+
+ migrate_paiements_orphelins_2($db,$langs,$conf);
// On commit dans tous les cas.
// La procédure etant conçue pour pouvoir passer plusieurs fois quelquesoit la situation.
@@ -281,7 +283,7 @@ function migrate_paiements($db,$langs,$conf)
* Pour verifier s'il reste des orphelins:
* select * from llx_paiement as p left join llx_paiement_facture as pf on pf.fk_paiement=p.rowid WHERE pf.rowid IS NULL AND (p.fk_facture = 0 OR p.fk_facture IS NULL)
*/
-function migrate_paiements_orphelins($db,$langs,$conf)
+function migrate_paiements_orphelins_1($db,$langs,$conf)
{
print '
';
@@ -299,16 +301,16 @@ function migrate_paiements_orphelins($db,$langs,$conf)
$sql.= " AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
$resql = $db->query($sql);
+ $row = array();
if ($resql)
{
$i = $j = 0;
- $row = array();
$num = $db->num_rows($resql);
while ($i < $num)
{
$obj = $db->fetch_object($resql);
- if ($obj->pamount == $obj->bamount) // Pour etre sur d'avoir bon cas
+ if ($obj->pamount == $obj->bamount && $obj->socid) // Pour etre sur d'avoir bon cas
{
$row[$j]['paymentid'] = $obj->rowid ; // paymentid
$row[$j]['pamount'] = $obj->pamount;
@@ -325,49 +327,45 @@ function migrate_paiements_orphelins($db,$langs,$conf)
dolibarr_print_error($db);
}
- if ($num)
+ if (sizeof($row))
{
- print $langs->trans('MigrationPaymentsNumberToUpdate', $num)." \n";
- if ($db->begin())
+ print $langs->trans('MigrationPaymentsNumberToUpdate', sizeof($row))." \n";
+ $db->begin();
+
+ $res = 0;
+ for ($i = 0 ; $i < sizeof($row) ; $i++)
{
- $res = 0;
- for ($i = 0 ; $i < sizeof($row) ; $i++)
- {
- //print '* '.$row[$i]['datec'].' paymentid='.$row[$i]['paymentid'].' '.$row[$i]['pamount'].' fk_bank='.$row[$i]['fk_bank'].' '.$row[$i]['bamount'].' socid='.$row[$i]['socid'].' ';
- // On cherche facture du meme montant pour meme societe.
- // Si y en a plusieurs, on prend la premiere sans lien vers un paiement
- if ($row[$i]['socid'] > 0)
- {
- $sql=" SELECT distinct f.rowid from ".MAIN_DB_PREFIX."facture as f";
- $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture";
- $sql.=" WHERE f.fk_statut in (2,3) AND fk_soc = ".$row[$i]['socid']." AND total_ttc = ".$row[$i]['pamount'];
- $sql.=" AND pf.fk_facture IS NULL";
- $sql.=" ORDER BY f.fk_statut";
- print $sql.' ';
- $resql=$db->query($sql);
- if ($resql)
- {
- $num = $db->num_rows($resql);
- //print 'Nb of invoice found for this amount and company :'.$num.' ';
- if ($num >= 1)
- {
- $obj=$db->fetch_object($resql);
- $facid=$obj->rowid;
-
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount)";
- $sql .= " VALUES (".$facid.",".$row[$i]['paymentid'].",".$row[$i]['pamount'].")";
- $res += $db->query($sql);
+ print '* '.$row[$i]['datec'].' paymentid='.$row[$i]['paymentid'].' '.$row[$i]['pamount'].' fk_bank='.$row[$i]['fk_bank'].' '.$row[$i]['bamount'].' socid='.$row[$i]['socid'].' ';
- print $langs->trans('MigrationProcessPaymentUpdate', 'facid='.$facid.'-paymentid='.$row[$i]['paymentid'].'-amount='.$row[$i]['pamount'])." \n";
- }
- }
- else
- {
- print 'ERROR';
- }
+ // On cherche facture sans lien paiement et du meme montant et pour meme societe.
+ $sql=" SELECT distinct f.rowid from ".MAIN_DB_PREFIX."facture as f";
+ $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture";
+ $sql.=" WHERE f.fk_statut in (2,3) AND fk_soc = ".$row[$i]['socid']." AND total_ttc = ".$row[$i]['pamount'];
+ $sql.=" AND pf.fk_facture IS NULL";
+ $sql.=" ORDER BY f.fk_statut";
+ //print $sql.' ';
+ $resql=$db->query($sql);
+ if ($resql)
+ {
+ $num = $db->num_rows($resql);
+ //print 'Nb of invoice found for this amount and company :'.$num.' ';
+ if ($num >= 1)
+ {
+ $obj=$db->fetch_object($resql);
+ $facid=$obj->rowid;
+
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount)";
+ $sql .= " VALUES (".$facid.",".$row[$i]['paymentid'].",".$row[$i]['pamount'].")";
+ $res += $db->query($sql);
+
+ print $langs->trans('MigrationProcessPaymentUpdate', 'facid='.$facid.'-paymentid='.$row[$i]['paymentid'].'-amount='.$row[$i]['pamount'])." \n";
}
- }
- }
+ }
+ else
+ {
+ print 'ERROR';
+ }
+ }
if ($res > 0)
{
@@ -377,6 +375,8 @@ function migrate_paiements_orphelins($db,$langs,$conf)
{
print $langs->trans('MigrationPaymentsNothingToUpdate')." \n";
}
+
+ $db->commit();
}
else
{
@@ -387,6 +387,128 @@ function migrate_paiements_orphelins($db,$langs,$conf)
}
+/**
+ * Corrige paiement orphelins (liens paumes suite a bugs)
+ * Pour verifier s'il reste des orphelins:
+ * select * from llx_paiement as p left join llx_paiement_facture as pf on pf.fk_paiement=p.rowid WHERE pf.rowid IS NULL AND (p.fk_facture = 0 OR p.fk_facture IS NULL)
+ */
+function migrate_paiements_orphelins_2($db,$langs,$conf)
+{
+ print '
';
+
+ print ' ';
+ print ''.$langs->trans('MigrationPaymentsUpdate')." \n";
+
+ // Tous les enregistrements qui sortent de cette requete devrait avoir un pere dans llx_paiement_facture
+ $sql = "SELECT distinct p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
+ $sql.= " bu2.url_id as socid";
+ $sql.= " FROM (".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."bank_url as bu, ".MAIN_DB_PREFIX."bank as b)";
+ $sql.= " left join llx_paiement_facture as pf on pf.fk_paiement=p.rowid";
+ $sql.= " left join llx_bank_url as bu2 on (bu.fk_bank=bu2.fk_bank AND bu2.type='company')";
+ $sql.= " WHERE pf.rowid IS NULL AND (p.fk_bank=bu.fk_bank AND bu.type='payment') AND bu.fk_bank = b.rowid";
+ $sql.= " AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
+ $resql = $db->query($sql);
+
+ $row = array();
+ if ($resql)
+ {
+ $i = $j = 0;
+ $num = $db->num_rows($resql);
+
+ while ($i < $num)
+ {
+ $obj = $db->fetch_object($resql);
+ if ($obj->pamount == $obj->bamount && $obj->socid) // Pour etre sur d'avoir bon cas
+ {
+ $row[$j]['paymentid'] = $obj->rowid ; // paymentid
+ $row[$j]['pamount'] = $obj->pamount;
+ $row[$j]['fk_bank'] = $obj->fk_bank;
+ $row[$j]['bamount'] = $obj->bamount;
+ $row[$j]['socid'] = $obj->socid;
+ $row[$j]['datec'] = $obj->datec;
+ $j++;
+ }
+ $i++;
+ }
+ }
+ else {
+ dolibarr_print_error($db);
+ }
+
+ if (sizeof($row))
+ {
+ print $langs->trans('MigrationPaymentsNumberToUpdate', sizeof($row))." \n";
+ $db->begin();
+
+ $res = 0;
+ for ($i = 0 ; $i < sizeof($row) ; $i++)
+ {
+ print '* '.$row[$i]['datec'].' paymentid='.$row[$i]['paymentid'].' '.$row[$i]['pamount'].' fk_bank='.$row[$i]['fk_bank'].' '.$row[$i]['bamount'].' socid='.$row[$i]['socid'].' ';
+
+ // On cherche facture sans lien paiement et du meme montant et pour meme societe.
+ $sql=" SELECT distinct f.rowid from ".MAIN_DB_PREFIX."facture as f";
+ $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture";
+ $sql.=" WHERE f.fk_statut in (2,3) AND fk_soc = ".$row[$i]['socid']." AND total_ttc = ".$row[$i]['pamount'];
+ $sql.=" AND pf.fk_facture IS NULL";
+ $sql.=" ORDER BY f.fk_statut";
+ //print $sql.' ';
+ $resql=$db->query($sql);
+ if ($resql)
+ {
+ $num = $db->num_rows($resql);
+ //print 'Nb of invoice found for this amount and company :'.$num.' ';
+ if ($num >= 1)
+ {
+ $obj=$db->fetch_object($resql);
+ $facid=$obj->rowid;
+
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount)";
+ $sql .= " VALUES (".$facid.",".$row[$i]['paymentid'].",".$row[$i]['pamount'].")";
+ $res += $db->query($sql);
+
+ print $langs->trans('MigrationProcessPaymentUpdate', 'facid='.$facid.'-paymentid='.$row[$i]['paymentid'].'-amount='.$row[$i]['pamount'])." \n";
+ }
+ }
+ else
+ {
+ print 'ERROR';
+ }
+ }
+
+ if ($res > 0)
+ {
+ print $langs->trans('MigrationSuccessfullUpdate')." ";
+ }
+ else
+ {
+ print $langs->trans('MigrationPaymentsNothingToUpdate')." \n";
+ }
+
+ $db->commit();
+ }
+ else
+ {
+ print $langs->trans('MigrationPaymentsNothingToUpdate')." \n";
+ }
+
+ print '
';
+}
+
+
+function migrate_paiements_orphelins_3($db,$langs,$conf)
+{
+
+/*
+select p.rowid from llx_paiement as p left join llx_paiement_facture as pf on pf.fk_paiement=p.rowid WHERE pf.rowid IS NULL AND (p.fk_facture = 0 OR p.fk_facture IS NULL)
+Poru chaque rep, test si
+select count(*) from llx_bank where rowid = obj->fk_bank
+select count(*) from llx_bank_url where url_id = 128 and type='payment'
+Si partout 0, on efface ligne de llx_paiement
+*/
+
+}
+
+
/*
* Mise a jour des contrats (gestion du contrat + detail de contrat)
*/
diff --git a/htdocs/langs/fr_FR/install.lang b/htdocs/langs/fr_FR/install.lang
index 12cf38cc01e..345b23214e1 100644
--- a/htdocs/langs/fr_FR/install.lang
+++ b/htdocs/langs/fr_FR/install.lang
@@ -1,4 +1,5 @@
# Dolibarr language file - fr_FR - install
+CHARSET=ISO-8859-1
InstallEasy=Nous avons fait en sorte que l'installation soit le plus simple possible, vous n'avez qu'à suivre les étapes une à une.
MiscellanousChecks=Vérification de prérequis
DolibarrWelcome=Bienvenue sur Dolibarr
@@ -107,7 +108,10 @@ CollationConnection=Collation utilis
CollationConnectionComment=Veuillez choisir la collation que vous désirez choisir pour la création de la base de données. Ce paramètre n'est pas sélectionnable si votre base est déjà créée.
CharacterSetDatabase=Codage utilisé pour la base de données
CharacterSetDatabaseComment=Veuillez choisir le codage que vous désirez choisir pour la création de la base de données. Ce paramètre n'est pas sélectionnable si votre base est déjà créée.
+YouAskDatabaseCreationSoDolibarrNeedToConnect=Vous avez demandé la création du login Dolibarr %s, mais pour cela, Dolibarr doit se connecter sur le serveur %s via le super utilisateur %s.
+BecauseConnectionFailedParametersMayBeWrong=La connexion ayant échoué, les paramètres du serveur ou du super utilisateur sont peut-etre incorrects.
+
#########
# upgrade
#########
diff --git a/htdocs/lib/CMailFile.class.php b/htdocs/lib/CMailFile.class.php
index e752758c518..432c54b90e1 100644
--- a/htdocs/lib/CMailFile.class.php
+++ b/htdocs/lib/CMailFile.class.php
@@ -244,7 +244,8 @@ class CMailFile
*/
function write_smtpheaders()
{
- $out = "";
+ global $conf;
+ $out = "";
// Sender
//$out .= "X-Sender: ".getValidAddress($this->addr_from,2).$this->eol;
@@ -266,7 +267,7 @@ class CMailFile
if ($this->msgishtml)
{
- $out.= "Content-Type: text/html; charset=".$_SESSION['charset'].$this->eol;
+ $out.= "Content-Type: text/html; charset=".$conf->charset_output.$this->eol;
$out.= "Content-Transfer-Encoding: 8bit".$this->eol;
}
else
diff --git a/htdocs/lib/databases/mysql.lib.php b/htdocs/lib/databases/mysql.lib.php
index 7e96da2c05a..0bb300db0d9 100644
--- a/htdocs/lib/databases/mysql.lib.php
+++ b/htdocs/lib/databases/mysql.lib.php
@@ -164,8 +164,9 @@ class DoliDb
// host, login ou password incorrect
$this->connected = 0;
$this->ok = 0;
+ $this->error=mysql_error();
dolibarr_syslog("DoliDB::DoliDB : Erreur Connect mysql_error=".mysql_error());
- }
+ }
// Si connexion serveur ok et si connexion base demandée, on essaie connexion base
if ($this->connected && $name)
diff --git a/htdocs/lib/databases/mysqli.lib.php b/htdocs/lib/databases/mysqli.lib.php
index 1f969e3fa5c..cbd583ead56 100644
--- a/htdocs/lib/databases/mysqli.lib.php
+++ b/htdocs/lib/databases/mysqli.lib.php
@@ -166,7 +166,8 @@ class DoliDb
// host, login ou password incorrect
$this->connected = 0;
$this->ok = 0;
- dolibarr_syslog("DoliDB::DoliDB : Erreur Connect");
+ $this->error=mysql_error();
+ dolibarr_syslog("DoliDB::DoliDB : Erreur Connect mysql_error=".mysql_error());
}
// Si connexion serveur ok et si connexion base demandée, on essaie connexion base
diff --git a/htdocs/lib/functions.inc.php b/htdocs/lib/functions.inc.php
index e095a8a482e..7aa15409b60 100644
--- a/htdocs/lib/functions.inc.php
+++ b/htdocs/lib/functions.inc.php
@@ -1299,7 +1299,7 @@ function dolibarr_print_error($db='',$error='')
if (! $langs)
{
require_once(DOL_DOCUMENT_ROOT ."/translate.class.php");
- $langs = new Translate(DOL_DOCUMENT_ROOT ."/langs", "en_US");
+ $langs = new Translate(DOL_DOCUMENT_ROOT ."/langs", $conf);
}
$langs->load("main");
diff --git a/htdocs/livraison/fiche.php b/htdocs/livraison/fiche.php
index 0abc9386b1c..988ccd00c04 100644
--- a/htdocs/livraison/fiche.php
+++ b/htdocs/livraison/fiche.php
@@ -146,7 +146,7 @@ if ($_REQUEST['action'] == 'builddoc') // En get ou en post
if ($_REQUEST['lang_id'])
{
- $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
+ $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf);
$outputlangs->setDefaultLang($_REQUEST['lang_id']);
}
$result=delivery_order_pdf_create($db, $_REQUEST['id'],$_REQUEST['model'],$outputlangs);
diff --git a/htdocs/master.inc.php b/htdocs/master.inc.php
index 78e175ed6b2..f83aa2c3e6b 100644
--- a/htdocs/master.inc.php
+++ b/htdocs/master.inc.php
@@ -105,16 +105,22 @@ if ($dolibarr_main_db_encrypted_pass) $dolibarr_main_db_pass = dolibarr_decode($
require_once(DOL_DOCUMENT_ROOT."/conf/conf.class.php");
$conf = new Conf();
+// On defini tous les parametres de conf
$conf->db->host = $dolibarr_main_db_host;
$conf->db->name = $dolibarr_main_db_name;
$conf->db->user = $dolibarr_main_db_user;
$conf->db->pass = $dolibarr_main_db_pass;
+if (! isset($dolibarr_main_db_type) && ! $dolibarr_main_db_type) $dolibarr_main_db_type='mysql'; // Pour compatibilite avec anciennes configs, si non defini, on prend 'mysql'
$conf->db->type = $dolibarr_main_db_type;
-if (! $conf->db->type) { $conf->db->type = 'mysql'; } // Pour compatibilite avec anciennes configs, si non defini, on prend 'mysql'
-// Defini prefix
-if (isset($_SERVER["LLX_DBNAME"])) $dolibarr_main_db_prefix=$_SERVER["LLX_DBNAME"];
+if (! isset($dolibarr_main_db_charset) && ! $dolibarr_main_db_charset) $dolibarr_main_db_charset='ISO-8859-1'; // Pour compatibilite avec anciennes configs, si non defini, on prend 'mysql'
+$conf->db->character_set=$dolibarr_main_db_charset;
+if (! isset($character_set_client) || ! $character_set_client) $character_set_client='ISO-8859-1';
+$conf->character_set_client=$character_set_client;
if (! isset($dolibarr_main_db_prefix) || ! $dolibarr_main_db_prefix) $dolibarr_main_db_prefix='llx_';
$conf->db->prefix = $dolibarr_main_db_prefix;
+
+// Defini prefix
+if (isset($_SERVER["LLX_DBNAME"])) $dolibarr_main_db_prefix=$_SERVER["LLX_DBNAME"];
define('MAIN_DB_PREFIX',$dolibarr_main_db_prefix);
// Detection browser
@@ -134,17 +140,7 @@ require_once(DOL_DOCUMENT_ROOT ."/lib/databases/".$conf->db->type.".lib.php");
* Creation objet $langs
*/
require_once(DOL_DOCUMENT_ROOT ."/translate.class.php");
-$langs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
-
-/*
- *
- */
-require_once(DOL_DOCUMENT_ROOT ."/conf/conf.class.php");
-if ($character_set_client ){
- $_SESSION['charset'] = $character_set_client;
-}else{
- $_SESSION['charset'] =$langs->trans("charset");
-}
+$langs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf); // A mettre apres lecture de la conf
/*
* Creation objet $db
diff --git a/htdocs/translate.class.php b/htdocs/translate.class.php
index 1b0faac9c9d..27738a3782f 100644
--- a/htdocs/translate.class.php
+++ b/htdocs/translate.class.php
@@ -40,16 +40,22 @@ class Translate {
var $tab_loaded=array(); // Tableau pour signaler les fichiers deja chargés
var $tab_translate=array(); // Tableau des traductions
- var $charset='ISO-8859-1'; // Codage du contenu du fichier langue
+ var $charset_inputfile='ISO-8859-1'; // Codage du contenu du fichier langue
+ var $charset_output='ISO-8859-1'; // Codage par defaut de la sortie de la méthode trans
/**
* \brief Constructeur de la classe
* \param dir Repertoire racine des fichiers de traduction
+ * \param conf Objet qui contient la config Dolibarr
*/
- function Translate($dir = "")
+ function Translate($dir = "",$conf)
{
- $this->charset=$_SESSION['charset'];
+ // Si charset output defini
+ if (isset($conf->character_set_client) && $conf->character_set_client)
+ {
+ $this->charset_output=$conf->character_set_client;
+ }
$this->dir=$dir;
}
@@ -183,7 +189,21 @@ class Translate {
if (! $this->getTransFromTab($key))
{
if (isset($tab[1])) $value=trim(ereg_replace('\\\n',"\n",$tab[1]));
- $this->setTransFromTab($key,$value);
+
+ 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.' ';
+ }
+ else
+ {
+ // On stocke toujours dans le tableau Tab en ISO
+ if ($this->charset_inputfile == 'ISO-8859-1') $value=$value;
+ if ($this->charset_inputfile == 'UTF-8') $value=utf8_decode($value);
+
+ $this->setTransFromTab($key,$value);
+ }
}
}
}
@@ -237,9 +257,7 @@ class Translate {
$newstr=ereg_replace('"','__quot__',$newstr);
// Cryptage en html de la chaine
- $this->load("main");
- $charset=sprintf($this->tab_translate["charset"]);
- $newstr=htmlentities($newstr,ENT_QUOTES,$charset);
+ $newstr=htmlentities($newstr,ENT_QUOTES,$this->charset_output);
// On restaure les tags HTML
$newstr=ereg_replace('__lt__','<',$newstr);
@@ -315,7 +333,7 @@ class Translate {
function lang_header()
{
//header("Content-Type: text/html; charset=$charset");
- $texte = "charset\">\n";
+ $texte = "\n";
return $texte;
}