<?php
// $Id: modfile.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) {
		redirect_header(XOOPS_URL."/user.php", 2, _MD_MUSTREGFIRST);
		exit();
		} else {
			$modifysubmitter = $xoopsUser->uid();
		}

$lid         = intval($HTTP_POST_VARS["lid"]);
$cid         = intval($HTTP_POST_VARS["cid"]);
$homepage    = formatURL($myts->makeTboxData4Save($HTTP_POST_VARS["homepage"]));
$url         = $myts->makeTboxData4Save($HTTP_POST_VARS["url"]);
$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"];

// 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("modfile.php?lid=$lid", 3, $upload->errors());
			exit();
		}
}

// Check if URL exist
if ( empty($url) ) {
	$eh->show("1016");
}

$newid = $db->genId($db->prefix("mydownloads_mod")."_requestid_seq");
$sql   = "
	INSERT INTO
	".$db->prefix("mydownloads_mod")."
	SET
	requestid=$newid,
	lid=$lid,
	cid=$cid,
	title='$title',
	url='$url',
	homepage='$homepage',
	version='$version',
	size='$size',
	platform='$platform',
	description='$description',
	modifysubmitter=$modifysubmitter";

$db->query($sql) or $eh->show("0013");
redirect_header("index.php", 2, _MD_THANKSFORINFO);
exit();

} else {
$lid = intval($HTTP_GET_VARS['lid']);

if (!$xoopsUser) {
	redirect_header(XOOPS_URL."/user.php", 2, _MD_MUSTREGFIRST);
	exit();
}

include_once(XOOPS_ROOT_PATH."/header.php");
OpenTable();
mainheader();
echo "<table width='80%' align='center'>"._MD_REQUESTMOD."<br /><br />";

$result = $db->query("SELECT cid, title, description, url, homepage, version, size, platform, submitter FROM ".$db->prefix("mydownloads_downloads")." WHERE lid=".$lid." AND status>0");
list($cid, $title, $description, $url, $homepage, $version, $size, $platform, $submitter) = $db->fetch_row($result);
$title       = $myts->makeTboxData4Edit($title);
$url         = $myts->makeTboxData4Edit($url);
$homepage    = $myts->makeTboxData4Edit($homepage);
$version     = $myts->makeTboxData4Edit($version);
$size        = $myts->makeTboxData4Edit($size);
$platform    = $myts->makeTboxData4Edit($platform);
$description = $myts->makeTboxData4Edit($description);

?>
<form action="modfile.php" method="post">
<table width="80%"><tr>
<td align="right"><b><?php echo _MD_FILEID;?></b></td>
<td><?php echo $lid;?></td>
</tr><tr>
<td align="right"><b><?php echo _MD_FILETITLE;?></b></td>
<td><input type="text" class="text" name="title" size="50" maxlength="100" value="<?php echo $title;?>" /></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="<?php echo $url;?>" />
<?php
if ( (($xoopsUser->uid() == $submitter) || $xoopsUser->isAdmin($xoopsModule->mid())) && ($mydownloadsConfig['allow_upload'] == 1) ) {
	$upload = new fileupload();
	$upload->set_max_file_size($mydownloadsConfig['upload_limit'], 'download');
	echo "<br />";
	$upload->render(1, 'download');
}
?>
</td>
</tr><tr>
<td align="right"><b><?php echo _MD_CATEGORYC;?></b></td>
<td><?php $mytree->makeMySelBox("title", "title", $cid);?></td>
</tr><tr>
<td align="right"><b><?php echo _MD_SITEURL;?></b></td>
<td><input type="text" class="text" name="homepage" size="50" maxlength="255" value="<?php echo $homepage;?>" /></td>
</tr><tr>
<td align="right"><b><?php echo _MD_VERSIONC;?></b></td>
<td><input type="text" class="text" name="version" size="10" maxlength="10" value="<?php echo $version;?>" /></td>
</tr><tr>
<td align="right"><b><?php echo _MD_FILESIZEC;?></b></td>
<td><input type="text" class="text" name="size" size="10" maxlength="8" value="<?php echo $size;?>" /> <?php echo _BYTES;?></td>
</tr><tr>
<td align="right"><b><?php echo _MD_PLATFORMC;?></b></td>
<td><input type="text" class="text" name="platform" size="45" maxlength="50" value="<?php echo $platform;?>" /></td>
</tr><tr>
<td align="right" valign="top"><b><?php echo _MD_DESCRIPTIONC;?></b></td>
<td>
<?php
$desc = new XoopsFormDhtmlTextArea('', 'filedesc', $description, 10, 50);
echo $desc->render();
?>
</td>
</tr><tr>
<td colspan="2" align="center"><br />
<input type="hidden" name="lid" value="<?php echo $lid;?>" />
<input name="submit" class="button" type="submit" value="<?php echo _SUBMIT;?>" />
<input type="button" class="button" value="<?php echo _CANCEL;?>" onclick="javascript:history.go(-1)" />
</form></td></tr></table>
<?php

CloseTable();
}

include_once("footer.php");
?>
