<?php require($_SERVER['DOCUMENT_ROOT'] . '/admin/inc/sessionStart.php'); ?>
<h3 class="centerText">Select a file to get more options</h3>
<?php
//
// jQuery File Tree PHP Connector
//
// Version 1.01
//
// Cory S.N. LaViska
// A Beautiful Site (http://abeautifulsite.net/)
// 24 March 2008
//
// History:
//
// 1.01 - updated to work with foreign characters in directory/file names (12 April 2008)
// 1.00 - released (24 March 2008)
//
// Output a list of files for jQuery File Tree
//

$_POST['dir'] = urldecode($_POST['dir']);
$root = $_SERVER['DOCUMENT_ROOT'] . "/";


if( file_exists($root . $_POST['dir']) ) {
	$files = scandir($root . $_POST['dir']);
	natcasesort($files);
	if( count($files) > 2 ) { /* The 2 accounts for . and .. */
		
		// All files
		foreach( $files as $file ) {
			/*
			echo $file;
			echo "<br>";
			echo file_exists($root . $_POST['dir'] . $file) ? "true" : "false";
			echo "<br>";
			echo $file != '.' ? "true" : "false";;
			echo "<br>";
			echo $file != '..' ? "true" : "false";;
			echo "<br>";
			echo !is_dir($root . $_POST['dir'] . $file) ? "true" : "false";
			echo "<br><br><br>";
			*/
							 
			if( file_exists($root . $_POST['dir'] . $file) && $file != '.' && $file != '..' && !is_dir($root . $_POST['dir'] . $file) ) {
				$ext = preg_replace('/^.*\./', '', $file);
?>
				<div class="aFile">
					<?php
						$thePic = "/" . $_POST['dir'] . $file;
						if($ext == "pdf"){
							$thePic = "css/images/pdf.png";
						}
					?>
					<div class="imgWrap">
						<img src="<?php echo $thePic ?>">
					</div>
					<p><a href="#" rel="<?php echo htmlentities($_POST['dir'] . $file); ?>"><?php echo htmlentities($file); ?></a></p>
				</div>
<?php
				//echo "<li class=\"file ext_$ext\"><a href=\"#\" rel=\"" . htmlentities($_POST['dir'] . $file) . "\">" . htmlentities($file) . "</a></li>";
			}
		}
	}
}
?>