<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<title></title> 
	<link href='dm.css' rel='stylesheet' type='text/css'>
<?php
	include "functions.php";
?>
<body leftmargin=0 topmargin=0>
	<div align="center">
	<table width="100%" border="0" cellspacing="3" cellpadding="0">
		<?php
			include "header.php";
		?>
		<tr>
			<td align="center" valign="top" class="content">
				<?php
					DBConnect();

 					$action = ( isset($_REQUEST['action'] ) ? $_REQUEST['action'] : "" );
 					$n = ( isset($_REQUEST['n'] ) ? $_REQUEST['n'] : "" );
					$Name	= ( isset($_REQUEST['Name'] ) ? $_REQUEST['Name'] : "" );
					$Datei	= ( isset($_REQUEST['Datei'] ) ? $_REQUEST['Datei'] : "" );
					$Upload	= ( isset($_REQUEST['Upload'] ) ? $_REQUEST['Upload'] : "" );
					$Views	= ( isset($_REQUEST['Views'] ) ? $_REQUEST['Views'] : "" );

					if( $action == "refresh" ) {
						// Nach neuen Bildern schauen
						if( $_SERVER['SERVER_NAME'] == "127.0.0.1" ) {
							$fulldir = "/homepage/panoramicum/p3/";
						} else {
							$fulldir = "/var/www/vhosts/vs148016.vserver.de/panoramicum.de/";
						}
	
						$handle = @opendir( $fulldir."planeten" );
						$files = array();
						while ($file = readdir ($handle)) {
							if (!preg_match("/^\.{1,2}$/i",$file)) {
								$pos = strpos( $file , ".jpg" );
								if( !( $pos === false ) ) {
									$query = "SELECT ID,Name,Datei FROM planeten where Datei='".$file."'";
					  		  $result = $db->query($query);
					  		  
					  		  if( $result->rowCount() == 0 ) {
					  		  	$upload = date( "Y-m-d" );
										$query = "INSERT INTO planeten (Datei,Upload) VALUES ('$file','$upload')";
		  		  				$result = $db->query($query);
					  		  	print "New Image $file<br>";
								  }
								}
							}
						}
					}
					
					if( $action == "edit" ) {
						if( $n == 0 ) {
							$query = "INSERT INTO planeten (Name,Datei,Upload,Views) VALUES ('$Name','$Datei','$Upload','$Views')";
	    				$result = $db->query($query);
	    			} else {
							$query = "UPDATE planeten SET Name='$Name',Datei='$Datei',Upload='$Upload',Views='$Views' WHERE ID=$n";
	    				$result = $db->query($query);
	    			}
					}

					if( $action == "delete" ) {
						$query = "delete from planeten WHERE ID=$n";
    				$result = $db->query($query);
					}
					
			    $query = "SELECT ID,Name,Datei FROM planeten order by Datei";
	  		  $result = $result = $db->query($query);

					print "<table width=100% border='0' cellspacing='3' cellpadding='4'><tr>";
					print "<td bgcolor='#CCCCCC'>Datei</td><td bgcolor='#CCCCCC'>Name</td>";
					print "<td colspan='3' bgcolor='#CCCCCC'>&nbsp;</td></tr>";
					foreach( $result as $line ) {
				  	print "<tr valign='top'><td bgcolor='#EEEEEE'>".$line["Datei"]."&nbsp;</td>";
						print "<td bgcolor='#EEEEEE'>".$line["Name"]."&nbsp;</td>";
						$ln = $line["ID"];
				  	print "<td bgcolor='#EEEEEE'><a href=\"edit.php?n=$ln\">Bearbeiten</a></td>";
				  	print "<td bgcolor='#EEEEEE'><a href=\"admin.php?n=$ln\">Verwalten</a></td>";
				  	print "<td bgcolor='#FF0000'><a href=\"index.php?n=$ln&action=delete\">Entfernen</a></td></tr>";
					}
					print "<tr><td bgcolor='#EEEEEE' colspan=5 align=\"center\"><a href=\"index.php?action=refresh\">Neue Bilder suchen</a></td></tr>";
					
					print "</table>";
				
				?>
				
			</td>
		</tr>
	</table>
	</div>

</body>
</html>
