$_SESSION["download_sort_reverse"] = 0;
    } else {
        if ($HTTP_GET_VARS["sort"] != '') {
            $_SESSION["download_sort_reverse"] = !$_SESSION["download_sort_reverse"];
        }
    }
}
//var_dump($_SESSION);
$sort_reverse = $_SESSION["download_sort_reverse"];
if ($sort_order != "") {
    $_SESSION["download_sort"] = $sort_order;
    usort(&$downloads, "my_cmp");
}
//
// Prepare categories index array
$cats = amule_get_categories();
foreach ($cats as $i => $c) {
    $cat_idx[$c] = $i;
}
foreach ($downloads as $file) {
    $filter_status_result = $_SESSION["filter_status"] == "all" or $_SESSION["filter_status"] == StatusString($file);
    $filter_cat_result = $_SESSION["filter_cat"] == "all" or $cat_idx[$_SESSION["filter_cat"]] == $file->category;
    if ($filter_status_result and $filter_cat_result) {
        print "<tr>";
        echo "<td class='texte' height='22'>", '<input type="checkbox" name="', $file->hash, '" >', "</td>";
        echo "<td class='texte' height='22'>", $file->short_name, "</td>";
        echo "<td class='texte' height='22' align='center'>", CastToXBytes($file->size), "</td>";
        echo "<td class='texte' height='22' align='center'>", CastToXBytes($file->size_done), "&nbsp;(", (double) $file->size_done * 100 / (double) $file->size, "%)</td>";
        echo "<td class='texte' height='22' align='center'>", $file->speed > 0 ? CastToXBytes($file->speed) . "/s" : "-", "</td>";
        echo "<td class='texte' height='22' align='center' align='center'>", $file->progress, "</td>";
        echo "<td class='texte' height='22' align='center'>";
function cat2idx($cat)
{
    $cats = amule_get_categories();
    $result = 0;
    foreach ($cats as $i => $c) {
        if ($cat == $c) {
            $result = $i;
        }
    }
    return $result;
}