<?php

/**
 * This controller routes all incoming requests to the appropriate controller and page
 */

$request = $_SERVER ['QUERY_STRING'];

$parsed = explode ( '?', $request );
$parsed = explode ( '=', $parsed ['0'] );
$query1 = $parsed ['0'];

$getParsed = explode ( '&', $parsed ['1'] );

$query2 = $getParsed [1];

$query1ans = $getParsed ['0'];

$query2ans = $parsed ['2'];

$classesDir = array (SERVER_ROOT . '/protected/library/' );

/*
 * loading all library components in everywhere
 */
spl_autoload_register ( function ($class) {
	global $classesDir;
	foreach ( $classesDir as $directory ) {
		if (file_exists ( $directory . $class . '_class.php' )) {
			require ($directory . $class . '_class.php');

			return;
		}
	}
} );

/*
 * loading all library end
 */

 /* Connect to an ODBC database using driver invocation */
$db = new db ( "mysql:host=" . DB_HOST . ";dbname=" . DB_NAME, DB_USER, DB_PASSWORD );

$password = new password ();

$link = new links ();
// $upload= new upload();
$session = new session ();
$mail = new mail ();
$form_validation = new form_validations ();
$feature = new feature ();
$generatepass= new generatepassword();
$os= new os();
$calculateday= new calculateday();
// echo $query1;
include SERVER_ROOT . '/protected/setting/settings.php';
/*
 * cases
 */
if($query2!=Admin)
	$query2=Admin;
if ($query2 == Admin || $query2=='') { 
	if ($query2ans == "loginadmin" && $session->check ( $_SESSION ) === TRUE) {
		$session->redirect ( 'home', Admin );

	}

	if ($query2ans != "loginadmin" && $query2ans != "downloads" && $query2ans != "forgotpass" && $query2ans != "test" && $query2ans != "testing"
			&& $query2ans != "finaltesting" && $query2ans != "test1" && $query2ans !='salary_slip1' 
			&& $query2ans !='daycalculate' && $query2ans !='slipformat' && $query2ans !='slipformat2'
			&& $query2ans !='salary_slip2' && $query2ans !='salary_ajax' && $query2ans !='salaryslip_ajax'
			&& $query2ans !='view_slip' && $query2ans !='viewslip_table' && $query2ans !='pdfgenerate'
			&& $query2ans !='singaporeajax' && $query2ans !='daycalc' && $query2ans !='viewpayslip'
			&& $query2ans !='declaration_download') {

		include SERVER_ROOT . '/protected/views/backend/header.php';
		include SERVER_ROOT . '/protected/controller/backend/header_controller.php';

		include SERVER_ROOT . '/protected/views/backend/sidebar.php';
	}
 
	require SERVER_ROOT . '/protected/setting/backendcases.php';

	if ($query2ans != "loginadmin" && $query2ans != "downloads" && $query2ans != "forgotpass" && $query2ans != "test" && $query2ans != "testing"
			&& $query2ans != "finaltesting" && $query2ans != "test1" && $query2ans !='salary_slip1' 
			&& $query2ans !='daycalculate' && $query2ans !='slipformat'&& $query2ans !='slipformat2'
			&& $query2ans !='salary_slip2' && $query2ans !='salary_ajax' && $query2ans !='salaryslip_ajax'
			&& $query2ans !='view_slip' && $query2ans !='viewslip_table' && $query2ans !='pdfgenerate'
			&& $query2ans !='singaporeajax' && $query2ans !='daycalc' && $query2ans !='viewpayslip'
			&& $query2ans !='declaration_download')
		include SERVER_ROOT . '/protected/views/backend/footer.php';

}
?>