diff --git a/ChangeLog b/ChangeLog
index 67920bbfee3197fdde20aedfd636be97875873ea..8d8e9ac9c729ef6b4ab5df333ab32972e7442625 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -23,6 +23,7 @@ Fix: [ bug #2837 ] Product list table column header does not match column body
 Fix: [ bug #2835 ] Customer prices of a product shows incorrect history order
 Fix: [ bug #2814 ] JPEG photos are not displayed in Product photos page
 Fix: [ bug #2715 ] Statistics page has broken layout with long thirdparty names
+Fix: [ bug #2570 ] [Contacts] Page should not process if ID is invalid
 
 ***** ChangeLog for 3.5.6 compared to 3.5.5 *****
 Fix: Avoid missing class error for fetch_thirdparty method #1973
diff --git a/htdocs/contact/exportimport.php b/htdocs/contact/exportimport.php
index 5149eed9efb877140d734177eb7e18cd6fe4814a..c76655f50993441f7804ce542d6719f1b25de67f 100644
--- a/htdocs/contact/exportimport.php
+++ b/htdocs/contact/exportimport.php
@@ -33,81 +33,80 @@ $id = GETPOST('id', 'int');
 if ($user->societe_id) $socid=$user->societe_id;
 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
 
+$contact = new Contact($db);
+
 
 /*
  *	View
  */
 
-$title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
-
-llxHeader('',$title,'EN:Module_Third_Parties|FR:Module_Tiers|ES:Módulo_Empresas');
-
 $form = new Form($db);
 
-$contact = new Contact($db);
-$contact->fetch($id, $user);
-
+$title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
 
-$head = contact_prepare_head($contact);
+llxHeader('',$title,'EN:Module_Third_Parties|FR:Module_Tiers|ES:Módulo_Empresas');
 
-dol_fiche_head($head, 'exportimport', $title, 0, 'contact');
+if ($id > 0)
+{
+	$contact->fetch($id, $user);
 
+	$head = contact_prepare_head($contact);
 
-/*
- * Fiche en mode visu
- */
-print '<table class="border" width="100%">';
+	dol_fiche_head($head, 'exportimport', $title, 0, 'contact');
 
-$linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php">'.$langs->trans("BackToList").'</a>';
 
-// Ref
-print '<tr><td>'.$langs->trans("Ref").'</td><td colspan="3">';
-print $form->showrefnav($contact, 'id', $linkback);
-print '</td></tr>';
+	/*
+	 * Fiche en mode visu
+	 */
+	print '<table class="border" width="100%">';
 
-// Name
-print '<tr><td width="20%">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td>'.$contact->lastname.'</td>';
-print '<td width="20%">'.$langs->trans("Firstname").'</td><td width="25%">'.$contact->firstname.'</td></tr>';
+	$linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php">'.$langs->trans("BackToList").'</a>';
 
-// Company
-if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
-{
-    if ($contact->socid > 0)
-    {
-    	$objsoc = new Societe($db);
-    	$objsoc->fetch($contact->socid);
-
-    	print '<tr><td width="15%">'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
-    }
-    else
-    {
-    	print '<tr><td width="15%">'.$langs->trans("Company").'</td><td colspan="3">';
-    	print $langs->trans("ContactNotLinkedToCompany");
-    	print '</td></tr>';
-    }
-}
+	// Ref
+	print '<tr><td>'.$langs->trans("Ref").'</td><td colspan="3">';
+	print $form->showrefnav($contact, 'id', $linkback);
+	print '</td></tr>';
 
-// Civility
-print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
-print $contact->getCivilityLabel();
-print '</td></tr>';
+	// Name
+	print '<tr><td width="20%">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td>'.$contact->lastname.'</td>';
+	print '<td width="20%">'.$langs->trans("Firstname").'</td><td width="25%">'.$contact->firstname.'</td></tr>';
 
-print '</table>';
+	// Company
+	if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
+	{
+	    if ($contact->socid > 0)
+	    {
+	        $objsoc = new Societe($db);
+	        $objsoc->fetch($contact->socid);
 
-print '</div>';
+	        print '<tr><td width="15%">'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
+	    }
+	    else
+	    {
+	        print '<tr><td width="15%">'.$langs->trans("Company").'</td><td colspan="3">';
+	        print $langs->trans("ContactNotLinkedToCompany");
+	        print '</td></tr>';
+	    }
+	}
 
-print '<br>';
+	// Civility
+	print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
+	print $contact->getCivilityLabel();
+	print '</td></tr>';
 
-print $langs->trans("ExportCardToFormat").': ';
-print '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$contact->id.'">';
-print img_picto($langs->trans("VCard"),'vcard.png').' ';
-print $langs->trans("VCard");
-print '</a>';
+	print '</table>';
 
+	print '</div>';
 
+	print '<br>';
 
+	print $langs->trans("ExportCardToFormat").': ';
+	print '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$contact->id.'">';
+	print img_picto($langs->trans("VCard"),'vcard.png').' ';
+	print $langs->trans("VCard");
+	print '</a>';
+}
 
 $db->close();
 
 llxFooter();
-?>
diff --git a/htdocs/contact/info.php b/htdocs/contact/info.php
index 3ac6747bb6b1943ea1888f0535b6f2187c83ce41..5d4904faa87715f21fc82701c5bff991a2eb2d29 100644
--- a/htdocs/contact/info.php
+++ b/htdocs/contact/info.php
@@ -35,6 +35,8 @@ $contactid = GETPOST("id",'int');
 if ($user->societe_id) $socid=$user->societe_id;
 $result = restrictedArea($user, 'contact', $contactid, 'socpeople&societe');
 
+$contact = new Contact($db);
+
 
 
 /*
@@ -43,25 +45,26 @@ $result = restrictedArea($user, 'contact', $contactid, 'socpeople&societe');
 
 llxHeader('',$langs->trans("ContactsAddresses"),'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Empresas');
 
+if ($contactid > 0)
+{
+	$result = $contact->fetch($contactid, $user);
 
-$contact = new Contact($db);
-$contact->fetch($contactid, $user);
-$contact->info($contactid);
+	$contact->info($contactid);
 
 
-$head = contact_prepare_head($contact);
+	$head = contact_prepare_head($contact);
 
-dol_fiche_head($head, 'info', $langs->trans("ContactsAddresses"), 0, 'contact');
+	dol_fiche_head($head, 'info', $langs->trans("ContactsAddresses"), 0, 'contact');
 
 
-print '<table width="100%"><tr><td>';
-print '</td></tr></table>';
+	print '<table width="100%"><tr><td>';
+	print '</td></tr></table>';
 
-dol_print_object_info($contact);
+	dol_print_object_info($contact);
 
-print "</div>";
+	print "</div>";
+}
 
 llxFooter();
 
 $db->close();
-?>
diff --git a/htdocs/contact/ldap.php b/htdocs/contact/ldap.php
index f284ee1834d6aa8af11d51dd31bdfb578dd1621d..79e6246fc6054071a155c8552a83e81794b373f4 100644
--- a/htdocs/contact/ldap.php
+++ b/htdocs/contact/ldap.php
@@ -40,37 +40,40 @@ if ($user->societe_id) $socid=$user->societe_id;
 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
 
 $contact = new Contact($db);
-$contact->fetch($id, $user);
 
+if ($id > 0)
+{
+	$contact->fetch($id, $user);
 
-/*
- * Actions
- */
+	/*
+	 * Actions
+	 */
 
-if ($action == 'dolibarr2ldap')
-{
-	$message="";
+	if ($action == 'dolibarr2ldap')
+	{
+		$message="";
 
-	$db->begin();
+		$db->begin();
 
-	$ldap=new Ldap();
-	$result=$ldap->connect_bind();
+		$ldap=new Ldap();
+		$result=$ldap->connect_bind();
 
-	$info=$contact->_load_ldap_info();
-	$dn=$contact->_load_ldap_dn($info);
-	$olddn=$dn;	// We can say that old dn = dn as we force synchro
+		$info=$contact->_load_ldap_info();
+		$dn=$contact->_load_ldap_dn($info);
+		$olddn=$dn;	// We can say that old dn = dn as we force synchro
 
-	$result=$ldap->update($dn,$info,$user,$olddn);
+		$result=$ldap->update($dn,$info,$user,$olddn);
 
-	if ($result >= 0)
-	{
-		$message.='<div class="ok">'.$langs->trans("ContactSynchronized").'</div>';
-		$db->commit();
-	}
-	else
-	{
-		$message.='<div class="error">'.$ldap->error.'</div>';
-		$db->rollback();
+		if ($result >= 0)
+		{
+			$message.='<div class="ok">'.$langs->trans("ContactSynchronized").'</div>';
+			$db->commit();
+		}
+		else
+		{
+			$message.='<div class="error">'.$ldap->error.'</div>';
+			$db->rollback();
+		}
 	}
 }
 
@@ -79,138 +82,139 @@ if ($action == 'dolibarr2ldap')
  *	View
  */
 
+$form = new Form($db);
+
 $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
 
 llxHeader('',$title,'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Empresas');
 
-$form = new Form($db);
+if ($id > 0)
+{
+	$head = contact_prepare_head($contact);
 
-$head = contact_prepare_head($contact);
+	dol_fiche_head($head, 'ldap', $title, 0, 'contact');
 
-dol_fiche_head($head, 'ldap', $title, 0, 'contact');
 
+	print '<table class="border" width="100%">';
 
-print '<table class="border" width="100%">';
+	// Ref
+	print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">';
+	print $form->showrefnav($contact,'id');
+	print '</td></tr>';
 
-// Ref
-print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">';
-print $form->showrefnav($contact,'id');
-print '</td></tr>';
+	// Name
+	print '<tr><td>'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td>'.$contact->lastname.'</td>';
+	print '<td>'.$langs->trans("Firstname").'</td><td width="25%">'.$contact->firstname.'</td></tr>';
 
-// Name
-print '<tr><td>'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td>'.$contact->lastname.'</td>';
-print '<td>'.$langs->trans("Firstname").'</td><td width="25%">'.$contact->firstname.'</td></tr>';
+	// Company
+	if ($contact->socid > 0)
+	{
+		$objsoc = new Societe($db);
+		$objsoc->fetch($contact->socid);
 
-// Company
-if ($contact->socid > 0)
-{
-	$objsoc = new Societe($db);
-	$objsoc->fetch($contact->socid);
+		print '<tr><td width="20%">'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
+	}
+	else
+	{
+		print '<tr><td width="20%">'.$langs->trans("Company").'</td><td colspan="3">';
+		print $langs->trans("ContactNotLinkedToCompany");
+		print '</td></tr>';
+	}
 
-	print '<tr><td width="20%">'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
-}
-else
-{
-	print '<tr><td width="20%">'.$langs->trans("Company").'</td><td colspan="3">';
-	print $langs->trans("ContactNotLinkedToCompany");
+	// Civility
+	print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
+	print $contact->getCivilityLabel();
 	print '</td></tr>';
-}
-
-// Civility
-print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
-print $contact->getCivilityLabel();
-print '</td></tr>';
 
-// LDAP DN
-print '<tr><td>LDAP '.$langs->trans("LDAPContactDn").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_CONTACT_DN."</td></tr>\n";
+	// LDAP DN
+	print '<tr><td>LDAP '.$langs->trans("LDAPContactDn").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_CONTACT_DN."</td></tr>\n";
 
-// LDAP Cle
-print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_KEY_CONTACTS."</td></tr>\n";
+	// LDAP Cle
+	print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_KEY_CONTACTS."</td></tr>\n";
 
-// LDAP Server
-print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
-print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
-print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
+	// LDAP Server
+	print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
+	print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
+	print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
 
-print '</table>';
+	print '</table>';
 
-print '</div>';
+	print '</div>';
 
 
-dol_htmloutput_mesg($message);
+	dol_htmloutput_mesg($message);
 
 
-/*
- * Barre d'actions
- */
+	/*
+	 * Barre d'actions
+	 */
 
-print '<div class="tabsAction">';
+	print '<div class="tabsAction">';
 
-if (! empty($conf->global->LDAP_CONTACT_ACTIVE) && $conf->global->LDAP_CONTACT_ACTIVE != 'ldap2dolibarr')
-{
-	print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$contact->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
-}
+	if (! empty($conf->global->LDAP_CONTACT_ACTIVE) && $conf->global->LDAP_CONTACT_ACTIVE != 'ldap2dolibarr')
+	{
+		print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$contact->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
+	}
 
-print "</div>\n";
+	print "</div>\n";
 
-if (! empty($conf->global->LDAP_CONTACT_ACTIVE) && $conf->global->LDAP_CONTACT_ACTIVE != 'ldap2dolibarr') print "<br>\n";
+	if (! empty($conf->global->LDAP_CONTACT_ACTIVE) && $conf->global->LDAP_CONTACT_ACTIVE != 'ldap2dolibarr') print "<br>\n";
 
 
 
-// Affichage attributs LDAP
-print_titre($langs->trans("LDAPInformationsForThisContact"));
+	// Affichage attributs LDAP
+	print_titre($langs->trans("LDAPInformationsForThisContact"));
 
-print '<table width="100%" class="noborder">';
+	print '<table width="100%" class="noborder">';
 
-print '<tr class="liste_titre">';
-print '<td>'.$langs->trans("LDAPAttributes").'</td>';
-print '<td>'.$langs->trans("Value").'</td>';
-print '</tr>';
+	print '<tr class="liste_titre">';
+	print '<td>'.$langs->trans("LDAPAttributes").'</td>';
+	print '<td>'.$langs->trans("Value").'</td>';
+	print '</tr>';
 
-// Lecture LDAP
-$ldap=new Ldap();
-$result=$ldap->connect_bind();
-if ($result > 0)
-{
-	$info=$contact->_load_ldap_info();
-	$dn=$contact->_load_ldap_dn($info,1);
-	$search = "(".$contact->_load_ldap_dn($info,2).")";
-	$records=$ldap->getAttribute($dn,$search);
+	// Lecture LDAP
+	$ldap=new Ldap();
+	$result=$ldap->connect_bind();
+	if ($result > 0)
+	{
+		$info=$contact->_load_ldap_info();
+		$dn=$contact->_load_ldap_dn($info,1);
+		$search = "(".$contact->_load_ldap_dn($info,2).")";
+		$records=$ldap->getAttribute($dn,$search);
 
-	//var_dump($records);
+		//var_dump($records);
 
-	// Affichage arbre
-	if (count($records) && $records != false && (! isset($records['count']) || $records['count'] > 0))
-	{
-		if (! is_array($records))
+		// Affichage arbre
+		if (count($records) && $records != false && (! isset($records['count']) || $records['count'] > 0))
 		{
-			print '<tr '.$bc[false].'><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></td></tr>';
+			if (! is_array($records))
+			{
+				print '<tr '.$bc[false].'><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></td></tr>';
+			}
+			else
+			{
+				$result=show_ldap_content($records,0,$records['count'],true);
+			}
 		}
 		else
 		{
-			$result=show_ldap_content($records,0,$records['count'],true);
+			print '<tr '.$bc[false].'><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')</td></tr>';
 		}
+
+		$ldap->unbind();
+		$ldap->close();
 	}
 	else
 	{
-		print '<tr '.$bc[false].'><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')</td></tr>';
+		dol_print_error('',$ldap->error);
 	}
 
-	$ldap->unbind();
-	$ldap->close();
-}
-else
-{
-	dol_print_error('',$ldap->error);
-}
-
-
-print '</table>';
 
+	print '</table>';
 
+}
 
 
 $db->close();
 
 llxFooter();
-?>
diff --git a/htdocs/contact/perso.php b/htdocs/contact/perso.php
index 86462d05fae4bdeabb08fa98357679e1c138bbe7..bd74fc75ef84abafbd127176d941e7247a4aae27 100644
--- a/htdocs/contact/perso.php
+++ b/htdocs/contact/perso.php
@@ -38,210 +38,213 @@ if ($user->societe_id) $socid=$user->societe_id;
 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
 $object = new Contact($db);
 
-/*
- * Action
- */
+$result = $object->fetch($id, $user);
 
-if ($action == 'update' && ! $_POST["cancel"] && $user->rights->societe->contact->creer)
+if ($id > 0)
 {
-	$ret = $object->fetch($id);
-
-	// Note: Correct date should be completed with location to have exact GM time of birth.
-	$object->birthday = dol_mktime(0,0,0,$_POST["birthdaymonth"],$_POST["birthdayday"],$_POST["birthdayyear"]);
-	$object->birthday_alert = $_POST["birthday_alert"];
-
-	$result = $object->update_perso($id, $user);
-	if ($result > 0)
-	{
-		$object->old_name='';
-		$object->old_firstname='';
-	}
-	else
-	{
-		$error = $object->error;
-	}
-}
+    /*
+     * Action
+     */
+
+    if ($action == 'update' && ! $_POST["cancel"] && $user->rights->societe->contact->creer)
+    {
+        // Note: Correct date should be completed with location to have exact GM time of birth.
+        $object->birthday = dol_mktime(0,0,0,$_POST["birthdaymonth"],$_POST["birthdayday"],$_POST["birthdayyear"]);
+        $object->birthday_alert = $_POST["birthday_alert"];
 
+        $result = $object->update_perso($id, $user);
+        if ($result > 0)
+        {
+            $object->old_name='';
+            $object->old_firstname='';
+        }
+        else
+        {
+            $error = $object->error;
+        }
+    }
+}
 
 /*
  *	View
  */
 
+$form = new Form($db);
+
 $now=dol_now();
 
 $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
 
 llxHeader('',$title,'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Empresas');
 
-$form = new Form($db);
+if ($id > 0)
+{
+    $head = contact_prepare_head($object);
 
-$object->fetch($id, $user);
+    dol_fiche_head($head, 'perso', $title, 0, 'contact');
 
-$head = contact_prepare_head($object);
+    if ($action == 'edit')
+    {
+        /*
+         * Fiche en mode edition
+         */
 
-dol_fiche_head($head, 'perso', $title, 0, 'contact');
+        print '<form name="perso" method="POST" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
+        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
+        print '<input type="hidden" name="action" value="update">';
+        print '<input type="hidden" name="id" value="'.$object->id.'">';
 
-if ($action == 'edit')
-{
-	/*
-	 * Fiche en mode edition
-	 */
+        print '<table class="border" width="100%">';
 
-    print '<form name="perso" method="POST" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
-    print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
-    print '<input type="hidden" name="action" value="update">';
-    print '<input type="hidden" name="id" value="'.$object->id.'">';
+        // Ref
+        print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">';
+        print $object->id;
+        print '</td></tr>';
 
-    print '<table class="border" width="100%">';
+        // Name
+        print '<tr><td width="20%">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td width="30%">'.$object->lastname.'</td>';
+        print '<td width="20%">'.$langs->trans("Firstname").'</td><td width="30%">'.$object->firstname.'</td>';
 
-    // Ref
-    print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">';
-    print $object->id;
-    print '</td></tr>';
+        // Company
+        if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
+        {
+            if ($object->socid > 0)
+            {
+                $objsoc = new Societe($db);
+                $objsoc->fetch($object->socid);
+
+                print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td>';
+            }
+            else
+            {
+                print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">';
+                print $langs->trans("ContactNotLinkedToCompany");
+                print '</td></tr>';
+            }
+        }
 
-    // Name
-    print '<tr><td width="20%">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td width="30%">'.$object->lastname.'</td>';
-    print '<td width="20%">'.$langs->trans("Firstname").'</td><td width="30%">'.$object->firstname.'</td>';
+        // Civility
+        print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
+        print $object->getCivilityLabel();
+        print '</td></tr>';
 
-    // Company
-    if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
-    {
-        if ($object->socid > 0)
-        {
-            $objsoc = new Societe($db);
-            $objsoc->fetch($object->socid);
+        // Date To Birth
+        print '<tr><td>'.$langs->trans("DateToBirth").'</td><td>';
+        $form=new Form($db);
+        print $form->select_date($object->birthday,'birthday',0,0,1,"perso");
+        print '</td>';
 
-            print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td>';
+        print '<td colspan="2">'.$langs->trans("Alert").': ';
+        if (! empty($object->birthday_alert))
+        {
+            print '<input type="checkbox" name="birthday_alert" checked="checked"></td>';
         }
         else
         {
-            print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">';
-            print $langs->trans("ContactNotLinkedToCompany");
-            print '</td></tr>';
+            print '<input type="checkbox" name="birthday_alert"></td>';
         }
-    }
+        print '</tr>';
 
-    // Civility
-    print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
-    print $object->getCivilityLabel();
-    print '</td></tr>';
+        print "</table><br>";
 
-    // Date To Birth
-    print '<tr><td>'.$langs->trans("DateToBirth").'</td><td>';
-    $form=new Form($db);
-    print $form->select_date($object->birthday,'birthday',0,0,1,"perso");
-    print '</td>';
+        print '<center>';
+        print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
+        print ' &nbsp; ';
+        print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
+        print '</center>';
 
-    print '<td colspan="2">'.$langs->trans("Alert").': ';
-    if (! empty($object->birthday_alert))
-    {
-        print '<input type="checkbox" name="birthday_alert" checked="checked"></td>';
+        print "</form>";
     }
     else
     {
-        print '<input type="checkbox" name="birthday_alert"></td>';
-    }
-    print '</tr>';
+        /*
+         * Fiche en mode visu
+         */
+        print '<table class="border" width="100%">';
 
-    print "</table><br>";
+        $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php">'.$langs->trans("BackToList").'</a>';
 
-    print '<center>';
-    print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
-    print ' &nbsp; ';
-    print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
-    print '</center>';
+        // Ref
+        print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">';
+        print $form->showrefnav($object, 'id', $linkback);
+        print '</td></tr>';
 
-    print "</form>";
-}
-else
-{
-    /*
-     * Fiche en mode visu
-     */
-    print '<table class="border" width="100%">';
-
-    $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php">'.$langs->trans("BackToList").'</a>';
+        // Name
+        print '<tr><td width="20%">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td width="30%">'.$object->lastname.'</td>';
+        print '<td width="20%">'.$langs->trans("Firstname").'</td><td width="30%">'.$object->firstname.'</td></tr>';
 
-    // Ref
-    print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">';
-    print $form->showrefnav($object, 'id', $linkback);
-    print '</td></tr>';
-
-    // Name
-    print '<tr><td width="20%">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td width="30%">'.$object->lastname.'</td>';
-    print '<td width="20%">'.$langs->trans("Firstname").'</td><td width="30%">'.$object->firstname.'</td></tr>';
-
-    // Company
-    if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
-    {
-        if ($object->socid > 0)
+        // Company
+        if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
         {
-            $objsoc = new Societe($db);
-            $objsoc->fetch($object->socid);
-
-            print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
+            if ($object->socid > 0)
+            {
+                $objsoc = new Societe($db);
+                $objsoc->fetch($object->socid);
+
+                print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
+            }
+
+            else
+            {
+                print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">';
+                print $langs->trans("ContactNotLinkedToCompany");
+                print '</td></tr>';
+            }
         }
 
-        else
+        // Civility
+        print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
+        print $object->getCivilityLabel();
+        print '</td></tr>';
+
+        // Date To Birth
+        print '<tr>';
+        if (! empty($object->birthday))
         {
-            print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">';
-            print $langs->trans("ContactNotLinkedToCompany");
-            print '</td></tr>';
-        }
-    }
+            include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
 
-    // Civility
-    print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
-    print $object->getCivilityLabel();
-    print '</td></tr>';
+            print '<td>'.$langs->trans("DateToBirth").'</td><td colspan="3">'.dol_print_date($object->birthday,"day");
 
-    // Date To Birth
-    print '<tr>';
-    if (! empty($object->birthday))
-    {
-        include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
+            print ' &nbsp; ';
+            //var_dump($birthdatearray);
+            $ageyear=convertSecondToTime($now-$object->birthday,'year')-1970;
+            $agemonth=convertSecondToTime($now-$object->birthday,'month')-1;
+            if ($ageyear >= 2) print '('.$ageyear.' '.$langs->trans("DurationYears").')';
+            else if ($agemonth >= 2) print '('.$agemonth.' '.$langs->trans("DurationMonths").')';
+            else print '('.$agemonth.' '.$langs->trans("DurationMonth").')';
 
-        print '<td>'.$langs->trans("DateToBirth").'</td><td colspan="3">'.dol_print_date($object->birthday,"day");
 
-        print ' &nbsp; ';
-        //var_dump($birthdatearray);
-        $ageyear=convertSecondToTime($now-$object->birthday,'year')-1970;
-        $agemonth=convertSecondToTime($now-$object->birthday,'month')-1;
-        if ($ageyear >= 2) print '('.$ageyear.' '.$langs->trans("DurationYears").')';
-        else if ($agemonth >= 2) print '('.$agemonth.' '.$langs->trans("DurationMonths").')';
-        else print '('.$agemonth.' '.$langs->trans("DurationMonth").')';
+            print ' &nbsp; - &nbsp; ';
+            if ($object->birthday_alert) print $langs->trans("BirthdayAlertOn");
+            else print $langs->trans("BirthdayAlertOff");
+            print '</td>';
+        }
+        else
+        {
+            print '<td>'.$langs->trans("DateToBirth").'</td><td colspan="3">'.$langs->trans("Unknown")."</td>";
+        }
+        print "</tr>";
 
+        print "</table>";
 
-        print ' &nbsp; - &nbsp; ';
-        if ($object->birthday_alert) print $langs->trans("BirthdayAlertOn");
-        else print $langs->trans("BirthdayAlertOff");
-        print '</td>';
     }
-    else
-    {
-        print '<td>'.$langs->trans("DateToBirth").'</td><td colspan="3">'.$langs->trans("Unknown")."</td>";
-    }
-    print "</tr>";
 
-    print "</table>";
+    dol_fiche_end();
 
-}
-
-dol_fiche_end();
-
-if ($action != 'edit')
-{
-    // Barre d'actions
-    if ($user->societe_id == 0)
+    if ($action != 'edit')
     {
-        print '<div class="tabsAction">';
-
-        if ($user->rights->societe->contact->creer)
+        // Barre d'actions
+        if ($user->societe_id == 0)
         {
-            print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=edit">'.$langs->trans('Modify').'</a>';
-        }
+            print '<div class="tabsAction">';
+
+            if ($user->rights->societe->contact->creer)
+            {
+                print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=edit">'.$langs->trans('Modify').'</a>';
+            }
 
-        print "</div>";
+            print "</div>";
+        }
     }
 }
 
@@ -249,4 +252,3 @@ if ($action != 'edit')
 llxFooter();
 
 $db->close();
-?>
diff --git a/htdocs/contact/vcard.php b/htdocs/contact/vcard.php
index 76d73133e0f8a69d31ba033c9794838ad0de9ebf..6e439b7a575e2f015164464ad87bd23ab061ce02 100644
--- a/htdocs/contact/vcard.php
+++ b/htdocs/contact/vcard.php
@@ -35,70 +35,72 @@ $id = GETPOST('id', 'int');
 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
 
 $contact = new Contact($db);
-$result=$contact->fetch($id);
 
-$physicalperson=1;
-
-$company = new Societe($db);
-if ($contact->socid)
+if ($id > 0)
 {
-	$result=$company->fetch($contact->socid);
-	//print "ee";
-}
+	$result=$contact->fetch($id);
 
-// We create VCard
-$v = new vCard();
-$v->setProdId('Dolibarr '.DOL_VERSION);
+	$physicalperson=1;
 
-$v->setUid('DOLIBARR-CONTACTID-'.$contact->id);
-$v->setName($contact->lastname, $contact->firstname, "", "", "");
-$v->setFormattedName($contact->getFullName($langs));
+	$company = new Societe($db);
+	if ($contact->socid)
+	{
+		$result=$company->fetch($contact->socid);
+		//print "ee";
+	}
 
-// By default, all informations are for work (except phone_perso and phone_mobile)
-$v->setPhoneNumber($contact->phone_pro, "PREF;WORK;VOICE");
-$v->setPhoneNumber($contact->phone_mobile, "CELL;VOICE");
-$v->setPhoneNumber($contact->fax, "WORK;FAX");
+	// We create VCard
+	$v = new vCard();
+	$v->setProdId('Dolibarr '.DOL_VERSION);
 
-$v->setAddress("", "", $contact->address, $contact->town, "", $contact->zip, ($contact->country_code?$contact->country_id:''), "WORK;POSTAL");
-$v->setLabel("", "", $contact->address, $contact->town, "", $contact->zip, ($contact->country_code?$contact->country_id:''), "WORK");
-$v->setEmail($contact->email,'internet,pref');
-$v->setNote($contact->note);
+	$v->setUid('DOLIBARR-CONTACTID-'.$contact->id);
+	$v->setName($contact->lastname, $contact->firstname, "", "", "");
+	$v->setFormattedName($contact->getFullName($langs));
 
-$v->setTitle($contact->poste);
+	// By default, all informations are for work (except phone_perso and phone_mobile)
+	$v->setPhoneNumber($contact->phone_pro, "PREF;WORK;VOICE");
+	$v->setPhoneNumber($contact->phone_mobile, "CELL;VOICE");
+	$v->setPhoneNumber($contact->fax, "WORK;FAX");
 
-// Data from linked company
-if ($company->id)
-{
-	$v->setURL($company->url, "WORK");
-	if (! $contact->phone_pro) $v->setPhoneNumber($company->phone, "WORK;VOICE");
-	if (! $contact->fax)       $v->setPhoneNumber($company->fax, "WORK;FAX");
-	if (! $contact->zip)        $v->setAddress("", "", $company->address, $company->town, "", $company->zip, $company->country_code, "WORK;POSTAL");
-	if ($company->email != $contact->email) $v->setEmail($company->email,'internet');
-	// Si contact lie a un tiers non de type "particulier"
-	if ($contact->typent_code != 'TE_PRIVATE') $v->setOrg($company->nom);
-}
+	$v->setAddress("", "", $contact->address, $contact->town, "", $contact->zip, ($contact->country_code?$contact->country_id:''), "WORK;POSTAL");
+	$v->setLabel("", "", $contact->address, $contact->town, "", $contact->zip, ($contact->country_code?$contact->country_id:''), "WORK");
+	$v->setEmail($contact->email,'internet,pref');
+	$v->setNote($contact->note);
+
+	$v->setTitle($contact->poste);
 
-// Personal informations
-$v->setPhoneNumber($contact->phone_perso, "HOME;VOICE");
-if ($contact->birthday) $v->setBirthday($contact->birthday);
+	// Data from linked company
+	if ($company->id)
+	{
+		$v->setURL($company->url, "WORK");
+		if (! $contact->phone_pro) $v->setPhoneNumber($company->phone, "WORK;VOICE");
+		if (! $contact->fax)       $v->setPhoneNumber($company->fax, "WORK;FAX");
+		if (! $contact->zip)        $v->setAddress("", "", $company->address, $company->town, "", $company->zip, $company->country_code, "WORK;POSTAL");
+		if ($company->email != $contact->email) $v->setEmail($company->email,'internet');
+		// Si contact lie a un tiers non de type "particulier"
+		if ($contact->typent_code != 'TE_PRIVATE') $v->setOrg($company->nom);
+	}
 
-$db->close();
+	// Personal informations
+	$v->setPhoneNumber($contact->phone_perso, "HOME;VOICE");
+	if ($contact->birthday) $v->setBirthday($contact->birthday);
 
+	$db->close();
 
-// Renvoi la VCard au navigateur
 
-$output = $v->getVCard();
+	// Renvoi la VCard au navigateur
 
-$filename =trim(urldecode($v->getFileName()));      // "Nom prenom.vcf"
-$filenameurlencoded = dol_sanitizeFileName(urlencode($filename));
-//$filename = dol_sanitizeFileName($filename);
+	$output = $v->getVCard();
 
+	$filename =trim(urldecode($v->getFileName()));      // "Nom prenom.vcf"
+	$filenameurlencoded = dol_sanitizeFileName(urlencode($filename));
+	//$filename = dol_sanitizeFileName($filename);
 
-header("Content-Disposition: attachment; filename=\"".$filename."\"");
-header("Content-Length: ".dol_strlen($output));
-header("Connection: close");
-header("Content-Type: text/x-vcard; name=\"".$filename."\"");
 
-print $output;
+	header("Content-Disposition: attachment; filename=\"".$filename."\"");
+	header("Content-Length: ".dol_strlen($output));
+	header("Connection: close");
+	header("Content-Type: text/x-vcard; name=\"".$filename."\"");
 
-?>
+	print $output;
+}