1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8//this script may only be included - so its better to die if called directly.
9if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
10	header("location: index.php");
11	exit;
12}
13
14function smarty_function_show_sort($params, $smarty)
15{
16	global $url_path;
17
18	if (isset($_REQUEST[$params['sort']])) {
19		$p = $_REQUEST[$params['sort']];
20	} elseif ($s = $smarty->getTemplateVars($params['sort'])) {
21		$p = $s;
22	}
23
24	if (isset($params['sort']) and isset($params['var']) and isset($p)) {
25		$prop = substr($p, 0, strrpos($p, '_'));
26		$order = substr($p, strrpos($p, '_') + 1);
27
28		if (strtolower($prop) == strtolower(trim($params['var']))) {
29			$smarty->loadPlugin('smarty_function_icon');
30
31			switch ($order) {
32				case 'asc':
33				case 'nasc':
34					return ' ' . smarty_function_icon(['name' => 'sort-up'], $smarty);
35				case 'desc':
36				case 'ndesc':
37					return ' ' . smarty_function_icon(['name' => 'sort-down'], $smarty);
38			}
39		}
40	}
41}
42