<?php

// include my functions
require_once ("functions.php");

if (session_id() == "")
	session_start();

?>

<?php
/*
Directory Listing Script - Version 2
====================================
Script Author: Ash Young <ash@evoluted.net>. www.evoluted.net
Layout: Manny <manny@tenka.co.uk>. www.tenka.co.uk

REQUIREMENTS
============
This script requires PHP and GD2 if you wish to use the 
thumbnail functionality.

INSTRUCTIONS
============
1) Unzip all files 
2) Edit this file, making sure everything is setup as required.
3) Upload to server
4) ??????
5) Profit!

CONFIGURATION
=============
Edit the variables in this section to make the script work as
you require.

Start Directory - To list the files contained within the current 
directory enter '.', otherwise enter the path to the directory 
you wish to list. The path must be relative to the current 
directory.
*/
$startdir = '.';

/*
Show Thumbnails? - Set to true if you wish to use the 
scripts auto-thumbnail generation capabilities.
This requires that GD2 is installed.
*/
$showthumbnails = false; 

/*
Show Directories - Do you want to make subdirectories available?
If not set this to false
*/
$showdirs = true;

/* 
Force downloads - Do you want to force people to download the files
rather than viewing them in their browser?
*/
$forcedownloads = false;

/*
Hide Files - If you wish to hide certain files or directories 
then enter their details here. The values entered are matched
against the file/directory names. If any part of the name 
matches what is entered below then it is now shown.
*/
$hide = array(
				'dlf',
				'.php',
				'Thumbs',
				'.htaccess',
				'.htpasswd'
			);
			 
/* 
Show index files - if an index file is found in a directory
to you want to display that rather than the listing output 
from this script?
*/			
$displayindex = false;

/*
Allow uploads? - If enabled users will be able to upload 
files to any viewable directory. You should really only enable
this if the area this script is in is already password protected.
*/
$allowuploads = false;

/*
Overwrite files - If a user uploads a file with the same
name as an existing file do you want the existing file
to be overwritten?
*/
$overwrite = false;

/*
Index files - The follow array contains all the index files
that will be used if $displayindex (above) is set to true.
Feel free to add, delete or alter these
*/

$indexfiles = array (
				'index.html',
				'index.htm',
				'default.htm',
				'default.html'
			);
			
/*
File Icons - If you want to add your own special file icons use 
this section below. Each entry relates to the extension of the 
given file, in the form <extension> => <filename>. 
These files must be located within the dlf directory.
*/
$filetypes = array (
				'png' => 'jpg.gif',
				'jpeg' => 'jpg.gif',
				'bmp' => 'jpg.gif',
				'jpg' => 'jpg.gif', 
				'gif' => 'gif.gif',
				'zip' => 'archive.png',
				'rar' => 'archive.png',
				'exe' => 'exe.gif',
				'setup' => 'setup.gif',
				'txt' => 'text.png',
				'htm' => 'html.gif',
				'html' => 'html.gif',
				'fla' => 'fla.gif',
				'swf' => 'swf.gif',
				'xls' => 'xls.gif',
				'doc' => 'doc.gif',
				'sig' => 'sig.gif',
				'fh10' => 'fh10.gif',
				'pdf' => 'pdf.gif',
				'psd' => 'psd.gif',
				'rm' => 'real.gif',
				'mpg' => 'video.gif',
				'mpeg' => 'video.gif',
				'mov' => 'video2.gif',
				'avi' => 'video.gif',
				'eps' => 'eps.gif',
				'gz' => 'archive.png',
				'asc' => 'sig.gif',
			);
			
/*
That's it! You are now ready to upload this script to the server.

Only edit what is below this line if you are sure that you know what you
are doing!
*/
error_reporting(0);
if(!function_exists('imagecreatetruecolor')) $showthumbnails = false;
$leadon = $startdir;
if($leadon=='.') $leadon = '';
if((substr($leadon, -1, 1)!='/') && $leadon!='') $leadon = $leadon . '/';
$startdir = $leadon;

if($_GET['dir']) {
	//check this is okay.
	
	if(substr($_GET['dir'], -1, 1)!='/') {
		$_GET['dir'] = $_GET['dir'] . '/';
	}
	
	$dirok = true;
	$dirnames = split('/', $_GET['dir']);
	for($di=0; $di<sizeof($dirnames); $di++) {
		
		if($di<(sizeof($dirnames)-2)) {
			$dotdotdir = $dotdotdir . $dirnames[$di] . '/';
		}
		
		if($dirnames[$di] == '..') {
			$dirok = false;
		}
	}
	
	if(substr($_GET['dir'], 0, 1)=='/') {
		$dirok = false;
	}
	
	if($dirok) {
		 $leadon = $leadon . $_GET['dir'];
	}
}

if($_GET['download'] && $forcedownloads) {
	$file = str_replace('/', '', $_GET['download']);
	$file = str_replace('..', '', $file);

	if(file_exists($leadon . $file)) {
		header("Content-type: application/x-download");
		header("Content-Length: ".filesize($leadon . $file)); 
		header('Content-Disposition: attachment; filename="'.$file.'"');
		readfile($leadon . $file);
		die();
	}
}

if($allowuploads && $_FILES['file']) {
	$upload = true;
	if(!$overwrite) {
		if(file_exists($leadon.$_FILES['file']['name'])) {
			$upload = false;
		}
	}
	
	if($upload) {
		move_uploaded_file($_FILES['file']['tmp_name'], $leadon . $_FILES['file']['name']);
	}
}

$opendir = $leadon;
if(!$leadon) $opendir = '.';
if(!file_exists($opendir)) {
	$opendir = '.';
	$leadon = $startdir;
}

clearstatcache();
if ($handle = opendir($opendir)) {
	while (false !== ($file = readdir($handle))) { 
		//first see if this file is required in the listing
		if ($file == "." || $file == "..")  continue;
		$discard = false;
		for($hi=0;$hi<sizeof($hide);$hi++) {
			if(strpos($file, $hide[$hi])!==false) {
				$discard = true;
			}
		}
		
		if($discard) continue;
		if (@filetype($leadon.$file) == "dir") {
			if(!$showdirs) continue;
		
			$n++;
			if($_GET['sort']=="date") {
				$key = @filemtime($leadon.$file) . ".$n";
			}
			else {
				$key = $n;
			}
			$dirs[$key] = $file . "/";
		}
		else {
			$n++;
			if($_GET['sort']=="date") {
				$key = @filemtime($leadon.$file) . ".$n";
			}
			elseif($_GET['sort']=="size") {
				$key = @filesize($leadon.$file) . ".$n";
			}
			else {
				$key = $n;
			}
			$files[$key] = $file;
			
			if($displayindex) {
				if(in_array(strtolower($file), $indexfiles)) {
					header("Location: $file");
					die();
				}
			}
		}
	}
	closedir($handle); 
}

//sort our files
if($_GET['sort']=="date") {
	@ksort($dirs, SORT_NUMERIC);
	@ksort($files, SORT_NUMERIC);
}
elseif($_GET['sort']=="size") {
	@natcasesort($dirs); 
	@ksort($files, SORT_NUMERIC);
}
else {
	@natcasesort($dirs); 
	@natcasesort($files);
}

//order correctly
if($_GET['order']=="desc" && $_GET['sort']!="size") {$dirs = @array_reverse($dirs);}
if($_GET['order']=="desc") {$files = @array_reverse($files);}
$dirs = @array_values($dirs); $files = @array_values($files);


?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-7">

	<meta name="description" content="διαδραστικό κατανεμημένο περιβάλλον επικοινωνίας κατά τη ζωντανή μουσική εκτέλεση, distributed interactive communication environment for live music performance">
  	<meta name="keywords" content="DIAMOUSES, ΔΙΑΜΟΥΣΕΣ, network live performances, δικτυακές συναυλίες, gesture recognition, αναγνώρηση χειρονομιών, OpenSound Control, MIDI, remote music, μουσική από απόσταση, distributed music, κατανεμημένη μουσική, διαδραστικά περιβάλλοντα μουσικής έκφρασης, interactive music environments,   τηλε-εκπαίδευση στη μουσική, telerecording, tele-music, e-music">
  <title>ΔΙ.Α.ΜΟΥΣ.ΕΣ - DI.A.MOUS.ES</title>
  <link rel="stylesheet" href="dlf/styles.css" type="text/css">
  
 <?php
 if(isset($showthumbnails)) {
	 if($showthumbnails) {
?>
	<script language="javascript" type="text/javascript">
	<!--
	function o(n, i) {
		document.images['thumb'+n].src = 'dlf/i.php?f='+i;
	}

	function f(n) {
		document.images['thumb'+n].src = 'dlf/trans.gif';
	}
	//-->
	</script>
<?php
	 }
 }
?>

  
</head>


<body>

<table  border="0" cellpadding="2" cellspacing="2"  width="98%">



  <tbody>



    <tr>
      <td width="35%" align="left"><a href="../index.htm"><img style="border: 0px solid ; width: 312px; height: 145px;" alt="logo" src="../logo02.gif"></a></td>
      <td width="60%" align="left" colspan="1" rowspan="1" class="Style1">
      <div style="text-align: center;"><span class="logo-text">διαδραστικό κατανεμημένο
περιβάλλον επικοινωνίας κατά τη ζωντανή μουσική εκτέλεση </span>
      </div>

      <hr style="width: 100%; height: 2px; font-style: italic;">
      
      
      <div style="text-align: center;"><span class="logo-text">distributed interactive
communication environment for live music performance </span></div>



      </td>



    </tr>

  </tbody>
</table>



<br>



&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; <br>



<table  class="Style2" border="0" cellpadding="2" cellspacing="2">

  <tbody>



    <tr>


      <td valign="top">
      
      
      <table class="nav-bar" border="0" cellpadding="2" cellspacing="2">



        <tbody>



          <tr>



            <td style="width: 28px;" colspan="1" rowspan="7"></td>



            <td style="color: rgb(0, 204, 204); width: 306px;"><a href="../geninfo/geninfo_gr.html">γενικά στοιχεία του έργου</a><br>



            
            
            <div style="margin-left: 160px;"><a href="../geninfo/geninfo_en.html">about DIAMOUSES</a></div>



            </td>



          </tr>



          <tr>



            <td style="width: 306px;"><a href="../partners/partners_gr.html">συνεργαζόμενοι φορείς</a><br>



            
            
            <div style="margin-left: 160px;"><a href="../partners/partners_en.html">consortium</a></div>



            </td>



          </tr>



       <tr>
									<td width="306"><a href="../stage/stage_gr.html">επιτεύγματα</a>
											<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<a href="../stage/photos/gallery/index.html"> <em>  φωτογραφίες</em> </a>
											<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<a href="../stage/screenshots/index.html"><em>  διεπαφή</em></a>
										<div style="MARGIN-LEFT: 160px"><a href="../stage/stage_en.html">achievements</a>
										<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<a href="../stage/photos/gallery/index.html"> <em>photo gallery  </em> </a>
										<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <a href="../stage/screenshots/index.html"><em>screenshots  </em> </a>
										</div>
									</td>
								</tr>

          <tr>



            <td style="width: 306px;"><a href="rel_work/rel_work_gr.html"><span style="color: rgb(51, 102, 102);"></span></a> <a href="../rel_work/rel_work_gr.html">σχετιζόμενη έρευνα</a><br>



            
            
            <div style="text-align: left; margin-left: 40px;">
            
            
            <div style="margin-left: 120px;"><a href="../rel_work/rel_work_en.html">related work</a><br>



            </div>


            </div>



            </td>



          </tr>



          <tr>
            <td style="width: 306px;"><a href="../pubs/pubs_gr.html">δημοσιεύσεις</span>         
            <div style="margin-left: 160px;"><a href="../pubs/pubs_en.html">publications</a></div>
            </td>
          </tr>



          <tr>



            <td style="width: 306px;"><a href="../contact/contact_gr.html">επικοινωνία</a><br>
            <div style="margin-left: 160px;"><a href="../contact/contact_en.html">contact</a></div>

            </td>



          </tr>

	<tr>
				
				<td width="306"><span style="color: rgb(204, 0, 0);">πρόσβαση μελών</span><br>
				<div style="TEXT-ALIGN: right">
				<div style="MARGIN-LEFT: 160px; TEXT-ALIGN: left"><span style="color: rgb(204, 0, 0);">member access</span><br>
				</div>
				</div>
				</td>
			</tr>

        
        
        </tbody>
      
      
      </table>



      </td>


<td  valign="middle" id="page-content">
 
<?php
	
// first visit just print out the form  check if submit was pressed
if(isset($_POST['submit'])) {

       	// check if username and password are valid
		if(username_and_password_are_valid($_POST['username'], $_POST['password'])) {
			// start session so we can store variables
			$_SESSION['logged_in'] = 1;
			$_SESSION['user_id']= get_user_id($_POST['username']);
			//print_r($_SESSION);
			$content ='<p><div align="right"><strong><a href="logout_gr.php">Αποσύνδεση</a></strong></div></p>';			
			echo $content;
			require_once "docs_index.php";
			//echo "<div id='container'> <h1>Directory Listing of " .dirname($_SERVER['PHP_SELF']).'/'.$leadon . "</h1></div>";
			

		} else {
			$content ='
			<div align="center">
				<form action="login_gr.php" method="post" ID="Form1">
					<table ID="Table1">
					<tr><td colspan="2">Wrong username or password... please retype!</td></tr>
					
					<tr>
					<th>Username</th><td><input type="text" name="username" ID="Text1"></td>
					</tr>
					<tr>
					<th>Password</th><td><input type="password"  name="password"></td>
					</tr>
					<tr> 
					<td colspan="2" align="center">
					<input type="submit" value="submit"  NAME="submit">
					</td>
					</tr>
					</table>		
				</form>
				</div>
			';
			echo $content;			
	}
} else if(isset($_SESSION['logged_in'])) {
		if( $_SESSION['logged_in'] == 1) {
			$content ='<p><div align="right"><strong><a href="logout_gr.php">Αποσύνδεση</a></strong></div></p>';
			echo $content;
			require_once 'docs_index.php';
		}
} else {
		
		$content ='
		<div align="center">
		<form action="login_gr.php" method="post" ID="Form2">
			<table ID="Table2">
					<tr>
					<th>Username</th><td><input type="text" name="username" ID="Text2"></td>
					</tr>
					<tr>
					<th>Password</th><td><input type="password" name="password"></td>
					</tr>
					<tr> 
					<td colspan="2" align="center">
					<input type="submit" value="submit" NAME="submit">
					</td>
					</tr>
			</table>
		</form>
		</div>
	';
	echo $content;
} 

	


?>


      </td>






    </tr>



  
  
  </tbody>
</table>



</body>
</html>
