###### Database-tabellen #######
CREATE TABLE `fbu` (
  `id` int(2) NOT NULL auto_increment,
  `gebruikersnaam` varchar(255) NOT NULL,
  `wachtwoord` varchar(255) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM;


CREATE TABLE `fotoalbum` (
  `nr` int(3) NOT NULL auto_increment,
  `id` int(3) NOT NULL,
  `album` varchar(255) NOT NULL,
  `beschrijving` text NOT NULL,
  PRIMARY KEY  (`nr`)
) ENGINE=MyISAM;


###### index.php #######
[code]
<?php
#########################
# Fotoscript            #
# Versie: 1.62          #
# Voor Zim #
# Door Zim #
#########################
session_start();
?>

<html>
<head>
<style type="text/css">
<!--
table      { border-collapse: collapse; border: 1px solid #C0C0C0; border-color:black; font-family: 'CG Times';}
td         { border: 1px solid #C0C0C0; border-color:black; font-family: 'CG Times';}
a:link     { color: black }
a:visited  { color: black }
a:hover    { color: gray  }
a:active   { color: black }
p		   { font-family: 'CG Times'; }


-->
</style>
<?php
define("BR", "\n");
define("TAB", "\t");
define("NT", "\n\t");

$album = $_GET['album'];
$directory = "./$album";	
$id = $_GET['id'];

echo '<title>Fotoalbum '.$album .'</title>'.BR;
echo '</head>'.BR;
echo '<body>'.BR;

echo '<table width="80%" align="center" style="text-align: center;">'. BR;
echo '<TR>'.BR;
	echo TAB.'<td width="100">'.BR;
		echo TAB,TAB.'<a href="'.$_SERVER['PHP_SELF'].'">Hoofdmenu</a>'. BR;
	echo TAB.'</td>'. BR;
	echo TAB.'<td width="100">'.BR;
	if(!isset($id) && isset($album)){
		echo TAB,TAB.'Album overzicht'. BR;
	} else {
		echo TAB,TAB.'<a href="?album='.$album.'">Album overzicht</a>'.BR;
	}
	echo TAB.'</td>'. BR;
	if(file_exists("login.php")){
		echo TAB.'<td width="100">'.BR;
			echo TAB,TAB.'<a href="login.php">Inloggen</a>'. BR;
		echo TAB.'</td>'. BR;
	}
echo '</table>'.BR; 

echo '<BR>'.BR;

if(empty($album)){
	echo '<center>Kies een album:<br>';
	foreach(glob("*", GLOB_ONLYDIR) as $filename){
    	echo '<a href="?album='.$filename.'">'.$filename.'</a><br>';
	}
	echo '</center>';
	
}elseif(is_dir($directory)){
	if(!isset($id)){		
		$a_jpeg = array(); 
		if($dir = @opendir($directory)) {
			while (($file = readdir($dir)) !== false) {
				$filetype = substr($file,-3,3);
				if ($filetype == 'jpg' || $filetype == 'JPG' ){
					$a_jpeg[] = $directory.'/thumbs/'.$file; 
		   		   	
					if(!is_dir("$directory/thumbs")){
				        $res = @mkdir($directory.'/thumbs',0777);
				        	if(!$res){
								echo "Geen rechten om thumbnails aan te maken.";
								exit();
							}else{
			            		chmod($directory.'/thumbs',0777);
		            		}
			   		}   

			    	if(!file_exists($directory.'/thumbs/'.$file)){
			    		$imagehw = GetImageSize($directory.'/'.$file);
				    	$src_width = $imagehw[0];  
				    	$src_height = $imagehw[1];
				            
				    	$src_width > $src_height ? $dest_width = 75 : $dest_width = 50;
				    
				    	$tmp = $src_width / $dest_width;
				    	$dest_height = $src_height / $tmp;
				        
				    	$src_img = imagecreatefromjpeg($directory.'/'.$file);
				    	$dst_img = imagecreatetruecolor($dest_width,$dest_height);
				    
				    	imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_width,    $dest_height, $src_width, $src_height);
				    	imagejpeg($dst_img, "$directory/thumbs/$file", 75);
				    	imagedestroy($src_img);
				    	imagedestroy($dst_img);
					}
				}
			} 
		closedir($dir);  
		sort($a_jpeg);
	}
	echo '<table border="0" align="center">'.BR;
	echo '<tr>'.BR;
		echo TAB .'<td colspan="4" align="center">'.BR;
			echo TAB,TAB.'<p style="text-transform: capitalize; font-size: 24pt;">'.$album.'</p>'.BR;
		echo TAB .'</td>'.BR;
	echo '</tr>'.BR;
	
	$i = 0;
	
	while($i < count($a_jpeg)){
		echo '<tr>'.BR;
			if(file_exists($a_jpeg[$i])){
				echo TAB.'<td align="center">'.BR;
					echo TAB,TAB .'<a href="?album='.$album.'&id='.$i.'"><img src="'.$a_jpeg[$i].'" border="0">'.BR;
				echo TAB.'</td>'.BR;
			}else{
				echo '';
			}
			$i++;
			if(file_exists($a_jpeg[$i])){
				echo TAB.'<td align="center">'.BR;
					echo TAB,TAB .'<a href="?album='.$album.'&id='.$i.'"><img src="'.$a_jpeg[$i].'" border="0">'.BR;
				echo TAB.'</td>'.BR;
			}else{
				echo '';
			}
			$i++;
			if(file_exists($a_jpeg[$i])){
				echo TAB.'<td align="center">'.BR;
					echo TAB,TAB .'<a href="?album='.$album.'&id='.$i.'"><img src="'.$a_jpeg[$i].'" border="0">'.BR;
				echo TAB.'</td>'.BR;
			}else{
				echo '';
			}
			$i++;
			if(file_exists($a_jpeg[$i])){
				echo TAB.'<td align="center">'.BR;
					echo TAB,TAB .'<a href="?album='.$album.'&id='.$i.'"><img src="'.$a_jpeg[$i].'" border="0">'.BR;
				echo TAB.'</td>'.BR;
			}else{
				echo '';
			}
			$i++;
			echo '</tr>'.BR;
		}

		echo '<tr>'.BR;
			echo TAB.'<td colspan="4" align="center">'.BR;
				echo TAB,TAB.'<font size="1">Made by Zim</a></font>'.BR;
			echo TAB.'</td>'.BR;
		echo '</tr>'.BR;
		echo '</table>'; 
	}else{
		$b_jpeg = array(); 
		if ($dir = @opendir($directory)) {
			while (($file = readdir($dir)) !== false) {
				$filetype = substr($file,-3,3);
				if ($filetype == 'jpg' || $filetype == 'JPG' ){
					$b_jpeg[] = $directory.'/'.$file; 
	   			}
   			$max = count($b_jpeg);
   			}
			closedir($dir);
			sort($b_jpeg);
		}
		
		$volgende = $id+1;
		$volgende2 = $id+2;
		$vorige = $id-1;
		$vorige2 = $id;
		
        if(file_exists("login.php") && file_exists("db_connect.php")){
        	include 'db_connect.php';
    	}
		
		echo '<table border="1" align="center">'.BR;
		echo '<tr>';
			echo TAB.'<td colspan="2" align="center">'.BR;
				echo TAB,TAB.'<p style="text-transform: capitalize; font-size: 24pt">'.$album.'</p>'.BR;
			echo TAB.'</td>'.BR;
		echo '</tr>'.BR;
				
		echo '<tr>'.BR;
			echo TAB.'<td width="50%" align="right">'.BR;
				if($vorige2 >= 1){
					echo TAB,TAB.'<a href="?album='.$album.'&id='.$vorige.'">Vorige</a>'.BR;
				}else{
					echo TAB,TAB.'Vorige'.BR;
				}
			echo TAB.'</td>'.BR;
			echo TAB.'<td width="50%" align="left">'.BR;
				if($volgende2 <= $max){
					echo TAB,TAB.'<a href="?album='.$album.'&id='.$volgende.'">Volgende</a>'.BR;
				}else{
					echo TAB,TAB.'Volgende'.BR;
				}
			echo TAB.'</td>'.BR;
			
		echo '</tr>'.BR;
		echo '<tr>'.BR;
			echo TAB.'<td colspan="2" align="center">'.BR;
				echo '<a href="'.$b_jpeg[$id].'"><img src="'.$b_jpeg[$id].'" width="600" border="0"></a>'.BR;
			echo TAB.'</td>'.BR;
		echo '</tr>'.BR;
		if(file_exists("login.php")){
		       if($_GET['actie'] == "wijzigen" && isset($_SESSION['gebruiker'])){

					
				$sql = "SELECT * FROM fotoalbum WHERE id='".$id."' AND album='".$album."'";
				$res=mysql_query($sql) or die("FOUT: ".mysql_error());
				if(mysql_num_rows($res) > 0) {
					while($row = @mysql_fetch_array($res)){
						$beschrijving = $row['beschrijving'];
					}
					echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?album='.$album.'&id='.$id.'&actie=update">'.BR;
					echo '<tr>'.BR;
						echo TAB.'<td colspan="2" align="center">'.BR;
							echo TAB,TAB.'<input type="text" name="veld" value="'.$beschrijving.'" size="80"><br>'.BR;
							echo '<input type="submit" value="Update">'.BR;
						echo TAB.'</td>'.BR;
					echo '</tr>'.BR;
				} else {
					echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?album='.$album.'&id='.$id.'&actie=insert">'.BR;
					echo '<tr>'.BR;
						echo TAB.'<td colspan="2" align="center">'.BR;
							echo '<input type="text" name="veld" size="80"><br>'.BR;
							echo '<input type="submit" value="Invoegen">'.BR;
						echo TAB.'</td>'.BR;
					echo '</tr>'.BR;
				}
				       }elseif($_GET['actie'] == "update"  && isset($_SESSION['gebruiker'])){

				$update ="UPDATE fotoalbum SET beschrijving='".$_POST['veld']."' WHERE id='".$id."' AND album='".$album."'";
				$resupdate=mysql_query($update) or die("FOUT: ".mysql_error());
				
				echo '<meta http-equiv="refresh" content="0;url='.$_SERVER['PHP_SELF'].'?album='.$album.'&id='.$id.'">';
				
			}elseif($_GET['actie'] == "insert" && isset($_SESSION['gebruiker'])){
				$sql="INSERT INTO fotoalbum (id,album,beschrijving) VALUES('".$_GET['id']."','".$_GET['album']."','".$_POST['veld']."');";
				$res=mysql_query($sql) or die (mysql_error()); 
				
				echo '<meta http-equiv="refresh" content="0;url='.$_SERVER['PHP_SELF'].'?album='.$album.'&id='.$id.'">';

			} else {

				echo '<tr>'.BR;
					echo TAB.'<td colspan="2">'.BR;
	
					if(isset($_SESSION['gebruiker'])){
						echo TAB,TAB.'<b><a href="'.$_SERVER['PHP_SELF'].'?album='.$album.'&id='.$id.'&actie=wijzigen">Beschrijving van foto '.$id.':</b></a>'.BR;
					} else {
						echo TAB,TAB.'<b><i>Beschrijving van foto '.$id.':</b></i>'.BR;
					}

						$sql = "SELECT * FROM fotoalbum WHERE id='".$id."' AND album='".$album."'";
						$res=mysql_query($sql) or die("FOUT: ".mysql_error());
						if(mysql_num_rows($res) > 0) {
							while($row = @mysql_fetch_array($res)){
								$beschrijving = $row['beschrijving'];
							}
						}
						if($beschrijving == ""){
							$beschrijving = "Geen beschrijving toegevoegd.";
						}
						echo TAB,TAB.$beschrijving.BR;
					echo TAB.'</td>'.BR;
				echo '</tr>'.BR;
			}
		}
		echo '</table>'.BR;
	}
}else{
	echo '<center>De directory die jij zoekt ('.$album.') bestaat niet.<br>';
	echo 'Maar je kunt wel kiezen uit de volgende albums:<br>';
	foreach (glob("*") as $filename){
    	echo ': '.$filename.'<br>';
    }
    echo '</center>';
}

?> 
[/code]
###### db_connect.php #####
[code]
<?
// db_connect.php by Zim 

    $user = "USERNAME"; 
    $pass = "PASSWORD"; 
    $host = "localhost"; 
    $dbdb = "DATABASENAME"; 
     
    if (!mysql_select_db($dbdb, mysql_connect($host, $user, $pass))) 
    { 
        echo "Kan geen verbinding maken met de database."; 
        exit(); 
    } 

?>
[/code]
###### login.php ######
[code]
<?

define("BR", "\n");
define("TAB", "\t");
define("NT", "\n\t");

if(!$_GET['actie'] == "verwerken"){

	echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?actie=verwerken">'.BR;
	echo '<table align="center">';
	echo '<tr>'.BR;
		echo TAB.'<td>'.BR;
			echo TAB,TAB.'Gebruikersnaam:'. BR;
		echo TAB.'</td>'. BR;
		echo TAB.'<td>'.BR;
			echo TAB,TAB.'<input type="text" name="gebruikersnaam" size="5" maxlength="10">'. BR;
		echo TAB.'</td>'. BR;
	echo '</tr>'.BR;
	echo '<tr>'.BR;
		echo TAB.'<td>'.BR;
			echo TAB,TAB.'Wachtwoord:'. BR;
		echo TAB.'</td>'. BR;
		echo TAB.'<td>'.BR;
			echo TAB,TAB.'<input type="password" name="wachtwoord" size="5" maxlength="10">'. BR;
		echo TAB.'</td>'. BR;
	echo '</tr>'.BR;
	echo '<tr>'.BR;
		echo TAB.'<td colspan="2" align="center">'.BR;
			echo TAB,TAB.'<input type="submit" value="Login">'.BR;
		echo TAB.'</td>'.BR;
	echo '</tr>'.BR;
	echo '</form>';
	echo '</table>';
	exit;
	
}else{
	
	session_start(); 
	include "db_connect.php";
	if(!empty($_POST)){
		
		$sql1 = "SELECT * FROM fbu WHERE gebruikersnaam='" . mysql_real_escape_string($_POST["gebruikersnaam"])  ."'  AND wachtwoord='". mysql_real_escape_string(md5($_POST["wachtwoord"])) . "'"; 
		$res1 = mysql_query($sql1) or die("De volgende fout is opgetreden: ".mysql_error());
		if(mysql_num_rows($res1) > 0) {
			
			$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
			$_SESSION['gebruiker'] = $_POST['gebruikersnaam'];
			
			header("Location: index.php");
		} else { 
		
			$text = "U hebt geen goede combinatie van gebruikersnaam en wachtwoord gebruikt! <a href=\"login.php\">Ga terug</a>"; 
			die($text); 
		
		}
	} else { 
		//pagina verkeerd aangeroepen 
		header("Location: index.html"); 
	}
	
}
?>
[/code]

### user.php ###
[code]
<?
include "db_connect.php";
$gebruikersnaam = "jougebruikersnaam";  //wijzig het naar je gebruikersnaam
$wachtwoord2 = "Jouwachtwoord";  //wijzig het naar je wachtwoord


//hieronder niks wijzigen

$wachtwoord = md5($wachtwoord2);

$sql ="INSERT INTO fbu ( id , gebruikersnaam , wachtwoord ) VALUES ( NULL , '$gebruikersnaam', '$wachtwoord')";
$res=mysql_query($sql) or die (mysql_error()); 
?>
[/code]
