package ptxArchiverVars;
# This is ptxArchierVars.pm module of ptxArchiver.pl, a program to archive 
# records from one MySQL table to an another table, a file or simply purged.
#
# This program is copyright 2009 frederic descamps <lefred@inuits.be>.
# Feedback and improvements are welcome.
#
# This program requires mk-archiver from maatkit <http://www.maatkit.org/>
#
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, version 2; OR the Perl Artistic License.  On UNIX and similar
# systems, you can issue `man perlgpl' or `man perlartistic' to read these
# licenses.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA  02111-1307  USA.

use strict;
use warnings;
use Config::General;
use FindBin qw( $Bin $Script $RealBin $RealScript );
use Exporter 'import';

our @EXPORT = qw(%tables $debug $purge $archiver $modulesPath
             $src_dbname $src_dbhost $src_dbuser $src_dbpass
             $dest_dbname $dest_dbhost $dest_dbuser $dest_dbpass
             $fileout $filename $ignorereplica
             @tab $i find timestampStr
            );

my $conf         = new Config::General("/etc/ptxarchiver.conf");
our %config      = $conf->getall;

our $debug       = $config{debug} || 0;
our $ignorereplica  = $config{ignorereplica} || 
our $purge       = $config{purge} || 0;
our $archiver    = $config{archiver};
our $modulesPath = $config{modulesPath};
our $fileout	 = $config{fileout} || 0;
our $filename    = $config{filename};

our $src_dbname  = $config{source}->{dbname};
our $src_dbhost  = $config{source}->{dbhost};
our $src_dbuser  = $config{source}->{dbuser};
our $src_dbpass  = $config{source}->{dbpass};

our $dest_dbname = $config{destination}->{dbname};
our $dest_dbhost = $config{destination}->{dbhost};
our $dest_dbuser = $config{destination}->{dbuser};
our $dest_dbpass = $config{destination}->{dbpass};

our $tables      = $config{tables};

our @tab=("/","-","\\","|","/","-","\\","|");
our $i=0;

sub find {
    my $tn = shift( @_ );
    my $startpoint = shift( @_ ) || $config{'tables'};

    my $retunpoint;

    foreach my $key ( keys %$startpoint ) {
        if( $key eq $tn ) {
                return $startpoint->{$key};
        }
        else {
                my $ref = ref $startpoint->{$key};
                if( $ref eq 'HASH' ) {
                        my $swp_retunpoint = find( $tn, $startpoint->{$key} );
                        if ($swp_retunpoint) { $retunpoint = $swp_retunpoint; }
                }
        }
    }
    return $retunpoint;
}

sub timestampStr {
	
	my ($nsec,$nmin,$nhour,$nmday,$nmon,$nyear,$nwday,$nyday,$nisdst) = localtime;
    $nyear += 1900;
    $nmon++;

    my $timestampStr = sprintf( "%04i-%02i-%02i_%02i-%02i", $nyear, $nmon, $nmday, $nhour, $nmin );
    
    return $timestampStr;
	
}

1;
