#! /usr/local/bin/sybperl

#
# This script takes a single parameter that supplies the "where" clause
# of an sql statement..
#


#
# See if everything is there.
#

sub authors_main {

	local ($fromtables, $query) = @_;
	local ($where) ="";
	$where = "where $query" if ($query);

	@results = &sql($DB, "
                        select authors.au_id, au_lname, au_fname,
                        phone, address, city, state, country, postalcode 
                        from $fromtables
	                $where
                        order by au_lname
");



	foreach $x (@results) {
	    ($au_id,$au_lname,$au_fname,$phone, $address, $city, $state, $country,
	     $postalcode) = split("~",$x);
	    
	    @blurbs = &sql($DB, "select copy from blurbs where au_id=\'$au_id\'");
	    $copy = @blurbs[0];
	    
	    &Output_Author;
	
	    @titles = &sql($DB, "
                        select titles.title_id, title, price, notes, pubdate
                        from titles, titleauthor
                        where titles.title_id = titleauthor.title_id and
                              titleauthor.au_id = '$au_id'
                        order by titles.title
");

	    print "\r\nBooks by $au_fname $au_lname\r\n";

	    foreach $x (@titles) {
		($title_id, $title, $price, $notes, $pubdate)
		    = split("~",$x);
	    &Output_Title;

	    }
	
	}	

}

#
#
#

sub Output_Author {
    print "-------------------------------\r\n";
    print "ID: $au_id\r\n";
    print "$au_fname $au_lname\r\n";
    print "$address\r\n";
    print "$city, $state $postalcode  $country\r\n";
    print "\r\nPhone: $phone\r\n\r\n";
    $copy =~ s/\n/\r\n/g;
    print "$copy";
    print "\r\n";
}

sub Output_Title {
    print "$title_id: $price   $title\r\n";
}
1;  # For Require
