<?php
/** Author: ArseN
/* icq: 799956
/* email: [email protected]
/* site: http://softmob.ru
*/
header("Content-type: text/html; charset=UTF-8");
include "../config.php";
if (empty($_GET['login']) or empty($_GET['p']))
{
$result = mysql_query("SELECT count(*) FROM `superadmin` WHERE 1");
$row=mysql_fetch_row($result);
$button = "Войти";
$input_type = "password";
echo "<html><head>\n";
echo "<title>Вход</title></head>";
echo "<body>";
echo "<small>";
echo "<p mode='nowrap'>";
echo "Вход в зону супер админа!";
echo "</p>";
if ($row[0] == 0)
{
echo "В базе не обнаруженно суперадминов!<br/> \n";
echo "Сейчас Вы можете создать учетную запись, и использовать ее в дальнейшем для управления рейтингом!<br/> \n";
$button = "Создать";
$input_type = "text";
}
echo "<form action='index.php'>";
echo "Логин: <br/> <input type='text' name='login' id='login'/><br/>";
echo "Пароль: <br/> <input type='$input_type' name='p' id='p' /><br/>";
echo "<input type='submit' value='$button' />";
echo "</form>";
echo "</small>";
echo "</body></html>";
exit;
}
$login = $_GET['login'];
$pass = $_GET['p'];
$result = mysql_query("SELECT count(*) FROM `superadmin` WHERE 1");
$row=mysql_fetch_row($result);
if($row[0] == 0)
{
$pass = md5($pass);
$sql="INSERT INTO `superadmin` VALUES ('','$login','$pass')";
@mysql_query($sql);
$uid = mysql_insert_id();
if ($uid == 0)
{
echo "<html><head>\n";
echo "<title>Созданно</title>";
echo "<meta http-equiv=\"refresh\" content=\"1;url=index.php\"/>";
echo "</head>";
echo "<body>";
echo "<small>";
echo "Не созданно!";
echo "</small>";
echo "</body></html>";
exit;
}
echo "<html><head>\n";
echo "<title>Созданно</title>";
echo "<meta http-equiv=\"refresh\" content=\"1;url=index.php?login=$login&p=$pass\"/>";
echo "</head>";
echo "<body>";
echo "<small>";
echo "Учетная запись созданна!";
echo "</small>";
echo "</body></html>";
exit;
}
$result = mysql_query("SELECT `pass` FROM `superadmin` WHERE `login`='$login';");
$row=mysql_fetch_row($result);
if(!empty($row))
{
$truepass = $row[0];
if ($truepass == $pass || $truepass == md5($pass))
{
// вход осуществлен
if (!empty($_GET['act'])) $action = $_GET['act'];
else $action = '';
echo "<html><head>\n";
echo "<title>Панель управления игрой</title>";
echo "</head>";
echo "<body> \n";
// меню действий
switch ($action)
{
case "club": // Редактирование клубов
echo "<a href=\"index.php?login=$login&p=$pass&act=viewclub\">Смотреть клубы</a> <br/> \n";
echo "<a href=\"index.php?login=$login&p=$pass&act=addclub\">Добавить клуб</a> <br/> \n";
break;
case "viewclub": // Смотреть клубы
$result_club = mysql_query("SELECT * FROM `clubs` WHERE 1;");
$count_clubs = mysql_num_rows($result_club);
if ($count_clubs == 0) echo "Нет клубов <br/> \n";
for ($i=0;$i<$count_clubs;$i++)
{
if ($i == 0)
{
echo "<table cols=\"5\"> \n";
echo "<tr> \n";
echo "<td>Клуб</td>";
echo "<td>Цена</td>";
echo "<td>Балл</td>";
echo "<td>Ред.</td>";
echo "<td>Уд.</td>";
echo "</tr> \n";
}
$club_data = mysql_fetch_array($result_club);
echo "<tr> \n";
echo "<td>".$club_data['club_name']."</td>";
echo "<td>".$club_data['club_price']."</td>";
echo "<td>".$club_data['club_points']."</td>";
echo "<td><a href=\"index.php?login=$login&p=$pass&id_club=".$club_data['id_club']."&act=editclub\"><img src=\"img/edit.png\" alt=\"edit\" /></a></td>";
echo "<td><a href=\"index.php?login=$login&p=$pass&id_club=".$club_data['id_club']."&act=delclub\"><img src=\"img/del.png\" alt=\"del\" /></a></td>";
echo "</tr> \n";
if ($i == $count_clubs-1) echo "</table> \n";
}
echo "<a href=\"index.php?login=$login&p=$pass&act=addclub\">Добавить клуб</a> <br/> \n";
break;
case "addclub": // Добавить клуб
if (empty($_GET['cname']) || empty($_GET['cprice']))
{
echo "<form action=\"index.php\" method=\"get\"> \n";
echo "Название клуба: <br/> \n";
echo "<input type=\"text\" name=\"cname\" /> <br/> \n";
echo "Стоимость клуба: <br/> \n";
echo "<input type=\"text\" name=\"cprice\" /> <br/> \n";
echo "Стартовые очки клуба: <br/> \n";
echo "<input type=\"text\" name=\"cpoints\" /> <br/> \n";
echo "<input type=\"hidden\" name=\"login\" value=\"$login\" /> \n";
echo "<input type=\"hidden\" name=\"p\" value=\"$pass\" /> \n";
echo "<input type=\"hidden\" name=\"act\" value=\"addclub\" /> \n";
echo "<input type=\"submit\" value=\"Создать\" /> <br/> \n";
echo "</form>";
echo "<a href=\"index.php?login=$login&p=$pass&act=viewclub\">Смотреть клубы</a> <br/> \n";
}else
{
$cname = $_GET['cname'];
$cprice = $_GET['cprice'];
$cpoints = 0;
if (!empty($_GET['cpoints']))
$cpoints = $_GET['cpoints'];
// добавление
@mysql_query("INSERT INTO `clubs` VALUES ('','$cname','$cprice','$cpoints')");
// проверка статуса выполнения операции
if (mysql_insert_id() > 0)
echo "Добавленно! <br/>\n";
else
echo "Ошибка! Не добавленно! <br/>\n";
echo "<a href=\"index.php?login=$login&p=$pass&act=addclub\">Добавить клуб</a> <br/> \n";
echo "<a href=\"index.php?login=$login&p=$pass&act=viewclub\">Смотреть клубы</a> <br/> \n";
}
break;
case "delclub": // Удалить клуб
if (!empty($_GET['id_club']))
{
$id_club = (int)$_GET['id_club'];
@mysql_query("DELETE FROM `clubs` WHERE `id_club`=$id_club LIMIT 1;");
echo "Удален! <br/> \n";
}
else
echo "Ошибка! Упущен параметр! <br/> \n";
echo "<a href=\"index.php?login=$login&p=$pass&act=addclub\">Добавить клуб</a> <br/> \n";
echo "<a href=\"index.php?login=$login&p=$pass&act=viewclub\">Смотреть клубы</a> <br/> \n";
break;
case "editclub": // Удалить клуб
if (!empty($_GET['id_club']))
{
if (empty($_GET['cname']) || empty($_GET['cprice']) || empty($_GET['cpoints']))
{
$id_club = (int)$_GET['id_club'];
$result_club = mysql_query("SELECT * FROM `clubs` WHERE `id_club`=$id_club LIMIT 1;");
$club_data = mysql_fetch_array($result_club);
echo "<form action=\"index.php\" method=\"get\"> \n";
echo "Название клуба: <br/> \n";
echo "<input type=\"text\" name=\"cname\" value=\"".$club_data['club_name']."\" /> <br/> \n";
echo "Стоимость клуба: <br/> \n";
echo "<input type=\"text\" name=\"cprice\" value=\"".$club_data['club_price']."\" /> <br/> \n";
echo "Стартовые очки клуба: <br/> \n";
echo "<input type=\"text\" name=\"cpoints\" value=\"".$club_data['club_points']."\" /> <br/> \n";
echo "<input type=\"hidden\" name=\"login\" value=\"$login\" /> \n";
echo "<input type=\"hidden\" name=\"p\" value=\"$pass\" /> \n";
echo "<input type=\"hidden\" name=\"id_club\" value=\"".$club_data['id_club']."\" /> \n";
echo "<input type=\"hidden\" name=\"act\" value=\"editclub\" /> \n";
echo "<input type=\"submit\" value=\"Изменить\" /> <br/> \n";
echo "</form>";
}else
{
// изменение в базе
$id_club = (int)$_GET['id_club'];
$cname = $_GET['cname'];
$cprice = $_GET['cprice'];
$cpoints = $_GET['cpoints'];
@mysql_query("UPDATE `clubs` SET `club_name` = '$cname', `club_price` = '$cprice', `club_points` = '$cpoints' WHERE `id_club`=$id_club LIMIT 1");
echo "Обновленно! <br/> \n";
}
}
else
echo "Ошибка! Упущен параметр! <br/> \n";
echo "<a href=\"index.php?login=$login&p=$pass&act=addclub\">Добавить клуб</a> <br/> \n";
echo "<a href=\"index.php?login=$login&p=$pass&act=viewclub\">Смотреть клубы</a> <br/> \n";
break;
case "addtour": // Создание турнира
if (empty($_GET['tname']) || empty($_GET['tperiod']))
{
echo "<form action=\"index.php\" method=\"get\"> \n";
echo "Название турнира: <br/> \n";
echo "<input type=\"text\" name=\"tname\" /> <br/> \n";
echo "Длительность турнира (в днях): <br/> \n";
echo "<input type=\"text\" name=\"tperiod\" /> <br/> \n";
echo "<input type=\"hidden\" name=\"login\" value=\"$login\" /> \n";
echo "<input type=\"hidden\" name=\"p\" value=\"$pass\" /> \n";
echo "<input type=\"hidden\" name=\"act\" value=\"addtour\" /> \n";
echo "<input type=\"submit\" value=\"Создать\" /> <br/> \n";
echo "</form>";
}else
{
$tname = $_GET['tname'];
$tperiod = $_GET['tperiod'];
$date = time();
// добавление
@mysql_query("INSERT INTO `tournament` VALUES ('','$date','$tname','$tperiod')");
// проверка статуса выполнения операции
if (mysql_insert_id() > 0)
echo "Добавленно! <br/>\n";
else
echo "Ошибка! Не добавленно! <br/>\n";
}
echo "<a href=\"index.php?login=$login&p=$pass&act=tour\">Турниры</a> <br/> \n";
break;
case "tour": // Смотреть турниры
$result_tour = mysql_query("SELECT * FROM `tournament` WHERE 1;");
$count_tour = mysql_num_rows($result_tour);
if ($count_tour == 0) echo "Нет турниров! <br/>\n";
for ($i=0;$i<$count_tour;$i++)
{
if ($i == 0)
{
echo "<table cols=\"3\"> \n";
echo "<tr> \n";
echo "<td>Турнир</td>";
echo "<td>Начало</td>";
echo "<td>Конец</td>";
//echo "<td>Ред.</td>";
//echo "<td>Уд.</td>";
echo "</tr> \n";
}
$tour_data = mysql_fetch_array($result_tour);
echo "<tr> \n";
echo "<td>".$tour_data['name']."</td>";
echo "<td>".date("d.m.",$tour_data['date'])."</td>";
echo "<td>".date("d.m.",mktime(0,0,0,date("m",$tour_data['date']),date("d",$tour_data['date'])+$tour_data['period'], date("Y",$tour_data['date'])))."</td>";
//echo "<td><a href=\"index.php?login=$login&p=$pass&id_club=".$tour_data['id_tour']."&act=edittour\"><img src=\"img/edit.png\" alt=\"edit\" /></a></td>";
//echo "<td><a href=\"index.php?login=$login&p=$pass&id_club=".$tour_data['id_tour']."&act=deltour\"><img src=\"img/del.png\" alt=\"del\" /></a></td>";
echo "</tr> \n";
if ($i == $count_tour-1) echo "</table> \n";
}
echo "<a href=\"index.php?login=$login&p=$pass&act=addtour\">Добавить турнир</a> <br/> \n";
break;
case "closetour": // Закрытие турнира
if (empty($_GET['id_tour'])) exit;
$points_array = array();
$id_tour = $_GET['id_tour'];
$result = mysql_query("SELECT * FROM `all_tour_result` WHERE `id_tour`=$id_tour;");
$count_data = mysql_num_rows($result);
if ($count_data == 0)
{
$result_user = mysql_query("SELECT `id_user` FROM `users` WHERE 1;");
$count_user = mysql_num_rows($result_user);
for ($j=0; $j<$count_user; $j++)
{
$row = mysql_fetch_array($result_user);
$id_user = (int) $row['id_user'];
//проверка команды наход в турнире
$result = mysql_query("SELECT * FROM `team_in_tour` WHERE `id_user`='$id_user' AND `id_tour`=$id_tour LIMIT 1;");
$row = mysql_fetch_array($result);
if(!empty($row))
{
$id_team = $row['id_team'];
$date_in_tour = $row['date'];
$points = 0;
$result = mysql_query("SELECT * FROM `users_team` WHERE `id_team`='$id_team' LIMIT 1;");
$row = mysql_fetch_array($result);
$id_clubs = explode(';', $row['id_club']);
foreach ($id_clubs as $id_club)
{
// данные по клубам
$result_club = mysql_query("SELECT * FROM `clubs` WHERE `id_club`=$id_club;");
$club_data = mysql_fetch_array($result_club);
// данные по играм
$result_game = mysql_query("SELECT * FROM `results_game` WHERE `id_tour`=$id_tour AND `id_club`='$id_club' AND `date`>='$date_in_tour';");
$game_num_data = mysql_num_rows($result_game);
$text_points = " Игры:";
for ($i = 0; $i < $game_num_data; $i++)
{
$game_data = mysql_fetch_array($result_game);
$text_points .= " ".$game_data['points'];
$points += $game_data['points'];
}
$points += (int)$club_data['club_points'];
}
$points_array[$id_user] = $points;
}
}
arsort($points_array);
foreach ($points_array as $id_user => $points)
{
$result_user = mysql_query("SELECT * FROM `users_team` WHERE `id_user`=$id_user;");
$user_data = mysql_fetch_array($result_user);
$id_clubs = $user_data['id_club'];
// добавление
$date = time();
@mysql_query("INSERT INTO `all_tour_result` VALUES ('',$date,$id_tour,$id_user,'$id_clubs',$points)");
// удаление и установка начальных параметров игрока
@mysql_query("DELETE FROM `users_team` WHERE `id_user`=$id_user LIMIT 1");
@mysql_query("DELETE FROM `team_in_tour` WHERE `id_user`=$id_user LIMIT 1");
@mysql_query("UPDATE `users` SET `money`=100 WHERE `id_user`=$id_user LIMIT 1");
}
} else echo "Данный турнир уже закрыт!";
break;
case "game": // Проведение игры
$time_now = time();
$result_tour = mysql_query("SELECT * FROM `tournament` WHERE 1");
$count_tour = mysql_num_rows($result_tour);
if ($count_tour == 0) echo "Нет созданных турниров! <br/>\n";
for ($i=0;$i<$count_tour;$i++)
{
if ($i == 0)
{
echo "Выберете турнир, для проведения игры (начисления очков командам):";
echo "<table cols=\"4\"> \n";
echo "<tr> \n";
echo "<td>Турнир</td>";
echo "<td>Начало</td>";
echo "<td>Конец</td>";
echo "<td>Статус</td>";
echo "</tr> \n";
}
$tour_data = mysql_fetch_array($result_tour);
$date = mktime(0,0,0,date("m",$tour_data['date']),date("d",$tour_data['date'])+$tour_data['period'], date("Y",$tour_data['date']));
echo "<tr> \n";
echo "<td>".$tour_data['name']."</td>";
echo "<td>".date("d.m.",$tour_data['date'])."</td>";
echo "<td>".date("d.m.",mktime(0,0,0,date("m",$tour_data['date']),date("d",$tour_data['date'])+$tour_data['period'], date("Y",$tour_data['date'])))."</td>";
// автоматическое появление ссылы Закрыть по окончании турнира
if ($time_now >= $date)
echo "<td><a href=\"index.php?login=$login&p=$pass&id_tour=".$tour_data['id_tour']."&act=closetour\">Закрыть</a></td>";
else
echo "<td><a href=\"index.php?login=$login&p=$pass&id_tour=".$tour_data['id_tour']."&act=playgame\">Открыт</a></td>";
echo "</tr> \n";
if ($i == $count_tour-1) echo "</table> \n";
}
echo "<a href=\"index.php?login=$login&p=$pass&act=addtour\">Добавить турнир</a> <br/> \n";
break;
case "playgame": // начисление очков за матч
if (!empty($_GET['id_tour']))
{
$id_tour = $_GET['id_tour'];
$result_club = mysql_query("SELECT * FROM `clubs` WHERE 1;");
$count_clubs = mysql_num_rows($result_club);
if ($count_clubs == 0) echo "Нет клубов <br/> \n";
for ($i=0;$i<$count_clubs;$i++)
{
if ($i == 0)
{
echo "<form action=\"index.php\" method=\"get\"> \n";
echo "<table cols=\"3\"> \n";
echo "<tr> \n";
echo "<td>Клуб (балл)</td>";
echo "<td>Цена</td>";
echo "<td>Рез.игры</td>";
echo "</tr> \n";
}
$club_data = mysql_fetch_array($result_club);
// суммарные очки клуза за все игры в данном турнире id_tour
$id_club = $club_data['id_club'];
$result_game_club = mysql_query("SELECT sum(`points`) FROM `results_game` WHERE `id_club`=$id_club AND `id_tour`=$id_tour LIMIT 1;");
$club_points = mysql_fetch_array($result_game_club);
$club_points = $club_points[0];
$club_points += $club_data['club_points'];
echo "<tr> \n";
echo "<td>".$club_data['club_name']." (".$club_points.")</td>";
echo "<td>".$club_data['club_price']."</td>";
echo "<td>+<input type=\"text\" name=\"club_".$club_data['id_club']."\" value=\"0\" maxlength=\"2\" size=\"2\" /></td>";
echo "</tr> \n";
if ($i == $count_clubs-1)
{
echo "</table> \n";
echo "<input type=\"hidden\" name=\"login\" value=\"$login\" /> \n";
echo "<input type=\"hidden\" name=\"p\" value=\"$pass\" /> \n";
echo "<input type=\"hidden\" name=\"act\" value=\"addgame\" /> \n";
echo "<input type=\"hidden\" name=\"id_tour\" value=\"".$_GET['id_tour']."\" /> \n";
echo "<input type=\"submit\" value=\"Записать результат\" /> <br/> \n";
echo "</form>";
echo "<a href=\"index.php?login=$login&p=$pass&act=game\">Проведение игры</a> <br/> \n";
}
}
}else echo "Упущен необходимый параметр! <br/> \n";
break;
case "addgame": // запись результа игры
if (!empty($_GET['id_tour']))
{
$date = time();
$id_tour = $_GET['id_tour'];
$result_club = mysql_query("SELECT `id_club` FROM `clubs` WHERE 1;");
$count_clubs = mysql_num_rows($result_club);
for ($i=0;$i<$count_clubs;$i++)
{
$club_data = mysql_fetch_array($result_club);
if (!empty($_GET['club_'.$club_data['id_club']]))
{
// выполняется если переменная вида club_N полученна
$game_points = $_GET['club_'.$club_data['id_club']];
$id_club = $club_data['id_club'];
mysql_query("INSERT INTO `results_game` VALUES ('$id_tour','$id_club','$date','$game_points');");
/*
$last_points = 0;
// проверка наличия записи клуба в турнирной таблице
$result_game_club = mysql_query("SELECT `id_club` FROM `results_game` WHERE `id_club`=$id_club AND `id_tour`=$id_tour LIMIT 1;");
$count_game_club = mysql_num_rows($result_game_club);
if ($count_game_club == 0)
mysql_query("INSERT INTO `results_game` VALUES ('$id_tour','$id_club','$date','$last_points');");
else
{
$result_last_game = mysql_query("SELECT `points` FROM `results_game` WHERE `id_club`=$id_club AND `id_tour`=$id_tour LIMIT 1;");
$last_points = mysql_fetch_array($result_last_game);
$last_points = (int) $last_points['points'];
}
// сумма очков за все игры
$game_points += $last_points;
// запись результата
mysql_query("UPDATE `results_game` SET `points`='$game_points', `date`='$date' WHERE `id_club`=$id_club AND `id_tour`=$id_tour LIMIT 1;");
*/
}
}
echo "Обновленно! <br/> \n";
echo "<a href=\"index.php?login=$login&p=$pass&act=game\">Проведение игры</a> <br/> \n";
}else echo "Упущен параметр! <br/> \n";
break;
default: // Главное меню
echo "<a href=\"index.php?login=$login&p=$pass&act=club\">Редактирование клубов</a> <br/> \n";
echo "<a href=\"index.php?login=$login&p=$pass&act=addtour\">Создание турнира</a> <br/> \n";
echo "<a href=\"index.php?login=$login&p=$pass&act=tour\">Турниры</a> <br/> \n";
echo "<a href=\"index.php?login=$login&p=$pass&act=game\">Проведение игры</a> <br/> \n";
}
echo "<hr/> \n";
echo "<a href=\"index.php?login=$login&p=$pass\">В главное меню</a> <br/> \n";
echo "</body></html>";
exit;
}else
{
echo "<html><head>\n";
echo "<title>Ошибка</title>";
echo "</head>";
echo "<body>";
echo "<small>";
echo "Пароль неверный!";
echo "</small>";
echo "</body></html>";
exit;
}
}else
{
echo "<html><head>\n";
echo "<title>Ошибка</title>";
echo "</head>";
echo "<body>";
echo "<small>";
echo "Пароль неверный!";
echo "</small>";
echo "</body></html>";
exit;
}
?>