<?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 .= TEXT_ADMIN_EMAIL." <br>";
    }else {
        if (!isValidEmail($txtEmail)) {
            $message .= INVALID_EMAIL." <br>";
        }else {
            $sql = "SELECT admin_name FROM ".$tableprefix."settings WHERE site_email = '".addslashes($txtEmail)."' ";
            $res = mysql_query($sql);
            if(mysql_num_rows($res)!=0) {
                $row = mysql_fetch_array($res);
                $firstname = $row["admin_name"];

                $randnum1 = mt_rand();
                if(strlen($randnum1) > 6) {
                    $randnum1 = substr($randnum1,0,6);
                }
                $newpass = $randnum1;
                $pass = md5($newpass);
                $sqlreset = "UPDATE ".$tableprefix."settings SET admin_password  = '$pass'";


                $to = $txtEmail;
                $subject = MAIL_ADMIN_FORGOT_PASSWORD_SUBJECT_1." ".stripslashes(SITE_NAME) . " ".MAIL_ADMIN_FORGOT_PASSWORD_SUBJECT_2;

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

                $mailmessage = readEmailTemplate('admin_forgotpassword');

                $mailmessage = str_replace('[name]',$firstname,$mailmessage);
                $mailmessage = str_replace('[user_name]',$firstname,$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 .= SUCCESS_MSG;
                }else {
                    $message .= TEXT_RETRY." <br>";
                }
            }else {
                $message .= TEXT_EMAIL_NOT_REG."<br>";
            }
        }
    }
    if ($message != "") { // error
        $message = "<br>".MSG_CORRECT_THE_ERRORS."<br>" . $message;
    }
    if($successmessage !="")
        $message=$successmessage;
}

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


<body>

    <center>

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




            <!--header area start -->
            <?php

            include_once("../includes/topheader_admin.php")

                    ?>

            <!--header area end -->




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



                <?php
                include_once("../includes/adminforgottopmenu.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 FIELDS_ARE_MANDATORY;?></td></tr>
                                    <tr><td width="34%" align="right" ><?php echo 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="32" maxlength="30" ></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">									<input type="submit" value="<?php echo RST_PWD;?>" name="btnResetPassword"  class="button" >
                                                        &nbsp;&nbsp;&nbsp;<input type="button" value="&nbsp;&nbsp;&nbsp;&nbsp;<?php echo BACK;?>&nbsp;&nbsp;&nbsp;&nbsp;" class="button" name="Back" onClick="Javascript:window.location.href='login.php';">
                                                    </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";
            ?>