View file public_html/admin/compresview.php

File size: 5.77Kb
<? include('checkcookie.php'); ?>
<h3>Просмотр результатов конкурсов</h3>
<br>

<?
if($_POST["action"]=="paypris")
{
	$idk=$_POST["idk"];
	$iduser=$_POST["iduser"];
	$place=$_POST["place"];
	
	$res=mysql_query("select * from tb_comp where id='$idk'");
	$res=mysql_fetch_array($res);
	
	if($res["pris".$place."status"]!='0')
	{
		echo "<font color=#ff0000><b>Приз уже выдавался. Повторная выдача невозможна!!!</b></font><br><br>";
	}else{
		if($res["pris".$place."type"]=='0')
		{
			$prisvalue=$res["pris".$place."value"];
			if($res["lidername"]=='0'){$lidertype='username';}else{$lidertype='wmid';}
			
			$res1=mysql_query("select user,purse from tb_compdata where id='$iduser'");
			$res1=mysql_fetch_array($res1);
			$lidername=$res1["user"];
			$purse=$res1["purse"];

			$res1=mysql_query("select money from tb_users where $lidertype='$lidername'");
			if(mysql_num_rows($res1)>0)
			{
				$res1=mysql_fetch_array($res1);
				$money=$res1["money"]+$prisvalue;
				mysql_query("update tb_users set money='$money' where $lidertype='$lidername'");
				mysql_query("update tb_comp set pris".$place."status='1' where id='$idk'");
				echo "<font color=#00cc00><b>Пользователь успешно получил свой приз</b></font><br><br>";
			}else{
				mysql_query("update tb_comp set pris".$place."status='1' where id='$idk'");
				?>
				<a href='wmk:payto?Purse=<?=$purse?>&Amount=<?=$prisvalue?>&Desc=Приз за <?=$place?> место в конкурсе '<?=$res["name"]?>'. Поздравляем Вас!!!&BringToFront=Y'><button>Выплатить приз</button></a>
				<?
				echo "<font color=#00cc00><b>Пользователь успешно получил свой приз</b></font><br><br>";
			}
		}else{
			$prisvalue=$res["pris".$place."value"];
			if($res["lidername"]=='0'){$lidertype='username';}else{$lidertype='wmid';}
			
			$res=mysql_query("select user from tb_compdata where id='$iduser'");
			$res=mysql_fetch_array($res);
			$lidername=$res["user"];

			$res=mysql_query("select referals, username from tb_users where $lidertype='$lidername'");
			if(mysql_num_rows($res)>0)
			{
				$res=mysql_fetch_array($res);
				$refs=$res["referals"]+$prisvalue;
				$login=$res["username"];

				$res=mysql_query("select * from tb_users where referer='' and username!='$login' order by visits desc limit $prisvalue");
				if(mysql_num_rows($res)<$prisvalue)
				{
					echo "<font color=#ff0000><b>У системы недостаточно свободных рефералов для выдачи приза!</b></font><br><br>";
				}else{
					while($row=mysql_fetch_array($res))
					{
						mysql_query("update tb_users set referer='$login', buying='4' where id='".$row["id"]."'");
					}

					mysql_query("update tb_users set referals='$refs' where $lidertype='$lidername'");
					mysql_query("update tb_comp set pris".$place."status='1' where id='$idk'");
					echo "<font color=#00cc00><b>Пользователь успешно получил свой приз</b></font><br><br>";
				}
			}else{
				echo "<font color=#ff0000><b>Призер не является зарегистрированным пользователем системы. Он не может получить рефералов!!!</b></font><br><br>";
			}
		}
	}	
}
?>

<font size=3>Зеленым подсвечиваются те пользователи, которые набрали минимум и считаются участниками конкурса, имеющими право на получение приза!!!</font><br>
<table width=100% border=0>
<tr><th width=50% align=center>Активные конкурсы</th><th width=50% align=center>Завершенные конкурсы</th></tr>
<tr><td width=50% valign=top>

<table width=100%>
<tr>
	<th>Место</th>
	<th>Пользователь</th>
	<th>Набрано очков</th>
</tr>
<?
$res=mysql_query("select * from tb_comp order by id desc");
while($row=mysql_fetch_array($res))
{
	$t=time();
	$sd=strtotime($row["startdate"]);
	$ed=strtotime($row["enddate"]);
	$idk=$row["id"];
	$minvalue=$row["min"];

	if($t>$sd && $t<$ed)
	{
		echo "<tr><td colspan=3 bgcolor=#333333><font color=#ffffff><b>".$row["name"]."</b></font></td></tr>";
		$res1=mysql_query("select * from tb_compdata where idk='$idk' order by resvalue desc limit 10");
		$place=0;
		while($row1=mysql_fetch_array($res1))
		{
			$place=$place+1;
			if($row1["resvalue"]>=$minvalue) { $cvet='00ff00'; }else{ $cvet='ffffff';}
			
			echo "<tr bgcolor=#$cvet><td align=center>$place</td><td align=center>".$row1["user"]."</td><td align=center>".$row1["resvalue"]."</td></tr>";
		}
	}
}
?>
</table>

</td><td width=50% valign=top>

<table width=100%>
<tr>
	<th>Место</th>
	<th>Пользователь</th>
	<th>Набрано очков</th>
	<th>Статус приза</th>
	<th></th>
</tr>
<?
$res=mysql_query("select * from tb_comp order by id desc");
while($row=mysql_fetch_array($res))
{
	$t=time();
	$dd=strtotime($row["deldate"]);
	$ed=strtotime($row["enddate"]);
	$idk=$row["id"];
	$minvalue=$row["min"];

	if($t>$ed)
	{
		echo "<tr><td colspan=5 bgcolor=#333333><font color=#ffffff><b>".$row["name"]."</b></font></td></tr>";
		$res1=mysql_query("select * from tb_compdata where idk='$idk' and resvalue>='$minvalue' order by resvalue desc limit 3");
		$place=0;
		while($row1=mysql_fetch_array($res1))
		{
			$place=$place+1;
			if($row["pris".$place."status"]=='0') { $prisstatus="<font color=#ff0000><b>Не получен</b></font>"; }else{ $prisstatus="<font color=#00ff00><b>Получен</b></font>"; }

			echo "<tr><td align=center>$place</td><td align=center>".$row1["user"]."</td><td align=center>".$row1["resvalue"]."</td>
			<td align=center>$prisstatus</td><td align=center>";

			if($row["pris".$place."status"]=='0')
			{
				?>
				<form action="" method=post>
				<input type=hidden value="<?=$idk?>" name="idk">
				<input type=hidden value="<?=$place?>" name="place">
				<input type=hidden value="<?=$row1["id"]?>" name="iduser">
				<input type=hidden value="paypris" name="action">
				<input type=submit value="Выдать приз за <?=$place?> место">
				</form>
				<?
			}
			echo "</td></tr>";
		}
	}
}
?>
</table>

</td></tr>
</table>