hallo,
möchte ein poll-skript mit flash nutzen, dabei muss aber eine bestimmte formatieren eingehalten werden.
suche eine möglichkeit die lplist.txt so zu formatieren, das sie im endeffekt folgendermassen formatiert ist:
&antwort1=14&antwort2=10&antwort3=19&
wär schön, wenn mir wer helfen kann, bzw mir sagen kann, welche zeile im skript dafür verantwortlich ist, das die antworten voneinander getrennt werden...
PHP-Code:
<?php
// settings:
$filename="lplist.txt"; //If you change this, change it in the settings.inc file too!
if (!isset($adminstep)) {
$adminstep=1;
}
if($adminstep==1) {
$adminstep1str='<form action="lp_admin.php" method="post" name="form1">Number of Items:<input type="hidden" name="adminstep" value="'.($adminstep+1).'"><input type="Text" name="numofitems" size="5"><br>Poll Question:     <input type="Text" name="question" size="25"><br><input type="Submit" value="OK"></form>';
}
if($adminstep==2) :
$adminstep2str='<form action="lp_admin.php" method="post" name="form2"><input type="hidden" name="question" value="'.$question.'"><input type="hidden" name="adminstep" value="'.($adminstep+1).'">';
if (isset($numofitems)) {
$hector=$numofitems+0;
if($numofitems<=0) {
$adminstep=0;
$errtext="The number of items should be an integer, above zero";
$hector=-1;
}
}
$in=0;
while($hector > 0) {
$adminstep2str=$adminstep2str.'Item '.($in+1).'<br><input type="Text" size="25" name="item['.$in.']"><br><br>';
$in++;
$hector=$hector-1;
}
$adminstep2str=$adminstep2str.'<input type="hidden" name="numofitems" value='.$numofitems.'><input type="Submit" value="OK"></form>';
endif;
if($adminstep==3) {
$fp=fopen($filename, "w");
$hector=$numofitems+0;
$in=0;
$linetoadd=stripslashes($question.":");
fputs($fp, $linetoadd);
while($hector > 0) {
$linetoadd=stripslashes($item[$in]).":0:";
fputs($fp, $linetoadd);
$in++;
$hector=$hector-1;
}
fclose($fp);
}
?>
<table border=0 width=400 bgcolor=#FFFFFF>
<tr>
<td><font size=2 color=#000000>
<strong>Step <?php echo($adminstep); ?></strong>
</td>
</tr>
<tr>
<td bgcolor="#000000">
<font size="2" color="#FFFFFF">
<br>
<blockquote>
<?php if($adminstep==0) {
echo($errtext.'<br>');
echo('<a href="lp_admin.php?adminstep=1">Try Again</a>');
}
if($adminstep==1) {
echo($adminstep1str);
}
if($adminstep==2) {
echo($adminstep2str);
}
if($adminstep==3) {
echo('File has been created... Poll can be used!<br><br><a href="lp_test.php">Test the Poll</a><br><br><br><font size="1"><a href="lp_admin.php?adminstep=1">Back to step 1</a> WARNING: all data will be destroyed!');
}
?>
ups, denke das gehört noch dazu, wird jedenfalls includet:
PHP-Code:
<?php
include("lp_settings.inc"); //include file containing general settings
function SumArray($arr) {
$h=count($arr); $in=0; $m=0;
while ($in<$h) { $m += $arr[$in]; $in++; }
return $m;
}
function ReadElements() {
global $filename;
$fp=fopen($filename, "r");
$file_contents=fread($fp,filesize($filename)-1);
fclose($fp);
$elements=explode(":",$file_contents);
$h=(count($elements)-1)/2;
$question=$elements[0];
$in=0;
while ($h>$in) {
$item[$in]=$elements[(2*$in+1)];
$itemvoted[$in]=$elements[(2*$in+2)];
$in++;
}
return array ($item, $itemvoted, $question);
}
if (isset($votingstep)) {
function ShowTheStuff($item, $itemvoted, $graph_width, $graph_height) {
$hector=count($itemvoted);$totalvotes=0;$in=0;$stepstr='';
$totalvotes=SumArray($itemvoted);
$in=0;
if ($totalvotes==0) { $totalvotes=0.0001; }
while ($in<$hector) {
$stepstr=$stepstr.$item[$in].': '.(int)(($itemvoted[$in]/$totalvotes)*100).'%<br>';
$timesred=(int)((($itemvoted[$in]/$totalvotes))*$graph_width);
$stepstr=$stepstr.'<img height='.$graph_height.' width='.$timesred.' src="lp_1.gif"><img height='.$graph_height.' width='.($graph_width-$timesred).' src="lp_0.gif"><br><br>';
$in++;
}
return $stepstr;
}
}
if (!isset($votingstep)) {
$votingstep=1;
}
if ($votingstep==2) {
if(!isset($radios)){
$votingstep=1;
} // detect if someone has clicked the voting button without choosing an item
}
if ($votingstep==1) {
setcookie("votingstep","2",time()+$time_beteen_votes);
$mainstr=$message1;
$step1str='<form action="'.$callingfile.'" method="post" name="form1">';
list ($item, $itemvoted, $question) = ReadElements();
$totalvotes=SumArray($itemvoted);
$in=0;
$datop=count($item);
while($in<$datop){
$step1str=$step1str.'<input type="radio" name="radios" value="'.$in.'"> '.$item[$in].'<br>';
$in++;
}
$step1str=$step1str.'<br><input type="Submit" value="Vote!"></form>';
}
if ($votingstep==2) {
setcookie("votingstep","3",time()+$time_beteen_votes);
$mainstr=$message2;
list ($item, $itemvoted, $question) = ReadElements();
$itemvoted[$radios]=$itemvoted[$radios]+1;
$totalvotes=SumArray($itemvoted);
$fp=fopen($filename, "w");
$hector=count($item);
$in=0;
$linetoadd=$question.':';
fputs($fp, $linetoadd);
while($in<$hector) {
$linetoadd=$item[$in].':'.$itemvoted[$in].':';
fputs($fp, $linetoadd);
$in++;
}
fclose($fp);
$step2str=ShowTheStuff($item, $itemvoted, $graph_width, $graph_height);
}
if ($votingstep==3) {
$mainstr=$message3;
list ($item, $itemvoted, $question) = ReadElements();
$totalvotes=SumArray($itemvoted);
$step3str=ShowTheStuff($item, $itemvoted, $graph_width, $graph_height);
}
?>