<?php 
//+-----------------------------------------------------+//
//+ Copyright Floopo.com
//+ admin_login.php
//+ Logging in
//+-----------------------------------------------------+//

defined('BASEPATH') or die('You can not directly access this file');//check its within this framework

//____DEFAULT TEMPLATE_____________________________
$template = ADMIN_TEMPLATES.'tpl_login.htm';


//____CHECK IF SETUP DIR IS STILL THERE_____________
$setup_file = BASEPATH.'/setup/index.php';
if (file_exists($setup_file)) {
    echo '
<div align="center">
	&nbsp;<p>&nbsp;</p>
	<table width="556" id="table1" style="border: 1px solid #FF3300; " cellspacing="0" cellpadding="0" bgcolor="#FFDDDD">
		<tr>
			<td bgcolor="#FFECEC">
			<table border="0" width="100%" id="table2" cellspacing="0" cellpadding="0">
				<tr>
					<td width="30">
			</td>
					<td height="20">
					<p align="center"><font face="Arial" size="2">Error! - You must delete the /setup folder to continue</font></td>
				</tr>
			</table>
			</td>
		</tr>
	</table>
</div>
<p align="center"><font color="#FF0000"><a href="index.php?option=com_admin">
<font color="#000080" face="Arial">try again</font></a></font></p>';
    die();
}



//____Mysql: Connect to dbase______________________
$dbase = new QuickMysql(DB_NAME, DB_USER, DB_PASS, DB_HOST);


//____Login if Submitted___________________________
if (isset($_POST['login'])) {
    $user_name = Sanatize($_POST['user_name']);
    $password = md5(Sanatize($_POST['password']));


//form filled in check
$process = new FormProcessor();
if($process->RequiredFields('all')){

//check if login is correct
$result = $dbase->SelectRecord("SELECT * FROM siteadmin WHERE user_name = '$user_name' AND password = '$password'");

//If login is correct - redirect
if(!empty($result)){
$_SESSION['admin'] = 1;
}else{
$notification = $lang['invalid_login'];
}

}else{
$notification = $lang['fill_in_all'];
}
}




//____Logout___________________________
if (isset($_GET['logout']) && $_GET['logout'] == 1) {
    @session_destroy();
    $redirect_url = BASEURL.'/index.php?option=com_admin_login';
    @header("Location: ".$redirect_url);
}


//____Redirect if logged in___________
($_SESSION['admin'] == 1) ? @header("Location: ".BASEURL.'/index.php?option=com_admin'): NULL;


//____Display any output_________________________
$TBS = new clsTinyButStrong;
$TBS->NoErr = true;
$TBS->LoadTemplate($template);
$TBS->MergeField('formdata',$_POST);
$TBS->MergeField('config',$config);
$TBS->MergeField('lang',$lang);
$TBS->Render = TBS_OUTPUT;
$TBS->Show();
@mysql_close();

/*-----------------------------------------------------

Types
-----
1 = activation of new user





-------------------------------------------------------*/ ?>