<?

/************************************************************************/
/* FlatNuke - Flat Text Based Content Management System                 */
/* ============================================                         */
/*                                                                      */
/* Copyright (c) 2003 by Simone Vellei                                  */
/* http://flatnuke.sourceforge.net                                      */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/

if (eregi("login.php",$_SERVER['PHP_SELF'])) {
    Header("Location: ../../index.php");
    die();
}

// count signaled news
function count_sig() {
	$proplist = array();
	$handle = opendir(get_fn_dir("var"));
	while($file = readdir($handle)) {
		if(eregi("^news_[0-9]+\.xml$", $file)) {
			array_push($proplist, $file);
		}
	}	//echo "<pre>";print_r($proplist);echo "</pre>";	//-> TEST
	closedir($handle);
	return(count($proplist));
}

// Security checks
$req = getparam("REQUEST_URI", PAR_SERVER, SAN_FLAT);
if(strstr($req,"myforum="))
	die(_NONPUOI);

// user is not logged
if(is_guest()) {
	?><div align="center">
	<form action="index.php?mod=none_Login" method="post">
	<input type="hidden" name="action" value="login" />
	<input type="hidden" name="from" value="home" />
	<label for="username"><?= _NOMEUTENTE ?>:</label><br />
	<input alt="username" name="nome" size="10" id="username" style="color:grey" value="Username" onfocus="if(this.value=='Username'){this.value='';}" onblur="if(this.value==''){this.value='Username';}" /><br />
	<label for="password"><?= _PASSWORD ?>:</label><br />
	<input alt="password di accesso" name="logpassword" type="password" size="10" id="password" style="color:grey;" value="********" onclick="javascript:this.value='';" /><br /><?
	// remember login checkbox
	global $remember_login;
	if($remember_login==1) {
		echo "<div style=\"margin:1em;\"><label for=\"rememberlogin\">"._REMEMBERLOGIN."</label>";
		echo "<input type=\"checkbox\" alt=\"remember_login\" name=\"rememberlogin\" id=\"rememberlogin\" /><br />";
		echo "</div>";
	} else echo "<br />";
	// login button
	?><input type="submit" value="<?= _LOGIN ?>" />
	</form><?
	// link to register
	global $reguser;
	if ($reguser=="1" or $reguser=="2"){
		echo _NONREG
		?><br /><a href="index.php?mod=none_Login&amp;action=visreg" title="<?=_REGORA?>"><b><?=_REGORA?></b></a>
                <br /><a href="index.php?mod=none_Login&amp;action=passwordlost" title="<?=_NEWPWDSTRING?>"><b><?=_NEWPWDSTRING?></b></a><?
	}
	// load external code
	echo "<div style='padding-left:0.5em;'>";
	load_php_code("include/blocks/login");
	echo "</div>";
	?></div><?
}
// user is logged
elseif(is_user() OR is_admin()) {
	$userdata = array();
	$userdata = load_user_profile(get_username());
	// print user name
	$username = get_username();
	print _BENVENUTO." <b><a href='index.php?mod=none_Login&amp;action=viewprofile&amp;user=$username' title=\""._VIEW_USERPROFILE."\">$username</a></b>!<br /><br />";
	print "<div align='center'>";
	print "<a href='index.php?mod=none_Login&amp;action=viewprofile&amp;user=$username' title=\""._VIEW_USERPROFILE."\">";
	// print avatar
	$img = $userdata['avatar'];
	if($img!="") {
		if(!stristr($img,"http://"))
			echo "<img src='forum/$img' alt='$username' border='0' style='max-width:95%' />";
		else echo "<img src='$img' alt='$username' border='0' style='max-width:95%' />";
	}
	else echo "<img src='forum/images/blank.png' alt='$username' border='0' style='max-width:95%' />";
	print "</a></div><br />";
	// print user level
	$level = $userdata['level'];
	if(!file_exists("themes/$theme/images/level_y.gif") OR !file_exists("themes/$theme/images/level_n.gif")) {
		$level_img_y = "images/useronline/level_y.gif";
		$level_img_n = "images/useronline/level_n.gif";
	} else {
		$level_img_y = "themes/$theme/images/level_y.gif";
		$level_img_n = "themes/$theme/images/level_n.gif";
	}
	print "<div style='position:relative;float:left;width:30px;'>0</div>";
	print "<div style='position:relative;float:right;width:30px;text-align:right;'>10</div>";
	print "<div style='position:relative;margin-left:0px;margin-right:0px;text-align:center;'><b>"._LEVEL." $level</b></div>";
	print "<div align='center'>";
	print "<hr size='1' noshade width='100%' />";
	for($i=0; $i<$level; $i++) {
		print "<img src='$level_img_y' alt='level' />";
	}
	for($j=$i; $j<10; $j++) {
		print "<img src='$level_img_n' alt='level' />";
	}
	print "<hr size='1' noshade width='100%' />";
	print "</div>";

	// administrator panel
	if(is_admin()) {
		?><div style="padding-left:0.5em;">
		&#187;&nbsp;<a href="index.php?mod=none_Admin" title="<? echo _MANAGEFLATNUKE; ?>"><?= _MANAGEFLATNUKE ?></a><br />
		&#187;&nbsp;<a href="index.php?mod=none_Admin&amp;op=fnccnews" title="<? echo _ADDNEWS; ?>"><?= _ADDNEWS ?></a>
		<?
		if(count_sig()>0) {
			?><br />&#187;&nbsp;<a href="index.php?mod=none_Admin&amp;op=fnccpropnews" title="<? echo _SEGNNOTIZIE; ?>"><?= _SEGNNOTIZIE ?> (<?=count_sig()?>)</a><?
		}
		?></div>
		<hr size="1" noshade width="100%" align="center" /><?
	}
	// load external code
	echo "<div style='padding-left:0.5em;'>";
	load_php_code("include/blocks/login");
	echo "</div>";
	// logout
	echo "<div align='right'><a href='index.php?mod=none_Login&amp;action=logout&amp;from=home' title=\""._LOGOUT."\"><b>"._LOGOUT."</b></a></div>";
}
else echo "Cookie mismatch, please <a href='index.php?mod=none_Login&amp;action=logout&amp;from=home'>delete your cookies!</a>";
?>
