# --
# Kernel/System/CustomerUser/Local/Init.pm - some customer user field initialization functions
# Copyright (C) 2002-2003 Tom Hesp <tghesp@euronet.nl>
# --
# $Id: $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see http://www.gnu.org/licenses/gpl.txt.
# --

package Kernel::System::CustomerUser::Local::Init;

use strict;

use vars qw(@ISA $VERSION);
$VERSION = '$Revision: 0.1 $';
$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/;

# --
sub new {
    my $Type = shift;
    my %Param = @_;

    # allocate new hash for object
    my $Self = {};
    bless ($Self, $Type);
    # --
    # check needed objects
    # --
    foreach (qw(ConfigObject LogObject)) {
        $Self->{$_} = $Param{$_} || die "Got no $_!";
    }
    return $Self;
}

# --
# Ensure Zip code does not contain any non-alpha's and alpha's are in uppercase.
sub VerifyZipcode {
	my $Self = shift;
	my %Param = @_;
	my $Zipcode = $Param{Zipcode};

	$Zipcode =~ tr/ //d;
	$Zipcode =~ tr/a-z/A-Z/;

	return $Zipcode;
}

# --
# This function generates random strings of a given length (8 if no length defined).
sub GenerateRandomString {
	my $Self = shift;
	my %Param = @_;
	my $PWLength = $Param{PWLength} || 8;


	my @Chars=('a'..'z','A'..'Z','0'..'9','_');
	my $RandomString;

	foreach (1 .. $PWLength) 
	{
		$RandomString .= $Chars[int(rand(@Chars))];
	}
	return $RandomString;
}

# --
# Generate CustomerId on the basis of the country code, numeric part of the zip code, house number and time.
sub GenerateCustomerID {
	my $Self = shift;
	my %Param = @_;
	my $ZipCode = $Param{ZipCode};
	my $Number = $Param{Number};

	if (!$ZipCode || !$Number) {
		$Self->{LogObject}->Log(Priority => 'error', Message => "Need Zipcode and Number to generate Customer ID!");
		return;
	}

	# ---
	# Strip any non-numeric data from Zip Code & Number.
	# ---
	$ZipCode =~ tr/0-9//cd;
	$Number =~ tr/0-9//cd;

	# Return constructed CustomerID.
	return "31-" . $ZipCode . $Number . "-" . time;

}
# --

1;
