<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.com>        		              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com � 2007                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?php
/*---------Multicart 2.0 Upgradation starts----------*/

$username_flag = 1;
$password_flag = 0;

/*---------Multicart 2.0 Upgradation ends----------*/


if(isset($_POST['loginbox'])){

   $txtUserName = $_POST["txtUserName"];
         
   $txtPassword = $_POST["txtPassword"];
	/*$sql=" SELECT user_id,user_name,password FROM ".$tableprefix."users WHERE user_name='".addslashes($txtUserName)."' AND password = '".addslashes(md5($txtPassword))."' AND deleted = 'N'";
	$result=mysql_query($sql) or die(mysql_error());
	if(mysql_num_rows($result) > 0 ){
			$row = mysql_fetch_array($result);
			$message="Success!";
			$_SESSION["sess_username"] = $row["user_name"];
			$_SESSION["sess_userid"] = $row["user_id"];*/

/*----------Multicart 2.0 Upgradation starts-----------*/

	
/*---------Checking the password----------------*/	
			
	$select_password = "SELECT password FROM ".$tableprefix."users WHERE user_name = ".GetSQLValueString($txtUserName,"text").
						" AND deleted = 'N'";
			
	$result_password = mysql_query($select_password) or die(mysql_error());			
	if(mysql_num_rows($result_password) > 0)
	{
	
		$password_row = mysql_fetch_assoc($result_password);
						
		if(GetSQLValueString($password_row['password'],"text") != GetSQLValueString(md5($txtPassword),"text"))
		{
		
			//$messagelog = "Invalid password !!";
			$password_flag = 1;
			
		}
	
	
	}
			
	//else
	//{
	
/*---------Checking the username----------------*/		
	
		$select_username = "SELECT user_name FROM ".$tableprefix."users 
							WHERE password = ".GetSQLValueString(md5($txtPassword),"text").
							" AND deleted = 'N'";
		
		$result_username = mysql_query($select_username) or die(mysql_error());			
		if(mysql_num_rows($result_username) > 0)
		{
		
			while($username_row = mysql_fetch_array($result_username))
			{
							
				if(GetSQLValueString($username_row['user_name'],"text") == GetSQLValueString($txtUserName,"text"))
				{
					$username_flag = 0;
				}
							
				/*if(GetSQLValueString($username_row['user_name'],"text") != GetSQLValueString($txtUserName,"text"))
				{
				
					$messagelog = "Invalid username !!";
					$username_flag = 1;
				
				}
				else
				{
				
					$username_flag = 0;
				
				}*/
			}	
		
		
		}
										
		if($username_flag == 1 && $password_flag == 0)
		{
			$messagelog = "Invalid username !!";
		}
		
		if($username_flag == 1 && $password_flag == 1)
		{
			$messagelog = "Invalid password !!";
		}
		
	//}	
	
	if($username_flag != 1 && $password_flag != 1)
	{
			
		$sql=" SELECT user_id,user_name,password FROM ".$tableprefix."users 
				WHERE user_name='".addslashes($txtUserName)."' AND password = '".addslashes(md5($txtPassword))."' AND deleted = 'N'";
		$result=mysql_query($sql) or die(mysql_error());
		if(mysql_num_rows($result) > 0 )
		{
			$row = mysql_fetch_array($result);
			$message="Success!";
			$_SESSION["sess_username"] = $row["user_name"];
			$_SESSION["sess_userid"] = $row["user_id"];
			
/*---------------Multicart 2.0 Upgradation------------------*/				
				
/*-------function call to manage the different sessions--------*/

				manageSession(3);
				
/*---------------Multicart 2.0 Upgradation------------------*/				
		
			if(!isVisitorCartEmpty(session_id()))
			{
				mergeVisitorCartToUserCart(session_id(),$row["user_id"]);
			}
			if($action!= "")
			{
				if($action == "checkout")
				{
					echo "<script>location.href='viewcart.php';</script>";
					//header("Location:viewcart.php");
					exit;
				}
			}
			else
			{
			
/*--------Multicart 2.0 starts-----------*/			
			
			    /*echo "<script>location.href='usermain.php';</script>";*/
				
				echo "<script>location.href='viewcart.php';</script>";
				
/*--------Multicart 2.0 ends-----------*/				
				
				//header("Location:usermain.php");
				exit;
			}

	}	
	else
	{
		$messagelog = "Invalid username and password !!";

	}
	
}	

/*----------Multicart 2.0 Upgradation ends-----------*/		

}else if(isset($_POST['newuser'])){
       echo "<script>location.href='register.php';</script>";
	  exit;
	  
	  
	  
}
?>



<!--User side javascript checking-->

<script src="./js/javascript_check_userside.js"></script>

<!--User side javascript checking-->

<script>

function checkLoginForm()
{

  var form_name = new Array('txtUserName','txtPassword');		
  var display_name = new Array('User Name','Password');
  var count = 2;	

  if(check_fieldsUser('frmLogin',form_name,display_name,count))	
  {
  
	
		   
  }
  else
  {
  
		return false;
  
  }
   
}

function openuserhelp()
{

	var url = './help/userhelp/index.html'
	window.open(url,"Help","scrollbars=yes");
}	

</script>



<!--
<body onload="MM_preloadImages('<?php //php echo $active_template[3]?>/new_items_h.gif')">
-->
	<body>

	<center>

	<div align="left" id="layout">
	
		<div align="left" id="header">
		<!--header area start -->
				
				<div align="left" id="logo"><a href="<?php echo SITE_URL?>/index.php">
					
<?php
	
    if(basename($_SERVER['PHP_SELF']) == "payment.php" || basename($_SERVER['PHP_SELF']) == "yourpay_payment.php") 
	{
?>
					
		<img src="<?php echo SECURE_SITE_URL?>/banners/<?php echo $logoimage?>" alt="" width="125" height="50" border="0" />			
					
<?php

	}
	else
	{
	
?>
						
		<img src="<?php echo $logofolder?>/<?php echo $logoimage?>" alt="" width="125" height="50" border="0" />
					
					
<?php
	
	}

?>					
					
					</a>
				</div>
				
				<div align="right" id="header_right">&nbsp;	</div>	
		
		<br>	
		<br>
		<br>
		<br>
				
		<!--header area end -->
		
		
		
		
				<div align="right" class="search_area">&nbsp;
			  	</div>			
		
		</div>
		
				
		
		<div align="left" id="links_container">
		<!--links area start -->
		
				<div align="center" class="links">&nbsp;
				</div>
		  			
		<!--links area end -->
		</div>
		<div style="height:180px">&nbsp;</div>

		<div align="center" id="banner_container">&nbsp;<font size="+1" face="Arial, Helvetica, sans-serif">Invalid License. Please contact <b><?php echo $admin_email;?></b></font>
		</div>