diff --git a/htdocs/core/tpl/contacts.tpl.php b/htdocs/core/tpl/contacts.tpl.php index eca100731ac..104ffe81bc6 100644 --- a/htdocs/core/tpl/contacts.tpl.php +++ b/htdocs/core/tpl/contacts.tpl.php @@ -162,72 +162,74 @@ print ""; // TODO: replace this with direct SQL string to use $db->sort($sortfield, $sortorder) $list = array(); -foreach (array('internal', 'external') as $source) +foreach(array('internal', 'external') as $source) { - $tmpobject = $object; - if (($object->element == 'shipping' || $object->element == 'reception') && is_object($objectsrc)) { - $tmpobject = $objectsrc; + $contactlist = $objectsrc->liste_contact(-1, $source); + } + else + { + $contactlist = $object->liste_contact(-1, $source); } - $tab = $tmpobject->liste_contact(-1, $source); - $num = count($tab); - - $i = 0; - while ($i < $num) + foreach ($contactlist as $contact) { $entry = new stdClass(); + $entry->id = $contact['rowid']; + $entry->type = $contact['libelle']; + $entry->nature = ""; + $entry->thirdparty_html = ""; + $entry->thirdparty_name = ""; + $entry->contact_html = ""; + $entry->contact_name = ""; + $entry->status = ""; - $entry->id = $tab[$i]['rowid']; - $entry->type = $tab[$i]['libelle']; - - if ($tab[$i]['source'] == 'internal') + if ($contact['source'] == 'internal') { $entry->nature = $langs->trans("User"); } - elseif ($tab[$i]['source'] == 'external') + else if ($contact['source'] == 'external') { $entry->nature = $langs->trans("ThirdPartyContact"); } - if ($tab[$i]['socid'] > 0) + if ($contact['socid'] > 0) { - $companystatic->fetch($tab[$i]['socid']); - $entry->thirdparty = $companystatic->getNomUrl(1); + $companystatic->fetch($contact['socid']); + $entry->thirdparty_html = $companystatic->getNomUrl(1); + $entry->thirdparty_name = strtolower($companystatic->getFullName($langs)); } - elseif ($tab[$i]['socid'] < 0) + else if ($contact['socid'] < 0) { - $entry->thirdparty = $conf->global->MAIN_INFO_SOCIETE_NOM; - } - elseif (!$tab[$i]['socid']) - { - $entry->thirdparty = ""; + $entry->thirdparty_html = $conf->global->MAIN_INFO_SOCIETE_NOM; + $entry->thirdparty_name = strtolower($conf->global->MAIN_INFO_SOCIETE_NOM); } - if ($tab[$i]['source'] == 'internal') + if ($contact['source'] == 'internal') { - $userstatic->fetch($tab[$i]['id']); - $entry->contact = $userstatic->getNomUrl(-1, '', 0, 0, 0, 0, '', 'valignmiddle'); + $userstatic->fetch($contact['id']); + $entry->contact_html = $userstatic->getNomUrl(-1, '', 0, 0, 0, 0, '', 'valignmiddle'); + $entry->contact_name = strtolower($userstatic->getFullName($langs)); } - elseif ($tab[$i]['source'] == 'external') + else if ($contact['source'] == 'external') { - $contactstatic->fetch($tab[$i]['id']); - $entry->contact = $contactstatic->getNomUrl(1, '', 0, '', 0, 0); + $contactstatic->fetch($contact['id']); + $entry->contact_html = $contactstatic->getNomUrl(1, '', 0, '', 0, 0); + $entry->contact_name = strtolower($contactstatic->getFullName($langs)); } - if ($tab[$i]['source'] == 'internal') + if ($contact['source'] == 'internal') { - $entry->status = $userstatic->LibStatut($tab[$i]['statuscontact'], 3); + $entry->status = $userstatic->LibStatut($contact['statuscontact'], 3); } - elseif ($tab[$i]['source'] == 'external') + else if ($contact['source'] == 'external') { - $entry->status = $contactstatic->LibStatut($tab[$i]['statuscontact'], 3); + $entry->status = $contactstatic->LibStatut($contact['statuscontact'], 3); } - $i++; $list[] = $entry; - } + } } @@ -255,9 +257,6 @@ $param = 'id='.$object->id.'&mainmenu=home'; /** * Show list */ - -print '
'; - print '
'; print ''; print ''; @@ -272,10 +271,10 @@ print ''; print ''; print_liste_field_titre($arrayfields['nature']['label'], $_SERVER["PHP_SELF"], "nature", "", $param, "", $sortfield, $sortorder); -print_liste_field_titre($arrayfields['thirdparty']['label'], $_SERVER["PHP_SELF"], "thirdparty", "", $param, "", $sortfield, $sortorder); -print_liste_field_titre($arrayfields['contact']['label'], $_SERVER["PHP_SELF"], "contact", "", $param, "", $sortfield, $sortorder); +print_liste_field_titre($arrayfields['thirdparty']['label'], $_SERVER["PHP_SELF"], "thirdparty_name", "", $param, "", $sortfield, $sortorder); +print_liste_field_titre($arrayfields['contact']['label'], $_SERVER["PHP_SELF"], "contact_name", "", $param, "", $sortfield, $sortorder); print_liste_field_titre($arrayfields['type']['label'], $_SERVER["PHP_SELF"], "type", "", $param, "", $sortfield, $sortorder); -print_liste_field_titre($arrayfields['status']['label'], $_SERVER["PHP_SELF"], "statut", "", $param, "", $sortfield, $sortorder, 'center '); +print_liste_field_titre($arrayfields['status']['label'], $_SERVER["PHP_SELF"], "statut", "", $param, "", $sortfield, $sortorder); print_liste_field_titre($arrayfields['link']['label'], $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder, 'center maxwidthsearch '); print ""; @@ -284,10 +283,10 @@ foreach ($list as $entry) print ''; print ''.$entry->nature.''; - print ''.$entry->thirdparty.''; - print ''.$entry->contact.''; + print ''.$entry->thirdparty_html.''; + print ''.$entry->contact_html.''; print ''.$entry->type.''; - print ''.$entry->status.''; + print ''.$entry->status.''; if ($permission) { @@ -307,7 +306,6 @@ foreach ($list as $entry) } print ""; -print ""; print "
"; print "";