<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
// www.bcoos.net 2006-09 1.0.2 GPL
//v1.3 www.exoops.info 2006/03 
// $Id: submit.php,v 1.2 2004/03/20 18:35:12 greyhead Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: James Knickelbein
// Author Website : http://www.journeymilwaukee.com
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //
// Passed on      : My Downloads
// New module name: My Sections
// Version        : 1.1
// Modified by    : Faisal
// Website        : < http://www.a-xoops.com >
// Email          : info@a-xoops.com
// ------------------------------------------------------------------------- //
include_once("header.php");
include_once(XOOPS_ROOT_PATH."/class/upload.class.php");
include_once(XOOPS_ROOT_PATH."/class/module.errorhandler.php");
include_once(XOOPS_ROOT_PATH."/class/xoopsform/formdhtmltextarea.php");
global $mysectionsConfig;
$eh     = new ErrorHandler();
$mytree = new XoopsTree($db->prefix("mysections_cat"), "cid", "pid");
if ( !empty($_POST['submit']) ) {
        if ( !$xoopsUser && empty($mysectionsConfig['anon_add']) ) {
                redirect_header(XOOPS_URL."/user.php", 2, _MUSTREGISTERFIRST);
                exit();
        }
if ( empty($_POST['submitter']) ) {
        if (!$xoopsUser) {
                $submitter = 0;
                } else {
                        $submitter = $xoopsUser->uid();
                }
}
if ( !empty($_POST['cid']) ) {
        $cid = intval($_POST['cid']);
        } else {
                $cid = 0;
        }
$url         = formatURL($myts->makeTboxData4Save($_POST['url']));
$homepage    = formatURL($myts->makeTboxData4Save($_POST['homepage']));
$title       = $myts->makeTboxData4Save($_POST['title']);
$titletip    = $myts->makeTboxData4Save($_POST['titletip']);
$version     = $myts->makeTboxData4Save($_POST['version']);
$platform    = $myts->makeTboxData4Save($_POST['platform']);
$description = $myts->makeTboxData4Save($_POST['filedesc']);
$size        = $_POST["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 ( ($mysectionsConfig['allow_upload'] == 1) && !empty($_FILES['download']['name']) ) {
        $upload = new Upload();
		$upload->setAllowedMimeTypes($mysectionsConfig['accepted_files']);
        $upload->setUploadPath(XOOPS_ROOT_PATH.'/modules/mysections/cache/files/', 'download');
        $upload->setDestinationFileName('download');
        $result = $upload->doUpload();
		
        if ($result) {
			$url  = $upload->HTTP_POST_FILES[$upload->uploadFieldName]['name'];
			$size = $upload->HTTP_POST_FILES[$upload->uploadFieldName]['size'];
		} else {
			$errors = $upload->getUploadErrors();
			$errorstring = "";
			$errorstring .= "<strong>::Errors occured::</strong><br />\n";
			while(list($filename,$values) = each($errors)) {
				$errorstring .= "File: " . $filename . "<br />";
				$count = count($values);
				for($i=0; $i<$count; $i++) { $errorstring .= "==>" . $values[$i] . "<br />"; }
			}
			redirect_header('submit.php', 3, $errorstring);
			exit();
		}
}
/*if ( empty($url) ) {
        $eh->show("1016");
}*/
$newid = $db->genId($db->prefix("mysections_articles")."_lid_seq");
$sql   = "
        INSERT INTO ".$db->prefix("mysections_articles")." SET
        lid=$newid,
        cid=$cid,
        title='$title',
        titletip='$titletip',
        description='$description',
        url='$url',
        homepage='$homepage',
        version='$version',
        size=$size,
        platform='$platform',
        submitter=$submitter,
        status=0,
        date=$date,
        hits=0,
        counter=0,
        rating=0,
        votes=0";
        $db->query($sql) or $eh->show("0013");
	if ($result && $mysectionsConfig['notifysubmit'] == 1) {
		$xoopsMailer =& getMailer();
		$xoopsMailer->useMail();
		$xoopsMailer->setToEmails($bcoosConfig['adminmail']);
		$xoopsMailer->setFromEmail($bcoosConfig['adminmail']);
		$xoopsMailer->setFromName($bcoosConfig['title']);
		$xoopsMailer->setSubject(_MD_NOTIFYSBJCT);
		$xoopsMailer->setBody(_MD_NOTIFYMSG);
		$xoopsMailer->send();
	}
	
        redirect_header("index.php", 2, _THANKSSUBMIT."<br />"._WHENAPPROVED."");
        exit();
} else {
        if ( !$xoopsUser && empty($mysectionsConfig['anon_add']) ) {
                redirect_header(XOOPS_URL."/user.php", 2, _MUSTREGISTERFIRST);
                exit();
        }
include_once(XOOPS_ROOT_PATH."/header.php");
OpenTable();
echo "<b>"._MI_MYSECTIONS_NAME."</b>";
if (!$xoopsUser) {
        $uid = 0;
        } else {
                $uid = $xoopsUser->uid();
        }
$disclaimer = join('', file("./cache/disclaimer.txt"));
$myts->setType('admin');
echo $myts->makeTareaData4Show($disclaimer, 1, 1, 1)."<br /><br />";
OpenTable();
?>
<h3><?php echo _ADDCONTENT;?></h3>
<form action="submit.php" method="post" enctype="multipart/form-data">
<table width="80%"><tr>
<td nowrap>*<b><?php echo _TITLE.': ';?></b></td>
<td><input type="text" class="text" name="title" size="50" maxlength="60"></td>
</tr><tr>
<td nowrap><b><?php echo _MD_FILETITLETIP;?></b></td>
<td><input type="text" class="text" name="titletip" size="50" maxlength="255"></td>
</tr><tr>
<td nowrap><b><?php echo _CATEGORY;?></b></td>
<td><?php echo $mytree->makeMySelBox("title", "title");?></td>
</tr><tr>
<td valign="top" nowrap>*<b><?php echo _DESCRIPTION.':';?></b></td>
<td>
<?php
echo _MD_PAGEBREAK;
echo "<br /><br />";
$desc = new XoopsFormDhtmlTextArea('', 'filedesc', '', 10, 50);
echo $desc->render();
?>
</td>
</tr></table><hr />
<table width="85%"><tr>
<td valign="top" nowrap><b><?php echo _DOWNLOADURL;?></b></td>
<td><input type="text" class="text" name="url" size="50" maxlength="255" value="http://">
<?php
if ($mysectionsConfig['allow_upload'] == 1) {
        $upload = new Upload();
		$upload->setMaxFileSize($mysectionsConfig['upload_limit']);
        echo "<br />";
		$upload->printFormField("download");
        echo " <b>" . $mysectionsConfig['upload_limit'] . "</b> " . _BYTES . " " . _MAX;
}
?>
</td>
</tr><tr>
<td nowrap><b><?php echo _SITEURL;?></b></td>
<td><input type="text" class="text" name="homepage" size="50" maxlength="255" value="http://"></td>
</tr><tr>
<td nowrap><b><?php echo _VERSION.': ';?></b></td>
<td><input type="text" class="text" name="version" size="10" maxlength="10"></td>
</tr><tr>
<td nowrap><b><?php echo _FILESIZE.': ';?></b></td>
<td><input type="text" class="text" name="size" size="10" maxlength="10"> <?php echo _BYTES;?></td>
</tr><tr>
<td nowrap><b><?php echo _PLATFORM.': ';?></b></td>
<td><input type="text" class="text" name="platform" size="45" maxlength="30"></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");
?>