<?php
ob_start();
require_once("init.php");
$cookiedir = substr($_SERVER['PHP_SELF'],0,-15);

$tmpl = new Koobi("templates/" . ADMINTHEME . "/");

if($_REQUEST['send']==1){
	if (!empty($_POST['kname']) && !empty($_POST['kpass'])) {
		$sql = new dbc("SELECT uid,email,uname,pass,status FROM ".PREFIX."_user WHERE (uname='".$_POST['kname']."' AND pass='".md5($_POST['kpass'])."') AND status='1'  LIMIT 1");
		$row = $sql->fetchrow();
		$name = $row->uname;
		
		
		if(bannedname($_POST['kname'])){
			setcookie("kuid", "" , time()-10000);
			setcookie("kpass", "" ,time()-10000);
			$row = "";
			$banned = 1;
			$msg .=  $langadmin['isbanned'];
		}
		
		
		if(bannedemail($row->email)){
			setcookie("kuid", "" , time()-10000);
			setcookie("kpass", "" ,time()-10000);
			$row = "";
			$banned = 1;
			$msg .=  $langadmin['isbanned_email'];
		}
		
		if(!$row->uid){
			if($msg){
			$msg = $msg; } else {
				$msg =  $langadmin['wronglogin'];
			}
		} else {
			
			
			
			if ($row->uid) {
				
				setcookie("kuid", $row->uid, time()+(365*24*3600), $cookiedir);
				setcookie("kpass",md5($_REQUEST['kpass']),time()+(365*24*3600), $cookiedir);
				$login="ok";
				
				header("Location:admin.php");
			}
		}
	}
	
	if ((!$_POST['kname'] || !$_POST['kpass']) && (!$login)) {
		$msg =  $langadmin['wronglogin'];
	}
}

$tmpl->assign("theme", ADMINTHEME);
$tmpl->assign("lang", $lang);
$tmpl->assign("langadmin", $langadmin);
$tmpl->assign("kversion", KVERSION);
$tmpl->assign("msg", $msg);

$tmpl->display("login.tpl");
?>