<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script>
<link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" />
<link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/file.css')?>" />
<link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/font-awesome.min.css')?>" />

<script type="text/javascript" src="<?php print base_url_make('/js/jquery.min.js')?>"></script>
<script type="text/javascript" src="<?php print base_url_make('/js/jquery-ui.min.js')?>"></script>
<link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/jquery-ui.css')?>" />

<title><?php print htmlspecialchars($project->name)?></title>
</head>

<body>

<div class="content" id="file_home_content">

<!-- ============================================================ -->

<?php $this->load->view ('taskbar'); ?>

<!-- ============================================================ -->

<?php
$this->load->view (
	'projectbar',
	array (
		'banner' => NULL,

		'page' => array (
			'type' => 'project',
			'id' => 'file',
			'project' => $project,
		),

		'ctxmenuitems' => array (
			array ("file/create/{$project->id}", '<i class="fa fa-plus"></i> ' . $this->lang->line('New')) 
		)
	)
);
?>

<!-- ============================================================ -->

<div class="mainarea" id="file_home_mainarea">
<div class="title"><?php print $this->lang->line('Files')?></div>

<div class="result" id="file_home_mainarea_result">
<?php
if (empty($files))
{
	print htmlspecialchars($this->lang->line('FILE_MSG_NO_FILES_AVAILABLE'));
}
else
{
	function comp_tag ($a, $b)
	{
		//$x = explode ('.', $a);
		//$y = explode ('.', $b);
		$x = explode ('.', str_replace('-', '.', $a));
		$y = explode ('.', str_replace('-', '.', $b));
		$cx = count($x);
		$cy = count($y);
		$min = min($cx, $cy);

		for ($i = 0; $i < $min; $i++)
		{
			if (is_numeric($x[$i]) && is_numeric($y[$i]))
			{
				$q = (int)$x[$i] - (int)$y[$i];
			}
			else
			{
				$q = strcmp($x[$i], $y[$i]);
			}
			if ($q != 0) return $q;
		}

		return ($cx > $cy)? -1:
		       ($cx < $cy)? 1: 0;
	}

	function comp_files ($a, $b)
	{
		//$cmp = version_compare ($b->tag, $a->tag);
		$cmp = comp_tag ($b->tag, $a->tag);
		if ($cmp == 0)
		{
			$cmp = strcmp ($a->name, $b->name);
		}
		return $cmp;
	}

	usort ($files, 'comp_files');

	//$download_anchor_text = '<i class="fa fa-download"></i> ' . $this->lang->line('Download');
	$download_anchor_text = '<i class="fa fa-download"></i>';

	print '<table id="file_home_mainarea_result_table" class="fit-width-result-table">';
	print '<tr class="heading">';
	print '<th>' . $this->lang->line('Tag') . '</th>';
	print '<th colspan=2>' . $this->lang->line('Name') . '</th>';
	print '<th>' . $this->lang->line('Summary') . '</th>';
	print '<th>' . $this->lang->line('MD5') . '</th>';
	//print '<th>' . $this->lang->line('Download') . '</th>';
	print '</tr>';
	
	$oldtag = '';
	$rownum = 0;
	$rowclasses = array ('odd', 'even');
	foreach ($files as $file) 
	{
		$hexname = $this->converter->AsciiToHex ($file->name);
		$rowclass = $rowclasses[$rownum++ % 2];
		print "<tr class='{$rowclass}'>";
		print '<td>';
		if ($file->tag != $oldtag)
		{
			print htmlspecialchars($file->tag);
			$oldtag = $file->tag;
		}
		print '</td>';
		print '<td>';
		print anchor ("file/show/{$project->id}/{$hexname}", htmlspecialchars($file->name));
		print '</td>';
		print '<td>';
		print anchor ("file/get/{$project->id}/{$hexname}", $download_anchor_text);
		print '</td>';
		print '<td>';
		print htmlspecialchars($file->summary);
		print '</td>';
		print '<td><tt>';
		print $file->md5sum;
		print '</tt></td>';
		print '</tr>';
	}
	print '</table>';
}
?>
</div>
</div> <!-- file_home_mainarea -->

<div class='footer-pusher'></div> <!-- for sticky footer -->

</div> <!-- file_home_content -->

<!-- ============================================================ -->

<?php $this->load->view ('footer'); ?>

<!-- ============================================================ -->


</body>
</html>
