<?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_affiliateid"] != "") {
    header("Location:affiliatemain.php");
}


$sql = "SELECT referral_charge FROM " . $tableprefix . "settings ";
$result = mysql_query($sql);
if (mysql_num_rows($result) != 0) {
    $row = mysql_fetch_array($result);
    $txtReferralCharge = $row["referral_charge"];
}


$txtUserName = $_POST["txtUserName"];
$txtPassword = $_POST["txtPassword"];

$username_flag = 1;
$password_flag = 0;

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


    /* ---------Checking the password---------------- */

    $select_password = "SELECT password FROM " . $tableprefix . "affiliates WHERE LOWER(affiliate_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 affiliate_name FROM " . $tableprefix . "affiliates 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['affiliate_name'], "text")) == strtolower(GetSQLValueString($txtUserName, "text"))) {

                //$message = "Sorry, the username you submitted is not present in our database !!";
                $username_flag = 0;
            }
            /* else
              {

              $username_flag = 0;

              } */
        }
    }

    if ($username_flag == 1 && $password_flag == 1) {
        $message = MSG_UNAME_WRONG." !!";
    }
    if ($username_flag == 1 && $password_flag == 0) {
        $message = MSG_UNAME_WRONG."!!";
    }

    if ($username_flag != 1 && $password_flag != 1) {


        $sql = " SELECT affiliate_id,affiliate_name,password FROM " . $tableprefix . "affiliates WHERE affiliate_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_affiliatename"] = $row["affiliate_name"];
            $_SESSION["sess_affiliateid"] = $row["affiliate_id"];
            header("Location:affiliatemain.php");

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

            /* -------function call to manage the different sessions-------- */

            manageSession(4);

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

            exit;
        } else {
            $message = MSG_ACC_NOT_APPR." !!";
        }
    }


    /* $sql=" SELECT affiliate_id,affiliate_name,password FROM ".$tableprefix."affiliates WHERE affiliate_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_affiliatename"] = $row["affiliate_name"];
      $_SESSION["sess_affiliateid"] = $row["affiliate_id"];
      header("Location:affiliatemain.php");
      exit;
      }else{
      $message="Invalid Login! Please retry.";

      } */
}

include "../includes/htmltop.php";
?>
<script>
    function checkAffiliateLoginForm()
    {
	
        var form_name = new Array('txtUserName','txtPassword');		
        var display_name = new Array('User Name','Password');
        var count = 2;	
	
        if(check_fields('frmLogin',form_name,display_name,count))	
        {
			
		 	   
        }
        else
        {
	  
            return false;
	  
        }
	   
    }
</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>

<body>

<center>

    <div align="left" id="layout">

	<div align="left" class="main_body sellerlog">


        <!--header area start -->
<?php
include_once("../includes/topheader_affiliate.php")
?>

        <!--header area end -->




            <!--main body start -->



<?php
//include_once("../includes/afftopmenu.php")
?>		

		<div class="col-sm-12 col-lg-3 col-md-3"></div>
		<div class="col-sm-12 col-lg-6 col-md-6">
			<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 checkAffiliateLoginForm();">
					<div class="registrationform_container">
						<h3><?php echo TEXT_AFFL_LOGIN;?></h3>
						<p>
						 	<?php echo MSG_SIGN_UP;?> <b><?php echo htmlentities(SITE_NAME); ?> <?php echo MSG_AFFL_PGM;?></b>
						 </p>
						 <p>
                             <?php echo MSG_REFER_VISITORS;?> <b><?php echo $txtReferralCharge; ?></b> <?php echo MSG_PERC_PUR;?>
                         </p>
						  <p class="createacc_link">
                              <?php echo MSG_CHECK_QTN;?> <a href="../faq.php#affiliate" class=""><b><?php echo MSG_FAQ;?></b></a>
						  </p>
						<div class="field_wrapper formfield_row">
							<input name="txtUserName" id="txtUserName" type="text" class="form-control" tabindex="1" 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" 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" />
								</div>
						</div>
							<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 class="new_userhd"> </div>
							</div>
							 <input type="hidden" name="from" value="<?php echo $from;?>" >
						<div class="clear"></div>
						<div class="field_wrapper formfield_row">
						<div class="createacc_link">
							<div class="new_userhd"> <?php echo NEW_AFFILIATE_TEXT;?>? <a href="register.php" class="reg_now_link"><?php echo TEXT_REG_NOW;?></a></div>
						</div>	
						</div>
						<div class="clear"></div>

					</div>
					</form>
				</div>
			</div>
		</div>
		<div class="col-sm-12 col-lg-3 col-md-3"></div>
		<div class="clear"></div>

                <!--content area start -->



<?php
include "../includes/footer.php";
?>
	<!--main body end -->
</div>
