From ac18091256611bf0bf18f262cbcaf8e3786e56d3 Mon Sep 17 00:00:00 2001
From: cdelambert <cdelambert>
Date: Wed, 23 May 2007 21:10:11 +0000
Subject: [PATCH] =?UTF-8?q?Modifications=20pour=20la=20mise=20en=20place?=
 =?UTF-8?q?=20de=20l'UTF8.=20A=20faire=20:=20*=20Approfondir=20les=20test?=
 =?UTF-8?q?=20d'installation=20pouvant=20entrainer=20des=20erreurs=20*=20F?=
 =?UTF-8?q?inir=20de=20complet=20les=20fichiers=20de=20langue=20afin=20de?=
 =?UTF-8?q?=20ne=20plus=20avoir=20de=20terme=20en=20dur=20dans=20les=20pag?=
 =?UTF-8?q?es.=20Dans=20le=20cas=20contraire,=20il=20y=20a=20des=20probl?=
 =?UTF-8?q?=C3=A8mes=20d'affichage=20de=20caract=C3=A8re=20lorsqu'ils=20so?=
 =?UTF-8?q?nt=20accentu=C3=A9s?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .project                                      |  11 ++
 htdocs/adherents/cartes/pre.inc.php           |   2 +-
 htdocs/adherents/pre.inc.php                  |   2 +-
 htdocs/admin/ihm.php                          |   2 +-
 .../menus/barre_left/eldy_backoffice.php      |   2 +-
 .../menus/barre_left/eldy_frontoffice.php     |   2 +-
 htdocs/index.php                              |   1 -
 htdocs/install/etape0.php                     | 120 +++++++++++++++++
 htdocs/install/etape1.php                     |  13 ++
 htdocs/install/etape2.php                     |   4 +
 htdocs/install/fileconf.php                   |   4 +-
 htdocs/install/inc.php                        |   8 +-
 htdocs/install/mysql.php                      |  79 ++++++++++++
 htdocs/install/mysqli.php                     |  79 ++++++++++++
 htdocs/install/pgsql.php                      |  28 ++++
 htdocs/langs/en_US/admin.lang                 |   3 +
 htdocs/langs/en_US/members.lang               |   1 +
 htdocs/langs/fr_BE/admin.lang                 |   9 ++
 htdocs/langs/fr_BE/install.lang               |   3 +-
 htdocs/langs/fr_BE/members.lang               |   1 +
 htdocs/langs/fr_FR/admin.lang                 |   9 ++
 htdocs/langs/fr_FR/install.lang               |   7 +
 htdocs/langs/fr_FR/members.lang               |   1 +
 htdocs/lib/CMailFile.class.php                |   2 +-
 htdocs/lib/databases/mysql.lib.php            | 108 ++++++++++++++--
 htdocs/lib/databases/mysqli.lib.php           | 121 +++++++++++++++---
 htdocs/lib/databases/pgsql.lib.php            |  56 ++++++--
 htdocs/main.inc.php                           |   2 +-
 htdocs/master.inc.php                         |   7 +
 htdocs/product/ajaxproducts.php               |   2 +-
 htdocs/translate.class.php                    |  11 +-
 .../tables/llx_paiementfourn_facturefourn.sql |   4 +-
 32 files changed, 646 insertions(+), 58 deletions(-)
 create mode 100644 .project
 create mode 100644 htdocs/install/etape0.php
 create mode 100644 htdocs/install/mysql.php
 create mode 100644 htdocs/install/mysqli.php
 create mode 100644 htdocs/install/pgsql.php

diff --git a/.project b/.project
new file mode 100644
index 00000000000..16b046902a8
--- /dev/null
+++ b/.project
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>dolibarrAuguria</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+	</buildSpec>
+	<natures>
+	</natures>
+</projectDescription>
diff --git a/htdocs/adherents/cartes/pre.inc.php b/htdocs/adherents/cartes/pre.inc.php
index 1a8a1e74442..57dc7e4aee1 100644
--- a/htdocs/adherents/cartes/pre.inc.php
+++ b/htdocs/adherents/cartes/pre.inc.php
@@ -51,7 +51,7 @@ function llxHeader($head = "") {
   $menu->add_submenu(DOL_URL_ROOT."/exports/index.php?leftmenu=export",$langs->trans("Datas"));
   $menu->add_submenu(DOL_URL_ROOT."/adherents/htpasswd.php",$langs->trans("Filehtpasswd"));
   $menu->add_submenu(DOL_URL_ROOT."/adherents/cartes/carte.php",$langs->trans("MembersCards"));
-  $menu->add_submenu(DOL_URL_ROOT."/adherents/cartes/etiquette.php","Etiquettes d'adh�rents");
+  $menu->add_submenu(DOL_URL_ROOT."/adherents/cartes/etiquette.php",$langs->trans("MembersTickets"));
 
   $langs->load("compta");
   $menu->add(DOL_URL_ROOT."/adherents/index.php",$langs->trans("Accountancy"));
diff --git a/htdocs/adherents/pre.inc.php b/htdocs/adherents/pre.inc.php
index c5aeecc5106..9200fbe19ef 100644
--- a/htdocs/adherents/pre.inc.php
+++ b/htdocs/adherents/pre.inc.php
@@ -54,7 +54,7 @@ function llxHeader($head = "")
 	$menu->add_submenu(DOL_URL_ROOT."/exports/index.php?leftmenu=export",$langs->trans("Datas"));
 	$menu->add_submenu(DOL_URL_ROOT."/adherents/htpasswd.php",$langs->trans("Filehtpasswd"));
 	$menu->add_submenu(DOL_URL_ROOT."/adherents/cartes/carte.php",$langs->trans("MembersCards"));
-	$menu->add_submenu(DOL_URL_ROOT."/adherents/cartes/etiquette.php","Etiquettes d'adh�rents");
+	$menu->add_submenu(DOL_URL_ROOT."/adherents/cartes/etiquette.php",$langs->trans("MembersTickets"));
 
 	$langs->load("compta");
 	$menu->add(DOL_URL_ROOT."/adherents/index.php",$langs->trans("Accountancy"));
diff --git a/htdocs/admin/ihm.php b/htdocs/admin/ihm.php
index ada919d2b54..cf5f6613af0 100644
--- a/htdocs/admin/ihm.php
+++ b/htdocs/admin/ihm.php
@@ -195,7 +195,7 @@ if (isset($_GET["action"]) && $_GET["action"] == 'edit')
 
     // Message d'accueil'
 	$var=!$var;
-    print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("MessageHome").'</td><td>';
+    print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("MessageLogin").'</td><td>';
 	if ($conf->fckeditor->enabled)
 	{
 		// Editeur wysiwyg
diff --git a/htdocs/includes/menus/barre_left/eldy_backoffice.php b/htdocs/includes/menus/barre_left/eldy_backoffice.php
index 5da0f619d62..df8a823f02f 100644
--- a/htdocs/includes/menus/barre_left/eldy_backoffice.php
+++ b/htdocs/includes/menus/barre_left/eldy_backoffice.php
@@ -743,7 +743,7 @@ class MenuLeft {
 					if ($conf->export->enabled && $leftmenu=="export") $newmenu->add_submenu(DOL_URL_ROOT."/exports/index.php?leftmenu=export",$langs->trans("Datas"),1,$user->rights->adherent->export);
 					if ($leftmenu=="export") $newmenu->add_submenu(DOL_URL_ROOT."/adherents/htpasswd.php?leftmenu=export",$langs->trans("Filehtpasswd"),1,$user->rights->adherent->export);
 					if ($leftmenu=="export") $newmenu->add_submenu(DOL_URL_ROOT."/adherents/cartes/carte.php?leftmenu=export",$langs->trans("MembersCards"),1,$user->rights->adherent->export,'_new');
-					if ($leftmenu=="export") $newmenu->add_submenu(DOL_URL_ROOT."/adherents/cartes/etiquette.php?leftmenu=export","Etiquettes d'adh�rents",1,$user->rights->adherent->export,'_new');
+					if ($leftmenu=="export") $newmenu->add_submenu(DOL_URL_ROOT."/adherents/cartes/etiquette.php?leftmenu=export",$langs->trans("MembersTickets"),1,$user->rights->adherent->export,'_new');
 
 					$newmenu->add(DOL_URL_ROOT."/public/adherents/index.php?leftmenu=member_public",$langs->trans("MemberPublicLinks"));
 					/*
diff --git a/htdocs/includes/menus/barre_left/eldy_frontoffice.php b/htdocs/includes/menus/barre_left/eldy_frontoffice.php
index 28902f0fd50..5eb2751a006 100644
--- a/htdocs/includes/menus/barre_left/eldy_frontoffice.php
+++ b/htdocs/includes/menus/barre_left/eldy_frontoffice.php
@@ -748,7 +748,7 @@ class MenuLeft {
 					if ($conf->export->enabled && $leftmenu=="export") $newmenu->add_submenu(DOL_URL_ROOT."/exports/index.php?leftmenu=export",$langs->trans("Datas"),1,$user->rights->adherent->export);
 					if ($leftmenu=="export") $newmenu->add_submenu(DOL_URL_ROOT."/adherents/htpasswd.php?leftmenu=export",$langs->trans("Filehtpasswd"),1,$user->rights->adherent->export);
 					if ($leftmenu=="export") $newmenu->add_submenu(DOL_URL_ROOT."/adherents/cartes/carte.php?leftmenu=export",$langs->trans("MembersCards"),1,$user->rights->adherent->export,'_new');
-					if ($leftmenu=="export") $newmenu->add_submenu(DOL_URL_ROOT."/adherents/cartes/etiquette.php?leftmenu=export","Etiquettes d'adh�rents",1,$user->rights->adherent->export,'_new');
+					if ($leftmenu=="export") $newmenu->add_submenu(DOL_URL_ROOT."/adherents/cartes/etiquette.php?leftmenu=export",$langs->trans("MembersTickets"),1,$user->rights->adherent->export,'_new');
 
 					$newmenu->add(DOL_URL_ROOT."/public/adherents/index.php?leftmenu=member_public",$langs->trans("MemberPublicLinks"));
 					/*
diff --git a/htdocs/index.php b/htdocs/index.php
index c39f25640bc..ee7d3302c0f 100644
--- a/htdocs/index.php
+++ b/htdocs/index.php
@@ -48,7 +48,6 @@ llxHeader();
 
 print_fiche_titre($langs->trans("HomeArea"));
 
-
 if (defined("MAIN_MOTD") && strlen(trim(MAIN_MOTD)))
 {
     print '<table width="100%" class="notopnoleftnoright"><tr><td>';
diff --git a/htdocs/install/etape0.php b/htdocs/install/etape0.php
new file mode 100644
index 00000000000..c84ff24fb23
--- /dev/null
+++ b/htdocs/install/etape0.php
@@ -0,0 +1,120 @@
+<?php
+/* Copyright (C) 2004-2007 Cyrille de Lambert <cyrille.delambert@auguria.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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Id$
+ * $Source$
+ */
+
+/**
+   \file       htdocs/install/etape1.php
+   \brief      Pemet d'afficher et de confirmer le charset par rapport aux informations pr�cedntes -> s�lection suite � connection'
+   \version    $Revision$
+*/
+
+define('DONOTLOADCONF',1);	// To avoid loading conf by file inc..php
+
+include_once("./inc.php");
+
+$setuplang=isset($_POST["selectlang"])?$_POST["selectlang"]:(isset($_GET["selectlang"])?$_GET["selectlang"]:'auto');
+$langs->setDefaultLang($setuplang);
+
+$langs->load("admin");
+$langs->load("install");
+
+pHeader($langs->trans("ConfigurationFile"),"etape1");
+
+$error = 0;
+
+/*
+ * Actions
+ */
+if ($_POST["action"] == "set")
+{
+  umask(0);
+    foreach($_POST as $cle=>$valeur)
+    {
+    echo '<input type="hidden" name="'.$cle.'"  value="'.$valeur.'">';
+    }
+}
+/**
+ * R�cuparation des information de connexion
+ */
+$userroot=isset($_POST["db_user_root"])?$_POST["db_user_root"]:"";
+$passroot=isset($_POST["db_pass_root"])?$_POST["db_pass_root"]:"";
+// R�pertoire des pages dolibarr
+$main_dir=isset($_POST["main_dir"])?trim($_POST["main_dir"]):'';
+/**
+* 	Si l'utilisateur n'est pas cr�� d�j� cr��, on se connecte � l'aide du login root'
+*/
+require_once($main_dir."/lib/databases/".$_POST["db_type"].".lib.php");
+if (isset($_POST["db_create_user"]) && $_POST["db_create_user"] == "on")
+{	
+	
+	$databasefortest=$conf->db->name;
+	if ($_POST["db_type"] == 'mysql' ||$_POST["db_type"] == 'mysqli')
+	{
+		$databasefortest='mysql';
+	}else{
+		$databasefortest='postgres';
+	}
+	$db = new DoliDb($_POST["db_type"],$_POST["db_host"],$userroot,$passroot,$databasefortest);
+}else{	
+	$db = new DoliDb($_POST["db_type"],$_POST["db_host"],$_POST["db_user"],$_POST["db_pass"],$_POST["db_name"]);
+}
+if ($db->error)
+{
+		print $langs->trans("ThisPHPDoesNotSupportTypeBase",$conf->db->type);
+		$error++;
+}
+
+/*
+* Si creation database demand�e, il est possible de faire un choix
+*/
+$disabled="";
+if (! $error && (isset($_POST["db_create_database"]) && $_POST["db_create_database"] == "on"))
+{
+	$disabled="";
+}else{
+	$disabled="disabled";
+}
+if ($db->connected){
+?>
+<table border="0" cellpadding="1" cellspacing="0">
+	<tr><td valign="top" class="label" colspan="3"><?php echo $langs->trans("CharsetChoice");?></td></tr>
+	<tr>
+		<td valign="top" class="label"><?php echo $langs->trans("CharacterSetClient"); ?></td>
+		<td valign="top" class="label"><select name="character_set_client"/><option>ISO-8859-1</option><option>ISO-8859-15</option><option>UTF-8</option><option>cp866</option><option>cp1251</option><option>cp1252</option><option>KOI8-R</option><option>BIG5</option><option>GB2312</option><option>BIG5-HKSCS</option><option>Shift_JIS</option><option>EUC-JP</option></select></td>
+		<td class="label"><div class="comment"><?php echo $langs->trans("CharacterSetClientComment"); ?></div></td>
+	</tr>
+	<?php  
+	include($_POST["db_type"].'.php');?>
+<?php
+}else{
+	
+	if (isset($_POST["db_create_user"]) && $_POST["db_create_user"] == "on")
+	{	
+			print 'Vous avez demand� la cr�ation du login Dolibarr "<b>'.$dolibarr_main_db_user.'</b>", mais pour cela, ';
+			print 'Dolibarr doit se connecter sur le serveur "<b>'.$dolibarr_main_db_host.'</b>" via le super utilisateur "<b>'.$userroot.'</b>".<br>';
+			print 'La connexion ayant �chou�, les param�tres du serveur ou du super utilisateur sont peut-etre incorrects.<br>';
+			print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
+	}else{
+			print 'La connexion ayant �chou�, les param�tres de connexion de l\'utilisateur  sont peut-etre incorrects.<br>';
+			print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
+	}
+}
+pFooter($err,$setuplang);
+?>
\ No newline at end of file
diff --git a/htdocs/install/etape1.php b/htdocs/install/etape1.php
index 1fc2ab3858d..37d7e1ccb4a 100644
--- a/htdocs/install/etape1.php
+++ b/htdocs/install/etape1.php
@@ -135,6 +135,16 @@ if ($_POST["action"] == "set")
 			fputs($fp, '$dolibarr_main_db_type="'.$_POST["db_type"].'";');
 			fputs($fp,"\n");
 
+			/* Choix des charsets*/
+			fputs($fp, '$character_set_client="'.$_POST["character_set_client"].'";');
+			fputs($fp,"\n");
+			
+			fputs($fp, '$character_set_database="'.$_POST["character_set_database"].'";');
+			fputs($fp,"\n");
+			
+			fputs($fp, '$collation_connection="'.$_POST["collation_connection"].'";');
+			fputs($fp,"\n");
+
 			/* Preparation integration SMARTY */
 			fputs($fp, '$dolibarr_smarty_libs_dir="";');
 			fputs($fp,"\n");
@@ -260,9 +270,12 @@ if ($_POST["action"] == "set")
 			if ($conf->db->type == 'mysql' || $conf->db->type == 'mysqli')
 			{
 				$databasefortest='mysql';
+			}else{
+				$databasefortest='postgres';
 			}
 			
 			// Creation handler de base, verification du support et connexion
+
 			$db = new DoliDb($conf->db->type,$conf->db->host,$userroot,$passroot,$databasefortest);
 			if ($db->error)
 			{
diff --git a/htdocs/install/etape2.php b/htdocs/install/etape2.php
index 56b20162f93..788dcd7703c 100644
--- a/htdocs/install/etape2.php
+++ b/htdocs/install/etape2.php
@@ -239,6 +239,10 @@ if ($_POST["action"] == "set")
                     {
 		                //print "<tr><td>Cr�ation des cl�s et index de la table $name: '$buffer'</td>";
 						$requestnb++;
+						if ($character_set_client=="UTF-8"){
+							$buffer=utf8_encode ($buffer);
+						}
+						
                         if ($db->query(trim($buffer)))
                         {
                             //print "<td>OK requete ==== $buffer</td></tr>";
diff --git a/htdocs/install/fileconf.php b/htdocs/install/fileconf.php
index b2bb53d2e74..e3fd49ac7b3 100644
--- a/htdocs/install/fileconf.php
+++ b/htdocs/install/fileconf.php
@@ -40,7 +40,7 @@ $langs->setDefaultLang($setuplang);
 $langs->load("install");
 
 
-pHeader($langs->trans("ConfigurationFile"),"etape1");
+pHeader($langs->trans("ConfigurationFile"),"etape0");
 
 
 print '<table border="0" cellpadding="1" cellspacing="0">';
@@ -76,7 +76,7 @@ if(! isset($dolibarr_main_url_root) || strlen($dolibarr_main_url_root) == 0)
         $dolibarr_main_document_root = ereg_replace('[\\\/]+$','',$dolibarr_main_document_root);
     }
 }
-
+echo $PMA_MYSQL_INT_VERSION;
 ?>
 <td  class="label" valign="top"><input type="text" size="60" value="<?php print $dolibarr_main_document_root; ?>" name="main_dir">
 </td><td class="comment">
diff --git a/htdocs/install/inc.php b/htdocs/install/inc.php
index f607bd2ea4f..0aa484776c1 100644
--- a/htdocs/install/inc.php
+++ b/htdocs/install/inc.php
@@ -39,9 +39,11 @@ if (isset($_SERVER["DOCUMENT_URI"]) && $_SERVER["DOCUMENT_URI"])
 
 
 $conffile = "../conf/conf.php";
+$charset="ISO-8859-1";
 if (file_exists($conffile))
 {
 	include_once($conffile);
+	$charset=$character_set_client;
 	if ($dolibarr_main_document_root)
 	{
 		require_once($dolibarr_main_document_root . "/conf/conf.class.php");
@@ -95,18 +97,20 @@ $bc[true]=' class="bg2"';
 
 function pHeader($soutitre,$next,$action='set')
 {
+	
+	global $charset;
     global $langs;
     $langs->load("main");
     $langs->load("admin");
 
 	// On force contenu en ISO-8859-1
-	header("Content-type: text/html; charset=iso-8859-1");
+	header("Content-type: text/html; charset=".$charset);
     //header("Content-type: text/html; charset=UTF-8");
 
     print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'."\n";
     print '<html>';
     print '<head>';
-    print '<meta http-equiv="content-type" content="text/html; charset='.$langs->trans("charset").'">';
+    print '<meta http-equiv="content-type" content="text/html; charset='.$charset.'">';
     print '<link rel="stylesheet" type="text/css" href="./default.css">';
     print '<title>'.$langs->trans("DolibarrSetup").'</title>';
     print '</head>';
diff --git a/htdocs/install/mysql.php b/htdocs/install/mysql.php
new file mode 100644
index 00000000000..85e9440179f
--- /dev/null
+++ b/htdocs/install/mysql.php
@@ -0,0 +1,79 @@
+<?php
+/* Copyright (C) 2004-2007 Cyrille de Lambert <cyrille.delambert@auguria.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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Id$
+ * $Source$
+ */
+
+	$listOfCharacterSet=$db->getListOfCharacterSet();
+	$listOfCollation=$db->getListOfCollation();
+?>
+<tr>
+	<td valign="top" class="label"><?php echo $langs->trans("CharacterSetDatabase"); ?></td>
+	<td valign="top" class="label">
+	<?php
+	$listOfCharacterSet=$db->getListOfCharacterSet();
+	?>
+	<select name="character_set_database" <?php echo $disabled ?>>
+	<?php
+	$selected="";
+	foreach ($listOfCharacterSet as $characterSet) {
+		if ($db->getDefaultCharacterSetDatabase() ==$characterSet['charset'] ){
+			$selected="selected";
+		}else{
+			$selected="";
+		}
+	?>
+	<option value="<?php echo $characterSet['charset'];?>"  <?php echo $selected;?>> <?php echo $characterSet['charset'];?> (<?php echo $characterSet['description'];?>)</option>
+	<?php
+	}
+	?>
+		</select>
+	</td>
+	<td class="label"><div class="comment"><?php echo $langs->trans("CharacterSetDatabaseComment"); ?></div></td>
+</tr>
+<tr>
+	<td valign="top" class="label"><?php echo $langs->trans("CollationConnection"); ?></td>
+	<td valign="top" class="label">
+	<?php
+	$listOfCollation=$db->getListOfCollation();
+	?>
+	<select name="collation_connection" <?php echo $disabled ?>>
+	<?php
+	$selected="";
+	foreach ($listOfCollation as $collation) {
+		if ($db->getDefaultCollationConnection() ==$collation['collation'] ){
+			$selected="selected";
+		}else{
+			$selected="";
+		}
+	?>
+	<option value="<?php echo $collation['collation'];?>"  <?php echo $selected;?>> <?php echo $collation['collation'];?></option>
+	<?php
+	}
+	?>
+		</select>
+	<?if ($disabled && $disabled=="disabled"){
+				?>
+			<input type="hidden" name="character_set_database"  value="<?php echo $collation['charset'] ?>">
+			<input type="hidden" name="collation_connection"  value="<?php echo $collation['collation'] ?>">
+			<?
+	}
+			?>
+	</td>
+	<td class="label"><div class="comment"><?php echo $langs->trans("CollationConnectionComment"); ?></div></td>
+</tr>
\ No newline at end of file
diff --git a/htdocs/install/mysqli.php b/htdocs/install/mysqli.php
new file mode 100644
index 00000000000..3c6943eae91
--- /dev/null
+++ b/htdocs/install/mysqli.php
@@ -0,0 +1,79 @@
+<?php
+/* Copyright (C) 2004-2007 Cyrille de Lambert <cyrille.delambert@auguria.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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Id$
+ * $Source$
+ */
+
+	$listOfCharacterSet=$db->getListOfCharacterSet();
+	$listOfCollation=$db->getListOfCollation();
+?>
+<tr>
+	<td valign="top" class="label"><?php echo $langs->trans("CharacterSetDatabase"); ?></td>
+	<td valign="top" class="label">
+	<?php
+	$listOfCharacterSet=$db->getListOfCharacterSet();
+	?>
+	<select name="character_set_database" <?php echo $disabled ?>>
+	<?php
+	$selected="";
+	foreach ($listOfCharacterSet as $characterSet) {
+		if ($db->getDefaultCharacterSetDatabase() ==$characterSet['charset'] ){
+			$selected="selected";
+		}else{
+			$selected="";
+		}
+	?>
+	<option value="<?php echo $characterSet['charset'];?>"  <?php echo $selected;?>> <?php echo $characterSet['charset'];?> (<?php echo $characterSet['description'];?>)</option>
+	<?php
+	}
+	?>
+		</select>
+	</td>
+	<td class="label"><div class="comment"><?php echo $langs->trans("CharacterSetDatabaseComment"); ?></div></td>
+</tr>
+<tr>
+	<td valign="top" class="label"><?php echo $langs->trans("CollationConnection"); ?></td>
+	<td valign="top" class="label">
+	<?php
+	$listOfCollation=$db->getListOfCollation();
+	?>
+	<select name="collation_connection" <?php echo $disabled ?>>
+	<?php
+	$selected="";
+	foreach ($listOfCollation as $collation) {
+		if ($db->getDefaultCollationConnection() ==$collation['collation'] ){
+			$selected="selected";
+		}else{
+			$selected="";
+		}
+	?>
+	<option value="<?php echo $collation['collation'];?>"  <?php echo $selected;?>> <?php echo $collation['collation'];?></option>
+	<?php
+	}
+	?>
+		</select>
+		<?if ($disabled && $disabled=="disabled"){
+				?>
+			<input type="hidden" name="character_set_database"  value="<?php echo $db->getDefaultCharacterSetDatabase() ?>">
+			<input type="hidden" name="collation_connection"  value="<?php echo $db->getDefaultCollationConnection() ?>">
+			<?
+	}
+			?>
+	</td>
+	<td class="label"><div class="comment"><?php echo $langs->trans("CollationConnectionComment"); ?></div></td>
+</tr>
\ No newline at end of file
diff --git a/htdocs/install/pgsql.php b/htdocs/install/pgsql.php
new file mode 100644
index 00000000000..61e438cc98d
--- /dev/null
+++ b/htdocs/install/pgsql.php
@@ -0,0 +1,28 @@
+<?php
+/* Copyright (C) 2004-2007 Cyrille de Lambert <cyrille.delambert@auguria.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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Id$
+ * $Source$
+ */
+?>
+<tr>
+	<td valign="top" class="label"><?php echo $langs->trans("CharacterSetDatabase"); ?></td>
+	<td valign="top" class="label">
+		<input name="character_set_database" <?php echo $disabled ?> value="<?php echo $db->getDefaultCharacterSetDatabase()?>">
+	</td>
+	<td class="label"><div class="comment"><?php echo $langs->trans("CharacterSetDatabaseComment"); ?></div></td>
+</tr>
\ No newline at end of file
diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang
index a018038a740..e6b09073768 100644
--- a/htdocs/langs/en_US/admin.lang
+++ b/htdocs/langs/en_US/admin.lang
@@ -30,6 +30,7 @@ NoMaxSizeByPHPLimit=Note: No limit are built in your PHP
 MaxSizeForUploadedFiles=Maximum size for uploaded files (0 to disallow any upload)
 ComptaSetup=Accounting module setup
 UserSetup=Users' management setup
+MenuSetup=Menus management setup
 Setup=Setup
 Activation=Activation
 SetupShort=Setup
@@ -198,6 +199,8 @@ Module1200Name=Mantis
 Module1200Desc=Mantis integration
 Module1780Name=Categories
 Module1780Desc=Categories' management
+Module2300Name=Menus
+Module2300Desc=Menus' management
 Permission11=Read invoices
 Permission12=Create invoices
 Permission13=Modify invoices
diff --git a/htdocs/langs/en_US/members.lang b/htdocs/langs/en_US/members.lang
index 064d86c1f70..1bac6ae19c3 100644
--- a/htdocs/langs/en_US/members.lang
+++ b/htdocs/langs/en_US/members.lang
@@ -4,6 +4,7 @@ PublicMembersArea=Public members area
 MemberCard=Member card
 Member=Member
 Members=Members
+MembersTickets=Members Tickets
 FundationMembers=Fundation members
 Attributs=Attributes
 Person=Person
diff --git a/htdocs/langs/fr_BE/admin.lang b/htdocs/langs/fr_BE/admin.lang
index 0bae56987a9..fffce2066fa 100644
--- a/htdocs/langs/fr_BE/admin.lang
+++ b/htdocs/langs/fr_BE/admin.lang
@@ -24,6 +24,7 @@ UsePopupCalendar=Utiliser des popup pour l'introduction de dates
 NextValue=Valeur suivante
 ComptaSetup=Configuration du module Comptabilit�
 UserSetup=Configuration de la gestion des utilisateurs
+MenuSetup=Administration des menus par base de donn�es
 Setup=Configuration
 Activation=Activation
 SetupShort=Config
@@ -112,6 +113,8 @@ Module40Name=Fournisseurs
 Module40Desc=Gestion fournisseurs
 Module42Name=Logs syst�me
 Module42Desc=Installations de logging (logs syst�me)
+Module49Name=�diteurs
+Module49Desc=Gestion des �diteurs
 Module50Name=Produits
 Module50Desc=Gestion des produits
 Module52Name=Stocks
@@ -144,6 +147,8 @@ Module200Name=LDAP
 Module200Desc=Synchronisation d'annuaire LDAP
 Module210Name=PostNuke
 Module210Desc=Int�gration de PostNuke
+Module240Name=Exports utilisateurs
+Module240Desc= Permet exports par les utilisateurs, via un assistant, de lot de donn�es personalis�es
 Module310Name=Membres
 Module310Desc=Gestion des membres de la fondation
 Module320Name=Flux RSS
@@ -166,6 +171,10 @@ Module900Name=OSCommerce 2
 Module900Desc=Interface d'affichage d'un magasin OS Commerce via les Web Services.\nCe module n�cessite l'installations de composants de /oscommerce_ws/ws_server dans votre serveur OSCommerce. Lisez le fichier README dans /oscommerce_ws/ws_server.
 Module1780Name=Cat�gories
 Module1780Desc=Gestion des cat�gories
+Module2200Name=Droit de pr�ts
+Module2200Desc=Gestion du droit de pr�ts
+Module2300Name=Menus
+Module2300Desc=Administration des menus par base de donn�es
 Permission11=Voir les factures
 Permission12=Cr�er des factures
 Permission13=Modifier des factures
diff --git a/htdocs/langs/fr_BE/install.lang b/htdocs/langs/fr_BE/install.lang
index a6917fa7569..6626e7cb018 100644
--- a/htdocs/langs/fr_BE/install.lang
+++ b/htdocs/langs/fr_BE/install.lang
@@ -88,11 +88,12 @@ Start=D
 InstallNotAllowed=Configuration non autoris�e par les permissions de <b>conf.php</b>
 NotAvailable=Non disponible
 YouMustCreateWithPermission=Vous devez cr�er le fichier %s et donner les permissions d'�crire dans ce fichier � votre serveur web pendant le processus d'installation.
+CharacterSetDatabase
 CorrectProblemAndReloadPage=Corrigez le probl�me et <a href="%s">rechargez la page</a> (Pressez la touche F5).
 AlreadyDone=D�j� migr�
 DatabaseVersion=Version de la base de donn�es
 ServerVersion=Version du serveur de bases de donn�es
-=
+
 #########=
 # upgrade=
 MigrationOrder=Migration des donn�es de commandes clients
diff --git a/htdocs/langs/fr_BE/members.lang b/htdocs/langs/fr_BE/members.lang
index 4eaed70a51c..aab568c9809 100644
--- a/htdocs/langs/fr_BE/members.lang
+++ b/htdocs/langs/fr_BE/members.lang
@@ -4,6 +4,7 @@ PublicMembersArea=Section membres publique
 MemberCard=Fiche membres
 Member=Membre
 Members=Membres
+MembersTickets=Etiquettes d'adh�rents
 FundationMembers=
 Attributs=Attributs
 Person=Personne
diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang
index 3365c057a28..3643204ceb2 100644
--- a/htdocs/langs/fr_FR/admin.lang
+++ b/htdocs/langs/fr_FR/admin.lang
@@ -30,6 +30,7 @@ NoMaxSizeByPHPLimit=Aucune limite interne 
 MaxSizeForUploadedFiles=Taille maximum des documents upload�s (0 pour interdire l'upload)
 ComptaSetup=Configuration du module Comptabilit�
 UserSetup=Configuration gestion des utilisateurs
+MenuSetup=Administration des menus par base de donn�es
 Setup=Configuration
 Activation=Activation
 SetupShort=Config
@@ -143,6 +144,8 @@ Module40Name=Fournisseurs
 Module40Desc=Gestion des fournisseurs
 Module42Name=Syslog
 Module42Desc=Utilisation de logs (syslog)
+Module49Name=�diteurs
+Module49Desc=Gestion des �diteurs
 Module50Name=Produits
 Module50Desc=Gestion des produits
 Module52Name=Stocks de produits
@@ -175,6 +178,8 @@ Module200Name=LDAP
 Module200Desc=Synchronisation avec un annuaire LDAP
 Module210Name=PostNuke
 Module210Desc=Int�gration avec PostNuke
+Module240Name=Exports utilisateurs
+Module240Desc= Permet exports par les utilisateurs, via un assistant, de lot de donn�es personalis�es
 Module310Name=Adh�rents
 Module310Desc=Gestion des adh�rents d'une association
 Module320Name=Fils RSS
@@ -199,6 +204,10 @@ Module1200Name=Mantis
 Module1200Desc=Interface avec le bug tracking Mantis
 Module1780Name=Cat�gories
 Module1780Desc=Gestion des cat�gories
+Module2200Name=Droit de pr�ts
+Module2200Desc=Gestion du droit de pr�ts
+Module2300Name=Menus
+Module2300Desc=Administration des menus par base de donn�es
 Permission11=Consulter les factures
 Permission12=Cr�er les factures
 Permission13=Modifier les factures
diff --git a/htdocs/langs/fr_FR/install.lang b/htdocs/langs/fr_FR/install.lang
index ba6140d619b..12cf38cc01e 100644
--- a/htdocs/langs/fr_FR/install.lang
+++ b/htdocs/langs/fr_FR/install.lang
@@ -100,6 +100,13 @@ AlreadyDone=D
 DatabaseVersion=Version de la base
 ServerVersion=Version du serveur de base de donn�e
 YouMustCreateItAndAllowServerToWrite=Vous devez cr�er ce dossier et permettre au serveur web d'�crire dans celui-ci.
+CharsetChoice=Choix du codage des caract�res
+CharacterSetClient=Codage utilis� pour l'affichage des pages
+CharacterSetClientComment=Veuillez choisir le codage que vous souhaitez pour l'affichage des pages.<br/> Le codage par d�faut est celui d�finie sur la base mysql par d�faut
+CollationConnection=Collation utilis�e pour la base de donn�es
+CollationConnectionComment=Veuillez choisir la collation que vous d�sirez choisir pour la cr�ation de la base de donn�es.<br/> 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.<br/> Ce param�tre n'est pas s�lectionnable si votre base est d�j� cr��e.
 
 #########
 # upgrade
diff --git a/htdocs/langs/fr_FR/members.lang b/htdocs/langs/fr_FR/members.lang
index 64d8a5eeae6..6188d44d47b 100644
--- a/htdocs/langs/fr_FR/members.lang
+++ b/htdocs/langs/fr_FR/members.lang
@@ -4,6 +4,7 @@ PublicMembersArea=Espace public des adh
 MemberCard=Fiche adh�rent
 Member=Adh�rent
 Members=Adh�rents
+MembersTickets=Etiquettes d'adh�rents
 FundationMembers=Membres de l'association
 Attributs=Attributs
 Person=Personne
diff --git a/htdocs/lib/CMailFile.class.php b/htdocs/lib/CMailFile.class.php
index 62cac51ee93..e752758c518 100644
--- a/htdocs/lib/CMailFile.class.php
+++ b/htdocs/lib/CMailFile.class.php
@@ -266,7 +266,7 @@ class CMailFile
        
         if ($this->msgishtml)
         {
-        	$out.= "Content-Type: text/html; charset=iso-8859-1".$this->eol;
+        	$out.= "Content-Type: text/html; charset=".$_SESSION['charset'].$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 9de17af84a2..7e96da2c05a 100644
--- a/htdocs/lib/databases/mysql.lib.php
+++ b/htdocs/lib/databases/mysql.lib.php
@@ -46,6 +46,8 @@ class DoliDb
   var $type='mysql';          
   //! Charset
   var $forcecharset='latin1';
+    //! Charset client
+  var $forcecharsetclient='iso-8859-1';
   //! Collate
   var $forcecollate='latin1_swedish_ci';
   //! Version min database
@@ -57,7 +59,9 @@ class DoliDb
   //! 1 si base s�lectionn�, 0 sinon
   var $database_selected; 
   //! Nom base s�lectionn�e
-  var $database_name;			
+  var $database_name;
+    //! Nom user base
+  var $database_user;		
   //! 1 si une transaction est en cours, 0 sinon
   var $transaction_opened;	
   //! Derniere requete ex�cut�e
@@ -71,7 +75,7 @@ class DoliDb
   
   var $ok;
   var $error;
-  
+
 
   // Constantes pour conversion code erreur MySql en code erreur g�n�rique
   var $errorcode_map = array(
@@ -115,6 +119,13 @@ class DoliDb
   function DoliDb($type='mysql', $host, $user, $pass, $name='', $newlink=0)
   {
     global $conf,$langs;
+	$conffile = "../conf/conf.php";
+	if (file_exists($conffile)) {
+	    include($conffile);
+	    $this->forcecharset=$character_set_database;
+	    $this->forcecollate=$collation_connection;
+	    $this->db_user=$dolibarr_main_db_user;
+	}
     $this->transaction_opened=0;
         
     if (! function_exists("mysql_connect"))
@@ -224,6 +235,23 @@ class DoliDb
     return mysql_get_server_info($this->db);
   }
   
+    /**
+     \brief          Renvoie la version du serveur sous forme de nombre
+     \return	        string      Chaine version
+	  */
+	  function getIntVersion()
+	  {
+			$version=	$this->getVersion();
+			$vlist=split('[.-]',$version);
+			if (strlen($vlist[1])==1){
+				$vlist[1]="0".$vlist[1];
+			}
+			if (strlen($vlist[2])==1){
+				$vlist[2]="0".$vlist[2];
+			}
+			return $vlist[0].$vlist[1].$vlist[2];
+	  }
+  
   
   /**
      \brief          Renvoie la version du serveur dans un tableau
@@ -633,13 +661,12 @@ class DoliDb
     $sql = 'CREATE DATABASE '.$database;
     $sql.= ' DEFAULT CHARACTER SET '.$this->forcecharset.' DEFAULT COLLATE '.$this->forcecollate;
     $ret=$this->query($sql);
-    if (! $ret)
-      {
-	// On r�essaie pour compatibilit� avec Mysql < 5.0
-	$sql = 'CREATE DATABASE '.$database;
-	$ret=$this->query($sql);
-      }
-    
+	if (! $ret)
+		{
+		// On r�essaie pour compatibilit� avec Mysql < 4.1.1
+		$sql = 'CREATE DATABASE '.$database;
+		$ret=$this->query($sql);
+		}
     return $ret;
   }
   
@@ -820,7 +847,68 @@ class DoliDb
 	
 		return 1;
 	}
-						
+	
+	function getDefaultCharacterSetDatabase(){
+		 $resql=$this->query('SHOW VARIABLES LIKE \'character_set_database\'');
+		  if (!$resql)
+	      {
+			// version Mysql < 4.1.1
+			return $this->forcecharset;
+	      }
+	    $liste=$this->fetch_array($resql);
+	    return $liste['Value'];
+	}
+	
+	function getListOfCharacterSet(){
+		 $resql=$this->query('SHOW CHARSET');
+		$liste = array();
+		if ($resql) 
+			{
+			$i = 0;
+			while ($obj = $this->fetch_object($resql) )
+			{
+				$liste[$i]['charset'] = $obj->Charset;
+				$liste[$i]['description'] = $obj->Description;
+				$i++;           
+			}   
+	    	$this->free($resql);
+	  	} else {
+	  		// version Mysql < 4.1.1
+	   		return null;
+	  	}
+    	return $liste;
+	}
+	
+	function getDefaultCollationConnection(){
+		$resql=$this->query('SHOW VARIABLES LIKE \'collation_connection\'');
+		 if (!$resql)
+	      {
+			// version Mysql < 4.1.1
+			return $this->forcecollate;
+	      }
+	    $liste=$this->fetch_array($resql);
+	    return $liste['Value'];
+	}
+	
+	function getListOfCollation(){
+		 $resql=$this->query('SHOW COLLATION');
+		$liste = array();
+		if ($resql) 
+			{
+			$i = 0;
+			while ($obj = $this->fetch_object($resql) )
+			{
+				$liste[$i]['collation'] = $obj->Collation;
+				$i++;           
+			}   
+	    	$this->free($resql);
+	  	} else {
+	  		// version Mysql < 4.1.1
+	   		return null;
+	  	}
+    	return $liste;
+	}
+
 }
 
 ?>
diff --git a/htdocs/lib/databases/mysqli.lib.php b/htdocs/lib/databases/mysqli.lib.php
index 0b36e20465c..1f969e3fa5c 100644
--- a/htdocs/lib/databases/mysqli.lib.php
+++ b/htdocs/lib/databases/mysqli.lib.php
@@ -46,6 +46,8 @@ class DoliDb
   var $type='mysqli';          
   //! Charset
   var $forcecharset='latin1';
+  //! Charset client
+  var $forcecharsetclient='iso-8859-1';
   //! Collate
   var $forcecollate='latin1_swedish_ci';
   //! Version min database
@@ -57,7 +59,9 @@ class DoliDb
   //! 1 si base s�lectionn�, 0 sinon
   var $database_selected; 
   //! Nom base s�lectionn�e
-  var $database_name;			
+  var $database_name;
+  //! Nom user base
+  var $database_user;	   
   //! 1 si une transaction est en cours, 0 sinon
   var $transaction_opened;	
   //! Derniere requete ex�cut�e
@@ -114,6 +118,14 @@ class DoliDb
     function DoliDb($type='mysqli', $host, $user, $pass, $name='', $newlink=0)
     {
         global $conf,$langs;
+        
+        $conffile = "../../conf/conf.php";
+        if (file_exists($conffile)) {
+	    	include($conffile);
+	    	$this->forcecharset=$character_set_database;
+	    	$this->forcecollate=$collation_connection;
+	    	$this->db_user=$dolibarr_main_db_user;
+		}
         $this->transaction_opened=0;
 
         //print "Name DB: $host,$user,$pass,$name<br>";
@@ -230,6 +242,22 @@ class DoliDb
 		return mysqli_get_server_info($this->db);
     }
 
+    /**
+     \brief          Renvoie la version du serveur sous forme de nombre
+     \return	        string      Chaine version
+	  */
+	  function getIntVersion()
+	  {
+			$version=	$this->getVersion();
+			$vlist=split('[.-]',$version);
+			if (strlen($vlist[1])==1){
+				$vlist[1]="0".$vlist[1];
+			}
+			if (strlen($vlist[2])==1){
+				$vlist[2]="0".$vlist[2];
+			}
+			return $vlist[0].$vlist[1].$vlist[2];
+	  }
 
     /**
             \brief          Renvoie la version du serveur dans un tableau
@@ -631,22 +659,20 @@ class DoliDb
             \return	        resource		resource d�finie si ok, null si ko
             \remarks        Ne pas utiliser les fonctions xxx_create_db (xxx=mysql, ...) car elles sont deprecated
     */
-    function DDLCreateDb($database)
-    {
-        $sql = 'CREATE DATABASE '.$database;
-        $sql.= ' DEFAULT CHARACTER SET '.$this->forcecharset.' DEFAULT COLLATE '.$this->forcecollate;
-        $ret=$this->query($sql);
-        if (! $ret)
-        {
-        	// On r�essaie pour compatibilit� avec Mysql < 5.0
-	        $sql = 'CREATE DATABASE '.$database;
-	        $ret=$this->query($sql);
-        }
-
-        //print "database=".$this->database_name." ret=".$ret." mysqlerror=".mysqli_error($this->db);
-        return $ret;
-    }
-
+  function DDLCreateDb($database)
+  {
+    // ALTER DATABASE dolibarr_db DEFAULT CHARACTER SET latin DEFAULT COLLATE latin1_swedish_ci
+    $sql = 'CREATE DATABASE '.$database;
+    $sql.= ' DEFAULT CHARACTER SET '.$this->forcecharset.' DEFAULT COLLATE '.$this->forcecollate;
+    $ret=$this->query($sql);
+	if (! $ret)
+		{
+		// On r�essaie pour compatibilit� avec Mysql < 4.1.1
+		$sql = 'CREATE DATABASE '.$database;
+		$ret=$this->query($sql);
+		}
+    return $ret;
+  }
 
     /**
         \brief      Liste des tables dans une database.
@@ -825,6 +851,67 @@ class DoliDb
 	
 		return 1;
 	}
+	
+	function getDefaultCharacterSetDatabase(){
+		 $resql=$this->query('SHOW VARIABLES LIKE \'character_set_database\'');
+		  if (!$resql)
+	      {
+			// version Mysql < 4.1.1
+			return $this->forcecharset;
+	      }
+	    $liste=$this->fetch_array($resql);
+	    return $liste['Value'];
+	}
+	
+	function getListOfCharacterSet(){
+		 $resql=$this->query('SHOW CHARSET');
+		$liste = array();
+		if ($resql) 
+			{
+			$i = 0;
+			while ($obj = $this->fetch_object($resql) )
+			{
+				$liste[$i]['charset'] = $obj->Charset;
+				$liste[$i]['description'] = $obj->Description;
+				$i++;           
+			}   
+	    	$this->free($resql);
+	  	} else {
+	  		// version Mysql < 4.1.1
+	   		return null;
+	  	}
+    	return $liste;
+	}
+	
+	function getDefaultCollationConnection(){
+		$resql=$this->query('SHOW VARIABLES LIKE \'collation_connection\'');
+		 if (!$resql)
+	      {
+			// version Mysql < 4.1.1
+			return $this->forcecollate;
+	      }
+	    $liste=$this->fetch_array($resql);
+	    return $liste['Value'];
+	}
+	
+	function getListOfCollation(){
+		 $resql=$this->query('SHOW COLLATION');
+		$liste = array();
+		if ($resql) 
+			{
+			$i = 0;
+			while ($obj = $this->fetch_object($resql) )
+			{
+				$liste[$i]['collation'] = $obj->Collation;
+				$i++;           
+			}   
+	    	$this->free($resql);
+	  	} else {
+	  		// version Mysql < 4.1.1
+	   		return null;
+	  	}
+    	return $liste;
+	}
 }
 
 ?>
diff --git a/htdocs/lib/databases/pgsql.lib.php b/htdocs/lib/databases/pgsql.lib.php
index a1898a30275..27400a1e099 100644
--- a/htdocs/lib/databases/pgsql.lib.php
+++ b/htdocs/lib/databases/pgsql.lib.php
@@ -44,6 +44,8 @@ class DoliDb
 {
     var $db;                      // Handler de base
     var $type='pgsql';            // Nom du gestionnaire
+   //! Charset
+    var $forcecharset='latin1';
 	var $versionmin=array(8,1,0);	// Version min database
 
     var $results;                 // Resultset de la derni�re requete
@@ -51,12 +53,14 @@ class DoliDb
     var $connected;               // 1 si connect�, 0 sinon
     var $database_selected;       // 1 si base s�lectionn�, 0 sinon
     var $database_name;			  // Nom base s�lectionn�e
+  var $database_user;	   //! Nom user base
     var $transaction_opened;      // 1 si une transaction est en cours, 0 sinon
     var $lastquery;
 	var $lastqueryerror;		// Ajout d'une variable en cas d'erreur
 
     var $ok;
     var $error;
+ 
 
 
     /**
@@ -71,6 +75,12 @@ class DoliDb
     function DoliDb($type='pgsql', $host, $user, $pass, $name='')
     {
         global $conf,$langs;
+        $conffile = "../conf/conf.php";
+		if (file_exists($conffile)) {	
+	    	include($conffile);
+	    	$this->forcecharset=$character_set_database;
+	    	$this->db_user=$dolibarr_main_db_user;
+		}
         $this->transaction_opened=0;
 
         //print "Name DB: $host,$user,$pass,$name<br>";
@@ -161,7 +171,10 @@ class DoliDb
     */
     function connect($host, $login, $passwd, $name)
     {
-        $con_string = "host=$host dbname=$name user=$login password=--hidden--";
+    	if (!$name){
+    		$name="postgres";
+    	}
+        $con_string = "host=$host dbname=$name user=$login password=$passwd";
         $this->db = pg_connect($con_string);
         if ($this->db)
         {
@@ -177,10 +190,28 @@ class DoliDb
     */
     function getVersion()
     {
-        return '?';
+    	$resql=$this->query('SHOW server_version');
+	    $liste=$this->fetch_array($resql);
+	    return $liste['server_version'];
     }
 
-
+    /**
+     \brief          Renvoie la version du serveur sous forme de nombre
+     \return	        string      Chaine version
+	  */
+	  function getIntVersion()
+	  {
+			$version=	$this->getVersion();
+			$vlist=split('[.-]',$version);
+			if (strlen($vlist[1])==1){
+				$vlist[1]="0".$vlist[1];
+			}
+			if (strlen($vlist[2])==1){
+				$vlist[2]="0".$vlist[2];
+			}
+			return $vlist[0].$vlist[1].$vlist[2];
+	  }
+  
     /**
             \brief          Renvoie la version du serveur dans un tableau
             \return	        array  		Tableau de chaque niveau de version
@@ -266,8 +297,11 @@ class DoliDb
     function query($query)
     {
         $query = trim($query);
-        $ret = pg_query($this->db, $query);
-
+        
+		if ($this->forcecharset=="UTF-8"){
+					$buffer=utf8_encode ($buffer);
+		}
+		$ret = pg_query($this->db, $query);	
         if (! eregi("^COMMIT",$query) && ! eregi("^ROLLBACK",$query))
         {
             // Si requete utilisateur, on la sauvegarde ainsi que son resultset
@@ -528,7 +562,7 @@ class DoliDb
         $nbre = pg_num_rows($result);
         $row = pg_fetch_result($result,0,0);
         return $row;
-
+    }
 
 	// Next function are not required. Only minor features use them.
 	//--------------------------------------------------------------
@@ -593,10 +627,9 @@ class DoliDb
     */
     function DDLCreateDb($database)
     {
-        $ret=$this->query('CREATE DATABASE '.$database.';');
+        $ret=$this->query('CREATE DATABASE '.$database.' OWNER '.$this->db_user.' ENCODING \''.$this->forcecharset.'\' ;');
         return $ret;
     }
-    }
 
     /**
         \brief      Liste des tables dans une database.
@@ -630,6 +663,11 @@ class DoliDb
 		
 		return 1;
 	}
+	
+	function getDefaultCharacterSetDatabase(){
+		 $resql=$this->query('SHOW SERVER_ENCODING');
+	    $liste=$this->fetch_array($resql);
+	    return $liste['server_encoding'];
+	}
 }
-
 ?>
diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php
index d468a0d3364..3454003de99 100644
--- a/htdocs/main.inc.php
+++ b/htdocs/main.inc.php
@@ -536,7 +536,7 @@ function top_htmlhead($head, $title="", $target="")
     if (! $conf->css)  $conf->css ='/theme/eldy/eldy.css.php';
 
     //header("Content-type: text/html; charset=UTF-8");
-    header("Content-type: text/html; charset=iso-8859-1");
+ 	header("Content-type: text/html; charset=".$_SESSION['charset']);
 
     print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
 //    print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd>';
diff --git a/htdocs/master.inc.php b/htdocs/master.inc.php
index 3b593059688..11ee76e3eaa 100644
--- a/htdocs/master.inc.php
+++ b/htdocs/master.inc.php
@@ -130,6 +130,13 @@ require_once(DOL_DOCUMENT_ROOT ."/menu.class.php");
 require_once(DOL_DOCUMENT_ROOT ."/html.form.class.php");
 require_once(DOL_DOCUMENT_ROOT ."/lib/databases/".$conf->db->type.".lib.php");
 
+require_once(DOL_DOCUMENT_ROOT ."/conf/conf.class.php");
+if ($character_set_client ){
+	$_SESSION['charset'] = $character_set_client;
+}else{
+	$_SESSION['charset'] =$langs->trans("charset");
+}
+
 /*
  * Creation objet $db
  */
diff --git a/htdocs/product/ajaxproducts.php b/htdocs/product/ajaxproducts.php
index 68fc633043e..04e337870ad 100644
--- a/htdocs/product/ajaxproducts.php
+++ b/htdocs/product/ajaxproducts.php
@@ -32,7 +32,7 @@ $langs->load("products");
 $langs->load("main");
 
 //header("Content-type: text/html; charset=UTF-8");
-header("Content-type: text/html; charset=iso-8859-1");
+header("Content-type: text/html; charset=$character_set_client");
 print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
 print "\n<html>";
 print "\n<body>";
diff --git a/htdocs/translate.class.php b/htdocs/translate.class.php
index 37e4328fc9e..1b0faac9c9d 100644
--- a/htdocs/translate.class.php
+++ b/htdocs/translate.class.php
@@ -49,6 +49,7 @@ class Translate {
      */
     function Translate($dir = "")
     {
+		$this->charset=$_SESSION['charset'];
         $this->dir=$dir;
     }
 
@@ -236,7 +237,9 @@ class Translate {
             $newstr=ereg_replace('"','__quot__',$newstr);
 
             // Cryptage en html de la chaine
-            $newstr=htmlentities($newstr,ENT_QUOTES,$this->charset);
+            $this->load("main");
+           $charset=sprintf($this->tab_translate["charset"]);
+            $newstr=htmlentities($newstr,ENT_QUOTES,$charset);
 
             // On restaure les tags HTML
             $newstr=ereg_replace('__lt__','<',$newstr);
@@ -311,12 +314,8 @@ class Translate {
 		
     function lang_header()
     {
-        $this->load("main");
-        $charset=$this->trans("charset");
-        if (! $charset) $charset="iso-8859-1";
-    
         //header("Content-Type: text/html; charset=$charset");
-        $texte = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=$charset\">\n";
+        $texte = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=$this->charset\">\n";
     
         return $texte;
     }
diff --git a/pgsql/tables/llx_paiementfourn_facturefourn.sql b/pgsql/tables/llx_paiementfourn_facturefourn.sql
index 76594090e57..d4fa6bd882c 100644
--- a/pgsql/tables/llx_paiementfourn_facturefourn.sql
+++ b/pgsql/tables/llx_paiementfourn_facturefourn.sql
@@ -28,7 +28,7 @@
 create table llx_paiementfourn_facturefourn
 (
   rowid SERIAL PRIMARY KEY,
-  "fk_paiementfourn" INT(11) DEFAULT NULL,
-  "fk_facturefourn"  INT(11) DEFAULT NULL,
+  "fk_paiementfourn" integer DEFAULT NULL,
+  "fk_facturefourn"  integer DEFAULT NULL,
   "amount" real DEFAULT '0'
 );
\ No newline at end of file
-- 
GitLab