#!/usr/bin/perl push(@INC, "/home2/bennette/HTML/cgi"); use CGI qw/:standard/; use Date::Manip; use DBI; use NewsDB_SQL; require "config.ph"; require "investorconfig.ph"; my (%in, $dbh); foreach (param()) { # $in{$_} = param($_); my (@a) = param($_); my ($count) = scalar @a; if ($count == 1) { $in{$_} = param($_); } else { $in{$_} = [ param($_) ]; } } &Show_Page(\%in); exit; sub Show_Page { my ($in) = shift; my (@a, @b); $dbh = DBI->connect("DBI:$DRV:$DB:$HOST:$PORT", $UID, $PWD); my ($dispstr) = ""; # $dispstr = header(); print header; if ($in->{a} ne "content") { $dispstr .= &show($in, $dbh); } else { use ClientArticle; my ($capage) = new ClientArticle($dbh, {}, $in); $dispstr .= $capage->show; } unless ($dbh) { print header() . "\nunable to connect to db."; return; } $dbh->disconnect; print $dispstr; } sub show { my ($in, $dbh) = @_; my ($dispstr) = ""; my ($NEWS_RELEASES) = ""; my ($FINANCIAL_REPORTS) = ""; my ($EXTRA_LINKS) = ""; my ($ROW) = ""; my ($PAGE) = ""; my ($newscount, $financialcount, $linkcount); $newscount = $financialcount = $linkcount = $DEFAULT_ITEMS_PER_PAGE; my ($str, $stmh, $ref); my ($page_number) = $in->{'page'}; my ($items_per_page); if ($in->{'count'}) { $items_per_page = $in->{'count'}; } else { $items_per_page = $DEFAULT_ITEMS_PER_PAGE; } # read template file my ($mode) = "default"; my (@modestack); open (CFILE, "$INVESTOR_TEMPLATE") || die "Error in News 1. $!"; while () { /^$NEWS_COUNT\s*(\d)$END_TAG/ && do { $newscount = $1; next; }; /^$FINANCIAL_COUNT\s*(\d)$END_TAG/ && do { $financialcount = $1; next; }; /^$LINK_COUNT\s*(\d)$END_TAG/ && do { $linkcount = $1; next; }; /^$TMPL_END/ && do { TMPL_BLOCK: { $_ = $mode; /news release/ && do { $NEWS_RELEASES = &MakeNewsBlock($NEWS_RELEASES, $ROW, $newscount); last TMPL_BLOCK; }; /financial reports/ && do { $FINANCIAL_REPORTS = &MakeFinancialBlock($FINANCIAL_REPORTS, $ROW, $financialcount); last TMPL_BLOCK; }; /extra links/ && do { $EXTRA_LINKS = &MakeExtraLinksBlock($EXTRA_LINKS, $ROW, $linkcount); last TMPL_BLOCK; }; }; # template block unless ($mode = pop @modestack) { $mode = "default"; }; next; }; /^$TMPL_NEWS_RELEASE/ && do { push @modestack, $mode; $mode = "news release"; next; }; /^$TMPL_FINANCIAL_REPORTS/ && do { push @modestack, $mode; $mode = "financial reports"; next; }; /^$TMPL_EXTRA_LINKS/ && do { push @modestack, $mode; $mode = "extra links"; next; }; /^$TMPL_ROW/ && do { push @modestack, $mode; $mode = "row"; $ROW = ""; next; }; if ($mode eq "row") { $ROW .= $_; next; } if ($mode eq "news release") { $NEWS_RELEASES .= $_; next; } if ($mode eq "financial reports") { $FINANCIAL_REPORTS .= $_; next; } if ($mode eq "extra links") { $EXTRA_LINKS .= $_; next; } if ($mode eq "default") { $PAGE .= $_; next; } }; close (CFILE); $dispstr = $PAGE; $dispstr =~ s/$NEWS_RELEASE_HERE/$NEWS_RELEASES/g; $dispstr =~ s/$FINANCIAL_REPORTS_HERE/$FINANCIAL_REPORTS/g; $dispstr =~ s/$EXTRA_LINKS_HERE/$EXTRA_LINKS/g; # my ($temp) = $self->hiddenData; # $dispstr =~ s/$HIDDEN_TAGS/$temp/g; return $dispstr; } sub MakeNewsBlock { my ($template, $row, $rowcount) = @_; my ($items) = &getItems("News Releases"); my ($itemcount) = scalar(@{$items}); my ($rowgroup, $rowtemplate, $dispstr); for ($i = 0; $i < $itemcount && $i < $rowcount; $i++) { $rowtemplate = $row; $rowtemplate =~ s/$ITEM_TITLE/$items->[$i]->{title}/g; my ($tempdate) = &UnixDate($items->[$i]->{date}, $DATE_FORMAT); $rowtemplate =~ s/$ITEM_DATE/$tempdate/g; if ($items->[$i]->{attachment} && $items->[$i]->{attachment} ne "") { my ($filesuffix) = ($items->[$i]->{attachment} =~ /.*(\..*)$/); my ($t) = "$GETFILE_SCRIPT?f=$items->[$i]->{id}$filesuffix"; $rowtemplate =~ s/$ITEM_CONTENT_URL/$t/g; $rowtemplate =~ s/$URL_TARGET/target=\"_blank\"/g; } else { my ($tempurl) = "$INVESTORSCRIPT?a=content&id=$items->[$i]->{id}"; $rowtemplate =~ s/$ITEM_CONTENT_URL/$tempurl/g; $rowtemplate =~ s/$URL_TARGET//g; } $rowgroup .= $rowtemplate; } $dispstr = $template; $dispstr =~ s/$NEWS/$NEWSSCRIPT/g; $dispstr =~ s/$ROW_HERE/$rowgroup/g; return $dispstr; } sub MakeFinancialBlock { my ($template, $row, $rowcount) = @_; my ($items) = &getItems("Financial Reports"); my ($itemcount) = scalar(@{$items}); my ($rowgroup, $rowtemplate, $dispstr); for ($i = 0; $i < $itemcount && $i < $rowcount; $i++) { $rowtemplate = $row; $rowtemplate =~ s/$ITEM_TITLE/$items->[$i]->{title}/g; my ($tempdate) = &UnixDate($items->[$i]->{date}, $DATE_FORMAT); $rowtemplate =~ s/$ITEM_DATE/$tempdate/g; my ($filesuffix) = ($items->[$i]->{attachment} =~ /.*(\..*)$/); my ($tempurl) = "$GETFILE_SCRIPT?f=$items->[$i]->{id}$filesuffix"; $rowtemplate =~ s/$ITEM_ATTACH_URL/$tempurl/g; $rowgroup .= $rowtemplate; } $dispstr = $template; $dispstr =~ s/$FINANCIALREPORTS/$FINANCIALREPORTSSCRIPT/g; $dispstr =~ s/$ROW_HERE/$rowgroup/g; return $dispstr; } sub MakeExtraLinksBlock { my ($template, $row, $rowcount) = @_; my ($items) = &getItems("Other Investor Links"); my ($itemcount) = scalar(@{$items}); my ($rowgroup, $rowtemplate, $dispstr); for ($i = 0; $i < $itemcount && $i < $rowcount; $i++) { $rowtemplate = $row; $rowtemplate =~ s/$ITEM_TITLE/$items->[$i]->{title}/g; my ($tempdate) = &UnixDate($items->[$i]->{date}, $DATE_FORMAT); $rowtemplate =~ s/$ITEM_DATE/$tempdate/g; $rowtemplate =~ s/$ITEM_URL/$items->[$i]->{url}/g; $rowgroup .= $rowtemplate; } $dispstr = $template; $dispstr =~ s/$ROW_HERE/$rowgroup/g; return $dispstr; } sub getItems { my ($cat) = shift; # get news items related to the current client # my ($newsdb) = new NewsDB_SQL($dbh); # my ($newsitems) = $newsdb->retrieve("owner", $self->{_userinfo}->{'name'}); my ($newsitems); my ($str, $stmh, $ref); my (@tempitems); my (%categories); $str = "SELECT * FROM categories"; $stmh = $dbh->prepare(qq[$str]); if ($stmh->execute) { while ($ref = $stmh->fetchrow_hashref) { $categories{ $ref->{category} } = $ref->{catid}; } } $stmh->finish; unless ( $categories{ $cat } ) { return 0; } $str = "SELECT * FROM news WHERE catid=\'$categories{$cat}\' ORDER BY date DESC"; $stmh = $dbh->prepare(qq[$str]); if ($stmh->execute) { my ($counter) = 0; while ($ref = $stmh->fetchrow_hashref) { foreach (keys %$ref) { $newsitems->[$counter]->{ $_ } = $ref->{ $_ }; } $counter++; } } $stmh->finish; foreach my $item (@$newsitems) { if ($item->{catid} == $categories{$cat}) { push @tempitems, $item; } } $newsitems = \@tempitems; return $newsitems; } #******************************** # append hidden tags sub hiddenData { my ($result) = ""; if ($in->{page}) { $result .= "{page}\">\n"; } # if ($in->{cat}) { # if (ref($in->{cat})) { # $result .= "{cat}[0]\">\n"; # } else { # $result .= "{cat}\">\n"; # } # } if ($in->{count}) { $result .= "{count}\">\n"; } return $result; }; 1;