diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php
index 34e88dd893e1f407c36bf115ab26e6ee8fe4dff3..56fb713ae0c7ac6c25c743990a2b247bc111651c 100644
--- a/htdocs/comm/action/class/actioncomm.class.php
+++ b/htdocs/comm/action/class/actioncomm.class.php
@@ -57,7 +57,7 @@ class ActionComm extends CommonObject
     var $datef;			// Date action end (datep2)
     var $durationp = -1;      // -1=Unkown duration			// deprecated
     var $fulldayevent = 0;    // 1=Event on full day
-    var $punctual = 1;        // Milestone					// TODO Not sure we need this. Milestone is already event with end date = start date
+    var $punctual = 1;        // Milestone					// deprecated. Milestone is already event with end date = start date
     var $percentage;    // Percentage
     var $location;      // Location
 
diff --git a/htdocs/comm/action/listactions.php b/htdocs/comm/action/listactions.php
index 245902013a189bbce8196024e062f2e434572990..7fa67695860e5284b6a41f3821a52aef4eb7a87a 100644
--- a/htdocs/comm/action/listactions.php
+++ b/htdocs/comm/action/listactions.php
@@ -180,7 +180,7 @@ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as ut ON a.fk_user_action = ut.rowid";
 if ($usergroup > 0) $sql.= ", ".MAIN_DB_PREFIX."usergroup_user as ugu";
 $sql.= " WHERE c.id = a.fk_action";
 $sql.= ' AND a.fk_user_author = u.rowid';
-$sql.= ' AND a.entity IN ('.getEntity('agenda', 1).')';    // To limit to entity
+$sql.= ' AND a.entity IN ('.getEntity('agenda', 1).')';
 if ($actioncode) $sql.=" AND c.code='".$db->escape($actioncode)."'";
 if ($pid) $sql.=" AND a.fk_project=".$db->escape($pid);
 if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND (a.fk_soc IS NULL OR sc.fk_user = " .$user->id . ")";
diff --git a/htdocs/comm/action/peruser.php b/htdocs/comm/action/peruser.php
index dcebefbcbb725e7eda8f625d5e539b2d9dfaf120..22cf8841c0253679733b3cb5a7f0b3a253a90ae6 100644
--- a/htdocs/comm/action/peruser.php
+++ b/htdocs/comm/action/peruser.php
@@ -610,7 +610,7 @@ else
 	$sql = "SELECT u.rowid, u.lastname as lastname, u.firstname, u.statut, u.login, u.admin, u.entity";
 	$sql.= " FROM ".MAIN_DB_PREFIX."user as u";
 	if ($usergroup > 0)	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ug ON u.rowid = ug.fk_user";
-	$sql.= " WHERE u.entity IN (".getEntity('user').")";
+	$sql.= " WHERE u.entity IN (".getEntity('user',1).")";
 	if ($usergroup > 0)	$sql.= " AND ug.fk_usergroup = ".$usergroup;
 	if (GETPOST("usertodo","int",3) > 0) $sql.=" AND u.rowid = ".GETPOST("usertodo","int",3);
 	//print $sql;
diff --git a/htdocs/comm/action/rapport/index.php b/htdocs/comm/action/rapport/index.php
index a9a19f57a9e9f1f1caa11d0ffb1394b92cdd5056..24eb117684f2fa119622f82d5edb1152af6df647 100644
--- a/htdocs/comm/action/rapport/index.php
+++ b/htdocs/comm/action/rapport/index.php
@@ -1,7 +1,7 @@
 <?php
 /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  * Copyright (C) 2003      Eric Seigne          <erics@rycks.com>
- * Copyright (C) 2004-2009 Laurent Destailleur  <eldy@users.sourceforge.net>
+ * Copyright (C) 2004-2014 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2005-2012 Regis Houssin        <regis.houssin@capnetworks.com>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -55,6 +55,7 @@ $result = restrictedArea($user, 'agenda', $socid, '', 'myactions');
 /*
  * Actions
  */
+
 if ($action == 'builddoc')
 {
 	$cat = new CommActionRapport($db, $month, $year);
@@ -79,7 +80,7 @@ $sql.= " date_format(a.datep, '%Y') as year";
 $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a,";
 $sql.= " ".MAIN_DB_PREFIX."user as u";
 $sql.= " WHERE a.fk_user_author = u.rowid";
-$sql.= " AND a.entity = ".$conf->entity;
+$sql.= ' AND a.entity IN ('.getEntity('agenda', 1).')';
 //$sql.= " AND percent = 100";
 $sql.= " GROUP BY year, month, df";
 $sql.= " ORDER BY year DESC, month DESC, df DESC";
diff --git a/htdocs/contact/canvas/default/tpl/contactcard_create.tpl.php b/htdocs/contact/canvas/default/tpl/contactcard_create.tpl.php
index a0605d3656ea0f38f9c966f0561fbe8666208d75..70d6b41bf3516de2baf224698402ca46d2ddd051 100644
--- a/htdocs/contact/canvas/default/tpl/contactcard_create.tpl.php
+++ b/htdocs/contact/canvas/default/tpl/contactcard_create.tpl.php
@@ -50,7 +50,7 @@ echo $this->control->tpl['ajax_selectcountry']; ?>
 </tr>
 
 <tr>
-	<td><?php echo $langs->trans("Company"); ?></td>
+	<td><?php echo $langs->trans("ThirdParty"); ?></td>
 	<td colspan="3"><?php echo $this->control->tpl['company']; ?></td>
 </tr>
 
diff --git a/htdocs/contact/canvas/default/tpl/contactcard_edit.tpl.php b/htdocs/contact/canvas/default/tpl/contactcard_edit.tpl.php
index a445444e42cd3f0965743ff661d12903e4a37094..3be1d16bc8dd6fe239bf638aaa8f6dae86e28acd 100644
--- a/htdocs/contact/canvas/default/tpl/contactcard_edit.tpl.php
+++ b/htdocs/contact/canvas/default/tpl/contactcard_edit.tpl.php
@@ -59,7 +59,7 @@ echo $this->control->tpl['ajax_selectcountry'];
 </tr>
 
 <tr>
-	<td><?php echo $langs->trans("Company"); ?></td>
+	<td><?php echo $langs->trans("ThirdParty"); ?></td>
 	<td colspan="3"><?php echo $this->control->tpl['company']; ?></td>
 </tr>
 
diff --git a/htdocs/contact/canvas/default/tpl/contactcard_view.tpl.php b/htdocs/contact/canvas/default/tpl/contactcard_view.tpl.php
index 623fad27e778fa127510815b429811feda712e7a..0b4b8a07fcb2d257727f03240ce46858a5931720 100644
--- a/htdocs/contact/canvas/default/tpl/contactcard_view.tpl.php
+++ b/htdocs/contact/canvas/default/tpl/contactcard_view.tpl.php
@@ -44,7 +44,7 @@ dol_htmloutput_errors($this->control->tpl['error'],$this->control->tpl['errors']
 </tr>
 
 <tr>
-	<td><?php echo $langs->trans("Company"); ?></td>
+	<td><?php echo $langs->trans("ThirdParty"); ?></td>
 	<td colspan="3"><?php echo $this->control->tpl['company']; ?></td>
 </tr>
 
diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php
index bcdea083c3f76cf85621b05f475f6ccf49080a40..a1030a682926ee748063b0ee937d64f0f6339adc 100644
--- a/htdocs/contact/card.php
+++ b/htdocs/contact/card.php
@@ -456,7 +456,7 @@ else
             {
                 if ($socid > 0)
                 {
-                    print '<tr><td><label for="socid">'.$langs->trans("Company").'</label></td>';
+                    print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td>';
                     print '<td colspan="3" class="maxwidthonsmartphone">';
                     print $objsoc->getNomUrl(1);
                     print '</td>';
@@ -464,7 +464,7 @@ else
                     print '</td></tr>';
                 }
                 else {
-                    print '<tr><td><label for="socid">'.$langs->trans("Company").'</label></td><td colspan="3" class="maxwidthonsmartphone">';
+                    print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td><td colspan="3" class="maxwidthonsmartphone">';
                     print $form->select_company($socid,'socid','',1);
                     print '</td></tr>';
                 }
@@ -690,7 +690,7 @@ else
             // Company
             if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
             {
-                print '<tr><td><label for="socid">'.$langs->trans("Company").'</label></td>';
+                print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td>';
                 print '<td colspan="3" class="maxwidthonsmartphone">';
                 print $form->select_company(GETPOST('socid','int')?GETPOST('socid','int'):($object->socid?$object->socid:-1),'socid','',1);
                 print '</td>';
@@ -924,7 +924,7 @@ else
         // Company
         if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
         {
-            print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">';
+            print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
             if ($object->socid > 0)
             {
                 $objsoc->fetch($object->socid);
diff --git a/htdocs/contact/exportimport.php b/htdocs/contact/exportimport.php
index bcb3b9c2be03385410275d1bf59f716172dc36bb..e9e9c70966c9f996836a10d14fc9af1e711f2b3e 100644
--- a/htdocs/contact/exportimport.php
+++ b/htdocs/contact/exportimport.php
@@ -77,11 +77,11 @@ if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
     	$objsoc = new Societe($db);
     	$objsoc->fetch($contact->socid);
 
-    	print '<tr><td width="15%">'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
+    	print '<tr><td width="15%">'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
     }
     else
     {
-    	print '<tr><td width="15%">'.$langs->trans("Company").'</td><td colspan="3">';
+    	print '<tr><td width="15%">'.$langs->trans("ThirdParty").'</td><td colspan="3">';
     	print $langs->trans("ContactNotLinkedToCompany");
     	print '</td></tr>';
     }
diff --git a/htdocs/contact/ldap.php b/htdocs/contact/ldap.php
index fe3098eaa9a260d0e488e9b3ecf2c4ff0fb6361b..170ed03990458e6272fe9aeb8b0b4d2cb482ad10 100644
--- a/htdocs/contact/ldap.php
+++ b/htdocs/contact/ldap.php
@@ -105,11 +105,11 @@ if ($contact->socid > 0)
 	$objsoc = new Societe($db);
 	$objsoc->fetch($contact->socid);
 
-	print '<tr><td width="20%">'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
+	print '<tr><td width="20%">'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
 }
 else
 {
-	print '<tr><td width="20%">'.$langs->trans("Company").'</td><td colspan="3">';
+	print '<tr><td width="20%">'.$langs->trans("ThirdParty").'</td><td colspan="3">';
 	print $langs->trans("ContactNotLinkedToCompany");
 	print '</td></tr>';
 }
diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php
index eab4369ac21d9dbca991abccb6ef473a806af578..4413b721fc9cdf6eb738c9d3bfc1b047a9fcb0f6 100644
--- a/htdocs/contact/list.php
+++ b/htdocs/contact/list.php
@@ -300,7 +300,7 @@ if ($result)
     print_liste_field_titre($langs->trans("Lastname"),$_SERVER["PHP_SELF"],"p.lastname", $begin, $param, '', $sortfield,$sortorder);
     print_liste_field_titre($langs->trans("Firstname"),$_SERVER["PHP_SELF"],"p.firstname", $begin, $param, '', $sortfield,$sortorder);
     print_liste_field_titre($langs->trans("PostOrFunction"),$_SERVER["PHP_SELF"],"p.poste", $begin, $param, '', $sortfield,$sortorder);
-    if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom", $begin, $param, '', $sortfield,$sortorder);
+    if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) print_liste_field_titre($langs->trans("ThirdParty"),$_SERVER["PHP_SELF"],"s.nom", $begin, $param, '', $sortfield,$sortorder);
     print_liste_field_titre($langs->trans("Phone"),$_SERVER["PHP_SELF"],"p.phone", $begin, $param, '', $sortfield,$sortorder);
     print_liste_field_titre($langs->trans("PhoneMobile"),$_SERVER["PHP_SELF"],"p.phone_mobile", $begin, $param, '', $sortfield,$sortorder);
     print_liste_field_titre($langs->trans("Fax"),$_SERVER["PHP_SELF"],"p.fax", $begin, $param, '', $sortfield,$sortorder);
diff --git a/htdocs/contact/note.php b/htdocs/contact/note.php
index 73b0f513db97e75b81b931dab90b47e71dc05fec..ab8101dd73992cf5f184da49d6479bfb8fd69cc7 100644
--- a/htdocs/contact/note.php
+++ b/htdocs/contact/note.php
@@ -98,12 +98,12 @@ if ($id > 0)
     		$objsoc = new Societe($db);
     		$objsoc->fetch($object->socid);
 
-    		print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
+    		print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
     	}
 
     	else
     	{
-    		print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">';
+    		print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
     		print $langs->trans("ContactNotLinkedToCompany");
     		print '</td></tr>';
     	}
diff --git a/htdocs/contact/perso.php b/htdocs/contact/perso.php
index 19644fe5bf5962a02abbcbd39d2b50bfe4ce20bb..173ccbcb265f2923c950533ac98d4e9354f70afd 100644
--- a/htdocs/contact/perso.php
+++ b/htdocs/contact/perso.php
@@ -111,11 +111,11 @@ if ($action == 'edit')
             $objsoc = new Societe($db);
             $objsoc->fetch($object->socid);
 
-            print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td>';
+            print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td>';
         }
         else
         {
-            print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">';
+            print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
             print $langs->trans("ContactNotLinkedToCompany");
             print '</td></tr>';
         }
@@ -179,12 +179,12 @@ else
             $objsoc = new Societe($db);
             $objsoc->fetch($object->socid);
 
-            print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
+            print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
         }
 
         else
         {
-            print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">';
+            print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
             print $langs->trans("ContactNotLinkedToCompany");
             print '</td></tr>';
         }
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 14b7c78cc7d0ce421baa1cf35050640dda3465ce..9feca9a70614450541e1198bb0cdabe92c672129 100755
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -827,7 +827,7 @@ class Form
 				{
 					if (count($events))		// Add management of event
 					{
-						print '<script type="text/javascript">
+						$out.='<script type="text/javascript">
 								$(document).ready(function() {
 									jQuery("#'.$htmlname.'").change(function () {
 										var obj = '.json_encode($events).';
diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php
index 8e749cfa9b761eab1554693a01ef7309261b4139..47325a9a34578f17ca4114a2ce66f4313c2ee3fe 100644
--- a/htdocs/core/class/html.formfile.class.php
+++ b/htdocs/core/class/html.formfile.class.php
@@ -271,13 +271,13 @@ class FormFile
         if (! empty($iconPDF)) {
         	return $this->getDocumentsLink($modulepart, $modulesubdir, $filedir);
         }
-        
+
         $printer=0;
         if (in_array($modulepart,array('facture','propal','proposal','order','commande')))	// This feature is implemented only for such elements
         {
         	$printer = (!empty($user->rights->printipp->read) && !empty($conf->printipp->enabled))?true:false;
         }
-        
+
         $hookmanager->initHooks(array('formfile'));
         $forname='builddoc';
         $out='';
@@ -1101,6 +1101,8 @@ class FormFile
         global $bc;
         global $sortfield, $sortorder;
 
+        $langs->load("link");
+
         require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
         $link = new Link($this->db);
         $links = array();
@@ -1162,7 +1164,7 @@ class FormFile
         $nboflinks = count($links);
         if ($nboflinks > 0) include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
 
-        $var = false;
+        $var = true;
         foreach ($links as $link)
         {
             $var =! $var;
diff --git a/htdocs/install/check.php b/htdocs/install/check.php
index 2d3c3b6ec668382034fc32e217b7f57eba5f0ef5..f7f5ae4b960bc79155621d27eb21a48390292975 100644
--- a/htdocs/install/check.php
+++ b/htdocs/install/check.php
@@ -71,12 +71,12 @@ if (! empty($useragent))
 
 
 // Check PHP version
-if (versioncompare(versionphparray(),array(4,3,10)) < 0)        // Minimum to use (error if lower)
+if (versioncompare(versionphparray(),array(5,2,3)) < 0)        // Minimum to use (error if lower)
 {
-	print '<img src="../theme/eldy/img/error.png" alt="Error"> '.$langs->trans("ErrorPHPVersionTooLow",'4.3.10');
+	print '<img src="../theme/eldy/img/error.png" alt="Error"> '.$langs->trans("ErrorPHPVersionTooLow",'5.2.3');
 	$checksok=0;	// 0=error, 1=warning
 }
-else if (versioncompare(versionphparray(),array(5,3,0)) < 0)    // Minimum supported (error if lower)
+else if (versioncompare(versionphparray(),array(5,3,0)) < 0)    // Minimum supported (warning if lower)
 {
     print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("ErrorPHPVersionTooLow",'5.3.0');
     $checksok=0;	// 0=error, 1=warning
diff --git a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql
index 40a7f7b86c68188d0a119fbeb6bac4174bbb469d..e2c586de47fdd807a88327fbaed6baf02c02e021 100755
--- a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql
+++ b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql
@@ -1140,6 +1140,8 @@ ALTER TABLE llx_facture_rec ADD COLUMN revenuestamp double(24,8) DEFAULT 0;
 ALTER TABLE llx_facturedet_rec MODIFY COLUMN tva_tx double(6,3);
 ALTER TABLE llx_facturedet_rec ADD COLUMN fk_contract_line integer NULL;
 
+ALTER TABLE llx_resource MODIFY COLUMN entity integer DEFAULT 1 NOT NULL;
+
 -- This request make mysql drop (mysql bug, so we add it at end):
 --ALTER TABLE llx_product ADD CONSTRAINT fk_product_barcode_type FOREIGN KEY (fk_barcode_type) REFERENCES llx_c_barcode_type(rowid);
 
diff --git a/htdocs/install/mysql/tables/llx_actioncomm.sql b/htdocs/install/mysql/tables/llx_actioncomm.sql
index c42cf377b8533d89a4c93c9a2ba16b9ea48858a6..f68d99f6a726c9df74ca2e8c9693aac7ab28d06e 100644
--- a/htdocs/install/mysql/tables/llx_actioncomm.sql
+++ b/htdocs/install/mysql/tables/llx_actioncomm.sql
@@ -51,10 +51,10 @@ create table llx_actioncomm
   
   priority			smallint,
   fulldayevent		smallint NOT NULL default 0,
-  punctual			smallint NOT NULL default 1,
+  punctual			smallint NOT NULL default 1, -- deprecated. milestone is event with date start = date end
   percent			smallint NOT NULL default 0,
   location			varchar(128),
-  durationp			real,							-- duree planifiee
+  durationp			real,							-- planed duration
   durationa			real,							-- deprecated
   note				text,
   
diff --git a/htdocs/install/mysql/tables/llx_resource.sql b/htdocs/install/mysql/tables/llx_resource.sql
index 91ebbe8b75da8bdbea501b295efa4d273103b20b..0d67075f1ea6323ebb43bbe0d12ea4f0bd32125e 100755
--- a/htdocs/install/mysql/tables/llx_resource.sql
+++ b/htdocs/install/mysql/tables/llx_resource.sql
@@ -17,7 +17,7 @@
 CREATE TABLE llx_resource
 (
   rowid           		integer AUTO_INCREMENT PRIMARY KEY,
-  entity          		integer,
+  entity          		integer DEFAULT 1 NOT NULL,
   ref             		varchar(255),
   description     		text,
   fk_code_type_resource varchar(32),
diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang
index 2febc9288c36516c2049086a614c25b42c2a1ccc..1110705e0e4bdaa0de6b76f18bd757b965b0ef37 100755
--- a/htdocs/langs/en_US/admin.lang
+++ b/htdocs/langs/en_US/admin.lang
@@ -783,6 +783,7 @@ DictionaryOrderMethods=Ordering methods
 DictionarySource=Origin of proposals/orders
 DictionaryAccountancyplan=Chart of accounts
 DictionaryAccountancysystem=Models for chart of accounts
+DictionaryEMailTemplates=Emails templates
 SetupSaved=Setup saved
 BackToModuleList=Back to modules list
 BackToDictionaryList=Back to dictionaries list
diff --git a/htdocs/langs/en_US/resource.lang b/htdocs/langs/en_US/resource.lang
index d64075dfbf595897a63e3eebf19194d8f71030dd..32bdd92f884785546c5345ebe4e9ebea1f563956 100644
--- a/htdocs/langs/en_US/resource.lang
+++ b/htdocs/langs/en_US/resource.lang
@@ -31,6 +31,4 @@ ConfirmDeleteResource=Confirm to delete this resource
 RessourceSuccessfullyDeleted=Resource successfully deleted
 DictionaryResourceType=Type of resources
 
-DictionaryEMailTemplates=Modèles d'Emails
-
 SelectResource=Select resource
diff --git a/htdocs/opensurvey/list.php b/htdocs/opensurvey/list.php
index 83482bbe04fbed321ad2daadc9167d00f2285460..d21a08007a48cebdefd2c071ffeae7678718f232 100644
--- a/htdocs/opensurvey/list.php
+++ b/htdocs/opensurvey/list.php
@@ -123,7 +123,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
 	$result = $db->query($sql);
 	$nbtotalofrecords = $db->num_rows($result);
 }
-$sql.= " WHERE p.entity = ".getEntity('survey');
+$sql.= " WHERE p.entity = ".getEntity('survey',1);
 if ($status == 'expired') $sql.=" AND date_fin < '".$db->idate($now)."'";
 if ($status == 'opened') $sql.=" AND date_fin >= '".$db->idate($now)."'";
 if ($surveytitle) $sql.=" AND titre LIKE '%".$db->escape($surveytitle)."%'";
diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php
index 738eec46ec097317524953011207fdcd977345e2..ec449f009c7a80ccc97b44911f0ca1bc165555e1 100644
--- a/htdocs/projet/class/project.class.php
+++ b/htdocs/projet/class/project.class.php
@@ -298,7 +298,7 @@ class Project extends CommonObject
         else if (! empty($ref))
         {
         	$sql.= " WHERE ref='".$this->db->escape($ref)."'";
-        	$sql.= " AND entity IN (".getEntity('project').")";
+        	$sql.= " AND entity IN (".getEntity('project',1).")";
         }
 
         dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
@@ -910,7 +910,7 @@ class Project extends CommonObject
             $sql.= ", " . MAIN_DB_PREFIX . "element_contact as ec";
             $sql.= ", " . MAIN_DB_PREFIX . "c_type_contact as ctc";
         }
-        $sql.= " WHERE p.entity IN (".getEntity('project').")";
+        $sql.= " WHERE p.entity IN (".getEntity('project',1).")";
         // Internal users must see project he is contact to even if project linked to a third party he can't see.
         //if ($socid || ! $user->rights->societe->client->voir)	$sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
         if ($socid > 0) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = " . $socid . ")";
diff --git a/htdocs/resource/class/resource.class.php b/htdocs/resource/class/resource.class.php
index a7be5d0d25ace79f1af95f3638909c706ff49d1b..c75f37b00c28c011b632be7cfa763786e01285f6 100644
--- a/htdocs/resource/class/resource.class.php
+++ b/htdocs/resource/class/resource.class.php
@@ -388,7 +388,7 @@ class Resource extends CommonObject
     	$sql.= " ty.label as type_label";
     	$sql.= " FROM ".MAIN_DB_PREFIX."resource as t";
     	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_resource as ty ON ty.code=t.fk_code_type_resource";
-    	//$sql.= " WHERE t.entity IN (".getEntity('resource').")";
+    	$sql.= " WHERE t.entity IN (".getEntity('resource',1).")";
 
     	//Manage filter
     	if (!empty($filter)){
@@ -402,7 +402,7 @@ class Resource extends CommonObject
     		}
     	}
     	$sql.= " GROUP BY t.rowid";
-    	$sql.= " ORDER BY $sortfield $sortorder ";
+    	$sql.= $this->db->order($sortfield,$sortorder);
     	if ($limit) $sql.= $this->db->plimit($limit+1,$offset);
     	dol_syslog(get_class($this)."::fetch_all", LOG_DEBUG);
 
@@ -462,7 +462,7 @@ class Resource extends CommonObject
 		$sql.= " t.fk_user_create,";
 		$sql.= " t.tms";
    		$sql.= ' FROM '.MAIN_DB_PREFIX .'element_resources as t ';
-   		//$sql.= " WHERE t.entity IN (".getEntity('resource').")";
+   		$sql.= " WHERE t.entity IN (".getEntity('resource',1).")";
 
    		//Manage filter
    		if (!empty($filter)){
@@ -476,7 +476,8 @@ class Resource extends CommonObject
    			}
    		}
    		$sql.= " GROUP BY t.rowid";
-   		$sql.= " ORDER BY $sortfield $sortorder " . $this->db->plimit($limit+1,$offset);
+    	$sql.= $this->db->order($sortfield,$sortorder);
+   		if ($limit) $sql.= $this->db->plimit($limit+1,$offset);
    		dol_syslog(get_class($this)."::fetch_all", LOG_DEBUG);
 
    		$resql=$this->db->query($sql);
@@ -547,7 +548,7 @@ class Resource extends CommonObject
     	$sql.= " t.fk_user_create,";
     	$sql.= " t.tms";
     	$sql.= ' FROM '.MAIN_DB_PREFIX .'element_resources as t ';
-    	//$sql.= " WHERE t.entity IN (".getEntity('resource').")";
+    	$sql.= " WHERE t.entity IN (".getEntity('resource',1).")";
 
     	//Manage filter
     	if (!empty($filter)){
@@ -561,7 +562,8 @@ class Resource extends CommonObject
     		}
     	}
     	$sql.= " GROUP BY t.resource_id";
-    	$sql.= " ORDER BY " . $sortfield . "  " . $sortorder . " " . $this->db->plimit($limit+1,$offset);
+    	$sql.= $this->db->order($sortfield,$sortorder);
+    	if ($limit) $sql.= $this->db->plimit($limit+1,$offset);
     	dol_syslog(get_class($this)."::fetch_all", LOG_DEBUG);
 
     	$resql=$this->db->query($sql);
diff --git a/htdocs/societe/consumption.php b/htdocs/societe/consumption.php
index d5ef1af6dbbecd824278a55bbd1beef7cf49755d..f8b5829b03eeded50eb0ad2bc516d694a1e3b395 100644
--- a/htdocs/societe/consumption.php
+++ b/htdocs/societe/consumption.php
@@ -76,11 +76,18 @@ $langs->load("orders");
 $langs->load("suppliers");
 $langs->load("propal");
 
+// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
+$hookmanager->initHooks(array('consumptionthirdparty'));
+
 
 /*
  * Actions
  */
 
+$parameters=array('id'=>$socid);
+$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
+if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
+
 
 
 /*
diff --git a/htdocs/societe/document.php b/htdocs/societe/document.php
index 2fde1ef5dcf38304fefe35f1268ece0fd385a95f..c2ad751f196ff0be6e0d6a61fe7da73a7d1e53d0 100644
--- a/htdocs/societe/document.php
+++ b/htdocs/societe/document.php
@@ -147,7 +147,7 @@ if ($object->id)
 
 	print '</table>';
 
-	print '</div>';
+	dol_fiche_end();
 
 	$modulepart = 'societe';
 	$permission = $user->rights->societe->creer;