View file forum/addvote.php

File size: 3.82Kb
<?php
require_once"../template/start.php";
require_once"../template/regglobals.php";
require_once"../template/config.php";
require_once"setforum.php";
require_once"../template/functions.php";
require_once"../template/antidos.php";
require_once"../template/cookies.php";
require_once"../template/gzip.php";
require_once"../template/header.php";
require_once"../template/referer.php";
include_once"../themes/$config_themes/index.php";
 
if($config_forum_off=="1"){
$text = @file("../local/profil/$log.prof"); 
if ($text!=""){
$udata = explode(":||:",$text[0]);
$provlog=trim($udata[0]);
$provpar=trim($udata[1]);
$dostup=trim($udata[7]);
$privat=trim($udata[10]);}


if($action=="vote"){
if ($_SESSION['log']!="" && md5($_SESSION['par'])!="" && md5($_SESSION['par'])==$provpar && $_SESSION['log']==$provlog ) {
	
$vvotes= file("../local/dataforumset/votefor/$id.dat");
$vv = explode("|",$vvotes[0]);

if($vvotes){
if($golos>0 && $vv[$golos]!==""){
$liness=file(BASEDIR."local/dataforumset/votefor/$id.kom");
for ($bs=0; $bs<count($liness); $bs++) { 
if ($log==check($liness[$bs])) {$user_okar="ok"; break;}}
if($user_okar!="ok"){

$golos=(int)$golos;	

$vresult = file("../local/dataforumset/votefor/$id.xat");
$vu = explode("|",$vresult[0]);
$vu[$golos]++;
$vt='|'.$vu[1].'|'.$vu[2].'|'.$vu[3].'|'.$vu[4].'|'.$vu[5].'|'.$vu[6].'|'.$vu[7].'|'.$vu[8].'|'.$vu[9].'|'.$vu[10].'|';

if($vt){
$fp = fopen("../local/dataforumset/votefor/$id.xat","a+");
flock ($fp,LOCK_EX);
ftruncate ($fp,0);
fputs($fp,$vt);
fflush ($fp);
flock ($fp,LOCK_UN);
fclose($fp);
chmod ($fp, 0666);
chmod ("../local/dataforumset/votefor/$id.xat", 0666);
////////////////////////////
$fprat=fopen(BASEDIR."local/dataforumset/votefor/$id.kom","a+");
flock ($fprat,LOCK_EX);
fputs($fprat,"$log\r\n");
flock ($fprat,LOCK_UN);
fclose($fprat);
chmod ($fprat, 0666);
chmod (BASEDIR."local/dataforumset/votefor/$id.kom", 0666);
$filerat=file(BASEDIR."local/dataforumset/votefor/$id.kom");
$irat = count($filerat);
if ($irat>=20) {
$fprat=fopen(BASEDIR."local/dataforumset/votefor/$id.kom","w");
flock ($fprat,LOCK_EX);
unset($filerat[0]);
unset($filerat[1]);
fputs($fprat, implode("",$filerat));
flock ($fprat,LOCK_UN);
fclose($fprat);
}


}

header ("Location: index.php?isset=yesvotes&".SID);
} else {echo '<b>Ошибка! Вы уже проголосовали!</b><br>';}
} else {echo '<b>Ошибка! Неверно указан вариант голосования!</b><br>';}
} else {echo '<b>Ошибка! Голосование еще не создано!</b><br>'; }
} else {
echo '<br>Вы не авторизованы<br>';

}

}

##########################################################################
##                        Главная страница
##########################################################################
if(!isset($action)) {
$vvotes = file(BASEDIR."local/dataforumset/votefor/$id.dat");
$vv = explode("|",$vvotes[0]);
$vcount=count($vv);

$vresult = file(BASEDIR."local/dataforumset/votefor/$id.xat");
$vr = explode("|",$vresult[0]);

if($vvotes){	
	
for ($i=1;$i<$vcount;$i++){
$x=$x+$vr[$i];
}

for($i=1;$i<$vcount;$i++){
$proc[$i]=round($vr[$i]*100/$x);
}


for($i=1;$i<$vcount;$i++){
	
if($vv[$i]!==""){
 echo '<b>'.$vv[$i].'</b> (Проголосовало: '.(int)$vr[$i].')<br>';
 echo '<img src="'.BASEDIR.'gallery/grafic.php?rat='.$proc[$i].'&amp;imgs=1" alt=""><br><br>'; 
}
}

$sum=array_sum($vr);

echo '<br><b>Всего проголосовавших: '.(int)$sum.'</b><br>';

}else{echo'<br>';}
} 
}
if($config_forum_off=="0"){echo'<center><font color="red">Форум сайта отключен!</font></center>';}
echo '<br><img src="../images/img/back.gif" alt=""> <a href="index.php?'.SID.'"> Форум</a><br>';
echo '<img src="../images/img/homepage.gif" alt=""> <a href="../index.php?'.SID.'">На главную</a>';
include_once"../themes/$config_themes/foot.php";


?>