#!/usr/bin/perl
##########################################################
# CSVread 17/Nov/2003
# © 1999-2003 EZscripting.co.uk
# Script by Alexandre Golovkine
##########################################################
my $CSV_file = "database.txt";
my $HTML_template = "featuredtopic_submissions.html";
my $no_matches_found = "Sorry, no results found";
##########################################################
#%FORM = parse_cgi();
print "Content-type: text/html\n\n";
(my $head, my $tmp, my $foot) = get_html($HTML_template);
$qs=$ENV{'QUERY_STRING'};
##read db
my @data = read_file($CSV_file);
chomp $data[0];
my @fields= split('\¦', shift @data);
$base_length = @data;
error("You have bad file!") if!@fields;
error("Database is clear!") if $base_length<1;
if($qs =~m/header=([^\&\Z]*)/){push @header,$1;}
@conditions=split(/&/,$qs);
my $a=0;
foreach (@conditions){
($name, $value) = split(/=/, $_);
if($name eq 'search'){
$FORM{search} = $value;
@data = search($value, $header[0]);
}
elsif($name eq 'header'){}
elsif($_=~/([^=<>!]+)!=([^=<>!]+)/){@data = search($value, $1, "!=");}
elsif($_=~/([^=<>!]+)=([^=<>!]+)/){@data = search($value, $1);}
$a++;
}
my $result;
##matched data
foreach(@data){
chomp;
@line = split('\¦', $_);
$a=0; %INSERT=();
foreach(@fields){$INSERT{$_} = $line[$a++];}
$result.=get_record($tmp)
}
%INSERT=();
$INSERT{'#_matches'} = @data;
$INSERT{'#_total'} = $base_length;
print get_record($head), $result, get_record($foot);
exit;
#########################################################
sub search{
my $word=shift;
my $field=shift;
my $action=shift;
$word=~tr/+/ /;
$word=~s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C",hex($1))/eg;
my $position=-1;
my $a=0;
if($field){
$field=~tr/+/ /;
$field=~s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C",hex($1))/eg;
foreach(@fields){$position=$a if $_ eq $field; $a++;}
}
my %match;
$word =~s/ +/ /g;
my @new_data=();
my @keys= split(" ", $word);
if($action eq '!='){for(0..@data-1){$match{$_} = 1;}}
foreach $key (@keys){
$a=0;
foreach $record (@data){
@line = split('\¦', $record);
if($field && $position>-1){
if($action eq '!='){
$match{$a} = 0 if $line[$position]=~m/$key/i;
}
else{$match{$a} = 1 if $line[$position]=~m/$key/i;}
}
else{
foreach(@line){if ($_=~m/$key/i){$match{$a} = 1; last;}}
}
$a++;
}
}
$a=0; my $b=0;
foreach(@data){
$new_data[$b++] = $_ if $match{$a};
$a++;
}
return @new_data;
}
sub get_record{
my $text = $_[0];
$text =~ s{<<(.*?)>>}{exists($INSERT{$1})? $INSERT{$1} : ""}gsex;
return $text;
}
sub get_html{
my @txt = read_file($_[0]);
foreach(@txt){$txt.=$_;}
$txt=~/(.*)<template>(.*)<\/template>(.*)/s;
error("Template-tag not found!") if!$1 or!$2;
return ($1,$2,$3);
}
sub read_file{
open(F, $_[0]) ¦¦ error("Can't open file $_[0]!");
my @data = <F>;
close F;
return @data;
}
sub error{
print "<html><head><title>Error</title>$style</head><body><br><br><br><font color=red><h3>$_[0]</h3></font></body></html>";
exit;
}
In essense, the form that the PL file pulls all these fields from has about 50 fields, and there should be about 30 instances of each field, so you can see where this may get a little cluttered. I'd like to be able to have my html template pull the first field (in this case, is called 'title') and only list the title from each form that's been submitted. Then each title will be linked to a second page that has all the fields displayed via another html template. Does this make sense? Is this possible? Do you need to see my current html template? I'm sorry for not being descriptive or posting the right thing with my first post, as I really don't know how to accomplish this and don't know what you all need to see in order to understand what I'm trying to convey, without 'dropping' my url. :D
Thanks!
mostly with large amounts of code like that, people don't have the time to work through it all and they often go unanswered.
So since my perl isn't great, do you understand the code well enough to figure out where/ what you need to change? Just need a little help changing it.
essentially I would play with the template to see what can be changed (keep a copy of the original, obviously). You may need to seperate templates on for the linked list and one for the detail pages.
You also may be able to use a param for it. if detail then grab all else only add the link to list.