<?php
if (!defined('MODULE_FILE')) {
	Header("Location: ../../index.php");
	exit;
}
$module_name = basename(dirname(__FILE__));
get_lang($module_name);
require_once("config/config_media2.php");


function menu() {
	global $prefix, $db, $addfiles, $addquest, $module_name;
	OpenTable();
	echo  "<center><img src='modules/media2/gamer2.png' border='0'><br><br><a href=\"index.php?name=media2\" title=\""._MHOME."\"><b>"._MHOME."</b></a> <b>| <a href=\"index.php?name=$module_name&op=liste\" title=\"Список игр\"><b>Список игр</b></a>  | <a href=\"index.php?name=Search_site\" title=\"Медиа-поиск\"><b>Поиск</b></a>"

	."";
	if ((is_user($user) && $addfiles == 1) || (!is_user($user) && $addquest == 1)) echo " | </b><a href=\"index.php?name=media2&op=add_file\" title=\""._ADDFILE."\">"._ADDFILE."</a>";
	echo "<br><br></center>";
	CloseTable();
}

function liste() {
	global $db, $prefix, $module_name, $pagetitle, $defis, $filelistnum;
	$filelistnum = intval($filelistnum);
	$let = (!preg_match("/[^a-zA-Zа-яА-Я0-9]/", $_GET['let'])) ? $_GET['let'] : "";
	if ($let) {
		$field = "op=liste&let=$let&";
		$pagetitle = "$defis "._FILES." $defis "._LIST." $defis $let";
		$order = "WHERE UPPER(f.title) LIKE '".$let."%' AND date <= now() AND status!='0'";
	} else {
		$field = "op=liste&";
		$pagetitle = "$defis "._FILES." $defis "._LIST."";
		$order = "WHERE date <= now() AND status!='0'";
	}
	$num = (intval($pagenum)) ? $pagenum : 1;
	$offset = ($num-1) * $filelistnum;
	$offset = intval($offset);
	$result = $db->sql_query("SELECT f.lid, f.cid, f.title, f.date, f.name, f.album, c.cid, c.title, f.year, f.votes, f.totalvotes FROM ".$prefix."_media2 AS f LEFT JOIN ".$prefix."_media2_categories AS c ON (f.cid=c.cid) ".$order." ORDER BY date DESC LIMIT $offset, $filelistnum");
	include("header.php");
	menu();
	if ($db->sql_numrows($result) > 0) {
		OpenTable();
        echo "<table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\"><tr class=\"bgcolor1\"><td align=\"center\">";
        echo "<a href=\"index.php?name=".$module_name."&op=liste\">"._ALL."</a>";
foreach(range(1, 9) as $number) echo " <a href='index.php?name=$module_name&op=liste&let=$number'>$number</a>";
        echo "<br><br>";
foreach(range('А', 'Я') as $letter) echo " <a href='index.php?name=$module_name&op=liste&let=$letter'>$letter</a>";
        echo "<br><br>";
foreach(range('A', 'Z') as $lettereng) echo "  <a href=\"index.php?name=$module_name&op=liste&let=$lettereng\">$lettereng</a>";
        echo "</center></td></tr></table><table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\"><td><tr></td></tr></table>";
		echo "<script language=\"JavaScript\" type=\"text/javascript\" src=\"javascripts/SortTable.js\"></script><table width=\"100%\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" class=\"sort\" id=\"sort_id\"><tr>"
		."<th>Название</th><th>Жанр игры</th><th>Год выпуска</th><th>Рейтинг</th><th>"._DATE."</th></tr>";
		while (list($id, $catid, $stitle, $time, $aid, $alb, $cid, $ctitle, $year, $votes, $totalvotes) = $db->sql_fetchrow($result)) {
			$ctitle = (!$ctitle) ? ""._NO."" : "<a href=\"index.php?name=$module_name&op=cat&id=$cid\" title=\"".$ctitle."\">".cutstr($ctitle, 19)."</a>";
			echo "<tr class=\"bgcolor7\">"
		
			."<td width=\"55%\"><a href=\"index.php?name=$module_name&op=view_file&lid=$id\" title=\"".$stitle."\">".cutstr($stitle, 65)."</a></td>"

			."<td align=\"center\">".$ctitle."</td>"
			."<td width=\"15%\" align=\"center\">".$year."</td><td width=\"15%\" align=\"center\">".vote_graphic($votes, $totalvotes)."</td><td width=\"12%\" align=\"center\">".formatTimestamp($time)."</td>"
	;
		}
		echo "</table>";
		CloseTable();
		$order2 = ($let) ? "WHERE UPPER(title) LIKE '".$let."%' AND date <= now() AND status!='0'" : "WHERE date <= now() AND status!='0'";
		list($numstories) = $db->sql_fetchrow($db->sql_query("SELECT Count(lid) FROM ".$prefix."_media2 ".$order2.""));
		$numpages = ceil($numstories / $filelistnum);
		num_page($module_name, $numstories, $numpages, $filelistnum, "".$field."");
		get_page($module_name);
	} else {
        echo "<table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" class=\"bgcolor4\"><tr class=\"bgcolor1\"><td align=\"center\">";
        echo "<a href=\"index.php?name=".$module_name."&op=liste\">"._ALL."</a>";
foreach(range(1, 9) as $number) echo " <a href='index.php?name=$module_name&op=liste&let=$number'>$number</a>";
        echo "<br><br>";
foreach(range('А', 'Я') as $letter) echo " <a href='index.php?name=$module_name&op=liste&let=$letter'>$letter</a>";
        echo "<br><br>";
foreach(range('A', 'Z') as $lettereng) echo "  <a href=\"index.php?name=$module_name&op=liste&let=$lettereng\">$lettereng</a>";
        echo "</center></td></tr></table><table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\"><td><tr></td></tr></table>";
		warning(""._NO_INFO."", "", "", 2);
	}
	
}

function categories($id="") {
	global $prefix, $db, $module_name, $tabcolumn, $showsubkat, $showtext, $showfilesincat, $showfilesinsubcat;
	static $massiv, $massiv2;
	$id = (intval($id)) ? $id : 0;
	$where = ($id) ? "WHERE parentid = '$id'" : "";
	$tdwidth = intval(100/$tabcolumn);
	while (list($cid, $title, $parentid) = $db->sql_fetchrow($result)) $massiv2[] = array($cid, $title, $parentid);
	if (!is_array($massiv)) {
		//m@rt upgrate start
		$result = $db->sql_query("SELECT cid, title, cdescription, cimg, parentid FROM ".$prefix."_media2_categories ".$where."");
		while (list($cid, $title, $cdescription, $imgcat, $parentid) = $db->sql_fetchrow($result)) $massiv[] = array($cid, $title, $cdescription, $imgcat, $parentid);
	}
	if (!is_array($massiv2)) {
		$result = $db->sql_query("SELECT cid, title, parentid FROM ".$prefix."_media2_categories");
		while (list($cid, $title, $parentid) = $db->sql_fetchrow($result)) $massiv2[] = array($cid, $title, $parentid);
	}
	if ($massiv) {
		foreach ($massiv as $key => $val) {
			if ($val[4] == $id) {
				$ccontent .= "<td valign=\"top\" width=\"".$tdwidth."%\"><table border=\"0\"><tr><td>";
				if ($val[3] != "") {
				$ccontent .= "<img border=\"0\" src=\"modules/media2/imgcat/$val[3]\" title=\"$title\">";
				} else {
				$ccontent .= "<img border=\"0\" src=\"modules/media2/imgcat/game.gif\" title=\"$title\">";
				}
				if ($showfilesincat == 1) {
				list($files_incat) = $db->sql_fetchrow($db->sql_query("SELECT Count(lid) FROM ".$prefix."_media2 WHERE status !='0' AND cid = '$val[0]'"));
				$fcat = " ($files_incat)";
				} else {
				$fcat = "";
				}				
				$ccontent .= "</td><td><table border=\"0\"><tr><td><a href=\"index.php?name=$module_name&op=cat&id=$val[0]\" title=\"$val[1]\"><b>$val[1]$fcat</b></a></td></tr>";
				if ($showtext == 1) {
				$ccontent .= "<tr><td>$val[2]</td></tr>";
				}
				$ccontent .= "</table></td></tr>";
				if ($showsubkat == 1 && $massiv2) {
					foreach ($massiv2 as $key => $val2) {
						if ($val[0] == $val2[2]) {
							if ($showfilesinsubcat == 1) {
							list($files_insubcat) = $db->sql_fetchrow($db->sql_query("SELECT Count(lid) FROM ".$prefix."_media2 WHERE status !='0' AND cid = '$val2[0]'"));
							$fsubcat = " ($files_insubcat)";
							} else {
							$fsubcat = "";
							}
							$ccontent .= "<tr><td colspan=\"2\"><img border=\"0\" src=\"images/dot.gif\" title=\"$val2[1]\"> <a href=\"index.php?name=$module_name&op=cat&id=$val2[0]\" title=\"$val2[1]\">$val2[1]$fsubcat</a></td></tr>";
						}
					}
				}
		//m@rt upgrate stop
				$ccontent .= "</table></td>";
				if ($cont == ($tabcolumn - 1)) {
					$ccontent .= "</tr><tr>";
					$cont = 0;
				} else {
					$cont++;
				}
			}
		}
	}
	if ($ccontent) {
		OpenTable();
		echo "<table border=\"0\" class=\"bgcolor1\" cellspacing=\"0\" cellpadding=\"1\" align=\"center\"><tr>".$ccontent."</td></tr></table>";
		list($files_num) = $db->sql_fetchrow($db->sql_query("SELECT Count(lid) FROM ".$prefix."_media2 WHERE status !='0'"));
		list($cat_num) = $db->sql_fetchrow($db->sql_query("SELECT Count(cid) FROM ".$prefix."_media2_categories"));
		echo "<hr><center>"._ALLFILES.": <b>$files_num</b> "._INF." <b>$cat_num</b> "._ALLFILES2."<br><br>А также, на нашем фтп-сервер Вы можете найти <a href=\"ftp://ftp3.icom.net/Games/emulyations\" target=\"blank\"><b>эмулированные</b></a> игры с приставок!<br> Рекомендуемая программа для монтирования образов - <a href=\"ftp://ftp3.icom.net/Games/!game_soft!/daemon\" target=\"blank\"><b>Daemon Tools</b></a>.<br>Если Вам необходим патч для какой-либо игры, попробуйте поискать его на <a href=\"ftp://ftp3.icom.net/NEW2/patch/\" target=\"blank\"><b>FTP</b></a>!</center><br>";
		CloseTable();
	}
}

function getparent($parentid,$title) {
	global $prefix, $db;
    list($cid, $filetitle, $pparentid) = $db->sql_fetchrow($db->sql_query("SELECT cid, title, parentid FROM ".$prefix."_media2_categories WHERE cid=$parentid"));
    if ($filetitle != "") $title = $filetitle."/".$title;
    if ($pparentid != 0) $title = getparent($pparentid, $title);
    return $title;
}

function mainfiles() {
    global $prefix, $db, $admin, $module_name, $tabcolumn, $showsubkat, $numsubkat, $admin_file, $pagetitle, $defis, $filenum, $showimgcat, $pagenum;
	$pagetitle = "$defis "._FILES."";
	if ($pagenum == "") $pagenum = 1;
    $offset = ($pagenum-1) * $filenum;
    include("header.php");
	menu();
	categories();
	$filenum = intval($filenum);
	$offset = intval($offset);
	if (isset($_GET['new'])) {
		$order = "date<=NOW() AND status !='0' ORDER BY formatted DESC LIMIT $filenum";
		$file_logo = ""._NEW_FILES."";
	} elseif(isset($_GET['hits'])) {
		$order = "hits AND status !='0' ORDER BY hits DESC LIMIT $filenum";
		$file_logo = ""._POP_FILES."";
	} elseif(isset($_POST['search_word'])) {
		$search_word = text_filter($_POST['search_word']);
		$order = "title LIKE '%$search_word%' AND status !='0'";
		$file_logo = ""._SEARCH_FILES."";
	} else {
		$order = "date AND status !='0' ORDER BY date DESC LIMIT $offset, $filenum";	
		$file_logo = ""._MHOME."";
	}

list($numstories) = $db->sql_fetchrow($db->sql_query("SELECT Count(cid) FROM ".$prefix."_media2 WHERE status !='0'"));
$numpages = ceil($numstories / $filenum);
num_page($module_name, $numstories, $numpages, $filenum, "op=mainfiles&id=".$cid."&");


	$result3 = $db->sql_query("SELECT m.lid, m.cid, m.title, m.description, m.url, UNIX_TIMESTAMP(m.date) as formatted, m.name, m.album, m.votes, m.totalvotes, m.totalcomments, m.year, m.hits, c.cid, c.title, c.cimg FROM ".$prefix."_media2 AS m LEFT JOIN ".$prefix."_media2_categories AS c ON (m.cid=c.cid) WHERE ".$order."");
	if ($db->sql_numrows($result3) > 0) {
		OpenTable();
		while (list($lid, $cid, $f_title, $description, $imgurl, $formatted, $aid, $album, $votes, $totalvotes, $comment, $year, $hits, $ccid, $ctitle, $cimg) = $db->sql_fetchrow($result3)) {
			$fp_data = date("d.m.Y", $formatted);

		//m@rt upgrate start
		echo "<table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" class=\"bgcolor5\">
		<tr class=\"bgcolor6\">
<th><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"left\"><tr><td nowrap><tr><td nowrap><b>&nbsp;<a href=index.php?name=$module_name&op=view_file&lid=$lid title=\"$f_title\"><font class=\"storytitle\">$f_title</a></font>&nbsp;".new_graphic($formatted)."";
		if ($album != "") {
		echo " - $album";
		}	
		echo "</b></a></td>";
		if ($cid == "0") {	

		}

		echo "</tr></table></th></tr><tr class=\"bgcolor7\"><td>"
		. "<table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"1\"><tr><td>";
		if ($imgurl != "") {
		echo "<a href=index.php?name=$module_name&op=view_file&lid=$lid title=\"$f_title\"><img src=\"$imgurl\" width=\"150\" title=\"Обложка\" border=\"1\">";
		} else {
		echo "<a href=index.php?name=$module_name&op=view_file&lid=$lid title=\"$f_title\"><img src=\"images/media.png\" title=\"Нет обложки\" border=\"1\">";
		}

		echo "</td><td>&nbsp;&nbsp;</td><td width=\"100%\" valign=\"top\">";
		if ($showimgcat == 1) {	
				if ($cimg != "") {
	echo "".cutstr(bb_decode($description), 600)."</td><td>&nbsp;</td><td valign=\"bottom\"><a href=\"index.php?name=$module_name&op=cat&id=$ccid\"><img border=\"0\" src=\"modules/$module_name/imgcat/$cimg\" title=\"$ctitle\"></a></td>";
	} elseif  ($cid == "0") {
	echo "".cutstr(bb_decode($description), 600)."</td><td>&nbsp;</td>";
	} else {
	echo "".cutstr(bb_decode($description), 600)."</td><td>&nbsp;</td><td valign=\"bottom\"></td>";
	}

	} else {
	echo "".cutstr(bb_decode($description), 600)."</td>";
	}

	echo "<td>&nbsp;</td></tr></table>"


		."</td></tr><tr class=\"bgcolor6\"><td><table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\"><tr><td align=\"left\" width=\"70%\"><a href=index.php?name=$module_name&op=view_file&lid=$lid title=\"$f_title\"><b>Подробнее</b></a> | Жанр: <a href=\"index.php?name=$module_name&op=cat&id=$cid\" title=\"".$ctitle."\"><b>".$ctitle."</b></a> | Год выпуска: <b>".$year."</b> | Просмотров:<b> $hits</b> | Общая оценка:<b> ".vote_graphic($votes, $totalvotes)."</b></td>";
			if (is_admin($admin)) {
			echo "<td>&nbsp;</td><td><a href=".$admin_file.".php?op=edit_media2&lid=$lid title=\""._EDIT."\"><img src=\"images/edit.gif\" border=\"0\"></a></td>
			<td><a href=".$admin_file.".php?op=delit_media2&lid=$lid title=\""._DELETE."\"><img src=\"images/delete.gif\" border=\"0\"></a></td>";
			}

		echo "</tr></table></td>
		</tr>
		</table><table width=\"100%\" cellpadding=\"5\" cellspacing=\"0\"><tr><td></td></tr></table>";
		//m@rt upgrate stop

		}

		CloseTable();
		}
		list($numstories) = $db->sql_fetchrow($db->sql_query("SELECT Count(cid) FROM ".$prefix."_media2 WHERE status !='0'"));
		$numpages = ceil($numstories / $filenum);
		num_page($module_name, $numstories, $numpages, $filenum, "op=mainfiles&id=".$cid."&");
		get_page($module_name);

		


	
}

function cat() {
	global $prefix, $db, $admin, $module_name, $pagenum, $filenum, $admin_file, $pagetitle, $defis, $figdactive, $figdwidth, $showimgcat;
	$cid = intval($_GET['id']);
	if ($pagenum == "") $pagenum = 1;
    $offset = ($pagenum-1) * $filenum;
	list($cat_title, $cat_description) = $db->sql_fetchrow($db->sql_query("SELECT title, cdescription FROM ".$prefix."_media2_categories WHERE cid='$cid'"));
	$pagetitle = "$defis "._FILES." $defis $cat_title";
	include("header.php");
    menu();
	OpenTable();
	echo "<center><table border=0 width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" class=\"bgcolor6\" ><td class=\"bgcolor7\"><font class=\"option\"><center>$cat_title</font><br></center></td></table>";
	CloseTable();
	categories($cid);
	$offset = intval($offset);
	$filenum = intval($filenum);
	$result2 = $db->sql_query("SELECT m.lid, m.title, m.description, m.url, UNIX_TIMESTAMP(m.date) as formatted, m.name, m.album, m.votes, m.totalvotes, m.totalcomments, m.year, m.hits, c.cid, c.title, c.cimg FROM ".$prefix."_media2 AS m LEFT JOIN ".$prefix."_media2_categories AS c ON (m.cid=c.cid) WHERE m.cid = '$cid' AND status !='0' ORDER BY date DESC LIMIT $offset, $filenum");
    if ($db->sql_numrows($result2) > 0) {
		OpenTable();
		while (list($lid, $f_title, $description, $imgurl, $formatted, $aid, $album, $votes, $totalvotes, $comment, $year, $hits, $ccid, $ctitle, $cimg) = $db->sql_fetchrow($result2)) {
			$fp_data = date("d.m.Y", $formatted);
		//m@rt upgrate start
		echo "<table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" class=\"bgcolor5\">
		<tr class=\"bgcolor6\">
<th><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"left\"><tr><td nowrap><b>&nbsp;<a href=index.php?name=$module_name&op=view_file&lid=$lid title=\"$f_title\"><font class=\"storytitle\">$f_title</a></font></b>";
		if ($album != "") {
		echo " - $album";
		}
		echo "</b></a></td>"
		."</tr></table></th></tr><tr class=\"bgcolor7\"><td>"
		. "<table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>";
		if ($imgurl != "") {
		echo "<a href=index.php?name=$module_name&op=view_file&lid=$lid title=\"$f_title\"><img src=\"$imgurl\" width=\"150\" title=\"Обложка\" border=\"1\">";
		} else {
		echo "<a href=index.php?name=$module_name&op=view_file&lid=$lid title=\"$f_title\"><img src=\"images/media.png\" title=\"Нет скриншота\" border=\"1\">";
		}
		echo "</td><td>&nbsp;&nbsp;</td><td width=\"100%\" valign=\"top\">";
		if ($showimgcat == 1) {	
				if ($cimg != "") {
	echo "".cutstr(bb_decode($description), 600)."</td><td>&nbsp;</td><td valign=\"bottom\"><a href=\"index.php?name=$module_name&op=cat&id=$ccid\"><img border=\"0\" src=\"modules/$module_name/imgcat/$cimg\" title=\"$ctitle\"></a></td>";
	} elseif  ($cid == "0") {
	echo "".cutstr(bb_decode($description), 600)."</td><td>&nbsp;</td";
	} else {
	echo "".cutstr(bb_decode($description), 600)."</td><td>&nbsp;</td>";
	}
	} else {
	echo "".cutstr(bb_decode($description), 600)."</td>";
	}
	echo "<td>&nbsp;</td></tr></table>"
		."</td></tr><tr class=\"bgcolor6\"><td><table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\"><tr><td align=\"left\" width=\"70%\"><a href=index.php?name=$module_name&op=view_file&lid=$lid title=\"$f_title\"><b>Подробнее</b></a> | Год выпуска: <b>".$year."</b> | Просмотров: <b>$hits</b> | Общая оценка:<b> ".vote_graphic($votes, $totalvotes)."</b></td>";
			if (is_admin($admin)) {
			echo "<td>&nbsp;</td><td><a href=".$admin_file.".php?op=edit_media2&lid=$lid title=\""._EDIT."\"><img src=\"images/edit.gif\" border=\"0\"></a></td>
			<td><a href=".$admin_file.".php?op=delit_media2&lid=$lid title=\""._DELETE."\"><img src=\"images/delete.gif\" border=\"0\"></a></td>";
			}
		echo "</tr></table></td>
		</tr>
		</table><table width=\"100%\" cellpadding=\"5\" cellspacing=\"0\"><tr><td></td></tr></table>";
		//m@rt upgrate stop
		}
		CloseTable();
	}
	list($numstories) = $db->sql_fetchrow($db->sql_query("SELECT Count(cid) AS ccid FROM ".$prefix."_media2 AS c WHERE cid = '$cid' AND status !='0'"));
	$numpages = ceil($numstories / $filenum);
	num_page($module_name, $numstories, $numpages, $filenum, "op=cat&id=".$cid."&");
	get_page($module_name);
	

}
function view_file() {
    global $hometext, $pagetitle, $prefix, $db, $admin, $module_name, $commentfiles, $poolfiles, $broclink, $admin_file, $defis, $datetime, $downfiles, $figdactive, $figdwidth, $viewimg, $showimgcat;
    $lid = intval($_GET['lid']);
	//m@rt upgrate start 
	$result = $db->sql_query("SELECT m.cid, m.title, m.description, m.url, m.date, m.size, m.roles, m.name, m.album, m.year, m.lang, m.format, m.quality, m.links, m.time, m.director, m.votes, m.totalvotes, m.totalcomments, m.hits, c.cid, c.title, c.cimg FROM ".$prefix."_media2 AS m LEFT JOIN ".$prefix."_media2_categories AS c ON (m.cid=c.cid) WHERE lid='$lid'");
	if ($db->sql_numrows($result) > 0) {
		$db->sql_query("UPDATE ".$prefix."_media2 SET hits=hits+1 WHERE lid='$lid'");
		list($cid, $title, $description, $url, $date, $size, $roles, $a_name, $a_album, $year, $f_langt, $format, $quality, $links, $time, $director, $votes, $totalvotes, $totalcomments, $hits, $ccid, $ctitle, $cimg) = $db->sql_fetchrow($result);
		$descript = "<table border=\"0\" width=\"100%\" cellpadding=\"3\" cellspacing=\"0\"><table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"1\" class=\"middle\"><tr><td><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\" class=\"bodyline\"><tr cellspacing=\"3\" cellpadding=\"3\"><td class=\"bgcolor9\" cellspacing=\"3\" cellpadding=\"3\">".bb_decode($description)."<br>";
		if ($year) {
		$descript .="<br><b>Год выпуска:</b> $year";
		}

		if ($director) {
		$descript .="<br><b>Разработчик:</b> $director";
		}
	if ($f_langt) {
		$descript .="<br><b>Локализация:</b> $f_langt<br><br><b>Системные требования</b>";
		}
		if ($roles) {
		$descript .="<br><b>Минимальные:</b> $roles";
		}
		if ($time) {
		$descript .="<br><b>Рекомендуемые:</b> $time<br>";
		}
		
		if ($size) {
		$descript .="<br><b>Общий размер:</b> $size";
		}
		$descript .="</td></tr></table>";
		$hometext = $description;
		$pagetitle = "$defis "._FILES." $defis $title";
		$ctitle = (!$ctitle) ? ""._NO."" : "<a href=\"index.php?name=$module_name&op=cat&id=$ccid\" title=\"".$ctitle."\">$ctitle</a>";
		formatTimestamp($date);
		include("header.php");
		menu();
	OpenTable();
    echo "<table border=\"0\" width=\"100%\" cellpadding=\"3\" cellspacing=\"1\" class=\"bgcolor1\"><tr class=\"bgcolor1\"><table border=\"0\" width=\"100%\" class=\"bgcolor5\" cellpadding=\"3\" cellspacing=\"0\"><th><center><font class=\"option2\">$title</th>";
    if ($a_album != "") {
    echo " - $a_album";
    }
    echo "</font></center></td></tr></table></th></tr><tr class=\"bgcolor1\"><td>"
	."<table border=\"0\" width=\"100%\" cellpadding=\"4\" cellspacing=\"0\"><tr><td><b>Дата размещения:</b> $datetime</td><td align=\"right\"><b>Жанр игры: ".$ctitle."</b></td></tr>"
	."<tr></tr></table><hr>"	
	."<table border=\"0\" width=\"100%\" cellpadding=\"3\" cellspacing=\"0\"><tr><td>";
	if ($url) {
		echo "<td><img width=\"150\" border=\"1\" align=\"left\" src=\"$url\" alt=\"".$title."\">"
	. "<div id=\"picDiv\" style=\"position: absolute; left: 525px; top: 180px; width: 200px; height: 200px; z-index: 1; display: none;\"><table class=\"bodyline\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" height=\"200\" width=\"200\"><tr class=\"bgcolor1\"><td align=\"center\" valign=\"middle\"><img src=\"images/load.gif\" id=\"picDivImg\"></td></tr></table></div>";
	}
	if ($showimgcat == 1) {
	echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>&nbsp;</td><td width=\"100%\" valign=\"top\">";
				if ($cimg != "") {
	echo "$descript</td><td>&nbsp;";
	} elseif  ($cid == "0") {
	echo "$descript</td><td>&nbsp;</td><td>&nbsp;";
	} else {
	echo "$descript</td><td>&nbsp;</td><td>&nbsp;";
	}
	echo "</td></tr></table>";
	} else {
	echo "$descript";
	}
	echo "</td></tr></table>";
	if (is_user($user) OR $downfiles == "1") {
	echo "<hr><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";

			if ($links) {
		
				$links = explode(",", $links);
				$i = 1;
				foreach ($links as $key => $val) {
					if ($val != "") {
						if ($i == 1) {
							echo "<td width=\"11%\"></td><td width=\"11%\"><a href=\"javascript:history.go(-1)\"><b><img src='/images/dot2.gif' border='0'>&nbsp;Назад</b></a><br>

<a href=\"index.php?name=media2\"><b><img src='/images/dot2.gif' border='0'>&nbsp;Начало</b>
<br><br><br><br><br><br></td><td width=\"78%\"><a href=\"".$val."\" target=\"_blank\" title=\""._URL2."\"><img src='modules/media2/d.gif' border='0'></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"ftp://ftp3.icom.net/Games/!game_soft!/daemon\" target=\"_blank\" title=\"Скачать Daemon Tools Lite!\"><img src='modules/media2/daemon.png' border='0'></a><br><br>";
						} else {"";
						
		}}				
		}}}
		if ($broclink == 1) echo "<a href=\"index.php?name=$module_name&op=broken&lid=$lid\"><b>Сообщить о недоступном файле</a></b><td>&nbsp;</td>";
    if ($poolfiles == 1) {
		echo "<form method=\"POST\" action=\"index.php?name=$module_name\" style=\"display: inline\">"
        ."<input type=\"hidden\" name=\"op\" value=\"pool\">"
        ."<input type=\"hidden\" name=\"lid\" value=\"$lid\">"
        ."<select name=\"send_reiting\">"
        ."<option selected value=\"5\">"._RATE5."</option>"
        ."<option value=\"4\">"._RATE4."</option>"
        ."<option value=\"3\">"._RATE3."</option>"
        ."<option value=\"2\">"._RATE2."</option>"
        ."<option value=\"1\">"._RATE1."</option></select>&nbsp;"
        ."<input type=\"submit\" value=\""._RATEFILE."\"></form><br><br></td><td>&nbsp;</td></td>";
    }
    if (is_admin($admin)) {			
		echo "<td><a href=".$admin_file.".php?op=edit_media2&lid=$lid title=\""._EDIT."\"><img src=\"images/edit.gif\" border=\"0\"></a></td><td><a href=".$admin_file.".php?op=delit_media2&lid=$lid title=\""._DELETE."\"><img src=\"images/delete.gif\" border=\"0\"></a></td>\n";			
			}
	echo "</tr></table></td></tr></table>";
	//m@rt upgrate stop	
	CloseTable();
		
		if ($commentfiles == 1) {
			echo "<a name=\"$lid\"></a>";
			ShowComments($lid);
		}
		
	} else {
		Header("Location: index.php?name=".$module_name."");
	}
}

function pool($lid, $send_reiting) {
    global $prefix, $db, $poolfiles, $pagetitle, $defis, $file_t, $module_name;
	$pagetitle = "$defis "._FILES." $defis "._RATEFILE."";
	$lid = intval($lid);
	if ($poolfiles == 1 && $lid) {
		$file_t = intval($file_t);
		include("header.php");
		menu();
		$ip = getenv("REMOTE_ADDR");
		$past = time() - $file_t;
		$db->sql_query("DELETE FROM ".$prefix."_media2_poolchec WHERE time < '$past'");
		$num = $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_media2_poolchec WHERE lid='$lid' AND host_addr='$ip'"));
		if ($_COOKIE['Files-'.$lid.''] == $lid || $num > 0) {
			warning(""._RATENOTE."<br><br><center><a href=\"javascript:history.go(-1)\">Назад</a>", "?name=$module_name&op=view_file&lid=$lid", 3, 1);
		} else {
			setcookie("Files-".$lid."", $lid, time() + $file_t);
			$ctime = time();
			$db->sql_query("INSERT INTO ".$prefix."_media2_poolchec (lid, time, host_addr) VALUES ('$lid', '$ctime', '$ip')");
			$db->sql_query("UPDATE ".$prefix."_media2 SET votes=votes+1, totalvotes=totalvotes+$send_reiting WHERE lid='$lid'");
			update_points(16);
			warning(""._RATECOMPLECT."<br><br><center><a href=\"javascript:history.go(-1)\">Назад</a>", "?name=$module_name&op=view_file&lid=$lid", 3, 2);
		}
		
	} else {
		Header("Location: index.php?name=".$module_name."");
	}
}

function broken() {
    global $prefix, $db, $pagetitle, $defis, $broclink, $module_name;
	$pagetitle = "$defis "._FILES." $defis "._BROCFILE."";
	$lid = intval($_GET['lid']);
	if ($broclink == 1 && $lid) {
		include("header.php");
		menu();
		$db->sql_query("UPDATE ".$prefix."_media2 SET status='2' WHERE lid='$lid'");
		warning(""._BROCNOTE."", "?name=$module_name&op=view_file&lid=$lid", 3, 2);
		
	} else {
		Header("Location: index.php?name=$module_name");
	}
}

function add_file() {
    global $db, $prefix, $module_name, $addfiles, $max_size, $addquest, $user, $anonymous, $pagetitle, $defis, $userinfo, $uploadfiles, $ftypefile, $stop, $nlinks, $langtm, $formatm, $qualitym;
	$pagetitle = "$defis "._FILES." $defis "._ADDFILE."";
    if ($addfiles == "1") {
		include("header.php");
		menu();
		if (is_user($user)) {
			getusrinfo($user);
			$author = $userinfo['user_name'];
		} elseif (!is_user($user) AND $addquest == "1") {
			$author = $anonymous;
		} else {
			Header("Location: index.php?name=$module_name");
			exit;
		}
		OpenTable();
		echo "<center><font class=\"option\"><b>"._ADDFILE."</b></font><br /><br />"._ADDFNOTE."";
		if ($uploadfiles == 1) echo "".sprintf(""._ADDFNOTE2."", $ftypefile, files_size($max_size))."";
		echo " "._ADDFNOTE3."</center>";
		CloseTable();
		if ($stop) warning($stop, "", "", 1);
		OpenTable();
		echo "<script language=\"JavaScript\" type=\"text/javascript\" src=\"javascripts/SwitchMenu.js\"></script>"
		."<form name=\"post\" enctype=\"multipart/form-data\" action=\"index.php?name=$module_name\" method=\"post\">"
		."<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" align=\"center\">"
		."<tr><td>Разместил:</td><td><input type=\"text\" name=\"author\" value=\"$author\" maxlength=\"100\" size=\"65\" style=\"width:400px\"></td></tr>"
		."<tr><td>Название / Исполнитель:</td><td><input type=\"text\" name=\"title\" maxlength=\"100\" size=\"65\" style=\"width:400px\"></td></tr>"
		."<tr><td>Альбом:</td><td><input type=\"text\" name=\"albumn\" maxlength=\"100\" size=\"65\" style=\"width:400px\"></td></tr>"
		."<tr><td>"._FCATEGORY.":</td><td><select name=\"cid\" style=\"width:400px\"><option value=\"0\">"._FHOMEFILES."</option>";
		$result = $db->sql_query("SELECT cid, title, parentid FROM ".$prefix."_media2_categories ORDER BY parentid,title");
		while (list($cid, $title, $parentid) = $db->sql_fetchrow($result)) {
			if ($parentid != 0) $title = getparent($parentid, $title);
			echo "<option value=\"$cid\">$title</option>";
		}
		echo "</select></td></tr>";
		echo "<tr><td>"._SUBTITLE.":</td><td><textarea id=\"area\" name=\"description\" cols=\"65\" rows=\"10\" style=\"width:400px\" OnKeyPress=\"TransliteFeld(this, event)\" OnSelect=\"FieldName(this, this.name)\" OnClick=\"FieldName(this, this.name)\" OnKeyUp=\"FieldName(this, this.name)\"></textarea>".get_code("area")."</td></tr>"
	."<tr><td>Год выпуска:</td><td>"
	."<select name=\"year\" style=\"width:400px\">";
	$date = getdate();
	$year = $date[year] - 100;
	while ($year <= $date[year]) {
		echo "<option value=\"$year\">$year</option>";
		$year++;

	}
	echo "</select></td></tr>"
	."<tr><td>Режиссер:</td><td><input type=\"text\" name=\"director\" maxlength=\"100\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>В ролях:</td><td><input type=\"text\" name=\"f_roles\" maxlength=\"100\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>Продолжительность:</td><td><input type=\"text\" name=\"time\" maxlength=\"10\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>Язык:</td><td>"
	."<select name=\"langt\" style=\"width:400px\">";
	$langt = explode(",", $langtm);
	foreach ($langt as $key => $val) {
		echo "<option value=\"$val\">$val</option>";
	}
	echo "</select></td></tr>"	
	."<tr><td>Формат:</td><td>"
	."<select name=\"format\" style=\"width:400px\">"
	."<option value=\"\">Нет информации</option>";
	$format = explode(",", $formatm);
	foreach ($format as $key => $val) {
		echo "<option value=\"$val\">$val</option>";
	}
	echo "</select></td></tr>"
	."<tr><td>Качество:</td><td>"
	."<select name=\"quality\" style=\"width:400px\">"
	."<option value=\"\">Нет информации</option>";
	$quality = explode(",", $qualitym);
	foreach ($quality as $key => $val) {
		echo "<option value=\"$val\">$val</option>";
	}
	echo "</select></td></tr>";
		if ($uploadfiles == 1) {
			echo "<tr><td>"._FILE_USER.":</td><td><input name=\"userfile\" type=\"file\" size=\"65\" style=\"width:400px\"></td></tr>"
			."<tr><td>"._FILE_SITE.":</td><td><input type=\"text\" name=\"sitefile\" value=\"\" size=\"65\" style=\"width:400px\"></td></tr>";
		}
		echo "<tr><td>"._IMGLINK.":</td><td><input type=\"text\" name=\"filelink\" maxlength=\"100\" value=\"http://\" size=\"65\" style=\"width:400px\"></td></tr>"
		."<tr><td>Общий размер::</td><td><input type=\"text\" name=\"size\" maxlength=\"10\" size=\"65\" style=\"width:400px\"></td></tr>"
		."<tr><td colspan=\"2\" align=\"center\">";
		$i = 0;
	while ($i < $nlinks) {
		$a = $i + 1;
		$display = ($i !== 0 && $links[$i] == "") ? "style=\"display:none;\"" : "";
		echo "<div id=\"dis".$i."\" ".$display.">"
		."<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\"><tr><td width=\"100%\">"._URL." - $a:</td><td><input type=\"text\" name=\"links[]\" value=\"".$links[$i]."\" size=\"60\" style=\"width:382px\"></td><td>&nbsp;<img src=\"images/editor/plus.gif\" id=\"cont\" border=\"0\" alt=\""._ADD."\" title=\""._ADD."\" id=\"menu".$a."\" OnClick=\"SwitchMenu('dis".$a."')\" style=\"cursor:pointer;\"></td></tr></table><table border=\"0\" cellpadding=\"2\" cellspacing=\"0\"><tr><td></td></tr></table>"
		."</div>";
		$i++;
	}
		echo "<input type=\"hidden\" name=\"op\" value=\"file_send\">"
		."<input type=\"submit\" value=\""._FADD."\"></td></tr></form></table>";
		CloseTable();
		
	} else {
		Header("Location: index.php?name=$module_name");
    }
}

function file_send($title, $description, $cid, $filelink, $author, $albumn, $year, $langt, $format, $quality, $links, $time, $director, $f_roles, $size) {
	global $prefix, $db, $temp_path, $max_size, $addfiles, $module_name, $ftypefile, $stop, $fiwidth, $fiheight;
	if ($addfiles == "1") {
		$links = $_POST['links'];
		$b = 0;
		foreach ($links as $key => $val) {
			if ($val != "") {
				if ($b == 0) {
					$links = $val;
					$b++;
				} else {
					$links .= ",".$val."";
				}
			}
		}	
		if ($filelink == "http://") $filelink = "";
		$title = text_filter($title);
		$description = text_filter($description);
		$filelink = text_filter($filelink);
		$author = text_filter($author);
		$albumn = text_filter($albumn);
		$year = text_filter($year);
		$langt = text_filter($langt);
		$format = text_filter($format);
		$quality = text_filter($quality);
		$links = text_filter($links);	
		$time = text_filter($time);
		$director = text_filter($director);
		$f_roles = text_filter($f_roles);
		$cid = intval($cid);
		$ip = getenv("REMOTE_ADDR");
		if (!$stop && $title && $description && $author && $links) {
			$filename = upload($temp_path, $ftypefile, $max_size, "media2", $fiwidth, $fiheight);
			if ($filename && !$stop) {
			$file_name = "".$temp_path."/".$filename."";
			$filelink = ($file_name) ? $file_name : $filelink;
				$db->sql_query("INSERT INTO ".$prefix."_media2 (lid, cid, title, description, url, date, size, roles, name, album, year, lang, format, quality, links, time, director, ip_sender, status) VALUES (NULL, '$cid', '$title', '$description', '$filelink', now(), '$size', '$f_roles', '$author', '$albumn', '$year', '$langt', '$format', '$quality', '$links', '$time', '$director', '$ip', '0')");
			} elseif (!$stop) {
				$db->sql_query("INSERT INTO ".$prefix."_media2 (lid, cid, title, description, url, date, size, roles, name, album, year, lang, format, quality, links, time, director, ip_sender, status) VALUES (NULL, '$cid', '$title', '$description', '$filelink', now(), '$size', '$f_roles', '$author', '$albumn', '$year', '$langt', '$format', '$quality', '$links', '$time', '$director', '$ip', '0')");	 
		} elseif ($stop) {
			$stop = $stop;
			}
		} else {
			$stop = ""._UPLOADEROR."";
		}
		if (!$stop) {
			include("header.php");
			menu();
			warning(""._UPLOADFINISH."", "?name=$module_name", 5, 2);
			
		} else {
			add_file();
		}
	} else {
		Header("Location: index.php?name=$module_name");
	}
}

switch($op) {


	case "cat":
    cat();
    break;
	
	case "view_file":
    view_file();
    break;

    case "pool":
    pool($lid, $send_reiting);
    break;

    case "broken":
    broken();
    break;

    case "add_file":
    add_file();
    break;

  
    
    case "liste":
    liste();
    break;

    default:
    mainfiles();
    break;

}
?>