Просмотр файла tennis/komanda/wtagame/archive.php

Размер файла: 6.94Kb
<?php
/** Author: ArseN
/*	icq: 799956
/*	email: [email protected]
/*	site: http://softmob.ru
*/
header("Content-type: text/html; charset=UTF-8");
include "config.php";
$month = array(
	"Январь",
	"Февраль",
	"Март",
	"Апрель",
	"Май",
	"Июнь",
	"Июль",
	"Август",
	"Сентябрь",
	"Октябрь",
	"Ноябрь",
	"Декабрь"
);
// проверка date на достоверность
if (!empty($_GET['date'])){
	$date = $_GET['date'];
	(int) $arrDate = explode("-",$date);
	if ($arrDate[0]>12 || $arrDate[0]<=0 || $arrDate[1]>2030 || $arrDate[1]<=2005) unset($arrDate);
}
// выборка сомой первой даты для точки отсчета cPoint
$result = mysql_query("SELECT min(`date`) FROM `all_tour_result`;");
$row = mysql_fetch_row($result);
$min_date = $row[0];
// максимальный id
$result = mysql_query("SELECT max(`id`) FROM `all_tour_result`;");
$row = mysql_fetch_row($result);
$max_id = $row[0];
// номер месяца и года cPoint
$num_month = (int) date("m",$min_date);
$num_year = (int) date("Y",$min_date);

echo "<html><head>\n";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"stylesheet.css\" />\n";
echo "<title>Архив игр</title></head>";
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 'view':// ПРОСМОТР ВЫБРАННОГО ТУРНИРА
	if (!empty($_GET['id']))
		$id_tour = $_GET['id'];
	else exit;
	
	// страница
	if(empty($_GET['p'])) $p = 1;
		else $p = (int)$_GET['p'];
			
	if (!empty($arrDate))
	{
		$result_tour = mysql_query("
			SELECT tournament.name as `name`, count(all_tour_result.id_tour) as `count`
			FROM `tournament`
			INNER JOIN all_tour_result
			ON all_tour_result.id_tour = tournament.id_tour
			WHERE all_tour_result.id_tour = $id_tour
			GROUP BY tournament.name
		");
		$row_tour = mysql_fetch_array($result_tour);
		$tour_name = $row_tour['name'];
		$count_all = $row_tour['count'];
		
		// размер всего текста и максим страница
		$max_page = ceil($count_all/$count_on_page);

		// проверка правильности страницы
		if ($p > $max_page) $p = $max_page;
		if ($p <= 0) $p = 1;
		
		// начало вывода
		$start = ($p-1)*$count_on_page;
			
		$result_tour = mysql_query("
			SELECT all_tour_result.*, users.name
			FROM all_tour_result
			INNER JOIN users
			ON users.id_user = all_tour_result.id_user
			WHERE all_tour_result.id_tour=$id_tour
			ORDER BY all_tour_result.points DESC
			LIMIT $start, $count_on_page;
		");
		$count_rows = mysql_num_rows($result_tour);
		
		echo "Турнир: $tour_name <br/><br/>\n";
		for ($i=0; $i<$count_rows; $i++)
		{
			$row_tour = mysql_fetch_array($result_tour);
			
			echo "<div class=\"header\">".($i+1)." МЕСТО </div>\n";
			echo "Имя игрока: ".$row_tour['name']."<br/>\n";
			echo "Набранно очков: ".$row_tour['points']."<br/>\n";
			echo "Сборка клубов: <br/>\n";
			
			$clubs = explode(';', $row_tour['id_clubs']);
			foreach ($clubs as $num => $id_club)
			{
				$result_club = mysql_query("SELECT * FROM `clubs` WHERE `id_club`=$id_club");
				$row_club = mysql_fetch_array($result_club);
				
				echo ($num+1).". ".$row_club['club_name']."<br/>\n";
			}
			echo "<hr/>";
		}
		// навигатор страниц
			$next_p = $p + 1;
			$prev_p = $p -1;

			if ($prev_p > 0)
				echo "<a href=\"archive.php?act=view&id=$id_tour&date=$date&p=$prev_p\">Пред.</a>";
			else
				echo "Пред.";
				
			echo " | ";
				
			if ($next_p <= $max_page)
				echo "<a href=\"archive.php?act=view&id=$id_tour&date=$date&p=$next_p\">След.</a>\n";
			else
				echo "След.";
				
			echo "<br/> \n";
			// форма перехода на произвольную страницу
			$max_len_digits = strlen($max_page);
			echo "<form action=\"archive.php\" method=\"get\"> \n";
				echo "<input type=\"hidden\" name=\"act\" value=\"view\" /> \n";
				echo "<input type=\"hidden\" name=\"id\" value=\"$id_tour\" /> \n";
				echo "<input type=\"hidden\" name=\"date\" value=\"$date\" /> \n";
				echo "Страница: <input class=\"itext\" type=\"text\" name=\"p\" size=\"$max_len_digits\" maxlength=\"$max_len_digits\" format=\"".str_repeat("N",$max_len_digits)."\" emptyok=\"true\" /> \n";
				echo "<input class=\"ibutton\" type=\"submit\" value=\"Смотреть\" />\n";
			echo "</form> \n";
			echo "<a href=\"archive.php?date=$date\">В архив</a>\n";
	}
		break;
	default:// ВЫВОД ДЕРЕВА АРХИВА
	$archiveM = array();
	$archiveY = array();
	// выясняем за кокие месяцы (года) есть новости в базе
	// заносим соответственно их в $archiveM ($archiveY)
	$notEnd = true;
	// формирование архива в массивы archiveM и archiveY
	if ($max_id)
	{
		while ($notEnd)
		{
			$cPoint = mktime(0,0,0,$num_month,1,$num_year);
			$cPointNext = mktime(0,0,0,$num_month+1,1,$num_year);
			$result = mysql_query("SELECT max(`id`) FROM `all_tour_result` WHERE `date`>=$cPoint AND `date`<$cPointNext;");
			$row = mysql_fetch_row($result);
			if (!empty($row[0]))
			{
				$id = $row[0];
				if ($id == $max_id) $notEnd = false;
				$indexMonth = (int) date("m",mktime(0,0,0,$num_month,1,$num_year));
				$year = date("Y",$cPoint);
				$archiveM[] = $indexMonth;
				$archiveY[] = $year;
			}
			$num_month++;
		}
	}
	else
		echo "(архив пуст) <br/>\n";
	// вывод архива
	echo "<a href=\"archive.php\">Свернуть все</a> <br/>\n";
	for ($index=count($archiveM)-1; $index>=0; $index--)
	{
		$indexMonth = $archiveM[$index];
		$textMonth = $month[$indexMonth-1];
		$year = $archiveY[$index];
		echo "<a href=\"archive.php?date=$indexMonth-$year\">$textMonth $year</a>\n";
		echo "<br>\n";
		
		// если выбран архив то выводим ссылки игр
		if (!empty($arrDate))
		{
			if ($arrDate[0]==$indexMonth && $arrDate[1]==$year)
			{
				$cPoint = mktime(0,0,0,$arrDate[0],1,$arrDate[1]);
				$cPointNext = mktime(0,0,0,$arrDate[0]+1,1,$arrDate[1]);
				
				$result = mysql_query("SELECT DISTINCT `id_tour` FROM `all_tour_result` WHERE `date`>=$cPoint AND `date`<$cPointNext ORDER BY `id` DESC;");
				$countRows = mysql_num_rows($result);

				for ($i=0; $i<$countRows; $i++)
				{
					$row = mysql_fetch_array($result);
					$result_tour = mysql_query("SELECT * FROM `tournament` WHERE `id_tour`=".$row['id_tour']);
					$row_tour = mysql_fetch_array($result_tour);
					
					echo " - <a href=\"archive.php?act=view&date=$indexMonth-$year&id=".$row['id_tour']."\">".$row_tour['name']."</a> <br/>\n";
				}
			}
		}
	}
}
echo "</body></html>";
?>