diff --git a/ChangeLog b/ChangeLog index 67920bbfee3..8d8e9ac9c72 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 5149eed9efb..c76655f5099 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 */ +$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 ''; - -$linkback = ''.$langs->trans("BackToList").''; - -// Ref -print ''; - -// Name -print ''; -print ''; - -// 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 ''; - } - else - { - print ''; - } + $head = contact_prepare_head($contact); + + dol_fiche_head($head, 'exportimport', $title, 0, 'contact'); + + + /* + * Fiche en mode visu + */ + print '
'.$langs->trans("Ref").''; -print $form->showrefnav($contact, 'id', $linkback); -print '
'.$langs->trans("Lastname").' / '.$langs->trans("Label").''.$contact->lastname.''.$langs->trans("Firstname").''.$contact->firstname.'
'.$langs->trans("Company").''.$objsoc->getNomUrl(1).'
'.$langs->trans("Company").''; - print $langs->trans("ContactNotLinkedToCompany"); - print '
'; + + $linkback = ''.$langs->trans("BackToList").''; + + // Ref + print ''; + + // Name + print ''; + print ''; + + // Company + if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) + { + if ($contact->socid > 0) + { + $objsoc = new Societe($db); + $objsoc->fetch($contact->socid); + + print ''; + } + else + { + print ''; + } + } + + // Civility + print ''; + + print '
'.$langs->trans("Ref").''; + print $form->showrefnav($contact, 'id', $linkback); + print '
'.$langs->trans("Lastname").' / '.$langs->trans("Label").''.$contact->lastname.''.$langs->trans("Firstname").''.$contact->firstname.'
'.$langs->trans("Company").''.$objsoc->getNomUrl(1).'
'.$langs->trans("Company").''; + print $langs->trans("ContactNotLinkedToCompany"); + print '
'.$langs->trans("UserTitle").''; + print $contact->getCivilityLabel(); + print '
'; + + print ''; + + print '
'; + + print $langs->trans("ExportCardToFormat").': '; + print ''; + print img_picto($langs->trans("VCard"),'vcard.png').' '; + print $langs->trans("VCard"); + print ''; } -// Civility -print ''.$langs->trans("UserTitle").''; -print $contact->getCivilityLabel(); -print ''; - -print ''; - -print ''; - -print '
'; - -print $langs->trans("ExportCardToFormat").': '; -print ''; -print img_picto($langs->trans("VCard"),'vcard.png').' '; -print $langs->trans("VCard"); -print ''; - - - - $db->close(); llxFooter(); -?> diff --git a/htdocs/contact/info.php b/htdocs/contact/info.php index 3ac6747bb6b..5d4904faa87 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ó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 '
'; -print '
'; + print '
'; + print '
'; -dol_print_object_info($contact); + dol_print_object_info($contact); -print ""; + print ""; +} llxFooter(); $db->close(); -?> diff --git a/htdocs/contact/ldap.php b/htdocs/contact/ldap.php index f284ee1834d..79e6246fc60 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); - -/* - * 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.='
'.$langs->trans("ContactSynchronized").'
'; - $db->commit(); - } - else - { - $message.='
'.$ldap->error.'
'; - $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.='
'.$langs->trans("ContactSynchronized").'
'; + $db->commit(); + } + else + { + $message.='
'.$ldap->error.'
'; + $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ódulo_Empresas'); -$form = new Form($db); - -$head = contact_prepare_head($contact); - -dol_fiche_head($head, 'ldap', $title, 0, 'contact'); - - -print ''; - -// Ref -print ''; - -// Name -print ''; -print ''; - -// Company -if ($contact->socid > 0) +if ($id > 0) { - $objsoc = new Societe($db); - $objsoc->fetch($contact->socid); + $head = contact_prepare_head($contact); - print ''; -} -else -{ - print '
'.$langs->trans("Ref").''; -print $form->showrefnav($contact,'id'); -print '
'.$langs->trans("Lastname").' / '.$langs->trans("Label").''.$contact->lastname.''.$langs->trans("Firstname").''.$contact->firstname.'
'.$langs->trans("Company").''.$objsoc->getNomUrl(1).'
'.$langs->trans("Company").''; - print $langs->trans("ContactNotLinkedToCompany"); + dol_fiche_head($head, 'ldap', $title, 0, 'contact'); + + + print ''; + + // Ref + print ''; -} -// Civility -print ''; + // Name + print ''; + print ''; -// LDAP DN -print '\n"; - -// LDAP Cle -print '\n"; - -// LDAP Server -print '\n"; -print '\n"; -print '\n"; - -print '
'.$langs->trans("Ref").''; + print $form->showrefnav($contact,'id'); print '
'.$langs->trans("UserTitle").''; -print $contact->getCivilityLabel(); -print '
'.$langs->trans("Lastname").' / '.$langs->trans("Label").''.$contact->lastname.''.$langs->trans("Firstname").''.$contact->firstname.'
LDAP '.$langs->trans("LDAPContactDn").''.$conf->global->LDAP_CONTACT_DN."
LDAP '.$langs->trans("LDAPNamingAttribute").''.$conf->global->LDAP_KEY_CONTACTS."
LDAP '.$langs->trans("LDAPPrimaryServer").''.$conf->global->LDAP_SERVER_HOST."
LDAP '.$langs->trans("LDAPSecondaryServer").''.$conf->global->LDAP_SERVER_HOST_SLAVE."
LDAP '.$langs->trans("LDAPServerPort").''.$conf->global->LDAP_SERVER_PORT."
'; - -print ''; - - -dol_htmloutput_mesg($message); - - -/* - * Barre d'actions - */ - -print '
'; - -if (! empty($conf->global->LDAP_CONTACT_ACTIVE) && $conf->global->LDAP_CONTACT_ACTIVE != 'ldap2dolibarr') -{ - print ''.$langs->trans("ForceSynchronize").''; -} - -print "
\n"; - -if (! empty($conf->global->LDAP_CONTACT_ACTIVE) && $conf->global->LDAP_CONTACT_ACTIVE != 'ldap2dolibarr') print "
\n"; - - - -// Affichage attributs LDAP -print_titre($langs->trans("LDAPInformationsForThisContact")); - -print ''; - -print ''; -print ''; -print ''; -print ''; - -// 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 ''; - } - else - { - $result=show_ldap_content($records,0,$records['count'],true); - } + $objsoc = new Societe($db); + $objsoc->fetch($contact->socid); + + print ''; } else { - print ''; + print ''; } - $ldap->unbind(); - $ldap->close(); + // Civility + print ''; + + // LDAP DN + print '\n"; + + // LDAP Cle + print '\n"; + + // LDAP Server + print '\n"; + print '\n"; + print '\n"; + + print '
'.$langs->trans("LDAPAttributes").''.$langs->trans("Value").'
'.$langs->trans("ErrorFailedToReadLDAP").'
'.$langs->trans("Company").''.$objsoc->getNomUrl(1).'
'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')
'.$langs->trans("Company").''; + print $langs->trans("ContactNotLinkedToCompany"); + print '
'.$langs->trans("UserTitle").''; + print $contact->getCivilityLabel(); + print '
LDAP '.$langs->trans("LDAPContactDn").''.$conf->global->LDAP_CONTACT_DN."
LDAP '.$langs->trans("LDAPNamingAttribute").''.$conf->global->LDAP_KEY_CONTACTS."
LDAP '.$langs->trans("LDAPPrimaryServer").''.$conf->global->LDAP_SERVER_HOST."
LDAP '.$langs->trans("LDAPSecondaryServer").''.$conf->global->LDAP_SERVER_HOST_SLAVE."
LDAP '.$langs->trans("LDAPServerPort").''.$conf->global->LDAP_SERVER_PORT."
'; + + print ''; + + + dol_htmloutput_mesg($message); + + + /* + * Barre d'actions + */ + + print '
'; + + if (! empty($conf->global->LDAP_CONTACT_ACTIVE) && $conf->global->LDAP_CONTACT_ACTIVE != 'ldap2dolibarr') + { + print ''.$langs->trans("ForceSynchronize").''; + } + + print "
\n"; + + if (! empty($conf->global->LDAP_CONTACT_ACTIVE) && $conf->global->LDAP_CONTACT_ACTIVE != 'ldap2dolibarr') print "
\n"; + + + + // Affichage attributs LDAP + print_titre($langs->trans("LDAPInformationsForThisContact")); + + print ''; + + print ''; + print ''; + print ''; + print ''; + + // 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 ''; + } + else + { + $result=show_ldap_content($records,0,$records['count'],true); + } + } + else + { + print ''; + } + + $ldap->unbind(); + $ldap->close(); + } + else + { + dol_print_error('',$ldap->error); + } + + + print '
'.$langs->trans("LDAPAttributes").''.$langs->trans("Value").'
'.$langs->trans("ErrorFailedToReadLDAP").'
'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')
'; + } -else -{ - dol_print_error('',$ldap->error); -} - - -print '
'; - - $db->close(); llxFooter(); -?> diff --git a/htdocs/contact/perso.php b/htdocs/contact/perso.php index 86462d05fae..bd74fc75ef8 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); + /* + * 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ó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 '
'; - print ''; - print ''; - print ''; + dol_fiche_head($head, 'perso', $title, 0, 'contact'); - print ''; - - // Ref - print ''; - - // Name - print ''; - print ''; - - // Company - if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) + if ($action == 'edit') { - if ($object->socid > 0) + /* + * Fiche en mode edition + */ + + print ''; + print ''; + print ''; + print ''; + + print '
'.$langs->trans("Ref").''; - print $object->id; - print '
'.$langs->trans("Lastname").' / '.$langs->trans("Label").''.$object->lastname.''.$langs->trans("Firstname").''.$object->firstname.'
'; + + // Ref + print ''; + + // Name + print ''; + print ''; + + // 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 ''; - } - else - { - print ''; - } - } - - // Civility - print ''; - - // Date To Birth - print ''; - - print ''; - } - else - { - print ''; - } - print ''; - - print "
'.$langs->trans("Ref").''; + print $object->id; + print '
'.$langs->trans("Lastname").' / '.$langs->trans("Label").''.$object->lastname.''.$langs->trans("Firstname").''.$object->firstname.'
'.$langs->trans("Company").''.$objsoc->getNomUrl(1).'
'.$langs->trans("Company").''; - print $langs->trans("ContactNotLinkedToCompany"); - print '
'.$langs->trans("UserTitle").''; - print $object->getCivilityLabel(); - print '
'.$langs->trans("DateToBirth").''; - $form=new Form($db); - print $form->select_date($object->birthday,'birthday',0,0,1,"perso"); - print ''.$langs->trans("Alert").': '; - if (! empty($object->birthday_alert)) - { - print '

"; - - print '
'; - print ''; - print '   '; - print ''; - print '
'; - - print "
"; -} -else -{ - /* - * Fiche en mode visu - */ - print ''; - - $linkback = ''.$langs->trans("BackToList").''; - - // Ref - print ''; - - // Name - print ''; - print ''; - - // Company - if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) - { - if ($object->socid > 0) - { - $objsoc = new Societe($db); - $objsoc->fetch($object->socid); - - print ''; + print ''; + } + else + { + print ''; + } } - else - { - print ''; - } - } + // Civility + print ''; - // Civility - print ''; - - // Date To Birth - print ''; - if (! empty($object->birthday)) - { - include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; - - print ''; + + print ''; + } + else + { + print ''; + } + print ''; + + print "
'.$langs->trans("Ref").''; - print $form->showrefnav($object, 'id', $linkback); - print '
'.$langs->trans("Lastname").' / '.$langs->trans("Label").''.$object->lastname.''.$langs->trans("Firstname").''.$object->firstname.'
'.$langs->trans("Company").''.$objsoc->getNomUrl(1).'
'.$langs->trans("Company").''.$objsoc->getNomUrl(1).'
'.$langs->trans("Company").''; + print $langs->trans("ContactNotLinkedToCompany"); + print '
'.$langs->trans("Company").''; - print $langs->trans("ContactNotLinkedToCompany"); - print '
'.$langs->trans("UserTitle").''; + print $object->getCivilityLabel(); + print '
'.$langs->trans("UserTitle").''; - print $object->getCivilityLabel(); - print '
'.$langs->trans("DateToBirth").''.dol_print_date($object->birthday,"day"); - - print '   '; - //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 '   -   '; - if ($object->birthday_alert) print $langs->trans("BirthdayAlertOn"); - else print $langs->trans("BirthdayAlertOff"); + // Date To Birth + print '
'.$langs->trans("DateToBirth").''; + $form=new Form($db); + print $form->select_date($object->birthday,'birthday',0,0,1,"perso"); print ''.$langs->trans("Alert").': '; + if (! empty($object->birthday_alert)) + { + print '

"; + + print '
'; + print ''; + print '   '; + print ''; + print '
'; + + print ""; } else { - print ''.$langs->trans("DateToBirth").''.$langs->trans("Unknown").""; - } - print ""; + /* + * Fiche en mode visu + */ + print ''; - print "
"; + $linkback = ''.$langs->trans("BackToList").''; -} + // Ref + print ''.$langs->trans("Ref").''; + print $form->showrefnav($object, 'id', $linkback); + print ''; -dol_fiche_end(); + // Name + print ''.$langs->trans("Lastname").' / '.$langs->trans("Label").''.$object->lastname.''; + print ''.$langs->trans("Firstname").''.$object->firstname.''; -if ($action != 'edit') -{ - // Barre d'actions - if ($user->societe_id == 0) - { - print '
'; - - if ($user->rights->societe->contact->creer) + // Company + if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) { - print ''.$langs->trans('Modify').''; + if ($object->socid > 0) + { + $objsoc = new Societe($db); + $objsoc->fetch($object->socid); + + print ''.$langs->trans("Company").''.$objsoc->getNomUrl(1).''; + } + + else + { + print ''.$langs->trans("Company").''; + print $langs->trans("ContactNotLinkedToCompany"); + print ''; + } } - print "
"; + // Civility + print ''.$langs->trans("UserTitle").''; + print $object->getCivilityLabel(); + print ''; + + // Date To Birth + print ''; + if (! empty($object->birthday)) + { + include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; + + print ''.$langs->trans("DateToBirth").''.dol_print_date($object->birthday,"day"); + + print '   '; + //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 '   -   '; + if ($object->birthday_alert) print $langs->trans("BirthdayAlertOn"); + else print $langs->trans("BirthdayAlertOff"); + print ''; + } + else + { + print ''.$langs->trans("DateToBirth").''.$langs->trans("Unknown").""; + } + print ""; + + print ""; + + } + + dol_fiche_end(); + + if ($action != 'edit') + { + // Barre d'actions + if ($user->societe_id == 0) + { + print '
'; + + if ($user->rights->societe->contact->creer) + { + print ''.$langs->trans('Modify').''; + } + + print "
"; + } } } @@ -249,4 +252,3 @@ if ($action != 'edit') llxFooter(); $db->close(); -?> diff --git a/htdocs/contact/vcard.php b/htdocs/contact/vcard.php index 76d73133e0f..6e439b7a575 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); + + $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; - -?>