#!/usr/bin/perl
##############################
##  AutoGallery Pro v3.0.x  ##
#######################################################################
##  remind.cgi - Remind partner of their username and password       ##
#######################################################################

eval
{
    require 'common.pl';
    require 'agp.pl';
    Header("Content-type: text/html\n\n");
    main();
};


if( $@ )
{
    Error("$@", 'remind.cgi');
}



sub main
{
    ParseRequest(1);

    if( $ENV{'REQUEST_METHOD'} eq 'GET' )
    {
        ParseTemplate('remind_main.tpl');
    }
    else
    {
        my $email   = undef;
        my $account = undef;
        my $found   = undef;

        SubmitError('E_REQUIRED', 'EMAIL_USER') if( !$F{'Input'} );

        $email = 1 if( $F{'Input'} =~ /@/ );

        sopen(DB, "$DDIR/dbs/accounts");
        for( <DB> )
        {
            @$account{@{$DB_FORMAT{'accounts'}}} = split(/\|/, $_);

            if( ($email && $account->{'Email'} eq $F{'Input'}) || $account->{'Account_ID'} eq $F{'Input'} )
            {
                $found = 1;
                last;
            }
        }
        close(DB);

        SubmitError('E_NO_ACCOUNT') if( !$found );

        $T{'To'}         = $account->{'Email'};
        $T{'From'}       = $ADMIN_EMAIL;
        $T{'Submit_URL'} = "$CGI_URL/submit.cgi";

        HashToTemplate($account);

        Mail("$TDIR/email_remind.tpl");

        ParseTemplate('remind_sent.tpl');
    }
}
