#!/s/std/bin/perl

# $Id: adminlist.pl,v 1.14 2008/12/16 21:57:33 koczan Exp $

# adminlist.pl dumps info for the 5th floor admin staff.
# used for web page reports

use strict;
use warnings;

use DBI;
use CSL::Pg;
use CSL::DBs;

my $dbh = DBI->connect($CSL::DBs::csdb)
  or die "Could not connect to CSDB: $!";
$dbh->do("set search_path to csdb");

# If they gave a file, redirect STDOUT to there.
my $outfile = shift @ARGV;
if ($outfile) {
  open STDOUT, '>', $outfile
    or die "$0: Could not open $outfile for writing: $!";
}

# Header
# no header this time

# get the data now
my $admin_query = $dbh->prepare("select login, lastname, firstname, uwoffice, uwphone, pnotes from people where secretary = 1 or login = 'perryk' order by lower(lastname), lower(firstname)");

# the format assumes a lot (like login limits), but we can change it if need be
my $format = "%-11s|%-25s|%-25s|%-5s|%-8s|%s";
$admin_query->execute;
while (my $row = $admin_query->fetchrow_arrayref) {
  foreach (@$row) { $_ = '' unless defined $_; } # stupid nulls
  printf "$format\n", @$row;
}
print "\n";

# Footer
# no footer this time

# clean up
$admin_query->finish;
$dbh->disconnect;
