Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/05/2004, 13:10
papirpo
 
Fecha de Ingreso: febrero-2003
Mensajes: 44
Antigüedad: 21 años, 2 meses
Puntos: 0
Ayuda con Script php

Estoy trabajando con un script de encuestas y me gustaria convertirlo a uno que dependiendo la respuesta mostrara o no un formulario de registro. El script en cuestion es:
Código PHP:
<?php
$ip 
getenv(REMOTE_ADDR);
$RESULT_FILE_NAME "poll_data.txt";
$que "question.txt";
$ans "ans.txt";
$fn fopen ($que"r");
$puff fread ($fnfilesize($que));
fclose ($fn);
$QUESTION "$puff";
$lis0;
$plsr file("ans.txt");
for(
$x=0;$x<sizeof($plsr);$x++) {
$temp explode("|",$plsr[$x]);
$list[$lis] = $temp[0];
$lis++;
}
$ANSWER $list;
extract($HTTP_GET_VARS);
extract($HTTP_POST_VARS);
$fname="ip_log.dat";
if (
strlen($answer)<=0&&!$vresult){
echo 
"<FORM METHOD=\"POST\">\n";
echo 
"<TABLE  align=center border=1 borderColor=#001199 cellPadding=2 class=normaltext                    style=\"BORDER-BOTTOM-COLOR: #001199; BORDER-COLLAPSE: collapse; BORDER-LEFT-COLOR: #001199; BORDER-RIGHT-COLOR: #001199; BORDER-TOP-COLOR: #001199\" >\n";
echo 
"<TR><TH>$QUESTION</TH></TR>\n";
while (list(
$key$val) = each($ANSWER)) {
echo 
"<TR><TD align=\"left\"><INPUT TYPE=\"radio\" NAME=\"answer\" VALUE=\"$key\"> $val</TD></TR>\n";}
echo 
"<TR><TD align=\"center\"><INPUT TYPE=\"Submit\" NAME=\"vote\" VALUE=\" Vote \"></TD></TR>\n";
echo 
"<TR><TD align=\"center\"></form><form method=post><input type=hidden name=vresult value=1><INPUT TYPE=\"Submit\" NAME=\"result\" VALUE=\"Result\">\n";
echo 
"</TABLE></form>";
}
if (
strlen($answer)>0) {
$plsr file("logger.txt");
for(
$x=0;$x<sizeof($plsr);$x++) {
$temp explode("|",$plsr[$x]);
}
if(
$ip==$temp[0] && strlen($answer)>){
echo 
"<font color=red size=1><div align=center>You have already voted</div></font>";
$file_array file($RESULT_FILE_NAME);
if (
$answer count($ANSWER) && $vote) {
while (list(
$key$val) = each($file_array)) {
$total += $val;
}
echo 
"<TABLE  align=center border=1 borderColor=#001199 cellPadding=2 class=normaltext                    style=\"BORDER-BOTTOM-COLOR: #001199; BORDER-COLLAPSE: collapse; BORDER-LEFT-COLOR: #001199; BORDER-RIGHT-COLOR: #001199; BORDER-TOP-COLOR: #001199\" width=60%>\n";
echo 
"<tr><th>Options</th><th>Percentage</th><th>Votes</th></tr>";
while (list(
$key$val) = each($ANSWER)){
$percent =  $file_array[$key] * 100 $total;
$percent_int floor($percent);
$percent_float number_format($percent1);
$tp += $percent_float;
if(
$percent_int>=75){
$color="blue";
}
elseif(
$percent_int>=50){
$color="green";
}
elseif(
$percent_int>=25){
$color="orange";
}
elseif(
$percent_int<25){
$color="red";
}
echo 
"<tr><td> $ANSWER[$key] </td><td><table cellpadding=1 cellspacing=0 width=100% border=0 bgcolor=black><tr><td><table cellpadding=0 cellspacing=0 border=0 width=100%>
<tr>
<td bgcolor=$color width=$percent_int% height=10 style=border:0 >
<spacer type=block width=2 height=8>
</td>
<td bgcolor=white width=91% height=10 style=border:0 >
<spacer type=block width=2 height=8>
</td>
</tr>
</table>
</td>
</tr>
</table>$percent_float%</td><td>$file_array[$key]</td></tr>"
;
}
$tv=$total;
echo 
"<td>Total Votes: $tv</td></TABLE>";
}
}elseif (
strlen($answer)>&& $ip!=$temp[0]){
$file_array file($RESULT_FILE_NAME);
if (
$answer count($ANSWER) && $vote) {
$old_answer $file_array[$answer];
$old_answer preg_replace("/\n\r*/"""$old_answer);
$file_array[$answer] = ($old_answer 1)."\n";
$fname="logger.txt";
$fq fopen($fname"a++");
fwrite ($fq$ip);
fwrite ($fq"|");
fwrite ($fq"\n");
fclose ($fq);
$file join(''$file_array);
$fp fopen("$RESULT_FILE_NAME""w");
            
flock($fp1);
                
fputs($fp$file);
                
flock($fp3);
                
fclose($fp);
                echo 
"<div align=center>Vote saved </div>";
}
while (list(
$key$val) = each($file_array)) {
$total += $val;
}
echo 
"<TABLE  align=center border=1 borderColor=#001199 cellPadding=2 class=normaltext                    style=\"BORDER-BOTTOM-COLOR: #001199; BORDER-COLLAPSE: collapse; BORDER-LEFT-COLOR: #001199; BORDER-RIGHT-COLOR: #001199; BORDER-TOP-COLOR: #001199\" width=60%>\n";
echo 
"<tr><th>Options</th><th>Percentage</th><th>Votes</th></tr>";
while (list(
$key$val) = each($ANSWER)){
$percent =  $file_array[$key] * 100 $total;
$percent_int floor($percent);
$percent_float number_format($percent1);
$tp += $percent_float;
if(
$percent_int>=75){
$color="blue";
}
elseif(
$percent_int>=50){
$color="green";
}
elseif(
$percent_int>=25){
$color="orange";
}
elseif(
$percent_int<25){
$color="red";
}
echo 
"<tr><td> $ANSWER[$key] </td><td><table cellpadding=1 cellspacing=0 width=100% border=0 bgcolor=black><tr><td><table cellpadding=0 cellspacing=0 border=0 width=100%>
<tr>
<td bgcolor=$color width=$percent_int% height=10 style=border:0>
<spacer type=block width=2 height=8>
</td>
<td bgcolor=white width=91% height=10 style=border:0>
<spacer type=block width=2 height=8>
</td>
</tr>
</table>
</td>
</tr>
</table>$percent_float%</td><td>$file_array[$key]</td></tr>"
;
}
$tv=$total;
echo 
"<td>Total Votes: $tv</td></TABLE>";
}
else {
echo 
"Please Select an option first";
}
}
if (!empty (
$vresult)){
$file_array file($RESULT_FILE_NAME);
while (list(
$key$val) = each($file_array)) {
$total += $val;
}
echo 
"<TABLE  align=center border=1 borderColor=#001199 cellPadding=2 class=normaltext                    style=\"BORDER-BOTTOM-COLOR: #001199; BORDER-COLLAPSE: collapse; BORDER-LEFT-COLOR: #001199; BORDER-RIGHT-COLOR: #001199; BORDER-TOP-COLOR: #001199\" width=60%>\n";
echo 
"<tr><th>Options</th><th>Percentage</th><th>Votes</th></tr>";
while (list(
$key$val) = each($ANSWER)){
$percent =  $file_array[$key] * 100 $total;
$percent_int floor($percent);
$percent_float number_format($percent1);
$tp += $percent_float;
if(
$percent_int>=75){
$color="blue";
}
elseif(
$percent_int>=50){
$color="green";
}
elseif(
$percent_int>=25){
$color="orange";
}
elseif(
$percent_int<25){
$color="red";
}
echo 
"<tr><td> $ANSWER[$key] </td><td><table cellpadding=1 cellspacing=0 width=100% border=0 bgcolor=black><tr><td><table cellpadding=0 cellspacing=0 border=0 width=100%>
<tr>
<td bgcolor=$color width=$percent_int% height=10 style=border:0 >
<spacer type=block width=2 height=8>
</td>
<td bgcolor=white width=91% height=10 style=border:0 >
<spacer type=block width=2 height=8>
</td>
</tr>
</table>
</td>
</tr>
</table>$percent_float%</td><td>$file_array[$key]</td></tr>"
;
}
$tv=$total;
echo 
"<td>Total Votes: $tv</td></TABLE>";
}
?>
Se que la respuesta correcta sería la dos pero no consigo averiguar cómo hacer para que me muestre un formulario de registro, desde ya gracias a todos por vuestro interés.

Un saludo Papirpo, y recordad que cuando digo que soy novato me refiero a que soy muy novato