function smarty_function_select_domains($params, &$smarty)
{
    $userdomain = User::getDomainFromCookie();
    $res = XDB::iterRow("SELECT  f.domain\n                           FROM  formations AS f\n                      LEFT JOIN  studies AS s ON s.formation_id = f.formation_id\n                       GROUP BY  f.domain\n                       ORDER BY  COUNT(f.domain) DESC");
    $sel = ' selected="selected"';
    $html = "";
    while (list($domain) = $res->next()) {
        $isSelected = $userdomain == $domain ? $sel : "";
        $html .= '<option value="' . $domain . '"' . $isSelected . '>' . $domain . '</option>' . "\n";
    }
    return $html;
}