<?php
//ini_set("display_errors", 1);
//error_reporting(0);
include_once('site_info.php');
    session_cache_limiter('private,must-revalidate');
ob_start();

	session_start();
	

    $Sess_UserId=$_SESSION['Sess_UserId'];
	include_once __INCLUDE_CLASS_PATH."/class.DB.php";

	$db=new db;
	$db->Connect($CONST_DB_USER, $CONST_DB_PASS, $CONST_DB_NAME, $CONST_DB_HOST);
	
 /*   $link=mysql_connect($CONST_DB_HOST, $CONST_DB_USER, $CONST_DB_PASS);
    if (!$link) die ("Database connection failure");
    mysql_select_db($CONST_DB_NAME) or die("Failure in connection ".mysql_error() );*/
    

################################################################
##  Set user language                                         ##

    if (!$_SESSION['lang_id']) $_SESSION['lang_id'] = $CONST_DEFAULT_LANGUAGE;
    if ($_REQUEST['lang_id']) {
        $_SESSION['lang_id'] = $_REQUEST['lang_id'];
        if (isset ($Sess_UserId)) { 
            $query="UPDATE members SET lang_id='".$_REQUEST['lang_id']."' WHERE mem_userid='$Sess_UserId'";
            $db->query($query);
			//$result=mysql_query($query,$link) or die(mysql_error());
        }
    }
    if (isset ($Sess_UserId)) {
        $query="UPDATE members SET mem_timeout=NOW() WHERE mem_userid='$Sess_UserId'";
        $row=$db->query($query);
		//$result=mysql_query($query,$link) or die(mysql_error());
        $query="SELECT * FROM members WHERE mem_userid='$Sess_UserId'";
        $result=mysql_query($query) or die(mysql_error());
        $row = mysql_fetch_assoc($result);
         $_SESSION['lang_id'] = $row['lang_id'];
    }
    
	$query="SELECT * FROM langfile WHERE lang_active=1";
    $arr_languages=$db->query($query);
	$arr_languages=$db->get_row($query,ARRAY_A);
	//print_r($arr_languages);
	//die;
	//$result=mysql_query($query,$link) or die(mysql_error());
   // $arr_languages = array();
    //while ($lang = mysql_fetch_assoc($result)) {
     //   $arr_languages[] = $lang;
     //   if ($lang['lang_id'] == $_SESSION['lang_id'])
        //    $language = $lang;
   // }
  $CONST_IMAGE_LANG = $arr_languages['lang_id'];
    $CONST_LANG_CHARSET = $arr_languages['lang_charset'];
    $CONST_FILE_LANG = $arr_languages['lang_filename'];

##################################################################    



##  Loading text constants                                      ##
    include $SITE_ROOT."/languages/".$arr_languages['lang_filename'].".php";
    
    $CONST_LINK_LANG_SWITCHER = include $SITE_ROOT."/langswitcher.inc.php"; 

//  var_dump($_SESSION['HISTORY_PAGE']);
    include_once $SITE_ROOT.'/nav_history.php';

################################################################
##  Handling extensions                                       ##

/*$extensionsList=array(
    "generatedEvents"=>"/speeddating/ext_events.php", 
    "generatedStories"=>"/speeddating/ext_stories.php"
);

foreach ($extensionsList as $extension=>$generator) {
    if (file_exists("$SITE_ROOT/$generator")) 
        ${$extension} = include($SITE_ROOT."/$generator");
}   
*/
header("Content-Type: text/html; charset='$CONST_LANG_CHARSET'");     
ob_end_clean();

$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$ur = mysql_escape_string(str_replace($CONST_LINK_ROOT, '', $url));
if($ur=='/home.php')   $_REQUEST['area']='home';
if($ur=='/news.php')   $_REQUEST['area']='news';
if($ur=='/stories.php')   $_REQUEST['area']='story';
if($ur=='/info.php')   $_REQUEST['area']='info';
if($ur=='/readBlogs.php')   $_REQUEST['case']='blogs';
if($ur=='/readArticles.php')   $_REQUEST['case']='articles';
if($ur=='/view_profile.php')   $_REQUEST['case']='view';
if($ur=='/my_account.php')   $_REQUEST['case']='accn';
if($ur=='/my_inbox.php')  { $_REQUEST['case']='mail'; $_REQUEST['type']='inbox';}
if($ur=='/new_email.php')  { $_REQUEST['case']='mail'; $_REQUEST['type']='comp';}
if($ur=='/my_trashcan.php')  { $_REQUEST['case']='mail'; $_REQUEST['type']='trash';}
if($ur=='/my_sentemails.php')  { $_REQUEST['case']='mail'; $_REQUEST['type']='sent';}
if($ur=='/member_alerts.php')  { $_REQUEST['case']='mail'; $_REQUEST['type']='alert';}
if($ur=='/my_favorites.php')  { $_REQUEST['case']='fav'; $_REQUEST['type']='f';}
if($ur=='/hotlisted_me.php')  { $_REQUEST['case']='fav'; $_REQUEST['type']='m';}
if($ur=='/edit_account.php')  { $_REQUEST['case']='accn'; $_REQUEST['area']='edit';}
if($ur=='/edit_profile.php')  { $_REQUEST['case']='accn'; $_REQUEST['area']='reg';}
if($ur=='/block_email.php')  { $_REQUEST['case']='accn'; $_REQUEST['area']='blok';}
if($ur=='/remove_me.php')  { $_REQUEST['case']='accn'; $_REQUEST['area']='del';}
if($ur=='/skype.php')  { $_REQUEST['case']='accn'; $_REQUEST['area']='sky';}
if($ur=='/sms.php')  { $_REQUEST['case']='accn'; $_REQUEST['area']='sms';}
if($ur=='/photo_admin.php')  { $_REQUEST['case']='med'; $_REQUEST['type']='p';}
if($ur=='/manage_gallery.php')  { $_REQUEST['case']='med'; $_REQUEST['type']='g';}
if($ur=='/audio_admin.php')  { $_REQUEST['case']='med'; $_REQUEST['type']='a';}
if($ur=='/video_admin.php')  { $_REQUEST['case']='med'; $_REQUEST['type']='v';}
if($ur=='/add_blogs.php')  { $_REQUEST['case']='med'; $_REQUEST['type']='b';}
if($ur=='/articles.php')  { $_REQUEST['case']='med'; $_REQUEST['type']='art';}
if($ur=='/edit_bio.php')  { $_REQUEST['case']='med'; $_REQUEST['area']='bio';}
if($ur=='/search.php')  { $_REQUEST['case']='sear'; $_REQUEST['type']='search';}
if($ur=='/advanced_search.php')  { $_REQUEST['case']='sear'; $_REQUEST['type']='adv';}
if($ur=='/saved_search.php')  { $_REQUEST['case']='sear'; $_REQUEST['type']='save';}
if($ur=='/my_matches.php')  $_REQUEST['type']='mat';
if($ur=='/my_interests.php')  $_REQUEST['type']='flirt';
if($ur=='/interested_in_me.php')  $_REQUEST['type']='whfrt';
if($ur=='/whoson.php')  $_REQUEST['type']='online';
if($ur=='/various_search.php')  $_REQUEST['type']='new';
if($ur=='/latest_videos.php')  $_REQUEST['type']='video';
if($ur=='/latest_audios.php')  $_REQUEST['type']='audio';
if($ur=='/latest_gallery.php')  $_REQUEST['type']='gallery';
if($ur=='/latest_photo.php')  $_REQUEST['type']='photo';
if($ur=='/hearAudio.php')  $_REQUEST['case']='audio';
if($ur=='/seePeople.php')  $_REQUEST['case']='people';
if($ur=='/index.php')  $_REQUEST['case']='home';
if($ur=='/about.php')  $_REQUEST['case']='about';
if($ur=='/site_tour.php')  $_REQUEST['case']='tour';
if($ur=='/register.php')  $_REQUEST['case']='reg';
if($ur=='/tellafriend.php')  $_REQUEST['case']='tell';
if($ur=='/contact.php')  $_REQUEST['case']='contact';
if($ur=='/manage_items.php')  { $_REQUEST['case']='med'; $_REQUEST['type']='g';}


?>