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
14/* params
15   level: level of tag <h>
16   title: title of the <h>
17   toggle: o for open, c for close
18   inTable: table class in a table otherwise will insert div
19*/
20function smarty_function_trackerheader($params, $smarty)
21{
22	global $prefs;
23	$headerlib = TikiLib::lib('header');
24	$output = $js = '';
25	static $trackerheaderStack = [];
26	static $iTrackerHeader = 0;
27	$last = count($trackerheaderStack);
28	$default = ['level' => 3, 'inTable' => ''];
29	$params = array_merge($default, $params);
30	extract($params, EXTR_SKIP);
31
32	if (! empty($inTable)) {
33		$output .= '</table>';
34	}
35	while (! empty($last) && $level <= $trackerheaderStack[$last - 1]) { // need to close block
36		$output .= "</div>";
37		array_pop($trackerheaderStack);
38		--$last;
39	}
40	if (! empty($title)) { // new header
41		array_push($trackerheaderStack, $level);
42		$output .= "<!--PUSH" . count($trackerheaderStack) . " -->";
43		$id = "trackerHeader_$iTrackerHeader";
44		$div_id = "block_$id";
45		$output .= "<h$level id=\"$id\"";
46		if ($prefs['javascript_enabled'] == 'y' && ($toggle == 'o' || $toggle == 'c')) {
47			$output .= ' class="' . ($toggle == 'c' ? 'trackerHeaderClose' : 'trackerHeaderOpen') . '"';
48		}
49		$output .= '>';
50		$output .= "$title";
51		$output .= "</h$level>";
52		if ($prefs['javascript_enabled'] == 'y' && ($toggle == 'o' || $toggle == 'c')) {
53			$js = "\$('#$id').click(function(event){";
54			$js .= "\$('#$div_id').toggle();";
55			$js .= "\$('#$id').toggleClass('trackerHeaderClose');";
56			$js .= "\$('#$id').toggleClass('trackerHeaderOpen');";
57			$js .= "});";
58			$headerlib->add_jq_onready($js);
59			if ($toggle == 'c') {
60				$headerlib->add_jq_onready("\$('#$div_id').hide();");
61			}
62		}
63		$output .= '<';
64		$output .= (isset($inTable) && $inTable == 'y') ? 'tbody' : 'div';
65		$output .= " id=\"$div_id\">";
66		++$iTrackerHeader;
67	} else {
68		$last = 0;
69		$trackerheaderStack = [];
70	}
71	if (! empty($inTable)) {
72		$output .= "<table class=\"$inTable\">";
73	}
74	return $output;
75}
76