<?php
//TODO @2014-03-21 BUG zmienic sposob autoryzacji na domyslny

function AUTHORIZE_USER_LOGIN( $ADM_ACCOUNT, $ADM_PASSWD ) {
global $SQL_USER,$SQL_DATABASE,$INTERFACE_ADDR,$SQL_USER_PASS;
			Lib::loadClass('Config');
			$conf = Config::getConfFile('default_db');

//echo "<hr>AUTHORIZE_USER_LOGIN User $SQL_USER Adm_Account=$ADM_ACCOUNT mysql_pconnect($INTERFACE_ADDR,$SQL_USER,$SQL_USER_PASS);";
$conn = mysql_pconnect($conf['host'], $conf['user'], $conf['pass']);
//$conn=DB::getdb();

			
if (!$conn) die("ERROR podczas tworzenia polaczenia do bazy $SQL_DATABASE !\n");
mysql_select_db($conf['database']) or die("ERROR podczas wyboru bazy R502!".mysql_error());

//User::login($ADM_ACCOUNT, $ADM_PASSWD);

$zapSQL = "SELECT u.*
	from `ADMIN_USERS` as u
	where
		u.`ADM_ACCOUNT`='".$ADM_ACCOUNT."'
		and ( u.`ADM_PASSWD`='".$ADM_PASSWD."' or u.`ADM_PASSWD`=md5('".$ADM_PASSWD."') )
		and u.`A_STATUS` in('WAITING','NORMAL')
	LIMIT 0,1;
";
//echo "$zapSQL";
$result = mysql_query($zapSQL, $conn) or die("Blad zapytania2!".mysql_error());
$num_rows = mysql_num_rows($result);

//echo "<BR>LICZBA_WIERSZY $num_rows<BR>";
if ($num_rows == 0) {
	echo "Podales zlego uzytkownika lub/i haslo()" ;
}
else if ($num_rows == 1) {
	if ($h = mysql_fetch_object($result)) {
		// if(( $ADM_ACCOUNT = $h->ADM_ACCOUNT ) && ( $ADM_ACCOUNT = $h->ADM_ACCOUNT )) {
		$_SESSION['ADM_PASSWD']=$ADM_PASSWD;
		$_SESSION['AUTHORIZE_USER']="$h->ADM_ACCOUNT";
		$_SESSION['ADM_ACCOUNT']="$h->ADM_ACCOUNT";
		$_SESSION['ADM_AREA']="$h->ADM_AREA";
		$_SESSION['ADM_NAME']="$h->ADM_NAME";
		$_SESSION['ADM_TECH_WORKER']="$h->ADM_TECH_WORKER";
		$_SESSION['ADM_COMPANY']="$h->ADM_COMPANY";
		$_SESSION['ADM_ADMIN_LEVEL']="$h->ADM_ADMIN_LEVEL";
		$_SESSION['ADM_PHONE']="$h->ADM_PHONE";
		$_SESSION['ADM_ADMIN_EXPIRE']="$h->ADM_ADMIN_EXPIRE";
		$_SESSION['ADM_ADMIN_DESC']="$h->ADM_ADMIN_DESC";
		$_SESSION['ADM_ID']="$h->ID";

		// SQL_WIEV();
		SEF('USERS_COLUMN_INIT');
		USERS_COLUMN_INIT();
		// }
	}
}


}
