<?php
DEFINE("ROOT_DIR", realpath(dirname(__FILE__).'/../') );
require(ROOT_DIR."/config.php");
require_once(ROOT_DIR."/funkcion.php");
$t = time();

// Общий конкурс
$res = mysql_query("SELECT `id_user`,`ball` FROM `nano_comp` WHERE `asoc`='1' ORDER BY `ball` DESC LIMIT 3") or die(mysql_error());
if(mysql_num_rows($res) > 0){
$number = "0";
while($row = mysql_fetch_assoc($res)){
$id_user_comp = $row["id_user"];
$ball_comp = $row["ball"];
$number++;
$style = NULL;
$summ_all = round($ball_comp, 2);
switch($number){
case 1:$mm = "1-е"; $proc = round($ball_comp*$proc_comp_1/100, 2); $summ_all = round($ball_comp+$proc, 2);break;
case 2:$mm = "2-е"; $proc = round($ball_comp*$proc_comp_2/100, 2); $summ_all = round($ball_comp+$proc, 2);break;
case 3:$mm = "3-е"; $summ_all = round($ball_comp, 2);break;
}
mysql_query("UPDATE `nano_user` SET `ballans`=`ballans`+'$summ_all' WHERE `id`='$id_user_comp'");
mysql_query("INSERT INTO `nano_mail` (`id_user`, `komy`, `status`, `tema`, `text`, `time`, `ok`, `chey`) VALUES ('$id_user_comp','2','4','Вы победили в конкурсе','<p>Поздравляем! Вы победили в общем конкурсе и заняли $mm место. Ваш приз составил $summ_all руб.<br /><br /> Сообщение сформировано автоматически и не требует ответа!</p>','$t','1','$id_user_comp')");
mysql_query("DELETE FROM `nano_comp` WHERE `asoc`='1'") or die(mysql_error());
}}
?> 