<?php
/*	
	name:	index.php
	job:	main processing script
	version: 0.4++
	Produktion!
*/


// include basic config script
	include("includes/vic_server_config.php");

error_reporting(0);

// some GET + URL security
	if(check_url_hacks($UNALLOWED_URL_STRINGS) != 0) { exit(); }
	if(check_unallowed_get_vars($_GET) != 0) { exit(); }

/*
// logout procedure
if(isset($_GET) && isset($_GET['exit']) && $_GET['exit'] == 1)	{
	define("INCLUDE_PAGE","start.php");
	$_SESSION['USER']['Login']="";
}
else {
	session_start();
}			


	//$u="fd2374e2981a374f7c89db29669d3904";
	//echo is_md5($u);


// setting the USER Session vor new visitors
if(isset($_GET['p']) && $_GET['p'] == "myclub" ) {
	if(isset($_GET['u']))	{
		if(is_md5($_GET['u'])) {
		//	query customer with $u
			$customer = search_user($_GET['u']);
			if($customer !== FALSE) {
			//	set sessions
				$_SESSION['USER']['id'] = $customer['id'];
				$_SESSION['USER']['u'] = $customer['auth'];
				$_SESSION['USER']['name'] = $customer['name'];
				$_SESSION['USER']['method_id'] = $customer['method_id'];
				$_SESSION['USER']['Login'] = "wahr";				
			}else{
			//	login war zwar ok, aber der user ist nicht vorhanden	
				$display_error_message = "Um den Recommender verwenden zu k&ouml;nnen müssen Sie mindestens drei Finanzanlageprodukte (Aktien, Optionsscheine, u.&auml;.) im Depot haben.";
				unset($_SESSION['USER']);
				define("INCLUDE_PAGE","start.php");
			}
		}else{
			$display_error_message = "Ung&uuml;tiger oder unvollst&auml;ndiger Loginversuch.";
			unset($_SESSION['USER']);
			define("INCLUDE_PAGE","start.php");
		}
	}
}


if ($_SESSION['USER']['Login'] == "wahr")	{
	// toggle email notification bit
	if(isset($_POST) && isset($_POST['notificationBit'])) 
	{
		$notificationBit = substr(urlencode($_POST['notificationBit']),0,1);
		//
		if($_POST['notificationBit'] == "1") {
			$sql = "UPDATE customer SET notify=1 WHERE auth=\"{$_SESSION['USER']['u']}\"; ";
			$recordSet = $db->Execute($sql);
			$notificationBitForm=0;
		}
		elseif($_POST['notificationBit'] == "0") {
			$sql = "UPDATE customer SET notify=0 WHERE auth=\"{$_SESSION['USER']['u']}\"; ";
			$recordSet = $db->Execute($sql);
			$notificationBitForm=1;
		}
	}

//	enter this section first after login, when no SESSION_var are set	
//	check for outstanding questionnairs only *once* and set SESSION[Var] to avoid heavy db activity
	if(isset($_SESSION['USER']['questionnair']) == FALSE) {
		// just take the first questionnair found in the list returned by the function above
		// this funtion returns "no_unfilled_qest" if no unfilles quest. is found
		$_SESSION['USER']['questionnair'] = check_for_unfilled_questionnairs($customer_id=$_SESSION['USER']['id']);
		//
		if($_SESSION['USER']['questionnair'] == "no_unfilled_qest") {
			$_SESSION['USER']['curr_questionnair'] = "filled";
		}else{
			// take first row of $_SESSION['USER']['questionnair'] an write it to curr_questionnair as TODO
			$_SESSION['USER']['curr_questionnair'] = $_SESSION['USER']['questionnair']['0'];
		}
//	enter here if some SESSION_var are allready set	= after 2nd reload of page		
	}else{
		//	enter here if a questionnair was just finished and filled ...
		if($_SESSION['USER']['questionnair'] == "no_unfilled_qest") {
			$_SESSION['USER']['curr_questionnair'] = "filled";
		}else{
			// take first row of $_SESSION['USER']['questionnair']...
			#$_SESSION['USER']['curr_questionnair'] = $_SESSION['USER']['questionnair']['0'];
		}
	}
}
// if-end for registered users	


*/
	
// do the menu navigation here
if(isset($_GET) && isset($_GET['p']))	{
	
	if($_GET['p'] == "home")	{
		define("INCLUDE_PAGE","start.php");
	}
	elseif($_GET['p'] == "myclub") {
		if($_SESSION['USER']['Login'] == "wahr")	{
			// if there are >= 1 questionnairs unfilled -> provide one for filling
			// *todo: if there are more than one, set some interval between two questionnairs
			//$_SESSION['USER']['curr_questionnair'] = "filled";
			if($_SESSION['USER']['curr_questionnair']) {
				if($_SESSION['USER']['curr_questionnair'] == "filled") { 
				
					// go directly to recommender page
					if($_SESSION['USER']['method_id'] == 6) {
						$kontrollgruppeText = $kontrollgruppe;
					}
					if($_GET['notifyer'] == "A1") {
						define("INCLUDE_PAGE","listpersonalrecos_notifyer.php");// a fragebogen.php is shown instead
					}elseif($_GET['notifyer'] == "A2") {
						define("INCLUDE_PAGE","listpersonalrecos_notifyer.php");// a fragebogen.php is shown instead
					}else{
						define("INCLUDE_PAGE","listpersonalrecos.php");// a fragebogen.php is shown instead
					}
				}else{
					// go directly to questionnair page
					#echo "path: ".LOCAL_QUESTIONNAIR_DIR.$_SESSION['USER']['curr_questionnair']['formname'];
					define("INCLUDE_PAGE",LOCAL_QUESTIONNAIR_DIR.$_SESSION['USER']['curr_questionnair']['formname']);
				}
			}
		}
		// for logged out, jumping backwards
		else {
			define("INCLUDE_PAGE","start.php");
		}
	}
	elseif($_GET['p'] == "register_others")	{
		define("INCLUDE_PAGE","register_others.php");
	}
	elseif($_GET['p'] == "register_trader")	{
		define("INCLUDE_PAGE","register_others.php");
	}
	elseif($_GET['p'] == "impressum")	{
		define("INCLUDE_PAGE","impressum.php");
	}
	elseif($_GET['p'] == "aboutproject")	{
		define("INCLUDE_PAGE","aboutproject.php");
	}
	elseif($_GET['p'] == "contact")	{
		define("INCLUDE_PAGE","contact.php");
	}
	elseif($_GET['p'] == "team")	{
		define("INCLUDE_PAGE","team.php");
	}
	elseif($_GET['p'] == "partner")	{
		define("INCLUDE_PAGE","partner.php");
	}
	elseif($_GET['p'] == "login")	{
		//define("INCLUDE_PAGE","login.php");
		define("INCLUDE_PAGE","relogin.php");
		//define("INCLUDE_PAGE","start.php");
	}
	elseif($_GET['p'] == "logout")	{
		$_SESSION['USER'] = "";
		header("Location: ".ABSOLUTE_URL."index.php?exit=1");
	}
}else {
	define("INCLUDE_PAGE","start.php");
}

// build webpage
	//include('./header.php');
	if(isset($_GET['notifyer']) && $_GET['notifyer'] == "A1") {			// show only recos for systray programm
		include('./header.php');
		include(INCLUDE_PAGE);
		include('./fuss.php');
	}elseif(isset($_GET['notifyer']) && $_GET['notifyer'] == "A2") {	// count recommendations
		include(INCLUDE_PAGE);
	}else{									// normal webpage
		include('./header.php');
		include('./body_begin2.php');
		include(INCLUDE_PAGE);
		include('./fuss.php');
	}

?>
<pre>
<?
	if($_SERVER['REMOTE_ADDR'] == "62.178.87.226" || $_SERVER['REMOTE_ADDR'] == "x137.208.42.115")
	{
		echo "<div style=\"padding-top:3500px;\"><pre>";
		echo "\n<br>POST::";
		print_r($_POST);
		//echo "\n<br>SESSION::";
		//print_r($_SESSION);
		#var_dump($_POST);
		
		echo "\n<br>GET::";
		print_r($_GET);
		echo date(His);
		echo "\n<br>SERVER::";
		print_r($_SERVER);

		echo "\n<br>COOKIE::";
		print_r($_COOKIE);

		echo "\n<br>ENV::";
		#print_r($_ENV);

		echo "\n<br>REQUEST::";
		#print_r($_REQUEST);

		//echo "\n<br>GLOBALS::";
		//print_r($GLOBALS);
		
		echo "\n<br>FILES::";
		print_r($_FILES);

		echo "\n<br>php_errormsg::";
		print_r($php_errormsg);


		echo "\n</pre></div>\n";
		print_r(chunk_split($php_errormsg));
		
	}
?>
