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_initials_filter_links($params, $smarty)
15{
16	$html = '';
17	$sep = ' . ';
18	$default_type = 'absolute_path';
19	if (! isset($params['_initial'])) {
20		$params['_initial'] = 'initial';
21	}
22	$current_initial = isset($_REQUEST[$params['_initial']]) ? $_REQUEST[$params['_initial']] : '';
23	if (! isset($params['_htmlelement'])) {
24		$params['_htmlelement'] = 'tiki-center';
25	}
26	if (! isset($params['_template'])) {
27		$params['_template'] = basename($_SERVER['PHP_SELF'], '.php') . '.tpl';
28	}
29	if (! isset($params['_class'])) {
30		$params['_class'] = 'prevnext';
31	}
32
33	// Include smarty functions used below
34	$smarty = TikiLib::lib('smarty');
35	$smarty->loadPlugin('smarty_block_ajax_href');
36	$smarty->loadPlugin('smarty_function_query');
37
38	$tag_start = "\n" . '<a class="' . $params['_class'] . '" ' . smarty_block_ajax_href(
39		['template' => $params['_template'], 'htmlelement' => $params['_htmlelement']],
40		smarty_function_query(
41			[
42				'_type' => $default_type,
43				$params['_initial'] => 'X',
44				'offset' => 'NULL',
45				'reloff' => 'NULL'
46			],
47			$smarty
48		),
49		$smarty,
50		false
51	) . '>';
52
53	$alpha = explode(',', tra('a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z'));
54	foreach ($alpha as $i) {
55		if ($current_initial == $i) {
56			$html .= "\n" . '<span class="highlight">' . strtoupper($i) . '</span>' . $sep;
57		} else {
58			$html .= "\n" . str_replace($params['_initial'] . '=X', $params['_initial'] . '=' . $i, $tag_start) . strtoupper($i) . '</a>' . $sep;
59		}
60	}
61	$html .= "\n" . str_replace($params['_initial'] . '=X', $params['_initial'] . '=', $tag_start) . tra('All') . '</a>';
62
63	return '<div class="alphafilter">' . $html . '</div>';
64}
65