From eb121182a99e5dec424e069916fe8b2a674bbdfd Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@users.sourceforge.net>
Date: Sun, 1 Feb 2004 01:50:21 +0000
Subject: [PATCH] =?UTF-8?q?Prefix=20en=20dur=20"llx=5F"=20remplac=E9=20par?=
 =?UTF-8?q?=20constante=20"MAIN=5FDB=5FPREFIX".?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 htdocs/actioncomm.class.php          |  8 ++--
 htdocs/cactioncomm.class.php         |  4 +-
 htdocs/chargesociales.class.php      |  2 +-
 htdocs/compta/bank/account.class.php | 28 +++++++-------
 htdocs/compta/bank/account.php       | 14 +++----
 htdocs/compta/bank/bank.lib.php      |  4 +-
 htdocs/compta/bank/bilan.php         |  8 ++--
 htdocs/compta/bank/bplc.php          |  2 +-
 htdocs/compta/bank/budget.php        |  6 +--
 htdocs/compta/bank/categ.php         |  4 +-
 htdocs/compta/bank/config.php        |  2 +-
 htdocs/compta/bank/ligne.php         | 22 +++++------
 htdocs/compta/bank/pre.inc.php       |  2 +-
 htdocs/compta/bank/rappro.php        | 12 +++---
 htdocs/compta/bank/releve.php        | 12 +++---
 htdocs/compta/bank/search.php        |  6 +--
 htdocs/compta/bank/virement.php      |  8 ++--
 htdocs/compta/commande.php           |  4 +-
 htdocs/compta/config.php             |  2 +-
 htdocs/compta/index.php              |  6 +--
 htdocs/compta/ligne.php              |  6 +--
 htdocs/compta/pmt.php                |  6 +--
 htdocs/compta/pointmort.php          |  4 +-
 htdocs/compta/propal.php             | 10 ++---
 htdocs/compta/tva.php                |  2 +-
 htdocs/contact.class.php             |  8 ++--
 htdocs/don.class.php                 | 22 +++++------
 htdocs/facture.class.php             | 58 ++++++++++++++--------------
 htdocs/facturefourn.class.php        | 36 ++++++++---------
 htdocs/index.php                     |  2 +-
 htdocs/install.php                   | 18 ++++-----
 htdocs/main.inc.php                  |  6 +--
 htdocs/notify.class.php              |  4 +-
 htdocs/paiement.class.php            |  8 ++--
 htdocs/product.class.php             | 38 +++++++++---------
 htdocs/project.class.php             |  8 ++--
 htdocs/projetdon.class.php           |  2 +-
 htdocs/propal.class.php              | 40 +++++++++----------
 htdocs/retourbplc.class.php          |  2 +-
 htdocs/service.class.php             | 10 ++---
 htdocs/societe.class.php             | 24 ++++++------
 htdocs/socnote.php                   |  2 +-
 htdocs/stats.php                     |  8 ++--
 htdocs/tva.class.php                 |  8 ++--
 htdocs/user.class.php                | 48 +++++++++++------------
 45 files changed, 268 insertions(+), 268 deletions(-)

diff --git a/htdocs/actioncomm.class.php b/htdocs/actioncomm.class.php
index 090b5d3e660..c041c1a88de 100644
--- a/htdocs/actioncomm.class.php
+++ b/htdocs/actioncomm.class.php
@@ -64,7 +64,7 @@ class ActionComm
 	{
 	  $this->propalrowid = 0;
 	}
-      $sql = "INSERT INTO llx_actioncomm (datea, fk_action, fk_soc, fk_user_author, fk_user_action, fk_contact, percent, note,priority,propalrowid) ";
+      $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm (datea, fk_action, fk_soc, fk_user_author, fk_user_action, fk_contact, percent, note,priority,propalrowid) ";
       $sql .= " VALUES ('$this->date', $this->type, $this->societe, $author->id,";
       $sql .= $this->user->id . ", $this->contact, $this->percent, '$this->note', $this->priority, $this->propalrowid);";
       
@@ -85,7 +85,7 @@ class ActionComm
   Function fetch($id)
     {      
       $sql = "SELECT ".$this->db->pdate("a.datea")." as da, a.note, c.libelle, fk_soc, fk_user_author, fk_contact, fk_facture, a.percent ";
-      $sql .= "FROM llx_actioncomm as a, c_actioncomm as c WHERE a.id=$id AND a.fk_action=c.id;";
+      $sql .= "FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."c_actioncomm as c WHERE a.id=$id AND a.fk_action=c.id;";
 
       if ($this->db->query($sql) )
 	{
@@ -127,7 +127,7 @@ class ActionComm
    */
   Function delete($id)
     {      
-      $sql = "DELETE FROM llx_actioncomm WHERE id=$id;";
+      $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm WHERE id=$id;";
       
       if ($this->db->query($sql) )
 	{
@@ -145,7 +145,7 @@ class ActionComm
 	  $this->percent = 100;
 	}
       
-      $sql = "UPDATE llx_actioncomm ";
+      $sql = "UPDATE ".MAIN_DB_PREFIX."actioncomm ";
       $sql .= " SET percent=$this->percent";
 
       if ($this->percent == 100)
diff --git a/htdocs/cactioncomm.class.php b/htdocs/cactioncomm.class.php
index 8109a51afc3..05be7e18d77 100644
--- a/htdocs/cactioncomm.class.php
+++ b/htdocs/cactioncomm.class.php
@@ -38,7 +38,7 @@ class CActioncomm {
   {
     $ga = array();
 
-    $sql = "SELECT id, libelle FROM c_actioncomm";
+    $sql = "SELECT id, libelle FROM ".MAIN_DB_PREFIX."c_actioncomm";
     $sql .= " ORDER BY id";
 
     if ($this->db->query($sql) )
@@ -68,7 +68,7 @@ class CActioncomm {
   Function fetch($db, $id)
     {
 
-      $sql = "SELECT libelle FROM c_actioncomm WHERE id=$id;";
+      $sql = "SELECT libelle FROM ".MAIN_DB_PREFIX."c_actioncomm WHERE id=$id;";
       
       if ($db->query($sql) )
 	{
diff --git a/htdocs/chargesociales.class.php b/htdocs/chargesociales.class.php
index 6e28a66ebea..17887f84cfb 100644
--- a/htdocs/chargesociales.class.php
+++ b/htdocs/chargesociales.class.php
@@ -45,7 +45,7 @@ class ChargeSociales {
   Function solde($year = 0) {
 
     $sql = "SELECT sum(f.amount) as amount";
-    $sql .= " FROM llx_chargesociales as f WHERE paye = 0";
+    $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as f WHERE paye = 0";
 
     if ($year) {
       $sql .= " AND f.datev >= '$y-01-01' AND f.datev <= '$y-12-31' ";
diff --git a/htdocs/compta/bank/account.class.php b/htdocs/compta/bank/account.class.php
index 4d97a0efd94..17049e6d07e 100644
--- a/htdocs/compta/bank/account.class.php
+++ b/htdocs/compta/bank/account.class.php
@@ -47,18 +47,18 @@ class Account
   }
 
   /*
-   * Efface une entree dans la table llx_bank
+   * Efface une entree dans la table ".MAIN_DB_PREFIX."bank
    */
 
   Function deleteline($rowid)
   {
-    $sql = "DELETE FROM llx_bank_class WHERE lineid=$rowid";
+    $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid=$rowid";
     $result = $this->db->query($sql);
 
-    $sql = "DELETE FROM llx_bank WHERE rowid=$rowid";
+    $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank WHERE rowid=$rowid";
     $result = $this->db->query($sql);
 
-    $sql = "DELETE FROM llx_bank_url WHERE fk_bank=$rowid";
+    $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url WHERE fk_bank=$rowid";
     $result = $this->db->query($sql);
   }
   /*
@@ -67,7 +67,7 @@ class Account
    */
   Function add_url_line($line_id, $url_id, $url, $label)
   {
-    $sql = "INSERT INTO llx_bank_url (fk_bank, url_id, url, label)";
+    $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_url (fk_bank, url_id, url, label)";
     $sql .= " VALUES ('$line_id', '$url_id', '$url', '$label')";
 
     if ($this->db->query($sql))
@@ -89,7 +89,7 @@ class Account
   Function get_url($line_id)
   {
     $lines = array();
-    $sql = "SELECT fk_bank, url_id, url, label FROM llx_bank_url WHERE fk_bank = $line_id";
+    $sql = "SELECT fk_bank, url_id, url, label FROM ".MAIN_DB_PREFIX."bank_url WHERE fk_bank = $line_id";
     $result = $this->db->query($sql);
 
     if ($result)
@@ -108,7 +108,7 @@ class Account
       }
   }
   /*
-   * Ajoute une entree dans la table llx_bank
+   * Ajoute une entree dans la table ".MAIN_DB_PREFIX."bank
    *
    */
   Function addline($date, $oper, $label, $amount, $num_chq="",$categorie='')
@@ -140,7 +140,7 @@ class Account
 	    break;
 	  }
 	
-	$sql = "INSERT INTO llx_bank (datec, dateo, label, amount, author, num_chq,fk_account, fk_type)";
+	$sql = "INSERT INTO ".MAIN_DB_PREFIX."bank (datec, dateo, label, amount, author, num_chq,fk_account, fk_type)";
 	$sql .= " VALUES (now(), '$date', '$label', '" . ereg_replace(",",".",$amount) . "','$author','$num_chq', '$this->rowid', '$oper')";
 
 
@@ -149,7 +149,7 @@ class Account
 	    $rowid = $this->db->last_insert_id();
 	    if ($categorie)
 	      {
-		$sql = "INSERT INTO llx_bank_class (lineid, fk_categ) VALUES ('$rowid', '$categorie')";
+		$sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_class (lineid, fk_categ) VALUES ('$rowid', '$categorie')";
 		$result = $this->db->query($sql);
 		if ($result){
 		  return $rowid;
@@ -172,7 +172,7 @@ class Account
    */
   Function create()
     {
-      $sql = "INSERT INTO llx_bank_account (datec, label) values (now(),'$this->label');";
+      $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_account (datec, label) values (now(),'$this->label');";
       if ($this->db->query($sql))
 	{
 	  if ($this->db->affected_rows()) 
@@ -180,7 +180,7 @@ class Account
 	      $this->id = $this->db->last_insert_id();
 	      if ( $this->update() )
 		{
-		  $sql = "INSERT INTO llx_bank (datec, label, amount, fk_account,datev,dateo,fk_type,rappro) ";
+		  $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank (datec, label, amount, fk_account,datev,dateo,fk_type,rappro) ";
 		  $sql .= " VALUES (now(),'Solde','" . ereg_replace(",",".",$this->solde) . "','$this->id','".$this->db->idate($this->date_solde)."','".$this->db->idate($this->date_solde)."','SOLD',1);";
 
 		  $this->db->query($sql);
@@ -203,7 +203,7 @@ class Account
       if (strlen($this->label)==0)
 	$this->label = "???";
 
-      $sql = "UPDATE llx_bank_account SET ";
+      $sql = "UPDATE ".MAIN_DB_PREFIX."bank_account SET ";
 
       $sql .= " bank = '" .$this->bank ."'";
       $sql .= ",label = '".$this->label ."'";
@@ -243,7 +243,7 @@ class Account
   Function fetch($id)
   {
     $this->id = $id; 
-    $sql = "SELECT rowid, label, bank, number, courant, clos, code_banque,code_guichet,cle_rib,bic,iban_prefix,domiciliation FROM llx_bank_account";
+    $sql = "SELECT rowid, label, bank, number, courant, clos, code_banque,code_guichet,cle_rib,bic,iban_prefix,domiciliation FROM ".MAIN_DB_PREFIX."bank_account";
     $sql .= " WHERE rowid  = ".$id;
 
     $result = $this->db->query($sql);
@@ -279,7 +279,7 @@ class Account
    */
   Function solde()
   {
-    $sql = "SELECT sum(amount) FROM llx_bank WHERE fk_account=$this->id AND dateo <=" . $this->db->idate(time() );
+    $sql = "SELECT sum(amount) FROM ".MAIN_DB_PREFIX."bank WHERE fk_account=$this->id AND dateo <=" . $this->db->idate(time() );
 
     $result = $this->db->query($sql);
 
diff --git a/htdocs/compta/bank/account.php b/htdocs/compta/bank/account.php
index 5bad61de550..1d7ef3c758f 100644
--- a/htdocs/compta/bank/account.php
+++ b/htdocs/compta/bank/account.php
@@ -54,12 +54,12 @@ if ($HTTP_POST_VARS["action"] == 'add' && $_GET["account"])
     /*
   if ($num_chq)
     {
-      $sql = "INSERT INTO llx_bank (datec, dateo, label, amount, author, num_chq,fk_account, fk_type)";
+      $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank (datec, dateo, label, amount, author, num_chq,fk_account, fk_type)";
       $sql .= " VALUES (now(), '$dateop', '$label', '$amount','$author','$num_chq','$account','$operation')";
     }
   else
     {
-      $sql = "INSERT INTO llx_bank (datec, dateo, label, amount, author,fk_account,fk_type)";
+      $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank (datec, dateo, label, amount, author,fk_account,fk_type)";
       $sql .= " VALUES (now(), '$dateop', '$label', '$amount','$author','$account','$operation')";
     }
   
@@ -69,7 +69,7 @@ if ($HTTP_POST_VARS["action"] == 'add' && $_GET["account"])
       $rowid = $db->last_insert_id();
       if ($cat1)
 	{
-	  $sql = "INSERT INTO llx_bank_class (lineid, fk_categ) VALUES ($rowid, $cat1)";
+	  $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_class (lineid, fk_categ) VALUES ($rowid, $cat1)";
 	  $result = $db->query($sql);
 	}
       Header("Location: $PHP_SELF?account=$account");
@@ -109,7 +109,7 @@ if ($_GET["account"] > 0)
   $acct = new Account($db);
   $acct->fetch($_GET["account"]);
 
-  $sql = "SELECT rowid, label FROM llx_bank_categ;";
+  $sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."bank_categ;";
   $result = $db->query($sql);
   if ($result)
     {
@@ -130,7 +130,7 @@ if ($_GET["account"] > 0)
   /*
    *
    */
-  $sql = "SELECT rowid, label FROM llx_bank_categ;";
+  $sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."bank_categ;";
   $result = $db->query($sql);
   if ($result)
     {
@@ -158,7 +158,7 @@ if ($_GET["account"] > 0)
    *
    *
    */
-  $sql = "SELECT count(*) FROM llx_bank as b WHERE 1=1";
+  $sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."bank as b WHERE 1=1";
   $sql .= " AND b.dateo <= now()";
   $sql .= " AND b.fk_account=".$acct->id;
 
@@ -250,7 +250,7 @@ if ($_GET["account"] > 0)
    */
 
   $sql = "SELECT b.rowid,".$db->pdate("b.dateo")." as do, b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type";
-  $sql .= " FROM llx_bank as b ";
+  $sql .= " FROM ".MAIN_DB_PREFIX."bank as b ";
   $sql .= " WHERE fk_account=".$acct->id;
 
   if ($req_debit) 
diff --git a/htdocs/compta/bank/bank.lib.php b/htdocs/compta/bank/bank.lib.php
index 512fc4996ce..888298287ff 100644
--- a/htdocs/compta/bank/bank.lib.php
+++ b/htdocs/compta/bank/bank.lib.php
@@ -22,10 +22,10 @@
  */
 
 Function bank_delete_line($db, $rowid) {
-  $sql = "DELETE FROM llx_bank WHERE rowid=$rowid";
+  $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank WHERE rowid=$rowid";
   $result = $db->query($sql);
   if ($result) {
-    $sql = "DELETE FROM llx_bank_class WHERE lineid=$rowid";
+    $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid=$rowid";
     $result = $db->query($sql);
   }
 }
diff --git a/htdocs/compta/bank/bilan.php b/htdocs/compta/bank/bilan.php
index 2e6860c7d9a..e2d7e5c0398 100644
--- a/htdocs/compta/bank/bilan.php
+++ b/htdocs/compta/bank/bilan.php
@@ -48,22 +48,22 @@ print_titre("Bilan");
 print "<TABLE border=\"1\" width=\"100%\" cellspacing=\"0\" cellpadding=\"2\">";
 
 $var=!$var;
-$sql = "SELECT sum(amount) FROM llx_paiement";
+$sql = "SELECT sum(amount) FROM ".MAIN_DB_PREFIX."paiement";
 $paiem = valeur($sql);
 print "<tr $bc[$var]><td>Somme des paiements (associ�s � une facture)</td><td align=\"right\">".price($paiem)."</td></tr>";
 
 $var=!$var;
-$sql = "SELECT sum(amount) FROM llx_bank WHERE amount > 0";
+$sql = "SELECT sum(amount) FROM ".MAIN_DB_PREFIX."bank WHERE amount > 0";
 $credits = valeur($sql);
 print "<tr $bc[$var]><td>Somme des credits</td><td align=\"right\">".price($credits)."</td></tr>";
 
 $var=!$var;
-$sql = "SELECT sum(amount) FROM llx_bank WHERE amount < 0";
+$sql = "SELECT sum(amount) FROM ".MAIN_DB_PREFIX."bank WHERE amount < 0";
 $debits = valeur($sql);
 print "<tr $bc[$var]><td>Somme des debits</td><td align=\"right\">".price($debits)."</td></tr>";
 
 $var=!$var;
-$sql = "SELECT sum(amount) FROM llx_bank ";
+$sql = "SELECT sum(amount) FROM ".MAIN_DB_PREFIX."bank ";
 $solde = valeur($sql);
 print "<tr $bc[$var]><td>Solde compte</td><td align=\"right\">".price($solde)."</td></tr>";
 
diff --git a/htdocs/compta/bank/bplc.php b/htdocs/compta/bank/bplc.php
index e542801b96d..e359c66797c 100644
--- a/htdocs/compta/bank/bplc.php
+++ b/htdocs/compta/bank/bplc.php
@@ -56,7 +56,7 @@ $sql = "SELECT ipclient,
                code_retour, 
                ref_commande";
 
-$sql .= " FROM llx_transaction_bplc";
+$sql .= " FROM ".MAIN_DB_PREFIX."transaction_bplc";
 
 $result = $db->query($sql);
 if ($result) {
diff --git a/htdocs/compta/bank/budget.php b/htdocs/compta/bank/budget.php
index 994429c80c7..8a39404a3b9 100644
--- a/htdocs/compta/bank/budget.php
+++ b/htdocs/compta/bank/budget.php
@@ -44,7 +44,7 @@ if ($_GET["bid"] == 0)
   print "</TR>\n";
 
   $sql = "SELECT sum(d.amount) as somme, count(*) as nombre, c.label, c.rowid ";
-  $sql .= " FROM llx_bank_categ as c, llx_bank_class as l, llx_bank as d";
+  $sql .= " FROM ".MAIN_DB_PREFIX."bank_categ as c, ".MAIN_DB_PREFIX."bank_class as l, ".MAIN_DB_PREFIX."bank as d";
   $sql .= " WHERE d.rowid=l.lineid AND c.rowid = l.fk_categ GROUP BY c.label, c.rowid ORDER BY c.label";
   
   $result = $db->query($sql);
@@ -84,7 +84,7 @@ else
   /*
    *  Vue
    */
-  $sql = "SELECT label FROM llx_bank_categ WHERE rowid=".$_GET["bid"];
+  $sql = "SELECT label FROM ".MAIN_DB_PREFIX."bank_categ WHERE rowid=".$_GET["bid"];
   if ( $db->query($sql) )
     {
       if ( $db->num_rows() )
@@ -102,7 +102,7 @@ else
   print "</TR>\n";
 
   $sql = "SELECT d.amount, d.label, ".$db->pdate("d.dateo")." as do, d.rowid";
-  $sql .= " FROM llx_bank_class as l, llx_bank as d";
+  $sql .= " FROM ".MAIN_DB_PREFIX."bank_class as l, ".MAIN_DB_PREFIX."bank as d";
   $sql .= " WHERE d.rowid=l.lineid AND l.fk_categ=".$_GET["bid"]." ORDER by d.dateo DESC";
   
   $result = $db->query($sql);
diff --git a/htdocs/compta/bank/categ.php b/htdocs/compta/bank/categ.php
index 0e34fd523c6..4d5fb3fb49b 100644
--- a/htdocs/compta/bank/categ.php
+++ b/htdocs/compta/bank/categ.php
@@ -41,7 +41,7 @@ if ($action == 'add')
       $amount = - $debit ;
     }
 
-  $sql = "INSERT INTO llx_bank_categ (label) VALUES ('$label')";
+  $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_categ (label) VALUES ('$label')";
   $result = $db->query($sql);
 
   if (!$result)
@@ -60,7 +60,7 @@ print "<td>Num</td><td colspan=\"2\">Description</TD>";
 print "</TR>\n";
 
 
-$sql = "SELECT rowid, label FROM llx_bank_categ ORDER BY label";
+$sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."bank_categ ORDER BY label";
 
 $result = $db->query($sql);
 if ($result)
diff --git a/htdocs/compta/bank/config.php b/htdocs/compta/bank/config.php
index 71f8cac6c11..98d176e8ec8 100644
--- a/htdocs/compta/bank/config.php
+++ b/htdocs/compta/bank/config.php
@@ -37,7 +37,7 @@ print "<td align=\"left\">Number</a></TD>";
 print "<td align=\"center\">Clos</a></TD>";
 print "</TR>\n";
 
-$sql = "SELECT rowid, label,number,bank,clos from llx_bank_account";
+$sql = "SELECT rowid, label,number,bank,clos from ".MAIN_DB_PREFIX."bank_account";
 
 $result = $db->query($sql);
 if ($result)
diff --git a/htdocs/compta/bank/ligne.php b/htdocs/compta/bank/ligne.php
index 553191db03f..2bf676c4a40 100644
--- a/htdocs/compta/bank/ligne.php
+++ b/htdocs/compta/bank/ligne.php
@@ -29,17 +29,17 @@ llxHeader();
 
 if ($HTTP_POST_VARS["action"] == 'confirm_delete_categ' && $HTTP_POST_VARS["confirm"] == yes)
 {
-  $sql = "DELETE FROM llx_bank_class WHERE lineid = $rowid AND fk_categ = $cat1";
+  $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid = $rowid AND fk_categ = $cat1";
   $db->query($sql);
 }
 
 
 if ($action == 'class')
 {
-  $sql = "DELETE FROM llx_bank_class WHERE lineid = $rowid AND fk_categ = $cat1";
+  $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid = $rowid AND fk_categ = $cat1";
   $db->query($sql);
 
-  $sql = "INSERT INTO llx_bank_class (lineid, fk_categ) VALUES ($rowid, $cat1)";
+  $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_class (lineid, fk_categ) VALUES ($rowid, $cat1)";
   if ($db->query($sql))
     {
       
@@ -57,7 +57,7 @@ if ($action == 'update')
 //print_r ($_POST);
   if (!empty($_POST['amount']))
   {
-    $sql = "SELECT b.rappro FROM llx_bank as b WHERE rowid=$rowid";
+    $sql = "SELECT b.rappro FROM ".MAIN_DB_PREFIX."bank as b WHERE rowid=$rowid";
     $result = $db->query($sql);
     if ($result)
     {
@@ -67,27 +67,27 @@ if ($action == 'update')
       $objp = $db->fetch_object( 0);
       if ($objp->rappro)
         die ("Vous ne pouvez pas modifier une �criture d�j� rapproch�e");
-      $sql = "update llx_bank set label='$label' , dateo = '$date', amount='$amount' where rowid = $rowid;";
+      $sql = "update ".MAIN_DB_PREFIX."bank set label='$label' , dateo = '$date', amount='$amount' where rowid = $rowid;";
     }
   }
   else 
-    $sql = "update llx_bank set label='$label' where rowid = $rowid;";
+    $sql = "update ".MAIN_DB_PREFIX."bank set label='$label' where rowid = $rowid;";
 $result = $db->query($sql);
 }
 
 if ($HTTP_POST_VARS["action"] == 'type')
 {
-  $sql = "update llx_bank set fk_type='$value' where rowid = $rowid;";
+  $sql = "update ".MAIN_DB_PREFIX."bank set fk_type='$value' where rowid = $rowid;";
   $result = $db->query($sql);
 }
 
 if ($HTTP_POST_VARS["action"] == 'num_releve')
 {
-  $sql = "update llx_bank set num_releve=$num_rel where rowid = $rowid;";
+  $sql = "update ".MAIN_DB_PREFIX."bank set num_releve=$num_rel where rowid = $rowid;";
   $result = $db->query($sql);
 }
 
-$sql = "SELECT rowid, label FROM llx_bank_categ;";
+$sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."bank_categ;";
 $result = $db->query($sql);
 if ($result)
 {
@@ -122,7 +122,7 @@ print "<td align=\"center\">Auteur</TD>";
 print "</TR>\n";
 
 $sql = "SELECT b.rowid,".$db->pdate("b.dateo")." as do, b.amount, b.label, b.rappro, b.num_releve, b.author, b.num_chq, b.fk_type, fk_account";
-$sql .= " FROM llx_bank as b WHERE rowid=$rowid";
+$sql .= " FROM ".MAIN_DB_PREFIX."bank as b WHERE rowid=$rowid";
 $sql .= " ORDER BY dateo ASC";
 $result = $db->query($sql);
 if ($result)
@@ -234,7 +234,7 @@ print '<td colspan="3">Description</td>';
 print "</TR>\n";
 
 $sql = "SELECT c.label, c.rowid";
-$sql .= " FROM llx_bank_class as a, llx_bank_categ as c WHERE a.lineid=$rowid AND a.fk_categ = c.rowid ";
+$sql .= " FROM ".MAIN_DB_PREFIX."bank_class as a, ".MAIN_DB_PREFIX."bank_categ as c WHERE a.lineid=$rowid AND a.fk_categ = c.rowid ";
 $sql .= " ORDER BY c.label";
 $result = $db->query($sql);
 if ($result)
diff --git a/htdocs/compta/bank/pre.inc.php b/htdocs/compta/bank/pre.inc.php
index d8bd4e25ad3..9518b9d6089 100644
--- a/htdocs/compta/bank/pre.inc.php
+++ b/htdocs/compta/bank/pre.inc.php
@@ -41,7 +41,7 @@ function llxHeader($head = "")
   $menu->add_submenu("search.php","Recherche");
 
 
-  $sql = "SELECT rowid, label FROM llx_bank_account where clos = 0 AND courant = 1";
+  $sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."bank_account where clos = 0 AND courant = 1";
   $result = $db->query($sql);
   if ($result)
     {
diff --git a/htdocs/compta/bank/rappro.php b/htdocs/compta/bank/rappro.php
index d16175a6ec9..eb3f4209401 100644
--- a/htdocs/compta/bank/rappro.php
+++ b/htdocs/compta/bank/rappro.php
@@ -31,11 +31,11 @@ llxHeader();
 if ($action == 'rappro')
 {
   if ($num_releve > 0) {
-    $sql = "UPDATE llx_bank set rappro=$rappro, num_releve=$num_releve WHERE rowid=$rowid";
+    $sql = "UPDATE ".MAIN_DB_PREFIX."bank set rappro=$rappro, num_releve=$num_releve WHERE rowid=$rowid";
     $result = $db->query($sql);
     if ($result) {
       if ($cat1 && $rappro) {
-	$sql = "INSERT INTO llx_bank_class (lineid, fk_categ) VALUES ($rowid, $cat1)";
+	$sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_class (lineid, fk_categ) VALUES ($rowid, $cat1)";
 	$result = $db->query($sql);
       }
     } else {
@@ -45,14 +45,14 @@ if ($action == 'rappro')
   }
 }
 if ($action == 'del') {
-  $sql = "DELETE FROM llx_bank WHERE rowid=$rowid";
+  $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank WHERE rowid=$rowid";
   $result = $db->query($sql);
   if (!$result) {
     print $db->error();
     print "<p>$sql";
   }
 }
-$sql = "SELECT rowid, label FROM llx_bank_categ ORDER BY label;";
+$sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."bank_categ ORDER BY label;";
 $result = $db->query($sql);
 if ($result) {
   $var=True;  
@@ -66,7 +66,7 @@ if ($result) {
   $db->free();
 }
 
-$sql = "SELECT max(num_releve) FROM llx_bank WHERE fk_account=$account";
+$sql = "SELECT max(num_releve) FROM ".MAIN_DB_PREFIX."bank WHERE fk_account=$account";
 if ( $db->query($sql) )
 {
   if ( $db->num_rows() )
@@ -86,7 +86,7 @@ $acct->fetch($account);
 print_titre('Rapprochement bancaire compte : <a href="account.php?account='.$account.'">'.$acct->label.'</a>');
 
 $sql = "SELECT b.rowid,".$db->pdate("b.dateo")." as do, b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type";
-$sql .= " FROM llx_bank as b WHERE rappro=0 AND fk_account=$account AND dateo <= now()";
+$sql .= " FROM ".MAIN_DB_PREFIX."bank as b WHERE rappro=0 AND fk_account=$account AND dateo <= now()";
 $sql .= " ORDER BY dateo ASC LIMIT 10";
 
 
diff --git a/htdocs/compta/bank/releve.php b/htdocs/compta/bank/releve.php
index 2c9963a5a90..2e236e69cfc 100644
--- a/htdocs/compta/bank/releve.php
+++ b/htdocs/compta/bank/releve.php
@@ -48,7 +48,7 @@ if (! strlen($_GET["num"]))
   $pagenext = $page + 1;
 
   $sql = "SELECT distinct(b.num_releve) as numr";
-  $sql .= ' FROM llx_bank as b WHERE fk_account = '.$_GET["account"].' ORDER BY numr DESC';
+  $sql .= ' FROM ".MAIN_DB_PREFIX."bank as b WHERE fk_account = '.$_GET["account"].' ORDER BY numr DESC';
   $sql .= $db->plimit($limit + 1,$offset);
 
   $result = $db->query($sql);
@@ -85,7 +85,7 @@ else
    */
   if ($rel == 'prev')
     {
-      $sql = "SELECT distinct(num_releve) FROM llx_bank WHERE num_releve < ".$_GET["num"]." AND fk_account = $account ORDER BY num_releve DESC";
+      $sql = "SELECT distinct(num_releve) FROM ".MAIN_DB_PREFIX."bank WHERE num_releve < ".$_GET["num"]." AND fk_account = $account ORDER BY num_releve DESC";
       $result = $db->query($sql);
       if ($result)
 	{
@@ -101,7 +101,7 @@ else
     }
   elseif ($rel == 'next')
     {
-      $sql = "SELECT distinct(num_releve) FROM llx_bank WHERE num_releve > ".$_GET["num"]." AND fk_account = $account ORDER BY num_releve ASC";
+      $sql = "SELECT distinct(num_releve) FROM ".MAIN_DB_PREFIX."bank WHERE num_releve > ".$_GET["num"]." AND fk_account = $account ORDER BY num_releve ASC";
       $result = $db->query($sql);
       if ($result)
 	{
@@ -136,7 +136,7 @@ else
   print "</TR>\n";
  
 
-  $sql = "SELECT sum(amount) FROM llx_bank WHERE num_releve < ".$_GET["num"]." AND fk_account = ".$acct->id;
+  $sql = "SELECT sum(amount) FROM ".MAIN_DB_PREFIX."bank WHERE num_releve < ".$_GET["num"]." AND fk_account = ".$acct->id;
   if ( $db->query($sql) )
     {
       $total = $db->result (0, 0);
@@ -145,7 +145,7 @@ else
 
 
   $sql = "SELECT b.rowid,".$db->pdate("b.dateo")." as do, b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type";
-  $sql .= " FROM llx_bank as b WHERE num_releve=".$_GET["num"]." AND fk_account = ".$acct->id;
+  $sql .= " FROM ".MAIN_DB_PREFIX."bank as b WHERE num_releve=".$_GET["num"]." AND fk_account = ".$acct->id;
   $sql .= " ORDER BY dateo ASC";
   $result = $db->query($sql);
   if ($result)
@@ -171,7 +171,7 @@ else
 	  if ($ve)
 	    {
 	      $dc = $db->clone();
-	      $sql = "SELECT label FROM llx_bank_categ as ct, llx_bank_class as cl WHERE ct.rowid=cl.fk_categ AND cl.lineid=$objp->rowid";
+	      $sql = "SELECT label FROM ".MAIN_DB_PREFIX."bank_categ as ct, ".MAIN_DB_PREFIX."bank_class as cl WHERE ct.rowid=cl.fk_categ AND cl.lineid=$objp->rowid";
 	      $resc = $dc->query($sql);
 	      if ($resc)
 		{
diff --git a/htdocs/compta/bank/search.php b/htdocs/compta/bank/search.php
index 23e9bb1c158..c223baaec85 100644
--- a/htdocs/compta/bank/search.php
+++ b/htdocs/compta/bank/search.php
@@ -73,7 +73,7 @@ print "</TR>\n";
 </td>
 </tr>
 <?PHP
-$sql = "SELECT count(*) FROM llx_bank";
+$sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."bank";
 if ($account) { $sql .= " WHERE fk_account=$account"; }
 if ( $db->query($sql) )
 {
@@ -81,7 +81,7 @@ if ( $db->query($sql) )
   $db->free();    
 }
   
-$sql = "SELECT rowid, label FROM llx_bank_categ;";
+$sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."bank_categ;";
 $result = $db->query($sql);
 if ($result) {
   $var=True;  
@@ -96,7 +96,7 @@ if ($result) {
 }
 
 $sql = "SELECT b.rowid,".$db->pdate("b.dateo")." as do, b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_account, b.fk_type";
-$sql .= " FROM llx_bank as b "; 
+$sql .= " FROM ".MAIN_DB_PREFIX."bank as b "; 
 $sql .= " WHERE fk_type like '" . $type . "'";
 
 $si=0;
diff --git a/htdocs/compta/bank/virement.php b/htdocs/compta/bank/virement.php
index 0ed7a2c8516..63dacf4ed4b 100644
--- a/htdocs/compta/bank/virement.php
+++ b/htdocs/compta/bank/virement.php
@@ -31,7 +31,7 @@ if ($action == 'add')
 {
   $dateo = $reyear."-".$remonth."-".$reday;
 
-  $sql = "INSERT INTO llx_bank (datec, dateo, label, amount, fk_user_author,fk_account, fk_type)";
+  $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank (datec, dateo, label, amount, fk_user_author,fk_account, fk_type)";
   $sql .= " VALUES (now(), '$dateo', '$label', (0 - $amount),$user->id,$account_from, 'VIR')";
 
   $result = $db->query($sql);
@@ -41,7 +41,7 @@ if ($action == 'add')
       print "<p>$sql";
     }
 
-  $sql = "INSERT INTO llx_bank (datec, dateo, label, amount, fk_user_author,fk_account, fk_type)";
+  $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank (datec, dateo, label, amount, fk_user_author,fk_account, fk_type)";
   $sql .= " VALUES (now(), '$dateo', '$label', $amount,$user->id, $account_to, 'VIR')";
 
 
@@ -63,7 +63,7 @@ print '<table class="border" width="100%" cellspacing="0" cellpadding="2">';
 print "<tr $bc[1]><td>De</td><td>Vers</td><td>Date</td><td>Libelle</td><td>Montant</td></tr>";
 print "<tr $bc[1]><td>";
 print "<select name=\"account_from\">";
-$sql = "SELECT rowid, label FROM llx_bank_account";
+$sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."bank_account";
 $result = $db->query($sql);
 if ($result)
 {
@@ -81,7 +81,7 @@ if ($result)
 print "</select></td><td>\n";
 
 print "<select name=\"account_to\">";
-$sql = "SELECT rowid, label FROM llx_bank_account";
+$sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."bank_account";
 $result = $db->query($sql);
 if ($result)
 {
diff --git a/htdocs/compta/commande.php b/htdocs/compta/commande.php
index 050a679d43a..1c125c43cee 100644
--- a/htdocs/compta/commande.php
+++ b/htdocs/compta/commande.php
@@ -138,7 +138,7 @@ if ($_GET["id"] > 0)
       echo '<br><table border="0" width="100%" cellspacing="0" cellpadding="3">';	  
       
       $sql = "SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice";
-      $sql .= " FROM llx_commandedet as l WHERE l.fk_commande =".$commande->id." ORDER BY l.rowid";
+      $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as l WHERE l.fk_commande =".$commande->id." ORDER BY l.rowid";
       
       $result = $db->query($sql);
       if ($result)
@@ -257,7 +257,7 @@ if ($_GET["id"] > 0)
 	   * Factures associees
 	   */
 	  $sql = "SELECT f.facnumber, f.total,".$db->pdate("f.datef")." as df, f.rowid as facid, f.fk_user_author, f.paye";
-	  $sql .= " FROM llx_facture as f, llx_co_fa as fp WHERE fp.fk_facture = f.rowid AND fp.fk_commande = ".$commande->id;
+	  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."co_fa as fp WHERE fp.fk_facture = f.rowid AND fp.fk_commande = ".$commande->id;
 
 	  if ($db->query($sql) )
 	    {
diff --git a/htdocs/compta/config.php b/htdocs/compta/config.php
index fcfecd9048b..ea03d3ee9a0 100644
--- a/htdocs/compta/config.php
+++ b/htdocs/compta/config.php
@@ -49,7 +49,7 @@ if ($action == 'create') {
     print_barre_liste("Comptes comptable",$page,$PHP_SELF);
 
     $sql = "SELECT number, label";
-    $sql .= " FROM llx_compta_account";
+    $sql .= " FROM ".MAIN_DB_PREFIX."compta_account";
     $sql .= " ORDER BY number";
   
     $result = $db->query($sql);
diff --git a/htdocs/compta/index.php b/htdocs/compta/index.php
index 8af802d355d..3436c0393bb 100644
--- a/htdocs/compta/index.php
+++ b/htdocs/compta/index.php
@@ -209,7 +209,7 @@ print '</td><td valign="top" width="70%">';
  */
 if ($user->comm > 0 && $conf->commercial ) 
 {
-  $sql = "SELECT p.rowid, p.ref, s.nom, s.idp FROM llx_commande as p, llx_societe as s";
+  $sql = "SELECT p.rowid, p.ref, s.nom, s.idp FROM ".MAIN_DB_PREFIX."commande as p, ".MAIN_DB_PREFIX."societe as s";
   $sql .= " WHERE p.fk_soc = s.idp AND p.fk_statut >= 1 AND p.facture = 0";
   if ($socidp)
     {
@@ -244,7 +244,7 @@ if ($user->comm > 0 && $conf->commercial )
  * Factures impay�es
  */
 
-$sql = "SELECT f.facnumber, f.rowid, s.nom, s.idp, f.total_ttc FROM llx_facture as f, llx_societe as s WHERE s.idp = f.fk_soc AND f.paye = 0 AND f.fk_statut > 0";
+$sql = "SELECT f.facnumber, f.rowid, s.nom, s.idp, f.total_ttc FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s WHERE s.idp = f.fk_soc AND f.paye = 0 AND f.fk_statut > 0";
 if ($socidp)
 {
   $sql .= " AND f.fk_soc = $socidp";
@@ -314,7 +314,7 @@ if ( $result ) {
 if ($user->societe_id == 0)
 {
   $sql = "SELECT ff.total_ttc as amount, ff.libelle, ff.rowid";
-  $sql .= " FROM llx_facture_fourn as ff";
+  $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as ff";
   $sql .= " WHERE ff.paye=0";
   
   if ( $db->query($sql) ) 
diff --git a/htdocs/compta/ligne.php b/htdocs/compta/ligne.php
index 7f4eef7bf90..ef1d15b3ebd 100644
--- a/htdocs/compta/ligne.php
+++ b/htdocs/compta/ligne.php
@@ -24,7 +24,7 @@ require("./pre.inc.php");
 llxHeader();
 
 
-$sql = "SELECT rowid, number, label FROM llx_compta_account ORDER BY number";
+$sql = "SELECT rowid, number, label FROM ".MAIN_DB_PREFIX."compta_account ORDER BY number";
 if ( $db->query($sql) ) {
   $num = $db->num_rows();
   $i = 0;
@@ -42,7 +42,7 @@ if ( $db->query($sql) ) {
 
 if ($action == 'add') {
 
-  $sql = "INSERT INTO llx_compta (datec, fk_compta_account, label, amount)";
+  $sql = "INSERT INTO ".MAIN_DB_PREFIX."compta (datec, fk_compta_account, label, amount)";
   $sql .= " VALUES (now(),$number, '$label',$amount)";
 
   $db->query($sql);
@@ -89,7 +89,7 @@ if ($action == 'create') {
 
 
   $sql = "SELECT ca.number, c.label, c.amount";
-  $sql .= " FROM llx_compta_account as ca, llx_compta as c WHERE c.fk_compta_account = ca.rowid";
+  $sql .= " FROM ".MAIN_DB_PREFIX."compta_account as ca, ".MAIN_DB_PREFIX."compta as c WHERE c.fk_compta_account = ca.rowid";
   $sql .= " ORDER BY ca.number";
   
   $result = $db->query($sql);
diff --git a/htdocs/compta/pmt.php b/htdocs/compta/pmt.php
index f59e95340fb..bbb8a56a703 100644
--- a/htdocs/compta/pmt.php
+++ b/htdocs/compta/pmt.php
@@ -35,8 +35,8 @@ print "Point mort";
 if ($action == 'update') {
   $datepm = mktime(12, 0 , 0, $pmonth, 1, $pyear); 
 
-  $sql = "DELETE FROM llx_pointmort WHERE int(month) = $datepm ;";
-  $sql .= "INSERT INTO llx_pointmort VALUES ($datepm, $pm)";
+  $sql = "DELETE FROM ".MAIN_DB_PREFIX."pointmort WHERE int(month) = $datepm ;";
+  $sql .= "INSERT INTO ".MAIN_DB_PREFIX."pointmort VALUES ($datepm, $pm)";
   $result = $db->query($sql);
 }
 
@@ -45,7 +45,7 @@ if ($action == 'update') {
 print "<TABLE border=\"0\" cellspacing=\"0\" cellpadding=\"4\">";
 print "<tr><td valign=\"top\">";
 
-$sql = "SELECT amount, int(month) as dm FROM llx_pointmort ORDER BY month DESC";
+$sql = "SELECT amount, int(month) as dm FROM ".MAIN_DB_PREFIX."pointmort ORDER BY month DESC";
 
 $result = $db->query($sql);
 
diff --git a/htdocs/compta/pointmort.php b/htdocs/compta/pointmort.php
index 99877930b9d..fcc6b1fc2ca 100644
--- a/htdocs/compta/pointmort.php
+++ b/htdocs/compta/pointmort.php
@@ -42,7 +42,7 @@ function pt ($db, $sql) {
 }
 
 function pm ($db) {
-  $sql = "SELECT amount, date_format('%Y%m',month) as dm FROM llx_pointmort";
+  $sql = "SELECT amount, date_format('%Y%m',month) as dm FROM ".MAIN_DB_PREFIX."pointmort";
   $result = $db->query($sql);
   if ($result) {
     $num = $db->num_rows();
@@ -68,7 +68,7 @@ function pm ($db) {
 function ppt ($db) {
     
   $sql = "SELECT sum(f.amount), date_format(f.datef,'%Y%m') as dm";
-  $sql .= " FROM llx_facture as f WHERE f.paye = 1";
+  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f WHERE f.paye = 1";
   $sql .= " GROUP BY dm";
   
   $ca = pt($db, $sql);
diff --git a/htdocs/compta/propal.php b/htdocs/compta/propal.php
index 24884f56334..ebaaa116377 100644
--- a/htdocs/compta/propal.php
+++ b/htdocs/compta/propal.php
@@ -59,11 +59,11 @@ if ($action == 'setstatut')
 
 if ( $action == 'delete' )
 {
-  $sql = "DELETE FROM llx_propal WHERE rowid = $propalid;";
+  $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE rowid = $propalid;";
   if ( $db->query($sql) )
     {
 
-      $sql = "DELETE FROM llx_propaldet WHERE fk_propal = $propalid ;";
+      $sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE fk_propal = $propalid ;";
       if ( $db->query($sql) )
 	{
 	  print "<b><font color=\"red\">Propal supprim�e</font></b>";
@@ -205,7 +205,7 @@ if ($_GET["propalid"])
        * Factures associees
        */
       $sql = "SELECT f.facnumber, f.total,".$db->pdate("f.datef")." as df, f.rowid as facid, f.fk_user_author, f.paye";
-      $sql .= " FROM llx_facture as f, llx_fa_pr as fp WHERE fp.fk_facture = f.rowid AND fp.fk_propal = ".$propal->id;
+      $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."fa_pr as fp WHERE fp.fk_facture = f.rowid AND fp.fk_propal = ".$propal->id;
 
       $result = $db->query($sql);
       if ($result)
@@ -313,7 +313,7 @@ if ($_GET["propalid"])
     print '<td align="right">Prix</td><td align="center">Remise</td><td align="center">Qt�.</td></tr>';
     
     $sql = "SELECT pt.rowid, p.label as product, p.ref, pt.price, pt.qty, p.rowid as prodid, pt.remise_percent";
-    $sql .= " FROM llx_propaldet as pt, llx_product as p WHERE pt.fk_product = p.rowid AND pt.fk_propal =".$propal->id;
+    $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pt, ".MAIN_DB_PREFIX."product as p WHERE pt.fk_product = p.rowid AND pt.fk_propal =".$propal->id;
     $sql .= " ORDER BY pt.rowid ASC";
     if ($db->query($sql)) 
       {
@@ -334,7 +334,7 @@ if ($_GET["propalid"])
       }
 
     $sql = "SELECT pt.rowid, pt.description as product,  pt.price, pt.qty, pt.remise_percent";
-    $sql .= " FROM llx_propaldet as pt  WHERE  pt.fk_propal = ".$propal->id." AND pt.fk_product = 0";
+    $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pt  WHERE  pt.fk_propal = ".$propal->id." AND pt.fk_product = 0";
     $sql .= " ORDER BY pt.rowid ASC";
     if ($db->query($sql)) 
       {
diff --git a/htdocs/compta/tva.php b/htdocs/compta/tva.php
index 1d1ec3c8546..d88905ac455 100644
--- a/htdocs/compta/tva.php
+++ b/htdocs/compta/tva.php
@@ -79,7 +79,7 @@ for ($y = $yearc ; $y >= $conf->years ; $y=$y-1 ) {
   print "<tr><td valign=\"top\">";
 
   $sql = "SELECT sum(f.tva) as amount , date_format(f.datef,'%Y-%m') as dm";
-  $sql .= " FROM llx_facture as f WHERE f.paye = 1 AND f.datef >= '$y-01-01' AND f.datef <= '$y-12-31' ";
+  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f WHERE f.paye = 1 AND f.datef >= '$y-01-01' AND f.datef <= '$y-12-31' ";
   $sql .= " GROUP BY dm DESC";
   
   pt($db, $sql,"Ann�e $y");
diff --git a/htdocs/contact.class.php b/htdocs/contact.class.php
index 26a72b57b61..4de356ef46e 100644
--- a/htdocs/contact.class.php
+++ b/htdocs/contact.class.php
@@ -52,7 +52,7 @@ class Contact
 	$this->socid = 0;
       }
 
-    $sql = "INSERT INTO llx_socpeople (datec, fk_soc, name, fk_user) ";
+    $sql = "INSERT INTO ".MAIN_DB_PREFIX."socpeople (datec, fk_soc, name, fk_user) ";
     $sql .= " VALUES (now(),$this->socid,'$this->name',$user->id)";
 
     if ($this->db->query($sql) )
@@ -76,7 +76,7 @@ class Contact
     {
       $this->email = trim($this->email);
 
-      $sql = "UPDATE llx_socpeople SET name='$this->name', firstname='$this->firstname'";
+      $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET name='$this->name', firstname='$this->firstname'";
       $sql .= ", poste='$this->poste'";
       $sql .= ", fax='$this->fax'";
       $sql .= ", email='$this->email'";
@@ -202,7 +202,7 @@ class Contact
 	  if ($user)
 	    {
 	      $sql = "SELECT fk_user";
-	      $sql .= " FROM llx_birthday_alert";
+	      $sql .= " FROM ".MAIN_DB_PREFIX."birthday_alert";
 	      $sql .= " WHERE fk_user = $user->id AND fk_contact = $id";
 	      
 	      if ($this->db->query($sql)) 
@@ -231,7 +231,7 @@ class Contact
    */
   Function delete($id)
     {
-      $sql = "DELETE FROM llx_socpeople";
+      $sql = "DELETE FROM ".MAIN_DB_PREFIX."socpeople";
       $sql .= " WHERE idp=$id";
 
       $result = $this->db->query($sql);
diff --git a/htdocs/don.class.php b/htdocs/don.class.php
index d55877fb5d1..70eecd03329 100644
--- a/htdocs/don.class.php
+++ b/htdocs/don.class.php
@@ -171,7 +171,7 @@ class Don
 
       $this->date = $this->db->idate($this->date);
 
-      $sql = "INSERT INTO llx_don (datec, amount, fk_paiement,prenom, nom, societe,adresse, cp, ville, pays, public, fk_don_projet, note, fk_user_author, datedon, email)";
+      $sql = "INSERT INTO ".MAIN_DB_PREFIX."don (datec, amount, fk_paiement,prenom, nom, societe,adresse, cp, ville, pays, public, fk_don_projet, note, fk_user_author, datedon, email)";
       $sql .= " VALUES (now(), $this->amount, $this->modepaiementid,'$this->prenom','$this->nom','$this->societe','$this->adresse', '$this->cp','$this->ville','$this->pays',$this->public, $this->projetid, '$this->commentaire', $userid, '$this->date','$this->email')";
       
       $result = $this->db->query($sql);
@@ -198,7 +198,7 @@ class Don
       
       $this->date = $this->db->idate($this->date);
 
-      $sql = "UPDATE llx_don SET ";
+      $sql = "UPDATE ".MAIN_DB_PREFIX."don SET ";
       $sql .= "amount = " . $this->amount;
       $sql .= ",fk_paiement = ".$this->modepaiementid;
       $sql .= ",prenom = '".$this->prenom ."'";
@@ -239,7 +239,7 @@ class Don
 
   {
     
-    $sql = "DELETE FROM llx_don WHERE rowid = $rowid AND fk_statut = 0;";
+    $sql = "DELETE FROM ".MAIN_DB_PREFIX."don WHERE rowid = $rowid AND fk_statut = 0;";
 
     if ( $this->db->query( $sql) )
       {
@@ -266,7 +266,7 @@ class Don
   Function fetch($rowid)
   {
     $sql = "SELECT d.rowid, ".$this->db->pdate("d.datedon")." as datedon, d.prenom, d.nom, d.societe, d.amount, p.libelle as projet, d.fk_statut, d.adresse, d.cp, d.ville, d.pays, d.public, d.amount, d.fk_paiement, d.note, cp.libelle, d.email, d.fk_don_projet";
-    $sql .= " FROM llx_don as d, llx_don_projet as p, c_paiement as cp";
+    $sql .= " FROM ".MAIN_DB_PREFIX."don as d, ".MAIN_DB_PREFIX."don_projet as p, ".MAIN_DB_PREFIX."c_paiement as cp";
     $sql .= " WHERE p.rowid = d.fk_don_projet AND cp.id = d.fk_paiement AND d.rowid = $rowid";
 
     if ( $this->db->query( $sql) )
@@ -309,7 +309,7 @@ class Don
   Function valid_promesse($rowid, $userid)
   {
 
-    $sql = "UPDATE llx_don SET fk_statut = 1, fk_user_valid = $userid WHERE rowid = $rowid AND fk_statut = 0;";
+    $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 1, fk_user_valid = $userid WHERE rowid = $rowid AND fk_statut = 0;";
 
     if ( $this->db->query( $sql) )
       {
@@ -334,7 +334,7 @@ class Don
    */
   Function set_paye($rowid, $modepaiement='')
   {
-    $sql = "UPDATE llx_don SET fk_statut = 2";
+    $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 2";
 
     if ($modepaiement)
       {
@@ -365,7 +365,7 @@ class Don
    */
   Function set_commentaire($rowid, $commentaire='')
   {
-    $sql = "UPDATE llx_don SET note = '$commentaire'";
+    $sql = "UPDATE ".MAIN_DB_PREFIX."don SET note = '$commentaire'";
 
     $sql .=  " WHERE rowid = $rowid ;";
 
@@ -393,7 +393,7 @@ class Don
   Function set_encaisse($rowid)
   {
 
-    $sql = "UPDATE llx_don SET fk_statut = 3 WHERE rowid = $rowid AND fk_statut = 2;";
+    $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 3 WHERE rowid = $rowid AND fk_statut = 2;";
 
     if ( $this->db->query( $sql) )
       {
@@ -418,7 +418,7 @@ class Don
   Function sum_actual()
   {
     $sql = "SELECT sum(amount)";
-    $sql .= " FROM llx_don";
+    $sql .= " FROM ".MAIN_DB_PREFIX."don";
     $sql .= " WHERE fk_statut = 3";
 
     if ( $this->db->query( $sql) )
@@ -436,7 +436,7 @@ class Don
   Function sum_pending()
   {
     $sql = "SELECT sum(amount)";
-    $sql .= " FROM llx_don";
+    $sql .= " FROM ".MAIN_DB_PREFIX."don";
     $sql .= " WHERE fk_statut = 2";
 
     if ( $this->db->query( $sql) )
@@ -454,7 +454,7 @@ class Don
   Function sum_intent()
   {
     $sql = "SELECT sum(amount)";
-    $sql .= " FROM llx_don";
+    $sql .= " FROM ".MAIN_DB_PREFIX."don";
     $sql .= " WHERE fk_statut = 1";
 
     if ( $this->db->query( $sql) )
diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php
index 38d84409add..021832c4761 100644
--- a/htdocs/facture.class.php
+++ b/htdocs/facture.class.php
@@ -55,7 +55,7 @@ class Facture
       $this->db = $DB ;
       $this->socidp = $soc_idp;
       $this->products = array();
-      $this->db_table = "llx_facture";
+      $this->db_table = MAIN_DB_PREFIX."facture";
       $this->amount = 0;
       $this->remise = 0;
       $this->remise_percent = 0;
@@ -89,7 +89,7 @@ class Facture
 	  $this->remise_percent = $_facrec->remise_percent;
 	}
 
-      $sql = "SELECT fdm,nbjour FROM llx_cond_reglement WHERE rowid = $this->cond_reglement";
+      $sql = "SELECT fdm,nbjour FROM ".MAIN_DB_PREFIX."cond_reglement WHERE rowid = $this->cond_reglement";
       if ($this->db->query($sql) )
 	{
 	  if ($this->db->num_rows())
@@ -129,18 +129,18 @@ class Facture
 	{
 	  $this->id = $this->db->last_insert_id();
 
-	  $sql = "UPDATE llx_facture SET facnumber='(PROV".$this->id.")' WHERE rowid=".$this->id;
+	  $sql = "UPDATE ".MAIN_DB_PREFIX."facture SET facnumber='(PROV".$this->id.")' WHERE rowid=".$this->id;
 	  $this->db->query($sql);
 
 	  if ($this->id && $this->propalid)
 	    {
-	      $sql = "INSERT INTO llx_fa_pr (fk_facture, fk_propal) VALUES (".$this->id.",".$this->propalid.")";
+	      $sql = "INSERT INTO ".MAIN_DB_PREFIX."fa_pr (fk_facture, fk_propal) VALUES (".$this->id.",".$this->propalid.")";
 	      $this->db->query($sql);
 	    }
 
 	  if ($this->id && $this->commandeid)
 	    {
-	      $sql = "INSERT INTO llx_co_fa (fk_facture, fk_commande) VALUES (".$this->id.",".$this->commandeid.")";
+	      $sql = "INSERT INTO ".MAIN_DB_PREFIX."co_fa (fk_facture, fk_commande) VALUES (".$this->id.",".$this->commandeid.")";
 	      $this->db->query($sql);
 	    }
 
@@ -219,7 +219,7 @@ class Facture
     {
 
       $sql = "SELECT f.fk_soc,f.facnumber,f.amount,f.tva,f.total,f.total_ttc,f.remise,f.remise_percent,".$this->db->pdate("f.datef")."as df,f.fk_projet,".$this->db->pdate("f.date_lim_reglement")." as dlr, c.rowid as cond_regl_id, c.libelle, c.libelle_facture, f.note, f.paye, f.fk_statut, f.fk_user_author";
-      $sql .= " FROM llx_facture as f, llx_cond_reglement as c";
+      $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."cond_reglement as c";
       $sql .= " WHERE f.rowid=$rowid AND c.rowid = f.fk_cond_reglement";
       
       if ($societe_id > 0) 
@@ -267,7 +267,7 @@ class Facture
 	       */
 
 	      $sql = "SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_taux, l.remise_percent, l.subprice";
-	      $sql .= " FROM llx_facturedet as l WHERE l.fk_facture = ".$this->id;
+	      $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as l WHERE l.fk_facture = ".$this->id;
 	
 	      $result = $this->db->query($sql);
 	      if ($result)
@@ -329,7 +329,7 @@ class Facture
    */
   Function valid($userid, $dir)
     {
-      $sql = "UPDATE llx_facture SET fk_statut = 1, date_valid=now(), fk_user_valid=$userid";
+      $sql = "UPDATE ".MAIN_DB_PREFIX."facture SET fk_statut = 1, date_valid=now(), fk_user_valid=$userid";
       $sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
       
       if ($this->db->query($sql) )
@@ -348,7 +348,7 @@ class Facture
    */
   Function classin($cat_id)
     {
-      $sql = "UPDATE llx_facture SET fk_projet = $cat_id";
+      $sql = "UPDATE ".MAIN_DB_PREFIX."facture SET fk_projet = $cat_id";
       $sql .= " WHERE rowid = $this->id;";
       
       if ($this->db->query($sql) )
@@ -367,24 +367,24 @@ class Facture
    */
   Function delete($rowid)
     {
-      $sql = "DELETE FROM llx_facture_tva_sum WHERE fk_facture = $rowid;";
+      $sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_tva_sum WHERE fk_facture = $rowid;";
 
       if ( $this->db->query( $sql) )
 	{
-	  $sql = "DELETE FROM llx_fa_pr WHERE fk_facture = $rowid;";
+	  $sql = "DELETE FROM ".MAIN_DB_PREFIX."fa_pr WHERE fk_facture = $rowid;";
 
 	  if ($this->db->query( $sql) )
 	    {
 
-	      $sql = "DELETE FROM llx_co_fa WHERE fk_facture = $rowid;";
+	      $sql = "DELETE FROM ".MAIN_DB_PREFIX."co_fa WHERE fk_facture = $rowid;";
 	      
 	      if ($this->db->query( $sql) )
 		{
-		  $sql = "DELETE FROM llx_facturedet WHERE fk_facture = $rowid;";
+		  $sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet WHERE fk_facture = $rowid;";
 	      
 		  if ($this->db->query( $sql) )
 		    {
-		      $sql = "DELETE FROM llx_facture WHERE rowid = $rowid AND fk_statut = 0;";
+		      $sql = "DELETE FROM ".MAIN_DB_PREFIX."facture WHERE rowid = $rowid AND fk_statut = 0;";
 		      
 		      if ($this->db->query( $sql) )
 			{
@@ -428,7 +428,7 @@ class Facture
    */
   Function set_payed($rowid)
     {
-      $sql = "UPDATE llx_facture set paye = 1 WHERE rowid = $rowid ;";
+      $sql = "UPDATE ".MAIN_DB_PREFIX."facture set paye = 1 WHERE rowid = $rowid ;";
       $return = $this->db->query( $sql);
     }
   /**
@@ -443,7 +443,7 @@ class Facture
 
 	  $numfa = facture_get_num($soc); // d�finit dans includes/modules/facture
 
-	  $sql = "UPDATE llx_facture set facnumber='$numfa', fk_statut = 1, fk_user_valid = $user->id WHERE rowid = $rowid ;";
+	  $sql = "UPDATE ".MAIN_DB_PREFIX."facture set facnumber='$numfa', fk_statut = 1, fk_user_valid = $user->id WHERE rowid = $rowid ;";
 	  $result = $this->db->query( $sql);
 
 	  if (! $result) { print "Err : ".$this->db->error(); return -1; }
@@ -462,7 +462,7 @@ class Facture
 	   * Update Stats
 	   *
 	   */
-	  $sql = "SELECT fk_product FROM llx_facturedet WHERE fk_facture = ".$this->id;
+	  $sql = "SELECT fk_product FROM ".MAIN_DB_PREFIX."facturedet WHERE fk_facture = ".$this->id;
 	  $sql .= " AND fk_product > 0";
 	  
 	  $result = $this->db->query($sql);
@@ -475,7 +475,7 @@ class Facture
 		{
 		  $obj = $this->db->fetch_object($i);
 		  
-		  $sql = "UPDATE llx_product SET nbvente=nbvente+1 WHERE rowid = ".$obj->fk_product;
+		  $sql = "UPDATE ".MAIN_DB_PREFIX."product SET nbvente=nbvente+1 WHERE rowid = ".$obj->fk_product;
 		  $db2 = $this->db->clone();
 		  $result = $db2->query($sql);
 		  $i++;
@@ -529,7 +529,7 @@ class Facture
 	      $price = $pu - $remise;
 	    }
 
-	  $sql = "INSERT INTO llx_facturedet (fk_facture,description,price,qty,tva_taux, fk_product, remise_percent, subprice, remise)";
+	  $sql = "INSERT INTO ".MAIN_DB_PREFIX."facturedet (fk_facture,description,price,qty,tva_taux, fk_product, remise_percent, subprice, remise)";
 	  $sql .= " VALUES ($facid, '$desc', $price, $qty, $txtva, $fk_product, $remise_percent, $subprice, $remise) ;";
 
 	  if ( $this->db->query( $sql) )
@@ -569,7 +569,7 @@ class Facture
 	      $remise_percent=0;
 	    }
 
-	  $sql = "UPDATE llx_facturedet set description='$desc',price=$price,subprice=$subprice,remise=$remise,remise_percent=$remise_percent,qty=$qty WHERE rowid = $rowid ;";
+	  $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set description='$desc',price=$price,subprice=$subprice,remise=$remise,remise_percent=$remise_percent,qty=$qty WHERE rowid = $rowid ;";
 	  $result = $this->db->query( $sql);
 
 	  $this->updateprice($this->id);
@@ -583,7 +583,7 @@ class Facture
     {
       if ($this->brouillon)
 	{
-	  $sql = "DELETE FROM llx_facturedet WHERE rowid = $rowid;";
+	  $sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = $rowid;";
 	  $result = $this->db->query( $sql);
 
 	  $this->updateprice($this->id);
@@ -597,7 +597,7 @@ class Facture
     {
       include_once DOL_DOCUMENT_ROOT . "/lib/price.lib.php";
       $err=0;
-      $sql = "SELECT price, qty, tva_taux FROM llx_facturedet WHERE fk_facture = $facid;";
+      $sql = "SELECT price, qty, tva_taux FROM ".MAIN_DB_PREFIX."facturedet WHERE fk_facture = $facid;";
   
       $result = $this->db->query($sql);
 
@@ -632,19 +632,19 @@ class Facture
 	   *
 	   */
 
-	  $sql = "UPDATE llx_facture SET amount = $this->amount_ht, remise=$this->total_remise,  total=$this->total_ht, tva=$this->total_tva, total_ttc=$this->total_ttc";
+	  $sql = "UPDATE ".MAIN_DB_PREFIX."facture SET amount = $this->amount_ht, remise=$this->total_remise,  total=$this->total_ht, tva=$this->total_tva, total_ttc=$this->total_ttc";
 	  $sql .= " WHERE rowid = $facid ;";
 	  
 	  if ( $this->db->query($sql) )
 	    {
 	      
-	      $sql = "DELETE FROM llx_facture_tva_sum WHERE fk_facture=".$this->id;
+	      $sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_tva_sum WHERE fk_facture=".$this->id;
 
 	      if ( $this->db->query($sql) )
 		{
 		  foreach ($tvas as $key => $value)
 		    {
-		      $sql = "REPLACE INTO llx_facture_tva_sum SET fk_facture=".$this->id;
+		      $sql = "REPLACE INTO ".MAIN_DB_PREFIX."facture_tva_sum SET fk_facture=".$this->id;
 		      $sql .= ", amount = ".$tvas[$key];
 		      $sql .= ", tva_tx=".$key;
 		      
@@ -692,7 +692,7 @@ class Facture
 
 	  $this->remise_percent = $remise ;
 
-	  $sql = "UPDATE llx_facture SET remise_percent = ".ereg_replace(",",".",$remise);
+	  $sql = "UPDATE ".MAIN_DB_PREFIX."facture SET remise_percent = ".ereg_replace(",",".",$remise);
 	  $sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
 	  
 	  if ($this->db->query($sql) )
@@ -746,7 +746,7 @@ class Facture
 		  
 		  $sendto = htmlentities($sendto);
 		  
-		  $sql = "INSERT INTO llx_actioncomm (datea,fk_action,fk_soc,note,fk_facture, fk_contact,fk_user_author, label, percent) VALUES (now(), 10 ,$this->socidp ,'Relance envoy�e � $sendto',$this->id, $sendtoid, $user->id, 'Relance Facture par mail',100);";
+		  $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm (datea,fk_action,fk_soc,note,fk_facture, fk_contact,fk_user_author, label, percent) VALUES (now(), 10 ,$this->socidp ,'Relance envoy�e � $sendto',$this->id, $sendtoid, $user->id, 'Relance Facture par mail',100);";
 		  
 		  if (! $this->db->query($sql) )
 		    {
@@ -771,7 +771,7 @@ class Facture
    */
   Function getSumTva()
   {
-    $sql = "SELECT amount, tva_tx FROM llx_facture_tva_sum WHERE fk_facture = ".$this->id;
+    $sql = "SELECT amount, tva_tx FROM ".MAIN_DB_PREFIX."facture_tva_sum WHERE fk_facture = ".$this->id;
     if ($this->db->query($sql))
       {
 	$num = $this->db->num_rows();
@@ -796,7 +796,7 @@ class Facture
    */
   Function getSommePaiement()
   {
-    $sql = "SELECT sum(amount) FROM llx_paiement WHERE fk_facture = ".$this->id;
+    $sql = "SELECT sum(amount) FROM ".MAIN_DB_PREFIX."paiement WHERE fk_facture = ".$this->id;
     if ($this->db->query($sql))
       {
 	$row = $this->db->fetch_row(0);
diff --git a/htdocs/facturefourn.class.php b/htdocs/facturefourn.class.php
index d15fcbca730..eef29b13dac 100644
--- a/htdocs/facturefourn.class.php
+++ b/htdocs/facturefourn.class.php
@@ -51,7 +51,7 @@ class FactureFourn
     $this->db = $DB ;
     $this->socidp = $soc_idp;
     $this->products = array();
-    $this->db_table = "llx_facture";
+    $this->db_table = MAIN_DB_PREFIX."facture";
     $this->amount = 0;
     $this->remise = 0;
     $this->tva = 0;
@@ -81,7 +81,7 @@ class FactureFourn
 	for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
 	  {	 
 
-	    $sql = "INSERT INTO llx_facture_fourn_det (fk_facture_fourn)";
+	    $sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_fourn_det (fk_facture_fourn)";
 	    $sql .= " VALUES ($this->id);";
 	    if ($this->db->query($sql) ) 
 	      {
@@ -118,7 +118,7 @@ class FactureFourn
     $totalttc = $totalht + $tva;
 
 
-    $sql = "UPDATE llx_facture_fourn_det ";
+    $sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn_det ";
     $sql .= "SET description ='".$label."'";
     $sql .= ", pu_ht = " . $puht;
     $sql .= ", qty =".$qty;
@@ -140,7 +140,7 @@ class FactureFourn
   Function delete_ligne($id)
   {
 
-    $sql = "DELETE FROM llx_facture_fourn_det ";
+    $sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_fourn_det ";
     $sql .= " WHERE rowid = $id";
 
     if (! $this->db->query($sql) ) 
@@ -174,7 +174,7 @@ class FactureFourn
     $tva = tva($totalht);
     $total = $totalht + $tva;
     
-    $sql = "INSERT INTO llx_facture_fourn (facnumber, libelle, fk_soc, datec, datef, note, fk_user_author) ";
+    $sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_fourn (facnumber, libelle, fk_soc, datec, datef, note, fk_user_author) ";
     $sql .= " VALUES ('".$this->number."','".$this->libelle."',". $this->socid.", now(),".$this->date.",'".$this->note."', ".$user->id.");";
 
     if ( $this->db->query($sql) )
@@ -184,7 +184,7 @@ class FactureFourn
 	for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
 	  {	 
 
-	    $sql = "INSERT INTO llx_facture_fourn_det (fk_facture_fourn)";
+	    $sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_fourn_det (fk_facture_fourn)";
 	    $sql .= " VALUES ($this->id);";
 	    if ($this->db->query($sql) ) 
 	      {
@@ -222,7 +222,7 @@ class FactureFourn
 
       $sql = "SELECT fk_soc,libelle,facnumber,amount,remise,".$this->db->pdate(datef)."as df";
       $sql .= ", total_ht, total_tva, total_ttc, fk_user_author";
-      $sql .= " FROM llx_facture_fourn as f WHERE f.rowid=$rowid;";
+      $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f WHERE f.rowid=$rowid;";
       
       if ($this->db->query($sql) )
 	{
@@ -249,7 +249,7 @@ class FactureFourn
 	      /* 
 	       * Lignes
 	       */
-	      $sql = "SELECT rowid,description, pu_ht, qty, tva_taux, tva, total_ht, total_ttc FROM llx_facture_fourn_det WHERE fk_facture_fourn=".$this->id;
+	      $sql = "SELECT rowid,description, pu_ht, qty, tva_taux, tva, total_ht, total_ttc FROM ".MAIN_DB_PREFIX."facture_fourn_det WHERE fk_facture_fourn=".$this->id;
       
 	      if ($this->db->query($sql) )
 		{
@@ -290,7 +290,7 @@ class FactureFourn
    */
   Function valid($userid, $dir)
     {
-      $sql = "UPDATE llx_facture SET fk_statut = 1, date_valid=now(), fk_user_valid=$userid";
+      $sql = "UPDATE ".MAIN_DB_PREFIX."facture SET fk_statut = 1, date_valid=now(), fk_user_valid=$userid";
       $sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
       
       if ($this->db->query($sql) )
@@ -310,13 +310,13 @@ class FactureFourn
   Function delete($rowid)
     {
 
-      $sql = "DELETE FROM llx_facture_fourn WHERE rowid = $rowid AND fk_statut = 0";
+      $sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_fourn WHERE rowid = $rowid AND fk_statut = 0";
 
       if ( $this->db->query( $sql) )
 	{
 	  if ( $this->db->affected_rows() )
 	    {
-	      $sql = "DELETE FROM llx_facture_fourn_det WHERE fk_facture_fourn = $rowid;";
+	      $sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_fourn_det WHERE fk_facture_fourn = $rowid;";
 
 	      if ($this->db->query( $sql) )
 		{
@@ -342,7 +342,7 @@ class FactureFourn
    */
   Function set_payed($rowid)
     {
-      $sql = "UPDATE llx_facture set paye = 1 WHERE rowid = $rowid ;";
+      $sql = "UPDATE ".MAIN_DB_PREFIX."facture set paye = 1 WHERE rowid = $rowid ;";
       $return = $this->db->query( $sql);
     }
   /*
@@ -355,7 +355,7 @@ class FactureFourn
     {
       global $conf;
 
-      $sql = "UPDATE llx_facture set fk_statut = 1, fk_user_valid = $userid WHERE rowid = $rowid ;";
+      $sql = "UPDATE ".MAIN_DB_PREFIX."facture set fk_statut = 1, fk_user_valid = $userid WHERE rowid = $rowid ;";
       $result = $this->db->query( $sql);
 
       $dir = $conf->facture->outputdir . "/" . $rowid;
@@ -376,7 +376,7 @@ class FactureFourn
    */
   Function addline($facid, $desc, $pu, $qty)
     {
-      $sql = "INSERT INTO llx_facturedet (fk_facture,description,price,qty) VALUES ($facid, '$desc', $pu, $qty) ;";
+      $sql = "INSERT INTO ".MAIN_DB_PREFIX."facturedet (fk_facture,description,price,qty) VALUES ($facid, '$desc', $pu, $qty) ;";
       $result = $this->db->query( $sql);
 
       $this->updateprice($facid);
@@ -387,7 +387,7 @@ class FactureFourn
    */
   Function updateline($rowid, $desc, $pu, $qty)
     {
-      $sql = "UPDATE llx_facturedet set description='$desc',price=$pu,qty=$qty WHERE rowid = $rowid ;";
+      $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set description='$desc',price=$pu,qty=$qty WHERE rowid = $rowid ;";
       $result = $this->db->query( $sql);
 
       $this->updateprice($this->id);
@@ -398,7 +398,7 @@ class FactureFourn
    */
   Function deleteline($rowid)
     {
-      $sql = "DELETE FROM llx_facturedet WHERE rowid = $rowid;";
+      $sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = $rowid;";
       $result = $this->db->query( $sql);
 
       $this->updateprice($this->id);
@@ -410,7 +410,7 @@ class FactureFourn
   Function updateprice($facid)
     {
 
-      $sql = "SELECT sum(total_ht), sum(tva), sum(total_ttc) FROM llx_facture_fourn_det";
+      $sql = "SELECT sum(total_ht), sum(tva), sum(total_ttc) FROM ".MAIN_DB_PREFIX."facture_fourn_det";
       $sql .= " WHERE fk_facture_fourn = $facid;";
   
       $result = $this->db->query($sql);
@@ -425,7 +425,7 @@ class FactureFourn
 	      $total_ttc = $row[2];
 	    }
 	  
-	  $sql = "UPDATE llx_facture_fourn SET total_ht = $total_ht, total_tva = $total_tva, total_ttc = $total_ttc";
+	  $sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn SET total_ht = $total_ht, total_tva = $total_tva, total_ttc = $total_ttc";
 	  $sql .= " WHERE rowid = $facid ;";
 	  
 	  $result = $this->db->query($sql);
diff --git a/htdocs/index.php b/htdocs/index.php
index 132947ca353..e4678e02d6a 100644
--- a/htdocs/index.php
+++ b/htdocs/index.php
@@ -33,7 +33,7 @@ print "<br>";
  */
 $user->getrights('');
 
-$sql = "SELECT b.rowid, b.box_id, d.file FROM llx_boxes as b, llx_boxes_def as d WHERE b.box_id = d.rowid";
+$sql = "SELECT b.rowid, b.box_id, d.file FROM ".MAIN_DB_PREFIX."boxes as b, ".MAIN_DB_PREFIX."boxes_def as d WHERE b.box_id = d.rowid";
 $result = $db->query($sql);
 if ($result) 
 {
diff --git a/htdocs/install.php b/htdocs/install.php
index 7d633225eb8..b8645a5eb5b 100644
--- a/htdocs/install.php
+++ b/htdocs/install.php
@@ -114,21 +114,21 @@ if ($HTTP_POST_VARS["action"] == "set")
       $conf->db->pass = $dolibarr_main_db_pass;
       $db = new DoliDb();
 
-      $sql[0] = "REPLACE INTO llx_const SET name = 'FAC_OUTPUTDIR', value='".$dolibarr_main_document_root."/document/facture', visible=0, type='chaine'";
+      $sql[0] = "REPLACE INTO ".MAIN_DB_PREFIX."const SET name = 'FAC_OUTPUTDIR', value='".$dolibarr_main_document_root."/document/facture', visible=0, type='chaine'";
 
-      $sql[1] = "REPLACE INTO llx_const SET name = 'FAC_OUTPUT_URL', value='".$dolibarr_main_url_root."/document/facture', visible=0, type='chaine'";
+      $sql[1] = "REPLACE INTO ".MAIN_DB_PREFIX."const SET name = 'FAC_OUTPUT_URL', value='".$dolibarr_main_url_root."/document/facture', visible=0, type='chaine'";
 
-      $sql[2] = "REPLACE INTO llx_const SET name = 'PROPALE_OUTPUTDIR', value='".$dolibarr_main_document_root."/document/propale', visible=0, type='chaine'";
+      $sql[2] = "REPLACE INTO ".MAIN_DB_PREFIX."const SET name = 'PROPALE_OUTPUTDIR', value='".$dolibarr_main_document_root."/document/propale', visible=0, type='chaine'";
 
-      $sql[3] = "REPLACE INTO llx_const SET name = 'PROPALE_OUTPUT_URL', value='".$dolibarr_main_url_root."/document/propale', visible=0, type='chaine'";
+      $sql[3] = "REPLACE INTO ".MAIN_DB_PREFIX."const SET name = 'PROPALE_OUTPUT_URL', value='".$dolibarr_main_url_root."/document/propale', visible=0, type='chaine'";
 
-      $sql[4] = "REPLACE INTO llx_const SET name = 'FICHEINTER_OUTPUTDIR', value='".$dolibarr_main_document_root."/document/ficheinter', visible=0, type='chaine'";
+      $sql[4] = "REPLACE INTO ".MAIN_DB_PREFIX."const SET name = 'FICHEINTER_OUTPUTDIR', value='".$dolibarr_main_document_root."/document/ficheinter', visible=0, type='chaine'";
 
-      $sql[5] = "REPLACE INTO llx_const SET name = 'FICHEINTER_OUTPUT_URL', value='".$dolibarr_main_url_root."/document/ficheinter', visible=0, type='chaine'";
+      $sql[5] = "REPLACE INTO ".MAIN_DB_PREFIX."const SET name = 'FICHEINTER_OUTPUT_URL', value='".$dolibarr_main_url_root."/document/ficheinter', visible=0, type='chaine'";
 
-      $sql[6] = "REPLACE INTO llx_const SET name = 'SOCIETE_OUTPUTDIR', value='".$dolibarr_main_document_root."/document/societe', visible=0, type='chaine'";
+      $sql[6] = "REPLACE INTO ".MAIN_DB_PREFIX."const SET name = 'SOCIETE_OUTPUTDIR', value='".$dolibarr_main_document_root."/document/societe', visible=0, type='chaine'";
 
-      $sql[7] = "REPLACE INTO llx_const SET name = 'SOCIETE_OUTPUT_URL', value='".$dolibarr_main_url_root."/document/societe', visible=0, type='chaine'";
+      $sql[7] = "REPLACE INTO ".MAIN_DB_PREFIX."const SET name = 'SOCIETE_OUTPUT_URL', value='".$dolibarr_main_url_root."/document/societe', visible=0, type='chaine'";
       $result = 0;
       for ($i=0; $i < sizeof($sql);$i++)
 	{
@@ -152,7 +152,7 @@ if ($HTTP_POST_VARS["action"] == "set")
 	  if ($error == 0)
 	    {
 
-	      $db->query("DELETE FROM llx_const WHERE name='MAIN_NOT_INSTALLED'");
+	      $db->query("DELETE FROM ".MAIN_DB_PREFIX."const WHERE name='MAIN_NOT_INSTALLED'");
 
 
 print '<div class="main">
diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php
index ad378d130c9..58682ab749c 100644
--- a/htdocs/main.inc.php
+++ b/htdocs/main.inc.php
@@ -52,7 +52,7 @@ require (DOL_DOCUMENT_ROOT."/conf/conf.class.php");
  * Doit figurer apr�s l'inclusion de conf.class.php pour overider certaines variables, � terme conf.class.php devra etre un fichier qui ne sera pas modifi� par l'utilisateur
  */
 $conf = new Conf();
-if (!strlen(getenv("LLX_DBNAME")))
+if (!strlen(getenv("".MAIN_DB_PREFIX."DBNAME")))
 {
   $conf->db->host = $dolibarr_main_db_host;
   $conf->db->name = $dolibarr_main_db_name;
@@ -93,7 +93,7 @@ else
 
       $params = array(
 		      "dsn" => $conf->db->getdsn(),
-		      "table" => "llx_user",
+		      "table" => MAIN_DB_PREFIX."user",
 		      "usernamecol" => "login",
 		      "passwordcol" => "pass",
 		      "cryptType" => "none",
@@ -131,7 +131,7 @@ define('FPDF_FONTPATH',DOL_DOCUMENT_ROOT .'/includes/fpdf/font/');
  * Definition de toutes les Constantes globales d'environement
  *
  */
-$sql = "SELECT name, value FROM llx_const";
+$sql = "SELECT name, value FROM ".MAIN_DB_PREFIX."const";
 $result = $db->query($sql);
 if ($result) 
 {
diff --git a/htdocs/notify.class.php b/htdocs/notify.class.php
index 40dc1bbb827..b948b530ed8 100644
--- a/htdocs/notify.class.php
+++ b/htdocs/notify.class.php
@@ -46,7 +46,7 @@ class Notify
   Function send($action, $socid, $texte, $objet_type, $objet_id, $file="")
     {
       $sql = "SELECT s.nom, c.email, c.idp, c.name, c.firstname, a.titre,n.rowid";
-      $sql .= " FROM llx_socpeople as c, llx_action_def as a, llx_notify_def as n, llx_societe as s";
+      $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c, ".MAIN_DB_PREFIX."action_def as a, ".MAIN_DB_PREFIX."notify_def as n, ".MAIN_DB_PREFIX."societe as s";
       $sql .= " WHERE n.fk_contact = c.idp AND a.rowid = n.fk_action";
       $sql .= " AND n.fk_soc = s.idp AND n.fk_action = ".$action;
       $sql .= " AND s.idp = ".$socid;
@@ -79,7 +79,7 @@ class Notify
 		    {
 		      $sendto = htmlentities($sendto);
 	      
-		      $sql = "INSERT INTO llx_notify (daten, fk_action, fk_contact, objet_type, objet_id)";
+		      $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_contact, objet_type, objet_id)";
 		      $sql .= " VALUES (now(), $action ,$obj->idp , '$objet_type', $objet_id);";
 		      $db2 = $this->db->clone();
 		      if (! $db2->query($sql) )
diff --git a/htdocs/paiement.class.php b/htdocs/paiement.class.php
index 275a3c252b6..0e82bc07812 100644
--- a/htdocs/paiement.class.php
+++ b/htdocs/paiement.class.php
@@ -54,7 +54,7 @@ class Paiement
     
     $this->amount = ereg_replace(",",".",$this->amount);
 
-    $sql = "INSERT INTO llx_paiement (fk_facture, datec, datep, amount, author, fk_paiement, num_paiement, note)";
+    $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement (fk_facture, datec, datep, amount, author, fk_paiement, num_paiement, note)";
     $sql .= " VALUES ($this->facid, now(), $this->datepaye,$this->amount,'$this->author', $this->paiementid, '$this->num_paiement', '$this->note')";
     
     $result = $this->db->query($sql);
@@ -100,8 +100,8 @@ class Paiement
    */
   Function delete()
   {
-    $sql = "SELECT llx_paiement.rowid FROM llx_facture, llx_paiement WHERE  llx_paiement.rowid = ".$this->id;
-    $sql .= " AND llx_paiement.fk_facture = llx_facture.rowid AND llx_facture.paye = 0";
+    $sql = "SELECT ".MAIN_DB_PREFIX."paiement.rowid FROM ".MAIN_DB_PREFIX."facture, ".MAIN_DB_PREFIX."paiement WHERE  ".MAIN_DB_PREFIX."paiement.rowid = ".$this->id;
+    $sql .= " AND ".MAIN_DB_PREFIX."paiement.fk_facture = ".MAIN_DB_PREFIX."facture.rowid AND ".MAIN_DB_PREFIX."facture.paye = 0";
 
     $result = $this->db->query($sql);
     
@@ -109,7 +109,7 @@ class Paiement
       {
 	if ($this->db->num_rows() == 1)
 	  {
-	    $sql = "DELETE FROM llx_paiement WHERE llx_paiement.rowid = ".$this->id;
+	    $sql = "DELETE FROM ".MAIN_DB_PREFIX."paiement WHERE ".MAIN_DB_PREFIX."paiement.rowid = ".$this->id;
 
 	    $result = $this->db->query($sql);
 	    
diff --git a/htdocs/product.class.php b/htdocs/product.class.php
index e60be36eec1..52ec5192489 100644
--- a/htdocs/product.class.php
+++ b/htdocs/product.class.php
@@ -71,7 +71,7 @@ class Product
   Function create($user) 
     {
       $sql = "SELECT count(*)";
-      $sql .= " FROM llx_product WHERE ref = '" .trim($this->ref)."'";
+      $sql .= " FROM ".MAIN_DB_PREFIX."product WHERE ref = '" .trim($this->ref)."'";
 
       $result = $this->db->query($sql) ;
 
@@ -87,7 +87,7 @@ class Product
 		}
 	      $this->price = round($this->price, 2);
 	      
-	      $sql = "INSERT INTO llx_product (datec, fk_user_author, fk_product_type, price)";
+	      $sql = "INSERT INTO ".MAIN_DB_PREFIX."product (datec, fk_user_author, fk_product_type, price)";
 	      $sql .= " VALUES (now(),".$user->id.",$this->type, " . ereg_replace(",",".",$this->price) . ")";
 	      $result = $this->db->query($sql);
 	      if ( $result )
@@ -129,7 +129,7 @@ class Product
 	  $this->libelle = 'LIBELLE MANQUANT';
 	}
       
-      $sql = "UPDATE llx_product ";
+      $sql = "UPDATE ".MAIN_DB_PREFIX."product ";
       $sql .= " SET label = '" . trim($this->libelle) ."'";
       if (strlen(trim($this->ref)))
 	{
@@ -159,7 +159,7 @@ class Product
   Function _log_price($user) 
     {
 
-      $sql = "REPLACE INTO llx_product_price ";
+      $sql = "REPLACE INTO ".MAIN_DB_PREFIX."product_price ";
       $sql .= " SET date_price= now()";
       $sql .= " ,fk_product = ".$this->id;
       $sql .= " ,fk_user_author = ".$user->id;
@@ -186,7 +186,7 @@ class Product
 	{
 	  $this->price = round($this->price, 2);
 
-	  $sql = "UPDATE llx_product ";
+	  $sql = "UPDATE ".MAIN_DB_PREFIX."product ";
 	  $sql .= " SET price = " . ereg_replace(",",".",$this->price);	  
 	  $sql .= " WHERE rowid = " . $id;
 	  
@@ -216,7 +216,7 @@ class Product
   Function fetch ($id)
     {    
       $sql = "SELECT rowid, ref, label, description, price, tva_tx, envente, nbvente, fk_product_type, duration, seuil_stock_alerte";
-      $sql .= " FROM llx_product WHERE rowid = $id";
+      $sql .= " FROM ".MAIN_DB_PREFIX."product WHERE rowid = $id";
 
       $result = $this->db->query($sql) ;
 
@@ -244,7 +244,7 @@ class Product
 
 
 	  $sql = "SELECT reel, fk_entrepot";
-	  $sql .= " FROM llx_product_stock WHERE fk_product = $id";
+	  $sql .= " FROM ".MAIN_DB_PREFIX."product_stock WHERE fk_product = $id";
 	  $result = $this->db->query($sql) ;
 	  if ( $result )
 	    {
@@ -286,7 +286,7 @@ class Product
   Function count_propale()
     {
       $sql = "SELECT pd.fk_propal";
-      $sql .= " FROM llx_propaldet as pd, llx_product as p";
+      $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pd, ".MAIN_DB_PREFIX."product as p";
       $sql .= " WHERE p.rowid = pd.fk_product AND p.rowid = ".$this->id;
       $sql .= " GROUP BY pd.fk_propal";
 
@@ -308,7 +308,7 @@ class Product
   Function count_propale_client()
     {
       $sql = "SELECT pr.fk_soc";
-      $sql .= " FROM llx_propaldet as pd, llx_product as p, llx_propal as pr";
+      $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pd, ".MAIN_DB_PREFIX."product as p, ".MAIN_DB_PREFIX."propal as pr";
       $sql .= " WHERE p.rowid = pd.fk_product AND pd.fk_propal = pr.rowid AND p.rowid = ".$this->id;
       $sql .= " GROUP BY pr.fk_soc";
 
@@ -330,7 +330,7 @@ class Product
   Function count_facture()
     {
       $sql = "SELECT pd.fk_facture";
-      $sql .= " FROM llx_facturedet as pd, llx_product as p";
+      $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as pd, ".MAIN_DB_PREFIX."product as p";
       $sql .= " WHERE p.rowid = pd.fk_product AND p.rowid = ".$this->id;
       $sql .= " GROUP BY pd.fk_facture";
 
@@ -403,7 +403,7 @@ class Product
   Function get_nb_vente()
     {
       $sql = "SELECT sum(d.qty), date_format(f.datef, '%Y%m') ";
-      $sql .= " FROM llx_facturedet as d, llx_facture as f";
+      $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as d, ".MAIN_DB_PREFIX."facture as f";
       $sql .= " WHERE f.rowid = d.fk_facture and f.paye = 1 and d.fk_product =".$this->id;
       $sql .= " GROUP BY date_format(f.datef,'%Y%m') DESC ;";
 
@@ -416,7 +416,7 @@ class Product
   Function get_num_vente()
     {
       $sql = "SELECT count(*), date_format(f.datef, '%Y%m') ";
-      $sql .= " FROM llx_facturedet as d, llx_facture as f";
+      $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as d, ".MAIN_DB_PREFIX."facture as f";
       $sql .= " WHERE f.rowid = d.fk_facture and f.paye = 1 and d.fk_product =".$this->id;
       $sql .= " GROUP BY date_format(f.datef,'%Y%m') DESC ;";
 
@@ -428,7 +428,7 @@ class Product
    */
   Function add_fournisseur($user, $id_fourn, $ref_fourn) 
     {
-      $sql = "SELECT count(*) FROM llx_product_fournisseur WHERE fk_product = $this->id AND fk_soc = $id_fourn";
+      $sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."product_fournisseur WHERE fk_product = $this->id AND fk_soc = $id_fourn";
 
       if ($this->db->query($sql) )
 	{
@@ -437,7 +437,7 @@ class Product
 	  if ($row[0] == 0)
 	    {
 
-	      $sql = "INSERT INTO llx_product_fournisseur ";
+	      $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur ";
 	      $sql .= " (datec, fk_product, fk_soc, ref_fourn, fk_user_author)";
 	      $sql .= " VALUES (now(), $this->id, $id_fourn, '$ref_fourn', $user->id)";
 	      
@@ -469,7 +469,7 @@ class Product
   Function create_stock($id_entrepot, $nbpiece)
   {
     
-    $sql = "INSERT INTO llx_product_stock ";
+    $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_stock ";
     $sql .= " (fk_product, fk_entrepot, reel)";
     $sql .= " VALUES ($this->id, $id_entrepot, $nbpiece)";
     
@@ -490,7 +490,7 @@ class Product
   Function correct_stock($user, $id_entrepot, $nbpiece, $mouvement)
   {
 
-    $sql = "SELECT count(*) FROM llx_product_stock ";
+    $sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."product_stock ";
     $sql .= " WHERE fk_product = $this->id AND fk_entrepot = $id_entrepot";
     
     if ($this->db->query($sql) )
@@ -527,19 +527,19 @@ class Product
     if ($this->db->begin())
       {
 
-	$sql = "UPDATE llx_product ";
+	$sql = "UPDATE ".MAIN_DB_PREFIX."product ";
 	$sql .= " SET stock_commande = stock_commande ".$op[$mouvement].", stock_propale = stock_propale ".$op[$mouvement];
 	$sql .= " WHERE rowid = $this->id ";
 	
 	if ($this->db->query($sql) )
 	  {	    
-	    $sql = "UPDATE llx_product_stock ";
+	    $sql = "UPDATE ".MAIN_DB_PREFIX."product_stock ";
 	    $sql .= " SET reel = reel ".$op[$mouvement];
 	    $sql .= " WHERE fk_product = $this->id AND fk_entrepot = $id_entrepot";
 	    
 	    if ($this->db->query($sql) )
 	      {		
-		$sql = "INSERT INTO llx_stock_mouvement (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author)";
+		$sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author)";
 		$sql .= " VALUES (now(), $this->id, $id_entrepot, ".$op[$mouvement].", 0, $user->id)";
 		
 		if ($this->db->query($sql) )
diff --git a/htdocs/project.class.php b/htdocs/project.class.php
index f9acb7d9d96..2d660f2a799 100644
--- a/htdocs/project.class.php
+++ b/htdocs/project.class.php
@@ -39,7 +39,7 @@ class Project {
 
   Function create($creatorid) {
 
-    $sql = "INSERT INTO llx_projet (ref, title, fk_soc, fk_user_creat) ";
+    $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet (ref, title, fk_soc, fk_user_creat) ";
     $sql .= " VALUES ('$this->ref', '$this->title', $this->socidp, $creatorid) ;";
     
     if (!$this->db->query($sql) ) 
@@ -57,7 +57,7 @@ class Project {
 
   Function fetch($rowid) {
 
-    $sql = "SELECT title, ref FROM llx_projet WHERE rowid=$rowid;";
+    $sql = "SELECT title, ref FROM ".MAIN_DB_PREFIX."projet WHERE rowid=$rowid;";
 
     if ($this->db->query($sql) ) {
       if ($this->db->num_rows()) {
@@ -81,7 +81,7 @@ class Project {
   Function get_propal_list()
     {
       $propales = array();
-      $sql = "SELECT rowid FROM llx_propal WHERE fk_projet=$this->id;";
+      $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."propal WHERE fk_projet=$this->id;";
       
       if ($this->db->query($sql) )
 	{
@@ -118,7 +118,7 @@ class Project {
     {
       $projets = array();
 
-      $sql = "SELECT rowid, title FROM llx_projet";
+      $sql = "SELECT rowid, title FROM ".MAIN_DB_PREFIX."projet";
 
       if (isset($id_societe))
 	{
diff --git a/htdocs/projetdon.class.php b/htdocs/projetdon.class.php
index f6b569686dc..294b76033eb 100644
--- a/htdocs/projetdon.class.php
+++ b/htdocs/projetdon.class.php
@@ -47,7 +47,7 @@ class ProjetDon {
     {
       $projets = array();
 
-      $sql = "SELECT rowid, libelle FROM llx_don_projet";
+      $sql = "SELECT rowid, libelle FROM ".MAIN_DB_PREFIX."don_projet";
       
       if ($this->db->query($sql) )
 	{
diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php
index b106796f6a9..f12ee5d2dfc 100644
--- a/htdocs/propal.class.php
+++ b/htdocs/propal.class.php
@@ -84,7 +84,7 @@ class Propal
 		  $price = $prod->price - $remise;
 		}
 	  
-	      $sql = "INSERT INTO llx_propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES ";
+	      $sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES ";
 	      $sql .= " (".$this->id.",". $idproduct.",". $qty.",". $price.",".$prod->tva_tx.",'".addslashes($prod->label)."',$remise_percent, $subprice)";
 	  
 	      if ($this->db->query($sql) )
@@ -127,7 +127,7 @@ class Propal
 	      $price = $p_price - $remise;
 	    }
 
-	  $sql = "INSERT INTO llx_propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES ";
+	  $sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES ";
 	  $sql .= " (".$this->id.", 0,". $p_qty.",". $price.",".$p_tva_tx.",'".$p_desc."',$remise_percent, $subprice) ; ";
 	  
 	  if ($this->db->query($sql) )
@@ -168,7 +168,7 @@ class Propal
     {
       if ($this->statut == 0)
 	{
-	  $sql = "DELETE FROM llx_propaldet WHERE rowid = $idligne";
+	  $sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE rowid = $idligne";
 	  
 	  if ($this->db->query($sql) )
 	    {
@@ -194,7 +194,7 @@ class Propal
        */
       $this->fin_validite = $this->datep + ($this->duree_validite * 24 * 3600);
 
-      $sql = "INSERT INTO llx_propal (fk_soc, fk_soc_contact, price, remise, tva, total, datep, datec, ref, fk_user_author, note, model_pdf, fin_validite) ";
+      $sql = "INSERT INTO ".MAIN_DB_PREFIX."propal (fk_soc, fk_soc_contact, price, remise, tva, total, datep, datec, ref, fk_user_author, note, model_pdf, fin_validite) ";
       $sql .= " VALUES ($this->socidp, $this->contactid, 0, $this->remise, 0,0,".$this->db->idate($this->datep).", now(), '$this->ref', $this->author, '$this->note','$this->modelpdf',".$this->db->idate($this->fin_validite).")";
       $sqlok = 0;
       
@@ -203,7 +203,7 @@ class Propal
 
 	  $this->id = $this->db->last_insert_id();
 	  
-	  $sql = "SELECT rowid FROM llx_propal WHERE ref='$this->ref';";
+	  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."propal WHERE ref='$this->ref';";
 	  if ( $this->db->query($sql) ) 
 	    { 
 	      /*
@@ -232,7 +232,7 @@ class Propal
 		   */
 		  if ($this->projetidp)
 		    {
-		      $sql = "UPDATE llx_propal SET fk_projet=$this->projetidp WHERE ref='$this->ref';";
+		      $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_projet=$this->projetidp WHERE ref='$this->ref';";
 		      $this->db->query($sql);
 		    }
 		}	  
@@ -259,7 +259,7 @@ class Propal
       /*
        *  Liste des produits a ajouter
        */
-      $sql = "SELECT price, qty, tva_tx FROM llx_propaldet WHERE fk_propal = $this->id";
+      $sql = "SELECT price, qty, tva_tx FROM ".MAIN_DB_PREFIX."propaldet WHERE fk_propal = $this->id";
       if ( $this->db->query($sql) )
 	{
 	  $num = $this->db->num_rows();
@@ -288,7 +288,7 @@ class Propal
       /*
        *
        */
-      $sql = "UPDATE llx_propal set price=$totalht, tva=$totaltva, total=$totalttc, remise=$total_remise WHERE rowid = $this->id";
+      $sql = "UPDATE ".MAIN_DB_PREFIX."propal set price=$totalht, tva=$totaltva, total=$totalttc, remise=$total_remise WHERE rowid = $this->id";
       if ( $this->db->query($sql) )
 	{
 	  return 1;
@@ -308,7 +308,7 @@ class Propal
     {
 
       $sql = "SELECT ref,total,price,remise,tva,fk_soc,fk_soc_contact,".$this->db->pdate("datep")."as dp,".$this->db->pdate("fin_validite")."as dfv, model_pdf, note, fk_statut, remise_percent";
-      $sql .= " FROM llx_propal WHERE rowid=$rowid;";
+      $sql .= " FROM ".MAIN_DB_PREFIX."propal WHERE rowid=$rowid;";
 
       if ($this->db->query($sql) )
 	{
@@ -349,7 +349,7 @@ class Propal
 	       */
 
 	      $sql = "SELECT p.rowid, p.label, p.description, p.ref, d.price, d.tva_tx, d.qty, d.remise_percent, d.subprice";
-	      $sql .= " FROM llx_propaldet as d, llx_product as p";
+	      $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as d, ".MAIN_DB_PREFIX."product as p";
 	      $sql .= " WHERE d.fk_propal = ".$this->id ." AND d.fk_product = p.rowid ORDER by d.rowid ASC";
 	
 	      $result = $this->db->query($sql);
@@ -387,7 +387,7 @@ class Propal
 	       * Lignes g�n�riques
 	       */
 	      $sql = "SELECT d.qty, d.description, d.price, d.subprice, d.tva_tx, d.rowid, d.remise_percent";
-	      $sql .= " FROM llx_propaldet as d";
+	      $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as d";
 	      $sql .= " WHERE d.fk_propal = ".$this->id ." AND d.fk_product = 0";
 	
 	      $result = $this->db->query($sql);
@@ -440,7 +440,7 @@ class Propal
       if ($user->rights->propale->valider)
 	{
 
-	  $sql = "UPDATE llx_propal SET fk_statut = 1, date_valid=now(), fk_user_valid=$user->id";
+	  $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_statut = 1, date_valid=now(), fk_user_valid=$user->id";
 	  $sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
 	  
 	  if ($this->db->query($sql) )
@@ -465,7 +465,7 @@ class Propal
 
 	  $remise = ereg_replace(",",".",$remise);
 
-	  $sql = "UPDATE llx_propal SET remise_percent = ".$remise;
+	  $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET remise_percent = ".$remise;
 	  $sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
 	  
 	  if ($this->db->query($sql) )
@@ -490,7 +490,7 @@ class Propal
       if ($user->rights->propale->creer)
 	{
 
-	  $sql = "UPDATE llx_propal SET model_pdf = '$modelpdf'";
+	  $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET model_pdf = '$modelpdf'";
 	  $sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
 	  
 	  if ($this->db->query($sql) )
@@ -513,7 +513,7 @@ class Propal
       $this->statut = $statut;
 
 
-      $sql = "UPDATE llx_propal SET fk_statut = $statut, note = '$note', date_cloture=now(), fk_user_cloture=$user->id";
+      $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_statut = $statut, note = '$note', date_cloture=now(), fk_user_cloture=$user->id";
       $sql .= " WHERE rowid = $this->id;";
       
       if ($this->db->query($sql) )
@@ -559,7 +559,7 @@ class Propal
    */
   Function reopen($userid)
     {
-      $sql = "UPDATE llx_propal SET fk_statut = 0";
+      $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_statut = 0";
       
       $sql .= " WHERE rowid = $this->id;";
       
@@ -580,7 +580,7 @@ class Propal
     {
       $ga = array();
 
-      $sql = "SELECT rowid, ref FROM llx_propal";
+      $sql = "SELECT rowid, ref FROM ".MAIN_DB_PREFIX."propal";
       if ($brouillon = 1)
 	{
 	  $sql .= " WHERE fk_statut = 0";
@@ -629,7 +629,7 @@ class Propal
     {
       $ga = array();
 
-      $sql = "SELECT fk_commande FROM llx_co_pr";      
+      $sql = "SELECT fk_commande FROM ".MAIN_DB_PREFIX."co_pr";      
       $sql .= " WHERE fk_propale = " . $this->id;
       if ($this->db->query($sql) )
 	{
@@ -659,10 +659,10 @@ class Propal
    */
   Function delete()
   {
-    $sql = "DELETE FROM llx_propaldet WHERE fk_propal = $this->id ;";
+    $sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE fk_propal = $this->id ;";
     if ( $this->db->query($sql) ) 
       {
-	$sql = "DELETE FROM llx_propal WHERE rowid = $this->id;";
+	$sql = "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE rowid = $this->id;";
 	if ( $this->db->query($sql) ) 
 	  {
 	    return 1;
diff --git a/htdocs/retourbplc.class.php b/htdocs/retourbplc.class.php
index 812d5a47597..6a0ef26b565 100644
--- a/htdocs/retourbplc.class.php
+++ b/htdocs/retourbplc.class.php
@@ -58,7 +58,7 @@ class Retourbplc
   {
 
 
-    $sql = "INSERT INTO llx_transaction_bplc";
+    $sql = "INSERT INTO ".MAIN_DB_PREFIX."transaction_bplc";
     $sql .= " (ipclient, 
                    num_transaction, 
                    date_transaction, 
diff --git a/htdocs/service.class.php b/htdocs/service.class.php
index b0a9d7eaf29..3a788ebedfe 100644
--- a/htdocs/service.class.php
+++ b/htdocs/service.class.php
@@ -47,7 +47,7 @@ class Service {
    */
   Function create($user) {
 
-    $sql = "INSERT INTO llx_service (datec, fk_user_author) VALUES (now(), ".$user->id.")";
+    $sql = "INSERT INTO ".MAIN_DB_PREFIX."service (datec, fk_user_author) VALUES (now(), ".$user->id.")";
 
     if ($this->db->query($sql) ) {
       $id = $this->db->last_insert_id();
@@ -66,7 +66,7 @@ class Service {
    */
   Function update($id, $user) {
 
-    $sql = "UPDATE llx_service ";
+    $sql = "UPDATE ".MAIN_DB_PREFIX."service ";
     $sql .= " SET label = '" . trim($this->libelle) ."'";
     $sql .= ",ref = '" . trim($this->ref) ."'";
     $sql .= ",price = " . $this->price ;
@@ -88,7 +88,7 @@ class Service {
    */
   Function start_comm($id, $user, $datedeb=0) {
 
-    $sql = "UPDATE llx_service ";
+    $sql = "UPDATE ".MAIN_DB_PREFIX."service ";
     if ($datedeb) {
       $sql .= " SET debut_comm = '$datedeb'";
     } else {
@@ -111,7 +111,7 @@ class Service {
    */
   Function stop_comm($id, $user, $datefin=0) {
 
-    $sql = "UPDATE llx_service ";
+    $sql = "UPDATE ".MAIN_DB_PREFIX."service ";
     if ($datefin) {
       $sql .= " SET fin_comm = '$datefin'";
     } else {
@@ -137,7 +137,7 @@ class Service {
     $sql = "SELECT s.ref,s.label,s.price,s.tms,s.debut_comm,s.fin_comm,s.description,";
     $sql .= $this->db->pdate("s.debut_comm") . ' as debut_epoch,';
     $sql .= $this->db->pdate("s.fin_comm") . ' as fin_epoch';
-    $sql .= " FROM llx_service as s";
+    $sql .= " FROM ".MAIN_DB_PREFIX."service as s";
     $sql .= " WHERE s.rowid = $id";
   
     $result = $this->db->query($sql);
diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php
index 3d99b58df36..44cf3dc1c41 100644
--- a/htdocs/societe.class.php
+++ b/htdocs/societe.class.php
@@ -55,7 +55,7 @@ class Societe {
    */
   Function create()
   {
-    $sql = "INSERT INTO llx_societe (nom, datec, datea, client) ";
+    $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, datec, datea, client) ";
     $sql .= " VALUES ('".trim($this->nom)."', now(), now(), $this->client);";
 
     if ($this->db->query($sql) ) {
@@ -78,7 +78,7 @@ class Societe {
 	$this->nom = "VALEUR MANQUANTE";
       }
 
-    $sql = "UPDATE llx_societe ";
+    $sql = "UPDATE ".MAIN_DB_PREFIX."societe ";
     $sql .= " SET nom = '" . trim($this->nom) ."'";
     $sql .= ",address = '" . trim($this->adresse) ."'";
     $sql .= ",cp = '" . trim($this->cp) ."'";
@@ -104,7 +104,7 @@ class Societe {
    */
   Function delete($id)
     {
-      $sql = "DELETE from llx_societe ";
+      $sql = "DELETE from ".MAIN_DB_PREFIX."societe ";
       $sql .= " WHERE idp = " . $id .";";
 
       if (! $this->db->query($sql))
@@ -150,7 +150,7 @@ class Societe {
        * Lignes
        */      
       $sql = "SELECT f.rowid";
-      $sql .= " FROM llx_facture as f WHERE f.fk_soc = ".$this->id;
+      $sql .= " FROM ".MAIN_DB_PREFIX."facture as f WHERE f.fk_soc = ".$this->id;
       $sql .= " AND f.fk_statut = 1 AND f.paye = 0";
 
       if ($this->db->query($sql))
@@ -181,7 +181,7 @@ class Societe {
 
       $sql = "SELECT s.idp, s.nom, s.address,".$this->db->pdate("s.datec")." as dc, prefix_comm,";
       $sql .= " s.tel, s.fax, s.url,s.cp,s.ville, s.note, s.siren, client, fournisseur";
-      $sql .= " FROM llx_societe as s";
+      $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
       $sql .= " WHERE s.idp = ".$this->id;
 
       $result = $this->db->query($sql);
@@ -229,7 +229,7 @@ class Societe {
 
   Function attribute_prefix()
     {
-      $sql = "SELECT nom FROM llx_societe WHERE idp = $this->id";
+      $sql = "SELECT nom FROM ".MAIN_DB_PREFIX."societe WHERE idp = $this->id";
       if ( $this->db->query( $sql) )
 	{
 	  if ( $this->db->num_rows() )
@@ -239,7 +239,7 @@ class Societe {
 	      
 	      $prefix = strtoupper(substr($nom, 0, 2));
       
-	      $sql = "SELECT count(*) FROM llx_societe WHERE prefix_comm = '$prefix'";
+	      $sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."societe WHERE prefix_comm = '$prefix'";
 	      if ( $this->db->query( $sql) )
 		{
 		  if ( $this->db->result(0, 0) )
@@ -250,7 +250,7 @@ class Societe {
 		    {
 		      $this->db->free();
 
-		      $sql = "UPDATE llx_societe set prefix_comm='$prefix' WHERE idp=$this->id";
+		      $sql = "UPDATE ".MAIN_DB_PREFIX."societe set prefix_comm='$prefix' WHERE idp=$this->id";
 		      
 		      if ( $this->db->query( $sql) )
 			{
@@ -283,7 +283,7 @@ class Societe {
   Function get_nom($id)
     {
 
-      $sql = "SELECT nom FROM llx_societe WHERE idp=$id;";
+      $sql = "SELECT nom FROM ".MAIN_DB_PREFIX."societe WHERE idp=$id;";
       
       $result = $this->db->query($sql);
       
@@ -307,7 +307,7 @@ class Societe {
     {
       $contact_email = array();
 
-      $sql = "SELECT idp, email, name, firstname FROM llx_socpeople WHERE fk_soc = $this->id";
+      $sql = "SELECT idp, email, name, firstname FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = $this->id";
       
       if ($this->db->query($sql) )
 	{
@@ -340,7 +340,7 @@ class Societe {
     {
       $contacts = array();
 
-      $sql = "SELECT idp, name, firstname FROM llx_socpeople WHERE fk_soc = $this->id";
+      $sql = "SELECT idp, name, firstname FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = $this->id";
       
       if ($this->db->query($sql) )
 	{
@@ -372,7 +372,7 @@ class Societe {
   Function contact_get_email($rowid)
     {
 
-      $sql = "SELECT idp, email, name, firstname FROM llx_socpeople WHERE idp = $rowid";
+      $sql = "SELECT idp, email, name, firstname FROM ".MAIN_DB_PREFIX."socpeople WHERE idp = $rowid";
       
       if ($this->db->query($sql) )
 	{
diff --git a/htdocs/socnote.php b/htdocs/socnote.php
index 0c366466c89..8e2bd077634 100644
--- a/htdocs/socnote.php
+++ b/htdocs/socnote.php
@@ -22,7 +22,7 @@
 require("./pre.inc.php");
 
 if ($HTTP_POST_VARS["action"] == 'add') {
-  $sql = "UPDATE llx_societe SET note='$note' WHERE idp=$socid";
+  $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET note='$note' WHERE idp=$socid";
   $result = $db->query($sql);
 }
 /*
diff --git a/htdocs/stats.php b/htdocs/stats.php
index 81ae5545df7..500c8c0886d 100644
--- a/htdocs/stats.php
+++ b/htdocs/stats.php
@@ -31,10 +31,10 @@ $mesg = '';
  *
  */
 $sql = array(
-	     array("Soci�t�","SELECT count(*) FROM llx_societe"),
-	     array("Contacts","SELECT count(*) FROM llx_socpeople"),
-	     array("Facture","SELECT count(*) FROM llx_facture"),
-	     array("Proposition commerciales","SELECT count(*) FROM llx_propal")
+	     array("Soci�t�","SELECT count(*) FROM ".MAIN_DB_PREFIX."societe"),
+	     array("Contacts","SELECT count(*) FROM ".MAIN_DB_PREFIX."socpeople"),
+	     array("Facture","SELECT count(*) FROM ".MAIN_DB_PREFIX."facture"),
+	     array("Proposition commerciales","SELECT count(*) FROM ".MAIN_DB_PREFIX."propal")
 );
 
 
diff --git a/htdocs/tva.class.php b/htdocs/tva.class.php
index d3377e62567..9acf3dbef5a 100644
--- a/htdocs/tva.class.php
+++ b/htdocs/tva.class.php
@@ -63,7 +63,7 @@ class Tva
     {
 
       $sql = "SELECT sum(f.tva) as amount";
-      $sql .= " FROM llx_facture as f WHERE f.paye = 1";
+      $sql .= " FROM ".MAIN_DB_PREFIX."facture as f WHERE f.paye = 1";
 
       if ($year)
 	{
@@ -102,7 +102,7 @@ class Tva
     {
       
       $sql = "SELECT sum(f.amount) as amount";
-      $sql .= " FROM llx_facture_fourn as f";
+      $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
       
       if ($year)
 	{
@@ -141,7 +141,7 @@ class Tva
     {
 
       $sql = "SELECT sum(f.amount) as amount";
-      $sql .= " FROM llx_tva as f";
+      $sql .= " FROM ".MAIN_DB_PREFIX."tva as f";
       
       if ($year)
 	{
@@ -177,7 +177,7 @@ class Tva
    */
   Function add_payement($datep, $datev, $amount)
     {
-      $sql = "INSERT INTO llx_tva (datep, datev, amount) ";
+      $sql = "INSERT INTO ".MAIN_DB_PREFIX."tva (datep, datev, amount) ";
       $sql .= " VALUES ('".$this->db->idate($datep)."',";
       $sql .= "'".$this->db->idate($datev)."'," . ereg_replace(",",".",$amount) .")";
 
diff --git a/htdocs/user.class.php b/htdocs/user.class.php
index d6434618dd8..a4d02baa72b 100644
--- a/htdocs/user.class.php
+++ b/htdocs/user.class.php
@@ -81,7 +81,7 @@ class User
 
       if ($lowid == 1)
 	{
-	  $sql = "REPLACE INTO llx_user_rights (fk_user, fk_id) VALUES ($this->id, $rid)";
+	  $sql = "REPLACE INTO ".MAIN_DB_PREFIX."user_rights (fk_user, fk_id) VALUES ($this->id, $rid)";
 	  if ($this->db->query($sql))
 	    {
 	    }
@@ -89,12 +89,12 @@ class User
       
       if ($lowid > 1)
 	{
-	  $sql = "REPLACE INTO llx_user_rights (fk_user, fk_id) VALUES ($this->id, $rid)";
+	  $sql = "REPLACE INTO ".MAIN_DB_PREFIX."user_rights (fk_user, fk_id) VALUES ($this->id, $rid)";
 	  if ($this->db->query($sql))
 	    {
 	    }
 	  $nid = $topid . "1";
-	  $sql = "REPLACE INTO llx_user_rights (fk_user, fk_id) VALUES ($this->id, $nid)";
+	  $sql = "REPLACE INTO ".MAIN_DB_PREFIX."user_rights (fk_user, fk_id) VALUES ($this->id, $nid)";
 	  if ($this->db->query($sql))
 	    {
 	      
@@ -110,7 +110,7 @@ class User
 	  for ($i = 1 ; $i < 10 ; $i++)
 	    {
 	      $nid = $topid . "$i";
-	      $sql = "REPLACE INTO llx_user_rights (fk_user, fk_id) VALUES ($this->id, $nid)";
+	      $sql = "REPLACE INTO ".MAIN_DB_PREFIX."user_rights (fk_user, fk_id) VALUES ($this->id, $nid)";
 	      if ($this->db->query($sql))
 		{
 		  
@@ -146,7 +146,7 @@ class User
 
       if ($lowid > 1)
 	{
-	  $sql = "DELETE FROM llx_user_rights WHERE fk_user = $this->id AND fk_id=$rid";
+	  $sql = "DELETE FROM ".MAIN_DB_PREFIX."user_rights WHERE fk_user = $this->id AND fk_id=$rid";
 	  if ($this->db->query($sql))
 	    {
 	    }
@@ -156,7 +156,7 @@ class User
 	{
 	  $fid = $topid . "0";
 	  $lid = $topid . "9";
-	  $sql = "DELETE FROM llx_user_rights WHERE fk_user = $this->id AND fk_id >= $fid AND fk_id <= $lid";
+	  $sql = "DELETE FROM ".MAIN_DB_PREFIX."user_rights WHERE fk_user = $this->id AND fk_id >= $fid AND fk_id <= $lid";
 	  if ($this->db->query($sql))
 	    {
 	      
@@ -172,7 +172,7 @@ class User
 	  for ($i = 1 ; $i < 10 ; $i++)
 	    {
 	      $nid = $topid . "$i";
-	      $sql = "DELETE FROM llx_user_rights WHERE fk_user = $this->id AND fk_id=$nid";
+	      $sql = "DELETE FROM ".MAIN_DB_PREFIX."user_rights WHERE fk_user = $this->id AND fk_id=$nid";
 	      if ($this->db->query($sql))
 		{
 		  
@@ -192,7 +192,7 @@ class User
    */
   Function getrights($module='')
     {
-      $sql = "SELECT fk_user, fk_id FROM llx_user_rights WHERE fk_user= $this->id";
+      $sql = "SELECT fk_user, fk_id FROM ".MAIN_DB_PREFIX."user_rights WHERE fk_user= $this->id";
       /*
 	if ($module)
 	{
@@ -375,8 +375,8 @@ class User
     {
 
       //$sql = "SELECT u.rowid, u.name, u.firstname, u.email, u.code, u.admin, u.module_comm, u.module_compta, u.login, u.pass, u.webcal_login, u.note";
-      //$sql .= " FROM llx_user as u";
-      $sql = "SELECT * FROM llx_user as u";
+      //$sql .= " FROM ".MAIN_DB_PREFIX."user as u";
+      $sql = "SELECT * FROM ".MAIN_DB_PREFIX."user as u";
       if ($this->id)
 	{
 	  $sql .= " WHERE u.rowid = $this->id";
@@ -433,11 +433,11 @@ class User
       if ($this->contact_id) 
 	{
 
-	  $sql = "DELETE FROM llx_user WHERE rowid = $this->id";
+	  $sql = "DELETE FROM ".MAIN_DB_PREFIX."user WHERE rowid = $this->id";
   
 	  $result = $this->db->query($sql);
 
-	  $sql = "UPDATE llx_socpeople SET fk_user = 0 WHERE idp = $this->contact_id";
+	  $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET fk_user = 0 WHERE idp = $this->contact_id";
 	    
 	  if ($this->db->query($sql)) 
 	    {
@@ -446,12 +446,12 @@ class User
 	}
       else
 	{
-	  $sql = "UPDATE llx_user SET login = '' WHERE rowid = $this->id";
+	  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET login = '' WHERE rowid = $this->id";
   
 	  $result = $this->db->query($sql);
 	}
 
-      $sql = "DELETE FROM llx_user_rights WHERE fk_user = $this->id";
+      $sql = "DELETE FROM ".MAIN_DB_PREFIX."user_rights WHERE fk_user = $this->id";
 
       if ($this->db->query($sql)) 
 	{
@@ -465,7 +465,7 @@ class User
    */
   Function create()
     {
-      $sql = "SELECT login FROM llx_user WHERE login ='$this->login'";
+      $sql = "SELECT login FROM ".MAIN_DB_PREFIX."user WHERE login ='$this->login'";
 
       if ($this->db->query($sql)) 
 	{
@@ -479,7 +479,7 @@ class User
 	    }
 	  else
 	    {            
-	      $sql = "INSERT INTO llx_user (datec, login) values (now(),'$this->login');";
+	      $sql = "INSERT INTO ".MAIN_DB_PREFIX."user (datec, login) values (now(),'$this->login');";
 	      if ($this->db->query($sql))
 		{
 		  if ($this->db->affected_rows()) 
@@ -513,7 +513,7 @@ class User
 
       $this->login = strtolower(substr($contact->prenom, 0, 3)) . strtolower(substr($contact->nom, 0, 3));
 
-      $sql = "SELECT login FROM llx_user WHERE login ='$this->login'";
+      $sql = "SELECT login FROM ".MAIN_DB_PREFIX."user WHERE login ='$this->login'";
 
       if ($this->db->query($sql)) 
 	{
@@ -527,7 +527,7 @@ class User
 	    }
 	  else
 	    {            
-	      $sql = "INSERT INTO llx_user (datec, login, fk_socpeople, fk_societe)";
+	      $sql = "INSERT INTO ".MAIN_DB_PREFIX."user (datec, login, fk_socpeople, fk_societe)";
 	      $sql .= " VALUES (now(),'$this->login',$contact->id, $contact->societeid);";
 	      if ($this->db->query($sql))
 		{
@@ -537,7 +537,7 @@ class User
 		      $this->admin = 0;
 		      $this->update();
 		      
-		      $sql = "UPDATE llx_socpeople SET fk_user = $this->id WHERE idp = $contact->id";
+		      $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET fk_user = $this->id WHERE idp = $contact->id";
 		      $this->db->query($sql);
 
 		      $this->set_default_rights();
@@ -563,7 +563,7 @@ class User
    */
   Function set_default_rights()
     {
-      $sql = "SELECT id FROM llx_rights_def WHERE bydefault = 1";
+      $sql = "SELECT id FROM ".MAIN_DB_PREFIX."rights_def WHERE bydefault = 1";
 
       if ($this->db->query($sql)) 
 	{
@@ -581,7 +581,7 @@ class User
       $i = 0;
       while ($i < $num)
 	{
-	  $sql = "REPLACE INTO llx_user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])";
+	  $sql = "REPLACE INTO ".MAIN_DB_PREFIX."user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])";
 	  if ($this->db->query($sql)) 
 	    {
 
@@ -595,7 +595,7 @@ class User
    */
   Function update()
     {
-      $sql = "SELECT login FROM llx_user WHERE login ='$this->login' AND rowid <> $this->id";
+      $sql = "SELECT login FROM ".MAIN_DB_PREFIX."user WHERE login ='$this->login' AND rowid <> $this->id";
 
       if ($this->db->query($sql)) 
 	{
@@ -612,7 +612,7 @@ class User
 	      if (!strlen($this->code))
 		$this->code = $this->login;
 
-	      $sql = "UPDATE llx_user SET ";
+	      $sql = "UPDATE ".MAIN_DB_PREFIX."user SET ";
 	      $sql .= " name = '$this->nom'";
 	      $sql .= ", firstname = '$this->prenom'";
 	      $sql .= ", login = '$this->login'";
@@ -662,7 +662,7 @@ class User
 	  $sqlpass = $password;
 	}
       $this->pass=$password;
-      $sql = "UPDATE llx_user SET pass = '".$sqlpass."'";
+      $sql = "UPDATE ".MAIN_DB_PREFIX."user SET pass = '".$sqlpass."'";
       $sql .= " WHERE rowid = $this->id";
       
       $result = $this->db->query($sql);
-- 
GitLab