<?php
/*---------------------------------------------------+
| PHP-Fusion 6 Content Management System
+----------------------------------------------------+
| Copyright © 2002 - 2005 Nick Jones
| http://www.php-fusion.co.uk/
+----------------------------------------------------+
| Released under the terms & conditions of v2 of the
| GNU General Public License. For details refer to
| the included gpl.txt file or visit http://gnu.org
+----------------------------------------------------*/
require_once "../../maincore.php";
require_once BASEDIR."subheader.php";
require_once ADMIN."navigation.php";

if (!checkrights("IP")) fallback("../index.php");

if (file_exists(INFUSIONS."Downloads_Submissions/locale/".$settings['locale'].".php")) {
	include INFUSIONS."Downloads_Submissions/locale/".$settings['locale'].".php";
} else {
	include INFUSIONS."Downloads_Submissions/locale/English.php";
}

if (isset ($_POST['publish_download']) && isNum($download_id)) {
	$download_title = stripinput($_POST['download_title']);
	$download_description = addslash($_POST['download_description']);
	$download_url = stripinput($_POST['download_url']);
	$download_cat = stripinput($_POST['download_cat']);
	$download_license = stripinput($_POST['download_license']);
	$download_os = stripinput($_POST['download_os']);
	$download_version = stripinput($_POST['download_version']);
	$download_filesize = stripinput($_POST['download_filesize']);
	$result = dbquery("INSERT INTO ".$db_prefix."downloads (download_title, download_description, download_url, download_cat, download_license, download_os, download_version, download_filesize, download_datestamp, download_count) VALUES ('$download_title', '$download_description', '$download_url', '$download_cat', '$download_license', '$download_os', '$download_version', '$download_filesize', '".time()."', '0')");
	$result = dbquery("DELETE FROM ".$db_prefix."downloads_submissions WHERE download_id='$download_id'");
	opentable($locale['dls121']);
	echo "<center>".$locale['dls122']."</center>\n";
	closetable();
}

if ($action == "view" && isNum($download_id)) {
opentable($locale['dls112']);
$result = dbquery("SELECT * FROM ".$db_prefix."downloads_submissions WHERE download_id='$download_id'");
$data = dbarray($result);
$result2 = dbquery("SELECT * FROM ".$db_prefix."download_cats ORDER BY download_cat_name");
if (dbrows($result2) != 0) {
	while ($data2 = dbarray($result2)) {
		$sel = ($data['download_cat'] == $data2['download_cat_id'] ? " selected" : "");
		$editlist .= "<option value='".$data2['download_cat_id']."'$sel>".$data2['download_cat_name']."</option>\n";
	}
echo "<form name='submitted_download' method='post' action='".FUSION_SELF.$aidlink."&download_id=".$data['download_id']."' onSubmit='return validateDownload(this);'>
<table align='center' cellpadding='0' cellspacing='0' width='480'>
<tr>
<td width='100' class='tbl'>".$locale['dls103']."</td>
<td class='tbl'><input type='text' name='download_title' value='".$data['download_title']."' class='textbox' style='width:380px;'></td>
</tr>
<tr>
<td width='100' class='tbl'>".$locale['dls104']."</td>
<td class='tbl'><textarea name='download_description' rows='5' class='textbox' style='width:380px;'>".$data['download_description']."</textarea></td>
</tr>
<tr>
<td width='100' class='tbl'>".$locale['dls105']."</td>
<td class='tbl'><input type='text' name='download_url' value='".$data['download_url']."' class='textbox' style='width:380px;'></td>
</tr>
<tr>
<td width='100' class='tbl'>".$locale['dls106']."</td>
<td class='tbl'><select name='download_cat' class='textbox'>$editlist</select></td>
</tr>
<tr>
<td width='100' class='tbl'>".$locale['dls107']."</td>
<td class='tbl'><input type='text' name='download_license' value='".$data['download_license']."' class='textbox' style='width:150px;'></td>
</tr>
<tr>
<td width='100' class='tbl'>".$locale['dls108']."</td>
<td class='tbl'><input type='text' name='download_os' value='".$data['download_os']."' class='textbox' style='width:150px;'></td>
</tr>
<tr>
<td width='100' class='tbl'>".$locale['dls109']."</td>
<td class='tbl'><input type='text' name='download_version' value='".$data['download_version']."' class='textbox' style='width:150px;'></td>
</tr>
<tr>
<td width='100' class='tbl'>".$locale['dls110']."</td>
<td class='tbl'><input type='text' name='download_filesize' value='".$data['download_filesize']."' class='textbox' style='width:150px;'></td>
</tr>
<tr>
<td width='100' class='tbl'>".$locale['dls113']."</td>
<td class='tbl'>".showdate("%d.%m.%y", $data['download_datestamp'])."</td>
</tr>\n";
$result3 = dbquery("SELECT user_name FROM ".$db_prefix."users WHERE user_id='".$data['download_submitted']."'");
$user = dbresult($result3, 0);
echo "<tr>
<td width='100' class='tbl'>".$locale['dls114']."</td>
<td class='tbl'><a href='../../profile.php?lookup=".$data['download_submitted']."'>$user</a></td>
</tr>
<tr>
<td align='center' colspan='2' class='tbl'><input type='submit' name='publish_download' value='".$locale['dls119']."' class='button'></td>
</tr>
</table>\n";
} else {
echo "<center><br>\n".$locale['dls128']."<br><br>\n</center>\n";
}
closetable();
}

if ($action == "publish" && isNum($download_id)) {
$result = dbquery("SELECT * FROM ".$db_prefix."downloads_submissions WHERE download_id='$download_id'");
$data = dbarray($result);
$result = dbquery("INSERT INTO ".$db_prefix."downloads (download_title, download_description, download_url, download_cat, download_license, download_os, download_version, download_filesize, download_datestamp, download_count) VALUES ('".$data['download_title']."', '".$data['download_description']."', '".$data['download_url']."', '".$data['download_cat']."', '".$data['download_license']."', '".$data['download_os']."', '".$data['download_version']."', '".$data['download_filesize']."', '".time()."', '0')");
$result = dbquery("DELETE FROM ".$db_prefix."downloads_submissions WHERE download_id='$download_id'");
	opentable($locale['dls121']);
	echo "<center>".$locale['dls122']."</center>\n";
	closetable();
}

if ($action == "remove" && isNum($download_id)) {
$result = dbquery("DELETE FROM ".$db_prefix."downloads_submissions WHERE download_id='$download_id'");
}

opentable($locale['dls100']);
$resultado = dbquery("SELECT * FROM ".$db_prefix."downloads_submissions ORDER BY download_datestamp DESC");
$rows = dbrows($resultado);
	echo "<table align='center' cellpadding='0' cellspacing='0' width='480'>\n";
	if ($rows != 0) {
		echo "<tr>
<td class='tbl2'>".$locale['dls115']."</td>
<td class='tbl2'>".$locale['dls116']."</td>
<td class='tbl2'>".$locale['dls117']."</td>
</tr>
<tr>
</tr>\n";
	}
	$i = 0;
	while ($dados = dbarray($resultado)) {
	$resultado2 = dbquery("SELECT user_name FROM ".$db_prefix."users WHERE user_id='".$dados['download_submitted']."'");
	$user = dbresult($resultado2, 0);
		echo "<tr>
<td class='".($i% 2==0?"tbl1":"tbl2")."'>".$dados['download_title']."</td>
<td class='".($i% 2==0?"tbl1":"tbl2")."'><a href='../../profile.php?lookup=".$dados['download_submitted']."'>$user</a></td>
<td class='".($i% 2==0?"tbl1":"tbl2")."'><a href='".FUSION_SELF.$aidlink."&action=view&download_id=".$dados['download_id']."'>".$locale['dls118']."</a> | <a href='".FUSION_SELF.$aidlink."&action=publish&download_id=".$dados['download_id']."'>".$locale['dls119']."</a> | <a href='".FUSION_SELF.$aidlink."&action=remove&download_id=".$dados['download_id']."'>".$locale['dls120']."</a></td>
</tr>\n";
	$i++;
	}
	echo "</table>\n";
closetable();

echo "<script type='text/javascript'>
function validateDownload(frm) {
	if (frm.download_title.value==\"\" || frm.download_description.value==\"\" || frm.download_url.value==\"\" || frm.download_license.value==\"\" || frm.download_os.value==\"\" || frm.download_version.value==\"\" || frm.download_filesize.value==\"\") {
		alert(\"".$locale['dls127']."\"); return false;
	}
}
</script>\n";

echo "</td>\n";
require_once BASEDIR."footer.php";
?>