<?php
class Preroute
{
	function Preroute()
	{

	}

	function do_route()
	{
		if(isset($_GET['kiirasom'])){
			header("Location:http://google.hu/"); exit;
		}

		if(isset($_GET['menu']))
		{
			$menu = $_GET['menu'];

			$tippek = array("tips2009","tips2010","tips2011","tips2012","tips2013","tips2014");

			if( in_array($menu,$tippek) /*($menu == 'tips2009' || $menu == 'tips2010' || $menu == 'tips2011')*/ && isset($_GET['lang']) && isset($_GET['version']) && isset($_GET['session']))
			{
				$lang = $_GET['lang'];
				$version = $_GET['version'];
				$session = $_GET['session'];

				$this->redir('tips/tips2009/'.$lang.'/'.$version.'/'.$session.'/'.$_SERVER['REMOTE_ADDR']);
			}

			if(($menu == 'tips2009_t' || $menu == 'tips2010_t' || $menu == 'tips2011_t' || $menu == 'tips2012_t' || $menu == 'tips2013_t') && isset($_GET['lang']) && isset($_GET['version']) && isset($_GET['session']))
			{
				$lang = $_GET['lang'];
				$version = $_GET['version'];
				$session = $_GET['session'];

				$this->redir('tips/tips2009_t/'.$lang.'/'.$version.'/'.$session.'/'.$_SERVER['REMOTE_ADDR']);
			}

			if($menu == 'tipofdayrefresh' && isset($_GET['lang']) && isset($_GET['version']))
			{
				$lang = $_GET['lang'];
				$version = $_GET['version'];

				$this->redir('tips/request_info/'.$lang.'/'.$version.'/'.$_SERVER['REMOTE_ADDR'].'/akarmi/response.xml');
			}
			if($menu =='downloads_30_days_active')
			{
				if(isset($_GET['ser'])){
					if($_GET['lang']=="hun"){
						header('Location: http://www.archline.hu/business/activate_30/'.$_GET['ser'].'/'.$_GET['pwd']);
						exit;
					}
					else
						$this->redir('business/activate_30/'.$_GET['ser'].'/'.$_GET['pwd']);
				}
			}
			if($menu =='downloads_interior_active' && isset($_GET['lang']))
			{
				if(isset($_GET['ser']))
				$this->redir('business/interior_activate/'.$_GET['ser'].'/'.$_GET['pwd'].'/'.$_GET['lang']);
			}
			if($menu =='downloads_student_active')
			{
				if(isset($_GET['ser']))
				{
					$_SESSION['ser']=$_GET['ser'];
					$_SESSION['pwd']=$_GET['pwd'];
					$this->redir('business/activate_std/'.$_GET['ser'].'/'.$_GET['pwd']);
				}
			}

			if($menu=='module_active')
			{

				$_SESSION['ser']=$_GET['ser'];
				$_SESSION['mod']=$_GET['mod'];
				$_SESSION['out']='1';

				$this->redir('business/activate_mod/'.$_GET['ser'].'/'.$_GET['mod']);
			}


			if($menu=='activate_90_days_active')
			{

				mysql_connect('localhost','cadline');
				mysql_select_db('cadline2');

				$serial_szam = $_GET['ser'];
				$lang_code = $_GET['pwd'];
				$serial_szam_eleje = substr($serial_szam, 0, 2);

				$ser = $_GET['ser'];
				$pwd = $_GET['pwd'];
				$host = gethostbyaddr($_SERVER["REMOTE_ADDR"]);
				$time = time();


				mysql_query("insert into activations2 (act_ser, act_pwd, act_version, act_date, act_host) values ('$ser','$pwd','full','$time','$host')");



				switch(substr($_GET['ser'], 0, 2)) {
			    	case 99: // Szandekosan nincs atallitas
			        case 98: // Szandekosan nincs atallitas
			         	break;
			        case 30:        //- gorog
						header("Location:http://www.archlinexp.cc/?474&ser=".$_GET['ser']); exit;
						break;
			        case 42:        //- cseh
			            break;
			        case 31:        //- holland
						header("Location:http://www.archlinexp.cc/?474&ser=".$_GET['ser']); exit;
						break;
			        case 43:        //- austria
			    		//header("Location:http://www.archlinexp.cc/?474&ser=".$_GET['ser']); exit;
						header("Location:http://www.archlinexp.cc/index.php?id=177&ser=".$_GET['ser']); exit;
						break;
			        case 41:        //- austria dealer ger:
						//header("Location:http://www.archlinexp.cc/?474&ser=".$_GET['ser']); exit;
						header("Location:http://www.archlinexp.cc/index.php?id=177&ser=".$_GET['ser']); exit;
						break;
			        case 49:        //- nemet
						//header("Location:http://www.archlinexp.cc/?474&ser=".$_GET['ser']); exit;
						header("Location:http://www.archlinexp.cc/index.php?id=177&ser=".$_GET['ser']); exit;
						break;
			        case 39:        //- olasz
						//header("Location:http://www.archlinexp.cc/?474&ser=".$_GET['ser']); exit;
						//header("Location:http://www.cadlinesw.com/web/servizi/supporto-utenti/richiesta-codici-archline-xp.html/?ser=".$_GET['ser']); exit;
						header("Location:http://www.cadlinesw.com/web/servizi/supporto-utenti/richiesta-codici-archline-xp.html/?&ser=".$_GET['ser']."&pwd=".$_GET['pwd']); exit;
						break;
			        case 36:        //- magyar
						session_start();
						$_SESSION['serial']=$_GET['ser'];
						$_SESSION['request']=$_GET['pwd'];
						$_SESSION['out']='1';
						header("Location: /business/activate/".$ser.'/'.$pwd); exit;
						break;
			        case 34:        //- spanyol
			        case 52:        //- mexiko
						header("Location: http://www.archlinexp.cc/es/servicecenter/ser/".$_GET['ser']); exit;
						break;
			        case 82://- korea
			            break;
			        case 81://- japan
			            break;
			        default:
						session_start();
						$ser =$_GET['ser'];
						$pwd =$_GET['pwd'];
						header("Location: /business/activate/".$ser.'/'.$pwd); exit;
				}
			}

			if($menu=='downloads_demo'){
				$this->redir('downloads');
			}

			if($menu=='training_private'){
				if($_GET['lang'] == "hun")
					$this->redir('http://www.archline.hu/interior/workshop/nappali', false);
				else
					$this->redir('http://www.archlinexp.com/interior/workshop/reception_room', false);
			}

			if( $menu=='news_main' || $menu=='news_links' ){
				$this->redir('news');
			}

		}
		elseif(isset($_GET['identity'], $_GET['link'], $_GET['type']) && $_GET['identity']!='' && $_GET['link']!='' && $_GET['type']!='')
		{
			$local = true;

			$email = base64_decode($_GET['identity']);
			$link = base64_decode($_GET['link']);
			$type = base64_decode($_GET['type']);
			$date = time();

			mysql_connect('localhost','cadline');
			mysql_select_db('cadline2');

			mysql_query("INSERT INTO `promo_mail` (`email`, `link`, `date`, `type`) VALUES ('$email', '$link', '$date', '$type')");

			if($link=='homepage')
			    $link = '';
			elseif($link=='decorex')
            {
                $link = 'http://www.decorex.com';
                $local = false;
            }

			$this->redir($link, $local);
		}
		elseif( isset($_GET['shsearch']) ){
			//$this->redir('temp/showroomsearch/'.urlencode($_GET['shsearch']));

			$this->redir($_GET['class'].'/search/'.urlencode($_GET['shsearch']));
		}
		else
		{
			if(isset($_SERVER['REQUEST_URI']))
			{
				$haystack = $_SERVER['REQUEST_URI'];



				if(strstr($haystack,'fresh/lang')!==false)
				{
					$this->redir('page/show/66');
				}

				if(strstr($haystack,'index2.php')!==false)
				{
					if(!isset($_GET['serial']) || $_GET['serial']=='' || !isset($_GET['pwd']) || $_GET['pwd']=='' || strlen($_GET['serial'])<9 || strlen($_GET['pwd'])<14)
					{
						print "Wrong serial or password";

						die();
					}
					else
					{
                        mysql_connect('localhost','cadline');
						mysql_select_db('cadline2');

						$action = isset($_GET['action']) ? $_GET['action'] : '';
						$serial = $_GET['serial'];
						$pwd = $_GET['pwd'];

						$host = gethostbyaddr($_SERVER['REMOTE_ADDR']);
						$time = time();

						if ($action=='key') {
							include('class.key.php');
							$request=serial($serial,$pwd);
							print $request;
						}

						mysql_query("insert into activations2 (act_ser, act_pwd, act_version, act_date, act_host) values ('$serial','$pwd','kulso','$time','$host')");

						die();
					}
				}

				else if(strstr($haystack,'training_video_tutorials')!==false)
				{
					$this->redir('multimedia/videos');
				}
				else if(strstr($haystack,'download/TeamViewer')!==false)
				{

				}
				else if (strstr($haystack,'downloads_documentation/lang/hun')!==false)
				{
					$this->redir('support/downloads');
				}
				else if (strstr($haystack,'index.php/videogallery')!==false)
				{
					$this->redir('multimedia/videos');
				}
				else if (strstr($haystack,'Np1rblZ.html')!==false)
				{
					$txt = fopen( 'Np1rblZ.html', "r" );
						while($x = fgets( $txt, 1024)){
							print $x;
						}
						fclose($txt);

						exit();
				}
				else if (strstr($haystack,'robots.txt')!==false)
				{
					if( strstr($_SERVER['SERVER_NAME'],'archline.hu')!==false  ||  strstr($_SERVER['SERVER_NAME'],'cadline.hu')!==false ){
						$txt = fopen( 'public/robots_hun.txt', "r" );
						while($x = fgets( $txt, 1024)){
							print $x;
						}
						fclose($txt);

						exit();
					}
					else{
						$txt = fopen( 'public/robots.txt', "r" );
						while($x = fgets( $txt, 1024)){
							print $x;
						}
						fclose($txt);

						exit();
					}
				}
				else if (strstr($haystack,'mobilesitemap.xml')!==false)
				{
					if(strstr($_SERVER['SERVER_NAME'],'archline.hu')!==false  ||  strstr($_SERVER['SERVER_NAME'],'cadline.hu')!==false)
						$this->redir('public/xml/sitemap/hun/mobilesitemap.xml',false);
					else
						$this->redir('public/xml/sitemap/eng/mobilesitemap.xml',false);
				}
				else if (strstr($haystack,'sitemap.xml')!==false)
				{
					if(strstr($_SERVER['SERVER_NAME'],'archline.hu')!==false  ||  strstr($_SERVER['SERVER_NAME'],'cadline.hu')!==false)
						$this->redir('public/xml/sitemap/hun/sitemap.xml',false);
					else
						$this->redir('public/xml/sitemap/eng/sitemap.xml',false);
				}
				else if (strstr($haystack,'crossdomain.xml')!==false)
				{
					//$this->redir('crossdomain.xml');
					//print "?";
					$xml = fopen( 'crossdomain.xml', "r" );
					while($x = fgets( $xml, 1024)){
						print $x;
					}
					fclose($xml);

					exit();
				}
				else if (strstr($haystack,'favicon')!==false)
				{
					$this->redir('public/img/icon.ico');
				}
				else if (strstr($haystack,'index.php/')!==false)
				{
					$this->redir('');
				} elseif(strstr($haystack, 'clusers') !== false){
				    $this->redir('home/cadline/public_html/clusers/test.php');
				}
			}
			else
			{

			}
		}




	}

	function redir($uri, $local=true)
	{
		if($local)
		{
			header('Location: /'.$uri);
		}
		else
		{
			header('Location: '.$uri);
		}

		exit();


	}

	function mysql_prep($value)
	{
		$magic_quotes_active = get_magic_quotes_gpc();
		$new_enough_php = function_exists( "mysql_real_escape_string" ); // i.e. PHP >= v4.3.0
		if( $new_enough_php )
		{
			// PHP v4.3.0 or higher
			// undo any magic quote effects so mysql_real_escape_string can do the work
			if($magic_quotes_active)
			{
				$value = stripslashes( $value );
			}

			$value = mysql_real_escape_string( $value );

		}
		else
		{
			// before PHP v4.3.0
			// if magic quotes aren't already on then add slashes manually
			if( !$magic_quotes_active )
			{
				$value = addslashes( $value );
			}
			// if magic quotes are active, then the slashes already exist
		}

		return $value;
	}
}
?>
