<?php
//+-----------------------------------------------+//
//+ Copyright Floopo.com
//+ helper.password.php
//+ Update members password
//+-----------------------------------------------+//

defined('BASEPATH') or die('You can not directly access this file'); //check its within this framework

$show_password_reset = 1;

//___CHECK IF SUBMIT_______

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

    //process the form
    $process = new FormProcessor();
    ($process->RequiredFields('all')) ? $proceed = true : $display_notification = $lang['fill_in_all'];


    //check user_details
    if($proceed) {

        $user_name = Sanatize(mysql_real_escape_string($_POST['user_name']));
        $email_address = Sanatize(mysql_real_escape_string($_POST['email_address']));

        $rows = $dbase->CountRows("SELECT user_name
                                        FROM member_profile
                                        WHERE user_name = '$user_name' AND email_address = '$email_address'");

        ($rows == 1) ? $proceed2 = true : $display_notification = $lang['details_do_not_match'];

    }


    if($proceed2) {

        $new_password = RandomCode(6);
        $new_password_md5 = md5($new_password);
        if($dbase->UpdateRecord("UPDATE
                                member_profile
                                SET password = '$new_password_md5'
                                WHERE user_name = '$user_name'")) {
            $display_notification = $lang['request_completed'];

            //_______Send Email
            $message = $lang['new_message'].': '.$new_password;
            $subject = $lang['password_reset'];
            $notify = new Postage($message);
            $notify->EmailFormat('html');
            $notify->ToFromSubject($email_address,$config['system_email'],$subject); echo $config['system_email'];
            $notify->SendNow();

        } else {
            //display error and reload post in form
            $display_notification = $lang['generic_error'];
        }
    }
}


?>