# ------------------------------------------------------------------------------------- # # get_person # # Gets login information based on cookie data # # ------------------------------------------------------------------------------------- sub get_person { # Get Person Info from Cookies my ($dbh,$query) = @_; my $person_title = $query->cookie('person_title'); my $person_id = $query->cookie('person_id'); unless (($person_title) && ($person_id)) { $person_title = "Anymouse"; $person_id = 2; } # Get Person Data my $stmt = qq|SELECT * FROM person WHERE person_title = ? AND person_id = ?|; my $sth = $dbh -> prepare($stmt); $sth -> execute($person_title,$person_id); $person = $sth -> fetchrow_hashref(); unless ($person) { &login_form_text($dbh,$options,$vars) ; exit; } # Login Failure $person->{posts} = {}; return $person if ($person_title eq "Anymouse"); # Get Person Posts-to-read Info $person->{posts} = {}; $stmt = qq|SELECT * FROM posttoread WHERE pr_person = ?|; $sth = $dbh -> prepare($stmt); $sth -> execute($person->{person_id}); while (my $ref = $sth -> fetchrow_hashref()) { my $thr = $ref->{pr_thread}; unless ($person->{posts}->{$thr}) { $person->{posts}->{$thr} = []; } push @{$person->{posts}->{$thr}},$ref->{pr_post}; } return $person; } # ------------------------------------------------------------------------------------- # # db_open # # Opens database # # ------------------------------------------------------------------------------------- sub db_open { my ($dsn,$user,$password) = @_; my $dbh = DBI->connect($dsn, $user, $password) or die "Database connect error: $! \n"; if ($dbh) { $dbh->trace(2,"dberror.txt"); } return $dbh; } # ------------------------------------------------------------------------------------- # # get_site # # Gets site configuration variables # # ------------------------------------------------------------------------------------- sub get_site { my ($Site,$conf) = @_; # Get site information open SITE, "$conf" || die "Cannot open site config: $!";; my $comment = '#'; while () { chomp; next unless ($_); next if ($_ =~ /^$comment/); my @vararr = split ' ',$_; my $key = shift @vararr; next unless ($key);next if ($key =~ '#'); my $val = join ' ',@vararr; my $junk; ($val,$junk) = split $comment,$val; $Site->{$key} = $val; } close SITE; } 1;