<?php
	session_start(); 
	$username=trim($_POST['username']);
	$password=trim($_POST['password']);
	$suffix_str=$_GET['suffix_str'];
	
	require_once('ls_admin/inc/conn.php');
	$opendb=new mydb();

	
	$config_sql="select * from ls_config ";
	$config_query=$opendb->query($config_sql);
	$config_row=mysqli_fetch_assoc($config_query);
	
	if(empty($username) || empty($password))
	{
		echo 
					"<script>
						alert('Please input the username and password'); 
						location='index.html';
					</script>";
	}
  else
  {
	  	
		$sqlstr="select * from ls_users where  userName='".$username."'";
	
		$query1=$opendb->query($sqlstr);
		$rows=mysqli_fetch_assoc($query1);
		$myrows=mysqli_num_rows($query1); 
		if($myrows==0)
		{
			echo "
					<script>
						alert('Username or password error');
						location='downloadlogin.php?suffix_str=".$suffix_str."';
					</script>
					";
		}
		
		if($password!=$rows['userPwd'])
		{
			echo "
					<script>
						alert('Username or password error');
						location='downloadlogin.php?suffix_str=".$suffix_str."';	
					</script>
					";
		} 
    else
    {
		if($rows['enable']==1)
		{
			$_SESSION['username_download']=$username;
			$_SESSION['id']=$rows['ID'];

			//$_SESSION['password']=$password;
			
  		  header("location:download_".$suffix_str.".php");	
		}
		else
		{
			echo "<script>alert(\"Your account is not actived, please contact webmaster ".$config_row['feedbackEmail']."\");\r\n location='downloadlogin.php';</script>\r\n";
		//<a href='mailto:".$config_row['email']."&subject=Please active the account ".$rows['userName']." '></a>
		}
    
    
    }
	
  }
  
?>