<?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 (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}

$txtEmail = $_POST["txtEmail"];
if (isset($_POST["btnResetPassword"])) {
    $message = "" ;
    if (!isNotNull($txtEmail)) {
        $message .= VAL_MSG_REG_EMAIL;
    }else {
        if (!isValidEmail($txtEmail)) {
            $message .= VAL_MSG_INVALID_MAIL;
        }
    }  
    
    $vSellerApproval    =    isSellerApproved($txtEmail);
    
    if($vSellerApproval=='NN')
    {
        $message .= VAL_SELLER_NOT_APPROVED;
    }
        if($message=='')
        {
            $sql = "SELECT first_name,last_name,artist_name, artist_id FROM ".$tableprefix."artists WHERE email = '".addslashes($txtEmail)."' ";
            $res = mysql_query($sql);
            if(mysql_num_rows($res)!=0) {
                $row = mysql_fetch_array($res);
                $firstname = $row["first_name"];
                $lastname = $row["last_name"];
                $artistname = $row["artist_name"];
                $artistid = $row["artist_id"];
                
                $randnum1 = mt_rand();
                if(strlen($randnum1) > 6) {
                    $randnum1 = substr($randnum1,0,6);
                }
                $newpass = $randnum1;
                $pass = md5($newpass);
                $sqlreset = "UPDATE ".$tableprefix."artists SET password = '$pass' WHERE artist_id = '".addslashes($artistid)."' ";

                $artistfullname = $firstname;
                if($lastname != "") {
                    $artistfullname .= " ". $lastname;
                }
                $to = $txtEmail;
                $subject = MSG_UR_PASS.stripslashes(SITE_NAME) .MSG_RESET_ON_REQ;

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

                $mailmessage = readEmailTemplate('seller_forgotpassword');

                $mailmessage = str_replace('[name]',$artistfullname,$mailmessage);
                $mailmessage = str_replace('[user_name]',$artistname,$mailmessage);
                $mailmessage = str_replace('[password]',$newpass,$mailmessage);

                $mailmessage = nl2br($mailmessage);

                $mail_send_details = "<html><head><link href='".SITE_URL."/style/template1-admin.css' rel='stylesheet' type='text/css'></head><body><center><div align='left' id='layout'><div align='left' class='header'><div align='left' class='logo'><img src=".$logofolder."/".$logoimage." width='125' height='39'/></div></div><div>".$mailmessage."</div></div><div align='left' class='clear_float'><img src=".$imagefolder."/clear.gif width=1 height=1/></div></div></div></center></body></html>";

                $headers  = "MIME-Version: 1.0" . "\r\n";
                $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
                $headers .= "From: ".SITE_EMAIL."<".SITE_EMAIL.">" . "\r\n";
                $mailsent = @mail($to, $subject, $mail_send_details, $headers);

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

                $successmessage="";
                if($mailsent) {
                    mysql_query($sqlreset);
                    $successmessage .= MSG_PASS_SENT."&nbsp;".$to;
                }else {
                    $message .= MSG_ERR_SEND;
                }
            }else {
                $message .= MSG_MAIL_NOT_FOUND;
        
    }
    
        }
    if ($message != "") { // error
        $message = VAL_MSG_PLS_CORRECT . $message;
    }
    if($successmessage !="")
        $message=$successmessage;
}

include "../includes/htmltop.php";
?>


<body>

    <center>

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

                    <div align="left" class="page_title"><?php echo TEXT_FORGOT_PASS;?></div>
                    <div align="center" class="text_information grey_tr"><?php echo $message?></div>
                    <br>

                    <div align="left">
                        <form name="frmForgotPassword" action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST">
                            <input type="hidden" name="artistid" value="<?php echo htmlentities($artistid);?>">
                            <div class="forgpass_sellers">
                                <table cellpadding="0" cellspacing="0"  class="manage_table" width="100%">
                                    <tr><td colspan="3">&nbsp;</td></tr>
                                    <tr><td colspan="3" align="right"><span class="required">*</span>&nbsp;<?php echo MSG_FIELD_MANDATORY;?></td></tr>
                                    <tr><td width="34%" align="right" ><?php echo TEXT_REG_EMAIL;?>&nbsp;<span class="required">*</span></td>
                                        <td width="2%" >&nbsp;</td><td width="64%" ><input  class="textarea" type="text" value="<?php echo htmlentities($txtEmail);?>" name="txtEmail" size="60" maxlength="80" style="width:250px;" ></td></tr>
                                    <tr><td colspan="3">&nbsp;</td></tr>
                                    <tr>
                                        <td colspan="3" align="left">
                                            <table width="100%" border="0" cellpadding="0" cellspacing="0">
                                                <tr>
                                                    <td width="66%" align="center">
                                                        &nbsp;&nbsp;&nbsp;<input type="button" value="&nbsp;&nbsp;&nbsp;&nbsp;<?php echo BTN_BACK;?>&nbsp;&nbsp;&nbsp;&nbsp;" class="button" name="Back" onClick="Javascript:history.go(-1);">&nbsp;<input type="submit" value="<?php echo BTN_RESET_PASS;?>" name="btnResetPassword"  class="button" >
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr><td colspan="3">&nbsp;</td></tr>
                                    <tr><td colspan="3">&nbsp;</td></tr>
                                </table>
                                <div class="clear"></div>
                            </div>
                        </form>

                    </div>


                    <!--content area end-->

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