<?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>


<body>

<center>

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




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

        <!--header area end -->




        <div align="left" class="main_body">
            <!--main body start -->



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


            <div align="left" class="content_area">

                <!--content area start -->

                <div align="left" class="page_title"><?php echo TEXT_AFFL_LOGIN;?></div>

                <table cellpadding="0" cellspacing="0" width="100%" border="0" class="manage_table">
                    <tr>
                        <td>
                            <p align="center">

                                <?php echo MSG_SIGN_UP;?> <b><?php echo htmlentities(SITE_NAME); ?> <?php echo MSG_AFFL_PGM;?></b><br><br>
                                <?php echo MSG_REFER_VISITORS;?> <b><?php echo $txtReferralCharge; ?></b> <?php echo MSG_PERC_PUR;?>
                                <br><br>
                                <?php echo MSG_CHECK_QTN;?> <a href="../faq.php#affiliate" class=""><b><?php echo MSG_FAQ;?></b></a>

                            </p>


                            <form name="frmLogin" action="<?php echo $_SERVER["PHP_SELF"] ?>" method="POST" onSubmit="return checkAffiliateLoginForm();">

                                <div align="center" class="text_information grey_tr"><?php echo $message ?></div>
                                <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" type="text" size="27" />
                                                <br />
                                                <?php echo TEXT_PASS;?><br /><input name="txtPassword" type="password" size="27" />
                                                <br />
                                                <div class="bttn_cnt">
                                                    <input type="reset" class="reset_bttn" value=" <?php echo BTN_RESET;?>">&nbsp;<input name="submit" type="submit" class="login_bttn" value=" <?php echo BTN_LOGIN;?>" />

                                                </div>

                                                <div align="left" class="login_btm_lnks" style="font-size: 12px!important;"><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></div>

                                            </div>
                                        </td>
                                    </tr>
                                </table>

                                <!--content area end-->

                            </form>

                        </td>
                    </tr>
                </table>	

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