<?php
// $Id: submit.php,v 1.1 2004/07/11 10:28:18 Farsus Exp $
// -------------------------------------------------------------------------//
//			                 RUNCMS                                         //
//                                                                          //
//	 reliable - Unique - Nocost &  Simplicity & ease off use                //
//                       < http://www.runcms.org >                          //
// -------------------------------------------------------------------------//
// Original Author: James Knickelbein
// Author Website : http://www.journeymilwaukee.com
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //

include_once("header.php");
include_once(XOOPS_ROOT_PATH."/class/fileupload.php");
include_once(XOOPS_ROOT_PATH."/class/module.errorhandler.php");
include_once(XOOPS_ROOT_PATH."/class/xoopsform/formdhtmltextarea.php");

$eh     = new ErrorHandler();
$mytree = new XoopsTree($db->prefix("mydownloads_cat"), "cid", "pid");

if ( !empty($HTTP_POST_VARS['submit']) ) {
	if ( !$xoopsUser && empty($mydownloadsConfig['anon_add']) ) {
		redirect_header(XOOPS_URL."/user.php", 2, _MD_MUSTREGFIRST);
		exit();
	}

if ( empty($HTTP_POST_VARS['submitter']) ) {
	if (!$xoopsUser) {
		$submitter = 0;
		} else {
			$submitter = $xoopsUser->uid();
		}
}

if ( !empty($HTTP_POST_VARS['cid']) ) {
	$cid = intval($HTTP_POST_VARS['cid']);
	} else {
		$cid = 0;
	}

$url         = formatURL($myts->makeTboxData4Save($HTTP_POST_VARS['url']));
$homepage    = formatURL($myts->makeTboxData4Save($HTTP_POST_VARS['homepage']));
$title       = $myts->makeTboxData4Save($HTTP_POST_VARS['title']);
$version     = $myts->makeTboxData4Save($HTTP_POST_VARS['version']);
$platform    = $myts->makeTboxData4Save($HTTP_POST_VARS['platform']);
$description = $myts->makeTboxData4Save($HTTP_POST_VARS['filedesc']);
$size        = $HTTP_POST_VARS["size"];
$date        = time();

// Check if Title exist
if ( empty($title) ) {
	$eh->show("1001");
}

// Check if Description exist
if ( empty($description) ) {
	$eh->show("1008");
}

if ( empty($size) || !is_numeric($size) ) {
	$size = 0;
}

if ( ($mydownloadsConfig['allow_upload'] == 1) && !empty($HTTP_POST_FILES['download']['name']) ) {
	$upload = new fileupload();
	$upload->set_upload_dir('./cache/files/', 'download');
	$upload->set_accepted($mydownloadsConfig['accepted_files'], 'download');
	$upload->set_overwrite(1, 'download');
	$result = $upload->upload();
	if ($result['download']['filename']) {
		$url  = $result['download']['filename'];
		$size = $result['download']['size'];
		} else {
			redirect_header('submit.php', 3, $upload->errors());
			exit();
		}
}

if ( empty($url) ) {
	$eh->show("1016");
}

$newid = $db->genId($db->prefix("mydownloads_downloads")."_lid_seq");
$sql   = "
	INSERT INTO ".$db->prefix("mydownloads_downloads")." SET
	lid=$newid,
	cid=$cid,
	title='$title',
	description='$description',
	url='$url',
	homepage='$homepage',
	version='$version',
	size=$size,
	platform='$platform',
	submitter=$submitter,
	status=0,
	date=$date,
	hits=0,
	rating=0,
	votes=0";

	$db->query($sql) or $eh->show("0013");
	redirect_header("index.php", 2, _MD_RECEIVED."<br />"._MD_WHENAPPROVED."");
	exit();

} else {
	if ( !$xoopsUser && empty($mydownloadsConfig['anon_add']) ) {
		redirect_header(XOOPS_URL."/user.php", 2, _MD_MUSTREGFIRST);
		exit();
	}

include_once(XOOPS_ROOT_PATH."/header.php");

OpenTable();
mainheader();

if (!$xoopsUser) {
	$uid = 0;
	} else {
		$uid = $xoopsUser->uid();
	}

$disclaimer = join('', file("./cache/disclaimer.php"));
$myts->setType('admin');
echo $myts->makeTareaData4Show($disclaimer, 1, 1, 1)."<br /><br />";
OpenTable();

?>
<h3><?php echo _MD_ADDNEWFILE;?></h3>
<form action="submit.php" method="post" enctype="multipart/form-data">
<table width="80%"><tr>
<td align="right" nowrap>*<b><?php echo _MD_FILETITLE;?></b></td>
<td><input type="text" class="text" name="title" size="50" maxlength="100"></td>
</tr><tr>
<td align="right" valign="top" nowrap>*<b><?php echo _MD_DLURL;?></b></td>
<td><input type="text" class="text" name="url" size="50" maxlength="255" value="http://">
<?php
if ($mydownloadsConfig['allow_upload'] == 1) {
	$upload = new fileupload();
	$upload->set_max_file_size($mydownloadsConfig['upload_limit'], 'download');
	echo "<br />";
	$upload->render(1, 'download');
	echo " <b>" . $mydownloadsConfig['upload_limit'] . "</b> " . _BYTES . " " . _MAX;
}
?>
</td>
</tr><tr>
<td align="right" nowrap><b><?php echo _MD_CATEGORY;?></b></td>
<td><?php echo $mytree->makeMySelBox("title", "title");?></td>
</tr><tr>
<td align="right" nowrap><b><?php echo _MD_SITEURL;?></b></td>
<td><input type="text" class="text" name="homepage" size="50" maxlength="255" value="http://"></td>
</tr><tr>
<td align="right" nowrap><b><?php echo _MD_VERSIONC;?></b></td>
<td><input type="text" class="text" name="version" size="10" maxlength="10"></td>
</tr><tr>
<td align="right" nowrap><b><?php echo _MD_FILESIZEC;?></b></td>
<td><input type="text" class="text" name="size" size="10" maxlength="8"> <?php echo _BYTES;?></td>
</tr><tr>
<td align="right" nowrap><b><?php echo _MD_PLATFORMC;?></b></td>
<td><input type="text" class="text" name="platform" size="45" maxlength="50"></td>
</tr><tr>
<td align="right" valign="top" nowrap>*<b><?php echo _MD_DESCRIPTIONC;?></b></td>
<td>
<?php
$desc = new XoopsFormDhtmlTextArea('', 'filedesc', '', 10, 50);
echo $desc->render();
?>
</td>
</tr></table>
<br />
<input type="hidden" name="submitter" value="<?php echo $uid;?>">
<div align="center">
<input type="submit" class="button" name="submit" value="<?php echo _SUBMIT;?>">
<input type="button" class="button" value="<?php echo _CANCEL;?>" onclick="javascript:history.go(-1)">
</div>
</form>

<?php
CloseTable();
CloseTable();
}

include_once("footer.php");
?>
