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

function menu() {
	global $prefix, $db, $addfiles, $addquest, $module_name;
	OpenTable();
	echo "<center><font class=\"title\"><b>"._FILE_LOGO."</b></font><br><br>"
	."<form action=\"index.php?name=$module_name\" method=\"post\"><input maxlength=\"100\" type=\"text\" name=\"search_word\" value=\"".$_POST['search_word']."\" size=\"25\"> <input type=\"submit\" title=\""._SEARCH."\" value=\""._SEARCH."\"></form>"
	."[ <a href=\"index.php?name=Files\" title=\""._MHOME."\">"._MHOME."</a> | <a href=\"index.php?name=Files&new\" title=\""._NEW_FILES."\">"._NEW_FILES."</a> | <a href=\"index.php?name=Files&hits\" title=\""._POP_FILES."\">"._POP_FILES."</a>";
	if ((is_user($user) && $addfiles == 1) || (!is_user($user) && $addquest == 1)) echo " | <a href=\"index.php?name=Files&op=add_file\" title=\""._ADDFILE."\">"._ADDFILE."</a>";
	echo " ]</center>";
	CloseTable();
}

function categories($id="") {
	global $prefix, $db, $module_name, $tabcolumn, $showsubkat;
	static $massiv, $massiv2;
	$id = (intval($id)) ? $id : 0;
	$where = ($id) ? "WHERE parentid = '$id'" : "";
	$tdwidth = intval(100/$tabcolumn);
	if (!is_array($massiv)) {
		$result = $db->sql_query("SELECT cid, title, parentid FROM ".$prefix."_files_categories ".$where."");
		while (list($cid, $title, $parentid) = $db->sql_fetchrow($result)) $massiv[] = array($cid, $title, $parentid);
	}
	if (!is_array($massiv2)) {
		$result = $db->sql_query("SELECT cid, title, parentid FROM ".$prefix."_files_categories");
		while (list($cid, $title, $parentid) = $db->sql_fetchrow($result)) $massiv2[] = array($cid, $title, $parentid);
	}
	if ($massiv) {
		foreach ($massiv as $key => $val) {
			if ($val[2] == $id) {
				$ccontent .= "<td valign=\"top\" width=\"".$tdwidth."%\"><table border=\"0\"><tr><td><img border=\"0\" src=\"images/blocks/Files.gif\" title=\"$title\"></td><td><a href=\"index.php?name=$module_name&op=cat&id=$val[0]\" title=\"$val[1]\"><b>$val[1]</b></a></td></tr>";
				if ($showsubkat == 1 && $massiv2) {
					foreach ($massiv2 as $key => $val2) {
						if ($val[0] == $val2[2]) {
							$ccontent .= "<tr><td colspan=\"2\"><img border=\"0\" src=\"images/navi.gif\" title=\"$val2[1]\"> <a href=\"index.php?name=$module_name&op=cat&id=$val2[0]\" title=\"$val2[1]\">$val2[1]</a></td></tr>";
						}
					}
				}
				$ccontent .= "</table></td>";
				if ($cont == ($tabcolumn - 1)) {
					$ccontent .= "</tr><tr>";
					$cont = 0;
				} else {
					$cont++;
				}
			}
		}
	}
	if ($ccontent) {
		OpenTable();
		echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"10\" align=\"center\"><tr>".$ccontent."</td></tr></table>";
		list($files_num) = $db->sql_fetchrow($db->sql_query("SELECT Count(lid) FROM ".$prefix."_files WHERE status !='0'"));
		list($cat_num) = $db->sql_fetchrow($db->sql_query("SELECT Count(cid) FROM ".$prefix."_files_categories"));
		echo "<hr><center>"._ALLFILES.": <b>$files_num</b> "._INF." <b>$cat_num</b> "._ALLFILES2."</center>";
		CloseTable();
	}
}

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

function getit() {
    global $prefix, $db, $module_name, $downfiles;
	$lid = intval($_POST['lid']);
    if (($lid && is_user($user)) || ($lid && $downfiles == "1")) {
		$db->sql_query("UPDATE ".$prefix."_files set hits=hits+1 WHERE lid=$lid");
		list($f_title, $url) = $db->sql_fetchrow($db->sql_query("SELECT title, url FROM ".$prefix."_files WHERE lid='$lid'"));
		update_points(15);
		head();
		menu();
		OpenTable();
		echo "<center>"._NOTEDOWNLOAD." <b>$f_title</b> "._NOTEDOWNLOAD2."<br><br>";
		echo "<b><a href=\"$url\" target=\"_blank\">$url</a></b><br><br>";
		CloseTable();
		get_page($module_name);
		foot();
	} else {
		Header("Location: index.php?name=$module_name");
		exit;
	}
}

function mainfiles() {
    global $prefix, $db, $admin, $module_name, $tabcolumn, $showsubkat, $numsubkat, $admin_file, $pagetitle, $defis, $filenum, $fidirectory, $figdactive, $figdwidth;
	$pagetitle = "$defis "._FILES."";
    head();
	menu();
	categories();
	$filenum = intval($filenum);
	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 = "cid = '0' AND status !='0' ORDER BY lid DESC";
		$file_logo = ""._MHOME."";
	}
	$result3 = $db->sql_query("SELECT lid, title, description, img, UNIX_TIMESTAMP(date) as formatted, votes, totalvotes, totalcomments, hits FROM ".$prefix."_files WHERE ".$order."");
	if ($db->sql_numrows($result3) > 0) {
		OpenTable();
		echo "<center><font class=\"option\"><b>".$file_logo."</b></font><hr><br />";
		while (list($lid, $f_title, $description, $f_img, $formatted, $votes, $totalvotes, $comment, $hits) = $db->sql_fetchrow($result3)) {
			$fp_data = date("d.m.Y", $formatted);
			if ($f_img) {
				$img = ($figdactive) ? create_img($fidirectory, $f_img, $figdwidth) : $f_img;
				$zimg = "<script language=\"JavaScript\" type=\"text/javascript\" src=\"javascripts/ShowPic.js\"></script><img border=\"0\" src=\"images/blocks/Album.gif\" style=\"cursor: pointer;\" OnMouseOver=\"PicDivShow('".$img."');\" OnMouseOut=\"PicDivHide();\" alt=\"".$f_title."\">";
			} else {
				$zimg = "<img border=\"0\" src=\"images/blocks/Files.gif\" alt=\"".$f_title."\">";
			}
			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>$zimg</td><td><a href=index.php?name=$module_name&op=view_file&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\">".cutstr(bb_decode($description), 250)."</td></tr>"
			."<tr class=\"bgcolor1\"><td width=\"33%\">"._FILEHITS.": $hits</td>"
			."<td width=\"33%\"><a href=index.php?name=$module_name&op=view_file&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_file&lid=$lid>"._DELETE."</a> | <a href=".$admin_file.".php?op=edit_files&lid=$lid>"._EDIT."</a> ]</td></tr>";
			}
			echo "</table><br />";
		}
		echo "</center>";
		CloseTable();
	}
	foot();
}

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);
	$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' ORDER BY lid DESC LIMIT $offset, $filenum");
    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);
			if ($f_img) {
				$img = ($figdactive) ? create_img($fidirectory, $f_img, $figdwidth) : $f_img;
				$zimg = "<script language=\"JavaScript\" type=\"text/javascript\" src=\"javascripts/ShowPic.js\"></script><img border=\"0\" src=\"images/blocks/Album.gif\" style=\"cursor: pointer;\" OnMouseOver=\"PicDivShow('".$img."');\" OnMouseOut=\"PicDivHide();\" alt=\"".$f_title."\">";
			} else {
				$zimg = "<img border=\"0\" src=\"images/blocks/Files.gif\" alt=\"".$f_title."\">";
			}
			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>$zimg</td><td><a href=index.php?name=$module_name&op=view_file&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\">".cutstr(bb_decode($description), 250)."</td></tr>"
			."<tr class=\"bgcolor1\"><td width=\"33%\">"._FILEHITS.": $hits</td>"
			."<td width=\"33%\"><a href=index.php?name=$module_name&op=view_file&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_file&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'"));
	$numpages = ceil($numstories / $filenum);
	num_page($module_name, $numstories, $numpages, $filenum, "op=cat&id=".$cid."&");
	get_page($module_name);
	foot();
}

function view_file() {
    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_file&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."");
	}
}

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);
		head();
		menu();
		$ip = getenv("REMOTE_ADDR");
		$past = time() - $file_t;
		$db->sql_query("DELETE FROM ".$prefix."_files_poolchec WHERE time < '$past'");
		$num = $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_files_poolchec WHERE lid='$lid' AND host_addr='$ip'"));
		if ($_COOKIE['Files-'.$lid.''] == $lid || $num > 0) {
			warning(""._RATENOTE."", "?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."_files_poolchec (lid, time, host_addr) VALUES ('$lid', '$ctime', '$ip')");
			$db->sql_query("UPDATE ".$prefix."_files SET votes=votes+1, totalvotes=totalvotes+$send_reiting WHERE lid='$lid'");
			update_points(16);
			warning(""._RATECOMPLECT."", "?name=$module_name&op=view_file&lid=$lid", 3, 2);
		}
		foot();
	} 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) {
		head();
		menu();
		$db->sql_query("UPDATE ".$prefix."_files SET status='2' WHERE lid='$lid'");
		warning(""._BROCNOTE."", "?name=$module_name&op=view_file&lid=$lid", 3, 2);
		foot();
	} 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;
	$pagetitle = "$defis "._FILES." $defis "._ADDFILE."";
    if ($addfiles == "1") {
		head();
		menu();
		if (is_user($user)) {
			getusrinfo($user);
			$author = $userinfo['user_name'];
			$authormail = $userinfo['user_email'];
		} 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 "<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>"._FILEAUTOR.":</td><td><input type=\"text\" name=\"author\" value=\"$author\" maxlength=\"100\" size=\"65\" style=\"width:400px\"></td></tr>"
		."<tr><td>"._FAUEMAIL.":</td><td><input type=\"text\" name=\"authormail\" value=\"$authormail\" maxlength=\"100\" size=\"65\" style=\"width:400px\"></td></tr>"
		."<tr><td>"._FTITLE.":</td><td><input type=\"text\" name=\"title\" 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."_files_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>"._FAUURL.":</td><td><input type=\"text\" name=\"authorurl\" maxlength=\"100\" value=\"http://\" size=\"65\" style=\"width:400px\"></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>"._FILELINK.":</td><td><input type=\"text\" name=\"filelink\" maxlength=\"100\" value=\"http://\" size=\"65\" style=\"width:400px\"></td></tr>"
		."<tr><td>"._IMGLINK.":</td><td><input type=\"text\" name=\"imglink\" maxlength=\"100\" value=\"http://\" size=\"65\" style=\"width:400px\"></td></tr>"
		."<tr><td>"._FILEVERSION.":</td><td><input type=\"text\" name=\"f_version\" maxlength=\"10\" size=\"65\" style=\"width:400px\"></td></tr>"
		."<tr><td>"._FILESIZE.":</td><td><input type=\"text\" name=\"file_size\" maxlength=\"10\" size=\"65\" style=\"width:400px\"></td></tr>";
		echo "<tr><td colspan=\"2\" align=\"center\"><input type=\"hidden\" name=\"op\" value=\"file_send\">"
		."<input type=\"submit\" value=\""._FADD."\"></td></tr></form></table>";
		CloseTable();
		foot();
	} else {
		Header("Location: index.php?name=$module_name");
    }
}

function file_send($title, $description, $cid, $filelink, $imglink, $author, $authormail, $authorurl, $f_version, $file_size) {
	global $prefix, $db, $path, $temp_path, $max_size, $addfiles, $module_name, $ftypefile, $stop;
	if ($addfiles == "1") {
		if ($filelink == "http://") $filelink = "";
		if ($imglink == "http://") $imglink = "";
		if ($authorurl == "http://") $authorurl = "";
		$title = text_filter($title);
		$description = text_filter($description);
		$filelink = text_filter($filelink);
		$imglink = text_filter($imglink);
		$author = text_filter($author);
		$authorurl = text_filter($authorurl);
		$f_version = text_filter($f_version);
		$cid = intval($cid);
		$ip = getenv("REMOTE_ADDR");
		checkemail($authormail);
		if (!$stop && $title && $description && $author && $f_version) {
			$filename = upload($temp_path, $ftypefile, $max_size, "Files", "", "");
			if ($filename && !$stop) {
				$file_name = "".$temp_path."/".$filename."";
				$file_size = filesize($file_name);
				$db->sql_query("INSERT INTO ".$prefix."_files (lid, cid, title, description, url, img, date, filesize, version, name, email, homepage, ip_sender, status) VALUES (NULL, '$cid', '$title', '$description', '$file_name', '$imglink', now(), '$file_size', '$f_version', '$author', '$authormail', '$authorurl', '$ip', '0')");
			} elseif ($filelink && !$stop) {
				$file_name = $filelink;
				$file_size = intval($file_size);
				$db->sql_query("INSERT INTO ".$prefix."_files (lid, cid, title, description, url, img, date, filesize, version, name, email, homepage, ip_sender, status) VALUES (NULL, '$cid', '$title', '$description', '$file_name', '$imglink', now(), '$file_size', '$f_version', '$author', '$authormail', '$authorurl', '$ip', '0')");
			} elseif ($stop) {
				$stop = $stop;
			} else {
				$stop = ""._UPLOADEROR2."";
			}
		} elseif ($stop) {
			$stop = $stop;
		} else {
			$stop = ""._UPLOADEROR."";
		}
		if (!$stop) {
			head();
			menu();
			warning(""._UPLOADFINISH."", "?name=$module_name", 5, 2);
			foot();
		} 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 "getit":
    getit();
    break;

    case "broken":
    broken();
    break;

    case "add_file":
    add_file();
    break;

    case "file_send":
    file_send($title, $description, $cid, $filelink, $imglink, $author, $authormail, $authorurl, $f_version, $file_size);
    break;

    default:
    mainfiles();
    break;
}
?>