diff --git a/htdocs/admin/commande.php b/htdocs/admin/commande.php
index 36efb483c94b8ba89396663af9f15b9007d10d34..7f41578058cd3aa376668378bb8d310b66d367f8 100644
--- a/htdocs/admin/commande.php
+++ b/htdocs/admin/commande.php
@@ -4,7 +4,7 @@
  * Copyright (C) 2004      Sebastien Di Cintio          <sdicintio@ressource-toi.org>
  * Copyright (C) 2004      Benoit Mortier               <benoit.mortier@opensides.be>
  * Copyright (C) 2004      Andre Cianfarani             <acianfa@free.fr>
- * Copyright (C) 2005-2011 Regis Houssin                <regis@dolibarr.fr>
+ * Copyright (C) 2005-2012 Regis Houssin                <regis@dolibarr.fr>
  * Copyright (C) 2008 	   Raphael Bertrand (Resultic)  <raphael.bertrand@resultic.fr>
  * Copyright (C) 2011-2012 Juanjo Menent			    <jmenent@2byte.es>
  * Copyright (C) 2011 	   Philippe Grand			    <philippe.grand@atoo-net.com>
@@ -36,8 +36,7 @@ require_once(DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php');
 $langs->load("admin");
 $langs->load("errors");
 
-if (!$user->admin)
-accessforbidden();
+if (! $user->admin) accessforbidden();
 
 $action = GETPOST("action");
 $value = GETPOST("value");
@@ -284,7 +283,7 @@ foreach ($conf->file->dol_document_root as $dirroot)
                         print '</td>'."\n";
 
 						print '<td align="center">';
-						if ($conf->global->COMMANDE_ADDON == "$file")
+						if ($conf->global->COMMANDE_ADDON == $file)
 						{
 							print img_picto($langs->trans("Activated"),'switch_on');
 						}
@@ -431,14 +430,14 @@ foreach ($conf->file->dol_document_root as $dirroot)
 	                            }
 	                            else
 	                            {
-	                                print "<td align=\"center\">\n";
+	                                print '<td align="center">'."\n";
 	                                print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
 	                                print "</td>";
 	                            }
 
 	                            // Defaut
-	                            print "<td align=\"center\">";
-	                            if ($conf->global->PROPALE_ADDON_PDF == "$name")
+	                            print '<td align="center">';
+	                            if ($conf->global->COMMANDE_ADDON_PDF == $name)
 	                            {
 	                                print img_picto($langs->trans("Default"),'on');
 	                            }
@@ -579,7 +578,7 @@ print '<br>';
 
 dol_htmloutput_mesg($mesg);
 
-$db->close();
-
 llxFooter();
+
+$db->close();
 ?>
diff --git a/htdocs/admin/workflow.php b/htdocs/admin/workflow.php
index 54a177e633079b302ff1f7232aa7c99d3c7443db..00775ed3070e53af35f372f5acaf46450b3b4089 100755
--- a/htdocs/admin/workflow.php
+++ b/htdocs/admin/workflow.php
@@ -26,7 +26,6 @@
 
 require("../main.inc.php");
 require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php");
-require_once(DOL_DOCUMENT_ROOT."/core/lib/ajax.lib.php");
 
 $langs->load("admin");
 $langs->load("workflow");
diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php
index 123c3207818c4e7944071029f25a9fd7ea358f4d..41028cdbe372b56f1fafa84e4edd57b20ce16ec3 100644
--- a/htdocs/comm/propal/class/propal.class.php
+++ b/htdocs/comm/propal/class/propal.class.php
@@ -1789,50 +1789,52 @@ class Propal extends CommonObject
 		$this->db->begin();
 
 		$sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE fk_propal = ".$this->id;
-		if ( $this->db->query($sql) )
+		if ($this->db->query($sql))
 		{
 			$sql = "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE rowid = ".$this->id;
-			if ( $this->db->query($sql) )
+			if ($this->db->query($sql))
 			{
+				// Delete linked object
+				$res = $this->deleteObjectLinked();
+				if ($res < 0) $error++;
+				
 				// Delete linked contacts
 				$res = $this->delete_linked_contact();
-				if ($res < 0)
-				{
-					$this->error='ErrorFailToDeleteLinkedContact';
-					$this->db->rollback();
-					return 0;
-				}
-
-				// We remove directory
-				$propalref = dol_sanitizeFileName($this->ref);
-				if ($conf->propale->dir_output)
+				if ($res < 0) $error++;
+				
+				if (! $error)
 				{
-					$dir = $conf->propale->dir_output . "/" . $propalref ;
-					$file = $conf->propale->dir_output . "/" . $propalref . "/" . $propalref . ".pdf";
-					if (file_exists($file))
+					// We remove directory
+					$propalref = dol_sanitizeFileName($this->ref);
+					if ($conf->propale->dir_output)
 					{
-						dol_delete_preview($this);
-
-						if (!dol_delete_file($file))
+						$dir = $conf->propale->dir_output . "/" . $propalref ;
+						$file = $conf->propale->dir_output . "/" . $propalref . "/" . $propalref . ".pdf";
+						if (file_exists($file))
 						{
-							$this->error='ErrorFailToDeleteFile';
-							$this->db->rollback();
-							return 0;
+							dol_delete_preview($this);
+					
+							if (!dol_delete_file($file))
+							{
+								$this->error='ErrorFailToDeleteFile';
+								$this->db->rollback();
+								return 0;
+							}
 						}
-					}
-					if (file_exists($dir))
-					{
-						$res=@dol_delete_dir($dir);
-						if (! $res)
+						if (file_exists($dir))
 						{
-							$this->error='ErrorFailToDeleteDir';
-							$this->db->rollback();
-							return 0;
+							$res=@dol_delete_dir($dir);
+							if (! $res)
+							{
+								$this->error='ErrorFailToDeleteDir';
+								$this->db->rollback();
+								return 0;
+							}
 						}
 					}
 				}
 
-				if (! $notrigger)
+				if (! $error && ! $notrigger)
 				{
 					// Call triggers
 					include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
@@ -1842,27 +1844,33 @@ class Propal extends CommonObject
 					// End call triggers
 				}
 
-				if (!$error)
+				if (! $error)
 				{
-					dol_syslog("Suppression de la proposition $this->id par $user->id", LOG_DEBUG);
+					dol_syslog(get_class($this)."::delete $this->id by $user->id", LOG_DEBUG);
 					$this->db->commit();
 					return 1;
 				}
 				else
 				{
+					$this->error=$this->db->lasterror();
+					dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
 					$this->db->rollback();
 					return 0;
 				}
 			}
 			else
 			{
+				$this->error=$this->db->lasterror();
+				dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
 				$this->db->rollback();
 				return -2;
 			}
 		}
 		else
 		{
-			$this->db->rollback();
+			$this->error=$this->db->lasterror();
+            dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
+            $this->db->rollback();
 			return -1;
 		}
 	}
diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php
index 547314759ac9a78d7807cf923428798e27bbb7dd..a8457896ed4306f928ecc751a6042e3cc8642175 100644
--- a/htdocs/commande/class/commande.class.php
+++ b/htdocs/commande/class/commande.class.php
@@ -2304,9 +2304,10 @@ class Commande extends CommonObject
      *	Delete the customer order
      *
      *	@param	User	$user		User object
+     *	@param	int		$notrigger	1=Does not execute triggers, 0= execuete triggers
      * 	@return	int					<=0 if KO, >0 if OK
      */
-    function delete($user)
+    function delete($user, $notrigger=0)
     {
         global $conf, $langs;
         require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
@@ -2369,7 +2370,7 @@ class Commande extends CommonObject
             }
         }
 
-        if (! $error)
+        if (! $error && ! $notrigger)
         {
             // Appel des triggers
             include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
@@ -2377,12 +2378,18 @@ class Commande extends CommonObject
             $result=$interface->run_triggers('ORDER_DELETE',$this,$user,$langs,$conf);
             if ($result < 0) { $error++; $this->errors=$interface->errors; }
             // Fin appel triggers
-
-            $this->db->commit();
-            return 1;
+        }
+        
+        if (! $error)
+        {
+        	dol_syslog(get_class($this)."::delete $this->id by $user->id", LOG_DEBUG);
+        	$this->db->commit();
+        	return 1;
         }
         else
         {
+            $this->error=$this->db->lasterror();
+            dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
             $this->db->rollback();
             return -1;
         }
diff --git a/htdocs/compta/bank/account.php b/htdocs/compta/bank/account.php
index ddc4569fbcc3decf37ad05576172e052878bb4fa..5e2cba398e342e20b6f6a5ccd20412497f11e7cc 100644
--- a/htdocs/compta/bank/account.php
+++ b/htdocs/compta/bank/account.php
@@ -2,9 +2,9 @@
 /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  * Copyright (C) 2003      Jean-Louis Bergamo   <jlb@j1b.org>
  * Copyright (C) 2004-2011 Laurent Destailleur  <eldy@users.sourceforge.net>
- * Copytight (C) 2004      Christophe Combelles <ccomb@free.fr>
- * Copytight (C) 2005-2011 Regis Houssin        <regis@dolibarr.fr>
- * Copytight (C) 2010-2011 Juanjo Menent        <jmenent@@2byte.es>
+ * Copyright (C) 2004      Christophe Combelles <ccomb@free.fr>
+ * Copyright (C) 2005-2012 Regis Houssin        <regis@dolibarr.fr>
+ * Copyright (C) 2010-2011 Juanjo Menent        <jmenent@@2byte.es>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -37,22 +37,22 @@ require_once(DOL_DOCUMENT_ROOT."/fourn/class/paiementfourn.class.php");
 
 $langs->load("bills");
 
+$id = (GETPOST('id','int') ? GETPOST('id','int') : GETPOST('account','int'));
+$ref = GETPOST('ref','alpha');
+$action=GETPOST('action','alpha');
+$confirm=GETPOST('confirm','alpha');
+
 // Security check
-if (isset($_GET["account"]) || isset($_GET["ref"]))
-{
-    $id = isset($_GET["account"])?$_GET["account"]:(isset($_GET["ref"])?$_GET["ref"]:'');
-}
-$fieldid = isset($_GET["ref"])?'ref':'rowid';
+$fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref :''));
+$fieldtype = (! empty($ref) ? 'ref' :'rowid');
 if ($user->societe_id) $socid=$user->societe_id;
-$result=restrictedArea($user,'banque',$id,'bank_account','','',$fieldid);
+$result=restrictedArea($user,'banque',$fieldvalue,'bank_account','','',$fieldtype);
 
 $req_nb=GETPOST("req_nb",'',3);
 $thirdparty=GETPOST("thirdparty",'',3);
-$account=GETPOST("account");
 $vline=GETPOST("vline");
-$action=GETPOST("action");
-$page=isset($_GET["page"])?$_GET["page"]:0;
-$negpage=isset($_GET["negpage"])?$_GET["negpage"]:0;
+$page=GETPOST('page','int');
+$negpage=GETPOST('negpage','int');
 if ($negpage)
 {
     $page=$_GET["nbpage"] - $negpage;
@@ -61,13 +61,14 @@ if ($negpage)
 
 $mesg='';
 
+$object = new Account($db);
 
 /*
  * Action
  */
 $dateop=-1;
 
-if ($action == 'add' && $account && ! isset($_POST["cancel"]) && $user->rights->banque->modifier)
+if ($action == 'add' && $id && ! isset($_POST["cancel"]) && $user->rights->banque->modifier)
 {
 	if (price2num($_POST["credit"]) > 0)
 	{
@@ -90,17 +91,16 @@ if ($action == 'add' && $account && ! isset($_POST["cancel"]) && $user->rights->
 	
 	if (! $mesg)
 	{
-		$acct=new Account($db);
-		$acct->fetch($account);
-		$insertid = $acct->addline($dateop, $operation, $label, $amount, $num_chq, $cat1, $user);
+		$object->fetch($id);
+		$insertid = $object->addline($dateop, $operation, $label, $amount, $num_chq, $cat1, $user);
 		if ($insertid > 0)
 		{
-			Header("Location: ".$_SERVER['PHP_SELF']."?account=" . $account."&action=addline");
+			Header("Location: ".$_SERVER['PHP_SELF']."?id=".$id."&action=addline");
 			exit;
 		}
 		else
 		{
-			dol_print_error($db,$acct->error);
+			$mesg=$object->error;
 		}
 	}
 	else
@@ -108,7 +108,7 @@ if ($action == 'add' && $account && ! isset($_POST["cancel"]) && $user->rights->
 		$action='addline';
 	}
 }
-if ($action == 'confirm_delete' && $_POST["confirm"]=='yes' && $user->rights->banque->modifier)
+if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->banque->modifier)
 {
 	$accline=new AccountLine($db);
 	$accline->fetch($_GET["rowid"]);
@@ -131,7 +131,7 @@ $paymentvatstatic=new TVA($db);
 
 $form = new Form($db);
 
-if ($account || $_GET["ref"])
+if ($id > 0 || ! empty($ref))
 {
 	if ($vline)
 	{
@@ -141,16 +141,8 @@ if ($account || $_GET["ref"])
 	{
 		$viewline = empty($conf->global->MAIN_SIZE_LISTE_LIMIT)?20:$conf->global->MAIN_SIZE_LISTE_LIMIT;
 	}
-	$acct = new Account($db);
-	if ($account)
-	{
-		$result=$acct->fetch($account);
-	}
-	if ($_GET["ref"])
-	{
-		$result=$acct->fetch(0,$_GET["ref"]);
-		$account=$acct->id;
-	}
+
+	$result=$object->fetch($id, $ref);
 	
 	// Chargement des categories bancaires dans $options
 	$nbcategories=0;
@@ -187,22 +179,22 @@ if ($account || $_GET["ref"])
 		$param.='&amp;req_nb='.urlencode($req_nb);
 		$mode_search = 1;
 	}
-	if ($_REQUEST["req_desc"])
+	if (GETPOST("req_desc"))
 	{
-		$sql_rech.= " AND b.label LIKE '%".$db->escape($_REQUEST["req_desc"])."%'";
-		$param.='&amp;req_desc='.urlencode($_REQUEST["req_desc"]);
+		$sql_rech.= " AND b.label LIKE '%".$db->escape(GETPOST("req_desc"))."%'";
+		$param.='&amp;req_desc='.urlencode(GETPOST("req_desc"));
 		$mode_search = 1;
 	}
-	if ($_REQUEST["req_debit"])
+	if (GETPOST("req_debit"))
 	{
-		$sql_rech.=" AND b.amount = -".price2num($_REQUEST["req_debit"]);
-		$param.='&amp;req_debit='.urlencode($_REQUEST["req_debit"]);
+		$sql_rech.=" AND b.amount = -".price2num(GETPOST("req_debit"));
+		$param.='&amp;req_debit='.urlencode(GETPOST("req_debit"));
 		$mode_search = 1;
 	}
-	if ($_REQUEST["req_credit"])
+	if (GETPOST("req_credit"))
 	{
-		$sql_rech.=" AND b.amount = ".price2num($_REQUEST["req_credit"]);
-		$param.='&amp;req_credit='.urlencode($_REQUEST["req_credit"]);
+		$sql_rech.=" AND b.amount = ".price2num(GETPOST("req_credit"));
+		$param.='&amp;req_credit='.urlencode(GETPOST("req_credit"));
 		$mode_search = 1;
 	}
 	if ($thirdparty)
@@ -211,10 +203,10 @@ if ($account || $_GET["ref"])
 		$param.='&amp;thirdparty='.urlencode($thirdparty);
 		$mode_search = 1;
 	}
-	if ($_REQUEST["paiementtype"])
+	if (GETPOST("paiementtype"))
 	{
-		$sql_rech.=" AND b.fk_type = '".$db->escape($_REQUEST["paiementtype"])."'";
-		$param.='&amp;paiementtype='.urlencode($_REQUEST["paiementtype"]);
+		$sql_rech.=" AND b.fk_type = '".$db->escape(GETPOST("paiementtype"))."'";
+		$param.='&amp;paiementtype='.urlencode(GETPOST("paiementtype"));
 		$mode_search = 1;
 	}
 	
@@ -226,7 +218,7 @@ if ($account || $_GET["ref"])
 		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu ON bu.fk_bank = b.rowid AND bu.type='company'";
 		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON bu.url_id = s.rowid";
 	}
-	$sql.= " WHERE b.fk_account = ".$acct->id;
+	$sql.= " WHERE b.fk_account = ".$object->id;
 	$sql.= " AND b.fk_account = ba.rowid";
 	$sql.= " AND ba.entity = ".$conf->entity;
 	$sql.= $sql_rech;
@@ -263,7 +255,7 @@ if ($account || $_GET["ref"])
 	//print $limitsql.'-'.$page.'-'.$viewline;
 	
 	// Onglets
-	$head=bank_prepare_head($acct);
+	$head=bank_prepare_head($object);
 	dol_fiche_head($head,'journal',$langs->trans("FinancialAccount"),0,'account');
 	
 	print '<table class="border" width="100%">';
@@ -271,12 +263,12 @@ if ($account || $_GET["ref"])
 	// Ref
 	print '<tr><td valign="top" width="25%">'.$langs->trans("Ref").'</td>';
 	print '<td colspan="3">';
-	print $form->showrefnav($acct,'ref','',1,'ref');
+	print $form->showrefnav($object,'ref','',1,'ref');
 	print '</td></tr>';
 	
 	// Label
 	print '<tr><td valign="top">'.$langs->trans("Label").'</td>';
-	print '<td colspan="3">'.$acct->label.'</td></tr>';
+	print '<td colspan="3">'.$object->label.'</td></tr>';
 	
 	print '</table>';
 	
@@ -287,7 +279,7 @@ if ($account || $_GET["ref"])
 	/**
 	 * Search form
 	 */
-	$param.='&amp;account='.$acct->id;
+	$param.='&amp;account='.$object->id;
 	
 	// Define transaction list navigation string
 	$navig='';
@@ -298,16 +290,16 @@ if ($account || $_GET["ref"])
 	$navig.= $langs->trans("Page")." "; // ' Page ';
 	$navig.='<input type="text" name="negpage" size="1" class="flat" value="'.($nbpage-$page).'">';
 	$navig.='<input type="hidden" name="req_nb"     value="'.$req_nb.'">';
-	$navig.='<input type="hidden" name="req_desc"   value="'.$_REQUEST["req_desc"].'">';
-	$navig.='<input type="hidden" name="req_debit"  value="'.$_REQUEST["req_debit"].'">';
-	$navig.='<input type="hidden" name="req_credit" value="'.$_REQUEST["req_credit"].'">';
+	$navig.='<input type="hidden" name="req_desc"   value="'.GETPOST("req_desc").'">';
+	$navig.='<input type="hidden" name="req_debit"  value="'.GETPOST("req_debit").'">';
+	$navig.='<input type="hidden" name="req_credit" value="'.GETPOST("req_credit").'">';
 	$navig.='<input type="hidden" name="thirdparty" value="'.$thirdparty.'">';
 	$navig.='<input type="hidden" name="nbpage"  value="'.$nbpage.'">';
-	$navig.='<input type="hidden" name="account" value="'.($acct->id).'">';
+	$navig.='<input type="hidden" name="id" value="'.$object->id.'">';
 	$navig.='/'.$nbpage.' ';
 	if ($total_lines > $limitsql )
 	{
-		$navig.= '<a href="account.php?'.$param.'&amp;page='.($page-1).'">'.img_next().'</a>';
+		$navig.= '<a href="'.$_SERVER["PHP_SELF"].'?'.$param.'&amp;page='.($page-1).'">'.img_next().'</a>';
 	}
 	$navig.='</form>';
 	//var_dump($navig);
@@ -316,7 +308,7 @@ if ($account || $_GET["ref"])
 	if ($action == 'delete')
 	{
 		$text=$langs->trans('ConfirmDeleteTransaction');
-		$ret=$form->form_confirm($_SERVER['PHP_SELF'].'?account='.$acct->id.'&amp;rowid='.$_GET["rowid"],$langs->trans('DeleteTransaction'),$text,'confirm_delete');
+		$ret=$form->form_confirm($_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;rowid='.$_GET["rowid"],$langs->trans('DeleteTransaction'),$text,'confirm_delete');
 		if ($ret == 'html') print '<br>';
 	}
 	
@@ -331,11 +323,11 @@ if ($account || $_GET["ref"])
 	// Form to add a transaction with no invoice
 	if ($user->rights->banque->modifier && $action == 'addline')
 	{
-		print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
+		print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
 		print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
 		print '<input type="hidden" name="action" value="add">';
-		print '<input type="hidden" name="vline" value="' . $vline . '">';
-		print '<input type="hidden" name="account" value="' . $acct->id . '">';
+		print '<input type="hidden" name="vline" value="'.$vline.'">';
+		print '<input type="hidden" name="id" value="'.$object->id.'">';
 		
 		print '<tr>';
 		print '<td align="left" colspan="10"><b>'.$langs->trans("AddBankRecordLong").'</b></td>';
@@ -357,18 +349,18 @@ if ($account || $_GET["ref"])
 		$form->select_date($dateop,'op',0,0,0,'transaction');
 		print '</td>';
 		print '<td nowrap="nowrap">';
-		$form->select_types_paiements((isset($_POST["operation"])?$_POST["operation"]:''),'operation','1,2',2,1);
+		$form->select_types_paiements((GETPOST('operation')?GETPOST('operation'):($object->courant == 2 ? 'LIQ' : '')),'operation','1,2',2,1);
 		print '</td><td>';
-		print '<input name="num_chq" class="flat" type="text" size="4" value="'.(isset($_POST["num_chq"])?$_POST["num_chq"]:'').'"></td>';
+		print '<input name="num_chq" class="flat" type="text" size="4" value="'.GETPOST("num_chq").'"></td>';
 		print '<td colspan="2">';
-		print '<input name="label" class="flat" type="text" size="24"  value="'.(isset($_POST["label"])?$_POST["label"]:'').'">';
+		print '<input name="label" class="flat" type="text" size="24"  value="'.GETPOST("label").'">';
 		if ($nbcategories)
 		{
 			print '<br>'.$langs->trans("Category").': <select class="flat" name="cat1">'.$options.'</select>';
 		}
 		print '</td>';
-		print '<td align=right><input name="debit" class="flat" type="text" size="4" value="'.(isset($_POST["debit"])?$_POST["debit"]:'').'"></td>';
-		print '<td align=right><input name="credit" class="flat" type="text" size="4" value="'.(isset($_POST["credit"])?$_POST["credit"]:'').'"></td>';
+		print '<td align=right><input name="debit" class="flat" type="text" size="4" value="'.GETPOST("debit").'"></td>';
+		print '<td align=right><input name="credit" class="flat" type="text" size="4" value="'.GETPOST("credit").'"></td>';
 		print '<td colspan="2" align="center">';
 		print '<input type="submit" name="save" class="button" value="'.$langs->trans("Add").'"><br>';
 		print '<input type="submit" name="cancel" class="button" value="'.$langs->trans("Cancel").'">';
@@ -394,14 +386,14 @@ if ($account || $_GET["ref"])
 	print '<td align="right">'.$langs->trans("Credit").'</td>';
 	print '<td align="right" width="80">'.$langs->trans("BankBalance").'</td>';
 	print '<td align="center" width="60">';
-	if ($acct->type != 2 && $acct->rappro) print $langs->trans("AccountStatementShort");
+	if ($object->type != 2 && $object->rappro) print $langs->trans("AccountStatementShort");
 	else print '&nbsp;';
 	print '</td></tr>';
 	
 	print '<form action="'.$_SERVER["PHP_SELF"].'?'.$param.'" name="search" method="POST">';
 	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
 	print '<input type="hidden" name="action" value="search">';
-	print '<input type="hidden" name="account" value="' . $acct->id . '">';
+	print '<input type="hidden" name="id" value="'.$object->id.'">';
 	
 	print '<tr class="liste_titre">';
 	print '<td>&nbsp;</td>';
@@ -412,10 +404,10 @@ if ($account || $_GET["ref"])
 	print $form->select_types_paiements($_REQUEST['paiementtype'],'paiementtype',$filtertype,2,1,1,8);
 	print '</td>';
 	print '<td><input type="text" class="flat" name="req_nb" value="'.$req_nb.'" size="2"></td>';
-	print '<td><input type="text" class="flat" name="req_desc" value="'.$_REQUEST["req_desc"].'" size="24"></td>';
+	print '<td><input type="text" class="flat" name="req_desc" value="'.GETPOST("req_desc").'" size="24"></td>';
 	print '<td><input type="text" class="flat" name="thirdparty" value="'.$thirdparty.'" size="14"></td>';
-	print '<td align="right"><input type="text" class="flat" name="req_debit" value="'.$_REQUEST["req_debit"].'" size="4"></td>';
-	print '<td align="right"><input type="text" class="flat" name="req_credit" value="'.$_REQUEST["req_credit"].'" size="4"></td>';
+	print '<td align="right"><input type="text" class="flat" name="req_debit" value="'.GETPOST("req_debit").'" size="4"></td>';
+	print '<td align="right"><input type="text" class="flat" name="req_credit" value="'.GETPOST("req_credit").'" size="4"></td>';
 	print '<td align="center">&nbsp;</td>';
 	print '<td align="center" width="40"><input type="image" class="liste_titre" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'"></td>';
 	print "</tr>\n";
@@ -461,7 +453,7 @@ if ($account || $_GET["ref"])
 		//$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu3 ON bu3.fk_bank = b.rowid AND bu3.type='company'";
 		//$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON bu3.url_id = s.rowid";
 	}
-	$sql.= " WHERE b.fk_account=".$acct->id;
+	$sql.= " WHERE b.fk_account=".$object->id;
 	$sql.= " AND b.fk_account = ba.rowid";
 	$sql.= " AND ba.entity = ".$conf->entity;
 	$sql.= $sql_rech;
@@ -537,7 +529,7 @@ if ($account || $_GET["ref"])
 					print dol_trunc($objp->label,60);
 				}
 				// Add links after description
-				$links = $acct->get_url($objp->rowid);
+				$links = $object->get_url($objp->rowid);
 				foreach($links as $key=>$val)
 				{
 					if ($links[$key]['type']=='payment')
@@ -664,14 +656,14 @@ if ($account || $_GET["ref"])
 				}
 				
 				// Transaction reconciliated or edit link
-				if ($objp->rappro && $acct->canBeConciliated() > 0)  // If line not conciliated and account can be conciliated
+				if ($objp->rappro && $object->canBeConciliated() > 0)  // If line not conciliated and account can be conciliated
 				{
 					print '<td align="center" nowrap>';
-					print '<a href="'.DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$objp->rowid.'&amp;account='.$acct->id.'&amp;page='.$page.'">';
+					print '<a href="'.DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$objp->rowid.'&amp;account='.$object->id.'&amp;page='.$page.'">';
 					print img_edit();
 					print '</a>';
 					print "&nbsp; ";
-					print '<a href="releve.php?num='.$objp->num_releve.'&amp;account='.$acct->id.'">'.$objp->num_releve.'</a>';
+					print '<a href="releve.php?num='.$objp->num_releve.'&amp;account='.$object->id.'">'.$objp->num_releve.'</a>';
 					print "</td>";
 				}
 				else
@@ -679,17 +671,17 @@ if ($account || $_GET["ref"])
 					print '<td align="center">';
 					if ($user->rights->banque->modifier || $user->rights->banque->consolidate)
 					{
-						print '<a href="'.DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$objp->rowid.'&amp;account='.$acct->id.'&amp;page='.$page.'">';
+						print '<a href="'.DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$objp->rowid.'&amp;account='.$object->id.'&amp;page='.$page.'">';
 						print img_edit();
 						print '</a>';
 					}
 					else
 					{
-						print '<a href="'.DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$objp->rowid.'&amp;account='.$acct->id.'&amp;page='.$page.'">';
+						print '<a href="'.DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$objp->rowid.'&amp;account='.$object->id.'&amp;page='.$page.'">';
 						print img_view();
 						print '</a>';
 					}
-					if ($acct->canBeConciliated() > 0 && empty($objp->rappro))
+					if ($object->canBeConciliated() > 0 && empty($objp->rappro))
 					{
 						if ($db->jdate($objp->dv) < ($now - $conf->bank->rappro->warning_delay))
 						{
@@ -699,7 +691,7 @@ if ($account || $_GET["ref"])
 					print '&nbsp;';
 					if ($user->rights->banque->modifier)
 					{
-						print '<a href="'.DOL_URL_ROOT.'/compta/bank/account.php?action=delete&amp;rowid='.$objp->rowid.'&amp;account='.$acct->id.'&amp;page='.$page.'">';
+						print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&amp;rowid='.$objp->rowid.'&amp;id='.$object->id.'&amp;page='.$page.'">';
 						print img_delete();
 						print '</a>';
 					}
@@ -742,11 +734,11 @@ if ($account || $_GET["ref"])
 	{
 		print '<div class="tabsAction">';
 		
-		if ($acct->type != 2 && $acct->rappro)  // If not cash account and can be reconciliate
+		if ($object->type != 2 && $object->rappro)  // If not cash account and can be reconciliate
 		{
 			if ($user->rights->banque->consolidate)
 			{
-				print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/bank/rappro.php?account='.$acct->id.'">'.$langs->trans("Conciliate").'</a>';
+				print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/bank/rappro.php?account='.$object->id.'">'.$langs->trans("Conciliate").'</a>';
 			}
 			else
 			{
@@ -758,7 +750,7 @@ if ($account || $_GET["ref"])
 		{
 			if ($user->rights->banque->modifier)
 			{
-				print '<a class="butAction" href="account.php?action=addline&amp;account='.$acct->id.'&amp;page='.$page.'">'.$langs->trans("AddBankRecord").'</a>';
+				print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=addline&amp;id='.$object->id.'&amp;page='.$page.'">'.$langs->trans("AddBankRecord").'</a>';
 			}
 			else
 			{
@@ -776,7 +768,7 @@ else
 	print $langs->trans("ErrorBankAccountNotFound");
 }
 
-$db->close();
-
 llxFooter();
+
+$db->close();
 ?>
\ No newline at end of file
diff --git a/htdocs/compta/bank/ligne.php b/htdocs/compta/bank/ligne.php
index 5ae6bef31bccd1a111c5d941e977f7c515b03ed0..6acb76f52d5861355594200c708d398b441e3aca 100644
--- a/htdocs/compta/bank/ligne.php
+++ b/htdocs/compta/bank/ligne.php
@@ -3,6 +3,7 @@
  * Copyright (C) 2003      Xavier DUTOIT        <doli@sydesy.com>
  * Copyright (C) 2004-2011 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2004      Christophe Combelles <ccomb@free.fr>
+ * Copyright (C) 2005-2012 Regis Houssin        <regis@dolibarr.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -27,22 +28,27 @@
 require("./pre.inc.php");
 require_once(DOL_DOCUMENT_ROOT."/compta/bank/class/account.class.php");
 
-if (! $user->rights->banque->lire && ! $user->rights->banque->consolidate) accessforbidden();
-
 $langs->load("banks");
 $langs->load("compta");
 $langs->load("bills");
 $langs->load("categories");
 if ($conf->adherent->enabled) $langs->load("members");
 
-$action=GETPOST('action');
-$rowid=GETPOST("rowid");
-$ref=GETPOST("ref");
+
+$id = (GETPOST('id','int') ? GETPOST('id','int') : GETPOST('account','int'));
+$ref = GETPOST('ref','alpha');
+$action=GETPOST('action','alpha');
+$confirm=GETPOST('confirm','alpha');
+$rowid=GETPOST("rowid",'int');
 $orig_account=GETPOST("orig_account");
-$accountid=GETPOST('accountid');
-$confirm=GETPOST('confirm');
 
-$form = new Form($db);
+// Security check
+$fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref :''));
+$fieldtype = (! empty($ref) ? 'ref' :'rowid');
+if ($user->societe_id) $socid=$user->societe_id;
+$result=restrictedArea($user,'banque',$fieldvalue,'bank_account','','',$fieldtype);
+if (! $user->rights->banque->lire && ! $user->rights->banque->consolidate) accessforbidden();
+
 
 /*
  * Actions
@@ -77,7 +83,7 @@ if ($action == 'class')
         dol_print_error($db);
     }
 
-    $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_class (lineid, fk_categ) VALUES (".$_GET["rowid"].", ".$_POST["cat1"].")";
+    $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_class (lineid, fk_categ) VALUES (".$rowid.", ".$_POST["cat1"].")";
     if (! $db->query($sql))
     {
         dol_print_error($db);
@@ -86,50 +92,64 @@ if ($action == 'class')
 
 if ($action == "update")
 {
-    // Avant de modifier la date ou le montant, on controle si ce n'est pas encore rapproche
-    $conciliated=0;
-    $sql = "SELECT b.rappro FROM ".MAIN_DB_PREFIX."bank as b WHERE rowid=".$rowid;
-    $result = $db->query($sql);
-    if ($result)
-    {
-        $objp = $db->fetch_object($result);
-        $conciliated=$objp->rappro;
-    }
-
-    $db->begin();
-
-    $amount = price2num($_POST['amount']);
-    $dateop = dol_mktime(12,0,0,$_POST["dateomonth"],$_POST["dateoday"],$_POST["dateoyear"]);
-    $dateval= dol_mktime(12,0,0,$_POST["datevmonth"],$_POST["datevday"],$_POST["datevyear"]);
-    $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
-    $sql.= " SET ";
-    // Always opened
-    if (isset($_POST['value']))      $sql.=" fk_type='".$db->escape($_POST['value'])."',";
-    if (isset($_POST['num_chq']))    $sql.=" num_chq='".$db->escape($_POST["num_chq"])."',";
-    if (isset($_POST['banque']))     $sql.=" banque='".$db->escape($_POST["banque"])."',";
-    if (isset($_POST['emetteur']))   $sql.=" emetteur='".$db->escape($_POST["emetteur"])."',";
-    // Blocked when conciliated
-    if (! $conciliated)
-    {
-        if (isset($_POST['label']))      $sql.=" label='".$db->escape($_POST["label"])."',";
-        if (isset($_POST['amount']))     $sql.=" amount='".$amount."',";
-        if (isset($_POST['dateomonth'])) $sql.=" dateo = '".$db->idate($dateop)."',";
-        if (isset($_POST['datevmonth'])) $sql.=" datev = '".$db->idate($dateval)."',";
-    }
-    $sql.= " fk_account = ".$accountid;
-    $sql.= " WHERE rowid = ".$rowid;
-
-    $result = $db->query($sql);
-    if ($result)
-    {
-        $mesg=$langs->trans("RecordSaved");
-        $db->commit();
-    }
-    else
-    {
-        $db->rollback();
-        dol_print_error($db);
-    }
+	$error=0;
+
+	$ac = new Account($db);
+	$ac->fetch($id);
+
+	if ($ac->courant == 2 && $_POST['value'] != 'LIQ')
+	{
+		$mesg = '<div class="error">'.$langs->trans("ErrorCashAccountAcceptsOnlyCashMoney").'</div>';
+		$error++;
+	}
+
+	if (! $error)
+	{
+		// Avant de modifier la date ou le montant, on controle si ce n'est pas encore rapproche
+		$conciliated=0;
+		$sql = "SELECT b.rappro FROM ".MAIN_DB_PREFIX."bank as b WHERE rowid=".$rowid;
+		$result = $db->query($sql);
+		if ($result)
+		{
+			$objp = $db->fetch_object($result);
+			$conciliated=$objp->rappro;
+		}
+
+		$db->begin();
+
+		$amount = price2num($_POST['amount']);
+		$dateop = dol_mktime(12,0,0,$_POST["dateomonth"],$_POST["dateoday"],$_POST["dateoyear"]);
+		$dateval= dol_mktime(12,0,0,$_POST["datevmonth"],$_POST["datevday"],$_POST["datevyear"]);
+		$sql = "UPDATE ".MAIN_DB_PREFIX."bank";
+		$sql.= " SET ";
+		// Always opened
+		if (isset($_POST['value']))      $sql.=" fk_type='".$db->escape($_POST['value'])."',";
+		if (isset($_POST['num_chq']))    $sql.=" num_chq='".$db->escape($_POST["num_chq"])."',";
+		if (isset($_POST['banque']))     $sql.=" banque='".$db->escape($_POST["banque"])."',";
+		if (isset($_POST['emetteur']))   $sql.=" emetteur='".$db->escape($_POST["emetteur"])."',";
+		// Blocked when conciliated
+		if (! $conciliated)
+		{
+			if (isset($_POST['label']))      $sql.=" label='".$db->escape($_POST["label"])."',";
+			if (isset($_POST['amount']))     $sql.=" amount='".$amount."',";
+			if (isset($_POST['dateomonth'])) $sql.=" dateo = '".$db->idate($dateop)."',";
+			if (isset($_POST['datevmonth'])) $sql.=" datev = '".$db->idate($dateval)."',";
+		}
+		$sql.= " fk_account = ".$id;
+		$sql.= " WHERE rowid = ".$rowid;
+
+		$result = $db->query($sql);
+		if ($result)
+		{
+			$mesg=$langs->trans("RecordSaved");
+			$db->commit();
+		}
+		else
+		{
+			$db->rollback();
+			dol_print_error($db);
+		}
+	}
 }
 
 // Reconcile
@@ -176,6 +196,8 @@ if ($user->rights->banque->consolidate && ($action == 'num_releve' || $action ==
  * View
  */
 
+$form = new Form($db);
+
 llxHeader();
 
 // On initialise la liste des categories
@@ -198,16 +220,16 @@ if ($result)
     $db->free($result);
 }
 
-$var=False;
+$var=false;
 $h=0;
 
 
-$head[$h][0] = DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$_GET["rowid"];
+$head[$h][0] = $_SERVER['PHP_SELF'].'?rowid='.$rowid;
 $head[$h][1] = $langs->trans('Card');
 $hselected=$h;
 $h++;
 
-$head[$h][0] = DOL_URL_ROOT.'/compta/bank/info.php?rowid='.$_GET["rowid"];
+$head[$h][0] = DOL_URL_ROOT.'/compta/bank/info.php?rowid='.$rowid;
 $head[$h][1] = $langs->trans("Info");
 $h++;
 
@@ -244,15 +266,15 @@ if ($result)
         // Confirmations
         if ($action == 'delete_categ')
         {
-            $ret=$form->form_confirm("ligne.php?rowid=".$rowid."&cat1=".GETPOST("fk_categ")."&orig_account=".$orig_account, $langs->trans("RemoveFromRubrique"), $langs->trans("RemoveFromRubriqueConfirm"), "confirm_delete_categ", '', 'yes', 1);
+            $ret=$form->form_confirm($_SERVER['PHP_SELF']."?rowid=".$rowid."&cat1=".GETPOST("fk_categ")."&orig_account=".$orig_account, $langs->trans("RemoveFromRubrique"), $langs->trans("RemoveFromRubriqueConfirm"), "confirm_delete_categ", '', 'yes', 1);
             if ($ret == 'html') print '<br>';
         }
 
-        print '<form name="update" method="post" action="ligne.php?rowid='.$rowid.'">';
+        print '<form name="update" method="POST" action="'.$_SERVER['PHP_SELF'].'?rowid='.$rowid.'">';
         print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
         print '<input type="hidden" name="action" value="update">';
         print '<input type="hidden" name="orig_account" value="'.$orig_account.'">';
-        print '<input type="hidden" name="accountid" value="'.$acct->id.'">';
+        print '<input type="hidden" name="id" value="'.$acct->id.'">';
 
         print '<table class="border" width="100%">';
 
@@ -424,9 +446,9 @@ if ($result)
             if (! $objp->rappro)
             {
                 print ' &nbsp; ';
-                print '<a href="'.$_SERVER['PHP_SELF'].'?action=dvprev&amp;account='.$_GET["account"].'&amp;rowid='.$objp->rowid.'">';
+                print '<a href="'.$_SERVER['PHP_SELF'].'?action=dvprev&amp;id='.$id.'&amp;rowid='.$objp->rowid.'">';
                 print img_edit_remove() . "</a> ";
-                print '<a href="'.$_SERVER['PHP_SELF'].'?action=dvnext&amp;account='.$_GET["account"].'&amp;rowid='.$objp->rowid.'">';
+                print '<a href="'.$_SERVER['PHP_SELF'].'?action=dvnext&amp;id='.$id.'&amp;rowid='.$objp->rowid.'">';
                 print img_edit_add() ."</a>";
             }
             print '</td>';
@@ -497,10 +519,10 @@ if ($result)
         {
             print '<br>'."\n";
             print_fiche_titre($langs->trans("Reconciliation"),'','');
-            print "<form method=\"post\" action=\"ligne.php?rowid=$objp->rowid\">";
+            print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?rowid='.$objp->rowid.'">';
             print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
             print '<input type="hidden" name="action" value="setreconcile">';
-            print "<input type=\"hidden\" name=\"orig_account\" value=\"".$orig_account."\">";
+            print '<input type="hidden" name="orig_account" value="'.$orig_account.'">';
 
             print '<table class="border" width="100%">';
 
@@ -556,12 +578,12 @@ print '</div>';
 print '<br>';
 print '<table class="noborder" width="100%">';
 
-print "<form method=\"post\" action=\"ligne.php?rowid=$rowid&amp;account=$account\">";
+print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?rowid='.$rowid.'&amp;id='.$id.'">';
 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
-print "<input type=\"hidden\" name=\"action\" value=\"class\">";
-print "<input type=\"hidden\" name=\"orig_account\" value=\"".$orig_account."\">";
-print "<tr class=\"liste_titre\"><td>".$langs->trans("Rubriques")."</td><td colspan=\"2\">";
-print "<select class=\"flat\" name=\"cat1\">".$options."</select>&nbsp;";
+print '<input type="hidden" name="action" value="class">';
+print '<input type="hidden" name="orig_account" value="'.$orig_account.'">';
+print '<tr class="liste_titre"><td>'.$langs->trans("Rubriques").'</td><td colspan="2">';
+print '<select class="flat" name="cat1">'.$options.'</select>&nbsp;';
 print '<input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
 print "</tr>";
 print "</form>";
@@ -587,7 +609,7 @@ if ($result)
         print "<td align=\"center\"><a href=\"budget.php?bid=".$objp->rowid."\">".$langs->trans("ListBankTransactions")."</a></td>";
         if ($user->rights->banque->modifier)
         {
-            print "<td align=\"right\"><a href=\"ligne.php?action=delete_categ&amp;rowid=".$rowid."&amp;fk_categ=$objp->rowid\">".img_delete($langs->trans("Remove"))."</a></td>";
+            print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=delete_categ&amp;rowid='.$rowid.'&amp;fk_categ='.$objp->rowid.'">'.img_delete($langs->trans("Remove")).'</a></td>';
         }
         print "</tr>";
 
@@ -597,7 +619,7 @@ if ($result)
 }
 print "</table>";
 
-$db->close();
-
 llxFooter();
+
+$db->close();
 ?>
diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index 2abfaeb9cd87bcb7b0263b304e1bd6a922e1f189..b8b580f04548bf5927adf2a5935690b89b9da0cc 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -1116,9 +1116,10 @@ class Facture extends CommonObject
      *	Delete invoice
      *
      *	@param     	int		$rowid      	Id of invoice to delete. If empty, we delete current instance of invoice
+     *	@param		int		$notrigger		1=Does not execute triggers, 0= execute triggers
      *	@return		int						<0 if KO, >0 if OK
      */
-    function delete($rowid=0)
+    function delete($rowid, $notrigger=0)
     {
         global $user,$langs,$conf;
 
@@ -1176,12 +1177,15 @@ class Facture extends CommonObject
                 $resql=$this->db->query($sql);
                 if ($resql)
                 {
-                    // Appel des triggers
-                    include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
-                    $interface=new Interfaces($this->db);
-                    $result=$interface->run_triggers('BILL_DELETE',$this,$user,$langs,$conf);
-                    if ($result < 0) { $error++; $this->errors=$interface->errors; }
-                    // Fin appel triggers
+                	if (! $notrigger)
+                	{
+                		// Appel des triggers
+                		include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
+                		$interface=new Interfaces($this->db);
+                		$result=$interface->run_triggers('BILL_DELETE',$this,$user,$langs,$conf);
+                		if ($result < 0) { $error++; $this->errors=$interface->errors; }
+                		// Fin appel triggers
+                	}
 
                     $this->db->commit();
                     return 1;
diff --git a/htdocs/core/ajax/row.php b/htdocs/core/ajax/row.php
index c7761cdfd27cbe36aa8b2464e0302ed340f95fa4..72a679ef5729ea5b91a182bc8d56f2c0fecfbe67 100644
--- a/htdocs/core/ajax/row.php
+++ b/htdocs/core/ajax/row.php
@@ -40,22 +40,22 @@ top_httphead();
 print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' -->'."\n";
 
 // Registering the location of boxes
-if((isset($_GET['roworder']) && !empty($_GET['roworder'])) && (isset($_GET['table_element_line']) && !empty($_GET['table_element_line']))
-	&& (isset($_GET['fk_element']) && !empty($_GET['fk_element'])) && (isset($_GET['element_id']) && !empty($_GET['element_id'])) )
+if ((isset($_POST['roworder']) && ! empty($_POST['roworder'])) && (isset($_POST['table_element_line']) && ! empty($_POST['table_element_line']))
+	&& (isset($_POST['fk_element']) && ! empty($_POST['fk_element'])) && (isset($_POST['element_id']) && ! empty($_POST['element_id'])) )
 {
-	$roworder = explode(',',$_GET['roworder']);
+	$roworder = explode(',',GETPOST('roworder','alpha',2));
 
 	foreach($roworder as $value)
 	{
 		if (! empty($value)) $newroworder[] = $value;
 	}
 
-	dol_syslog("AjaxRow roworder=".$_GET['roworder']." fk_element=".$_GET['fk_element'], LOG_DEBUG);
+	dol_syslog("AjaxRow roworder=".GETPOST('roworder','alpha',2)." fk_element=".GETPOST('fk_element','int',2), LOG_DEBUG);
 
 	$row=new GenericObject($db);
-	$row->table_element_line = $_GET['table_element_line'];
-	$row->fk_element = $_GET['fk_element'];
-	$row->id = $_GET['element_id'];
+	$row->table_element_line = GETPOST('table_element_line','alpha',2);
+	$row->fk_element = GETPOST('fk_element','int',2);
+	$row->id = GETPOST('element_id','int',2);
 	$result=$row->line_ajaxorder($newroworder);
 	$result=$row->line_order(true);
 }
diff --git a/htdocs/core/lib/bank.lib.php b/htdocs/core/lib/bank.lib.php
index 0e524b73be587c0ec8d46a4c54d5b319952ada82..741a2903769872ae455671498e17913b401e06c8 100644
--- a/htdocs/core/lib/bank.lib.php
+++ b/htdocs/core/lib/bank.lib.php
@@ -1,5 +1,6 @@
 <?php
-/* Copyright (C) 2006-2007 Laurent Destailleur  <eldy@users.sourceforge.net>
+/* Copyright (C) 2006-2007	Laurent Destailleur	<eldy@users.sourceforge.net>
+ * Copyright (C) 2012		Regis Houssin		<regis@dolibarr.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -47,7 +48,7 @@ function bank_prepare_head($object)
 		$h++;
 	}
 
-    $head[$h][0] = DOL_URL_ROOT."/compta/bank/account.php?account=".$object->id;
+    $head[$h][0] = DOL_URL_ROOT."/compta/bank/account.php?id=".$object->id;
     $head[$h][1] = $langs->trans("Transactions");
     $head[$h][2] = 'journal';
     $h++;
diff --git a/htdocs/core/tpl/ajaxrow.tpl.php b/htdocs/core/tpl/ajaxrow.tpl.php
index 59dc7b8ed7885b9b321ddd70ec447666ec81ed59..cd66372604b3afb5dcbdea9c73a955061ed0b8b7 100644
--- a/htdocs/core/tpl/ajaxrow.tpl.php
+++ b/htdocs/core/tpl/ajaxrow.tpl.php
@@ -36,7 +36,7 @@ $(document).ready(function(){
 			var table_element_line = "<?php echo $object->table_element_line; ?>";
 			var fk_element = "<?php echo $object->fk_element; ?>";
 			var element_id = "<?php echo $object->id; ?>";
-			$.get("<?php echo DOL_URL_ROOT; ?>/core/ajax/row.php",
+			$.post("<?php echo DOL_URL_ROOT; ?>/core/ajax/row.php",
 					{
 						roworder: roworder,
 						table_element_line: table_element_line,
diff --git a/htdocs/ecm/index.php b/htdocs/ecm/index.php
index 2296276562954832afd4eaf11fe5bb595b0e9edc..59df6ad2e94e9c0cf62f7816d2385d8645996f28 100644
--- a/htdocs/ecm/index.php
+++ b/htdocs/ecm/index.php
@@ -289,14 +289,20 @@ if ($action == 'refreshmanual')
 }
 
 
+
 /*******************************************************************
  * View
  ********************************************************************/
 
+$userstatic = new User($db);
+$ecmdirstatic = new EcmDirectory($db);
+
 //print "xx".$_SESSION["dol_screenheight"];
 $maxheightwin=(isset($_SESSION["dol_screenheight"]) && $_SESSION["dol_screenheight"] > 500)?($_SESSION["dol_screenheight"]-166):660;
-
-$morecss="
+$morejs=array(
+"/filemanager/includes/jqueryFileTree/jqueryFileTree.js",
+);
+$moreheadcss="
 <!-- dol_screenheight=".$_SESSION["dol_screenheight"]." -->
 <style type=\"text/css\">
     #containerlayout {
@@ -307,7 +313,7 @@ $morecss="
         _width:     700px; /* min-width for IE6 */
     }
 </style>";
-$morejs="
+$moreheadjs="
 <script type=\"text/javascript\">
     jQuery(document).ready(function () {
         jQuery('#containerlayout').layout({
@@ -341,10 +347,10 @@ $morejs="
     });
 </script>";
 
-llxHeader($morecss.$morejs,$langs->trans("ECM"),'','','','','','',0,0);
+llxHeader($moreheadcss.$moreheadjs,$langs->trans("ECM"),'','','','',$morejs,'',0,0);
 
 
-// Ajout rubriques automatiques
+// Add sections to manage
 $rowspan=0;
 $sectionauto=array();
 if ($conf->product->enabled || $conf->service->enabled)     { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'product', 'test'=>$conf->product->enabled, 'label'=>$langs->trans("ProductsAndServices"),     'desc'=>$langs->trans("ECMDocsByProducts")); }
@@ -357,10 +363,6 @@ if ($conf->fournisseur->enabled) { $rowspan++; $sectionauto[]=array('level'=>1,
 if ($conf->fournisseur->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'invoice_supplier', 'test'=>$conf->fournisseur->enabled, 'label'=>$langs->trans("SuppliersInvoices"),   'desc'=>$langs->trans("ECMDocsByInvoices")); }
 if ($conf->tax->enabled)         { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'tax', 'test'=>$conf->tax->enabled, 'label'=>$langs->trans("SocialContributions"),     'desc'=>$langs->trans("ECMDocsBySocialContributions")); }
 
-
-//***********************
-// List
-//***********************
 print_fiche_titre($langs->trans("ECMArea").' - '.$langs->trans("ECMFileManager"));
 
 print $langs->trans("ECMAreaDesc")."<br>";
@@ -376,58 +378,47 @@ if ($action == 'delete')
 
 dol_htmloutput_mesg($mesg);
 
-// Toolbar
-//$head = ecm_prepare_head_fm($fac);
-//dol_fiche_head($head, 'file_manager', '', 1);
-
-
-//$conf->use_javascript_ajax=0;
-
 
+// Start container of all panels
 if ($conf->use_javascript_ajax)
 {
 ?>
-<div id="containerlayout"> <!-- begin div id="containerlayout" -->
-    <div id="ecm-layout-north" class="toolbar">
+	<div id="containerlayout"> <!-- begin div id="containerlayout" -->
+	<div id="ecm-layout-north" class="toolbar">
 <?php
 }
 else
 {
     print '<table class="border" width="100%">';
-
-    // Toolbar
     print '<tr><td colspan="2" style="background: #FFFFFF" style="height: 24px !important">';
 }
+// Start top panel, toolbar
+
+
+// Toolbar
+if ($user->rights->ecm->setup)
+{
+    print '<a href="'.DOL_URL_ROOT.'/ecm/docdir.php?action=create" title="'.dol_escape_htmltag($langs->trans('ECMAddSection')).'">';
+    print '<img width="32" height="32" border="0" src="'.DOL_URL_ROOT.'/theme/common/folder-new.png">';
+    print '</a>';
+}
+else
+{
+    print '<a href="#" title="'.$langs->trans("NotAllowed").'">';
+    print '<img width="32" height="32" border="0" src="'.DOL_URL_ROOT.'/theme/common/folder-new.png">';
+    print '</a>';
+}
 
-// Show button to create a directory
-//if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i',$action))
-//{
-    if ($user->rights->ecm->setup)
-    {
-        print '<a href="'.DOL_URL_ROOT.'/ecm/docdir.php?action=create" title="'.dol_escape_htmltag($langs->trans('ECMAddSection')).'">';
-        //print $langs->trans('ECMAddSection');
-        print '<img width="32" height="32" border="0" src="'.DOL_URL_ROOT.'/theme/common/folder-new.png">';
-        print '</a>';
-    }
-    else
-    {
-        print '<a href="#" title="'.$langs->trans("NotAllowed").'">';
-        //print $langs->trans('ECMAddSection');
-        print '<img width="32" height="32" border="0" src="'.DOL_URL_ROOT.'/theme/common/folder-new.png">';
-        print '</a>';
-    }
-//}
-// Show button to refresh listing
 print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual'.($module?'&amp;module='.$module:'').($section?'&amp;section='.$section:'').'"  title="'.dol_escape_htmltag($langs->trans('Refresh')).'">';
 print '<img width="32" height="32" border="0" src="'.DOL_URL_ROOT.'/theme/common/view-refresh.png">';
 print '</a>';
 
 
+// End top panel, toolbar
 if ($conf->use_javascript_ajax)
 {
 ?>
-   </div>
-
+	</div>
     <div id="ecm-layout-west" class="hidden">
 <?php
 }
@@ -435,25 +426,25 @@ else
 {
     print '</td></tr>';
     print '<tr>';
-
     print '<td width="40%" valign="top" style="background: #FFFFFF" rowspan="2">';
 }
+// Start left area
 
 
-// Left area
+
+// Confirmation de la suppression d'une ligne categorie
+if ($action == 'delete_section')
+{
+    $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?section='.urlencode($_GET["section"]), $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$ecmdir->label), 'confirm_deletesection','','',1);
+    if ($ret == 'html') print '<br>';
+}
+// End confirm
+
 
 
 if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i',$action) || $action == 'delete')
 {
-	$userstatic = new User($db);
-	$ecmdirstatic = new EcmDirectory($db);
 
-	// Confirmation de la suppression d'une ligne categorie
-	if ($action == 'delete_section')
-	{
-		$ret=$form->form_confirm($_SERVER["PHP_SELF"].'?section='.urlencode($_GET["section"]), $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$ecmdir->label), 'confirm_deletesection','','',1);
-		if ($ret == 'html') print '<br>';
-	}
 
 	print '<table width="100%" class="nobordernopadding">';
 
@@ -464,6 +455,8 @@ if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i',$acti
 
     $showonrightsize='';
 
+
+    // Auto section
 	if (count($sectionauto))
 	{
 		// Root title line (Automatic section)
@@ -565,7 +558,10 @@ if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i',$acti
 		}
 	}
 
-	// Root title line (Manual section)
+
+	// Manual section
+
+	// Root of manual section
 	print '<tr><td>';
 	print '<table class="nobordernopadding"><tr class="nobordernopadding">';
 	print '<td align="left" width="24px">';
@@ -585,214 +581,267 @@ if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i',$acti
 	print '</td>';
 	print '</tr>';
 
+    if (! empty($conf->global->MAIN_ECM_TRY_JS))
+    {
+        print '<tr><td>';
+
+    	// Show filemanager tree
+	    print '<div id="filetree" class="filetree">';
+	    print '</div>';
+
+	    print '</td></tr>';
+
+	    $openeddir='/';
+        ?>
+
+	   	<script type="text/javascript">
+
+	    function loadandshowpreview(filedirname)
+	    {
+	        //alert('filename='+filename);
+	        //jQuery('#fileview').empty();
+
+	        url='<?php echo dol_buildpath('/core/ajax/ajaxshowpreview.php',1); ?>?action=preview&rootpath=<?php echo $filemanagerroots->id ?>&modulepart=filemanager&type=auto&file='+urlencode(filedirname);
+
+	        jQuery.get(url, function(data) {
+	            //alert('Load of url '+url+' was performed : '+data);
+	            pos=data.indexOf("TYPE=directory",0);
+	            //alert(pos);
+	            if ((pos > 0) && (pos < 20))
+	            {
+	                filediractive=filedirname;    // Save current dirname
+	                filetypeactive='directory';
+	            }
+	            else
+	            {
+	                filediractive=filedirname;    // Save current dirname
+	                filetypeactive='file';
+	            }
+	            //jQuery('#fileview').append(data);
+	        });
+	    }
+
+		jQuery(document).ready( function() {
+    	    jQuery('#filetree').fileTree({ root: '<?php print dol_escape_js($openeddir); ?>',
+                       script: '<?php echo DOL_URL_ROOT.'/core/ajax/ajaxfiletree.php?modulepart=ecm&openeddir='.urlencode($openeddir); ?>',
+                       folderEvent: 'click',
+                       multiFolder: false  },
+                     function(file) {
+                    	   jQuery("#mesg").hide();
+                    	   loadandshowpreview(file);
+               		 }
+               );
+		});
+
+	    </script>
+	    <?php
+    }
+    else
+    {
 
+    	// Load full tree
+    	if (empty($sqltree)) $sqltree=$ecmdirstatic->get_full_arbo(0);
+
+    	// ----- This section will show a tree from a fulltree array -----
+    	// $section must also be defined
+    	// ----------------------------------------------------------------
+
+    	// Define fullpathselected ( _x_y_z ) of $section parameter
+    	$fullpathselected='';
+    	foreach($sqltree as $key => $val)
+    	{
+    		//print $val['id']."-".$section."<br>";
+    		if ($val['id'] == $section)
+    		{
+    			$fullpathselected=$val['fullpath'];
+    			break;
+    		}
+    	}
+    	//print "fullpathselected=".$fullpathselected."<br>";
+
+    	// Update expandedsectionarray in session
+    	$expandedsectionarray=array();
+    	if (isset($_SESSION['dol_ecmexpandedsectionarray'])) $expandedsectionarray=explode(',',$_SESSION['dol_ecmexpandedsectionarray']);
+
+    	if ($section && $_GET['sectionexpand'] == 'true')
+    	{
+    		// We add all sections that are parent of opened section
+    		$pathtosection=explode('_',$fullpathselected);
+    		foreach($pathtosection as $idcursor)
+    		{
+    			if ($idcursor && ! in_array($idcursor,$expandedsectionarray))	// Not already in array
+    			{
+    				$expandedsectionarray[]=$idcursor;
+    			}
+    		}
+    		$_SESSION['dol_ecmexpandedsectionarray']=join(',',$expandedsectionarray);
+    	}
+    	if ($section && $_GET['sectionexpand'] == 'false')
+    	{
+    		// We removed all expanded sections that are child of the closed section
+    		$oldexpandedsectionarray=$expandedsectionarray;
+    		$expandedsectionarray=array();	// Reset
+    		foreach($oldexpandedsectionarray as $sectioncursor)
+    		{
+    			// is_in_subtree(fulltree,sectionparent,sectionchild)
+    			if ($sectioncursor && ! is_in_subtree($sqltree,$section,$sectioncursor)) $expandedsectionarray[]=$sectioncursor;
+    		}
+    		$_SESSION['dol_ecmexpandedsectionarray']=join(',',$expandedsectionarray);
+    	}
+    	//print $_SESSION['dol_ecmexpandedsectionarray'].'<br>';
+
+    	$nbofentries=0;
+    	$oldvallevel=0;
+    	$var=true;
+    	foreach($sqltree as $key => $val)
+    	{
+    		$var=false;
+
+    		$ecmdirstatic->id=$val['id'];
+    		$ecmdirstatic->ref=$val['label'];
+
+    		// Refresh cache
+    		if (preg_match('/refresh/i',$_GET['action']))
+    		{
+    			$result=$ecmdirstatic->fetch($val['id']);
+    			$ecmdirstatic->ref=$ecmdirstatic->label;
+
+    			$result=$ecmdirstatic->refreshcachenboffile();
+    			$val['cachenbofdoc']=$result;
+    		}
+
+    		//$fullpathparent=preg_replace('/(_[^_]+)$/i','',$val['fullpath']);
+
+    		// Define showline
+    		$showline=0;
+
+    		// If directory is son of expanded directory, we show line
+    		if (in_array($val['id_mere'],$expandedsectionarray)) $showline=4;
+    		// If directory is brother of selected directory, we show line
+    		elseif ($val['id'] != $section && $val['id_mere'] == $ecmdirstatic->motherof[$section]) $showline=3;
+    		// If directory is parent of selected directory or is selected directory, we show line
+    		elseif (preg_match('/'.$val['fullpath'].'_/i',$fullpathselected.'_')) $showline=2;
+    		// If we are level one we show line
+    		elseif ($val['level'] < 2) $showline=1;
+
+    		if ($showline)
+    		{
+    			if (in_array($val['id'],$expandedsectionarray)) $option='indexexpanded';
+    			else $option='indexnotexpanded';
+    			//print $option;
+
+    			print '<tr>';
+
+    			// Show tree graph pictos
+    			print '<td align="left">';
+    			print '<table class="nobordernopadding"><tr class="nobordernopadding"><td>';
+    			$resarray=tree_showpad($sqltree,$key);
+    			$a=$resarray[0];
+    			$nbofsubdir=$resarray[1];
+    			$c=$resarray[2];
+    			$nboffilesinsubdir=$resarray[3];
+    			print '</td>';
+
+    			// Show picto
+    			print '<td valign="top">';
+    			//print $val['fullpath']."(".$showline.")";
+    			$n='2';
+    			if ($b == 0 || ! in_array($val['id'],$expandedsectionarray)) $n='3';
+    			if (! in_array($val['id'],$expandedsectionarray)) $ref=img_picto('',DOL_URL_ROOT.'/theme/common/treemenu/plustop'.$n.'.gif','',1);
+    			else $ref=img_picto('',DOL_URL_ROOT.'/theme/common/treemenu/minustop'.$n.'.gif','',1);
+    			if ($option == 'indexexpanded') $lien = '<a href="'.$_SERVER["PHP_SELF"].'?section='.$val['id'].'&amp;sectionexpand=false">';
+    	    	if ($option == 'indexnotexpanded') $lien = '<a href="'.$_SERVER["PHP_SELF"].'?section='.$val['id'].'&amp;sectionexpand=true">';
+    	    	//$newref=str_replace('_',' ',$ref);
+    	    	$newref=$ref;
+    	    	$lienfin='</a>';
+    	    	print $lien.$newref.$lienfin;
+    			if (! in_array($val['id'],$expandedsectionarray)) print img_picto($ecmdirstatic->ref,DOL_URL_ROOT.'/theme/common/treemenu/folder.gif','',1);
+    			else print img_picto($ecmdirstatic->ref,DOL_URL_ROOT.'/theme/common/treemenu/folder-expanded.gif','',1);
+    			print '</td>';
+    			// Show link
+    			print '<td valign="middle">';
+    			if ($section == $val['id']) print ' <u>';
+    			print $ecmdirstatic->getNomUrl(0,'index',32);
+    			if ($section == $val['id']) print '</u>';
+    			print '</td>';
+    			print '<td>&nbsp;</td>';
+    			print '</tr></table>';
+    			print "</td>\n";
+
+    			// Nb of docs
+    			print '<td align="right">';
+    			print $val['cachenbofdoc'];
+    			print '</td>';
+    			print '<td align="left">';
+    			if ($nbofsubdir && $nboffilesinsubdir) print '<font color="#AAAAAA">+'.$nboffilesinsubdir.'</font> ';
+    			print '</td>';
+
+    			// Edit link
+    			print '<td align="right"><a href="'.DOL_URL_ROOT.'/ecm/docmine.php?section='.$val['id'].'">'.img_view().'</a></td>';
+
+    			// Add link
+    			//print '<td align="right"><a href="'.DOL_URL_ROOT.'/ecm/docdir.php?action=create&amp;catParent='.$val['id'].'">'.img_edit_add().'</a></td>';
+    			print '<td align="right">&nbsp;</td>';
+
+    			// Info
+    			print '<td align="center">';
+    			$userstatic->id=$val['fk_user_c'];
+    			$userstatic->lastname=$val['login_c'];
+    			$htmltooltip='<b>'.$langs->trans("ECMSection").'</b>: '.$val['label'].'<br>';
+    			$htmltooltip='<b>'.$langs->trans("Type").'</b>: '.$langs->trans("ECMSectionManual").'<br>';
+    			$htmltooltip.='<b>'.$langs->trans("ECMCreationUser").'</b>: '.$userstatic->getNomUrl(1).'<br>';
+    			$htmltooltip.='<b>'.$langs->trans("ECMCreationDate").'</b>: '.dol_print_date($val['date_c'],"dayhour").'<br>';
+    			$htmltooltip.='<b>'.$langs->trans("Description").'</b>: '.$val['description'].'<br>';
+    			$htmltooltip.='<b>'.$langs->trans("ECMNbOfFilesInDir").'</b>: '.$val['cachenbofdoc'].'<br>';
+    			if ($nbofsubdir) $htmltooltip.='<b>'.$langs->trans("ECMNbOfFilesInSubDir").'</b>: '.$nboffilesinsubdir;
+    			else $htmltooltip.='<b>'.$langs->trans("ECMNbOfSubDir").'</b>: '.$nbofsubdir.'<br>';
+    			print $form->textwithpicto('',$htmltooltip,1,0);
+    			print "</td>";
+
+    			print "</tr>\n";
+    		}
+
+    		$oldvallevel=$val['level'];
+    		$nbofentries++;
+    	}
+
+    	// If nothing to show
+    	if ($nbofentries == 0)
+    	{
+    		print '<tr>';
+    		print '<td class="left"><table class="nobordernopadding"><tr class="nobordernopadding"><td>'.img_picto_common('','treemenu/branchbottom.gif').'</td>';
+    		print '<td>'.img_picto('',DOL_URL_ROOT.'/theme/common/treemenu/minustop3.gif','',1).'</td>';
+    		print '<td valign="middle">';
+    		print $langs->trans("ECMNoDirecotyYet");
+    		print '</td>';
+    		print '<td>&nbsp;</td>';
+    		print '</table></td>';
+    		print '<td colspan="5">&nbsp;</td>';
+    		print '</tr>';
+    	}
+    }
 
-	// Load full tree
-	if (empty($sqltree)) $sqltree=$ecmdirstatic->get_full_arbo(0);
-
-	// ----- This section will show a tree from a fulltree array -----
-	// $section must also be defined
-	// ----------------------------------------------------------------
-
-	// Define fullpathselected ( _x_y_z ) of $section parameter
-	$fullpathselected='';
-	foreach($sqltree as $key => $val)
-	{
-		//print $val['id']."-".$section."<br>";
-		if ($val['id'] == $section)
-		{
-			$fullpathselected=$val['fullpath'];
-			break;
-		}
-	}
-	//print "fullpathselected=".$fullpathselected."<br>";
-
-	// Update expandedsectionarray in session
-	$expandedsectionarray=array();
-	if (isset($_SESSION['dol_ecmexpandedsectionarray'])) $expandedsectionarray=explode(',',$_SESSION['dol_ecmexpandedsectionarray']);
-
-	if ($section && $_GET['sectionexpand'] == 'true')
-	{
-		// We add all sections that are parent of opened section
-		$pathtosection=explode('_',$fullpathselected);
-		foreach($pathtosection as $idcursor)
-		{
-			if ($idcursor && ! in_array($idcursor,$expandedsectionarray))	// Not already in array
-			{
-				$expandedsectionarray[]=$idcursor;
-			}
-		}
-		$_SESSION['dol_ecmexpandedsectionarray']=join(',',$expandedsectionarray);
-	}
-	if ($section && $_GET['sectionexpand'] == 'false')
-	{
-		// We removed all expanded sections that are child of the closed section
-		$oldexpandedsectionarray=$expandedsectionarray;
-		$expandedsectionarray=array();	// Reset
-		foreach($oldexpandedsectionarray as $sectioncursor)
-		{
-			// is_in_subtree(fulltree,sectionparent,sectionchild)
-			if ($sectioncursor && ! is_in_subtree($sqltree,$section,$sectioncursor)) $expandedsectionarray[]=$sectioncursor;
-		}
-		$_SESSION['dol_ecmexpandedsectionarray']=join(',',$expandedsectionarray);
-	}
-	//print $_SESSION['dol_ecmexpandedsectionarray'].'<br>';
-
-	$nbofentries=0;
-	$oldvallevel=0;
-	$var=true;
-	foreach($sqltree as $key => $val)
-	{
-		$var=false;
-
-		$ecmdirstatic->id=$val['id'];
-		$ecmdirstatic->ref=$val['label'];
-
-		// Refresh cache
-		if (preg_match('/refresh/i',$_GET['action']))
-		{
-			$result=$ecmdirstatic->fetch($val['id']);
-			$ecmdirstatic->ref=$ecmdirstatic->label;
-
-			$result=$ecmdirstatic->refreshcachenboffile();
-			$val['cachenbofdoc']=$result;
-		}
-
-		//$fullpathparent=preg_replace('/(_[^_]+)$/i','',$val['fullpath']);
-
-		// Define showline
-		$showline=0;
-
-		// If directory is son of expanded directory, we show line
-		if (in_array($val['id_mere'],$expandedsectionarray)) $showline=4;
-		// If directory is brother of selected directory, we show line
-		elseif ($val['id'] != $section && $val['id_mere'] == $ecmdirstatic->motherof[$section]) $showline=3;
-		// If directory is parent of selected directory or is selected directory, we show line
-		elseif (preg_match('/'.$val['fullpath'].'_/i',$fullpathselected.'_')) $showline=2;
-		// If we are level one we show line
-		elseif ($val['level'] < 2) $showline=1;
-
-		if ($showline)
-		{
-			if (in_array($val['id'],$expandedsectionarray)) $option='indexexpanded';
-			else $option='indexnotexpanded';
-			//print $option;
-
-			print '<tr>';
-
-			// Show tree graph pictos
-			print '<td align="left">';
-			print '<table class="nobordernopadding"><tr class="nobordernopadding"><td>';
-			$resarray=tree_showpad($sqltree,$key);
-			$a=$resarray[0];
-			$nbofsubdir=$resarray[1];
-			$c=$resarray[2];
-			$nboffilesinsubdir=$resarray[3];
-			print '</td>';
-
-			// Show picto
-			print '<td valign="top">';
-			//print $val['fullpath']."(".$showline.")";
-			$n='2';
-			if ($b == 0 || ! in_array($val['id'],$expandedsectionarray)) $n='3';
-			if (! in_array($val['id'],$expandedsectionarray)) $ref=img_picto('',DOL_URL_ROOT.'/theme/common/treemenu/plustop'.$n.'.gif','',1);
-			else $ref=img_picto('',DOL_URL_ROOT.'/theme/common/treemenu/minustop'.$n.'.gif','',1);
-			if ($option == 'indexexpanded') $lien = '<a href="'.$_SERVER["PHP_SELF"].'?section='.$val['id'].'&amp;sectionexpand=false">';
-	    	if ($option == 'indexnotexpanded') $lien = '<a href="'.$_SERVER["PHP_SELF"].'?section='.$val['id'].'&amp;sectionexpand=true">';
-	    	//$newref=str_replace('_',' ',$ref);
-	    	$newref=$ref;
-	    	$lienfin='</a>';
-	    	print $lien.$newref.$lienfin;
-			if (! in_array($val['id'],$expandedsectionarray)) print img_picto($ecmdirstatic->ref,DOL_URL_ROOT.'/theme/common/treemenu/folder.gif','',1);
-			else print img_picto($ecmdirstatic->ref,DOL_URL_ROOT.'/theme/common/treemenu/folder-expanded.gif','',1);
-			print '</td>';
-			// Show link
-			print '<td valign="middle">';
-			if ($section == $val['id']) print ' <u>';
-			print $ecmdirstatic->getNomUrl(0,'index',32);
-			if ($section == $val['id']) print '</u>';
-			print '</td>';
-			print '<td>&nbsp;</td>';
-			print '</tr></table>';
-			print "</td>\n";
-
-			// Nb of docs
-			print '<td align="right">';
-			print $val['cachenbofdoc'];
-			print '</td>';
-			print '<td align="left">';
-			if ($nbofsubdir && $nboffilesinsubdir) print '<font color="#AAAAAA">+'.$nboffilesinsubdir.'</font> ';
-			print '</td>';
-
-			// Edit link
-			print '<td align="right"><a href="'.DOL_URL_ROOT.'/ecm/docmine.php?section='.$val['id'].'">'.img_view().'</a></td>';
-
-			// Add link
-			//print '<td align="right"><a href="'.DOL_URL_ROOT.'/ecm/docdir.php?action=create&amp;catParent='.$val['id'].'">'.img_edit_add().'</a></td>';
-			print '<td align="right">&nbsp;</td>';
-
-			// Info
-			print '<td align="center">';
-			$userstatic->id=$val['fk_user_c'];
-			$userstatic->lastname=$val['login_c'];
-			$htmltooltip='<b>'.$langs->trans("ECMSection").'</b>: '.$val['label'].'<br>';
-			$htmltooltip='<b>'.$langs->trans("Type").'</b>: '.$langs->trans("ECMSectionManual").'<br>';
-			$htmltooltip.='<b>'.$langs->trans("ECMCreationUser").'</b>: '.$userstatic->getNomUrl(1).'<br>';
-			$htmltooltip.='<b>'.$langs->trans("ECMCreationDate").'</b>: '.dol_print_date($val['date_c'],"dayhour").'<br>';
-			$htmltooltip.='<b>'.$langs->trans("Description").'</b>: '.$val['description'].'<br>';
-			$htmltooltip.='<b>'.$langs->trans("ECMNbOfFilesInDir").'</b>: '.$val['cachenbofdoc'].'<br>';
-			if ($nbofsubdir) $htmltooltip.='<b>'.$langs->trans("ECMNbOfFilesInSubDir").'</b>: '.$nboffilesinsubdir;
-			else $htmltooltip.='<b>'.$langs->trans("ECMNbOfSubDir").'</b>: '.$nbofsubdir.'<br>';
-			print $form->textwithpicto('',$htmltooltip,1,0);
-			print "</td>";
-
-			print "</tr>\n";
-		}
-
-		$oldvallevel=$val['level'];
-		$nbofentries++;
-	}
-
-	// If nothing to show
-	if ($nbofentries == 0)
-	{
-		print '<tr>';
-		print '<td class="left"><table class="nobordernopadding"><tr class="nobordernopadding"><td>'.img_picto_common('','treemenu/branchbottom.gif').'</td>';
-		print '<td>'.img_picto('',DOL_URL_ROOT.'/theme/common/treemenu/minustop3.gif','',1).'</td>';
-		print '<td valign="middle">';
-		print $langs->trans("ECMNoDirecotyYet");
-		print '</td>';
-		print '<td>&nbsp;</td>';
-		print '</table></td>';
-		print '<td colspan="5">&nbsp;</td>';
-		print '</tr>';
-	}
-
-
-	// ----- End of section -----
-	// --------------------------
 
 	print "</table>";
-	// Fin de zone Ajax
-
-
-
 }
 
+
+// End left banner
 if ($conf->use_javascript_ajax)
 {
 ?>
     </div>
-
     <div id="ecm-layout-center" class="hidden">
-
-        <div class="pane-in ecm-in-layout-center">
+    <div class="pane-in ecm-in-layout-center">
 <?php
 }
 else
 {
     print '</td><td valign="top" style="background: #FFFFFF">';
 }
+// Start right panel
+
+
 
 $formfile=new FormFile($db);
 
@@ -894,30 +943,27 @@ else    // Manual area
     $formfile->list_of_documents($filearray,'','ecm',$param,1,$relativepath,$user->rights->ecm->upload,1,$textifempty,$maxlengthname);
 }
 
-//	print '<table width="100%" class="border">';
-
-//	print '<tr><td> </td></tr></table>';
-
 
 
+// End right panel
 if ($conf->use_javascript_ajax)
 {
 ?>
-        </div>
-        <div class="pane-in ecm-in-layout-south layout-padding">
+    </div>
+    <div class="pane-in ecm-in-layout-south layout-padding">
 <?php
 }
 else
 {
     print '</td></tr>';
-
-    // Actions attach new file
     print '<tr height="22">';
-    //print '<td align="center">';
-    //print '</td>';
     print '<td>';
 }
+// Start Add new file area
 
+
+
+// To attach new file
 if (! empty($section))
 {
 	$formfile->form_attach_new_file(DOL_URL_ROOT.'/ecm/index.php', 'none', 0, $section,$user->rights->ecm->upload, 48);
@@ -925,27 +971,26 @@ if (! empty($section))
 else print '&nbsp;';
 
 
+
+// End Add new file area
 if ($conf->use_javascript_ajax)
 {
 ?>
-        </div>
     </div>
-
-</div> <!-- end div id="containerlayout" -->
-
-
+    </div>
+	</div> <!-- end div id="containerlayout" -->
 <?php
 }
 else
 {
     print '</td></tr>';
-
     print '</table>';
 }
+// End of page
 
 
-// End of page
-$db->close();
 
 llxFooter();
+
+$db->close();
 ?>
diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php
index 8b5be34f969538f4391113982890b240e4b85267..68a005d62f859769914eb4b775151ebbc12e1da7 100644
--- a/htdocs/main.inc.php
+++ b/htdocs/main.inc.php
@@ -900,9 +900,6 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs
 		// Output standard javascript links
 		if (! $disablejs && $conf->use_javascript_ajax)
 		{
-			// Other external js
-			require_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
-
 			$ext='.js';
 			if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x01)) { $ext='.jgz'; }	// mini='_mini', ext='.gz'