\n";
#if a css file with the same name as the cssclass setting, then add a link to it
if (-e "$cssclass[1].css") {
print "\n";
}
print &getEntries($startnum,$endnum);
}
##Subroutines --------------------------------------------------------
#Reads CGI args, sets args in associative array %cgi, returns raw CGI args.
sub getCGI() {
my $i;
my $in;
my @pairs;
my $pair;
my $name;
my $value;
#Get any modifiers from querystring for get or stdin for post
if ($ENV{'REQUEST_METHOD'}) {
$ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/;
if ($ENV{'REQUEST_METHOD'} eq "POST") {
read(STDIN, $in, $ENV{'CONTENT_LENGTH'});
}
else {
$in = $ENV{'QUERY_STRING'};
}
}
else {
for ($i=0;$i <= $#ARGV;$i++) {$in .= $ARGV[$i];}
}
# parses query string into an acceptable form
@pairs = split (/&/, $in);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$cgi{$name} = $value if (length($value) > 0);
}
return $in;
}
#Reads file, returns contents
sub getDatafile($) {
my @datafile;
if (-e $_[0]) {
if (open(DATAFILE, $_[0])) {
#Read in data
@datafile = ;
close(DATAFILE);
return @datafile;
} else {die "Can not Open \"$_[0]\": $!";}
} else {die "$_[0] Does Not Exist"};
}
#Sets the Journal to Edit
sub setJournal($) {
if ($_[0] =~ /\d+/) {
$journalnum = $_[0];
} else {
for (my $i; $i <= $#journals; $i++) {
@name = &getElements("name",$journals[$i]);
$journalnum = $i if $name[1] eq $_[0];
}
}
}
#Gets requested Element from given content, returns array with all instances of Element
sub getElements($@) {
my $element = $_[0];
my @elementContents;
my $section;
my $i;
my $text;
my @attribs;
my $attr;
my $key;
my $value;
my $index;
#Fill $section with passed content and strip linefeeds
for ($i = 1; $i <= $#_; $i++) {$section = $section . $_[$i];}
$section =~ s/\n//g;
#Pull occurances of the element and drop their contents into @elementContents sequentially or by id attribs
while ($section =~ /<$element\s*(.*?)(\/>|>(.*?)<\/$element>)/gsi) {
$text = "";
@attribs = split(/"\s+/,$1);
$text = $3 if $3;
#strip CDATA tags from contents
$text =~ s/\<\!\[CDATA\[//g;
$text =~ s/\]\]\>//g;
foreach $attr (@attribs) {
next if !$attr;
($key,$value) = split(/=/,$attr);
$value =~ s/\"//g;
if ($key eq "id") {
$index = $value;
} else {
$text .= "<$key>$value$key>";
}
}
#Check if the indexing needs to be by id or increment
if (!defined($index)) {
if ($#elementContents = -1) {
$index = 1;
} else {
$index = $#elementContents + 1;
}
}
$elementContents[$index] = $text;
}
return @elementContents;
}
#Gets formatted Entries from $_[0]) to $_[1] out of $_[2] and returns them in an array that is a formatted table
sub getEntries($$) {
my $start=$_[0];
my $end=$_[1];
my $i;
my @formattedEntries;
my $currentformattedEntry;
@defaultfields = &getElements("field",$entries[0]);
@name = &getElements("name",$journals[$journalnum]);
unless ($cgi{'ignoreformatting'}) {
@border = &getElements("border",$journals[$journalnum]);
@fg = &getElements("fg",$journals[$journalnum]);
@bg = &getElements("bg",$journals[$journalnum]);
}
#Check $start and $end, alter if out of range
if ($start < 1) {$start = 1;}
if ($start > $#entries) {$start = $#entries;}
if ($end < 1) {$end = 1;}
if ($end > $#entries) {$end = $#entries;}
#Create formatted table with entries
$formattedEntries[0] .= "
\n"; }
if ($shownames[1]) {
$formattedEntries[0] .= "\t
$start) {
for ($i = $start; $i <= $end; $i++) {
if ($cgi{'search'}) {
if ($entries[$i] =~ /$cgi{'search'}/) {
$currentformattedEntry++;
$formattedEntries[$currentformattedEntry] .= "\t
\n";
return $NavLinks;
}
#Gets $_[0] entry from $_[1] and returns it formatted.
sub getEntry($) {
my $entry;
my $i;
my @usefields = split(/,/,$cgi{'field'});
my $usefield;
#Grab the fields from the requested entry
@fields = &getElements("field",$entries[$_[0]]);
#Grab entry name
@name = &getElements("name",$entries[$_[0]]);
#Grab entry properties unless CGI sez no
unless ($cgi{'ignoreformatting'}) {
@border = &getElements("border",$entries[$_[0]]);
@border = &getElements("border",$entries[0]) if !$border[1];
@fg = &getElements("fg",$entries[$_[0]]);
@fg = &getElements("fg",$entries[0]) if !$fg[1];
#Inherit fg from default if not explicitly set
if (!$fg[1]) { @fg = &getElements("fg",$journals[$journalnum]); }
@bg = &getElements("bg",$entries[$_[0]]);
@bg = &getElements("bg",$entries[0]) if !$bg[1];
}
#Create the formatted Entry if the entry contains data
if ($entries[$_[0]]) {
$entry .= "\t
View Entry\n";
}
$entry .= "\t
\n";
}
return $entry;
}
#returns Field with id of $_
sub getField($) {
my $field;;
#Pull name, background and foreground information out of field
@name = &getElements("name",$fields[$_[0]]);
unless ($cgi{'ignoreformatting'}) {
@fg = &getElements("fg",$fields[$_[0]]);
@fg = &getElements("fg",$defaultfields[$_[0]]) if !$fg[1];
@bg = &getElements("bg",$fields[$_[0]]);
@bg = &getElements("bg",$defaultfields[$_[0]]) if !$bg[1];
@border = &getElements("border",$fields[$_[0]]);
@border = &getElements("border",$defaultfields[$_[0]]) if !$border[1];
}
if ($fields[$_[0]]) {
$fields[$_[0]] =~ s/\<(bg|fg|name|border)\>.*\<\/(bg|fg|name|border)\>//g;
$field .= "\t\t