#!/usr/bin/perl

# $Id: la-find-expired 2795 2010-07-31 10:04:13Z nanardon $

use strict;
use warnings;
use LATMOS::Accounts::Maintenance;
use LATMOS::Accounts::Log;
use Getopt::Long;
use Pod::Usage;

=head1 NAME

    la-sql-find-expired - Find expired user

=head1 SYNOPSIS

    la-sql-find-expired [options]

=cut

GetOptions(
    'c|config=s' => \my $config,
    'help'       => sub { pod2usage(0) },
    'old=s'       => \my $delay,
    'test'       => \my $test,
) or pod2usage();

=head1 OPTIONS

=over 4

=item old DELAY

The minimum delay user has been expired

=item -c|--config configdir

Use this configuration directory instead of the default one.

=back

=cut

my $LA = LATMOS::Accounts::Maintenance->new($config);

foreach ($LA->find_expired_users($delay)) {
    my $obj = $LA->_base->get_object('user', $_);
    printf("%s - %s (%s%s)\n", $obj->id, $obj->get_attributes('displayName'),
        $obj->get_attributes('expireText'),
        ($obj->get_attributes('manager') ? ' ' .
            $obj->get_attributes('manager') : ''),
    );
}
