#!/usr/bin/perl use CGI qw(:standard); use Time::Local; $html_fragments_dir="/home/toby/webs/www.qtq.org/htdocs/mud2/NOW"; $polls="/home/toby/webs/www.qtq.org/htdocs/mud2/NOW/polls"; $pollname=param('question'); $polldir="$polls/$pollname"; $questionfile="$polldir/question.txt"; $outputfile="$$.html"; $outputdir="/home/toby/webs/www.qtq.org/htdocs/mud2/NOW/tmp"; $outputurl="/mud2/NOW/tmp"; if (length($pollname)>0) { open (QUESTION,"$questionfile"); $question=; chomp($question); close (QUESTION); } $listofpolls=&get_poll_list; &OutputPage; print "Location: $outputurl/$outputfile\n\n"; exit; sub get_poll_list { local ($question,$output,$starttime,$endtime,$startepoch,$endepoch); local ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst,$month); $output="

Ballots

    "; foreach (`ls -1t $polls`) { chomp; if (-e "$polls/$_") { open(QUESTION,"$polls/$_/question.txt"); $question=; chomp($question); #$output.="
  1. $question"; open(START,"$polls/$_/closed_begin.txt") or open(START,"$polls/$_/begin.txt"); $startepoch=; close(START); chomp($startepoch); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($startepoch); $month=(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[$mon]; $year=substr($year,length($year)-2,2); $starttime="$mday $month $year"; open(END,"$polls/$_/closed_end.txt") or open(END,"$polls/$_/end.txt"); $endepoch=; close(END); chomp($endepoch); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($endepoch); $month=(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[$mon]; $year=substr($year,length($year)-2,2); $endtime="$mday $month $year"; $middleepoch=(($endepoch-$startepoch)/2)+$startepoch; $ballot{$middleepoch}="
  2. $question ($starttime - $endtime)"; #$output.=" ($starttime - $endtime)"; } } @keys=sort by_number keys(%ballot); foreach (@keys) { $output.=$ballot{$_}; } $output.="
"; return ($output); } sub OutputPage { open(OUTPUT,">$outputdir/$outputfile"); print OUTPUT &Template("poll_list.htmlf"); close(OUTPUT); } sub by_number { $b <=> $a; } sub Template { local(*FILE); local($file); local($HTML); local($_); $file = $html_fragments_dir."/".$_[0] || die "Template : No template file specified\n"; open(FILE, "$file") || print " Error: $!"; while () { $HTML .= $_; } close(FILE); $HTML =~ s/\$(\w+)/${$1}/g; return $HTML; }