diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php
index daf22e0af7c8f478bc81e25a6abb7f87f770c1ca..d384eea9b914ebdb8fd99160225fdb4932844982 100644
--- a/htdocs/contrat/class/contrat.class.php
+++ b/htdocs/contrat/class/contrat.class.php
@@ -448,6 +448,14 @@ class Contrat extends CommonObject
 				$this->extraparams				= (array) json_decode($result["extraparams"], true);
 
 				$this->db->free($resql);
+				
+				// Retreive all extrafield for thirdparty
+				// fetch optionals attributes and labels
+				require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php');
+				$extrafields=new ExtraFields($this->db);
+				$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
+				$this->fetch_optionals($this->id,$extralabels);
+				
 
 				return $this->id;
 			}
@@ -753,6 +761,19 @@ class Contrat extends CommonObject
 			// Insert contacts commerciaux ('SALESREPFOLL','contrat')
 			$result=$this->add_contact($this->commercial_suivi_id,'SALESREPFOLL','internal');
 			if ($result < 0) $error++;
+			
+			
+			if (! $error)
+			{
+				if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
+				{
+					$result=$this->insertExtraFields();
+					if ($result < 0)
+					{
+						$error++;
+					}
+				}
+			}
 
 			if (! $error)
 			{
diff --git a/htdocs/contrat/fiche.php b/htdocs/contrat/fiche.php
index 0bee62d4f12e1b34d60f30bff83a6484828c3267..4c842e25f554441e2ae9fd0b0e5e8a8a7e91d016 100644
--- a/htdocs/contrat/fiche.php
+++ b/htdocs/contrat/fiche.php
@@ -5,7 +5,7 @@
  * Copyright (C) 2006		Andre Cianfarani		<acianfa@free.fr>
  * Copyright (C) 2010-2013	Juanjo Menent			<jmenent@2byte.es>
  * Copyright (C) 2013       Christophe Battarel     <christophe.battarel@altairis.fr>
- * Copyright (C) 2013       Florian Henry		  	<florian.henry@open-concept.pro>
+ * Copyright (C) 2013-2014  Florian Henry		  	<florian.henry@open-concept.pro>
  *
  * 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
@@ -40,6 +40,7 @@ if (! empty($conf->projet->enabled)) {
 	require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
 	require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
 }
+require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
 
 $langs->load("contracts");
 $langs->load("orders");
@@ -65,6 +66,10 @@ $usehm=(! empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?$conf->global->MA
 $hookmanager->initHooks(array('contractcard'));
 
 $object = new Contrat($db);
+$extrafields = new ExtraFields($db);
+
+// fetch optionals attributes and labels
+$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
 
 $permissionnote=$user->rights->contrat->creer;	// Used by the include of actions_setnotes.inc.php
 
@@ -86,7 +91,7 @@ if ($action == 'confirm_active' && $confirm == 'yes' && $user->rights->contrat->
         exit;
     }
     else {
-        $mesg=$object->error;
+        setEventMessage($object->error,'errors');
     }
 }
 
@@ -107,7 +112,7 @@ else if ($action == 'confirm_closeline' && $confirm == 'yes' && $user->rights->c
 	        exit;
 	    }
 	    else {
-	        $mesg=$object->error;
+	        setEventMessage($object->error,'errors');
 	    }
 	}
 }
@@ -176,7 +181,7 @@ if ($action == 'add' && $user->rights->contrat->creer)
 	if (empty($datecontrat))
 	{
 		$error++;
-		$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")).'</div>';
+		setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")),'errors');
 		$action='create';
 	}
 
@@ -228,7 +233,7 @@ if ($action == 'add' && $user->rights->contrat->creer)
 
 	        $id = $object->create($user);
 	        if ($id < 0) {
-	            $mesg='<div class="error">'.$object->error.'</div>';
+	        	setEventMessage($object->error,'errors');
 	        }
 
 	        if ($id > 0)
@@ -319,26 +324,30 @@ if ($action == 'add' && $user->rights->contrat->creer)
 	            }
 	            else
 	            {
-	                $mesg=$srcobject->error;
+	                setEventMessage($srcobject->error,'errors');
 	                $error++;
 	            }
 	        }
 	        else
 	        {
-	            $mesg=$object->error;
+	            setEventMessage($object->error,'errors');
 	            $error++;
 	        }
 	    }
 	    else
 	    {
-	        $result = $object->create($user,$langs,$conf);
+	    	
+	    	// Fill array 'array_options' with data from add form
+	    	$ret = $extrafields->setOptionalsFromPost($extralabels, $object);
+	    	
+	        $result = $object->create($user);
 	        if ($result > 0)
 	        {
 	            header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
 	            exit;
 	        }
 	        else {
-	            $mesg='<div class="error">'.$object->error.'</div>';
+	        	setEventMessage($object->error,'errors');
 	        }
 	        $action='create';
 		}
@@ -389,7 +398,7 @@ else if ($action == 'addline' && $user->rights->contrat->creer)
         $ret=$object->fetch($id);
         if ($ret < 0)
         {
-            dol_print_error($db,$object->error);
+        	setEventMessage($object->error,'errors');
             exit;
         }
         $ret=$object->fetch_thirdparty();
@@ -546,7 +555,7 @@ else if ($action == 'addline' && $user->rights->contrat->creer)
         }
         else
         {
-            $mesg='<div class="error">'.$object->error.'</div>';
+        	setEventMessage($object->error,'errors');
         }
     }
 }
@@ -604,13 +613,13 @@ else if ($action == 'updateligne' && $user->rights->contrat->creer && ! GETPOST(
         }
         else
         {
-            dol_print_error($db,'Failed to update contrat_det');
+        	setEventMessage($objectline->error,'errors');
             $db->rollback();
         }
     }
     else
     {
-        dol_print_error($db);
+    	setEventMessage($objectline->error,'errors');
     }
 }
 
@@ -626,7 +635,7 @@ else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->
     }
     else
     {
-        $mesg=$object->error;
+    	setEventMessage($object->error,'errors');
     }
 }
 
@@ -655,7 +664,7 @@ else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->cont
 	}
 	else
 	{
-		$mesg='<div class="error">'.$object->error.'</div>';
+		setEventMessage($object->error,'errors');
 	}
 }
 
@@ -674,12 +683,33 @@ else if ($action == 'confirm_move' && $confirm == 'yes' && $user->rights->contra
 		}
 		else
 		{
-			$mesg='<div class="error">'.$object->error.'</div>';
+			setEventMessage($object->error,'errors');
 		}
 	}
 	else
 	{
-		$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("RefNewContract")).'</div>';
+		setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("RefNewContract")),'errors');
+	}
+} else if ($action == 'update_extras') {
+	// Fill array 'array_options' with data from update form
+	$object->fetch($id);
+	$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
+	$ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
+	if ($ret < 0)
+		$error ++;
+
+	if (! $error) {
+		
+			$result = $object->insertExtraFields();
+			if ($result < 0) {
+				$error ++;
+			}
+		} else if ($reshook < 0)
+			$error ++;
+
+	if ($error) {
+		$action = 'edit_extras';
+		setEventMessage($object->error,'errors');
 	}
 }
 
@@ -705,11 +735,11 @@ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->contrat-
 			if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
 			{
 				$langs->load("errors");
-				$mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
+				setEventMessage($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"),'errors');
 			}
 			else
 			{
-				$mesg = '<div class="error">'.$object->error.'</div>';
+				setEventMessage($object->error,'errors');
 			}
 		}
 	}
@@ -723,7 +753,7 @@ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->contrat-
 		}
 		else
 		{
-			dol_print_error($db);
+			setEventMessage($object->error,'errors');
 		}
 	}
 
@@ -739,7 +769,7 @@ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->contrat-
 			exit;
 		}
 		else {
-			dol_print_error($db);
+			setEventMessage($object->error,'errors');
 		}
 	}
 }
@@ -765,8 +795,6 @@ if ($action == 'create')
 {
 	print_fiche_titre($langs->trans('AddContract'));
 
-    dol_htmloutput_errors($mesg,'');
-
     $soc = new Societe($db);
     if ($socid>0) $soc->fetch($socid);
 
@@ -902,8 +930,13 @@ if ($action == 'create')
     }
 
     // Other attributes
-    $parameters=array('colspan' => ' colspan="3"');
+    $parameters=array('objectsrc' => $objectsrc,'colspan' => ' colspan="3"');
     $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
+    
+    // Other attributes
+    if (empty($reshook) && ! empty($extrafields->attribute_label)) {
+    	print $object->showOptionals($extrafields, 'edit');
+    }
 
     print "</table>\n";
 
@@ -937,8 +970,6 @@ else
         $result=$object->fetch_thirdparty();
         if ($result < 0) dol_print_error($db,$object->error);
 
-        dol_htmloutput_errors($mesg,'');
-
         $nbofservices=count($object->lines);
 
         $author = new User($db);
@@ -1065,6 +1096,50 @@ else
         // Other attributes
         $parameters=array('colspan' => ' colspan="3"');
         $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
+        
+        $res = $object->fetch_optionals($object->id, $extralabels);
+        if (empty($reshook) && ! empty($extrafields->attribute_label)) {
+        	foreach ($extrafields->attribute_label as $key => $label) {
+        		if ($action == 'edit_extras') {
+        			$value = (isset($_POST ["options_" . $key]) ? $_POST ["options_" . $key] : $object->array_options ["options_" . $key]);
+        		} else {
+        			$value = $object->array_options ["options_" . $key];
+        		}
+        		if ($extrafields->attribute_type [$key] == 'separate') {
+        			print $extrafields->showSeparator($key);
+        		} else {
+        			print '<tr><td';
+        			if (! empty($extrafields->attribute_required [$key]))
+        				print ' class="fieldrequired"';
+        			print '>' . $label . '</td><td colspan="5">';
+        			// Convert date into timestamp format
+        			if (in_array($extrafields->attribute_type [$key], array('date','datetime'))) {
+        				$value = isset($_POST ["options_" . $key]) ? dol_mktime($_POST ["options_" . $key . "hour"], $_POST ["options_" . $key . "min"], 0, $_POST ["options_" . $key . "month"], $_POST ["options_" . $key . "day"], $_POST ["options_" . $key . "year"]) : $db->jdate($object->array_options ['options_' . $key]);
+        			}
+        
+        			if ($action == 'edit_extras' && $user->rights->commande->creer && GETPOST('attribute') == $key) {
+        				print '<form enctype="multipart/form-data" action="' . $_SERVER["PHP_SELF"] . '" method="post" name="formcontract">';
+        				print '<input type="hidden" name="action" value="update_extras">';
+        				print '<input type="hidden" name="attribute" value="' . $key . '">';
+        				print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
+        				print '<input type="hidden" name="id" value="' . $object->id . '">';
+        
+        				print $extrafields->showInputField($key, $value);
+        
+        				print '<input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
+        				print '</form>';
+        			} else {
+        				print $extrafields->showOutputField($key, $value);
+        				if ($object->statut == 0 && $user->rights->commande->creer)
+        					print '<a href="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=edit_extras&attribute=' . $key . '">' . img_picto('', 'edit') . ' ' . $langs->trans('Modify') . '</a>';
+        			}
+        			print '</td></tr>' . "\n";
+        		}
+        	}
+        }
+        
+        
+        
 
         print "</table>";
 
diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php
index df302f0ffad43c35ae7da9ef2800b5b0c412e00d..de8e5fc636de79e752154541218f9534ad2d09ab 100644
--- a/htdocs/core/class/extrafields.class.php
+++ b/htdocs/core/class/extrafields.class.php
@@ -677,7 +677,7 @@ class ExtraFields
 			if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && ! $forcecombo)
 			{
 				include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
-				$out.= ajax_combobox('options_'.$key.$keyprefix, $event, $conf->global->COMPANY_USE_SEARCH_TO_SELECT);
+				$out.= ajax_combobox('options_'.$key.$keyprefix, array(), $conf->global->COMPANY_USE_SEARCH_TO_SELECT);
 			}
 
 			$out.='<select class="flat" name="options_'.$key.$keyprefix.'" id="options_'.$key.$keyprefix.'" '.($moreparam?$moreparam:'').'>';
@@ -697,7 +697,7 @@ class ExtraFields
 			if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && ! $forcecombo)
 			{
 				include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
-				$out.= ajax_combobox('options_'.$key.$keyprefix, $event, $conf->global->COMPANY_USE_SEARCH_TO_SELECT);
+				$out.= ajax_combobox('options_'.$key.$keyprefix, array(), $conf->global->COMPANY_USE_SEARCH_TO_SELECT);
 			}
 
 			$out.='<select class="flat" name="options_'.$key.$keyprefix.'" id="options_'.$key.$keyprefix.'" '.($moreparam?$moreparam:'').'>';
diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php
index 4255f124c1ccc97cba4128cba6cb2b41219358b8..170cc1e0fc74c0a8ca6c76b4d6d15b0ffcef9659 100644
--- a/htdocs/core/tpl/objectline_create.tpl.php
+++ b/htdocs/core/tpl/objectline_create.tpl.php
@@ -31,7 +31,7 @@
 $usemargins=0;
 if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($object->element,array('facture','propal','commande'))) $usemargins=1;
 
-global $dateSelector, $forceall, $senderissupplier, $inputalsopricewithtax;
+global $forceall, $senderissupplier, $inputalsopricewithtax;
 if (empty($dateSelector)) $dateSelector=0;
 if (empty($forceall)) $forceall=0;
 if (empty($senderissupplier)) $senderissupplier=0;
diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php
index 54348b2d6468689991ec340e1309ec2c2a9aa1ac..95402139f7e9f2646c988caea758347cae22be21 100644
--- a/htdocs/core/tpl/objectline_edit.tpl.php
+++ b/htdocs/core/tpl/objectline_edit.tpl.php
@@ -31,7 +31,7 @@
 $usemargins=0;
 if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($object->element,array('facture','propal','commande'))) $usemargins=1;
 
-global $dateSelector, $forceall, $senderissupplier, $inputalsopricewithtax;
+global $forceall, $senderissupplier, $inputalsopricewithtax;
 if (empty($dateSelector)) $dateSelector=0;
 if (empty($forceall)) $forceall=0;
 if (empty($senderissupplier)) $senderissupplier=0;
diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index 2bdc950495e543c5d2c2b254a288725282f89795..32d96ec60fc7e189ea1f8761e6f4e2b6c9605c66 100644
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -1392,6 +1392,14 @@ class Product extends CommonObject
 				$this->entity					= $obj->entity;
 
 				$this->db->free($resql);
+				
+				
+				// Retreive all extrafield for thirdparty
+				// fetch optionals attributes and labels
+				require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php');
+				$extrafields=new ExtraFields($this->db);
+				$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
+				$this->fetch_optionals($this->id,$extralabels);
 
 
 				// multilangs