<?php
/**
 * display_list_view.php - View file for rendering the display_list. Previous programmers didn't know how to
 * 								make this generic and instead made multiple copies of this code. Have to fix it later...
 *
 * @author $Author: dtong $
 * @version $Id: display_list_view.php,v 1.9 2011/05/09 08:03:10 dtong Exp $
 * @copyright Copyright (c) 2010, Tiller Software Co., Ltd.
*/
if ( isset($display) && is_object($display) ) {
	$sortup_url   = osa_imagepath() . 'arrow_up.gif';
	$sortdown_url = osa_imagepath() . 'arrow_down.gif';
	//$update_url   = base_url().'search/sort/get/sort/';
	$display->reset();
	//This is for the sort cilumn links
   $refresh_divid = $display->sort_refresh_divid;
?>
<div id="<?php echo $refresh_divid?>" style="margin:0px;padding:0px">
	<?php if ($display->use_div_table) {?>
	<div style="display:table" class="map_restab">
		<div style="display:table-row" class="<?php echo $display->cssclass_titlerow?>">
	<?php } else { ?>
	<table class="map_restab">
		<tr class="<?php echo $display->cssclass_titlerow?>">
	<?php }
	$tdwidths = array();
	foreach ($display->titles as $key=>$title) {
		$width = $display->widths[$key];
		if ( $width != '' ) {
			$width = "width=\"{$width}\"";
		}
		else {
			$width='';
		}
		$tdwidths[$key] = $width;
		$has_tagpos = strpos($title, '<');
      if ( ($has_tagpos !== FALSE && $has_tagpos <= 1) || $display->total <= 1 ) {
      	//If we find a open tag on the title then it means it is a link and should not add the sort code
      	$sort = $title;
      }
      else {
      	//Normal title so add the sort code
      	$url = base_url() . "search/table/index/{$display->divid}/$key/$display->sort_direction";
			$click = "onClick=\"ajaxGetpage('$refresh_divid','$url',false);return false;\"";
			$imgsrc  = $sortdown_url;
			if ($display->sort_direction == 0) {
				$imgsrc  = $sortup_url;
			}
			$img  = '';
			if ($display->default_col==$key)
				$img = "<img src='$imgsrc' class='searchsort_button_image' title='sort' />";
			if ( $display->title_nobr === TRUE )
				$sort = "<a title='sort' href='$url' $click><nobr>$title $img</nobr></a>";
			else
				$sort = "<a title='sort' href='$url' $click>$title $img</a>";

			if ( !$display->sort_columns ) {
				$sort = $title;
			}
      }

		if ( $display->use_div_table )
			echo "<div style=\"display:table-cell;width:{$display->widths[$key]}\" class=\"map_restitle\">$sort</div>";
		else
			echo "<td {$width} class=\"map_restitle\">$sort</td>";
	}
	if ( $display->use_div_table )
		echo "</div>";
	else
		echo "</tr>";

	$colortrack=FALSE;
	$trclass = $trclass1 = $display->cssclass_datarow1;
	$trclass2 = $display->cssclass_datarow2;
	while ( ($node = $display->next()) !== FALSE)  {
		if ( $display->colortrack ) {
			if (!$colortrack)
				$trclass = $trclass1;
			else
				$trclass = $trclass2;
			$colortrack = !$colortrack;
		}
		if ( $display->use_div_table )
			echo "<div style=\"display:table-row\" class=\"$trclass\">";
		else
			echo "<tr class=\"$trclass\">";
		foreach ($node as $key=>$value) {
			$temp = htmlspecialchars_decode($value);
			$text_alignment = 'left';
			if ( array_key_exists($key, $display->column_data_align) ) {
				if ( $display->column_data_align[$key] == 'center' || $display->column_data_align[$key] == 'right' ) {
					$text_alignment = $display->column_data_align[$key];
				}
			}
			if ( $display->use_div_table ) {
				echo "<div style=\"display:table-cell;vertical-align:top;width:{$display->widths[$key]};text-align:{$text_alignment}\" class=\"map_resitem\">$temp</div>";
			}
			else {
				if ( $display->col_align_top === TRUE )
					echo "<td {$tdwidths[$key]} class='map_resitem' valign='top' style='text-align:{$text_alignment}'>$temp</td>";
				else
					echo "<td {$tdwidths[$key]} class='map_resitem' style='text-align:{$text_alignment}'>$temp</td>";
			}
		}
		if ( $display->use_div_table )
			echo '</div>';
		else
			echo '</tr>';
	} //while
	if ( $display->use_div_table )
		echo '</div>';
	else
		echo '</table>';
?>
</div>
<?php } //if ( isset($display) && is_object($display) )?>