<?php
function check_admin() {
@require_once("../../../../config.php");
	$link = @mysql_connect($dbhost, $dbuname, $dbpass);
	if (!$link)
	{
	echo "Non puņ essere effettuata la connessione a MySQL.<br />";
	echo "Errore di MySQL: (" . mysql_errno() . ") " . mysql_error() . " \n";
	die("<br />MANUTENZIONE");
	}
if(isset($HTTP_COOKIE_VARS)) {
    $_COOKIE = $HTTP_COOKIE_VARS;
  }
$admin = $_COOKIE['admin'];

if (!$admin) { echo "NON PRESENTE"; }
if (!$admin) { return 0; }

static $adminSave; 
    
if (isset($adminSave)) return $adminSave;
$admin = base64_decode($admin);
$admin = addslashes($admin);
$admin = explode(':', $admin);

$aid = $admin[0];
$pwd = $admin[1];
$site_id = $admin[3];


//echo "- cookie";
//echo  "<br />- ".$aid;
//echo  "<br />- ".$pwd;
//echo  "<br />- ".$site_id;


static $adminSave; 
if (isset($adminSave)) return $adminSave;
$aid = substr(addslashes($aid), 0, 25);
if (!empty($aid) && !empty($pwd)) {
if (empty($siteid) OR ($siteid <'1')) $siteid='1';
		

	$query = "SELECT pwd, site_id FROM {$dbname}.{$prefix}_authors WHERE aid='$aid'";
	$result = mysql_query($query, $link);
	if (!$result)
		{
			echo " Errore di MySQL: (" . mysql_errno() . ") " . mysql_error() . " \n";
			exit();
		}
	
$pass = mysql_fetch_row($result);
mysql_free_result($result);
//echo "<br />Database";
//echo "<br />".$pass[0];
//echo "<br />".$pass[1];


if ((($pass[0] == $pwd && !empty($pass[0])) AND ($pass[1] == $siteid && !empty($pass[1])))) {
        	
			//echo "<br />1".$adminSave;
			return $adminSave = 1;
        } else {

    
    
	//echo "<br />0".$adminSave;
	return $adminSave = 0;
	}
}
}

check_admin();
?>