function cat() {
	global $prefix, $db, $admin, $module_name, $pagenum, $filenum, $admin_file, $pagetitle, $defis, $fidirectory, $figdactive, $figdwidth;
	$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."_files_categories WHERE cid='$cid'"));
	$pagetitle = "$defis "._FILES." $defis $cat_title";
	head();
    menu();
	OpenTable();
	echo "<center><font class=\"option\">$cat_title</font><br />$cat_description</center>";
	CloseTable();
	categories($cid);
	$offset = intval($offset);
	$filenum = intval($filenum);
$let = text_filter($_GET['let']); #вставленная строка
    if (isset ($let)) {$letter = "and lower(title) LIKE  '$let%'";} else {$letter = "";} #вставленная строка


	$result2 = $db->sql_query("SELECT lid, title, description, img, UNIX_TIMESTAMP(date) as formatted, votes, totalvotes, totalcomments, hits FROM ".$prefix."_files WHERE cid = '$cid' AND status !='0' $letter ORDER BY title ASC");
    if ($db->sql_numrows($result2) > 0) {
		OpenTable();
		while (list($lid, $f_title, $description, $f_img, $formatted, $votes, $totalvotes, $comment, $hits) = $db->sql_fetchrow($result2)) {
			$fp_data = date("d.m.Y", $formatted);

#исключаем старое формироване превьюшки для иконки в заголовке
/*
			$imgf = "";
      if ($f_img != "") {
         $img = ($figdactive) ? create_img($fidirectory, $f_img, $figdwidth) : $f_img;
         $imgf = (file_exists("".$fidirectory."/".$f_img."")) ? "".$fidirectory."/".$f_img."" : $f_img;
         $imgf = "<script language=\"JavaScript\" type=\"text/javascript\" src=\"javascripts/CaricaFoto.js\"></script>"
         ."<script language=\"JavaScript\" type=\"text/javascript\" src=\"javascripts/ShowPic.js\"></script>"
         ."<a href=\"javascript:CaricaFoto('".$imgf."')\" OnMouseOver=\"PicDivShow('".$imgf."');\" OnMouseOut=\"PicDivHide();\" border=\"0\" title=\"".$title."\"><img width=\"".$figdwidth."\" border=\"0\" align=\"left\" src=\"".$img."\" alt=\"".$title."\"></a>";
      }
            $zimg = "<img border=\"0\" src=\"images/blocks/Files.gif\" alt=\"".$f_title."\">";
*/

#делаем превьюшку (выдернуто из функции view_file)
#это начало номер1
		if ($f_img != "") {
			$img = ($figdactive) ? create_img($fidirectory, $f_img, $figdwidth) : $f_img;
			$imgf = (file_exists("".$fidirectory."/".$f_img."")) ? "".$fidirectory."/".$f_img."" : $f_img;
			$img_pre = "<script language=\"JavaScript\" type=\"text/javascript\" src=\"javascripts/CaricaFoto.js\"></script>"
			."<script language=\"JavaScript\" type=\"text/javascript\" src=\"javascripts/ShowPic.js\"></script>"
			."<a href=\"javascript:CaricaFoto('".$imgf."')\" OnMouseOver=\"PicDivShow('".$imgf."');\" OnMouseOut=\"PicDivHide();\" border=\"0\" title=\"".$title."\"><img width=\"".$figdwidth."\" border=\"0\" align=\"left\" src=\"".$img."\" alt=\"".$title."\"></a>";
		}
#это конец намера1

#вставляем $img_pre там, где нам надо (около описания файла)
			echo "<table border=\"0\" width=\"100%\" cellpadding=\"3\" cellspacing=\"1\" class=\"bgcolor4\"><tr class=\"bgcolor1\">"
			."<td colspan=\"2\"><table border=\"0\" cellpadding=\"1\" cellspacing=\"0\"><tr><td></td><td><a href=index.php?name=$module_name&op=view_files&lid=$lid title=\"$f_title\"><b>$f_title</b></a></td><td>".new_graphic($formatted)."</td></tr></table></td><td align=\"right\">"._ADDDATE.": $fp_data</td></tr>"
			."<tr class=\"bgcolor1\"><td colspan=\"3\">".$img_pre."".cutstr(bb_decode($description), 350)."</td></tr>"
			."<tr class=\"bgcolor1\"><td width=\"33%\">"._FILEHITS.": $hits</td>"
			."<td width=\"33%\"><a href=index.php?name=$module_name&op=view_files&lid=$lid#$lid title=\"$f_title\">"._FILECOMMENTS.": $comment</a></td><td width=\"34%\" align=\"right\">"._FILEREITING.": ".vote_graphic($votes, $totalvotes)."</td></tr>";
			if (is_admin($admin)) {
				echo "<tr class=\"bgcolor1\"><td colspan=\"3\" align=\"center\">[ <a href=".$admin_file.".php?op=delit_files&lid=$lid>"._DELETE."</a> | <a href=".$admin_file.".php?op=edit_files&lid=$lid>"._EDIT."</a> ]</td></tr>";
			}
			echo "</table><br />";
		}
		CloseTable();
	}
list($numstories) = $db->sql_fetchrow($db->sql_query("SELECT Count(cid) AS ccid FROM ".$prefix."_files AS c WHERE cid = '$cid' AND status !='0' $letter "));
	$numpages = ceil($numstories / $filenum);
	num_page($module_name, $numstories, $numpages, $filenum, "let=".urlencode($let)."&op=cat&id=".$cid."&");
	get_page($module_name);
	foot();
}









function view_files() {
    global $hometext, $pagetitle, $prefix, $db, $admin, $module_name, $commentfiles, $poolfiles, $broclink, $admin_file, $defis, $datetime, $downfiles, $fidirectory, $figdactive, $figdwidth;
    $lid = intval($_GET['lid']);
	$result = $db->sql_query("SELECT cid, title, url, description, img, date, filesize, version, name, email, homepage, votes, totalvotes, totalcomments, hits FROM ".$prefix."_files WHERE lid='$lid'");
	if ($db->sql_numrows($result) > 0) {
		list($cid, $title, $url, $description, $f_img, $date, $f_size, $f_version, $a_name, $a_email, $a_homepage, $votes, $totalvotes, $totalcomments, $hits) = $db->sql_fetchrow($result);
		$hometext = $description;
		$pagetitle = "$defis "._FILES." $defis $title";
		formatTimestamp($date);
		head();
		menu();
		OpenTable();
		$a_email = ($a_email) ? "<a href=\"mailto:".$a_email."\"><img border=\"0\" src=\"images/blocks/Contact.gif\" alt=\""._FAUEMAIL."\"></a>" : "";
		$a_homepage = ($a_homepage) ? "<a href=\"".$a_homepage."\" target=\"_blank\"><img border=\"0\" src=\"images/blocks/Home.gif\" alt=\""._FAUURL."\"></a>" : "";
		echo "<center><font class=\"option\">$title</font></center><hr>"
		."<table border=\"0\" width=\"100%\" cellpadding=\"3\" cellspacing=\"0\"><tr><td>"._FILEAUTOR.": ".$a_name." ".$a_email." ".$a_homepage."</td><td>"._FILEREITING.": ".vote_graphic($votes, $totalvotes)."</td></tr>"
		."<tr><td>"._FILESIZE.": ".files_size($f_size)."</td><td>"._ADDDATE.": $datetime</td></tr>"
		."<tr><td>"._FILEVERS.": $f_version</td><td>"._FILEHITS.": $hits</td></tr></table><hr>"
		."<table border=\"0\" width=\"100%\" cellpadding=\"3\" cellspacing=\"0\"><tr><td>";
		if ($f_img != "") {
			$img = ($figdactive) ? create_img($fidirectory, $f_img, $figdwidth) : $f_img;
			$imgf = (file_exists("".$fidirectory."/".$f_img."")) ? "".$fidirectory."/".$f_img."" : $f_img;
			echo "<script language=\"JavaScript\" type=\"text/javascript\" src=\"javascripts/CaricaFoto.js\"></script>"
			."<script language=\"JavaScript\" type=\"text/javascript\" src=\"javascripts/ShowPic.js\"></script>"
			."<a href=\"javascript:CaricaFoto('".$imgf."')\" OnMouseOver=\"PicDivShow('".$imgf."');\" OnMouseOut=\"PicDivHide();\" border=\"0\" title=\"".$title."\"><img width=\"".$figdwidth."\" border=\"0\" align=\"left\" src=\"".$img."\" alt=\"".$title."\"></a>";
		}
		echo "".bb_decode($description)."</td></tr>";
		if ($broclink == 1) echo "<tr><td colspan=\"2\"><a href=\"index.php?name=$module_name&op=broken&lid=$lid\"><img border=\"0\" src=\"images/red_dot.gif\" alt=\""._BROCFILE."\"> "._BROCFILE."</a></td></tr>";
		echo "</table><hr><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\"><tr>";
		if (is_user($user) OR $downfiles == "1") {
			echo "<td><form method=\"POST\" action=\"index.php?name=$module_name\" style=\"display: inline\">"
			."<input type=\"hidden\" name=\"lid\" value=\"$lid\">"
			."<input type=\"hidden\" name=\"op\" value=\"getit\">"
			."<input type=\"submit\" onClick=\"window.open('$url')\" value=\""._DOWNLFILE."\">&nbsp;</form></td>";
		}
		if ($poolfiles == 1) {
			echo "<td><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></td>";
		}
		echo "</tr></table>";
		if (is_admin($admin)) echo "<hr><center>[ <a href=".$admin_file.".php?op=delit_files&lid=$lid>"._DELETE."</a> | <a href=".$admin_file.".php?op=edit_files&lid=$lid>"._EDIT."</a> ]</center>";
		CloseTable();
		if ($commentfiles == 1) {
			echo "<a name=\"$lid\"></a>";
			ShowComments($lid);
		}
		foot();
	} else {
		Header("Location: index.php?name=".$module_name."");
	}
}

