#!/afs/athena/contrib/perl5/perl

use MITEvents;
$|=1;

$dbfile = "/mit/mkgray/project/mitevents/test.db";

# Load the database
loadDB($dbfile);

if($ARGV[0] eq "add"){
    $title = &input("Title: ");
    $date = &input("Date: ");
    $time = &input("Time: ");
    $categories = &input("Categories: ");
    $sponsor = &input("Sponsor: ");
    $email = &input("Email: ");
    $url = &input("URL: ");
    $location = &input("Location: ");
    $fees = &input("Fees: ");
    $aud = &input("Intentded Audience: ");
    $attire = &input("Attire: ");
    $desc = &input("Description: ");

    @e = ($date, $time, $title, $categories, $sponsor, $email, $url,
	  $location, $fees, $aud, $attire, $desc, $conf);

    &newEvent(\@e);
}
elsif($ARGV[0] eq "list"){
    $f = &input("From: ");
    $t = &input("To: ");

    @elist = &getEvents($f, $t);
    foreach $eid (@elist) {
	print("EventID $eid\n");
	&printEvent($eid);
    }
}
elsif($ARGV[0] eq "expire"){
    &expireDB();
}
elsif($ARGV[0] eq "all"){
    @elist = &getEvents([0, 0, 0], [ 31, 12, 2010]);
    foreach $eid (@elist) {
	&printEvent($eid);
	print("\n\n");
    }
}

&writeDB($dbfile);

sub input {
    my $p = shift;
    print $p;
    $inp = (<STDIN>);
    chop($inp);
    return $inp;
}
