<?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 � 2005                |
// | 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
include "../includes/config.php";
include "../includes/session.php";
include "../includes/functions.php";

if($_SESSION["sess_artistid"] != "" && !isset($_GET['from']))
{
	header("Location:artistmain.php");
}	

if(isset($_GET['from']) and $_GET['from'] =='upgrade' and $_SESSION["sess_artistid"] != "")

{
	 header("Location:seller_plan_upgrade.php?sellerid=".$_SESSION["sess_artistid"]);
	 exit;
}

if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE); 
} 



//Remember Me
$remembered = false;
$json = isset($_COOKIE['mcart_seller']) ? stripslashes($_COOKIE['mcart_seller']) : '';
if($json != '')
{
    $cookieArr = json_decode($json);
    
    if($cookieArr->usr != '' && $cookieArr->pwd != '')
    {
        $txtUserName = base64_decode($cookieArr->usr);
        $txtPassword = base64_decode($cookieArr->pwd);
        $remembered = true;
    }
}



$username_flag = 1;
$password_flag = 0;

$message="";
$stat=$_GET['stat'];

if(!empty($stat)&& $stat=="Y" )
{
	
	$message=MSG_ACC_APPR_SUC;
}
if(isset($_GET['from']))
{
	$from	=$_GET['from'];
}
else if(isset($_POST['from']))
{
	$from	=$_POST['from'];
}
if(isset($_POST["submit"]))
{
    $txtUserName = $_POST["txtUserName"];
    $txtPassword  = $_POST["txtPassword"];
	/*---------Checking the password----------------*/	
			
	$select_password = "SELECT password FROM ".$tableprefix."artists 
						WHERE LOWER(artist_name) = ".strtolower(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"))
		{
		
			//$message = "Sorry, the password you submitted is not present in our database !!";
			$password_flag = 1;
			
		}
	}
/*---------Checking the username----------------*/		
	
		$select_username = "SELECT artist_name FROM ".$tableprefix."artists 
							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(strtolower(GetSQLValueString($username_row['artist_name'],"text")) == strtolower(GetSQLValueString($txtUserName,"text")))
				{
				
					//$message = "Sorry, the username you submitted is not present in our database !!";
					$username_flag = 0;
				
				}
				
			}	
		
		}
		if($username_flag == 1 && $password_flag == 1)
		{
			$message = MSG_PASS_INCORCT;
		}
		if($username_flag == 1 && $password_flag == 0)
		{
			$message = MSG_UNAME_INCORCT;
		}
		
		if($username_flag != 1 && $password_flag != 1)
		{				

			$sql = "SELECT artist_id,artist_name,password, vapproved,plan_expired FROM ".$tableprefix."artists 
					WHERE artist_name='".addslashes($txtUserName)."' 
					 AND password = '".addslashes(md5($txtPassword))."' AND deleted = 'N' AND vapproved='Y' ";
			$result=mysql_query($sql) or die(mysql_error());
			
			if(mysql_num_rows($result) > 0 )
			{
					$row = mysql_fetch_array($result);
					$message="Success!";
					$_SESSION["sess_artistname"] = $row["artist_name"];
					$_SESSION["sess_artistid"] = $row["artist_id"];
					
					$exipry_status	= $row["plan_expired"];
					
			// Ending Session for User, Affiliates		
			if(isset($_SESSION["sess_userid"]) and $_SESSION["sess_userid"]!= "")
			{ // Logging Out User  from same window
			if(function_exists('session_unregister')) {
				session_unregister($_SESSION["sess_userid"]);
                        }
                        else{
                            unset($_SESSION["sess_userid"]);
                        }
					
			}
			if(isset($_SESSION["sess_affiliateid"]) and $_SESSION["sess_affiliateid"]!= "")
			{ // Logging Outaffliliate  from same window
			if(function_exists('session_unregister')){
				session_unregister($_SESSION["sess_affiliateid"]);
                        }else{
                            unset($_SESSION["sess_affiliateid"]);
                        }
					
			}
			if($exipry_status=='Y')
			{
				
				header("Location:seller_plan_upgrade.php?sellerid=".$_SESSION["sess_artistid"]);
				 exit;
			}
			if(isset($_POST['from']) and  $_POST['from']=='upgrade')
			{
				 header("Location:seller_plan_upgrade.php?sellerid=".$_SESSION["sess_artistid"]);
				 exit;
			}
	// End check 		
                        if(isset($_POST['rememberme']))
                                {
                                    $value = array('usr' => base64_encode($txtUserName), 'pwd' => base64_encode($txtPassword));
                                    setcookie("mcart_seller", json_encode($value), time()+3600*24*30);
                                }
                                else
                                {
                                    setcookie("mcart_seller", json_encode($value), time() - 3600);
                                }
					header("Location:artistmain.php");
					
/*---------------Multicart 2.0 Upgradation------------------*/				
				
/*-------function call to manage the different sessions--------*/

				manageSession(2);
				
/*---------------Multicart 2.0 Upgradation------------------*/					

					exit;
			}
			else
			{
					$message = MSG_ACC_NOT_APPR;
		
			}

		}
}

include "../includes/htmltop.php";
?>
<script>
	function checkArtistLoginForm()
	{
	
	  var form_name = new Array('txtUserName','txtPassword');		
	  var display_name = new Array('User Name','Password');
	  var count = 2;	
	
	  if(check_login('frmLogin',form_name,display_name,count))	
	  {
			
	  }
	  else
	  {
			return false;
	  }
	   
	}
	function resetAll()
	{
		document.getElementById("txtUserName").value="";
		document.getElementById("txtPassword").value="";
	}
</script>
		
		<div align="left" id="layout">
				<!--header area start -->
<?php
	include_once("../includes/topheader_seller.php")
?>
				<!--header area end -->
				<div align="left" class="main_body">
				<!--main body start -->
<?php
		include_once("../includes/artisttopmenu.php")
?>		
					<div align="left" class="content_area">
					<!--content area start -->
					<form name="frmLogin" action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST" onSubmit="return checkArtistLoginForm();">
					<div align="left" class="page_title"><?php echo TEXT_SELLER_LOGIN;?></div>
					<div align="center" class="text_information grey_tr"><?php echo $message?></div>
					<table cellpadding="0" cellspacing="0" width="100%" border="0" class="manage_table">
					<tr>
						<td>
							<br>
							<p align="center">
								<?php echo MSG_CHECK_QTN;?><a href="../faq.php#sellers" class=""><b><?php echo MSG_FAQ;?></b></a>
							</p>	
							<br>
								<table cellpadding="0" cellspacing="0" width="100%" border="0" class="login_btm_lnks1">
								<tr>
									<td align="center">
										<div align="left" id="login_area_new">
											<?php echo TEXT_USER_NAME;?><br /><input name="txtUserName" id="txtUserName" type="text" size="27" tabindex="1"  value="<?php echo htmlentities($txtUserName) ; ?>"/>
											<br />
											<?php echo TEXT_PASS;?><br /><input name="txtPassword" id="txtPassword" type="password" size="27" tabindex="2" value="<?php echo htmlentities($txtPassword) ; ?>" />
											<br />
											<div class="bttn_cnt">
												<input name="submit" type="submit" class="login_bttn" value=" <?php echo BTN_LOGIN;?>" tabindex="3" /><input style="width: 28px;" <?php echo $remembered === true ? 'checked="checked"' : '' ?> type="checkbox" name="rememberme"><?php echo TEXT_REMEMBR;?>
											</div>
											
                                                                                        <div align="left" class="login_btm_lnks"><img src="../images/arrow1.gif" alt="" width="10" height="10" border="0" class="login_arrow"/>&nbsp;<a href="register.php"  style="font-size: 12px!important;" class="login_btm_lnks1"><?php echo TEXT_REG_NOW;?>!</a></div>
										<div align="left" class="login_btm_lnks"><img src="../images/arrow1.gif" alt="" width="10" height="10" border="0" class="login_arrow"/>&nbsp;<a href="forgotpassword.php" style="font-size: 12px!important;" class="login_btm_lnks1"><?php echo TEXT_RESET_PASS;?></a>
                                                                                    
                                                                                    
										  <input type="hidden" name="from" value="<?php echo $from;?>" >
										</div>																		
									</div>
								</td>
							</tr>
						</table>	
						<!--content area end-->
				</td>
			</tr>
		</table>					
		</form>
				</div>
					<div align="left" class="clear_float"><img src="<?php echo $imagefolder;?>/clear.gif" alt="" width="1" height="1" /></div>
				<!--main body end -->
				</div>
<?php
	include "../includes/footer.php";
?>