function formatColumnHeaders($columns, $sort_by, $sort_dir, $view)
{
/* Get the current url, remove any sorting parameters. */
$url = Horde::selfUrl(true)->remove(array($view . '_sortby', $view . '_sortdir'));
/* Go through the column headers to format and add sorting links. */
$headers = array();
foreach ($columns as $col_name => $col_title) {
$extra = array();
/* Is this a column with two headers? */
if (is_array($col_title)) {
$keys = array_keys($col_title);
$extra_name = $keys[0];
if ($sort_by == $keys[1]) {
$extra = array($keys[0] => $col_title[$keys[0]]);
$col_name = $keys[1];
$col_title = $col_title[$keys[1]];
} else {
$extra = array($keys[1] => $col_title[$keys[1]]);
$col_name = $keys[0];
$col_title = $col_title[$keys[0]];
}
}
if ($sort_by == $col_name) {
/* This column is currently sorted by, plain title and
* add sort direction arrow. */
$sort_img = $sort_dir ? 'za.png' : 'az.png';
$sort_title = $sort_dir ? _("Sort Ascending") : _("Sort Descending");
$col_arrow = Horde::link($url->add(array($view . '_sortby' => $col_name, $view . '_sortdir' => $sort_dir ? 0 : 1)), $sort_title) . Horde::img($sort_img, $sort_title) . '</a> ';
$col_class = 'selected';
} else {
/* Column not currently sorted, add link to sort by
* this one and no sort arrow. */
$col_arrow = '';
$col_title = Horde::link($url->add($view . '_sortby', $col_name), sprintf(_("Sort by %s"), $col_title)) . $col_title . '</a>';
$col_class = 'item';
}
$col_class .= ' leftAlign';
if (count($extra)) {
list($name, $title) = each($extra);
$col_title .= ' <small>[' . Horde::link($url->add($view . '_sortby', $name), sprintf(_("Sort by %s"), $title)) . $title . '</a>' . ']</small>';
$col_name = $extra_name;
}
$headers[$col_name] = $col_arrow . $col_title;
$headers[$col_name . '_class_plain'] = $col_class;
$headers[$col_name . '_class'] = empty($col_class) ? '' : ' class="' . $col_class . '"';
}
return $headers;
}