<?php
/**
* Immo Manager verhuur op jaarbasis
*
*/

/**
* Veiligheid controle ...
*/

define('dArKCMS', true);
//error_reporting(E_ALL); 

/**
* Includes ophalen ...
*/

include($_SERVER['DOCUMENT_ROOT']."/CMS/includes/_darkcmsConfiguratie.php"); 
include($_SERVER['DOCUMENT_ROOT']."/CMS/includes/class.sessieBeheer.php");
include($_SERVER['DOCUMENT_ROOT']."/CMS/includes/_darkcmsCore.php");

include($_SERVER['DOCUMENT_ROOT']."/CMS/modules/mod_fotoAlbum/includes/_modFunkties.php");
include_once($_SERVER['DOCUMENT_ROOT']."/CMS/modules/mod_fotoAlbum/includes/class.upload.php");


/**
* Taal ophalen ...
*/

$CoreTaal	= strtoupper($_GET['tl']); if ($CoreTaal == ''){$CoreTaal = 'NL';}

if (($CoreTaal != 'NL') && ($CoreTaal != 'FR')){ 
	$CoreTaal = 'NL'; 
}

/**
* CoreTaal ophalen ...
*/

include($_SERVER['DOCUMENT_ROOT']."/CMS/talen/_core".$CoreTaal.".php");

//include("../../talen/_core".$CoreTaal.".php");

/**
* Module Taal ophalen ...
*/

include($_SERVER['DOCUMENT_ROOT']."/CMS/modules/mod_fotoAlbum/talen/_modTaal".$CoreTaal.".php");

//include("talen/_modTaal".$CoreTaal.".php");

/**
* Diverse akties gaan uitvoeren ...
*/

switch ($_GET['a']){

	case "logUit" :
		$session->uitloggen();
	break;

}	

/**
 * Gebruiker is ingelogd ...
 */

if($session->checkLogin()){
	
	switch ($_GET['a']){

	case "Toevoegen" :

		include($_SERVER['DOCUMENT_ROOT']."/CMS/modules/mod_fotoAlbum/includes/_modHeader.php");
		//include('includes/_modHeader.php');
		coreGebruikerStats($CoreTaal);
		coreModules (2,$CoreTaal);
		Toevoegen();
		echo '</div>';
		include($_SERVER['DOCUMENT_ROOT']."/CMS/includes/_darkcmsFooter.php");
		//include('../../includes/_darkcmsFooter.php');
		
	break;
	
	case "Opslaan" :
	
		$nTaal	= strtoupper($_GET['nTaal']); if ($nTaal == ''){$nTaal = $CoreTaal;}
	
		if(!get_magic_quotes_gpc()) {
		
			$omschrijving 	= addslashes($_POST['titel']);
					
		} else {
 		
			$omschrijving = ($_POST['titel']);
			
 		}
		
		$dbconnect		= mysql_connect (DBhost,DBgebruiker,DBwachtwoord) or die ("Kan niet verbinden: " . mysql_error());
		$dbselect 		= mysql_select_db (DBnaam,$dbconnect);
		
		$SQL = "INSERT INTO mod_fotoAlbum ( omschrijving, Publiceren) VALUES ('$omschrijving','0')";
		
		//print $SQL;
		
		
		$result = mysql_query ($SQL) OR DIE(mysql_error());
		mysql_close($dbconnect);
		header ('location: index.php?tl='.$CoreTaal);

	break;

	case "DetailsOpslaan" :
	
		$nTaal	= strtoupper($_GET['nTaal']); if ($nTaal == ''){$nTaal = $CoreTaal;}
		$id = $_GET['id'];	
		
		if(!get_magic_quotes_gpc()) {
		
			$titel = addslashes($_POST['titel']);
			$titel_fr = addslashes($_POST['titel_fr']);
						
		} else {
 		
			$titel = ($_POST['titel']);
			$titel_fr = ($_POST['titel_fr']);
	
 		}
		
		$dbconnect		= mysql_connect (DBhost,DBgebruiker,DBwachtwoord) or die ("Kan niet verbinden: " . mysql_error());
		$dbselect 		= mysql_select_db (DBnaam,$dbconnect);
		
		$SQL = "UPDATE mod_fotoAlbum SET	
							omschrijving = '$titel',
							omschrijving_fr = '$titel_fr'
							WHERE id=$id"; 
		
		$result = mysql_query ($SQL) OR DIE(mysql_error());
		mysql_close($dbconnect);
		header ('location: index.php?tl='.$CoreTaal);

	break;
	
		case "Details" :

		include($_SERVER['DOCUMENT_ROOT']."/CMS/modules/mod_fotoAlbum/includes/_modHeader.php");
		coreGebruikerStats($CoreTaal);
		coreModules (2,$CoreTaal);
		Details();
		echo '</div>';
		include($_SERVER['DOCUMENT_ROOT']."/CMS/includes/_darkcmsFooter.php");
		
	break;
	
	case "fotoOpslaan" :
 
			$albumId	= $_GET['id'];
											
			$handle = new upload($_FILES['image_field'], 'nl_NL');
			if ($handle->uploaded) 
			{
				$handle->auto_create_dir 	  = true;
				$handle->dir_chmod 	  		  = 0777;
				$handle->file_auto_rename 	  = true;
				$handle->image_resize         = true;
				$handle->image_x              = 480;
				$handle->image_ratio_y        = true;
				$handle->process('/home/hetkompa/public_html/CMS/fotos/', 'nl_NL');
				if ($handle->processed) 
				{
				 $naam = $handle->file_dst_name;
			
			 	$dbconnect	= mysql_connect (DBhost,DBgebruiker,DBwachtwoord) or die ("Kan niet verbinden: " . mysql_error());
				$dbselect 	= mysql_select_db (DBnaam,$dbconnect);

				$SQL = ("INSERT INTO mod_fotoAlbumFotos SET 
												albumId = '".$albumId."',
												bestandsNaam	= '".$naam."'");
				$sql_result = mysql_query ($SQL);

				mysql_close($dbconnect); 
				$handle->clean();
	
				} else {
				echo 'error : ' . $handle->error;
				}
				
				header("Location: index.php?a=Details&id=".$albumId."&tl=".$CoreTaal);
			}
			
		
		break;
		
	case "Wissen" :
		
		$id = $_GET['id'];
		$dbconnect	= mysql_connect (DBhost,DBgebruiker,DBwachtwoord) or die ("Kan niet verbinden: " . mysql_error());
		$dbselect 	= mysql_select_db (DBnaam,$dbconnect);
		$SQL = ("DELETE FROM mod_fotoAlbum WHERE id='".$id."'");
		$sql_result = mysql_query ($SQL);
		$SQL = ("DELETE FROM mod_fotoAlbumFotos WHERE albumId='".$id."'");
		$sql_result = mysql_query ($SQL);
		mysql_close($dbconnect);
		header("Location: index.php?tl=".$CoreTaal);
		
	break;
	
	case "wisFoto" :
		
		$FotoId	= $_GET['fotoId'];
		$dbconnect	= mysql_connect (DBhost,DBgebruiker,DBwachtwoord) or die ("Kan niet verbinden: " . mysql_error());
		$dbselect 	= mysql_select_db (DBnaam,$dbconnect);
		
		$SQL = ("DELETE FROM mod_fotoAlbumFotos WHERE id='".$FotoId."'");
		$sql_result = mysql_query ($SQL);
		
		mysql_close($dbconnect);

        header("Location: index.php?a=Details&p=1&id=".$_GET['id']."&tl=".$CoreTaal);
		
	break;
	
	
	case "Publiceer" :
			
		$id = $_GET['id'];
		$dbconnect	= mysql_connect (DBhost,DBgebruiker,DBwachtwoord) or die ("Kan niet verbinden: " . mysql_error());
		$dbselect 	= mysql_select_db (DBnaam,$dbconnect);
		$SQL = ("SELECT * FROM mod_fotoAlbum WHERE id='".$id."'");
		$sql_result	= mysql_query($SQL);

		while ($row=mysql_fetch_array ($sql_result)) {  

			if ($row['publiceren']=='1'){ $tmpVar='0'; } else { $tmpVar='1'; }
			$SQL2 = "UPDATE mod_fotoAlbum SET publiceren=$tmpVar WHERE id=$id";
			$result = mysql_query ($SQL2) OR DIE(mysql_error());	

		}

		mysql_close($dbconnect);
		header("Location: index.php?tl=".$CoreTaal);
	 	
 	break;
 	
 		default :
		
		include($_SERVER['DOCUMENT_ROOT']."/CMS/modules/mod_fotoAlbum/includes/_modHeader.php");
		coreGebruikerStats($CoreTaal);
		coreModules (2,$CoreTaal);
		Overzicht();
		echo '</div>';
		include($_SERVER['DOCUMENT_ROOT']."/CMS/includes/_darkcmsFooter.php");
	}	
	

/**
 * Gebruiker is NIET ingelogd ...
 */

} else {
	header("Location: ".CORE_Path."index.php");
}

?>