home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
- # Change above so it points to perl. Next line controls output buffering.
- $|=1;
-
-
- ########
- #
- # Reader feedback listing script, (c) Alex Cruickshank 2003 (alex@itreviews.co.uk)
- #
- # This code is released under the GNU Public Licence (see www.gnu.org for details) and is supplied
- # as is with no warranty either expressed or implied. No liability will be accepted for loss or damage of any kind.
- #
- # Always back up your data before using new software.
- #
- # You are free to use this script to manage and serve data on your site.
- # Please notify the author of any such use, as well as bug reports, modifications, etc.
- #
- # chmod this file to 755.
- #
- $maintitle = "Readers' feedback";
- # title for all pages
- #
- $database_name = "feedback.txt";
- # the path and name of the file containing the feedback; a plain text file containing one entry per line
- #
- $per_page = 10;
- # number of entries to display per page
- #
- $script_name = "/cgi-bin/feedback.cgi";
- # relative URL of this script
- #
- $HeaderFile = "head.htm";
- # HTML header file path
- #
- $FooterFile = "foot.htm";
- # HTML footer file path
- #
- $contact_script = "/cgi-bin/contact.cgi";
- # URL location of 'contact us' page
- #
- ########
-
-
- &parse;
- print "Content-type: text/html\n\n";
- if ($ENV{'QUERY_STRING'} eq "") {&main;}
- else {&show_feedback;}
- exit;
-
-
- sub parse { # handle form data
-
- read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
- @pairs = split(/&/, $buffer);
- foreach $pair (@pairs) {
- ($name, $value) = split(/=/, $pair);
- $value =~ tr/+/ /;
- $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
- if ($FORM{$name}) { $fields{$name} = $fields{$name}.",".$value; }
- else { $FORM{$name} = $value; }
- }
- }
-
-
- sub header { # load and use a formatted page header
-
- open (HEADER,"$HeaderFile");
- @header = <HEADER>;
- close (HEADER);
- foreach $headerline (@header) {
- print "$headerline";
- }
- print "<H1>$maintitle</H1>\n";
- }
-
-
- sub footer { # load and use a formatted page footer
-
- open (FOOTER,"$FooterFile");
- @footer = <FOOTER>;
- close (FOOTER);
- foreach $footerline (@footer) {
- print "$footerline";
- }
- }
-
-
- sub main { # show the intro page
- &header;
-
- print<<"OUTPUT";
- <P>
- Whenever a customer buys one of our products, we ask them to tell us what they think of our site, good or bad.
- <A HREF="$script_name?$database_name&1">Click here</A> to read their comments and suggestions.
- </P>
- <P>
- If you have your own comment or suggestion to make, <A HREF="$contact_script">click here</A>.
- </P>
- OUTPUT
-
- &footer;
- exit;
- }
-
-
- sub show_feedback { # display the feedback, breaking it up into pages
- &header;
-
- $line_count = 0;
- $counter = 0;
- $printed_lines = 0;
-
- $query = $ENV{'QUERY_STRING'};
- @query_terms = split (/&/, $query);
- ($database_name, $range) = @query_terms;
-
- open (FBDB, "$database_name");
- @open_comments = <FBDB>;
- close (FBDB);
-
- foreach (@open_comments) {
- $line_count++;
- }
-
- $page_total_int = int($line_count / $per_page);
- if ($page_total_int < ($line_count / $per_page)) {$page_total_int++;}
- print "<P>Page $range of $page_total_int</P>\n";
-
- $next_page = $range + 1;
- $prev_page = $range - 1;
-
- print "<UL>\n";
- foreach $rline (@open_comments) {
- chomp($rline);
- if ($counter / $per_page >= $range - 1) {
- if ($counter / $per_page < $range) {
- print "<LI>$rline </LI>\n";
- $printed_lines += 1;
- }
- }
- $counter++;
- }
- print "</UL>\n<BR><TABLE WIDTH=\"80%\" ALIGN=\"CENTER\" BGCOLOR=\"#EEEEEE\" BORDER=\"0\"><TR>\n";
- print "<TD ALIGN=\"LEFT\" WIDTH=\"33%\">\n";
- if ($prev_page > 0) {
- print "<A HREF=\"$script_name?$database_name&$prev_page\">< PREVIOUS</A>\n";
- }
- print "</TD><TD ALIGN=\"CENTER\" WIDTH=\"34%\">\n";
- print "<A HREF=\"$script_name\">FEEDBACK INDEX</A>\n";
-
- print "</TD><TD ALIGN=\"RIGHT\" WIDTH=\"33%\">\n";
- if ($next_page < $page_total_int + 1) {
- print "<A HREF=\"$script_name?$database_name&$next_page\">NEXT ></A>\n";
- }
- print "</TD></TR></TABLE>\n";
-
- &footer;
- exit;
- }
-