<?php

function get_browser2() {

	global $_SERVER;

	$u_agent=$_SERVER['HTTP_USER_AGENT'];

	if (eregi("(opera) ([0-9]{1,2}.[0-9]{1,3}){0,1}",$u_agent,$st_regs) || eregi("(opera/)([0-9]{1,2}.[0-9]{1,3}){0,1}",$u_agent,$st_regs)) {

		$st_brows = "Opera ";

		$st_ver = $st_regs[2];

	} elseif(eregi("(konqueror)/([0-9]{1,2}.[0-9]{1,3})",$u_agent,$st_regs)) {

		$st_brows = "KONQ";

		$st_ver = $st_regs[2];

		$st_sys = "Linux ";

	} elseif(eregi("(lynx)/([0-9]{1,2}.[0-9]{1,2}.[0-9]{1,2})",$u_agent,$st_regs) ) {

		$st_brows = "Lynx ";

		$st_ver = $st_regs[2];

	} elseif(eregi("(links) \(([0-9]{1,2}.[0-9]{1,3})",$u_agent,$st_regs)) {

		$st_brows = "Links ";

		$st_ver = $st_regs[2];

	} elseif(eregi("(omniweb/)([0-9]{1,2}.[0-9]{1,3})",$u_agent,$st_regs)) {

		$st_brows = "OmniWeb ";

		$st_ver = $st_regs[2];

	} elseif(eregi("(webtv/)([0-9]{1,2}.[0-9]{1,3})",$u_agent,$st_regs)) {

		$st_brows = "WebTV ";

		$st_ver = $st_regs[2];

	} elseif(eregi("(msie) ([0-9]{1,2}.[0-9]{1,3})",$u_agent,$st_regs)) {

		$st_brows = "Internet Explorer ";

		$st_ver = $st_regs[2];

	} elseif(eregi("(Firefox/)([0-9]{1,2}.[0-9]{1,2}.[0-9]{1,2})",$u_agent,$st_regs)) {

		$st_brows = "Mozzila Firefox ";

		$st_ver = $st_regs[2];

	} elseif(eregi("(Chrome/)([0-9]{1,2}.[0-9]{1,2})",$u_agent,$st_regs)) {

		$st_brows = "Chrome ";

		$st_ver = $st_regs[2];

	} elseif(eregi("(netscape6)/(6.[0-9]{1,3})",$u_agent,$st_regs)) {

		$st_brows = "Netscape Navigator ";

		$st_ver = $st_regs[2];

	} elseif(eregi("(rv:)([0-9]{1,2}.[0-9]{1,2})(\))( ){0,1}(Gecko/)",$u_agent,$st_regs)) {

		$st_brows = "Mozzila ";

		$st_ver = $st_regs[2];

	} elseif(eregi("(mozilla)/([0-9]{1,2}.[0-9]{1,3})",$u_agent,$st_regs)) {

		$st_brows = "Netscape Navigator ";

		$st_ver = $st_regs[2];

	} elseif(eregi("w3m",$u_agent)) {

		$st_brows = "w3m";

	} elseif(eregi("(scooter)-([0-9]{1,2}.[0-9]{1,3})",$u_agent,$st_regs)) {

		$st_brows = "Scooter";

		$st_ver = $st_regs[2];

	} elseif(eregi("(w3c_validator)/([0-9]{1,2}.[0-9]{1,3})",$u_agent,$st_regs)) {

		$st_brows = "W3C";

		$st_ver = $st_regs[2];

	} elseif(eregi("(googlebot)/([0-9]{1,2}.[0-9]{1,3})",$u_agent,$st_regs)) {

		$st_brows = "Google";

		$st_ver = $st_regs[2];

	} else {

		$st_brows = $i18n['welcome']['unknown'];

		$st_ver = "";

	}

	return $st_brows.$st_ver;

}



function get_os() {

	global $_SERVER;

	$u_agent = $_SERVER['HTTP_USER_AGENT'];

	if (eregi("linux",$u_agent)) $st_sys = "Linux";

	elseif(eregi("Win 9x 4.90",$u_agent)) $st_sys = "MS Windows Me";

	elseif(eregi("win32",$u_agent)) $st_sys = "Win 32";

	elseif(eregi("windows 2000",$u_agent)) $st_sys = "MS Windows 2000";

	elseif((eregi("(win)([0-9]{2})",$u_agent,$st_regs)) || (eregi("(windows) ([0-9]{2})",$u_agent,$st_regs))) $st_sys = "MS Windows ".$st_regs[2];

	elseif(eregi("(windows nt)( ){0,1}(5.0)",$u_agent,$st_regs)) $st_sys = "MS Windows 2000";

	elseif(eregi("(windows nt)( ){0,1}(5.1)",$u_agent,$st_regs)) $st_sys = "MS Windows XP";

	elseif(eregi("(winnt)([0-9]{1,2}.[0-9]{1,2}){0,1}",$u_agent,$st_regs)) $st_sys = "MS Windows NT".$st_regs[2];

	elseif(eregi("(windows nt)( ){0,1}([0-9]{1,2}.[0-9]{1,2}){0,1}",$u_agent,$st_regs)) $st_sys = "MS Windows NT".$st_regs[3];

	elseif(eregi("PPC",$u_agent) || eregi("Mac_PowerPC",$u_agent)) $st_sys = "Mac PPC";

	elseif(eregi("mac",$u_agent)) $st_sys = "Mac";

	elseif(eregi("(sunos) ([0-9]{1,2}.[0-9]{1,2}){0,1}",$u_agent,$st_regs)) {

		$st_sys = "SunOS";

		$st_sysver = $st_regs[2];

	} elseif(eregi("(beos) r([0-9]{1,2}.[0-9]{1,2}){0,1}",$u_agent,$st_regs)) {

		$st_sys = "BeOS";

		$st_sysver = $st_regs[2];

	} elseif(eregi("freebsd",$u_agent)) $st_sys = "FreeBSD";

	elseif(eregi("openbsd",$u_agent)) $st_sys = "OpenBSD";

	elseif(eregi("irix",$u_agent)) $st_sys = "IRIX";

	elseif(eregi("os/2",$u_agent)) $st_sys = "OS/2";

	elseif(eregi("plan9",$u_agent)) $st_sys = "Plan9";

	elseif(eregi("unix",$u_agent) || eregi("hp-ux",$u_agent) ) $st_sys = "Unix";

	elseif(eregi("osf",$u_agent)) $st_sys = "OSF";

	elseif(eregi("X11",$u_agent) && !isset($st_sys)) $st_sys = "Unix";

	else $st_sys=$i18n['welcome']['unknown'];

	return $st_sys;

}



$sql="";

if (isset($ui["login"]) && $ui["password"]) {

	$ui["login"]=addslashes($ui["login"]);

	$ui["password"]=addslashes($ui["password"]);

        $sql="select * from users".$config["table_prefix"]." where login='$ui[login]' and password='$ui[password]' and status='1'";

} elseif(isset($login) && isset($password)) {

	if (!get_magic_quotes_gpc()) {

		$login_def=$login;

		$login=addslashes($login);

		$password=addslashes($password);

	} else  $login_def=stripcslashes($login);

	$_SESSION['login_def']=$login_def;

        $sql="select * from users".$config["table_prefix"]." where login='$login' and password='$password' and status='1'";

}

$rs=$db->select($sql);

if (count($rs)) {

        $ui["id"]=$rs[0]["id"];

        $ui["login"]=$rs[0]["login"];

        $ui["password"]=$rs[0]["password"];

        $ui["system_status"]=$rs[0]["system_status"];

        $_SESSION['ui']=$ui;

        $page->section("ACCOUNT");

	$page->assign(array(

		"a_login"	=> $rs[0]["login"],

		"a_mail"	=> $rs[0]["mail"],

		"a_name"	=> $rs[0]["name"],

		"a_ip"		=> $_SERVER['REMOTE_ADDR'],

		"a_os"		=> get_os(),

		"a_browser"	=> get_browser2(),

	));

} else {

        if (isset($_SESSION['ui'])) unset($_SESSION['ui']);

	$page = new Template("templates/first.tpl");

	$page->dictionary("common/dict.ru");

        $page->section("LOGIN");

	$page->assign(array(

		"PATH"  => $PATH,

                "login" => htmlspecialchars($login_def),

		"alert"	=> (isset($login) ? "{rs:ERROR_AUTH}" : ""),

	));

        print $page->evaluate();

        exit;

}

?>