diff --git a/ChangeLog b/ChangeLog
index e75a2d82d7b13029c079f2ce582470b61e978735..00aab1d3d59381c7b3fc88dad9271904be795043 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -24,7 +24,9 @@ For users:
 - Add juridical status and number of employees in third party 
   export definition.
 - A lot of enhancements and translation in withdraw module.
-  
+- Full support of Mysql option mode=strict.
+- Added new event from member module to possible agenda tracked events.
+
 For translators:
 - The errors language file contains only error or warning messages with 
   prefix Error or Warning.
@@ -33,6 +35,7 @@ For translators:
 For developers:
 - Update skeletons.
 - Add an experimental Cash Desk module.
+- Added new triggers events in agenda module.
 - All submodules are moved in the includes directory.
 - Removed some deprecated files.
 
diff --git a/htdocs/actioncomm.class.php b/htdocs/actioncomm.class.php
index ccd41ce7b1788d6141a80a033150a55880ddbce9..b6dffd15f192d18c38e21bd396c6b63ec96328b4 100644
--- a/htdocs/actioncomm.class.php
+++ b/htdocs/actioncomm.class.php
@@ -18,19 +18,17 @@
  */
 
 /**
-        \file       htdocs/actioncomm.class.php
-        \ingroup    commercial
-        \brief      Fichier de la classe des actions commerciales
-        \version    $Id$
-*/
-
+ *       \file       htdocs/actioncomm.class.php
+ *       \ingroup    commercial
+ *       \brief      Fichier de la classe des actions commerciales
+ *       \version    $Id$
+ */
 require_once(DOL_DOCUMENT_ROOT.'/cactioncomm.class.php');
 
 
 /**     \class      ActionComm
-	    \brief      Classe permettant la gestion des actions commerciales
-*/
-
+ *	    \brief      Classe permettant la gestion des actions commerciales
+ */
 class ActionComm
 {
     var $db;
@@ -133,7 +131,7 @@ class ActionComm
 		}
 		
 		
-		$this->db->begin();
+		$this->db->begin("ActionComm::add");
 
         $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm";
         $sql.= "(datec,";
@@ -143,7 +141,9 @@ class ActionComm
         $sql.= "datea2,";
         $sql.= "durationp,";
         $sql.= "durationa,";
-        $sql.= "fk_action,fk_soc,note,";
+        $sql.= "fk_action,";
+        $sql.= "fk_soc,";
+        $sql.= "note,";
 		$sql.= "fk_contact,";
 		$sql.= "fk_user_author,";
 		$sql.= "fk_user_action,";
@@ -158,7 +158,9 @@ class ActionComm
         $sql.= (strval($this->dateend)!=''?"'".$this->db->idate($this->dateend)."'":"null").",";
         $sql.= ($this->durationp >= 0 && $this->durationp != ''?"'".$this->durationp."'":"null").",";
         $sql.= ($this->durationa >= 0 && $this->durationa != ''?"'".$this->durationa."'":"null").",";
-        $sql.= "'".$this->type_id."', '".$this->societe->id."' ,'".addslashes($this->note)."',";
+        $sql.= " '".$this->type_id."',";
+        $sql.= ($this->societe->id>0?" '".$this->societe->id."'":"null").",";
+        $sql.= " '".addslashes($this->note)."',";
         $sql.= ($this->contact->id > 0?"'".$this->contact->id."'":"null").",";
         $sql.= ($user->id > 0 ? "'".$user->id."'":"null").",";
 		$sql.= ($this->usertodo->id > 0?"'".$this->usertodo->id."'":"null").",";
@@ -185,13 +187,13 @@ class ActionComm
 	            // Fin appel triggers
 			}
 			
-			$this->db->commit();
+			$this->db->commit("ActionComm::add");
             return $this->id;
         }
         else
         {
 			$this->error=$this->db->lasterror().' sql='.$sql;
-			$this->db->rollback();
+			$this->db->rollback("ActionComm::add");
             return -1;
         }
     
diff --git a/htdocs/adherents/adherent.class.php b/htdocs/adherents/adherent.class.php
index e61ff31545bd3d0e7c7e5cc56c07188702cca4a9..7b274ae6f8f0f828f072ced0aa7e21626236a2a0 100644
--- a/htdocs/adherents/adherent.class.php
+++ b/htdocs/adherents/adherent.class.php
@@ -21,25 +21,25 @@
  */
 
 /**
-	    \file       htdocs/adherents/adherent.class.php
-        \ingroup    adherent
-		\brief      Fichier de la classe permettant la gestion d'un adherent
-		\author     Rodolphe Qiedeville
-		\author	    Jean-Louis Bergamo
-		\author	    Laurent Destailleur
-		\author     Sebastien Di Cintio
-		\author     Benoit Mortier
-		\version    $Id$
-*/
+ \file       htdocs/adherents/adherent.class.php
+ \ingroup    adherent
+ \brief      Fichier de la classe permettant la gestion d'un adherent
+ \author     Rodolphe Qiedeville
+ \author	    Jean-Louis Bergamo
+ \author	    Laurent Destailleur
+ \author     Sebastien Di Cintio
+ \author     Benoit Mortier
+ \version    $Id$
+ */
 
 require_once(DOL_DOCUMENT_ROOT."/commonobject.class.php");
 require_once(DOL_DOCUMENT_ROOT."/adherents/cotisation.class.php");
 
 
 /**
-        \class      Adherent
-		\brief      Classe permettant la gestion d'un adherent
-*/
+ *      \class      Adherent
+ *		\brief      Classe permettant la gestion d'un adherent
+ */
 
 class Adherent extends CommonObject
 {
@@ -48,7 +48,7 @@ class Adherent extends CommonObject
 	var $errors=array();
 	var $element='member';
 	var $table_element='adherent';
-	
+
 	var $id;
 	var $ref;
 	var $prenom;
@@ -100,10 +100,10 @@ class Adherent extends CommonObject
 
 
 	/**
-			\brief Adherent
-			\param DB		base de donnees
-			\param id		id de l'adherent
-	*/
+	 \brief Adherent
+	 \param DB		base de donnees
+	 \param id		id de l'adherent
+	 */
 	function Adherent($DB)
 	{
 		$this->db = $DB ;
@@ -134,10 +134,10 @@ class Adherent extends CommonObject
 		\remarks		%INFOS% : l'ensemble des attributs de cet adherent
 		\remarks		%SERVEUR% : URL du serveur web
 		\remarks		etc..
-	*/
+		*/
 	function send_an_email($text,$subject,
-					$filename_list=array(),$mimetype_list=array(),$mimefilename_list=array(),
-                    $addr_cc="",$addr_bcc="",$deliveryreceipt=0,$msgishtml=-1, $errors_to='')
+	$filename_list=array(),$mimetype_list=array(),$mimefilename_list=array(),
+	$addr_cc="",$addr_bcc="",$deliveryreceipt=0,$msgishtml=-1, $errors_to='')
 	{
 		global $conf,$langs;
 
@@ -145,27 +145,27 @@ class Adherent extends CommonObject
 		if ($msgishtml == -1)
 		{
 			$msgishtml = 0;
-			if (dol_textishtml($text,1)) $msgishtml = 1;	
+			if (dol_textishtml($text,1)) $msgishtml = 1;
 		}
 
 		$infos='';
-	    $infos.= $langs->trans("Lastname").": $this->nom\n";
-	    $infos.= $langs->trans("Firstname").": $this->prenom\n";
-	    $infos.= $langs->trans("Company").": $this->societe\n";
-	    $infos.= $langs->trans("Address").": $this->adresse\n";
-	    $infos.= $langs->trans("Zip").": $this->cp\n";
-	    $infos.= $langs->trans("Town").": $this->ville\n";
-	    $infos.= $langs->trans("Country").": $this->pays\n";
-	    $infos.= $langs->trans("EMail").": $this->email\n";
-	    $infos.= $langs->trans("Login").": $this->login\n";
-	    $infos.= $langs->trans("Password").": $this->pass\n";
-	    $infos.= $langs->trans("Birthday").": $this->naiss\n";
-	    $infos.= $langs->trans("Photo").": $this->photo\n";
+		$infos.= $langs->trans("Lastname").": $this->nom\n";
+		$infos.= $langs->trans("Firstname").": $this->prenom\n";
+		$infos.= $langs->trans("Company").": $this->societe\n";
+		$infos.= $langs->trans("Address").": $this->adresse\n";
+		$infos.= $langs->trans("Zip").": $this->cp\n";
+		$infos.= $langs->trans("Town").": $this->ville\n";
+		$infos.= $langs->trans("Country").": $this->pays\n";
+		$infos.= $langs->trans("EMail").": $this->email\n";
+		$infos.= $langs->trans("Login").": $this->login\n";
+		$infos.= $langs->trans("Password").": $this->pass\n";
+		$infos.= $langs->trans("Birthday").": $this->naiss\n";
+		$infos.= $langs->trans("Photo").": $this->photo\n";
 		$infos.= $langs->trans("Public").": ".yn($this->public)."\n";
 		if ($msgishtml) $infos = dol_htmlentitiesbr($infos);
 
 		// Substitutions
-	    $patterns = array (
+		$patterns = array (
 		       '/%PRENOM%/',
 		       '/%NOM%/',
 		       '/%INFOS%/',
@@ -181,180 +181,78 @@ class Adherent extends CommonObject
 		       '/%LOGIN%/',
 		       '/%PASSWORD%/'
 		       );
-	    $replace = array (
-		      $this->prenom,
-		      $this->nom,
-		      $infos,
-		      DOL_MAIN_URL_ROOT,
-		      $this->societe,
-		      $this->adresse,
-		      $this->cp,
-		      $this->ville,
-		      $this->pays,
-		      $this->email,
-		      $this->naiss,
-		      $this->photo,
-		      $this->login,
-		      $this->pass
-		      );
-		$texttosend = preg_replace ($patterns, $replace, $text);
-		$subjectosend = preg_replace ($patterns, $replace, $subject);
-
-		// Envoi mail confirmation
-        $from=$conf->email_from;
-        if ($conf->global->ADHERENT_MAIL_FROM) $from=$conf->global->ADHERENT_MAIL_FROM;
-
-        include_once(DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php");
-		$mailfile = new CMailFile($subjectosend,$this->email,$from,$texttosend,
-									$filename_list,$mimetype_list,$mimefilename_list,
-									$addr_cc, $addr_bcc, $deliveryreceipt, $msgishtml);
-        if ($mailfile->sendfile())
-        {
-            return 1;
-        }
-        else
-        {
-            $this->error=$langs->trans("ErrorFailedToSendMail",$from,$this->email).'. '.$mailfile->error;
-            return -1;
-        }
-
-	}
-
-
-/**
-		\brief	imprime une liste d'erreur.
-*/
-
-  function print_error_list()
-  {
-    $num = sizeof($this->error);
-    for ($i = 0 ; $i < $num ; $i++)
-      {
-	print "<li>" . $this->error[$i];
-      }
-  }
-
-
-/**
-		\brief      Renvoie le libelle traduit de la nature d'un adherent (physique ou morale)
-		\param	    morphy		Nature physique ou morale de l'adherent
-*/
-
-  function getmorphylib($morphy='')
-  {
-    global $langs;
-    if (! $morphy) { $morphy=$this->morphy; }
-    if ($morphy == 'phy') { return $langs->trans("Physical"); }
-    if ($morphy == 'mor') { return $langs->trans("Moral"); }
-    return $morphy;
-  }
-
-/**
-		\brief      Verifie les donnees entrees
-		\param	    minimum
-*/
-
-  function check($minimum=0)
-    {
-      $err = 0;
-
-      if (strlen(trim($this->societe)) == 0)
-	{
-	  if ((strlen(trim($this->nom)) + strlen(trim($this->prenom))) == 0)
-	    {
-	      $error_string[$err] = "Vous devez saisir vos nom et prenom ou le nom de votre societe.";
-	      $err++;
-	    }
-	}
-
-      if (strlen(trim($this->adresse)) == 0)
-	{
-	  $error_string[$err] = "L'adresse saisie est invalide";
-	  $err++;
-	}
-
-      if (strlen(trim($this->cp)) == 0)
-	{
-	  $error_string[$err] = "Le code postal saisi est invalide";
-	  $err++;
-	}
+		       $replace = array (
+		       $this->prenom,
+		       $this->nom,
+		       $infos,
+		       DOL_MAIN_URL_ROOT,
+		       $this->societe,
+		       $this->adresse,
+		       $this->cp,
+		       $this->ville,
+		       $this->pays,
+		       $this->email,
+		       $this->naiss,
+		       $this->photo,
+		       $this->login,
+		       $this->pass
+		       );
+		       $texttosend = preg_replace ($patterns, $replace, $text);
+		       $subjectosend = preg_replace ($patterns, $replace, $subject);
 
-      if (strlen(trim($this->ville)) == 0)
-	{
-	  $error_string[$err] = "La ville saisie est invalide";
-	  $err++;
-	}
+		       // Envoi mail confirmation
+		       $from=$conf->email_from;
+		       if ($conf->global->ADHERENT_MAIL_FROM) $from=$conf->global->ADHERENT_MAIL_FROM;
 
-      if (strlen(trim($this->email)) == 0)
-	{
-	  $error_string[$err] = "L'email saisi est invalide";
-	  $err++;
-	}
-
-      if (strlen(trim($this->login)) == 0)
-	{
-	  $error_string[$err] = "Le login saisi est invalide";
-	  $err++;
-	}
+		       include_once(DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php");
+		       $mailfile = new CMailFile($subjectosend,$this->email,$from,$texttosend,
+									$filename_list,$mimetype_list,$mimefilename_list,
+									$addr_cc, $addr_bcc, $deliveryreceipt, $msgishtml);
+									if ($mailfile->sendfile())
+									{
+										return 1;
+									}
+									else
+									{
+										$this->error=$langs->trans("ErrorFailedToSendMail",$from,$this->email).'. '.$mailfile->error;
+										return -1;
+									}
 
-      if (strlen(trim($this->pass)) == 0)
-	{
-	  $error_string[$err] = "Le pass saisi est invalide";
-	  $err++;
 	}
-      $this->amount = trim($this->amount);
 
-      $map = range(0,9);
-      for ($i = 0; $i < strlen($this->amount) ; $i++)
-	{
-	  if (!isset($map[substr($this->amount, $i, 1)] ))
-	    {
-	      $error_string[$err] = "Le montant du don contient un/des caractere(s) invalide(s)";
-	      $err++;
-	      $amount_invalid = 1;
-	      break;
-	    }
-	}
 
-      if (! $amount_invalid)
+	/**
+	 *	\brief	imprime une liste d'erreur.
+	 */
+	function print_error_list()
 	{
-	  if ($this->amount == 0)
-	    {
-	      $error_string[$err] = "Le montant du don est null";
-	      $err++;
-	    }
-	  else
-	    {
-	      if ($this->amount < $minimum && $minimum > 0)
+		$num = sizeof($this->error);
+		for ($i = 0 ; $i < $num ; $i++)
 		{
-		  $error_string[$err] = "Le montant minimum du don est de $minimum";
-		  $err++;
+			print "<li>" . $this->error[$i];
 		}
-	    }
 	}
 
-      /*
-       * Return errors
-       */
 
-      if ($err)
-	{
-	  $this->error = $error_string;
-	  return 0;
-	}
-      else
+	/**
+	 *	\brief      Renvoie le libelle traduit de la nature d'un adherent (physique ou morale)
+	 *	\param	    morphy		Nature physique ou morale de l'adherent
+	 */
+	function getmorphylib($morphy='')
 	{
-	  return 1;
+		global $langs;
+		if (! $morphy) { $morphy=$this->morphy; }
+		if ($morphy == 'phy') { return $langs->trans("Physical"); }
+		if ($morphy == 'mor') { return $langs->trans("Moral"); }
+		return $morphy;
 	}
 
-    }
-
 	/**
-		\brief  	Fonction qui cree l'adherent
-		\param      user        	Objet user qui demande la creation
-		\param      notrigger		1 ne declenche pas les triggers, 0 sinon
-		\return		int				<0 si ko, >0 si ok
-	*/
+	 *	\brief  	Fonction qui cree l'adherent
+	 *	\param      user        	Objet user qui demande la creation
+	 *	\param      notrigger		1 ne declenche pas les triggers, 0 sinon
+	 *	\return		int				<0 si ko, >0 si ok
+	 */
 	function create($user,$notrigger=0)
 	{
 		global $conf,$langs;
@@ -366,16 +264,16 @@ class Adherent extends CommonObject
 			return -1;
 		}
 		if (! $this->datec) $this->datec=time();
-		
+
 		$this->db->begin();
-		
+
 		// Insertion membre
 		$sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent";
-		$sql.= " (datec,login,fk_user_author,fk_user_mod,fk_user_valid)";
+		$sql.= " (datec,login,fk_user_author,fk_user_mod,fk_user_valid,morphy)";
 		$sql.= " VALUES (";
 		$sql.= " '".$this->db->idate($this->datec)."',";
 		$sql.= " '".addslashes($this->login)."',";
-		$sql.= " '".$user->id."',null,null";
+		$sql.= " '".$user->id."',null,null,'".$this->morphy."'";
 		$sql.= ")";
 
 		dolibarr_syslog("Adherent::create sql=".$sql);
@@ -386,7 +284,7 @@ class Adherent extends CommonObject
 			if ($id > 0)
 			{
 				$this->id=$id;
-				
+
 				// Update minor fields
 				$result=$this->update($user,1,1);
 				if ($result < 0)
@@ -394,19 +292,19 @@ class Adherent extends CommonObject
 					$this->db->rollback();
 					return -1;
 				}
-				
+
 				$this->use_webcal=($conf->global->PHPWEBCALENDAR_MEMBERSTATUS=='always'?1:0);
 
 				if (! $notrigger)
 				{
-		            // Appel des triggers
-		            include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
-		            $interface=new Interfaces($this->db);
-		            $result=$interface->run_triggers('MEMBER_CREATE',$this,$user,$langs,$conf);
+					// Appel des triggers
+					include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
+					$interface=new Interfaces($this->db);
+					$result=$interface->run_triggers('MEMBER_CREATE',$this,$user,$langs,$conf);
 					if ($result < 0) { $error++; $this->errors=$interface->errors; }
-		            // Fin appel triggers
+					// Fin appel triggers
 				}
-				
+
 				if (sizeof($this->errors))
 				{
 					$this->db->rollback();
@@ -423,7 +321,7 @@ class Adherent extends CommonObject
 				$this->error='Failed to get last insert id';
 				$this->db->rollback();
 				return -2;
-			}				
+			}
 		}
 		else
 		{
@@ -435,19 +333,19 @@ class Adherent extends CommonObject
 
 
 	/**
-			\brief 		Fonction qui met a jour l'adherent (sauf mot de passe)
-			\param		user			Utilisateur qui realise la mise a jour
-			\param		notrigger		1=desactive le trigger UPDATE (quand appele par creation)
-			\param		nosyncuser		Do not synchronize linked user
-			\return		int				<0 si KO, >0 si OK
-	*/
+	 \brief 		Fonction qui met a jour l'adherent (sauf mot de passe)
+	 \param		user			Utilisateur qui realise la mise a jour
+	 \param		notrigger		1=desactive le trigger UPDATE (quand appele par creation)
+	 \param		nosyncuser		Do not synchronize linked user
+	 \return		int				<0 si KO, >0 si OK
+	 */
 	function update($user,$notrigger=0,$nosyncuser=0)
 	{
 		global $conf, $langs;
-		
+
 		$nbrowsaffected=0;
 		$error=0;
-		
+
 		dolibarr_syslog("Adherent::update notrigger=".$notrigger.", nosyncuser=".$nosyncuser);
 
 		// Verification parametres
@@ -487,7 +385,7 @@ class Adherent extends CommonObject
 		$resql = $this->db->query($sql);
 		if ($resql)
 		{
-        	$nbrowsaffected+=$this->db->affected_rows($resql);
+			$nbrowsaffected+=$this->db->affected_rows($resql);
 
 			if (sizeof($this->array_options) > 0)
 			{
@@ -498,14 +396,22 @@ class Adherent extends CommonObject
 				$sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options (adhid";
 				foreach($this->array_options as $key => $value)
 				{
-					// recupere le nom de l'attribut
+					// Add field o fattribut
 					$attr=substr($key,8);
 					$sql.=",$attr";
 				}
 				$sql .= ") VALUES (".$this->id;
 				foreach($this->array_options as $key => $value)
 				{
-					$sql.=",'".$this->array_options[$key]."'";
+					// Add field o fattribut
+					if ($this->array_options[$key] != '')
+					{
+						$sql.=",'".$this->array_options[$key]."'";
+					}
+					else
+					{
+						$sql.=",null";
+					}
 				}
 				$sql.=")";
 
@@ -524,19 +430,19 @@ class Adherent extends CommonObject
 				}
 			}
 
-        	// Mise a jour mot de passe
-	        if ($this->pass)
-	        {
-	        	if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted)
-	       		{
-	       			// Si mot de passe saisi et different de celui en base
-	       			$result=$this->setPassword($user,$this->pass,0,$notrigger);
-	       			
-	       			if (! $nbrowsaffected) $nbrowsaffected++;
-	       		}
-	       	}
-	       	
-	       	if ($nbrowsaffected)
+			// Mise a jour mot de passe
+			if ($this->pass)
+			{
+				if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted)
+				{
+					// Si mot de passe saisi et different de celui en base
+					$result=$this->setPassword($user,$this->pass,0,$notrigger);
+
+					if (! $nbrowsaffected) $nbrowsaffected++;
+				}
+			}
+
+			if ($nbrowsaffected)
 			{
 				if ($this->user_id && ! $nosyncuser)
 				{
@@ -559,7 +465,7 @@ class Adherent extends CommonObject
 						$luser->email=$this->email;
 						$luser->office_phone=$this->phone;
 						$luser->user_mobile=$this->phone_mobile;
-						
+
 						$luser->note=$this->note;
 
 						$luser->fk_member=$this->id;
@@ -577,23 +483,23 @@ class Adherent extends CommonObject
 						$this->error=$luser->error;
 						$error++;
 					}
-				}	
-				
+				}
+
 				$this->fullname=trim($this->nom.' '.$this->prenom);
-				
+
 				if (! $error && ! $notrigger)
 				{
 					$this->use_webcal=($conf->global->PHPWEBCALENDAR_MEMBERSTATUS=='always'?1:0);
 
 					// Appel des triggers
-			        include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
-			        $interface=new Interfaces($this->db);
-			        $result=$interface->run_triggers('MEMBER_MODIFY',$this,$user,$langs,$conf);
-		            if ($result < 0) { $error++; $this->errors=$interface->errors; }
-		 	        // Fin appel triggers
+					include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
+					$interface=new Interfaces($this->db);
+					$result=$interface->run_triggers('MEMBER_MODIFY',$this,$user,$langs,$conf);
+					if ($result < 0) { $error++; $this->errors=$interface->errors; }
+					// Fin appel triggers
 				}
 			}
-			
+
 			if (! $error)
 			{
 				$this->db->commit();
@@ -602,7 +508,7 @@ class Adherent extends CommonObject
 			{
 				$this->db->rollback();
 			}
-			
+
 			return $nbrowsaffected;
 		}
 		else
@@ -617,16 +523,16 @@ class Adherent extends CommonObject
 
 
 	/**
-			\brief 		Fonction qui met a jour le chp denormalise date fin adh�sion
-			\param		user			Utilisateur qui realise la mise a jour
-			\return		int				<0 si KO, >0 si OK
-	*/
+	 \brief 		Fonction qui met a jour le chp denormalise date fin adh�sion
+	 \param		user			Utilisateur qui realise la mise a jour
+	 \return		int				<0 si KO, >0 si OK
+	 */
 	function update_end_date($user)
 	{
 		global $conf, $langs;
-		
+
 		$error=0;
-		
+
 		$this->db->begin();
 
 		// Search for last subscription id and end date
@@ -641,7 +547,7 @@ class Adherent extends CommonObject
 		{
 			$obj=$this->db->fetch_object($resql);
 			$datefin=$obj->datef;
-		
+
 			$sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
 			$sql.= " datefin=".($datefin != '' ? "'".$this->db->idate($datefin)."'" : "null");
 			$sql.= " WHERE rowid = ".$this->id;
@@ -666,14 +572,14 @@ class Adherent extends CommonObject
 			$this->db->rollback();
 			return -1;
 		}
-		
+
 	}
-		
+
 	/**
-			\brief 		Fonction qui supprime l'adherent et les donnees associees
-			\param		rowid		Id de l'adherent a effacer
-			\return		int			<0 si KO, 0=rien a effacer, >0 si OK
-	*/
+	 \brief 		Fonction qui supprime l'adherent et les donnees associees
+	 \param		rowid		Id de l'adherent a effacer
+	 \return		int			<0 si KO, 0=rien a effacer, >0 si OK
+	 */
 	function delete($rowid)
 	{
 		global $conf, $langs, $user;
@@ -683,7 +589,7 @@ class Adherent extends CommonObject
 
 		// Suppression options
 		$sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options WHERE adhid = ".$rowid;
-		
+
 		dolibarr_syslog("Adherent::delete sql=".$sql);
 		$resql=$this->db->query($sql);
 		if ($resql)
@@ -703,11 +609,11 @@ class Adherent extends CommonObject
 						$this->use_webcal=($conf->global->PHPWEBCALENDAR_MEMBERSTATUS=='always'?1:0);
 
 						// Appel des triggers
-				        include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
-				        $interface=new Interfaces($this->db);
-				        $result=$interface->run_triggers('MEMBER_DELETE',$this,$user,$langs,$conf);
+						include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
+						$interface=new Interfaces($this->db);
+						$result=$interface->run_triggers('MEMBER_DELETE',$this,$user,$langs,$conf);
 						if ($result < 0) { $error++; $this->errors=$interface->errors; }
-				        // Fin appel triggers
+						// Fin appel triggers
 
 						$this->db->commit();
 						return 1;
@@ -739,13 +645,13 @@ class Adherent extends CommonObject
 			$this->db->rollback();
 			return -1;
 		}
-	
+
 		return $result;
-	
+
 	}
 
-	
-		/**
+
+	/**
 	 *    \brief     Change le mot de passe d'un utilisateur
 	 *    \param     user             Object user de l'utilisateur qui fait la modification
 	 *    \param     password         Nouveau mot de passe (e generer si non communique)
@@ -754,49 +660,49 @@ class Adherent extends CommonObject
 	 *    \param	 nosyncuser		  Do not synchronize linked user
 	 *    \return    string           If OK return clear password, 0 if no change, < 0 if error
 	 */
-    function setPassword($user, $password='', $isencrypted=0, $notrigger=0, $nosyncuser=0)
-    {
-        global $conf, $langs;
+	function setPassword($user, $password='', $isencrypted=0, $notrigger=0, $nosyncuser=0)
+	{
+		global $conf, $langs;
 
 		$error=0;
 
-        dolibarr_syslog("Adherent::Password user=".$user->id." password=".eregi_replace('.','*',$password)." isencrypted=".$isencrypted);
+		dolibarr_syslog("Adherent::Password user=".$user->id." password=".eregi_replace('.','*',$password)." isencrypted=".$isencrypted);
 
-        // Si nouveau mot de passe non communique, on genere par module
-        if (! $password)
-        {
-        	// TODO Mettre appel au module de generation de mot de passe
-        	$password=creer_pass_aleatoire_1('');
-        	//$password=creer_pass_aleatoire_2('');
-        }
+		// Si nouveau mot de passe non communique, on genere par module
+		if (! $password)
+		{
+			// TODO Mettre appel au module de generation de mot de passe
+			$password=creer_pass_aleatoire_1('');
+			//$password=creer_pass_aleatoire_2('');
+		}
 
 		// Cryptage mot de passe
-        if ($isencrypted)
-        {
-        	// Crypte avec systeme encodage par defaut du PHP
-            //$sqlpass = crypt($password, makesalt());
-            $password_indatabase = md5($password);
-        }
-        else
-        {
-            $password_indatabase = $password;
-        }
+		if ($isencrypted)
+		{
+			// Crypte avec systeme encodage par defaut du PHP
+			//$sqlpass = crypt($password, makesalt());
+			$password_indatabase = md5($password);
+		}
+		else
+		{
+			$password_indatabase = $password;
+		}
 
 		// Mise a jour
-        $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET pass = '".addslashes($password_indatabase)."'";
-        $sql.= " WHERE rowid = ".$this->id;
+		$sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET pass = '".addslashes($password_indatabase)."'";
+		$sql.= " WHERE rowid = ".$this->id;
 
 		//dolibarr_syslog("Adherent::Password sql=hidden");
 		dolibarr_syslog("Adherent::Password sql=".$sql);
-	    $result = $this->db->query($sql);
-        if ($result)
-        {
-            $nbaffectedrows=$this->db->affected_rows();
+		$result = $this->db->query($sql);
+		if ($result)
+		{
+			$nbaffectedrows=$this->db->affected_rows();
 
 			if ($nbaffectedrows)
-            {
-		        $this->pass=$password;
-		        $this->pass_indatabase=$password_indatabase;
+			{
+				$this->pass=$password;
+				$this->pass_indatabase=$password_indatabase;
 
 				if ($this->user_id && ! $nosyncuser)
 				{
@@ -827,39 +733,39 @@ class Adherent extends CommonObject
 
 				if (! $error && ! $notrigger)
 				{
-	                // Appel des triggers
-	                include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
-	                $interface=new Interfaces($this->db);
-	                $result=$interface->run_triggers('MEMBER_NEW_PASSWORD',$this,$user,$langs,$conf);
-	                if ($result < 0) { $error++; $this->errors=$interface->errors; }
-	                // Fin appel triggers
+					// Appel des triggers
+					include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
+					$interface=new Interfaces($this->db);
+					$result=$interface->run_triggers('MEMBER_NEW_PASSWORD',$this,$user,$langs,$conf);
+					if ($result < 0) { $error++; $this->errors=$interface->errors; }
+					// Fin appel triggers
 				}
-				
-                return $this->pass;
-            }
-            else
+
+				return $this->pass;
+			}
+			else
 			{
-                return 0;
-            }
-        }
-        else
-        {
-            dolibarr_print_error($this->db);
-            return -1;
-        }
-    }
-	
-	
+				return 0;
+			}
+		}
+		else
+		{
+			dolibarr_print_error($this->db);
+			return -1;
+		}
+	}
+
+
 	/**
-	*		\brief      Fonction qui recupere l'adherent depuis son login
-	*		\param	    login		login de l'adherent
-	*/
+	 *		\brief      Fonction qui recupere l'adherent depuis son login
+	 *		\param	    login		login de l'adherent
+	 */
 	function fetch_login($login)
 	{
 		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent WHERE login='$login'";
-	
+
 		$resql=$this->db->query( $sql);
-	
+
 		if ($resql)
 		{
 			if ($this->db->num_rows($resql))
@@ -875,128 +781,128 @@ class Adherent extends CommonObject
 	}
 
 
-    /**
-    		\brief 		Fonction qui recupere l'adherent en donnant son rowid
-    		\param		rowid
-    		\return		int			<0 si KO, >0 si OK
-    */
-    function fetch($rowid)
-    {
-        global $langs;
-
-        $sql = "SELECT d.rowid, d.prenom, d.nom, d.societe, d.statut, d.public, d.adresse, d.cp, d.ville, d.note,";
-        $sql.= " d.email, d.phone, d.phone_perso, d.phone_mobile, d.login, d.pass,";
-        $sql.= " d.photo, d.fk_adherent_type, d.morphy,";
-        $sql.= " ".$this->db->pdate("d.datec")." as datec,";
-        $sql.= " ".$this->db->pdate("d.tms")." as datem,";
-        $sql.= " ".$this->db->pdate("d.datefin")." as datefin,";
-   		$sql.= " d.naiss as datenaiss,";
-        $sql.= " ".$this->db->pdate("d.datevalid")." as datev,";
-        $sql.= " d.pays,";
-        $sql.= " p.rowid as pays_id, p.code as pays_code, p.libelle as pays_lib,";
-        $sql.= " t.libelle as type, t.cotisation as cotisation,";
-        $sql.= " u.rowid as user_id, u.login as user_login";
-        $sql.= " FROM ".MAIN_DB_PREFIX."adherent_type as t, ".MAIN_DB_PREFIX."adherent as d";
-        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_pays as p ON d.pays = p.rowid";
-        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON d.rowid = u.fk_member";
-        $sql.= " WHERE d.fk_adherent_type = t.rowid";
+	/**
+	 *	\brief 		Fonction qui recupere l'adherent en donnant son rowid
+	 *	\param		rowid
+	 *	\return		int			<0 si KO, >0 si OK
+	 */
+	function fetch($rowid)
+	{
+		global $langs;
+
+		$sql = "SELECT d.rowid, d.prenom, d.nom, d.societe, d.statut, d.public, d.adresse, d.cp, d.ville, d.note,";
+		$sql.= " d.email, d.phone, d.phone_perso, d.phone_mobile, d.login, d.pass,";
+		$sql.= " d.photo, d.fk_adherent_type, d.morphy,";
+		$sql.= " ".$this->db->pdate("d.datec")." as datec,";
+		$sql.= " ".$this->db->pdate("d.tms")." as datem,";
+		$sql.= " ".$this->db->pdate("d.datefin")." as datefin,";
+		$sql.= " d.naiss as datenaiss,";
+		$sql.= " ".$this->db->pdate("d.datevalid")." as datev,";
+		$sql.= " d.pays,";
+		$sql.= " p.rowid as pays_id, p.code as pays_code, p.libelle as pays_lib,";
+		$sql.= " t.libelle as type, t.cotisation as cotisation,";
+		$sql.= " u.rowid as user_id, u.login as user_login";
+		$sql.= " FROM ".MAIN_DB_PREFIX."adherent_type as t, ".MAIN_DB_PREFIX."adherent as d";
+		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_pays as p ON d.pays = p.rowid";
+		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON d.rowid = u.fk_member";
+		$sql.= " WHERE d.fk_adherent_type = t.rowid";
 		$sql.= " AND d.rowid = ".$rowid;
 		dolibarr_syslog("Adherent::fetch sql=".$sql);
-		
-        $resql=$this->db->query($sql);
-        if ($resql)
-        {
-            if ($this->db->num_rows($resql))
-            {
-                $obj = $this->db->fetch_object($resql);
+
+		$resql=$this->db->query($sql);
+		if ($resql)
+		{
+			if ($this->db->num_rows($resql))
+			{
+				$obj = $this->db->fetch_object($resql);
 
 				$this->ref            = $obj->rowid;
-                $this->id             = $obj->rowid;
-                $this->prenom         = $obj->prenom;
-                $this->nom            = $obj->nom;
-                $this->fullname       = trim($obj->nom.' '.$obj->prenom);
-                $this->login          = $obj->login;
-                $this->pass           = $obj->pass;
-                $this->societe        = $obj->societe;
-                $this->adresse        = $obj->adresse;
-                $this->cp             = $obj->cp;
-                $this->ville          = $obj->ville;
-                $this->pays_id        = $obj->pays_id;
-                $this->pays_code      = $obj->pays_code;
-                if ($langs->trans("Country".$obj->pays_code) != "Country".$obj->pays_code) $this->pays = $langs->trans("Country".$obj->pays_code);
-                elseif ($obj->pays_lib) $this->pays=$obj->pays_lib;
-                else $this->pays=$obj->pays;
-                $this->phone          = $obj->phone;
-                $this->phone_perso    = $obj->phone_perso;
-                $this->phone_mobile   = $obj->phone_mobile;
-                $this->email          = $obj->email;
-
-                $this->photo          = $obj->photo;
-                $this->statut         = $obj->statut;
-                $this->public         = $obj->public;
-
-                $this->datec          = $obj->datec;
-                $this->datem          = $obj->datem;
-                $this->datefin        = $obj->datefin;
-                $this->datevalid      = $obj->datevalid;
-                $this->naiss          = $obj->datenaiss;
-
-                $this->note           = $obj->note;
-                $this->morphy         = $obj->morphy;
-
-                $this->typeid         = $obj->fk_adherent_type;
-                $this->type           = $obj->type;
-                $this->need_subscription = ($obj->cotisation=='yes'?1:0);
-				
-                $this->user_id        = $obj->user_id;
-                $this->user_login     = $obj->user_login;
-				
+				$this->id             = $obj->rowid;
+				$this->prenom         = $obj->prenom;
+				$this->nom            = $obj->nom;
+				$this->fullname       = trim($obj->nom.' '.$obj->prenom);
+				$this->login          = $obj->login;
+				$this->pass           = $obj->pass;
+				$this->societe        = $obj->societe;
+				$this->adresse        = $obj->adresse;
+				$this->cp             = $obj->cp;
+				$this->ville          = $obj->ville;
+				$this->pays_id        = $obj->pays_id;
+				$this->pays_code      = $obj->pays_code;
+				if ($langs->trans("Country".$obj->pays_code) != "Country".$obj->pays_code) $this->pays = $langs->trans("Country".$obj->pays_code);
+				elseif ($obj->pays_lib) $this->pays=$obj->pays_lib;
+				else $this->pays=$obj->pays;
+				$this->phone          = $obj->phone;
+				$this->phone_perso    = $obj->phone_perso;
+				$this->phone_mobile   = $obj->phone_mobile;
+				$this->email          = $obj->email;
+
+				$this->photo          = $obj->photo;
+				$this->statut         = $obj->statut;
+				$this->public         = $obj->public;
+
+				$this->datec          = $obj->datec;
+				$this->datem          = $obj->datem;
+				$this->datefin        = $obj->datefin;
+				$this->datevalid      = $obj->datevalid;
+				$this->naiss          = $obj->datenaiss;
+
+				$this->note           = $obj->note;
+				$this->morphy         = $obj->morphy;
+
+				$this->typeid         = $obj->fk_adherent_type;
+				$this->type           = $obj->type;
+				$this->need_subscription = ($obj->cotisation=='yes'?1:0);
+
+				$this->user_id        = $obj->user_id;
+				$this->user_login     = $obj->user_login;
+
 				// Charge autres proprietes
 				$result=$this->fetch_subscriptions();
 
 				return $result;
-            }
+			}
 			else
 			{
 				return -1;
 			}
-        }
-        else
-        {
-            $this->error=$this->db->error();
+		}
+		else
+		{
+			$this->error=$this->db->error();
 			return -1;
-        }
-    }
-
-
-    /**
-    		\brief 		Fonction qui recupere pour un adherent les parametres
-						firstsubscription_date
-						fistrsubscription_amount
-						lastsubscription_date
-						lastsubscription_amount
-    		\return		int			<0 si KO, >0 si OK
-    */
-    function fetch_subscriptions()
-    {
-        global $langs;
-
-        $sql = "SELECT c.rowid, c.fk_adherent, c.cotisation, c.note, c.fk_bank,";
-        $sql.= " ".$this->db->pdate("c.tms")." as datem,";
-        $sql.= " ".$this->db->pdate("c.datec")." as datec,";
-        $sql.= " ".$this->db->pdate("c.dateadh")." as dateadh";
-        $sql.= " FROM ".MAIN_DB_PREFIX."cotisation as c";
-        $sql.= " WHERE c.fk_adherent = ".$this->id;
-        $sql.= " ORDER BY c.dateadh";
+		}
+	}
+
+
+	/**
+	 *	\brief 		Fonction qui recupere pour un adherent les parametres
+	 *				firstsubscription_date
+	 *				fistrsubscription_amount
+	 *				lastsubscription_date
+	 *				lastsubscription_amount
+	 *	\return		int			<0 si KO, >0 si OK
+	 */
+	function fetch_subscriptions()
+	{
+		global $langs;
+
+		$sql = "SELECT c.rowid, c.fk_adherent, c.cotisation, c.note, c.fk_bank,";
+		$sql.= " ".$this->db->pdate("c.tms")." as datem,";
+		$sql.= " ".$this->db->pdate("c.datec")." as datec,";
+		$sql.= " ".$this->db->pdate("c.dateadh")." as dateadh";
+		$sql.= " FROM ".MAIN_DB_PREFIX."cotisation as c";
+		$sql.= " WHERE c.fk_adherent = ".$this->id;
+		$sql.= " ORDER BY c.dateadh";
 		dolibarr_syslog("Adherent::fetch_subscriptions sql=".$sql);
-		
-        $resql=$this->db->query($sql);
-        if ($resql)
-        {
-            $i=0;
+
+		$resql=$this->db->query($sql);
+		if ($resql)
+		{
+			$i=0;
 			while ($obj = $this->db->fetch_object($resql))
 			{
-				if ($i==0) 
+				if ($i==0)
 				{
 					$this->firstsubscription_date=$obj->dateadh;
 					$this->firstsubscription_amount=$obj->cotisation;
@@ -1004,116 +910,116 @@ class Adherent extends CommonObject
 				$this->lastsubscription_date=$obj->dateadh;
 				$this->lastsubscription_amount=$obj->cotisation;
 
-				// TODO Completer avec records
+				// TODO Add also array of subscription records
 
 				$i++;
 			}
 			return 1;
-        }
-        else
-        {
-            $this->error=$this->db->error().' sql='.$sql;
+		}
+		else
+		{
+			$this->error=$this->db->error().' sql='.$sql;
 			return -1;
-        }
-    }
-	
-	
+		}
+	}
+
+
 	/**
-		\brief      Fonction qui recupere les donnees optionelles de l'adherent
-		\param	    rowid
-	*/
+	 *	\brief      Fonction qui recupere les donnees optionelles de l'adherent
+	 *	\param	    rowid
+	 */
 	function fetch_optionals($rowid)
-  {
-    $tab=array();
-    $sql = "SELECT *";
-    $sql .= " FROM ".MAIN_DB_PREFIX."adherent_options";
-    $sql .= " WHERE adhid=".$rowid;
-
-    $result=$this->db->query( $sql);
-
-    if ($result)
-    {
-    	if ($this->db->num_rows())
-    	{
-    	  $tab = $this->db->fetch_array($result);
-
-    	  foreach ($tab as $key => $value)
-    	  {
-    	    if ($key != 'optid' && $key != 'tms' && $key != 'adhid')
-    	    {
-    	      // we can add this attribute to adherent object
-    	      $this->array_options["options_$key"]=$value;
-    	    }
-    	  }
-    	}
-    }
-    else
-    {
-      dolibarr_print_error($this->db);
-    }
-
-  }
-
-  /*
-   * fetch optional attribute name
-   */
-  function fetch_name_optionals()
-  {
-    $array_name_options=array();
-    $sql = "SHOW COLUMNS FROM ".MAIN_DB_PREFIX."adherent_options";
-
-    $result=$this->db->query( $sql);
-
-    if ($result)
-    {
-        if ($this->db->num_rows())
-        {
-            //$array_name_options[]=$tab->Field;
-            while ($tab = $this->db->fetch_object($result))
-            {
-                if ($tab->Field != 'optid' && $tab->Field != 'tms' && $tab->Field != 'adhid')
-                {
-                    // we can add this attribute to adherent object
-                    $array_name_options[]=$tab->Field;
-                }
-            }
-            return $array_name_options;
-        }
-        else
-        {
-            return array();
-        }
-    }
-    else
-    {
-        dolibarr_print_error($this->db);
-        return array() ;
-    }
-
-  }
-
-    /**
-    		\brief      Fonction qui insere la cotisation dans la base de donnees
-    					et eventuellement liens dans banques, mailman, etc...
-    		\param	    date        	Date d'effet de la cotisation
-    		\param	    montant     	Montant cotisation (accepte 0 pour les adherents non soumis e cotisation)
-    		\param		account_id		Id compte bancaire
-    		\param		operation		Type operation (si Id compte bancaire fourni)
-    		\param		label			Label operation (si Id compte bancaire fourni)
-    		\param		num_chq			Numero cheque (si Id compte bancaire fourni)
-    		\param		emetteur_nom	Nom emetteur cheque
-    		\param		emetteur_banque	Nom banque emetteur cheque
-			\param		datesubend		Date fin adhesion
-            \return     int         	rowid de l'entree ajoutee, <0 si erreur
-    */
-    function cotisation($date, $montant, $accountid=0, $operation='', $label='', $num_chq='', $emetteur_nom='', $emetteur_banque='', $datesubend=0)
-    {
-        global $conf,$langs,$user;
+	{
+		$tab=array();
+		$sql = "SELECT *";		// \TODO Should not use this syntax
+		$sql.= " FROM ".MAIN_DB_PREFIX."adherent_options";
+		$sql.= " WHERE adhid=".$rowid;
+
+		$result=$this->db->query( $sql);
+
+		if ($result)
+		{
+			if ($this->db->num_rows())
+			{
+				$tab = $this->db->fetch_array($result);
+
+				foreach ($tab as $key => $value)
+				{
+					if ($key != 'optid' && $key != 'tms' && $key != 'adhid')
+					{
+						// we can add this attribute to adherent object
+						$this->array_options["options_$key"]=$value;
+					}
+				}
+			}
+		}
+		else
+		{
+			dolibarr_print_error($this->db);
+		}
+
+	}
+
+	/**
+	 * 	\brief	Fetch optional attribute name
+	 */
+	function fetch_name_optionals()
+	{
+		$array_name_options=array();
+		$sql = "SHOW COLUMNS FROM ".MAIN_DB_PREFIX."adherent_options";
+
+		$result=$this->db->query( $sql);
+
+		if ($result)
+		{
+			if ($this->db->num_rows())
+			{
+				//$array_name_options[]=$tab->Field;
+				while ($tab = $this->db->fetch_object($result))
+				{
+					if ($tab->Field != 'optid' && $tab->Field != 'tms' && $tab->Field != 'adhid')
+					{
+						// we can add this attribute to adherent object
+						$array_name_options[]=$tab->Field;
+					}
+				}
+				return $array_name_options;
+			}
+			else
+			{
+				return array();
+			}
+		}
+		else
+		{
+			dolibarr_print_error($this->db);
+			return array() ;
+		}
+
+	}
+
+	/**
+	 \brief      Fonction qui insere la cotisation dans la base de donnees
+	 et eventuellement liens dans banques, mailman, etc...
+	 \param	    date        	Date d'effet de la cotisation
+	 \param	    montant     	Montant cotisation (accepte 0 pour les adherents non soumis e cotisation)
+	 \param		account_id		Id compte bancaire
+	 \param		operation		Type operation (si Id compte bancaire fourni)
+	 \param		label			Label operation (si Id compte bancaire fourni)
+	 \param		num_chq			Numero cheque (si Id compte bancaire fourni)
+	 \param		emetteur_nom	Nom emetteur cheque
+	 \param		emetteur_banque	Nom banque emetteur cheque
+	 \param		datesubend		Date fin adhesion
+	 \return     int         	rowid de l'entree ajoutee, <0 si erreur
+	 */
+	function cotisation($date, $montant, $accountid=0, $operation='', $label='', $num_chq='', $emetteur_nom='', $emetteur_banque='', $datesubend=0)
+	{
+		global $conf,$langs,$user;
 
 		// Nettoyage parametres
 		if (! $montant) $montant=0;
-		
-        $this->db->begin();
+
+		$this->db->begin();
 
 		if ($datesubend)
 		{
@@ -1135,59 +1041,59 @@ class Adherent extends CommonObject
 		$cotisation->note=$label;
 
 		$rowid=$cotisation->create($user);
-		
-        if ($rowid > 0)
-        {
+
+		if ($rowid > 0)
+		{
 			// Update denormalized subscription end date
-            $result=$this->update_end_date($user);
-            if ($result > 0)
-            {
-		        // Rajout du nouveau cotisant dans les listes qui vont bien
-		        if ($conf->global->ADHERENT_MAILMAN_LISTS_COTISANT && ! $adh->datefin)
-		        {
-		            $result=$adh->add_to_mailman($conf->global->ADHERENT_MAILMAN_LISTS_COTISANT);
-		        }
-
-	            // Insertion dans la gestion bancaire si configure pour
-	            if ($conf->global->ADHERENT_BANK_USE && $accountid)
-	            {
-	                $acct=new Account($this->db);
+			$result=$this->update_end_date($user);
+			if ($result > 0)
+			{
+				// Rajout du nouveau cotisant dans les listes qui vont bien
+				if ($conf->global->ADHERENT_MAILMAN_LISTS_COTISANT && ! $adh->datefin)
+				{
+					$result=$adh->add_to_mailman($conf->global->ADHERENT_MAILMAN_LISTS_COTISANT);
+				}
+
+				// Insertion dans la gestion bancaire si configure pour
+				if ($conf->global->ADHERENT_BANK_USE && $accountid)
+				{
+					$acct=new Account($this->db);
 					$result=$acct->fetch($accountid);
-					
-	                $dateop=time();
-
-	                $insertid=$acct->addline($dateop, $operation, $label, $montant, $num_chq, '', $user, $emetteur_nom, $emetteur_banque);
-	                if ($insertid > 0)
-	                {
-	        			$inserturlid=$acct->add_url_line($insertid, $this->id, DOL_URL_ROOT.'/adherents/fiche.php?rowid=', $this->getFullname(), 'member');
-	                    if ($inserturlid > 0)
-	                    {
-	                        // Met a jour la table cotisation
+
+					$dateop=time();
+
+					$insertid=$acct->addline($dateop, $operation, $label, $montant, $num_chq, '', $user, $emetteur_nom, $emetteur_banque);
+					if ($insertid > 0)
+					{
+						$inserturlid=$acct->add_url_line($insertid, $this->id, DOL_URL_ROOT.'/adherents/fiche.php?rowid=', $this->getFullname(), 'member');
+						if ($inserturlid > 0)
+						{
+							// Met a jour la table cotisation
 							$sql="UPDATE ".MAIN_DB_PREFIX."cotisation SET fk_bank=".$insertid." WHERE rowid=".$rowid;
-	                        
+
 							dolibarr_syslog("Adherent::cotisation sql=".$sql);
 							$resql = $this->db->query($sql);
-	                        if (! $resql)
-	                        {
-				                $this->error=$this->db->error();
-				                $this->db->rollback();
-				                return -5;
-	                        }
-	                    }
-	                    else
-	                    {
-			                $this->error=$acct->error();
-			                $this->db->rollback();
-			                return -4;
-	                    }
-	                }
-	                else
-	                {
-		                $this->error=$acct->error;
-		                $this->db->rollback();
-		                return -3;
-	                }
-	            }
+							if (! $resql)
+							{
+								$this->error=$this->db->error();
+								$this->db->rollback();
+								return -5;
+							}
+						}
+						else
+						{
+							$this->error=$acct->error();
+							$this->db->rollback();
+							return -4;
+						}
+					}
+					else
+					{
+						$this->error=$acct->error;
+						$this->db->rollback();
+						return -3;
+					}
+				}
 
 				// Ajout de proprietes pour le triggers
 				$this->last_subscription_date=$dateop;
@@ -1195,40 +1101,48 @@ class Adherent extends CommonObject
 				$this->last_subscription_date_end=$datefin;
 				$this->last_subscription_amount=$montant;
 				$this->use_webcal=($conf->global->PHPWEBCALENDAR_MEMBERSTATUS=='always'?1:0);
-				
-                // Appel des triggers
-                include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
-                $interface=new Interfaces($this->db);
-                $result=$interface->run_triggers('MEMBER_SUBSCRIPTION',$this,$user,$langs,$conf);
-                if ($result < 0) { $error++; $this->errors=$interface->errors; }
-                // Fin appel triggers
-
-               	$this->db->commit();
-               	return $rowid;
-            }
-            else
-            {
-                $this->db->rollback();
-                return -2;
-            }
-        }
-        else
-        {
-            $this->error=$cotisation->error;
-            $this->db->rollback();
-            return -1;
-        }
-    }
+
+				// Appel des triggers
+				include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
+				$interface=new Interfaces($this->db);
+				$result=$interface->run_triggers('MEMBER_SUBSCRIPTION',$this,$user,$langs,$conf);
+				if ($result < 0) { $error++; $this->errors=$interface->errors; }
+				// Fin appel triggers
+
+				$this->db->commit();
+				return $rowid;
+			}
+			else
+			{
+				$this->db->rollback();
+				return -2;
+			}
+		}
+		else
+		{
+			$this->error=$cotisation->error;
+			$this->db->rollback();
+			return -1;
+		}
+	}
 
 	/**
 	 *		\brief 		Function that validate a member
 	 *		\param		user		user adherent qui valide
-	 *		\return		int			<0 si ko, >0 si ok
+	 *		\return		int			<0 if KO, 0 if nothing done, >0 if OK
 	 */
 	function validate($user)
 	{
 		global $langs,$conf;
 
+		if ($this->statut == 1)
+		{
+			dolibarr_syslog("Adherent::validate statut of member does not allow this", LOG_WARNING);
+			return 0;	
+		}
+		
+		$this->db->begin();
+		
 		$sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
 		$sql.= " statut=1, datevalid = ".$this->db->idate(mktime()).",";
 		$sql.= " fk_user_valid=".$user->id;
@@ -1241,12 +1155,12 @@ class Adherent extends CommonObject
 			$this->statut=1;
 
 			$this->use_webcal=($conf->global->PHPWEBCALENDAR_MEMBERSTATUS=='always'?1:0);
-			
+
 			// Appel des triggers
 			include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
 			$interface=new Interfaces($this->db);
 			$result=$interface->run_triggers('MEMBER_VALIDATE',$this,$user,$langs,$conf);
-            if ($result < 0) { $error++; $this->errors=$interface->errors; }
+			if ($result < 0) { $error++; $this->errors=$interface->errors; }
 			// Fin appel triggers
 
 			$this->db->commit();
@@ -1270,12 +1184,18 @@ class Adherent extends CommonObject
 	{
 		global $langs,$conf;
 
+		if ($this->statut == 0)
+		{
+			dolibarr_syslog("Adherent::resiliate statut of member does not allow this", LOG_WARNING);
+			return 0;	
+		}
+		
 		$this->db->begin();
 
-		$sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET ";
-		$sql .= "statut=0";
-		$sql .= ",fk_user_valid=".$user->id;
-		$sql .= " WHERE rowid = ".$this->id;
+		$sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
+		$sql.= " statut=0,";
+		$sql.= " fk_user_valid=".$user->id;
+		$sql.= " WHERE rowid = ".$this->id;
 
 		$result = $this->db->query($sql);
 		if ($result)
@@ -1284,12 +1204,12 @@ class Adherent extends CommonObject
 
 			$this->use_webcal=($conf->global->PHPWEBCALENDAR_MEMBERSTATUS=='always'?1:0);
 
-	        // Appel des triggers
-	        include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
-	        $interface=new Interfaces($this->db);
-	        $result=$interface->run_triggers('MEMBER_RESILIATE',$this,$user,$langs,$conf);
-            if ($result < 0) { $error++; $this->errors=$interface->errors; }
-	        // Fin appel triggers
+			// Appel des triggers
+			include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
+			$interface=new Interfaces($this->db);
+			$result=$interface->run_triggers('MEMBER_RESILIATE',$this,$user,$langs,$conf);
+			if ($result < 0) { $error++; $this->errors=$interface->errors; }
+			// Fin appel triggers
 
 			$this->db->commit();
 			return 1;
@@ -1304,11 +1224,11 @@ class Adherent extends CommonObject
 
 
 	/**
-			\brief 		Fonction qui ajoute l'adherent au abonnements automatiques
-			\param		adht
-			\remarks	mailing-list, spip, etc...
-			\return		int		<0 si KO, >=0 si OK
-	*/
+	 \brief 		Fonction qui ajoute l'adherent au abonnements automatiques
+	 \param		adht
+	 \remarks	mailing-list, spip, etc...
+	 \return		int		<0 si KO, >=0 si OK
+	 */
 	function add_to_abo($adht)
 	{
 		$err=0;
@@ -1322,7 +1242,7 @@ class Adherent extends CommonObject
 				$err+=1;
 			}
 		}
-	
+
 		// spip
 		if (
 		defined("ADHERENT_USE_SPIP") && ADHERENT_USE_SPIP ==1 &&
@@ -1348,10 +1268,10 @@ class Adherent extends CommonObject
 
 
 	/**
-			\brief      fonction qui supprime l'adherent des abonnements automatiques
-			\param	    adht
-			\remarks	mailing-list, spip, etc...
-	*/
+	 \brief      fonction qui supprime l'adherent des abonnements automatiques
+	 \param	    adht
+	 \remarks	mailing-list, spip, etc...
+	 */
 	function del_to_abo($adht)
 	{
 		$err=0;
@@ -1375,16 +1295,16 @@ class Adherent extends CommonObject
 		if ($err>0){
 			// error
 			return 0;
-			}else{
-				return 1;
-			}
+		}else{
+			return 1;
 		}
+	}
 
 
 	/**
-			\brief fonction qui donne les droits redacteurs dans spip
-			\return		int		=0 si KO, >0 si OK
-	*/
+	 \brief fonction qui donne les droits redacteurs dans spip
+	 \return		int		=0 si KO, >0 si OK
+	 */
 	function add_to_spip()
 	{
 		require_once(DOL_DOCUMENT_ROOT.'/lib/security.lib.php');
@@ -1392,11 +1312,11 @@ class Adherent extends CommonObject
 		dolibarr_syslog("Adherent::add_to_spip");
 
 		if (defined("ADHERENT_USE_SPIP") && ADHERENT_USE_SPIP ==1 &&
-				defined('ADHERENT_SPIP_SERVEUR') && ADHERENT_SPIP_SERVEUR != '' &&
-				defined('ADHERENT_SPIP_USER') && ADHERENT_SPIP_USER != '' &&
-				defined('ADHERENT_SPIP_PASS') && ADHERENT_SPIP_PASS != '' &&
-				defined('ADHERENT_SPIP_DB') && ADHERENT_SPIP_DB != ''
-				){
+		defined('ADHERENT_SPIP_SERVEUR') && ADHERENT_SPIP_SERVEUR != '' &&
+		defined('ADHERENT_SPIP_USER') && ADHERENT_SPIP_USER != '' &&
+		defined('ADHERENT_SPIP_PASS') && ADHERENT_SPIP_PASS != '' &&
+		defined('ADHERENT_SPIP_DB') && ADHERENT_SPIP_DB != ''
+		){
 			$mdpass=md5($this->pass);
 			$htpass=crypt($this->pass,makesalt());
 			$query = "INSERT INTO spip_auteurs (nom, email, login, pass, htpass, alea_futur, statut) VALUES(\"".$this->prenom." ".$this->nom."\",\"".$this->email."\",\"".$this->login."\",\"$mdpass\",\"$htpass\",FLOOR(32000*RAND()),\"1comite\")";
@@ -1418,98 +1338,98 @@ class Adherent extends CommonObject
 	}
 
 	/**
-			\brief fonction qui enleve les droits redacteurs dans spip
-	*/
+	 \brief fonction qui enleve les droits redacteurs dans spip
+	 */
 	function del_to_spip()
-    {
-      if (defined("ADHERENT_USE_SPIP") && ADHERENT_USE_SPIP ==1 &&
-	  defined('ADHERENT_SPIP_SERVEUR') && ADHERENT_SPIP_SERVEUR != '' &&
-	  defined('ADHERENT_SPIP_USER') && ADHERENT_SPIP_USER != '' &&
-	  defined('ADHERENT_SPIP_PASS') && ADHERENT_SPIP_PASS != '' &&
-	  defined('ADHERENT_SPIP_DB') && ADHERENT_SPIP_DB != ''
-	  ){
-	$query = "DELETE FROM spip_auteurs WHERE login='".$this->login."'";
-	$mydb=new DoliDb('mysql',ADHERENT_SPIP_SERVEUR,ADHERENT_SPIP_USER,ADHERENT_SPIP_PASS,ADHERENT_SPIP_DB,ADHERENT_SPIP_PORT);
-	$result = $mydb->query($query);
-
-	if ($result)
+	{
+		if (defined("ADHERENT_USE_SPIP") && ADHERENT_USE_SPIP ==1 &&
+		defined('ADHERENT_SPIP_SERVEUR') && ADHERENT_SPIP_SERVEUR != '' &&
+		defined('ADHERENT_SPIP_USER') && ADHERENT_SPIP_USER != '' &&
+		defined('ADHERENT_SPIP_PASS') && ADHERENT_SPIP_PASS != '' &&
+		defined('ADHERENT_SPIP_DB') && ADHERENT_SPIP_DB != ''
+		){
+			$query = "DELETE FROM spip_auteurs WHERE login='".$this->login."'";
+			$mydb=new DoliDb('mysql',ADHERENT_SPIP_SERVEUR,ADHERENT_SPIP_USER,ADHERENT_SPIP_PASS,ADHERENT_SPIP_DB,ADHERENT_SPIP_PORT);
+			$result = $mydb->query($query);
+
+			if ($result)
 	  {
-	    $mydb->close();
-	    return 1;
+	  	$mydb->close();
+	  	return 1;
 	  }
-	else
+	  else
 	  {
-	    $this->error=$mydb->error();
-	    return 0;
+	  	$this->error=$mydb->error();
+	  	return 0;
 	  }
-      }
-    }
+		}
+	}
 
 	/**
-			\brief      Fonction qui dit si cet utilisateur est un redacteur existant dans spip
-			\return     int     1=existe, 0=n'existe pas, -1=erreur
-	*/
+	 \brief      Fonction qui dit si cet utilisateur est un redacteur existant dans spip
+	 \return     int     1=existe, 0=n'existe pas, -1=erreur
+	 */
 	function is_in_spip()
-    {
-        if (defined("ADHERENT_USE_SPIP") && ADHERENT_USE_SPIP ==1 &&
-            defined('ADHERENT_SPIP_SERVEUR') && ADHERENT_SPIP_SERVEUR != '' &&
-            defined('ADHERENT_SPIP_USER') && ADHERENT_SPIP_USER != '' &&
-            defined('ADHERENT_SPIP_PASS') && ADHERENT_SPIP_PASS != '' &&
-            defined('ADHERENT_SPIP_DB') && ADHERENT_SPIP_DB != '')
-        {
-
-            $query = "SELECT login FROM spip_auteurs WHERE login='".$this->login."'";
-            $mydb=new DoliDb('mysql',ADHERENT_SPIP_SERVEUR,ADHERENT_SPIP_USER,ADHERENT_SPIP_PASS,ADHERENT_SPIP_DB,ADHERENT_SPIP_PORT);
-
-            if ($mydb->ok) {
-
-                $result = $mydb->query($query);
-
-                if ($result)
-                {
-                    if ($mydb->num_rows())
-                    {
-                        # nous avons au moins une reponse
-                        $mydb->close();
-                        return 1;
-                    }
-                    else
-                    {
-                    # nous n'avons pas de reponse => n'existe pas
-                    $mydb->close();
-                    return 0;
-                    }
-                }
-                else
-                {
-                    # error
-                    $this->error=$mydb->error();
-                    return -1;
-                }
-            } else {
-                $this->error="Echec de connexion avec les identifiants ".ADHERENT_SPIP_SERVEUR." ".ADHERENT_SPIP_USER." ".ADHERENT_SPIP_PASS." ".ADHERENT_SPIP_DB;
-                return -1;
-            }
-        }
-    }
+	{
+		if (defined("ADHERENT_USE_SPIP") && ADHERENT_USE_SPIP ==1 &&
+		defined('ADHERENT_SPIP_SERVEUR') && ADHERENT_SPIP_SERVEUR != '' &&
+		defined('ADHERENT_SPIP_USER') && ADHERENT_SPIP_USER != '' &&
+		defined('ADHERENT_SPIP_PASS') && ADHERENT_SPIP_PASS != '' &&
+		defined('ADHERENT_SPIP_DB') && ADHERENT_SPIP_DB != '')
+		{
+
+			$query = "SELECT login FROM spip_auteurs WHERE login='".$this->login."'";
+			$mydb=new DoliDb('mysql',ADHERENT_SPIP_SERVEUR,ADHERENT_SPIP_USER,ADHERENT_SPIP_PASS,ADHERENT_SPIP_DB,ADHERENT_SPIP_PORT);
+
+			if ($mydb->ok) {
+
+				$result = $mydb->query($query);
+
+				if ($result)
+				{
+					if ($mydb->num_rows())
+					{
+						# nous avons au moins une reponse
+						$mydb->close();
+						return 1;
+					}
+					else
+					{
+						# nous n'avons pas de reponse => n'existe pas
+						$mydb->close();
+						return 0;
+					}
+				}
+				else
+				{
+					# error
+					$this->error=$mydb->error();
+					return -1;
+				}
+			} else {
+				$this->error="Echec de connexion avec les identifiants ".ADHERENT_SPIP_SERVEUR." ".ADHERENT_SPIP_USER." ".ADHERENT_SPIP_PASS." ".ADHERENT_SPIP_DB;
+				return -1;
+			}
+		}
+	}
 
 	/**
-			\brief 		Fonction qui rajoute l'utilisateur dans mailman
-			\return		int		<0 si KO, >0 si OK
-	*/
+	 \brief 		Fonction qui rajoute l'utilisateur dans mailman
+	 \return		int		<0 si KO, >0 si OK
+	 */
 	function add_to_mailman($listes='')
 	{
 		global $conf,$langs;
-		
+
 		dolibarr_syslog("Adherent::add_to_mailman");
 
 		if (! function_exists("curl_init"))
 		{
 			$langs->load("errors");
 			$this->error=$langs->trans("ErrorFunctionNotAvailableInPHP","curl_init");
-			return -1;	
+			return -1;
 		}
-		
+
 		if (defined("ADHERENT_MAILMAN_URL") && ADHERENT_MAILMAN_URL != '' && defined("ADHERENT_MAILMAN_LISTS") && ADHERENT_MAILMAN_LISTS != '')
 		{
 			if ($listes =='')
@@ -1518,7 +1438,7 @@ class Adherent extends CommonObject
 			}
 			else
 			{
-					$lists=explode(',',$listes);
+				$lists=explode(',',$listes);
 			}
 			foreach ($lists as $list)
 			{
@@ -1573,11 +1493,11 @@ class Adherent extends CommonObject
 	/**
 		\brief 		Fonction qui desinscrit l'utilisateur de toutes les mailing list mailman
 		\remarks	Utilise lors de la resiliation d'adhesion
-	*/
+		*/
 	function del_to_mailman($listes='')
 	{
 		global $conf;
-		
+
 		if (defined("ADHERENT_MAILMAN_UNSUB_URL") && ADHERENT_MAILMAN_UNSUB_URL != '' && defined("ADHERENT_MAILMAN_LISTS") && ADHERENT_MAILMAN_LISTS != '')
 		{
 			if ($listes==''){
@@ -1642,13 +1562,13 @@ class Adherent extends CommonObject
 	 *    \brief      Retourne le nom complet de l'adherent
 	 *    \return     string      	Nom complet
 	 */
-    function getFullname()
-    {
-        if ($this->nom && $this->prenom) return $this->nom.' '.$this->prenom;
-        if ($this->nom)    return $this->nom;
-        if ($this->prenom) return $this->prenom;
-        return '';
-    }
+	function getFullname()
+	{
+		if ($this->nom && $this->prenom) return $this->nom.' '.$this->prenom;
+		if ($this->nom)    return $this->nom;
+		if ($this->prenom) return $this->prenom;
+		return '';
+	}
 
 
 	/**
@@ -1661,7 +1581,7 @@ class Adherent extends CommonObject
 	function getNomUrl($withpicto=0,$maxlen=0,$option='card')
 	{
 		global $langs;
-		
+
 		$result='';
 
 		if ($option == 'card')
@@ -1674,10 +1594,10 @@ class Adherent extends CommonObject
 			$lien = '<a href="'.DOL_URL_ROOT.'/adherents/card_subscriptions.php?rowid='.$this->id.'">';
 			$lienfin='</a>';
 		}
-		
+
 		$picto='user';
 		$label=$langs->trans("ShowMember");
-		
+
 		if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin);
 		if ($withpicto && $withpicto != 2) $result.=' ';
 		$result.=$lien.($maxlen?dolibarr_trunc($this->ref,$maxlen):$this->ref).$lienfin;
@@ -1690,157 +1610,157 @@ class Adherent extends CommonObject
 	 *    	\param      mode        0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
 	 *    	\return     string		Libelle
 	 */
-    function getLibStatut($mode=0)
-    {
+	function getLibStatut($mode=0)
+	{
 		return $this->LibStatut($this->statut,$this->need_subscription,$this->datefin,$mode);
-    }
+	}
 
 	/**
-	*    	\brief      Renvoi le libelle d'un statut donne
- 	*    	\param      statut      			Id statut
-	*		\param		need_subscription		1 si type adherent avec cotisation, 0 sinon
-	*		\param		date_end_subscription	Date fin adhesion
-	*    	\param      mode        			0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
- 	*    	\return     string      			Libelle
- 	*/
-    function LibStatut($statut,$need_subscription,$date_end_subscription,$mode=0)
-    {
-        global $langs;
-        $langs->load("members");
+	 *    	\brief      Renvoi le libelle d'un statut donne
+	 *    	\param      statut      			Id statut
+	 *		\param		need_subscription		1 si type adherent avec cotisation, 0 sinon
+	 *		\param		date_end_subscription	Date fin adhesion
+	 *    	\param      mode        			0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
+	 *    	\return     string      			Libelle
+	 */
+	function LibStatut($statut,$need_subscription,$date_end_subscription,$mode=0)
+	{
+		global $langs;
+		$langs->load("members");
 		if ($mode == 0)
 		{
-	        if ($statut == -1) return $langs->trans("MemberStatusDraft");
-	        if ($statut >= 1)
-	        {
-	        	if (! $date_end_subscription)            return $langs->trans("MemberStatusActive");
-	        	elseif ($date_end_subscription < time()) return $langs->trans("MemberStatusActiveLate");
-	        	else                                     return $langs->trans("MemberStatusPayed");
-	        }
-	        if ($statut == 0)  return $langs->trans("MemberStatusResiliated");
+			if ($statut == -1) return $langs->trans("MemberStatusDraft");
+			if ($statut >= 1)
+			{
+				if (! $date_end_subscription)            return $langs->trans("MemberStatusActive");
+				elseif ($date_end_subscription < time()) return $langs->trans("MemberStatusActiveLate");
+				else                                     return $langs->trans("MemberStatusPayed");
+			}
+			if ($statut == 0)  return $langs->trans("MemberStatusResiliated");
 		}
 		if ($mode == 1)
 		{
-	        if ($statut == -1) return $langs->trans("MemberStatusDraft");
-	        if ($statut >= 1)
-	        {
-	        	if (! $date_end_subscription)            return $langs->trans("MemberStatusActiveShort");
-	        	elseif ($date_end_subscription < time()) return $langs->trans("MemberStatusActiveLateShort");
-	        	else                                     return $langs->trans("MemberStatusPayedShort");
-	        }
-	        if ($statut == 0)  return $langs->trans("MemberStatusResiliated");
+			if ($statut == -1) return $langs->trans("MemberStatusDraft");
+			if ($statut >= 1)
+			{
+				if (! $date_end_subscription)            return $langs->trans("MemberStatusActiveShort");
+				elseif ($date_end_subscription < time()) return $langs->trans("MemberStatusActiveLateShort");
+				else                                     return $langs->trans("MemberStatusPayedShort");
+			}
+			if ($statut == 0)  return $langs->trans("MemberStatusResiliated");
 		}
 		if ($mode == 2)
 		{
-	        if ($statut == -1) return img_picto($langs->trans('MemberStatusDraft'),'statut0').' '.$langs->trans("MemberStatusDraft");
-	        if ($statut >= 1)
-	        {
-	        	if (! $date_end_subscription)            return img_picto($langs->trans('MemberStatusActive'),'statut1').' '.$langs->trans("MemberStatusActiveShort");
-	        	elseif ($date_end_subscription < time()) return img_picto($langs->trans('MemberStatusActiveLate'),'statut3').' '.$langs->trans("MemberStatusActiveLateShort");
-	        	else                                     return img_picto($langs->trans('MemberStatusPayed'),'statut4').' '.$langs->trans("MemberStatusPayedShort");
-	        }
-	        if ($statut == 0)  return img_picto($langs->trans('MemberStatusResiliated'),'statut5').' '.$langs->trans("MemberStatusResiliated");
+			if ($statut == -1) return img_picto($langs->trans('MemberStatusDraft'),'statut0').' '.$langs->trans("MemberStatusDraft");
+			if ($statut >= 1)
+			{
+				if (! $date_end_subscription)            return img_picto($langs->trans('MemberStatusActive'),'statut1').' '.$langs->trans("MemberStatusActiveShort");
+				elseif ($date_end_subscription < time()) return img_picto($langs->trans('MemberStatusActiveLate'),'statut3').' '.$langs->trans("MemberStatusActiveLateShort");
+				else                                     return img_picto($langs->trans('MemberStatusPayed'),'statut4').' '.$langs->trans("MemberStatusPayedShort");
+			}
+			if ($statut == 0)  return img_picto($langs->trans('MemberStatusResiliated'),'statut5').' '.$langs->trans("MemberStatusResiliated");
 		}
 		if ($mode == 3)
 		{
-	        if ($statut == -1) return img_picto($langs->trans('MemberStatusDraft'),'statut0');
-	        if ($statut >= 1)
-	        {
-	        	if (! $date_end_subscription)            return img_picto($langs->trans('MemberStatusActive'),'statut1');
-	        	elseif ($date_end_subscription < time()) return img_picto($langs->trans('MemberStatusActiveLate'),'statut3');
-	        	else                                     return img_picto($langs->trans('MemberStatusPayed'),'statut4');
-	        }
-	        if ($statut == 0)  return img_picto($langs->trans('MemberStatusResiliated'),'statut5');
+			if ($statut == -1) return img_picto($langs->trans('MemberStatusDraft'),'statut0');
+			if ($statut >= 1)
+			{
+				if (! $date_end_subscription)            return img_picto($langs->trans('MemberStatusActive'),'statut1');
+				elseif ($date_end_subscription < time()) return img_picto($langs->trans('MemberStatusActiveLate'),'statut3');
+				else                                     return img_picto($langs->trans('MemberStatusPayed'),'statut4');
+			}
+			if ($statut == 0)  return img_picto($langs->trans('MemberStatusResiliated'),'statut5');
 		}
 		if ($mode == 4)
 		{
-	        if ($statut == -1) return img_picto($langs->trans('MemberStatusDraft'),'statut0').' '.$langs->trans("MemberStatusDraft");
-	        if ($statut >= 1)
-	        {
-	        	if (! $date_end_subscription)            return img_picto($langs->trans('MemberStatusActive'),'statut1').' '.$langs->trans("MemberStatusActive");
-	        	elseif ($date_end_subscription < time()) return img_picto($langs->trans('MemberStatusActiveLate'),'statut3').' '.$langs->trans("MemberStatusActiveLate");
-	        	else                                     return img_picto($langs->trans('MemberStatusPayed'),'statut4').' '.$langs->trans("MemberStatusPayed");
-	        }
-	        if ($statut == 0)  return img_picto($langs->trans('MemberStatusResiliated'),'statut5').' '.$langs->trans("MemberStatusResiliated");
-		}
-        if ($mode == 5)
-        {
-	        if ($statut == -1) return $langs->trans("MemberStatusDraft").' '.img_picto($langs->trans('MemberStatusDraft'),'statut0');
-	        if ($statut >= 1)
-	        {
-	        	if (! $date_end_subscription)            return $langs->trans("MemberStatusActive").' '.img_picto($langs->trans('MemberStatusActive'),'statut1');
-	        	elseif ($date_end_subscription < time()) return $langs->trans("MemberStatusActiveLate").' '.img_picto($langs->trans('MemberStatusActiveLate'),'statut3');
-	        	else                                     return $langs->trans("MemberStatusPayed").' '.img_picto($langs->trans('MemberStatusPayed'),'statut4');
-	        }
-	        if ($statut == 0)  return $langs->trans("MemberStatusResiliated").' '.img_picto($langs->trans('MemberStatusResiliated'),'statut5');
-		}
-    }
-
-
-    /**
-     *      \brief      Charge indicateurs this->nb de tableau de bord
-     *      \return     int         <0 si ko, >0 si ok
-     */
-    function load_state_board()
-    {
-        global $conf;
-
-        $this->nb=array();
-
-        $sql = "SELECT count(a.rowid) as nb";
-        $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a";
-        $sql.= " WHERE a.statut > 0";
-        $resql=$this->db->query($sql);
-        if ($resql)
-        {
-            while ($obj=$this->db->fetch_object($resql))
-            {
-                $this->nb["members"]=$obj->nb;
-            }
-            return 1;
-        }
-        else
-        {
-            dolibarr_print_error($this->db);
-            $this->error=$this->db->error();
-            return -1;
-        }
-
-    }
-
-    /**
-     *      \brief      Charge indicateurs this->nbtodo et this->nbtodolate de tableau de bord
-     *      \param      user        Objet user
-     *      \return     int         <0 si ko, >0 si ok
-     */
-    function load_board($user)
-    {
-        global $conf;
-
-        if ($user->societe_id) return -1;   // protection pour eviter appel par utilisateur externe
-
-        $this->nbtodo=$this->nbtodolate=0;
-        $sql = "SELECT a.rowid,".$this->db->pdate("a.datefin")." as datefin";
-        $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a";
-        $sql.= " WHERE a.statut=1";
-        $resql=$this->db->query($sql);
-        if ($resql)
-        {
-            while ($obj=$this->db->fetch_object($resql))
-            {
-                $this->nbtodo++;
-                if ($obj->datefin < (time() - $conf->adherent->cotisation->warning_delay)) $this->nbtodolate++;
-            }
-            return 1;
-        }
-        else
-        {
-            dolibarr_print_error($this->db);
-            $this->error=$this->db->error();
-            return -1;
-        }
-    }
-
-	
+			if ($statut == -1) return img_picto($langs->trans('MemberStatusDraft'),'statut0').' '.$langs->trans("MemberStatusDraft");
+			if ($statut >= 1)
+			{
+				if (! $date_end_subscription)            return img_picto($langs->trans('MemberStatusActive'),'statut1').' '.$langs->trans("MemberStatusActive");
+				elseif ($date_end_subscription < time()) return img_picto($langs->trans('MemberStatusActiveLate'),'statut3').' '.$langs->trans("MemberStatusActiveLate");
+				else                                     return img_picto($langs->trans('MemberStatusPayed'),'statut4').' '.$langs->trans("MemberStatusPayed");
+			}
+			if ($statut == 0)  return img_picto($langs->trans('MemberStatusResiliated'),'statut5').' '.$langs->trans("MemberStatusResiliated");
+		}
+		if ($mode == 5)
+		{
+			if ($statut == -1) return $langs->trans("MemberStatusDraft").' '.img_picto($langs->trans('MemberStatusDraft'),'statut0');
+			if ($statut >= 1)
+			{
+				if (! $date_end_subscription)            return $langs->trans("MemberStatusActive").' '.img_picto($langs->trans('MemberStatusActive'),'statut1');
+				elseif ($date_end_subscription < time()) return $langs->trans("MemberStatusActiveLate").' '.img_picto($langs->trans('MemberStatusActiveLate'),'statut3');
+				else                                     return $langs->trans("MemberStatusPayed").' '.img_picto($langs->trans('MemberStatusPayed'),'statut4');
+			}
+			if ($statut == 0)  return $langs->trans("MemberStatusResiliated").' '.img_picto($langs->trans('MemberStatusResiliated'),'statut5');
+		}
+	}
+
+
+	/**
+	 *      \brief      Charge indicateurs this->nb de tableau de bord
+	 *      \return     int         <0 si ko, >0 si ok
+	 */
+	function load_state_board()
+	{
+		global $conf;
+
+		$this->nb=array();
+
+		$sql = "SELECT count(a.rowid) as nb";
+		$sql.= " FROM ".MAIN_DB_PREFIX."adherent as a";
+		$sql.= " WHERE a.statut > 0";
+		$resql=$this->db->query($sql);
+		if ($resql)
+		{
+			while ($obj=$this->db->fetch_object($resql))
+			{
+				$this->nb["members"]=$obj->nb;
+			}
+			return 1;
+		}
+		else
+		{
+			dolibarr_print_error($this->db);
+			$this->error=$this->db->error();
+			return -1;
+		}
+
+	}
+
+	/**
+	 *      \brief      Charge indicateurs this->nbtodo et this->nbtodolate de tableau de bord
+	 *      \param      user        Objet user
+	 *      \return     int         <0 si ko, >0 si ok
+	 */
+	function load_board($user)
+	{
+		global $conf;
+
+		if ($user->societe_id) return -1;   // protection pour eviter appel par utilisateur externe
+
+		$this->nbtodo=$this->nbtodolate=0;
+		$sql = "SELECT a.rowid,".$this->db->pdate("a.datefin")." as datefin";
+		$sql.= " FROM ".MAIN_DB_PREFIX."adherent as a";
+		$sql.= " WHERE a.statut=1";
+		$resql=$this->db->query($sql);
+		if ($resql)
+		{
+			while ($obj=$this->db->fetch_object($resql))
+			{
+				$this->nbtodo++;
+				if ($obj->datefin < (time() - $conf->adherent->cotisation->warning_delay)) $this->nbtodolate++;
+			}
+			return 1;
+		}
+		else
+		{
+			dolibarr_print_error($this->db);
+			$this->error=$this->db->error();
+			return -1;
+		}
+	}
+
+
 	/**
 	 *		\brief		Initialise le membre avec valeurs fictives aleatoire
 	 */
@@ -1876,26 +1796,26 @@ class Adherent extends CommonObject
 
 		$this->datefin=time();
 		$this->datevalid=time();
-		
+
 		$this->typeid=1;				// Id type adherent
 		$this->type='Type adherent';	// Libelle type adherent
 		$this->need_subscription=0;
-		
+
 		$this->firstsubscription_date=time();
 		$this->firstsubscription_amount=10;
 		$this->lastsubscription_date=time();
 		$this->lastsubscription_amount=10;
 	}
-	
-	
+
+
 	/*
-	*	\brief		Retourne chaine DN complete dans l'annuaire LDAP pour l'objet
-	*	\param		info		Info string loaded by _load_ldap_info
-	*	\param		mode		0=Return DN without key inside (ou=xxx,dc=aaa,dc=bbb)
-								1=Return full DN (uid=qqq,ou=xxx,dc=aaa,dc=bbb)
-								2=Return key only (uid=qqq)
-	*	\return		string		DN
-	*/
+	 *	\brief		Retourne chaine DN complete dans l'annuaire LDAP pour l'objet
+	 *	\param		info		Info string loaded by _load_ldap_info
+	 *	\param		mode		0=Return DN without key inside (ou=xxx,dc=aaa,dc=bbb)
+	 1=Return full DN (uid=qqq,ou=xxx,dc=aaa,dc=bbb)
+	 2=Return key only (uid=qqq)
+	 *	\return		string		DN
+	 */
 	function _load_ldap_dn($info,$mode=0)
 	{
 		global $conf;
@@ -1908,9 +1828,9 @@ class Adherent extends CommonObject
 
 
 	/*
-	*	\brief		Initialise tableau info (tableau des attributs LDAP)
-	*	\return		array		Tableau info des attributs
-	*/
+	 *	\brief		Initialise tableau info (tableau des attributs LDAP)
+	 *	\return		array		Tableau info des attributs
+	 */
 	function _load_ldap_info()
 	{
 		global $conf,$langs;
@@ -1919,7 +1839,7 @@ class Adherent extends CommonObject
 
 		// Object classes
 		$info["objectclass"]=split(',',$conf->global->LDAP_MEMBER_OBJECT_CLASS);
-		
+
 		// Member
 		if ($this->fullname  && $conf->global->LDAP_FIELD_FULLNAME) $info[$conf->global->LDAP_FIELD_FULLNAME] = $this->fullname;
 		if ($this->nom && $conf->global->LDAP_FIELD_NAME)         $info[$conf->global->LDAP_FIELD_NAME] = $this->nom;
@@ -1946,15 +1866,15 @@ class Adherent extends CommonObject
 		if (isset($this->firstsubscription_amount) && $conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT) $info[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT] = $this->firstsubscription_amount;
 		if ($this->lastsubscription_date && $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE)       $info[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE]   = dolibarr_print_date($this->lastsubscription_date,'dayhourldap');
 		if (isset($this->lastsubscription_amount) && $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT)   $info[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT] = $this->lastsubscription_amount;
-		
+
 		return $info;
-	}	
+	}
 
 
-    /**
-     *      \brief     Charge les informations d'ordre info dans l'objet adherent
-     *      \param     id       Id du membre a charger
-     */
+	/**
+	 *      \brief     Charge les informations d'ordre info dans l'objet adherent
+	 *      \param     id       Id du membre a charger
+	 */
 	function info($id)
 	{
 		$sql = 'SELECT a.rowid, '.$this->db->pdate('a.datec').' as datec,';
diff --git a/htdocs/adherents/options.php b/htdocs/adherents/options.php
index b6f1390cf29153e914e720e03338d0e5a775e414..b4d42c960d73a0594f96ce6eb33ca727cebafde3 100644
--- a/htdocs/adherents/options.php
+++ b/htdocs/adherents/options.php
@@ -130,7 +130,7 @@ if (sizeof($array_options)>0)
       print "<td>".$adho->attribute_label[$key]."&nbsp;</td>\n";
       print "<td>$key</td>\n";
       print "<td>$value</td>\n";
-      print "<td align=\"center\"><a href=\"options.php?action=edit&attrname=$key\">".img_edit()."</a>";
+      print "<td align=\"right\"><a href=\"options.php?action=edit&attrname=$key\">".img_edit()."</a>";
       print "&nbsp; <a href=\"options.php?action=delete&attrname=$key\">".img_delete()."</a></td>\n";
       print "</tr>";
       //      $i++;
diff --git a/htdocs/admin/agenda.php b/htdocs/admin/agenda.php
index ea3cdd86bbf8026b8a2bd7b8c8d304b55f526ab1..304d01b737438dab9c0b94805856c9e4a623b3b3 100644
--- a/htdocs/admin/agenda.php
+++ b/htdocs/admin/agenda.php
@@ -53,8 +53,10 @@ $eventstolog=array(
 	array('id'=>'BILL_SUPPLIER_VALIDATE', 'test'=>$conf->fournisseur->enabled),
 //	array('id'=>'PAYMENT_CUSTOMER_CREATE','test'=>$conf->facture->enabled),
 //	array('id'=>'PAYMENT_SUPPLIER_CREATE','test'=>$conf->fournisseur->enabled),
-//	array('id'=>'MEMBER_VALIDATE',        'test'=>$conf->adherent->enabled),
-//	array('id'=>'MEMBER_SUBSCRIPTION',    'test'=>$conf->adherent->enabled),
+	array('id'=>'MEMBER_VALIDATE',        'test'=>$conf->adherent->enabled),
+	array('id'=>'MEMBER_SUBSCRIPTION',    'test'=>$conf->adherent->enabled),
+	array('id'=>'MEMBER_RESILIATE',       'test'=>$conf->adherent->enabled),
+	array('id'=>'MEMBER_DELETE',          'test'=>$conf->adherent->enabled),
 );
 
 
diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php
index abaefb4283467bc1b0f83c4a11ec8b3b888fd7c9..bf52925f70f74e6860d2763ad5c5bd94b9027af3 100644
--- a/htdocs/comm/action/index.php
+++ b/htdocs/comm/action/index.php
@@ -68,6 +68,8 @@ $day=isset($_REQUEST["day"])?$_REQUEST["day"]:0;
 
 $langs->load("other");
 
+if (! isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW)) $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW=3;
+
 
 /*
  * Actions
@@ -413,7 +415,7 @@ if ($_GET["action"] != 'show_day')
 			{
 				$style='cal_other_month';
 				echo '  <td class="'.$style.'" width="14%" valign="top"  nowrap="nowrap">';
-				show_day_events ($db, $max_day_in_prev_month + $tmpday, $prev_month, $prev_year, $style, $actionarray,3);
+				show_day_events ($db, $max_day_in_prev_month + $tmpday, $prev_month, $prev_year, $style, $actionarray, $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW);
 				echo "  </td>\n";
 			}
 			/* Show days of the current month */
@@ -429,7 +431,7 @@ if ($_GET["action"] != 'show_day')
 				$style='cal_current_month';
 
 				echo '  <td class="'.$style.'" width="14%" valign="top"  nowrap="nowrap">';
-				show_day_events($db, $tmpday, $month, $year, $style, $actionarray, 3);
+				show_day_events($db, $tmpday, $month, $year, $style, $actionarray, $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW);
 				echo "  </td>\n";
 			}
 			/* Show days after the current month (next month) */
@@ -437,7 +439,7 @@ if ($_GET["action"] != 'show_day')
 			{
 				$style='cal_other_month';
 				echo '  <td class="'.$style.'" width="14%" valign="top"  nowrap="nowrap">';
-				show_day_events($db, $tmpday - $max_day_in_month, $next_month, $next_year, $style, $actionarray, 3);
+				show_day_events($db, $tmpday - $max_day_in_month, $next_month, $next_year, $style, $actionarray, $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW);
 				echo "</td>\n";
 			}
 			$tmpday++;
@@ -448,6 +450,7 @@ if ($_GET["action"] != 'show_day')
 }
 else
 {
+	// Code to show just one day
 	$style='cal_current_month';
 	$timestamp=dolibarr_mktime(12,0,0,$month,$_GET["day"],$year);
 	$arraytimestamp=adodb_getdate(dolibarr_mktime(12,0,0,$month,$_GET["day"],$year));
@@ -458,7 +461,7 @@ else
 	echo " </tr>\n";
 	echo " <tr>\n";
 	echo '  <td class="'.$style.'" width="14%" valign="top"  nowrap="nowrap">';
-	show_day_events ($db, $_GET["day"], $month, $year, $style, $actionarray);
+	show_day_events ($db, $_GET["day"], $month, $year, $style, $actionarray, 0, 0);
 	echo "</td>\n";
 	echo " </tr>\n";
 	echo '</table>';
@@ -480,16 +483,17 @@ llxFooter('$Date$ - $Revision$');
  * @param unknown_type $year			Year
  * @param unknown_type $style			Style to use for this day
  * @param unknown_type $actionarray		Array of actions
- * @param unknown_type $maxPrint		Nb of actions to show each day on month view
+ * @param unknown_type $maxPrint		Nb of actions to show each day on month view (0 means non limit)
+ * @param unknown_type nbofchartoshow	Nb of characters to show for event line
  */
-function show_day_events($db, $day, $month, $year, $style, $actionarray, $maxPrint=-1)
+function show_day_events($db, $day, $month, $year, $style, $actionarray, $maxPrint=0, $nbofchartoshow=14)
 {
 	global $user, $conf, $langs;
 	global $filtera, $filtert, $filted;
 	global $theme_datacolor;
 	if ($_GET["action"] == 'maxPrint')
 	{
-		$maxPrint=-1;
+		$maxPrint=0;
 	}
 	$curtime = dolibarr_mktime (0, 0, 0, $month, $day, $year);
 
@@ -517,7 +521,7 @@ function show_day_events($db, $day, $month, $year, $style, $actionarray, $maxPri
 			foreach ($actionarray[$daykey] as $index => $action)
 			{
 					
-				if ($i < $maxPrint || $maxPrint == -1)
+				if ($i < $maxPrint || $maxPrint == 0)
 				{
 					$ponct=($action->date_start_in_calendar == $action->date_end_in_calendar);
 					// Show rect of event
@@ -562,11 +566,11 @@ function show_day_events($db, $day, $month, $year, $style, $actionarray, $maxPri
 							print dolibarr_print_date($action->date_end_in_calendar,'%H:%M');
 						}
 						print '<br>';
-						print $action->getNomUrl(0,14,'cal_event');
+						print $action->getNomUrl(0,$nbofchartoshow,'cal_event');
 					}
 					else	// It's a birthday
 					{
-						print $action->getNomUrl(0,14,'cal_event','birthday');
+						print $action->getNomUrl(0,$nbofchartoshow,'cal_event','birthday');
 					}
 					print '</td>';
 					print '<td align="right" nowrap="nowrap">';
diff --git a/htdocs/includes/triggers/interface_all_Logevents.class.php b/htdocs/includes/triggers/interface_all_Logevents.class.php
index 871566ddfc8ddbdf95226749de78a6cb016ec0b9..3a30c02230c89fd4d4f993d92bed575b3c686082 100644
--- a/htdocs/includes/triggers/interface_all_Logevents.class.php
+++ b/htdocs/includes/triggers/interface_all_Logevents.class.php
@@ -402,11 +402,18 @@ class InterfaceLogevents
         // Members
         elseif ($action == 'MEMBER_CREATE')
         {
-            $this->date=time();
+            dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
+            $langs->load("other");
+            $langs->load("members");
+
+        	$this->date=time();
             $this->duree=0;
-            $this->texte=$langs->transnoentities("NewMemberCreated",$object->id);
-            $this->desc=$langs->transnoentities("NewMemberCreated",$object->id);
-		}
+            $this->texte=$langs->transnoentities("NewMemberCreated",$object->ref);
+            $this->desc=$langs->transnoentities("NewMemberCreated",$object->ref);
+            $this->desc.="\n".$langs->transnoentities("Member").': '.$object->fullname;
+            $this->desc.="\n".$langs->transnoentities("Type").': '.$object->type;
+            $this->desc.="\n".$langs->transnoentities("Author").': '.$user->login;
+        }
         elseif ($action == 'MEMBER_VALIDATE')
         {
             dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
@@ -415,8 +422,8 @@ class InterfaceLogevents
 
             $this->date=time();
             $this->duree=0;
-            $this->texte=$langs->transnoentities("MemberValidatedInDolibarr",$object->id);
-            $this->desc=$langs->transnoentities("MemberValidatedInDolibarr",$object->id);
+            $this->texte=$langs->transnoentities("MemberValidatedInDolibarr",$object->ref);
+            $this->desc=$langs->transnoentities("MemberValidatedInDolibarr",$object->ref);
             $this->desc.="\n".$langs->transnoentities("Member").': '.$object->fullname;
             $this->desc.="\n".$langs->transnoentities("Type").': '.$object->type;
             $this->desc.="\n".$langs->transnoentities("Author").': '.$user->login;
@@ -429,8 +436,8 @@ class InterfaceLogevents
 
             $this->date=time();
             $this->duree=0;
-            $this->texte=$langs->transnoentities("MemberSubscriptionInDolibarr",$object->id);
-            $this->desc=$langs->transnoentities("MemberSubscriptionInDolibarr",$object->id);
+            $this->texte=$langs->transnoentities("MemberSubscriptionAddedInDolibarr",$object->ref);
+            $this->desc=$langs->transnoentities("MemberSubscriptionAddedInDolibarr",$object->ref);
             $this->desc.="\n".$langs->transnoentities("Member").': '.$object->fullname;
             $this->desc.="\n".$langs->transnoentities("Type").': '.$object->type;
             $this->desc.="\n".$langs->transnoentities("Amount").': '.$object->last_subscription_amount;
@@ -445,8 +452,8 @@ class InterfaceLogevents
 
             $this->date=time();
             $this->duree=0;
-            $this->texte=$langs->transnoentities("MemberModifiedInDolibarr",$object->id);
-            $this->desc=$langs->transnoentities("MemberModifiedInDolibarr",$object->id);
+            $this->texte=$langs->transnoentities("MemberModifiedInDolibarr",$object->ref);
+            $this->desc=$langs->transnoentities("MemberModifiedInDolibarr",$object->ref);
             $this->desc.="\n".$langs->transnoentities("Member").': '.$object->fullname;
             $this->desc.="\n".$langs->transnoentities("Type").': '.$object->type;
             $this->desc.="\n".$langs->transnoentities("Author").': '.$user->login;
@@ -459,8 +466,8 @@ class InterfaceLogevents
 
             $this->date=time();
             $this->duree=0;
-            $this->texte=$langs->transnoentities("MemberResiliatedInDolibarr",$object->id);
-            $this->desc=$langs->transnoentities("MemberResiliatedInDolibarr",$object->id);
+            $this->texte=$langs->transnoentities("MemberResiliatedInDolibarr",$object->ref);
+            $this->desc=$langs->transnoentities("MemberResiliatedInDolibarr",$object->ref);
             $this->desc.="\n".$langs->transnoentities("Member").': '.$object->fullname;
             $this->desc.="\n".$langs->transnoentities("Type").': '.$object->type;
             $this->desc.="\n".$langs->transnoentities("Author").': '.$user->login;
@@ -473,8 +480,8 @@ class InterfaceLogevents
 
             $this->date=time();
             $this->duree=0;
-            $this->texte=$langs->transnoentities("MemberDeletedInDolibarr",$object->id);
-            $this->desc=$langs->transnoentities("MemberDeletedInDolibarr",$object->id);
+            $this->texte=$langs->transnoentities("MemberDeletedInDolibarr",$object->ref);
+            $this->desc=$langs->transnoentities("MemberDeletedInDolibarr",$object->ref);
             $this->desc.="\n".$langs->transnoentities("Member").': '.$object->fullname;
             $this->desc.="\n".$langs->transnoentities("Type").': '.$object->type;
             $this->desc.="\n".$langs->transnoentities("Author").': '.$user->login;
diff --git a/htdocs/includes/triggers/interface_modAgenda_ActionsAuto.class.php b/htdocs/includes/triggers/interface_modAgenda_ActionsAuto.class.php
index a1f93603bcc7b565f817c4b286fb05555f7112c4..06e825924353c0f5cfeada25ca9863bef486f3ca 100644
--- a/htdocs/includes/triggers/interface_modAgenda_ActionsAuto.class.php
+++ b/htdocs/includes/triggers/interface_modAgenda_ActionsAuto.class.php
@@ -104,8 +104,8 @@ class InterfaceActionsAuto
 		
 		// Following properties must be filled:
 		// $object->actiontypecode;
-		// $object->actionmsg (label)
-		// $object->actionmsg2 (note)
+		// $object->actionmsg (note, long text)
+		// $object->actionmsg2 (label, short text)
 		// $object->sendtoid
 		// $object->socid
 		// Optionnal:
@@ -328,7 +328,87 @@ class InterfaceActionsAuto
 			$ok=1;
 		}
 		
-		
+        // Members
+        elseif ($action == 'MEMBER_VALIDATE')
+        {
+            dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
+            $langs->load("other");
+            $langs->load("members");
+            $langs->load("agenda");
+
+			$object->actiontypecode='AC_OTH';
+            $object->actionmsg2=$langs->transnoentities("MemberValidatedInDolibarr",$object->ref);
+            $object->actionmsg=$langs->transnoentities("MemberValidatedInDolibarr",$object->ref);
+            $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->fullname;
+            $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type;
+            $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
+            
+			$object->sendtoid=0;
+			$object->facid=0;	// Supplier invoice not yet supported
+			$object->orderrowid=$object->propalrowid=0;
+			$ok=1;
+        }
+        elseif ($action == 'MEMBER_SUBSCRIPTION')
+        {
+            dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
+            $langs->load("other");
+            $langs->load("members");
+            $langs->load("agenda");
+
+			$object->actiontypecode='AC_OTH';
+            $object->actionmsg2=$langs->transnoentities("MemberSubscriptionAddedInDolibarr",$object->ref);
+            $object->actionmsg=$langs->transnoentities("MemberSubscriptionAddedInDolibarr",$object->ref);
+            $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->fullname;
+            $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type;
+            $object->actionmsg.="\n".$langs->transnoentities("Amount").': '.$object->last_subscription_amount;
+            $object->actionmsg.="\n".$langs->transnoentities("Period").': '.dolibarr_print_date($object->last_subscription_date_start,'day').' - '.dolibarr_print_date($object->last_subscription_date_end,'day');
+            $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
+            
+			$object->sendtoid=0;
+			$object->facid=$object->orderrowid=$object->propalrowid=0;
+			$ok=1;
+        }
+        elseif ($action == 'MEMBER_MODIFY')
+        {
+            dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
+        }
+        elseif ($action == 'MEMBER_RESILIATE')
+        {
+            dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
+            $langs->load("other");
+            $langs->load("members");
+            $langs->load("agenda");
+
+			$object->actiontypecode='AC_OTH';
+            $object->actionmsg2=$langs->transnoentities("MemberResiliatedInDolibarr",$object->ref);
+            $object->actionmsg=$langs->transnoentities("MemberResiliatedInDolibarr",$object->ref);
+            $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->fullname;
+            $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type;
+            $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
+            
+			$object->sendtoid=0;
+			$object->facid=$object->orderrowid=$object->propalrowid=0;
+			$ok=1;
+        }
+        elseif ($action == 'MEMBER_DELETE')
+        {
+            dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
+            $langs->load("other");
+            $langs->load("members");
+            $langs->load("agenda");
+
+			$object->actiontypecode='AC_OTH';
+            $object->actionmsg2=$langs->transnoentities("MemberDeletedInDolibarr",$object->ref);
+            $object->actionmsg=$langs->transnoentities("MemberDeletedInDolibarr",$object->ref);
+            $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->fullname;
+            $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type;
+            $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
+            
+			$object->sendtoid=0;
+			$object->facid=$object->orderrowid=$object->propalrowid=0;
+			$ok=1;
+        }
+        		
 		// If not found
 /*
         else
diff --git a/htdocs/includes/triggers/interface_modLdap_Ldapsynchro.class.php b/htdocs/includes/triggers/interface_modLdap_Ldapsynchro.class.php
index 5a16b6eb2786ef289e8d687a83cf4f6ca409db74..85b4be528805c2de5b065174bc63732e90179fcf 100644
--- a/htdocs/includes/triggers/interface_modLdap_Ldapsynchro.class.php
+++ b/htdocs/includes/triggers/interface_modLdap_Ldapsynchro.class.php
@@ -101,6 +101,12 @@ class InterfaceLdapsynchro
     
         if (! $conf->ldap->enabled) return 0;     // Module non actif
 
+        if (! function_exists('ldap_connect'))
+        {
+        	dolibarr_syslog("Warning, module LDAP is enabled but LDAP functions not available in this PHP", LOG_WARNING);
+        	return 0;	
+        }
+        
         // Users
         if ($action == 'USER_CREATE')
         {
diff --git a/htdocs/includes/triggers/interface_modPhenix_Phenixsynchro.class.php b/htdocs/includes/triggers/interface_modPhenix_Phenixsynchro.class.php
index cd7c16f2b048bc4b4792ab07cf72f67025c2fe0e..1e2037617e88b1d61c5a5b85dd62225bf321bf5e 100644
--- a/htdocs/includes/triggers/interface_modPhenix_Phenixsynchro.class.php
+++ b/htdocs/includes/triggers/interface_modPhenix_Phenixsynchro.class.php
@@ -288,7 +288,18 @@ class InterfacePhenixsynchro
         // Members
         elseif ($action == 'MEMBER_CREATE')
         {
-		}
+            dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
+            $langs->load("other");
+            $langs->load("members");
+
+        	$this->date=time();
+            $this->duree=0;
+            $this->texte=$langs->transnoentities("NewMemberCreated",$object->ref);
+            $this->desc=$langs->transnoentities("NewMemberCreated",$object->ref);
+            $this->desc.="\n".$langs->transnoentities("Member").': '.$object->fullname;
+            $this->desc.="\n".$langs->transnoentities("Type").': '.$object->type;
+            $this->desc.="\n".$langs->transnoentities("Author").': '.$user->login;
+        }
         elseif ($action == 'MEMBER_VALIDATE')
         {
             dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
@@ -297,8 +308,8 @@ class InterfacePhenixsynchro
 
             $this->date=time();
             $this->duree=0;
-            $this->texte=$langs->transnoentities("MemberValidatedInDolibarr",$object->id);
-            $this->desc=$langs->transnoentities("MemberValidatedInDolibarr",$object->id);
+            $this->texte=$langs->transnoentities("MemberValidatedInDolibarr",$object->ref);
+            $this->desc=$langs->transnoentities("MemberValidatedInDolibarr",$object->ref);
             $this->desc.="\n".$langs->transnoentities("Member").': '.$object->fullname;
             $this->desc.="\n".$langs->transnoentities("Type").': '.$object->type;
             $this->desc.="\n".$langs->transnoentities("Author").': '.$user->login;
@@ -311,8 +322,8 @@ class InterfacePhenixsynchro
 
             $this->date=time();
             $this->duree=0;
-            $this->texte=$langs->transnoentities("MemberSubscriptionInDolibarr",$object->id);
-            $this->desc=$langs->transnoentities("MemberSubscriptionInDolibarr",$object->id);
+            $this->texte=$langs->transnoentities("MemberSubscriptionAddedInDolibarr",$object->ref);
+            $this->desc=$langs->transnoentities("MemberSubscriptionAddedInDolibarr",$object->ref);
             $this->desc.="\n".$langs->transnoentities("Member").': '.$object->fullname;
             $this->desc.="\n".$langs->transnoentities("Type").': '.$object->type;
             $this->desc.="\n".$langs->transnoentities("Amount").': '.$object->last_subscription_amount;
@@ -327,8 +338,8 @@ class InterfacePhenixsynchro
 
             $this->date=time();
             $this->duree=0;
-            $this->texte=$langs->transnoentities("MemberModifiedInDolibarr",$object->id);
-            $this->desc=$langs->transnoentities("MemberModifiedInDolibarr",$object->id);
+            $this->texte=$langs->transnoentities("MemberModifiedInDolibarr",$object->ref);
+            $this->desc=$langs->transnoentities("MemberModifiedInDolibarr",$object->ref);
             $this->desc.="\n".$langs->transnoentities("Member").': '.$object->fullname;
             $this->desc.="\n".$langs->transnoentities("Type").': '.$object->type;
             $this->desc.="\n".$langs->transnoentities("Author").': '.$user->login;
@@ -341,8 +352,8 @@ class InterfacePhenixsynchro
 
             $this->date=time();
             $this->duree=0;
-            $this->texte=$langs->transnoentities("MemberResiliatedInDolibarr",$object->id);
-            $this->desc=$langs->transnoentities("MemberResiliatedInDolibarr",$object->id);
+            $this->texte=$langs->transnoentities("MemberResiliatedInDolibarr",$object->ref);
+            $this->desc=$langs->transnoentities("MemberResiliatedInDolibarr",$object->ref);
             $this->desc.="\n".$langs->transnoentities("Member").': '.$object->fullname;
             $this->desc.="\n".$langs->transnoentities("Type").': '.$object->type;
             $this->desc.="\n".$langs->transnoentities("Author").': '.$user->login;
@@ -355,8 +366,8 @@ class InterfacePhenixsynchro
 
             $this->date=time();
             $this->duree=0;
-            $this->texte=$langs->transnoentities("MemberDeletedInDolibarr",$object->id);
-            $this->desc=$langs->transnoentities("MemberDeletedInDolibarr",$object->id);
+            $this->texte=$langs->transnoentities("MemberDeletedInDolibarr",$object->ref);
+            $this->desc=$langs->transnoentities("MemberDeletedInDolibarr",$object->ref);
             $this->desc.="\n".$langs->transnoentities("Member").': '.$object->fullname;
             $this->desc.="\n".$langs->transnoentities("Type").': '.$object->type;
             $this->desc.="\n".$langs->transnoentities("Author").': '.$user->login;
diff --git a/htdocs/includes/triggers/interface_modWebcalendar_Webcalsynchro.class.php b/htdocs/includes/triggers/interface_modWebcalendar_Webcalsynchro.class.php
index cfe2aa5bd3f2037a295c8f7d646ca956135b4fab..a49bcbba9109fd8f361b442ef0a1bfd098a293c1 100644
--- a/htdocs/includes/triggers/interface_modWebcalendar_Webcalsynchro.class.php
+++ b/htdocs/includes/triggers/interface_modWebcalendar_Webcalsynchro.class.php
@@ -265,7 +265,18 @@ class InterfaceWebcalsynchro
         // Members
         elseif ($action == 'MEMBER_CREATE')
         {
-		}
+            dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
+            $langs->load("other");
+            $langs->load("members");
+
+        	$this->date=time();
+            $this->duree=0;
+            $this->texte=$langs->transnoentities("NewMemberCreated",$object->ref);
+            $this->desc=$langs->transnoentities("NewMemberCreated",$object->ref);
+            $this->desc.="\n".$langs->transnoentities("Member").': '.$object->fullname;
+            $this->desc.="\n".$langs->transnoentities("Type").': '.$object->type;
+            $this->desc.="\n".$langs->transnoentities("Author").': '.$user->login;
+        }
         elseif ($action == 'MEMBER_VALIDATE')
         {
             dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
@@ -274,8 +285,8 @@ class InterfaceWebcalsynchro
 
             $this->date=time();
             $this->duree=0;
-            $this->texte=$langs->transnoentities("MemberValidatedInDolibarr",$object->id);
-            $this->desc=$langs->transnoentities("MemberValidatedInDolibarr",$object->id);
+            $this->texte=$langs->transnoentities("MemberValidatedInDolibarr",$object->ref);
+            $this->desc=$langs->transnoentities("MemberValidatedInDolibarr",$object->ref);
             $this->desc.="\n".$langs->transnoentities("Member").': '.$object->fullname;
             $this->desc.="\n".$langs->transnoentities("Type").': '.$object->type;
             $this->desc.="\n".$langs->transnoentities("Author").': '.$user->login;
@@ -288,8 +299,8 @@ class InterfaceWebcalsynchro
 
             $this->date=time();
             $this->duree=0;
-            $this->texte=$langs->transnoentities("MemberSubscriptionInDolibarr",$object->id);
-            $this->desc=$langs->transnoentities("MemberSubscriptionInDolibarr",$object->id);
+            $this->texte=$langs->transnoentities("MemberSubscriptionAddedInDolibarr",$object->ref);
+            $this->desc=$langs->transnoentities("MemberSubscriptionAddedInDolibarr",$object->ref);
             $this->desc.="\n".$langs->transnoentities("Member").': '.$object->fullname;
             $this->desc.="\n".$langs->transnoentities("Type").': '.$object->type;
             $this->desc.="\n".$langs->transnoentities("Amount").': '.$object->last_subscription_amount;
@@ -304,8 +315,8 @@ class InterfaceWebcalsynchro
 
             $this->date=time();
             $this->duree=0;
-            $this->texte=$langs->transnoentities("MemberModifiedInDolibarr",$object->id);
-            $this->desc=$langs->transnoentities("MemberModifiedInDolibarr",$object->id);
+            $this->texte=$langs->transnoentities("MemberModifiedInDolibarr",$object->ref);
+            $this->desc=$langs->transnoentities("MemberModifiedInDolibarr",$object->ref);
             $this->desc.="\n".$langs->transnoentities("Member").': '.$object->fullname;
             $this->desc.="\n".$langs->transnoentities("Type").': '.$object->type;
             $this->desc.="\n".$langs->transnoentities("Author").': '.$user->login;
@@ -318,8 +329,8 @@ class InterfaceWebcalsynchro
 
             $this->date=time();
             $this->duree=0;
-            $this->texte=$langs->transnoentities("MemberResiliatedInDolibarr",$object->id);
-            $this->desc=$langs->transnoentities("MemberResiliatedInDolibarr",$object->id);
+            $this->texte=$langs->transnoentities("MemberResiliatedInDolibarr",$object->ref);
+            $this->desc=$langs->transnoentities("MemberResiliatedInDolibarr",$object->ref);
             $this->desc.="\n".$langs->transnoentities("Member").': '.$object->fullname;
             $this->desc.="\n".$langs->transnoentities("Type").': '.$object->type;
             $this->desc.="\n".$langs->transnoentities("Author").': '.$user->login;
@@ -332,8 +343,8 @@ class InterfaceWebcalsynchro
 
             $this->date=time();
             $this->duree=0;
-            $this->texte=$langs->transnoentities("MemberDeletedInDolibarr",$object->id);
-            $this->desc=$langs->transnoentities("MemberDeletedInDolibarr",$object->id);
+            $this->texte=$langs->transnoentities("MemberDeletedInDolibarr",$object->ref);
+            $this->desc=$langs->transnoentities("MemberDeletedInDolibarr",$object->ref);
             $this->desc.="\n".$langs->transnoentities("Member").': '.$object->fullname;
             $this->desc.="\n".$langs->transnoentities("Type").': '.$object->type;
             $this->desc.="\n".$langs->transnoentities("Author").': '.$user->login;
diff --git a/htdocs/interfaces.class.php b/htdocs/interfaces.class.php
index 1cee0125c1c2b477c5408bcdd4063d9c51cd941a..da19f9edc26317f7aecfb5fdd6b9e797f3014324 100644
--- a/htdocs/interfaces.class.php
+++ b/htdocs/interfaces.class.php
@@ -95,7 +95,8 @@ class Interfaces
 					dolibarr_syslog("Interfaces::run_triggers Triggers for file '".$file."' need module to be enabled",LOG_INFO);
 					continue;
 				}
-dolibarr_syslog("Interfaces::run_triggers Launch triggers for file '".$file."'",LOG_INFO);
+
+				dolibarr_syslog("Interfaces::run_triggers Launch triggers for file '".$file."'",LOG_INFO);
 				include_once($this->dir."/".$file);
 				$objMod = new $modName($this->db);
 				if ($objMod)
diff --git a/htdocs/langs/en_US/other.lang b/htdocs/langs/en_US/other.lang
index 19af87ba50086c2efceec8a3ed548e614473659a..ae788067c15f87595f15c064993082f62d5fb4ec 100644
--- a/htdocs/langs/en_US/other.lang
+++ b/htdocs/langs/en_US/other.lang
@@ -118,6 +118,7 @@ SupplierPaymentDoneInDolibarr=Supplier payment %s done in Dolibarr
 MemberValidatedInDolibarr=Member %s validated in Dolibarr
 MemberResiliatedInDolibarr=Member %s resiliated in Dolibarr
 MemberDeletedInDolibarr=Member %s deleted from Dolibarr
+MemberSubscriptionAddedInDolibarr=Subscription for member %s added in Dolibarr
 ##### Export #####
 ExportsArea=Exports area
 AvailableFormats=Available formats
diff --git a/htdocs/langs/fr_FR/other.lang b/htdocs/langs/fr_FR/other.lang
index d35933c78d534ef5d1b232dbbe2f33a03ab5067c..6ca19a4deef33f11717132d6fb6a59fa89b9ddac 100644
--- a/htdocs/langs/fr_FR/other.lang
+++ b/htdocs/langs/fr_FR/other.lang
@@ -120,6 +120,7 @@ SupplierPaymentDoneInDolibarr=Paiement fournisseur %s dans Dolibarr
 MemberValidatedInDolibarr=Adh�rent %s valid� dans Dolibarr
 MemberResiliatedInDolibarr=Adh�rent %s r�sili� dans Dolibarr
 MemberDeletedInDolibarr=Adh�rent %s supprim� de Dolibarr
+MemberSubscriptionAddedInDolibarr=Souscription adh�rent %s ajout�e dans Dolibarr
 ##### Export #####
 ExportsArea=Espace exports
 AvailableFormats=Formats disponibles