<?php
/*
 * Copyright (c) 2013, webvariants GbR, http://www.webvariants.de
 *
 * This file is released under the terms of the MIT license. You can find the
 * complete text in the attached LICENSE file or online at:
 *
 * http://www.opensource.org/licenses/mit-license.php
 */

if (!isset($this->htmlAttributes['class'])) {
	$this->htmlAttributes['class'] = '';
}

$isIcon = strpos($this->htmlAttributes['class'], 'sly-icon') !== false;
$left   = '';
$right  = '';

if (!$isIcon && $table->isSorting() && !$table->hasDragAndDrop() && !empty($this->sortkey)) {
	$params = $_GET;
	$id     = $table->getID();
	unset($params[$id.'_sortby'], $params[$id.'_direction']);

	$params[$id.'_sortby'] = $this->sortkey;

	switch ($this->direction) {
		case 'asc':
			$params[$id.'_direction'] = 'desc';
			$left  = '<a href="index.php?'.http_build_query($params, '', '&amp;').'" class="sort asc" title="'.t('sort_asc').'">';
			$right = '</a>';
			break;

		case 'desc':
			$params[$id.'_direction'] = 'asc';
			$left  = '<a href="index.php?'.http_build_query($params, '', '&amp;').'" class="sort desc" title="'.t('sort_desc').'">';
			$right = '</a>';
			break;

		case 'none':
		default:
			$params[$id.'_direction'] = 'asc';
			$left  = '<a href="index.php?'.http_build_query($params, '', '&amp;').'" class="sort nosort" title="'.t('sort_none').'">';
			$right = '</a>';
			break;
	}

	$this->htmlAttributes['class'] .= ' has-sort-icon';
}

$this->htmlAttributes['class'] .= ' sly-col-'.chr(97 + $index);

$attribs = sly_Util_HTML::buildAttributeString($this->htmlAttributes);
$content = $left.$this->content.$right;

?>
<th <?php echo $attribs ?>><?php echo $content ?></th>
