<?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     function.tableSort.php
 * Type:     function
 * Name:     link
 * Purpose:  zwraca link do sortowania
 * -------------------------------------------------------------
 */


function smarty_function_tableSort($params, &$smarty){

    if(is_array($params)) {
        if(isset($params['title'])) {
            $title = $params['title'];
        } else {
            throw new Exception('Wymagany tytuł!');
        }

        if(isset($params['url'])) {
            $url = $params['url'];

        } else {
			$url = "_current";
            //throw new Exception('Wymagany url!');
        }

        if(isset($params['field'])) {
            $field = $params['field'];
        } else {
            throw new Exception('Wymagane pole!');
        }
		if(isset($params['sufix']))
			$sufix = $params['sufix'];
		else
			$sufix = null;
		
		if($smarty->get_template_vars($field. $sufix) == "desc")
			$direction = "asc";
		else
			$direction = "desc";

			
        $return = "<a href=\"";
		if($url == "_current")
			$return .= Router::GenerateUrl( "sort$sufix" ,array('_current'=>true, "sort$sufix" => $field, "direction$sufix" => $direction));
		else
			$return .= Router::GenerateUrl( "sort" ,array('_value'=>$url));

        $return .= "\">";
        if($smarty->get_template_vars($field. $sufix) == "desc") {
            $return .= '<img alt="" border="0" height="8" src="' . URL_STATIC_CONTENT . '/image/Admin/arrowsdownsel.gif" width="14" /> ';
        } else if($smarty->get_template_vars($field. $sufix) == "asc") {
			$return .= '<img alt="" border="0" height="8" src="' . URL_STATIC_CONTENT . '/image/Admin/arrowsupsel.gif" width="14" /> ';
        }
		else if($smarty->get_template_vars($field. $sufix) == "")
            $return .= '<img alt="" border="0" height="8" src="' . URL_STATIC_CONTENT . '/image/Admin/arrowsdesel.gif" width="14" /> ';
 $return .= "</a>";

//        if($smarty->get_template_vars($field . $sufix)) {
//            $return .= " ";
//        }
        $return .= $title;
//        if($smarty->get_template_vars($field. $sufix)) {
//            $return .= " ";
//        }


       

} else {
        throw new Exception('Podaj parametry!');
    }
    return $return;
}
?>