Da wäre er^^
<?php
# Copyright by: Manuel
# Support: www.ilch.de
defined ('main') or die ( 'no direct access' );
$title = $allgAr['title'].' :: Umfrage';
$hmenu = 'Umfrage';
$design = new design ( $title , $hmenu, 0 );
$design->header();
$max = 25; // max. Umfrageoptionen
$wbbuserdata = 900 ;
if ($_SESSION['authright'] < '0')
{
If ($menu->get(0) == "poll" AND $menu->getA(1) == "t" AND $menu->getE(1) != "" ){
$fid = $menu->getE(1);
$tpl = new tpl ( 'poll/pollstart.htm' );
$tpl->set('maxpolloptions', $max);
$tpl->set('fid', $fid);
if(isset($_POST['send'])) {
$question=htmlspecialchars(trim($_POST['question']));
$abf = "INSERT INTO bb1_polls (pollid,question,starttime,choicecount,timeout) VALUES (NULL,'".addslashes($question)."','".time()."','".intval($_POST['choicecount'])."','".intval($_POST['timeout'])."')";
// $erg = db_query($abf);
$pollid = db_last_id();
$pollid=113;
$options=explode("\\n",$_POST['polloptions']);
$count=1;
for($i=0;$i<count($options);$i++) {
$options[$i]=trim($options[$i]);
if(!$options[$i]) continue;
// db_query("INSERT INTO bb1_polloptions (polloptionid,pollid,polloption,showorder) VALUES (NULL,'$pollid','".addslashes($options[$i])."','$count')");
$count++;
}
$question=str_replace("'","\'",$question);
$tpl = new tpl ( 'poll/pollstart_give_parent.htm' );
$ar = array(
'question' => $question,
'fid' => $fid,
'pollid' => $pollid
);
$tpl->set_ar_out($ar, 0);
}
else {
$question= "";
$choicecount=1;
$timeout=0;
$ar = array(
'question' => $question,
'choicecount' => $choicecount,
'imagefolder' => "include/images/poll",
'timeout' => $timeout
);
$tpl->set_ar_out($ar, 0);
}
}
//////////////////////////////////
//////////// polledit ////////////
//////////////////////////////////
If ($menu->getA(1) == "e"){
$pollid = $menu->getE(1);
if ($pollid !=""){
$tpl = new tpl ( 'poll/polledit.htm' );
$tpl->set('maxpolloptions', $max);
//if(!$wbbuserdata['issupermod'] && !$modpermissions['userid']) access_error();
if(isset($_REQUEST['action'])) $action=$_REQUEST['action'];
else $action="";
if(isset($_REQUEST['polloptionid'])) $polloptionid=intval($_REQUEST['polloptionid']);
else $polloptionid=0;
if($action=="polldelete") {
if(isset($_POST['deletepoll']) && $_POST['deletepoll']==1) {
db_query("DELETE FROM bb1_polls WHERE pollid='$pollid'");
db_query("DELETE FROM bb1_polloptions WHERE pollid='$pollid'");
db_query("DELETE FROM bb1_votes WHERE id='$pollid' AND votemode='1'");
db_query("UPDATE bb1_threads SET pollid='0' WHERE pollid='$pollid'");
}
// header("Location: thread.php?threadid=$poll[threadid]&sid=$session[hash]");
exit();
}
if($action=="ShiftToTop" && $polloptionid) {
list($showorder)=db_result(db_query("SELECT showorder FROM bb1_polloptions WHERE polloptionid='$polloptionid'"),0);
if($showorder > 1) {
db_query("UPDATE bb1_polloptions SET showorder=showorder+1 WHERE pollid='$pollid' AND showorder<'$showorder'");
db_query("UPDATE bb1_polloptions SET showorder=1 WHERE polloptionid='$polloptionid'");
}
}
if($action=="ShiftUp" && $polloptionid) {
list($showorder)=db_result(db_query("SELECT showorder FROM bb1_polloptions WHERE polloptionid='$polloptionid'"),0);
if($showorder>1) {
db_query("UPDATE bb1_polloptions SET showorder=showorder+1 WHERE pollid='$pollid' AND showorder='".($showorder-1)."'");
db_query("UPDATE bb1_polloptions SET showorder=showorder-1 WHERE polloptionid='$polloptionid'");
}
}
if($action=="ShiftDown" && $polloptionid) {
list($optioncount)=db_result(db_query("SELECT COUNT(*) FROM bb1_polloptions WHERE pollid='$pollid' "),0);
list($showorder)=db_result(db_query("SELECT showorder FROM bb1_polloptions WHERE polloptionid='$polloptionid'"),0);
if($showorder < $optioncount) {
db_query("UPDATE bb1_polloptions SET showorder=showorder-1 WHERE pollid='$pollid' AND showorder='".($showorder+1)."'");
db_query("UPDATE bb1_polloptions SET showorder=showorder+1 WHERE polloptionid='$polloptionid'");
}
}
if($action=="ShiftToBottom" && $polloptionid) {
list($optioncount)=db_result(db_query("SELECT COUNT(*) FROM bb1_polloptions WHERE pollid='$pollid'"),0);
list($showorder)=db_result(db_query("SELECT showorder FROM bb1_polloptions WHERE polloptionid='$polloptionid'"),0);
if($showorder < $optioncount) {
db_query("UPDATE bb1_polloptions SET showorder=showorder-1 WHERE pollid='$pollid' AND showorder>'$showorder'");
db_query("UPDATE bb1_polloptions SET showorder='$optioncount' WHERE polloptionid='$polloptionid'");
}
}
if($action=="delentry" && $polloptionid) {
list($showorder)=db_result(db_query("SELECT showorder FROM bb1_polloptions WHERE polloptionid='$polloptionid'"),0);
db_query("DELETE FROM bb1_polloptions WHERE polloptionid='$polloptionid'");
db_query("UPDATE bb1_polloptions SET showorder=showorder-1 WHERE pollid='$pollid' AND showorder>'$showorder'");
}
if($action=="addentry") {
list($showorder)=db_result(db_query("SELECT MAX(showorder) FROM bb1_polloptions WHERE pollid='$pollid'"),0);
db_query("INSERT INTO bb1_polloptions (polloptionid,pollid,polloption,votes,showorder) VALUES (NULL,'$pollid','".addslashes($_REQUEST['option'])."','0','".($showorder+1)."')");
}
if($action=="saveentry" && $polloptionid) db_query("UPDATE bb1_polloptions SET polloption='".addslashes($_REQUEST['option'])."' WHERE polloptionid='$polloptionid'");
if($action=="savepoll") {
db_query("UPDATE bb1_polls SET question='".addslashes($_REQUEST['question'])."', choicecount='".addslashes($_REQUEST['choicecount'])."', timeout='".addslashes($_REQUEST['timeout'])."' WHERE pollid='$pollid'");
// header("Location: thread.php?threadid=$poll[threadid]&sid=$session[hash]");
exit();
}
$result = "SELECT * FROM bb1_polls WHERE pollid= ".$pollid." ";
$erg = db_query($result);
while ($row = db_fetch_assoc($erg)){
$question=$row['question'];
$choicecount=$row['choicecount'];
$timeout=$row['timeout'];
}
$result="SELECT * FROM bb1_polloptions WHERE pollid='$pollid' ORDER BY showorder ASC";
$erg = db_query($result);
while ($row = db_fetch_assoc($erg)) $polloptions.=makeoption($row['polloptionid'],htmlspecialchars($row['polloption']),$polloptionid);
$ar = array(
'question' => $question,
'choicecount' => $choicecount,
'timeout' => $timeout,
'pollid' => $pollid,
'imagefolder' => "include/images/poll",
'polloptions' => $polloptions
);
$tpl->set_ar_out($ar, 0);
}
}
//////////////////////////////////
//////////// poll anzeigen ///////
//////////////////////////////////
If ($menu->getA(1) == "s"){
$pollid = $menu->getE(1);
$polloptions = array();
$tpl= new tpl ('poll/thread_poll.htm');
$tpl->set ('pollid', $pollid);
unset($votecheck);
$poll=db_fetch_assoc(db_query("SELECT * FROM bb1_polls WHERE pollid= ".$pollid." "));
list($memberscount)=db_result(db_query("SELECT count(id) FROM bb1_votes WHERE id= ".$pollid." AND votemode='1'"),0);
if($poll['timeout']==0) $timeout=time()+1;
else $timeout=$poll['starttime']+$poll['timeout']*86400;
$question = $poll['question'];
$tpl->set_out('question', $question , 0);
if($menu->getE(2)!=1 && $timeout >= time()) {
$votecheck = db_fetch_assoc(db_query("SELECT id AS pollid FROM bb1_votes WHERE id= ".$pollid." AND votemode=1 AND userid= ".$wbbuserdata." ")); // user moch ändern '".$_SESSION['authid']."'"
}
if($menu->getE(2)==1 || $votecheck['pollid'] || $timeout<time()) { // already voted; show result
$votes=0;
unset($polloption);
$totalvotes=0;
$result=db_query("SELECT * FROM bb1_polloptions WHERE pollid= ".$pollid." ORDER BY votes DESC");
while($row=db_fetch_assoc($result)) {
$totalvotes+=$row['votes'];
$polloptions[]=$row;
}
$i=1;
while(list($key,$row)=each($polloptions)) {
$row['polloption']=$row['polloption'];
if($totalvotes) {
$percent_float = $row['votes']*100/$totalvotes;
$percent = number_format($percent_float, 2);
$percent_int = floor($percent_float)*3;
$percent_int += 1;
}
else $percent = $percent_int = 0;
$ar = array(
'question' => $question,
'polloption' => $row['polloption'],
'votes' => $row['votes'],
'imagefolder' => "include/images/poll",
'i' => $i,
'percent' => $percent,
'percent_int' => $percent_int
);
$tpl->set_ar_out($ar, 2);
//$tpl= new tpl ('poll/thread_poll_resultbit.htm');
if($i==5) $i=0;
$i++;
}
$ar = array(
'question' => $question,
'totalvotes' => $totalvotes,
'votes' => $row['votes'],
'memberscount' => $memberscount
);
$tpl->set_ar_out($ar, 4);
//$tpl = new tpl('poll/result.htm');
}
/// voten
else {
if($poll['choicecount']>1) $inputtype="checkbox";
else $inputtype="radio";
$result=db_query("SELECT * FROM bb1_polloptions WHERE pollid= ".$pollid." ORDER BY showorder ASC");
while($row=db_fetch_assoc($result)) {
$ar = array(
'polloption' => $row['polloption'],
'polloptionid' => $row['polloptionid'],
'inputtype' => $inputtype
);
$tpl->set_ar_out($ar, 1);
//$tpl= new tpl ('poll/thread_pollbit.htm');
}
$tpl->set_out('pollid', $pollid, 3);
// $tpl= new tpl ('poll/thread_poll.htm');
}
$tpl->out(5);
}
//////////////////////////////////
//////////// voten /////////
//////////////////////////////////
If ($menu->getA(1) == "v"){
$pollid = $menu->getE(1);
unset($votecheck);
$poll=db_fetch_assoc(db_query("SELECT * FROM bb1_polls WHERE pollid= ".$pollid." "));
if($poll['timeout']==0) $timeout=time()+1;
else $timeout=$poll['starttime']+$poll['timeout']*86400;
// if(!isset($pollid)) eval("error(\"".$tpl->get("error_falselink")."\");");
// if(!count($_POST['polloptionid'])) eval("error(\"".$tpl->get("error_falsevote")."\");");
// if($poll['timeout'] && time() > $poll['starttime']+$poll['timeout']*86400) eval("error(\"".$tpl->get("error_polltimeout")."\");");
// if(count($_POST['polloptionid'])> $poll['choicecount']) eval("error(\"".$tpl->get("error_tomanyvotes")."\");");
$votecheck = db_fetch_assoc(db_query("SELECT id AS pollid FROM bb1_votes WHERE id= ".$pollid." AND votemode=1 AND userid= ".$wbbuserdata." ")); // user moch ändern '".$_SESSION['authid']."'"
// if($votecheck['pollid']) eval("error(\"".$tpl->get("error_alreadyvoted")."\");");
$REMOTE_ADDR = getip();
db_query("INSERT INTO bb1_votes (id, votemode, userid, ipaddress) VALUES ( ".$pollid.", 1, ".$wbbuserdata.", '".$REMOTE_ADDR."')"); // user moch ändern '".$_SESSION['authid']."'"
$polloptionsids=implode(",",$_POST['polloptionid']);
$polloptionsids=preg_replace("/[^0-9,]/","",$polloptionsids);
db_query("UPDATE bb1_polloptions SET votes=votes+1 WHERE polloptionid IN ($polloptionsids)");
//header("Location: thread.php?threadid=$poll[threadid]&sid=$session[hash]");
}
if($thread['voted']) {
$avarage=number_format($thread['votepoints']/$thread['voted'],2);
$threads['voted']=$thread['voted'];
$tpl= new tpl ('poll/board_threadbit_rating.htm');
$threadrating=str_repeat($threadrating, round($avarage));
}
else $threadrating="";
}
$design->footer();
?>