<?php

########################################
#This  comes with absolutley NO WARRENTY and I assume NO RESPONSABILITY if this does any damage to any #system running it.
#
#This code is released under gnu.
#
#By [NICK] http://www.linickx.com
#
#Further info about this project/code might be avilable at http://www.linickx.com
#
####################################
#
#Copyright: 2005
#
#This program is free software; you can redistribute it and/or modify 
#it under the terms of the GNU General Public License as published by 
#the Free Software Foundation; either version 2 of the License, or 
#(at your option) any later version
#
#This program is distributed in the hope that it will be useful, but
#WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#General Public License for more details.
#
#You should have received a copy of the GNU General Public License with
#this program.  If not, write to the Free Software Foundation, Inc., 675
#Mass Ave, Cambridge, MA 02139, USA.
#
# or http://www.linickx.com (I will always keep a copy there !)
#########################################################################


#~#~#~##~#~#~##~#~#~##~#~#~##~#~#~##~#~#~##~#~#~##~#~#~##~#~#~##~#~#~##~#~#~#
# If you want these, uncomment them !
#$USERBROWSING=true;
# User Browsing allows the page viewer to decide which directory to select files from
#$STARTDIRECTORY="/etc";
# This is the default directory the "browser" loads
#~#~#~##~#~#~##~#~#~##~#~#~##~#~#~##~#~#~##~#~#~##~#~#~##~#~#~##~#~#~##~#~#~#

############################################################
# I wouldn't edit below here unless you're really bored !! #
############################################################

$self=$_SERVER["PHP_SELF"];
if ($USERBROWSING) {
?>
<div align=center>
<form enctype="multipart/form-data" action="<?php echo "$self"; ?>" method="POST" >
Path: <input type="text" name="path">
<input type="submit" value="Refresh"> 
</form>
</div>
<?php
}

# OK... How are we called _GET or _POST

if ( $_GET['path'] != "" ) {
	$wewozgot = true;
}

if ( $_POST['path'] != "" ) {
	$wewozpost = true;
}


if ( $wewozgot) { 
	$path=$_GET['path'];
} elseif ( $wewozpost) {
	$path=$_POST['path'];
} elseif ( $STARTDIRECTORY != "") {
	# IF Start Dir is set, use it ;-)
	$path=$STARTDIRECTORY;
} else {
	$path="./";
}



function backbutton() {

?>
<!-- Java Script Back Button -->
<a href="javascript:history.go(-1)" onMouseOver="self.status=document.referrer;return true">BACK</a>

<?php
}
if ( $path == "" ) {
	$path ="./";
}

#Clean up path
$path = trim($path);

#Check for trailing slashes
$pathlength = strlen($path);
$pathlength = $pathlength - 1;
$lastchar = substr("$path", $pathlength, 1);

if ( $lastchar != "/") {
	$path = "$path/";
}

if (is_dir($path)) {
backbutton();
?>
<form enctype="multipart/form-data" action="./view_file.php" method="POST" >
<ul>
<?php
   if ($dh = opendir($path)) {
       while (($file = readdir($dh)) !== false) {
		$firstchar = substr($file,0,1);
		if ( $firstchar !== "." ) {
			?><li><?php
			if (is_dir("$path$file")) {
				?>
				<A href="<?php echo "$self?path=$path/$file/" ;?>">[<?php echo $file; ?>]</A>
			<?php
			} else {
			?>
				<input type="checkbox" name="mpeg[]" value="<?php echo $file;?>" />
				<A href="<?php echo "$path$file"; ?>"><?php echo $file ;?></A><br>
			<?php
			}
			?></li><?php
		}
       }
       closedir($dh);
   }
?>
</ul>
<?php
}
?>
<input type=hidden name="path" value="<?php echo "$path"; ?>" />
<input type="submit" value="Submit">
