View file tennis/komanda/chm/index.php.txt

File size: 12.84Kb
<?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']))

{

		echo "<html><head>\n";

        echo "<title>Вход</title></head>";

        echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"stylesheet.css\" />\n";

        echo "<body>";



       echo "<div class=\"header\"><img src=\"img/logo1.gif\" alt=\"world football\" /><br/><img src=\"img/ball.gif\" alt=\"Enter\" />Команда</div>";

        echo "<form action='index.php'>";

 echo "<a href=\"pravila.htm\">Правила</a><br/>";

  echo "<a href=\"registration.php\">Вы новый пользователь</a><br/>";

echo"<hr>";

  

        echo "Логин: <br/> <input class=\"itext\" type='text' name='login' id='login'/><br/>";

        echo "Пароль: <br/> <input class=\"itext\" type='password' name='p' id='p' /><br/>";

        echo "<input class=\"ibutton\" type='submit' value='Войти' />";

        echo "</form>";

echo"<hr>";

echo"<big>Media</big><br/>";

echo "<a href=\"http://\">Novosti</a><br/><a href=\"http://\">foto</a><br/><a href=\"http://\">statistika</a><br/>";

echo"<hr>";

echo"<big>Livescore</big><br/>";

echo "<a href=\"http://wap.fonbet.info/liveres/4\">Fonbet</a><br/><a href=\"http://wap.live-sport.ru\">Livesport</a><br/>";

echo"<hr>";

echo"<big>Рейтинг Команд</big><br/>";

echo "<a href=\"tour.php\">Текущий</a><br/>";

echo "<a href=\"archive.php\">Итоговый</a><br/>";

echo"<hr>";

echo"<big>Общение</big><br/>";

echo "<a href=\"http://wapnarod.ru/book10872\">Гостевая</a><br/><a href=\"http://wap.tennis-mobile.net.ru/chat2\">Чат</a><br/>";

        echo "</body></html>";

        exit;

}

$login = $_GET['login'];

$pass = $_GET['p'];



$result = mysql_query("SELECT `pass` FROM `users` WHERE `name`='$login';");

$row=mysql_fetch_row($result);

if(!empty($row))

{

	$truepass = $row[0];

	if ($truepass == $pass || $truepass == md5($pass))

	{

		$pass = $truepass;

		// вxод осуществлен

		echo "<html><head>\n";

        echo "<title>Панель игрока</title></head>";

        echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"stylesheet.css\" />\n";

        echo "<body>";

        echo "<div class=\"header\"><img src=\"img/ball.gif\" alt=\"Enter\" />Панель игрока</div>";

		$action = '';

		if (!empty($_GET['act'])) $action = $_GET['act'];

		

		switch ($action)

		{

			case "makecmd": // меню сборки комнды

				// данные пользователя

				$result = mysql_query("SELECT `id_user`,`money` FROM `users` WHERE `name`='$login';");

				$row = mysql_fetch_array($result);

				if(empty($row)){ echo "Пользователь отсутствует!"; exit; }

				$id_user = $row['id_user'];

				$user_money = $row['money'];

				

				// команды пользователя

				$result = mysql_query("SELECT * FROM `users_team` WHERE `id_user`='$id_user' ORDER BY `id_team`  DESC LIMIT 1;");

				$row = mysql_fetch_array($result);

				

				if(empty($row))

				{

					$result_club = mysql_query("SELECT * FROM `clubs` WHERE 1;");

					$count_clubs = mysql_num_rows($result_club);

					if ($count_clubs == 0) echo "Нет клубов <br/> \n";

					

					echo "Доступно средств: $user_money \$<br/> \n";

					// цикл вывода

					echo "<form action='index.php'>";

					for ($i=0;$i<$count_clubs;$i++)

					{

						if ($i == 0)

						{

							//echo "<table cols=\"4\"> \n";

							//echo "<tr> \n";

							//echo "<td>Клуб</td>";

							//echo "<td>Цена</td>";

							//echo "<td>Балл</td>";

							//echo "<td>Купить</td>";

							//echo "</tr> \n";

							echo "Клуб";

							echo " | Цена";

							echo " | Балл";

							echo " | Купить<br/>";

						}

						$club_data = mysql_fetch_array($result_club);

						//echo "<tr> \n";

						echo $club_data['club_name'];

						echo " | ".$club_data['club_price'];

						echo " | ".$club_data['club_points'];

						echo " | <input type=\"checkbox\" name=\"club_".$club_data['id_club']."\" value=\"1\" /><br/>";

						//echo "</tr> \n";

						if ($i == $count_clubs-1)

						{

							//echo "</table> \n";

							echo "<input  class=\"ibutton\" type=\"submit\" value=\"Купить\" /> \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=\"docmd\" /> \n";

					echo "</form>";

				}

				else

					{

						$id_team = (int) $row['id_team'];

						$id_clubs = explode(';', $row['id_club']);

						$cost = 0;

						

						echo "Команда Вами уже набрана! <br/> \n";

						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);

							echo $club_data['club_name'];

							$cost += (int)$club_data['club_price'];

							echo "<br/> \n";

						}

						echo "Купленно за: $cost <br/> \n";

						//$price = round($cost*0.8);

						//echo "<a href=\"index.php?login=$login&p=$pass&act=sell\">Продать за $price </a> <br/> \n";

					}

				echo "<a href=\"index.php?login=$login&p=$pass\">В главное меню</a> <br/>\n";

				break;

			case "docmd": // собираем команду

				$result = mysql_query("SELECT `id_user`,`money` FROM `users` WHERE `name`='$login';");

				$row = mysql_fetch_array($result);

				if(empty($row)){ echo "Пользователь отсутствует!"; exit; }

				$id_user = (int) $row['id_user'];

				$user_money = (int) $row['money'];

				

				// смотрим есль ли команды у игрока

				$result = mysql_query("SELECT `id_team` FROM `users_team` WHERE `id_user`=$id_user;");

				$row = mysql_fetch_array($result);

				if (empty($row))

				{

					// данные сборки

					$clubs = '';

					$cost = 0;

					

					$result_club = mysql_query("SELECT `id_club`,`club_price` 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']]))

						{

							$clubs .= $club_data['id_club'].";";

							$cost += $club_data['club_price'];

						}

					}

					$clubs = substr($clubs, 0, strlen($clubs)-1);

					

					// проверка вложился ли пользователь в сумму

					if ($user_money < $cost)

					{

						echo "Недостаточно средств для сборки команды!<br/> \n";

						echo "У Вас средств: $user_money \$<br/> \n";

						echo "Стоимость собранной команды: $cost \$<br/> \n";

					}

					else

						{

							if ($cost == 0) echo "Ничего не выбранно! <br/> \n";

							else

							{

								$user_money -= $cost;

						        mysql_query("INSERT INTO `users_team` VALUES ('','$id_user','$clubs')");

							    $team_id = mysql_insert_id();

							    if ($team_id != 0)

									mysql_query("UPDATE `users` SET `money`=$user_money;");

								else "Ошибка!";

								

								echo "Команда собрана!<br/> \n";

								echo "У Вас осталось средств: $user_money \$<br/> \n";

								echo "Стоимость собранной команды: $cost \$<br/> \n";

							}

						}

				}else

					echo "У Вас уже есть собранная команда! <br/> \n";

				echo "<a href=\"index.php?login=$login&p=$pass\">В главное меню</a> <br/>\n";

				break;

			case "intour": // Участвовать в турнире

				$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']));

					

					if ($time_now < $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>";

						echo "<td><a href=\"index.php?login=$login&p=$pass&id_tour=".$tour_data['id_tour']."&act=intotour\">Войти</a></td>";

						echo "</tr> \n";

					}

					if ($i == $count_tour-1) echo "</table> \n";

				}

				echo "<a href=\"index.php?login=$login&p=$pass\">В главное меню</a> <br/>\n";

				break;

			case "intotour": // вход в турнир

				if (!empty($_GET['id_tour']))

				{

					$id_tour = (int) $_GET['id_tour'];

					$date = time();

					

					$result = mysql_query("SELECT `id_user` FROM `users` WHERE `name`='$login';");

					$row = mysql_fetch_array($result);

					if(empty($row)){ echo "Пользователь отсутствует!"; exit; }

					$id_user = (int) $row['id_user'];

					

					$result = mysql_query("SELECT * FROM `team_in_tour` WHERE `id_tour`='$id_tour' AND `id_user`='$id_user';");

					$row = mysql_fetch_array($result);

					if(empty($row))

					{

						$result = mysql_query("SELECT `id_team` FROM `users_team` WHERE `id_user`='$id_user' ORDER BY `id_team`  DESC LIMIT 1;");

						$row = mysql_fetch_array($result);

						if(empty($row)){ echo "Команда отсутствует!"; exit; }

						$id_team = (int) $row['id_team'];

						

						mysql_query("INSERT INTO `team_in_tour` VALUES ('$id_user','$id_tour','$id_team','$date');");

						echo "Вы успешно вошли в турнир! <br/> \n";

					}else

						echo "Вы уже участвуете в данном турнире! <br/> \n";

				}

				echo "<a href=\"index.php?login=$login&p=$pass\">В главное меню</a> <br/>\n";

				break;

			case "viewtour": // Смотреть очки турнира

				$result = mysql_query("SELECT `id_user` FROM `users` WHERE `name`='$login';");

				$row = mysql_fetch_array($result);

				if(empty($row)){ echo "Пользователь отсутствует!"; exit; }

				$id_user = (int) $row['id_user'];

				

				//проверка команды наход в турнире

				$result = mysql_query("SELECT * FROM `team_in_tour` WHERE `id_user`='$id_user' LIMIT 1;");

				$row = mysql_fetch_array($result);

				if(!empty($row))

				{

					$id_tour = $row['id_tour'];

					$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'];

						echo $club_data['club_name']." очков:".$club_data['club_points'].$text_points;

						echo "<br/> \n";

					}

					echo "Всего набранно очков: $points <br/> \n";

				}else

					echo "Вы не участвуете ни в одном турнире! <br/> \n";

				echo "<a href=\"index.php?login=$login&p=$pass\">В главное меню</a> <br/>\n";

				break;

			default: // меню

				echo "<a href=\"index.php?login=$login&p=$pass&act=makecmd\">Набрать (смотреть) команду</a> <br/>\n";

				echo "<a href=\"index.php?login=$login&p=$pass&act=intour\">Участвовать в турнире</a> <br/>\n";

				echo "<a href=\"index.php?login=$login&p=$pass&act=viewtour\">Смотреть очки турнира </a> <br/>\n";

		}

	echo "</body></html>";

	}else

		{

			echo "<html><head>\n";

		    echo "<title>Ошибка</title>";

		    echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"stylesheet.css\" />\n";

		    echo "</head>";

		    echo "<body>";

		    echo "<small>";

		    echo "Пароль неверный!";

		    echo "</small>";

		    echo "</body></html>";

		    exit;

		}

}else

	{

		echo "<html><head>\n";

	    echo "<title>Ошибка</title>";

	    echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"stylesheet.css\" />\n";

	    echo "</head>";

	    echo "<body>";

	    echo "<small>";

	    echo "Пароль неверный!";

	    echo "</small>";

	    echo "</body></html>";

	    exit;

	}

?>