<?php

// +----------------------------------------------------------------------+
// | OpenConf                                                             |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2016 Zakon Group LLC.  All Rights Reserved.       |
// +----------------------------------------------------------------------+
// | This source file is subject to the OpenConf License, available on    |
// | the OpenConf web site: www.OpenConf.com                              |
// +----------------------------------------------------------------------+

require_once "../include.php";

beginChairSession();

printHeader("Files Directory",1);

$skipAR = array('.','..','index.html','.htaccess');

$dir = $OC_configAR['OC_paperDir'];
$linkParams = 'c=1';

if (oc_hookSet('chair-list_files-preprocess')) {
	foreach ($GLOBALS['OC_hooksAR']['chair-list_files-preprocess'] as $hook) {
		require_once $hook;
	}
}
	
if ($pdh = opendir($dir)) {
	$fAR = array();
	while(($f = readdir($pdh)) !== false) {
		if (is_file($dir.$f) && !in_array($f,$skipAR)) {
			$fAR[$f] = oc_fileMtime($dir.$f);
		}
	}
	closedir($pdh);

	if (oc_hookSet('chair-list_files')) {
		foreach ($GLOBALS['OC_hooksAR']['chair-list_files'] as $hook) {
			require_once $hook;
		}
	}
	
	if (count($fAR) > 0) {
		if (isset($_GET['s']) && ($_GET['s'] == 'date')) {
			$dsort = 'Last Updated<br />' . $OC_sortImg;
			$fsort = '<a href="' . $_SERVER['PHP_SELF'] . '?s=file' . ((isset($_GET['oc_multifile_type']) && ctype_digit($_GET['oc_multifile_type'])) ? ('&oc_multifile_type=' . urlencode($_GET['oc_multifile_type'])) : '') . '">File</a>';
			arsort($fAR,SORT_NUMERIC);
		} else {
			$fsort = 'File<br />' . $OC_sortImg;
			$dsort = '<a href="' . $_SERVER['PHP_SELF'] . '?s=date' . ((isset($_GET['oc_multifile_type']) && ctype_digit($_GET['oc_multifile_type'])) ? ('&oc_multifile_type=' . urlencode($_GET['oc_multifile_type'])) : '') . '">Last Updated</a>';
			ksort($fAR,SORT_NUMERIC);
		}
		
		print '<div style="text-align: center; width: 150px; margin: 1em auto;"><table border="0" cellspacing="0" cellpadding="0"><tr><td style="padding-right: 20px;"><a href="download.php?t=' . ((isset($_GET['oc_multifile_type']) && ctype_digit($_GET['oc_multifile_type'])) ? urlencode($_GET['oc_multifile_type']) : 1) . '"><img src="../images/documentmulti-sm.gif" width="17" height="20" alt="icon" border="0" /><br />ZIP<br />all&nbsp;files</a></td><td style="padding-left: 20px;"><a href="download.php?t=' . ((isset($_GET['oc_multifile_type']) && ctype_digit($_GET['oc_multifile_type'])) ? urlencode($_GET['oc_multifile_type']) : 1) . '&acc=1"><img src="../images/documentmulti-sm.gif" width="17" height="20" alt="icon" border="0" /><br />ZIP<br />accepted&nbsp;only</a></td></tr></table></div>';
		
		print '<table border="0" cellspacing="1" cellpadding="4" style="margin: 0 auto;"><tr class="rowheader"><th>' . $fsort . '</th><th>Size</th><th>' . $dsort . '</th></tr>';
		$row = 1;
		foreach ($fAR as $f => $d) {
			print '<tr class="row' . $row . '"><td><a href="../review/paper.php?' . $linkParams . '&p=' . urlencode($f) . '" target="paper">' . urlencode($f) . '</a></td><td align="right">' . safeHTMLstr(oc_formatNumber(oc_fileSize($dir.$f))) . '</td><td>' . safeHTMLstr(date("d M Y H:i:s", $d)) . "</td></tr>\n";
			$row = $rowAR[$row];
		}
		print "</table>\n";
	} else { // 0 files
		print '<p style="text-align: center;"><span class="warn">No files found</span></p>';
	}
} else {
	print '<p class="warn">Unable to open files directory</p>';
}

printFooter();

?>