<?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";
include "../classes/cls_user.php";
include "../classes/cls_store.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;
}
$message="";
//******************************************Multicart3.0 Additions **************************************
// Check buyer having single seller and buyer account redirect user to seller dashboard // prevent user to re-login if logout pressed
$from =  $_REQUEST['from'];
if($_SESSION["sess_userid"]!='' && $from=='') {
 $sellerAccObj   =    User::is_seller_account_activated($_SESSION["sess_userid"]);

    $seller_activated_status        =   'N';
    //echopre($sellerAccObj);
        if($sellerAccObj->status==SUCCESS)
            {
                    $sellerAccObjVal            =   $sellerAccObj->data;
                    $seller_activated_status    =   $sellerAccObjVal->is_seller;
                    $activated_seller_id        =   $sellerAccObjVal->seller_id;
                    
                   $sellerObj  =    Store::get_seller_account_info($activated_seller_id);

            if($sellerObj->status==SUCCESS)
                    {
                        $sellerObjVal                       =   $sellerObj->data;
                        $vapproved                          =   $sellerObjVal->vapproved;
                        $deleted                            =   $sellerObjVal->deleted;
                        $seller_activated_status            =   'Y';
                    }
                    else {
                            $seller_activated_status        = 'N';
                         }

                    if($vapproved=='NN' )
                    {
                       $seller_activated_status        =   'N';
                       $message=MSG_ACCOUNT_NOT_APPROVED;
                    }

                     else if($vapproved=='N' || $deleted=='Y' )
                    {
                       $seller_activated_status        =   'N';
                       $message=MSG_ACCOUNT_DISABLED;
                    }
                   else if(($activated_seller_id==$_SESSION["sess_userid"]) &&  ($seller_activated_status=='Y'))
                        {
                             header("Location: activate_seller_session.php?sellerid=".$activated_seller_id);
                                    exit;
                        }
            }
}
//******************************************Multicart3.0 Additions **************************************
 

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

//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;


$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>
                <link href="<?php echo $site_url; ?>/themes/<?php echo $active_template[4] ?>" rel="stylesheet" type="text/css">
				<link href="<?php echo $site_url; ?>/themes/responsive/css/commonstyle.css" rel="stylesheet" type="text/css">
                <link href="<?php echo $site_url; ?>/themes/responsive/css/bootstrap.min.css" rel="stylesheet" type="text/css">
                <link href="<?php echo $site_url; ?>/themes/responsive/css/bootstrap.css" rel="stylesheet" type="text/css">
                <link href="<?php echo $site_url; ?>/style/bootstrap-modal-bs3patch.css" rel="stylesheet" type="text/css">
                <link href="<?php echo $site_url; ?>/style/bootstrap-modal.css" rel="stylesheet" type="text/css">
                <link href="<?php echo $site_url; ?>/themes/responsive/css/font-awesome.css" rel="stylesheet" type="text/css">
                <link href="<?php echo $site_url; ?>/themes/responsive/css/font-awesome.min.css" rel="stylesheet" type="text/css">
              
                <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
                <script type="text/javascript" language="javascript" src="<?php echo $site_url; ?>/themes/responsive/js/bootstrap.js"></script>
                <script type="text/javascript" language="javascript" src="<?php echo $site_url; ?>/themes/responsive/js/bootstrap.min.js"></script>
                <script type="text/javascript" language="javascript" src="<?php echo $site_url; ?>/js/bootstrap-modalmanager.js"></script>
                <script type="text/javascript" language="javascript" src="<?php echo $site_url; ?>/js/bootstrap-modal.js"></script>
                <script type="text/javascript" language="javascript" src="<?php echo $site_url; ?>/themes/responsive/js/responsivemobilemenu.js"></script>
                <script type="text/javascript" language="javascript" src="<?php echo $site_url; ?>/themes/responsive/js/responsive-tables.js"></script>

		<div align="left" id="layout">
				<div align="left" class="main_body sellerlog">
				<!--header area start -->
<?php
	include_once("../includes/topheader_seller.php")
?>
				<!--header area end -->
				<!--main body start -->
<?php
		//include_once("../includes/artisttopmenu.php")
?>		

					
					
					<div id="item_details">
	<!--items display area start -->
	
	
	
	
		<div class="col-sm-12 col-lg-4 col-md-4"></div>
		<div class="col-sm-12 col-lg-4 col-md-4">
			<div class="text_information" align="center"><?php echo $message?></div>
			<div class="clear"></div>
			<div class="form_wrapper">
				<div class="register_form_outer">
					<form name="frmLogin" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"], ENT_QUOTES, 'UTF-8')?>" method="POST" onSubmit="return checkArtistLoginForm();">
					<div class="registrationform_container">
						<h3><?php echo TEXT_SELLER_LOGIN;?></h3>
						<div class="field_wrapper formfield_row">
						<div class="createacc_link">
							<p>
									<?php echo MSG_CHECK_QTN;?><a href="../faq.php#sellers" class=""> <?php echo MSG_FAQ;?></a>
							</p>
						</div>	
						</div>
						<div class="field_wrapper formfield_row">
							<input name="txtUserName" id="txtUserName" type="text" class="form-control" tabindex="1" value="<?php echo htmlentities($txtUserName) ; ?>" placeholder="<?php echo TEXT_USER_NAME;?>"/>
						</div>
						<div class="field_wrapper formfield_row">
							<input name="txtPassword" id="txtPassword" type="password" class="form-control" tabindex="2" value="<?php echo htmlentities($txtPassword) ; ?>" placeholder="<?php echo TEXT_PASS;?>"/>
						</div>
						<div class="field_wrapper formfield_row">
								<div class="secondarypannel">
								<input name="submit" type="submit" class="login_btn" value=" <?php echo BTN_LOGIN;?>" tabindex="3" />
								<input style="width: 28px;" <?php echo $remembered === true ? 'checked="checked"' : '' ?> type="checkbox" name="rememberme"><span class="remember_link"><?php echo TEXT_REMEMBR;?></span>
								</div>
						</div>
						<div class="field_wrapper formfield_row">
							<div class="forgot_row">
								<div class="login_btm_lnks"> <a href="forgotpassword.php" class="login_btm_lnks"><?php echo TEXT_FORGOT_PASS;?>? </a></div>
							</div>
							 
						<div class="clear"></div>
						</div>
						<div class="field_wrapper formfield_row">
						<div class="createacc_link">
							<div class="new_userhd"> <?php echo NEW_SELLER_TEXT;?>? <a href="register.php" class="reg_now_link"><?php echo TEXT_REG_NOW;?>!</a></div>
						</div>	
						</div>
					<div class="clear"></div>
						<input type="hidden" name="from" value="<?php echo $from;?>" >
					</div>
					</form>
				</div>
			</div>
		</div>
		<div class="col-sm-12 col-lg-4 col-md-4"></div>
		<div class="clear"></div>																						
	</div>
	 <!--items display area end -->
					
				<?php
					include "../includes/footer.php";
				?>					
							
				<!--main body end -->
				</div>
				
