Fix: [ bug #2570 ] [Contacts] Page should not process if ID is invalid

This commit is contained in:
Laurent Destailleur 2015-07-19 11:21:21 +02:00
parent d422fac3fe
commit 8d7c1f8d4c
6 changed files with 456 additions and 445 deletions

View File

@ -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

View File

@ -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
*/
$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ódulo_Empresas');
$form = new Form($db);
$contact = new Contact($db);
$contact->fetch($id, $user);
$head = contact_prepare_head($contact);
dol_fiche_head($head, 'exportimport', $title, 0, 'contact');
/*
* Fiche en mode visu
*/
print '<table class="border" width="100%">';
$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>';
// 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>';
// Company
if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
if ($id > 0)
{
if ($contact->socid > 0)
{
$objsoc = new Societe($db);
$objsoc->fetch($contact->socid);
$contact->fetch($id, $user);
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>';
}
$head = contact_prepare_head($contact);
dol_fiche_head($head, 'exportimport', $title, 0, 'contact');
/*
* Fiche en mode visu
*/
print '<table class="border" width="100%">';
$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>';
// 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>';
// 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>';
}
}
// Civility
print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
print $contact->getCivilityLabel();
print '</td></tr>';
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>';
}
// Civility
print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
print $contact->getCivilityLabel();
print '</td></tr>';
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();
?>

View File

@ -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();
?>

View File

@ -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);
/*
* Actions
*/
if ($action == 'dolibarr2ldap')
if ($id > 0)
{
$message="";
$contact->fetch($id, $user);
$db->begin();
/*
* Actions
*/
$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
$result=$ldap->update($dn,$info,$user,$olddn);
if ($result >= 0)
if ($action == 'dolibarr2ldap')
{
$message.='<div class="ok">'.$langs->trans("ContactSynchronized").'</div>';
$db->commit();
}
else
{
$message.='<div class="error">'.$ldap->error.'</div>';
$db->rollback();
$message="";
$db->begin();
$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
$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();
}
}
}
@ -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);
$head = contact_prepare_head($contact);
dol_fiche_head($head, 'ldap', $title, 0, 'contact');
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>';
// 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)
if ($id > 0)
{
$objsoc = new Societe($db);
$objsoc->fetch($contact->socid);
$head = contact_prepare_head($contact);
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");
dol_fiche_head($head, 'ldap', $title, 0, 'contact');
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>';
}
// Civility
print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
print $contact->getCivilityLabel();
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>';
// 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 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 '</div>';
dol_htmloutput_mesg($message);
/*
* Barre d'actions
*/
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>';
}
print "</div>\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"));
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>';
// 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);
// Affichage arbre
if (count($records) && $records != false && (! isset($records['count']) || $records['count'] > 0))
// Company
if ($contact->socid > 0)
{
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);
}
$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 '.$bc[false].'><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')</td></tr>';
print '<tr><td width="20%">'.$langs->trans("Company").'</td><td colspan="3">';
print $langs->trans("ContactNotLinkedToCompany");
print '</td></tr>';
}
$ldap->unbind();
$ldap->close();
// 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 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";
print '</table>';
print '</div>';
dol_htmloutput_mesg($message);
/*
* Barre d'actions
*/
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>';
}
print "</div>\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"));
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>';
// 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);
// Affichage arbre
if (count($records) && $records != false && (! isset($records['count']) || $records['count'] > 0))
{
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
{
print '<tr '.$bc[false].'><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')</td></tr>';
}
$ldap->unbind();
$ldap->close();
}
else
{
dol_print_error('',$ldap->error);
}
print '</table>';
}
else
{
dol_print_error('',$ldap->error);
}
print '</table>';
$db->close();
llxFooter();
?>

View File

@ -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);
/*
* Action
*/
// 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"];
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;
}
$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);
$object->fetch($id, $user);
$head = contact_prepare_head($object);
dol_fiche_head($head, 'perso', $title, 0, 'contact');
if ($action == 'edit')
if ($id > 0)
{
/*
* Fiche en mode edition
*/
$head = contact_prepare_head($object);
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.'">';
dol_fiche_head($head, 'perso', $title, 0, 'contact');
print '<table class="border" width="100%">';
// Ref
print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">';
print $object->id;
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>';
// Company
if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
if ($action == 'edit')
{
if ($object->socid > 0)
/*
* Fiche en mode edition
*/
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.'">';
print '<table class="border" width="100%">';
// Ref
print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">';
print $object->id;
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>';
// Company
if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
{
$objsoc = new Societe($db);
$objsoc->fetch($object->socid);
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>';
}
}
// Civility
print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
print $object->getCivilityLabel();
print '</td></tr>';
// 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 '<td colspan="2">'.$langs->trans("Alert").': ';
if (! empty($object->birthday_alert))
{
print '<input type="checkbox" name="birthday_alert" checked="checked"></td>';
}
else
{
print '<input type="checkbox" name="birthday_alert"></td>';
}
print '</tr>';
print "</table><br>";
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 "</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>';
// 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)
{
$objsoc = new Societe($db);
$objsoc->fetch($object->socid);
print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
print '<tr><td>'.$langs->trans("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>';
}
}
else
{
print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">';
print $langs->trans("ContactNotLinkedToCompany");
print '</td></tr>';
}
}
// Civility
print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
print $object->getCivilityLabel();
print '</td></tr>';
// 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))
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
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");
// 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 '<td colspan="2">'.$langs->trans("Alert").': ';
if (! empty($object->birthday_alert))
{
print '<input type="checkbox" name="birthday_alert" checked="checked"></td>';
}
else
{
print '<input type="checkbox" name="birthday_alert"></td>';
}
print '</tr>';
print "</table><br>";
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 "</form>";
}
else
{
print '<td>'.$langs->trans("DateToBirth").'</td><td colspan="3">'.$langs->trans("Unknown")."</td>";
}
print "</tr>";
/*
* Fiche en mode visu
*/
print '<table class="border" width="100%">';
print "</table>";
$linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php">'.$langs->trans("BackToList").'</a>';
}
// Ref
print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">';
print $form->showrefnav($object, 'id', $linkback);
print '</td></tr>';
dol_fiche_end();
// 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>';
if ($action != 'edit')
{
// Barre d'actions
if ($user->societe_id == 0)
{
print '<div class="tabsAction">';
if ($user->rights->societe->contact->creer)
// Company
if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
{
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=edit">'.$langs->trans('Modify').'</a>';
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>';
}
}
print "</div>";
// 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))
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
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>";
}
dol_fiche_end();
if ($action != 'edit')
{
// Barre d'actions
if ($user->societe_id == 0)
{
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>";
}
}
}
@ -249,4 +252,3 @@ if ($action != 'edit')
llxFooter();
$db->close();
?>

View File

@ -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);
$physicalperson=1;
$company = new Societe($db);
if ($contact->socid)
{
$result=$company->fetch($contact->socid);
//print "ee";
}
// We create VCard
$v = new vCard();
$v->setProdId('Dolibarr '.DOL_VERSION);
$v->setUid('DOLIBARR-CONTACTID-'.$contact->id);
$v->setName($contact->lastname, $contact->firstname, "", "", "");
$v->setFormattedName($contact->getFullName($langs));
// 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");
$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);
// 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);
}
// 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();
$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;
}
// We create VCard
$v = new vCard();
$v->setProdId('Dolibarr '.DOL_VERSION);
$v->setUid('DOLIBARR-CONTACTID-'.$contact->id);
$v->setName($contact->lastname, $contact->firstname, "", "", "");
$v->setFormattedName($contact->getFullName($langs));
// 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");
$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);
// 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);
}
// 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();
$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;
?>