<? 

include_once("CreateRss.php");

header("Content-type: text/xml; charset=iso-8859-1");



$aantal		=	($_GET['aantal'])?intval($_GET['aantal']):10;

include ("/home/zoekbijbaa/domains/zoekbijbaan.nl/public_html/studenten/settings.php");
	mysql_connect("$ip","$dbuser","$dbpass");
						mysql_select_db("$dbname");
	
	
	
if($_GET['action'] == 'zoeken'){


$_SESSION['searchResult'] = $_GET;


}

if(isset($_SESSION['searchResult'])){

	//Zorgen dat als er niets aangevinkt is in onderstaande boxen, het script het dan nog begrijpt
	//We doen dan net of de gebruiker "Maakt niet uit" heeft ingevuld.
	if(!$_SESSION['searchResult']['BrancheBox']){
	
		$_SESSION['searchResult']['BrancheBox'][]	=	0;
	
	}

	if(!$_SESSION['searchResult']['RegioBox']){
	
		$_SESSION['searchResult']['RegioBox'][]	=	0;
	
	}
	
	if(!$_SESSION['searchResult']['SoortWerkBox']){
	
		$_SESSION['searchResult']['SoortWerkBox'][]	=	0;
	
	}


	

	
$leftjoin	=	array();
$where		=	array();	
	
	
##### Zoeken naar studierichting #######	
$studierichting	=	stripslashes($_SESSION['searchResult']['Studierichting']);

if($studierichting != '0'){

$leftjoin[]	=	" LEFT JOIN tblKoppelVacaturesStudierichting vs ON b.Id=vs.Id ";
$where[]	=	" vs.Waarde = '".$studierichting."' ";


}

##### Zoeken naar branche #######

if(!in_array('0',$_SESSION['searchResult']['BrancheBox'])){

	foreach($_SESSION['searchResult']['BrancheBox'] as $waarde){
	$waarde = mysql_real_escape_string($waarde);
	$whereBranche[]	=	"b.Branche='$waarde'";
	}
	
	$whereBranche	=	implode(" OR ",$whereBranche);
	
	$where[]	=	" ( $whereBranche )";	

}	

##### Zoeken naar soortwerk #######

if(!in_array('0',$_SESSION['searchResult']['SoortWerkBox'])){


	$leftjoin[]	=	" LEFT JOIN tblKoppelVacaturesSoortwerk vsw ON b.Id=vsw.Id ";
	
	foreach($_SESSION['searchResult']['SoortWerkBox'] as $waarde){
	$waarde = mysql_real_escape_string($waarde);
	$whereSoortwerk[]	=	"vsw.Waarde='$waarde'";
	}
	
	$whereSoortwerk	=	implode(" OR ",$whereSoortwerk);
	
	$where[]	=	" ( $whereSoortwerk )";	

}	

##### Zoeken naar regio #######
if(!in_array('0',$_SESSION['searchResult']['RegioBox'])){


	$leftjoin[]	=	" LEFT JOIN tblKoppelVacaturesRegio vr ON b.Id=vr.Id ";
	
	foreach($_SESSION['searchResult']['RegioBox'] as $waarde){
	$waarde = mysql_real_escape_string($waarde);
	$whereRegio[]	=	"vr.Waarde='$waarde'";
	}
	
	$whereRegio	=	implode(" OR ",$whereRegio);
	
	$where[]	=	" ( $whereRegio )";	

}	

##### Zoeken naar Niveau #######
if($_SESSION['searchResult']['Niveau'] != '0'){

$niveau	=	addslashes($_SESSION['searchResult']['Niveau']);

if (!is_numeric($niveau)) {
	$sql = "SELECT `Id` FROM tblWaardesStudieniveaus WHERE `Waarde` = '$niveau'";
	$sql_result = mysql_query($sql);
	
	$niveau = mysql_result($sql_result, 0, 'Id');
}

$leftjoin[] = " LEFT JOIN $tblname52 kvn ON b.Studieniveau = kvn.Id";
$where[]	=	" b.Studieniveau='$niveau' ";	

}

##### Zoeken naar trefwoord #######
if($_SESSION['searchResult']['Trefwoord'] != ''){

$trefwoord	=	addslashes($_SESSION['searchResult']['Trefwoord']);

$where[]	=	" (b.Functieomschrijving LIKE '%$trefwoord%' OR b.Vereisten LIKE '%$trefwoord%' OR b.Titel LIKE '%$trefwoord%' OR b.Locatie LIKE '%$trefwoord%') ";	

$aWhere[]	=	" (s.Functieomschrijving LIKE '%$trefwoord%' OR s.Vereisten LIKE '%$trefwoord%' OR s.Titel LIKE '%$trefwoord%' OR s.Locatie LIKE '%$trefwoord%') ";	


}

##### Zoeken naar dagen per week beschikbaar #######

if($_SESSION['searchResult']['Dagen'] != '0'){

$dagen	=	addslashes($_SESSION['searchResult']['Dagen']);

$where[]	=	" b.AantalDagen='$dagen' ";

$aWhere[]	=	" s.AantalDagen='$dagen' ";

}

##### Zoeken naar Beschikbaarheid #######

if($_SESSION['searchResult']['Beschikbaarheid'] != '0'){

$Beschikbaarheid	=	addslashes($_SESSION['searchResult']['Beschikbaarheid']);

$where[]	=	" b.Beschikbaarheid='$Beschikbaarheid' ";
$aWhere[]	=	" s.Beschikbaarheid='$Beschikbaarheid' ";

}

##### Zoeken naar dienstverband #######

if($_SESSION['searchResult']['Dienstverband'] != '0'){

	$leftjoin[] = "LEFT JOIN tblKoppelVacaturesDienstverband kvd ON b.Id = kvd.Id";
	
	$Dienstverband	=	addslashes($_SESSION['searchResult']['Dienstverband']);
	
	$where[]	=	" kvd.Waarde='$Dienstverband' ";
	$aWhere[]	=	" kvd.Waarde='$Dienstverband' ";
}
	

#### Joins die we zowieso nodig hebben om informatie over branches etc op te halen ####

$leftjoin[]	=	" LEFT JOIN tblWaardesBranches  br ON b.Branche=br.Id ";	
$leftjoin[]	=	" LEFT JOIN tblDienstverband dvb ON b.Dienstverband=dvb.Id ";	
	
	$leftjoin_combine	=	implode("",$leftjoin);
	$where_combine		=	implode(" AND ",$where);
	
	$and	=	(count($where) > 0)?"AND":"";
	

	
$sqlrss 	= 	"SELECT  b.* FROM tblBijbanen b $leftjoin_combine WHERE StatusOwner='1' $and $where_combine GROUP BY b.Id ORDER BY Creation DESC,b.Id DESC LIMIT 100";	
}	

if(!isset($sqlrss)){
	$aantal	=	100;
		if($_GET['aantal']){
		$aantal = intval($_GET['aantal']);
		if($aantal >= 400){
			$aantal = 400;
		}
	}
	
	if ($aantal == 0) $aantal = 100;
	$sqlrss	=	"SELECT * FROM tblBijbanen b LEFT JOIN tblKoppelVacaturesDienstverband kvd ON b.Id = kvd.Id WHERE b.StatusOwner = '1' AND kvd.Waarde = '4' ORDER BY b.Id DESC LIMIT $aantal";
}

CreateRss($sqlrss,"Zoekvakantiewerk.nl: nieuw vakantiewerk","Vind nieuw vakantiewerk op Zoekvakantiewerk.nl");

 ?> 
