<?php

/**
 *
 * @author François Guenot <fguenot@waterproof.fr>
 * @copyright WaterProof (c)
 * @date 29/04/2009
 * @update
 */
use_helper('Form');

/**
 * end_form()
 *
 * @param string $submit_value
 * @return end of a <form>
 */

function end_form($submit_value) {
    $end_form = submit_tag($submit_value);
    $end_form .= '</form>';
    return $end_form;
}

function pager($pager, $link, $type = '') {
    $result = '<div id="list-footer">';

    if ('' != $type) {
        $result .= '<div id="persistence-manager">';
        $result .= sprintf('Sélectionnés : %s <a href="javascript://" onclick="cleanSelection(\'' . $type . '\', \'' . $type . '-count\');">[vider la sélection]</a>', multiple_action_info_selected($type));
        $result .= '</div>';
    }

    if ($pager->haveToPaginate()) {
        $result .= '<div id="pager">';

        if ($pager->getFirstPage() < $pager->getPage()) {
            $result .= catalyz_link_to_image_tag($link . '&page=' . $pager->getFirstPage(), 'pager-first.png', array('title' => 'Première page'), array('align' => 'top', 'alt' => ''));
            $result .= catalyz_link_to_image_tag($link . '&page=' . $pager->getPreviousPage(), 'pager-previous.png', array('title' => 'Page précédente'), array('align' => 'top', 'alt' => ''));
            $result .= '&nbsp;';
        }

        foreach ($pager->getLinks(5) as $page) {
            if ($page == $pager->getPage()) {
                $result .= '<span style="color:#F26513">' . $page . '</span>';
            } else {
                $result .= link_to($page, $link . '&page=' . $page, 'class=pages');
            }
            $result .= '&nbsp;';
        }

        if ($pager->getPage() < $pager->getLastPage()) {
            $result .= catalyz_link_to_image_tag($link . '&page=' . $pager->getNextPage(), 'pager-next.png', array('title' => 'Page suivante'), array('align' => 'top', 'alt' => ''));
            $result .= catalyz_link_to_image_tag($link . '&page=' . $pager->getLastPage(), 'pager-last.png', array('title' => 'Dernière page'), array('align' => 'top', 'alt' => ''));
        }

        $result .= '</div>';
    }

    $result .= '</div>';

    return $result;
}

function sort_links($sf_request, $field_name, $url, $params = array()) {
    $result = '';
    $listParam = '';
    if (!empty($params)) {
        foreach($params as $name => $param) {
            $listParam .= '&' . $name . '=' . $param;
        }
        if ($field_name == $sf_request->getParameter('sort')) {
            if ($sf_request->hasParameter('desc')) {
                // $result .= link_to_image_tag($url . '?sort=' . $field_name . $listParam, 'layout/asc.png');
                $result .= link_to('&nbsp;&darr;&nbsp;', $url . '?sort=' . $field_name . $listParam, array('style' => 'text-decoration:none'));
                // $result .= image_tag('layout/desc-active.png');
            } else {
                // $result .= image_tag('layout/asc-active.png');
                // $result .= link_to_image_tag($url . '?sort=' . $field_name . '&desc=on' . $listParam, 'layout/desc.png');
                $result .= link_to('&nbsp;&uarr;&nbsp;', $url . '?sort=' . $field_name . '&desc=on' . $listParam, array('style' => 'text-decoration:none'));
            }
        } else {
            // $result .= link_to_image_tag($url . '?sort=' . $field_name . $listParam, 'layout/asc.png');
            $result .= link_to('&nbsp;&darr;&nbsp;', $url . '?sort=' . $field_name . $listParam, array('style' => 'text-decoration:none'));
            // $result .= link_to_image_tag($url . '?sort=' . $field_name . '&desc=on' . $listParam, 'layout/desc.png');
            $result .= link_to('&nbsp;&uarr;&nbsp;', $url . '?sort=' . $field_name . '&desc=on' . $listParam, array('style' => 'text-decoration:none'));
        }
    } else {
        if ($field_name == $sf_request->getParameter('sort')) {
            if ($sf_request->hasParameter('desc')) {
                $result .= link_to('&nbsp;&darr;&nbsp;', $url . '?sort=' . $field_name, array('style' => 'text-decoration:none'));
                // $result .= link_to_image_tag($url . '?sort=' . $field_name, 'layout/asc.png');
                // $result .= image_tag('layout/desc-active.png');
            } else {
                $result .= link_to('&nbsp;&uarr;&nbsp;', $url . '?sort=' . $field_name . '&desc=on', array('style' => 'text-decoration:none'));
                // $result .= image_tag('layout/asc-active.png');
                // $result .= link_to_image_tag($url . '?sort=' . $field_name . '&desc=on', 'layout/desc.png');
            }
        } else {
            $result .= link_to('&nbsp;&darr;&nbsp;', $url . '?sort=' . $field_name, array('style' => 'text-decoration:none'));
            $result .= link_to('&nbsp;&uarr;&nbsp;', $url . '?sort=' . $field_name . '&desc=on', array('style' => 'text-decoration:none'));
            // $result .= link_to_image_tag($url . '?sort=' . $field_name, 'layout/asc.png');
            // $result .= link_to_image_tag($url . '?sort=' . $field_name . '&desc=on', 'layout/desc.png');
        }
    }
    return $result;
}

?>