Add sorting for "Contacts of ..."

This commit is contained in:
Tobias Sekan
2020-03-04 13:31:19 +01:00
committed by GitHub
parent c466f551e0
commit f823feba52

View File

@@ -28,7 +28,6 @@ if (empty($object) || !is_object($object))
exit;
}
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
@@ -66,8 +65,9 @@ $userstatic = new User($db);
<div class="tagtable tableforcontact centpercent noborder nobordertop allwidth">
<?php
if ($permission) {
?>
if ($permission)
{
?>
<form class="tagtr liste_titre">
<div class="tagtd liste_titre"><?php echo $langs->trans("NatureOfContact"); ?></div>
<div class="tagtd liste_titre"><?php echo $langs->trans("ThirdParty"); ?></div>
@@ -153,94 +153,180 @@ if ($permission) {
<?php
}
}
?>
<form class="tagtr liste_titre liste_titre_add formnoborder">
<div class="tagtd liste_titre"><?php echo $langs->trans("NatureOfContact"); ?></div>
<div class="tagtd liste_titre"><?php echo $langs->trans("ThirdParty"); ?></div>
<div class="tagtd liste_titre"><?php echo $langs->trans("Users").'/'.$langs->trans("Contacts"); ?></div>
<div class="tagtd liste_titre"><?php echo $langs->trans("ContactType"); ?></div>
<div class="tagtd liste_titre center"><?php echo $langs->trans("Status"); ?></div>
<div class="tagtd liste_titre">&nbsp;</div>
</form>
print "</div>";
<?php
$arrayofsource=array('internal','external'); // Show both link to user and thirdparties contacts
foreach($arrayofsource as $source) {
$tmpobject=$object;
if (($object->element == 'shipping'|| $object->element == 'reception') && is_object($objectsrc)) $tmpobject=$objectsrc;
/**
* Prepare list
*/
// TODO: replace this with direct SQL string to use $db->sort($sortfield, $sortorder)
$list = array();
foreach(array('internal', 'external') as $source)
{
$tmpobject = $object;
if (($object->element == 'shipping'|| $object->element == 'reception') && is_object($objectsrc))
{
$tmpobject = $objectsrc;
}
$tab = $tmpobject->liste_contact(-1, $source);
$num=count($tab);
$num = count($tab);
$i = 0;
while ($i < $num) {
?>
while ($i < $num)
{
$entry = '';
$entry->id = $tab[$i]['rowid'];
$entry->type = $tab[$i]['libelle'];
if ($tab[$i]['source'] == 'internal')
{
$entry->nature = $langs->trans("User");
}
else if ($tab[$i]['source'] == 'external')
{
$entry->nature = $langs->trans("ThirdPartyContact");
}
<form class="tagtr oddeven">
<div class="tagtd left">
<?php if ($tab[$i]['source']=='internal') echo $langs->trans("User"); ?>
<?php if ($tab[$i]['source']=='external') echo $langs->trans("ThirdPartyContact"); ?>
</div>
<div class="tagtd left">
<?php
if ($tab[$i]['socid'] > 0)
{
$companystatic->fetch($tab[$i]['socid']);
echo $companystatic->getNomUrl(1);
$entry->thirdparty = $companystatic->getNomUrl(1);
}
if ($tab[$i]['socid'] < 0)
else if ($tab[$i]['socid'] < 0)
{
echo $conf->global->MAIN_INFO_SOCIETE_NOM;
$entry->thirdparty = $conf->global->MAIN_INFO_SOCIETE_NOM;
}
if (! $tab[$i]['socid'])
else if (! $tab[$i]['socid'])
{
echo '&nbsp;';
$entry->thirdparty = "";
}
?>
</div>
<div class="tagtd">
<?php
$statusofcontact = $tab[$i]['status'];
if ($tab[$i]['source']=='internal')
{
$userstatic->fetch($tab[$i]['id']);
echo $userstatic->getNomUrl(-1, '', 0, 0, 0, 0, '', 'valignmiddle');
$entry->contact = $userstatic->getNomUrl(-1, '', 0, 0, 0, 0, '', 'valignmiddle');
}
if ($tab[$i]['source']=='external')
else if ($tab[$i]['source']=='external')
{
$contactstatic->fetch($tab[$i]['id']);
echo $contactstatic->getNomUrl(1, '', 0, '', 0, 0);
$entry->contact =$contactstatic->getNomUrl(1, '', 0, '', 0, 0);
}
?>
</div>
<div class="tagtd"><?php echo $tab[$i]['libelle']; ?></div>
<div class="tagtd center">
<?php //if ($object->statut >= 0) echo '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=swapstatut&amp;ligne='.$tab[$i]['rowid'].'">';
if ($tab[$i]['source']=='internal')
{
echo $userstatic->LibStatut($tab[$i]['statuscontact'], 3);
$entry->status = $userstatic->LibStatut($tab[$i]['statuscontact'], 3);
}
if ($tab[$i]['source']=='external')
else if ($tab[$i]['source']=='external')
{
echo $contactstatic->LibStatut($tab[$i]['statuscontact'], 3);
$entry->status = $contactstatic->LibStatut($tab[$i]['statuscontact'], 3);
}
//if ($object->statut >= 0) echo '</a>'; ?>
</div>
<div class="tagtd nowrap right">
<?php if ($permission) { ?>
&nbsp;<a href="<?php echo $_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=deletecontact&amp;lineid='.$tab[$i]['rowid']; ?>"><?php echo img_picto($langs->trans('Unlink'), 'unlink'); ?></a>
<?php } ?>
</div>
</form>
<?php $i++;
$i++;
$list[] = $entry;
}
}
print "</div>\n";
print "</div>\n";
$sortfield = GETPOST("sortfield", "alpha");
$sortorder = GETPOST("sortorder", 'alpha');
if (!$sortfield) $sortfield = "nature";
if (!$sortorder) $sortorder = "asc";
/**
* Re-sort list
*/
// TODO: switch to $db->sort($sortfield, $sortorder);
if($sortorder == "asc")
{
if($sortfield == "nature") usort($list, "nature_asc");
if($sortfield == "thirdparty") usort($list, "thirdparty_asc");
if($sortfield == "contact") usort($list, "contact_asc");
if($sortfield == "type") usort($list, "type_asc");
if($sortfield == "status") usort($list, "status_asc");
}
else
{
if($sortfield == "nature") usort($list, "nature_desc");
if($sortfield == "thirdparty") usort($list, "thirdparty_desc");
if($sortfield == "contact") usort($list, "contact_desc");
if($sortfield == "type") usort($list, "type_desc");
if($sortfield == "status") usort($list, "status_desc");
}
$arrayfields = array(
'rowid' => array('label'=>$langs->trans("Id"), 'checked'=>1),
'nature' => array('label'=>$langs->trans("NatureOfContact"), 'checked'=>1),
'thirdparty' => array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
'contact' => array('label'=>$langs->trans("Users").'/'.$langs->trans("Contacts"), 'checked'=>1),
'type' => array('label'=>$langs->trans("ContactType"), 'checked'=>1),
'status' => array('label'=>$langs->trans("Status"), 'checked'=>1),
'link' => array('label'=>$langs->trans("Link"), 'checked'=>1),
);
$param = 'id='.$object->id.'&mainmenu=home';
/**
* Show list
*/
print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="action" value="list">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
print '<table class="tagtable nobottomiftotal liste">';
print '<tr class="liste_titre_filter">';
print '</tr>';
print '<tr class="liste_titre">';
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['type']['label'], $_SERVER["PHP_SELF"], "type", "", $param, "", $sortfield, $sortorder);
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 "</tr>";
foreach($list as $entry)
{
print '<tr class="oddeven">';
print '<td class="nowrap">'.$entry->nature.'</td>';
print '<td class="tdoverflowmax200">'.$entry->thirdparty.'</td>';
print '<td class="tdoverflowmax200">'.$entry->contact.'</td>';
print '<td class="tdoverflowmax200">'.$entry->type.'</td>';
print '<td class="tdoverflowmax200">'.$entry->status.'</td>';
if ($permission)
{
$href = $_SERVER["PHP_SELF"];
$href .= "?id=".$object->id;
$href .= "&action=deletecontact";
$href .= "&lineid=".$entry->id;
print "<td class='center'>";
print "<a href='$href'>";
print img_picto($langs->trans("Unlink"), "unlink");
print "</a>";
print "</td>";
}
print "</tr>";
}
print "</table>";
print "</div>";
print "</form>";
print "</div>";
print "<!-- TEMPLATE CONTACTS HOOK BEGIN HERE -->\n";
if (is_object($hookmanager)) {
$hookmanager->initHooks(array('contacttpl'));
@@ -248,3 +334,17 @@ if (is_object($hookmanager)) {
$reshook=$hookmanager->executeHooks('formContactTpl', $parameters, $object, $action);
}
print "<!-- END PHP TEMPLATE CONTACTS -->\n";
// TODO: Remove this functions after switch to $db->sort($sortfield, $sortorder);
function nature_asc($left, $right) { return $left->nature > $right->nature; }
function thirdparty_asc($left, $right) { return $left->thirdparty > $right->thirdparty; }
function contact_asc($left, $right) { return $left->contact > $right->contact; }
function type_asc($left, $right) { return $left->type > $right->type; }
function status_asc($left, $right) { return $left->status > $right->status; }
function nature_desc($left, $right) { return $left->nature < $right->nature; }
function thirdparty_desc($left, $right) { return $left->thirdparty < $right->thirdparty; }
function contact_desc($left, $right) { return $left->contact < $right->contact; }
function type_desc($left, $right) { return $left->type < $right->type; }
function status_desc($left, $right) { return $left->status < $right->status; }