<?php
if (!defined("MODULE_FILE")) {
	Header("Location: ../../index.php");
	exit;
}
get_lang($conf['name']);
include("config/config_files.php");

function menu($logo) {
	global $conf, $conff;
	$home = "<a href=\"index.php?name=".$conf['name']."\" title=\""._HOME."\">"._HOME."</a>";
	$best = ($conff['rate']) ? "<a href=\"index.php?name=".$conf['name']."&best=1\" title=\""._BEST."\">"._BEST."</a>" : "";
	$pop = ($conff['rate']) ? "<a href=\"index.php?name=".$conf['name']."&hits=1\" title=\""._POP."\">"._POP."</a>" : "";
	$liste = "<a href=\"index.php?name=".$conf['name']."&op=liste\" title=\""._LIST."\">"._LIST."</a>";
	$add = ((is_user() && $conff['addfiles'] == 1) || (!is_user() && $conff['addquest'] == 1)) ? "<a href=\"index.php?name=".$conf['name']."&op=add\" title=\""._ADD."\">"._ADD."</a>" : "";
	$navi = "[ <a href=\"index.php?name=".$conf['name']."\" title=\""._HOME."\">"._HOME."</a>";
	$navi .= ($conff['rate']) ? " | <a href=\"index.php?name=".$conf['name']."&best=1\" title=\""._BEST."\">"._BEST."</a> | <a href=\"index.php?name=".$conf['name']."&hits=1\" title=\""._POP."\">"._POP."</a>" : "";
	$navi .= " | <a href=\"index.php?name=".$conf['name']."&op=liste\" title=\""._LIST."\">"._LIST."</a>";
	$navi .= ((is_user() && $conff['addfiles'] == 1) || (!is_user() && $conff['addquest'] == 1)) ? " | <a href=\"index.php?name=".$conf['name']."&op=add\" title=\""._ADD."\">"._ADD."</a>" : "";
	$navi .= " ]";
	search($logo, $conf['name'], $navi, $home, $best, $pop, $liste, $add);
}

function files() {
	global $prefix, $db, $admin_file, $pagetitle, $conf, $conff, $home, $currentlang;
	$lang = ($conf['multilingual']) ? "AND (c.language='$currentlang' OR c.language='')" : "";
	$filenum = intval($conff['num']);
	$fbest = (isset($_GET['best'])) ? 1 : 0;
	$fhits = (isset($_GET['hits'])) ? 1 : 0;
	$fcat = (isset($_GET['cat'])) ? $_GET['cat'] : 0;
	if ($fbest && $conff['rate']) {
		$caton = 0;
		$field = "best=1&";
		$order = "WHERE date <= now() AND status!='0' ".$lang." ORDER BY totalvotes DESC";
		$ordernum = "date <= now() AND status!='0'";
		$files_logo = ""._BEST."";
		$pagetitle = "".$conf['defis']." "._FILES." ".$conf['defis']." $files_logo";
	} elseif ($fhits && $conff['rate']) {
		$caton = 0;
		$field = "hits=1&";
		$order = "WHERE date <= now() AND status!='0' ".$lang." ORDER BY hits DESC";
		$ordernum = "date <= now() AND status!='0'";
		$files_logo = ""._POP."";
		$pagetitle = "".$conf['defis']." "._FILES." ".$conf['defis']." $files_logo";
	} elseif ($fcat) {
		$caton = 1;
		$field = "cat=$fcat&";
		list($cat_title, $cat_description) = $db->sql_fetchrow($db->sql_query("SELECT title, description FROM ".$prefix."_categories WHERE id='$fcat'"));
		$order = "WHERE cid='$fcat' AND date <= now() AND status!='0' ".$lang." ORDER BY date DESC";
		$ordernum = "cid='$fcat' AND date <= now() AND status!='0'";
		$pagetitle = "".$conf['defis']." "._FILES." ".$conf['defis']." $cat_title";
	} else {
		$caton = 1;
		$field = "";
		$order = "WHERE date <= now() AND status!='0' ".$lang." ORDER BY date DESC";
		$ordernum = "date <= now() AND status!='0'";
		$files_logo = ""._FILES."";
		$pagetitle = "".$conf['defis']." $files_logo";
	}
	head();
	if (!$home) {
		if ($fcat) {
			menu($cat_title);
		} else {
			menu($files_logo);
		}
		if ($caton == 1) categories($conf['name'], $conff['tabcol'], $conff['subkat'], $conff['catdesc'], $fcat);
	}
	$num = isset($_GET['num']) ? intval($_GET['num']) : "1";
	$offset = ($num-1) * $filenum;
	$offset = intval($offset);
	$result = $db->sql_query("SELECT f.lid, f.cid, f.title, f.description, UNIX_TIMESTAMP(f.date) as formatted, f.name, f.votes, f.totalvotes, f.totalcomments, f.hits, c.id, c.title, c.description, c.img FROM ".$prefix."_files AS f LEFT JOIN ".$prefix."_categories AS c ON (f.cid=c.id) ".$order." LIMIT $offset, $filenum");
	if ($db->sql_numrows($result) > 0) {
		while (list($id, $fcid, $f_title, $description, $formatted, $aid, $votes, $totalvotes, $comment, $hits, $cid, $ctitle, $cdescription, $cimg) = $db->sql_fetchrow($result)) {
			$fp_data = date(""._DATESTRING."", $formatted);
			$title = "<a href=\"index.php?name=".$conf['name']."&op=view&id=$id\" title=\"$f_title\">$f_title</a> ".new_graphic($formatted)."";
			$read = "<a href=\"index.php?name=".$conf['name']."&op=view&id=$id\" title=\"$f_title\">"._READMORE."</a>";
			$post = " "._POSTEDBY.": ".user_info($aid, 1)."";
			$ndate = ($conff['date']) ? " "._DATE.": ".$fp_data."" : "";
			$reads = ($conff['read']) ? " "._FILEHITS.": ".$hits."" : "";
			if ($conff['comm']) {
				if ($comment == 0) {
					$comm = " <a href=\"index.php?name=".$conf['name']."&op=view&id=$id#$id\" title=\"$f_title\">"._COMMENTS."</a>";
				} elseif ($comment == 1) {
					$comm = " <a href=\"index.php?name=".$conf['name']."&op=view&id=$id#$id\" title=\"$f_title\">"._COMMENT.": $comment</a>";
				} elseif ($comment > 1) {
					$comm = " <a href=\"index.php?name=".$conf['name']."&op=view&id=$id#$id\" title=\"$f_title\">"._COMMENTS.": $comment</a>";
				}
			}
			$arating = " ".ajax_rating(0, $id, $conf['name'], $votes, $totalvotes)."";
			$print = " ".ad_print("index.php?name=".$conf['name']."&op=printe&id=".$id."")."";
			$admin = (is_moder($conf['name'])) ? " ".ad_edit("".$admin_file.".php?op=files_add&id=".$id."")."" : "";
			$cdescription = ($cdescription) ? $cdescription : $ctitle;
			$cimg = ($cimg) ? "<a href=\"index.php?name=".$conf['name']."&cat=$cid\"><img src=\"images/categories/".$cimg."\" border=\"0\" alt=\"$cdescription\" title=\"$cdescription\" align=\"right\" hspace=\"10\" vspace=\"10\"></a>" : "";
			$link = "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"75%\" align=\"left\"><b>".$read."</b>".$post."".$ndate."".$reads."".$comm."</td><td>".$arating."</td><td align=\"right\">".$print."".$admin."</td></tr></table>";
			basic($cid, $cimg, $ctitle, $id, $title, cutstr(text_filter(bb_decode($description, $conf['name'])), 500), $link, $read, $post, $ndate, $reads, $comm, $arating, $print, $admin, $size, $vers, $down, $broc, $email, $home);
		}
		num_article($conf['name'], $filenum, $field, "lid", "_files", "cid", $ordernum);
	}
	foot();
}

function liste() {
	global $db, $prefix, $pagetitle, $conf, $conff, $currentlang;
	$lang = ($conf['multilingual']) ? "AND (c.language='$currentlang' OR c.language='')" : "";
	$listnum = intval($conff['listnum']);
	$let = (!preg_match("/[^a-zA-Zà-ÿÀ-ß0-9]/", $_GET['let'])) ? $_GET['let'] : "";
	if ($let) {
		$field = "op=liste&let=".urlencode($let)."&";
		$pagetitle = "".$conf['defis']." "._FILES." ".$conf['defis']." "._LIST." ".$conf['defis']." $let";
		$order = "WHERE UPPER(f.title) LIKE '".$let."%' AND date <= now() AND status!='0'";
	} else {
		$field = "op=liste&";
		$pagetitle = "".$conf['defis']." "._FILES." ".$conf['defis']." "._LIST."";
		$order = "WHERE date <= now() AND status!='0'";
	}
	$num = isset($_GET['num']) ? intval($_GET['num']) : "1";
	$offset = ($num-1) * $listnum;
	$offset = intval($offset);
	$result = $db->sql_query("SELECT f.lid, f.cid, f.title, f.date, f.name, c.id, c.title FROM ".$prefix."_files AS f LEFT JOIN ".$prefix."_categories AS c ON (f.cid=c.id) ".$order." ".$lang." ORDER BY date DESC LIMIT $offset, $listnum");
	head();
	menu(""._LIST."");
	if ($db->sql_numrows($result) > 0) {
		OpenTable();
		if ($conff['letter']) letter($conf['name']);
		echo "<script language=\"JavaScript\" type=\"text/javascript\" src=\"ajax/SortTable.js\"></script><table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\" class=\"sort\" id=\"sort_id\"><tr>"
		."<th>"._ID."</th><th>"._TITLE."</th><th>"._CATEGORY."</th><th>"._DATE."</th><th>"._POSTEDBY."</th></tr>";
		while (list($id, $catid, $stitle, $time, $aid, $cid, $ctitle) = $db->sql_fetchrow($result)) {
			$ctitle = (!$ctitle) ? ""._NO."" : "<a href=\"index.php?name=".$conf['name']."&cat=$cid\" title=\"".$ctitle."\">".cutstr($ctitle, 10)."</a>";
			echo "<tr class=\"bgcolor1\">"
			."<td align=\"center\">".$id."</td>"
			."<td><a href=\"index.php?name=".$conf['name']."&op=view&id=$id\" title=\"".$stitle."\">".cutstr($stitle, 50)."</a></td>"
			."<td align=\"center\">".$ctitle."</td>"
			."<td align=\"center\">".formatTimestamp($time)."</td>"
			."<td align=\"center\">".user_info($aid, 1)."</td></tr>";
		}
		echo "</table>";
		CloseTable();
		$ordernum = ($let) ? "UPPER(title) LIKE '".$let."%' AND date <= now() AND status!='0'" : "date <= now() AND status!='0'";
		num_article($conf['name'], $listnum, $field, "lid", "_files", "cid", $ordernum);
	} else {
		warning(""._NO_INFO."", "", "", 2);
	}
	foot();
}

function printe() {
	global $prefix, $db, $pagetitle, $conf;
	$id = intval($_GET['id']);
	$result = $db->sql_query("SELECT f.cid, f.title, f.url, f.description, f.date, f.filesize, f.version, f.name, f.email, f.homepage, f.votes, f.totalvotes, f.totalcomments, f.hits, c.id, c.title, c.description, c.img FROM ".$prefix."_files AS f LEFT JOIN ".$prefix."_categories AS c ON (f.cid=c.id) WHERE lid='$id' AND date <= now() AND status!='0'");
	if ($db->sql_numrows($result) == 1) {
		list($cid, $title, $url, $description, $date, $f_size, $f_version, $aid, $a_email, $a_homepage, $votes, $totalvotes, $totalcomments, $hits, $ccid, $ctitle, $cdescription, $cimg) = $db->sql_fetchrow($result);
		$ThemeSel = get_theme();
		if (file_exists("templates/$ThemeSel/index.php")) {
			require_once("templates/$ThemeSel/index.php");
		} else {
			require_once("function/template.php");
		}
		$conf['defis'] = urldecode($conf['defis']);
		$ftitle = (intval($ccid)) ? "$title ".$conf['defis']." $ctitle ".$conf['defis']." "._FILES." ".$conf['defis']." ".$conf['sitename']."" : "$title ".$conf['defis']." "._FILES." ".$conf['defis']." ".$conf['sitename']."";
		$ctitle = (!$ctitle) ? ""._NO."" : "<a href=\"index.php?name=".$conf['name']."&cat=$ccid\" title=\"".$ctitle."\">".cutstr($ctitle, 10)."</a>";
		$ptitle = "".formatTimestamp($date)." - ".$title."";
		$text .= "<table border=\"0\" width=\"100%\" cellpadding=\"3\" cellspacing=\"0\"><tr><td>"._POSTEDBY.": ".user_info($aid, 1)."</td><td>"._CATEGORY.": ".$ctitle."</td></tr>"
		."<tr><td>"._FILESIZE.": ".files_size($f_size)."</td><td>"._DATE.": ".formatTimestamp($date)."</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>".bb_decode($description, $conf['name'])."</td></tr></table>";
		$url = ""._COMESFROM.": <a href=\"".$conf['homeurl']."\" title=\"".$conf['sitename']."\">".$conf['homeurl']."</a><br />"._THEURL.": <a href=\"".$conf['homeurl']."/index.php?name=".$conf['name']."&op=view&id=$id\" title=\"".$title."\">".$conf['homeurl']."/index.php?name=".$conf['name']."&op=view&id=$id</a>";
		prints($ftitle, $ptitle, $text, $url);
	} else {
		Header("Location: index.php?name=".$conf['name']."");
	}
}

function view() {
	global $prefix, $db, $hometext, $pagetitle, $admin_file, $conf, $conff, $datetime;
	$id = intval($_GET['id']);
	$word = ($_GET['word']) ? text_filter($_GET['word']) : "";
	$result = $db->sql_query("SELECT f.cid, f.title, f.url, f.description, f.date, f.filesize, f.version, f.name, f.email, f.homepage, f.votes, f.totalvotes, f.totalcomments, f.hits, c.id, c.title, c.description, c.img FROM ".$prefix."_files AS f LEFT JOIN ".$prefix."_categories AS c ON (f.cid=c.id) WHERE lid='$id' AND date <= now() AND status!='0'");
	if ($db->sql_numrows($result) == 1) {
		list($cid, $title, $url, $description, $date, $f_size, $f_version, $aid, $a_email, $a_homepage, $votes, $totalvotes, $totalcomments, $hits, $ccid, $ctitle, $cdescription, $cimg) = $db->sql_fetchrow($result);
		$pagetitle = (intval($cid)) ? "".$conf['defis']." "._FILES." ".$conf['defis']." $ctitle ".$conf['defis']." $title" : "".$conf['defis']." "._FILES." ".$conf['defis']." $title";
		$hometext = $description;
		$ctitle = (!$ctitle) ? ""._NO."" : "<a href=\"index.php?name=".$conf['name']."&cat=$ccid\" title=\"".$ctitle."\">".cutstr($ctitle, 15)."</a>";
		head();
		menu(""._FILES."");
		$post = ""._POSTEDBY.": ".user_info($aid, 1)."";
		$ndate = ($conff['date']) ? " "._DATE.": ".formatTimestamp($date)."" : "";
		$reads = ($conff['read']) ? " "._FILEHITS.": ".$hits."" : "";
		$size = " "._FILESIZE.": ".files_size($f_size)."";
		$vers = " "._FILEVERS.": ".$f_version."";
		if (is_user() || $conff['down'] == "1") {
			$onclick = (!$conff['stream']) ? "OnClick=\"window.open('$url')\"" : "";
			$down = "<form action=\"index.php?name=".$conf['name']."\" method=\"post\" style=\"display: inline\">"
			."<input type=\"hidden\" name=\"id\" value=\"$id\">"
			."<input type=\"hidden\" name=\"op\" value=\"geturl\">"
			."<input type=\"submit\" value=\""._DOWNLFILE."\" $onclick>"
			."</form>";
		}
		$arating = " ".ajax_rating(1, $id, $conf['name'], $votes, $totalvotes)."";
		$print = " ".ad_print("index.php?name=".$conf['name']."&op=printe&id=".$id."")."";
		$broc = ($conff['broc'] == 1) ? " <a href=\"index.php?name=".$conf['name']."&op=broken&id=$id\" title=\""._BROCFILE."\"><img src=\"".find_img("warning.gif")."\" border=\"0\" align=\"center\"></a>" : "";
		$email = ($a_email) ? " "._AUEMAIL.": ".anti_spam($a_email)."" : "";
		$home = ($a_homepage) ? " "._FAUURL.": ".domain($a_homepage)."" : "";
		$admin = (is_moder($conf['name'])) ? " ".ad_edit("".$admin_file.".php?op=files_add&id=".$id."")."" : "";
		$cdescription = ($cdescription) ? $cdescription : $ctitle;
		$cimg = ($cimg) ? "<a href=\"index.php?name=".$conf['name']."&cat=$cid\"><img src=\"images/categories/".$cimg."\" border=\"0\" alt=\"$cdescription\" title=\"$cdescription\" align=\"right\" hspace=\"10\" vspace=\"10\"></a>" : "";
		$ctitle = " "._CATEGORY.": ".$ctitle."";
		$link = "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"33%\">".$arating."</td><td width=\"33%\" align=\"center\">".$down."</td><td width=\"33%\" align=\"right\">".$print."".$broc."";
		if (is_moder($conf['name']) && $a_email) $link .= " <a href=\"mailto:".$a_email."\" title=\""._AUEMAIL."\"><img src=\"".find_img("Contact.gif")."\" border=\"0\" align=\"center\"></a>";
		if ($a_homepage) $link .= " <a href=\"".$a_homepage."\" target=\"_blank\" title=\""._FAUURL."\"><img src=\"".find_img("Home.gif")."\" border=\"0\" align=\"center\"></a>";
		$link .= "".$admin."</td></tr></table>";
		basic($cid, $cimg, $ctitle, $id, search_color($title, $word), search_color(bb_decode($description, $conf['name']), $word), $link, $read, $post, $ndate, $reads, $comm, $arating, $print, $admin, $size, $vers, $down, $broc, $email, $home);
		if ($conff['comm']) {
			echo "<a name=\"$id\"></a>";
			show_com($id);
		}
		foot();
	} else {
		Header("Location: index.php?name=".$conf['name']."");
	}
}

function broken() {
	global $prefix, $db, $pagetitle, $conf, $conff;
	$pagetitle = "".$conf['defis']." "._FILES." ".$conf['defis']." "._BROCFILE."";
	$id = intval($_GET['id']);
	if ($conff['broc'] == 1 && $id) {
		head();
		menu(""._BROCFILE."");
		$db->sql_query("UPDATE ".$prefix."_files SET status='2' WHERE lid='$id'");
		warning(""._BROCNOTE."", "?name=".$conf['name']."&op=view&id=$id", 5, 2);
		foot();
	} else {
		Header("Location: index.php?name=".$conf['name']."");
	}
}

function add() {
	global $db, $prefix, $pagetitle, $conf, $conff, $confu, $stop;
	$pagetitle = "".$conf['defis']." "._FILES." ".$conf['defis']." "._ADD."";
	if ((is_user() && $conff['addfiles'] == 1) || (!is_user() && $conff['addquest'] == 1)) {
		if (is_user()) {
			$userinfo = getusrinfo();
			$author = (isset($_POST['author'])) ? $_POST['author'] : $userinfo['user_name'];
			$authormail = (isset($_POST['authormail'])) ? $_POST['authormail'] : $userinfo['user_email'];
			$authorurl = (isset($_POST['authorurl'])) ? $_POST['authorurl'] : $userinfo['user_website'];
		} else {
			$author = (isset($_POST['author'])) ? $_POST['author'] : $confu['anonym'];
			$authormail = (isset($_POST['authormail'])) ? $_POST['authormail'] : "";
			$authorurl = (isset($_POST['authorurl'])) ? $_POST['authorurl'] : "http://";
		}
		head();
		menu(""._ADD."");
		$info = ""._ADDFNOTE."";
		if ($conff['upload'] == 1) $info .= "".sprintf(""._ADDFNOTE2."", str_replace(",", ", ", $conff['typefile']), files_size($conff['max_size']))."";
		$info .= " "._ADDFNOTE3."";
		if ($stop) warning($stop, "", "", 1);
		warning($info, "", "", 2);
		if ($_POST['description']) preview($_POST['title'], $_POST['description'], "", "", $conf['name']);
		OpenTable();
		echo "<form name=\"post\" enctype=\"multipart/form-data\" action=\"index.php?name=".$conf['name']."\" method=\"post\">"
		."<div class=\"left\">"._POSTEDBY.":</div><div class=\"center\"><input type=\"text\" name=\"author\" value=\"".$author."\" maxlength=\"100\" size=\"65\" class=\"".$conf['style']."\"></div>"
		."<div class=\"left\">"._AUEMAIL.":</div><div class=\"center\"><input type=\"text\" name=\"authormail\" value=\"".$authormail."\" maxlength=\"100\" size=\"65\" class=\"".$conf['style']."\"></div>"
		."<div class=\"left\">"._FTITLE.":</div><div class=\"center\"><input type=\"text\" name=\"title\" value=\"".$_POST['title']."\" maxlength=\"100\" size=\"65\" class=\"".$conf['style']."\"></div>"
		."<div class=\"left\">"._CATEGORY.":</div><div class=\"center\"><select name=\"cid\" class=\"".$conf['style']."\">".getcat($conf['name'], $_POST['cid'])."</select></div>"
		."<div class=\"left\">"._DESCRIPTION.":</div><div class=\"center\">".textarea("1", "description", "", $conf['name'], "10")."</div>"
		."<div class=\"left\">"._FAUURL.":</div><div class=\"center\"><input type=\"text\" name=\"authorurl\" value=\"".$authorurl."\" maxlength=\"100\" size=\"65\" class=\"".$conf['style']."\"></div>";
		if ($conff['upload'] == 1) {
			echo "<div class=\"left\">"._FILE_USER.":</div><div class=\"center\"><input name=\"userfile\" type=\"file\" size=\"65\" class=\"".$conf['style']."\"></div>"
			."<div class=\"left\">"._FILE_SITE.":</div><div class=\"center\"><input type=\"text\" name=\"sitefile\" value=\"\" size=\"65\" class=\"".$conf['style']."\"></div>";
		}
		echo "<div class=\"left\">"._FILELINK.":</div><div class=\"center\"><input type=\"text\" name=\"filelink\" value=\"".$_POST['filelink']."\" maxlength=\"100\" value=\"http://\" size=\"65\" class=\"".$conf['style']."\"></div>"
		."<div class=\"left\">"._FILEVERSION.":</div><div class=\"center\"><input type=\"text\" name=\"f_version\" value=\"".$_POST['f_version']."\" maxlength=\"10\" size=\"65\" class=\"".$conf['style']."\"></div>"
		."<div class=\"left\">"._FILESIZE.":</div><div class=\"center\"><input type=\"text\" name=\"file_size\" value=\"".$_POST['file_size']."\" maxlength=\"10\" size=\"65\" class=\"".$conf['style']."\"></div>"
		."".div_captcha_random().""
		."<div class=\"button\"><select name=\"posttype\">"
		."<option value=\"preview\">"._PREVIEW."</option>"
		."<option value=\"save\">"._SEND."</option></select>"
		."<input type=\"hidden\" name=\"op\" value=\"send\">"
		." <input type=\"submit\" value=\""._OK."\"></div></form>";
		CloseTable();
		foot();
	} else {
		Header("Location: index.php?name=".$conf['name']."");
	}
}

function send() {
	global $prefix, $db, $conf, $conff, $stop;
	if ((is_user() && $conff['addfiles'] == 1) || (!is_user() && $conff['addquest'] == 1)) {
		$title = text_filter($_POST['title']);
		$description = nl2br(text_filter($_POST['description'], 2));
		$url = ($_POST['filelink'] == "http://") ? "" : text_filter($_POST['filelink']);
		$authorurl = ($_POST['authorurl'] == "http://") ? "" : text_filter($_POST['authorurl']);
		$author = text_filter($_POST['author']);
		$authormail = text_filter($_POST['authormail']);
		$f_version = text_filter($_POST['f_version']);
		$cid = intval($_POST['cid']);
		$ip = getip();
		if (!$title) $stop = ""._CERROR."";
		if (!$description) $stop = ""._CERROR1."";
		checkemail($authormail);
		if (captcha_check()) $stop = ""._SECCODEINCOR."";
		if ($db->sql_numrows($db->sql_query("SELECT title FROM ".$prefix."_files WHERE title='$title'")) > 0) $stop = ""._MEDIAEXIST."";
		$filename = upload($conff['temp'], $conff['typefile'], $conff['max_size'], "Files", "", "");
		$url = ($filename) ? "".$conff['temp']."/".$filename."" : $url;
		$filesize =  ($filename) ? filesize($url) : $filesize;
		if ($stop) {
			$stop = $stop;
		} elseif (!$url  && $_POST['posttype'] == "save") {
			$stop = ""._UPLOADEROR2."";
		}
		if (!$stop && $_POST['posttype'] == "save") {
			$db->sql_query("INSERT INTO ".$prefix."_files (lid, cid, title, description, url, date, filesize, version, name, email, homepage, ip_sender, status) VALUES (NULL, '$cid', '$title', '$description', '$url', now(), '$filesize', '$f_version', '$author', '$authormail', '$authorurl', '$ip', '0')");
			update_points(9);
			head();
			menu(""._ADD."");
			warning(""._UPLOADFINISH."", "?name=".$conf['name']."", 10, 2);
			foot();
		} else {
			add();
		}
	} else {
		Header("Location: index.php?name=".$conf['name']."");
	}
}

function geturl() {
	global $prefix, $db, $pagetitle, $conf, $conff;
	$id = intval($_POST['id']);
	if (($id && is_user()) || ($id && $conff['down'] == "1")) {
		$db->sql_query("UPDATE ".$prefix."_files SET hits=hits+1 WHERE lid=$id");
		list($f_title, $url) = $db->sql_fetchrow($db->sql_query("SELECT title, url FROM ".$prefix."_files WHERE lid='$id'"));
		update_points(11);
		if ($conff['stream'] == 2) {
			$type = strtolower(end(explode(".", $url)));
			stream($url, "".gen_pass(10).".".$type."");
		} elseif ($conff['stream'] == 1) {
			stream($url, preg_replace("/(.*?)\//i", "", $url));
		} else {
			$pagetitle = "".$conf['defis']." "._FILES." ".$conf['defis']." $f_title";
			head();
			menu(""._FILES."");
			OpenTable();
			echo "<center>"._NOTEDOWNLOAD." <b>$f_title</b> "._NOTEDOWNLOAD2."<br /><br />"
			."<b><a href=\"$url\" target=\"_blank\">$url</a></b><br /><br /></center>";
			CloseTable();
			get_page($conf['name']);
			foot();
		}
	} else {
		Header("Location: index.php?name=".$conf['name']."");
	}
}

switch($op) {
	default:
	files();
	break;

	case "liste":
	liste();
	break;

	case "printe":
	printe();
	break;

	case "view":
	view();
	break;

	case "geturl":
	geturl();
	break;

	case "broken":
	broken();
	break;

	case "add":
	add();
	break;

	case "send":
	send();
	break;

	case "save_com":
	save_com();
	break;
}
?>