[GastForen Archiv Perl und CGI cgi-script - eigentlich einfach

  • Suche
  • Hilfe
  • Lesezeichen
  • Benutzerliste
Archiv - Archivierte Foren
Themen
Beiträge
Moderatoren
Letzter Beitrag

cgi-script - eigentlich einfach

bscyb1898
Beiträge gesamt: 5

28. Sep 2006, 13:58
Beitrag # 1 von 1
Bewertung:
(4493 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Guten Tag. Ich hoffe dass mir jemand weiterhelfen kann ;-)

Ich habe ein einfaches umfragescript heruntergeladen. Nun komme ich mit einigen (Pfad)-Angaben nicht ganz zurecht, und zwar:

$dpaths = "votedata";
$cgi_path = "votedata/";
$template_path = "votedata";


nun sollte das "votdata" auf meine website angepasst werden. kann mir jemand kurz ein beispiel dafür geben. besten dank

hier das ganze script:

Code
#!/usr/bin/perl 
################################################################################
#
#Rate a site version 1
#GB Resources http://cgi-resource.co.uk
#
#Links in success and error page must be left intact
#
################################################################################

getdata(%fields);

################################################################################
#paths to where you want to put the data files and where your graph images are.
#
$dpaths = "votedata";
$ipaths = "votedata";
$cgi_path = "http://www.simon-willener.ch/cgi-bin/";
$template_path = "votedata";
################################################################################
print "Content-type: text/html\n\n";

if ($fields{'rating'}){
&vote;
}
elsif ($fields{'breakdown'}){
&breakdown;
}
else {
&display;
}

sub vote {
################################################################################
my ($data, $id, $votes, $nvotes, $rating, $nrating, $ip, $count, $i, $rateb);
$id = $fields{'id'};
if (open(VOTE,"$dpaths/rate2m$id.txt")) {
chomp ($data = <VOTE>);
chomp ($rateb = <VOTE>);
close(VOTE);
($votes, $rating, $ip) = split(/\|/,$data);
print "error no rating given, please go back and select a rating" and return unless (($fields{'rating'} > 0) and ($fields{'rating'} < 11));
&vote_error and return if ($ENV{'REMOTE_ADDR'} eq $ip);
$nvotes = $votes + 1;
$nrating = sprintf ("%.2f", ((($rating*$votes) + $fields{'rating'})/$nvotes));
my @votes = split(/\|/,$rateb);

open (VOTE, ">$dpaths/rate2m$id.txt") or die("doh, there is the following problem: $! \n");
print VOTE "$nvotes|$nrating|$ENV{'REMOTE_ADDR'}\n";
foreach $i (@votes){
$count++;
if ($count == $fields{'rating'}){
$i = $i + 1;
print VOTE "$i|";
}
else {
print VOTE "$i|";
}
}
close VOTE;
}
else {
open (VOTE, ">$dpaths/rate2m$id.txt") or die("doh, there is the following problem: $! \n");
print VOTE "1|$fields{'rating'}|$ENV{'REMOTE_ADDR'}\n";
foreach $i (1..10){
$count++;
if ($count == $fields{'rating'}){
print VOTE "1|";
}
else {
print VOTE "0|";
}
}
close VOTE;
}
&vote_success;
}

sub display {
################################################################################
my ($data, $id, $votes, $nvotes, $rating, $nrating, $ip);
$total = $fields{'id'};
print "error no id number defined" and return if (!$total);
if (open (VOTE,"$dpaths/rate2m$total.txt")){
chomp ($data = <VOTE>);
close(VOTE);
($votes, $rating, $ip) = split(/\|/,$data);
$rate = int($rating);
#print out the html
$content=qq|
Votes:<b>$votes</b>
Rating:
</font>
<a href="javascript:;" onClick="window.open('$cgi_path/ratem2.cgi?id=$total&breakdown=yes','','width=300,height=400,resizable=yes,scrollbars=1')">
<IMG SRC="$ipaths/gbar$rate.gif" ALT="Rating = $rating" border=0>
Ratings Breakdown</a>
</form>
|;
}
else {
$content = qq|
Not votes yet!</font></form>|;
}

$template= "$template_path/ratem2.html";
&templater;
}


sub breakdown {
################################################################################
my ($count2, $ip, $data, $count, $t, $contents, $i, $id, $id, $height);
$id = $fields{'id'};
print "error no id number defined" and return if (!$id);
$lrate = 11;
$hrate = $count2 = 0;
open(VOTE,"$dpaths/rate2m$id.txt") or die("doh!: $! \n");
chomp ($d = <VOTE>);
chomp ($data = <VOTE>);
close(VOTE);
my @votes = split(/\|/,$data);

foreach $i (@votes){
$count++;
$total = $total + $i;
if ($i){
($hrate = $count) if ($hrate < $count);
($lrate = $count) if ($lrate > $count);
}
}
foreach $i (@votes) {
$count2++;
if ($total > 5){
$height = int(($i/$total)*400);
}
else{
$height = int(($i/$total)*200);
}
if ($i){
if ($i > 1){
$content .= qq|<td VALIGN=BOTTOM BGCOLOR="#999999"><img SRC="$ipaths/cbar2.jpg" height=1 width=20 alt="$i people gave a rating of $count2"><br><img SRC="$ipaths/cbar1.jpg" height=$height width=20 alt="$i people gave a rating of $count2"></td>|;
}
else{
$content .= qq|<td VALIGN=BOTTOM BGCOLOR="#999999"><img SRC="$ipaths/cbar2.jpg" height=1 width=20 alt="$i person gave a rating of $count2"><br><img SRC="$ipaths/cbar1.jpg" height=$height width=20 alt="$i person gave a rating of $count2"></td>|;
}

}
else {
$content .= qq|<td VALIGN=BOTTOM BGCOLOR="#999999"><img SRC="$ipaths/cbar2.jpg" height=1 width=20 alt="$i people gave a rating of $count2"><br></td>
|;
}
}

$template= "$template_path/ratem2_graph.html";
&templater;
}

sub vote_success {
################################################################################
#print a success page
$content = qq|<b> Vote added:</b>
<br>
<br>
Thanks for the vote.
<br><br> <br>
Rate a site by <a href="http://cgi-resource.co.uk">GB Resources</a>|;
$template= "$template_path/ratem2_sucess.html";
&templater;

}

sub vote_error {
################################################################################
#print an error page
$content = qq|You have already voted recently!
<br><br><br>
Rate a site by <a href="http://cgi-resource.co.uk">GB Resources</a>|;
$template= "$template_path/ratem2_error.html";
&templater;
}

sub templater {
################################################################################
open(TEMPHTML, $template) or print ("error can't open template<br> Reason $!");
while(<TEMPHTML>){
$pcontent .= $_;
}
;
$pcontent =~ s/<%content%>/$content/g;
$pcontent =~ s/<%lrate%>/$lrate/g;
$pcontent =~ s/<%hrate%>/$hrate/g;
$pcontent =~ s/<%total%>/$total/g;

print $pcontent;

}



sub getdata {
################################################################################
my ($buffer);

if ($ENV{'REQUEST_METHOD'} eq 'GET') {
$buffer = $ENV{'QUERY_STRING'};
}
else {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}

foreach (split(/&/, $buffer)) {
my($key, $value) = split(/=/, $_);
$value =~ tr/+/ /;
$value =~ s/%(..)/pack('c', hex($1))/eg;
$fields{$key} = $value;
}
}

X