<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
// www.bcoos.net 2006-09 1.0.2 GPL
//v1.5 www.exoops.info 2006/03 
// $Id: submit.php,v 1.4 2003/02/28 06:02:38 half-dead Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: James Knickelbein
// Author Website : http://www.journeymilwaukee.com
// Licence Type   : GPL
// ------------------------------------------------------------------------- //
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 $_POST,$_FILES;
$eh     = new ErrorHandler();
$mytree = new XoopsTree($db->prefix("adresses_cat"), "cid", "pid");
if ( !empty($_POST['submit']) ) {
	if ( !$xoopsUser && empty($adressesConfig['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']);
$adres       = $myts->makeTboxData4Save($_POST['adres']);
$zip         = $myts->makeTboxData4Save($_POST['zip']);
$city        = $myts->makeTboxData4Save($_POST['city']);
$country     = $myts->makeTboxData4Save($_POST['country']);
$phone       = $myts->makeTboxData4Save($_POST['phone']);
$mobile      = $myts->makeTboxData4Save($_POST['mobile']);
$fax         = $myts->makeTboxData4Save($_POST['fax']);
$email       = $myts->makeTboxData4Save($_POST['email']);
$opentime    = $myts->makeTboxData4Save($_POST['opentime']);
$description = $myts->makeTboxData4Save($_POST['filedesc']);
$banner      = $myts->makeTboxData4Save($_POST['banner']);
$logourl     = formatURL($myts->makeTboxData4Save($_POST['logourl']));
$date        = time();
// Check if Title exist
if ( empty($title) ) {
	$eh->show("2001");
}
// Check if Adres exist
if ( empty($adres) ) {
	$eh->show("1004");
}
// Check if City exist
if ( empty($city) ) {
	$eh->show("1005");
}
// Check if Zip exist
if ( empty($zip) ) {
	$eh->show("1007");
}
// Check if Country exist
if ( empty($country) ) {
	$eh->show("2002");
}
// Check if Description exist
if ( empty($description) ) {
	$eh->show("1008");
}
$sql = "SELECT lid FROM `".$db->prefix("adresses_adresses")."` ORDER BY lid DESC LIMIT 1";
$queryid = $db->query($sql) or $eh->show("0013");
	if ($db->getRowsNum($queryid) == 0 ) {
		$newid = 1;
	} else {
		$newid =  $db->result($queryid,0);
		$newid++;
	}
		
if ( ($adressesConfig['allow_upload'] == 1) && !empty($_FILES['image']['name']) ) {
	$upload = new Upload();
	$upload->setUploadPath(XOOPS_ROOT_PATH.'/modules/adresses/cache/shots');
	$upload->setAllowedMimeTypes(".gif|.jpeg|.jpg|.png");
	$upload->setDestinationFileName("image");
	$upload->setFileName($newid);
	$result = $upload->doUpload();
	
	if ($result == true) {
		$logourl = $upload->FileName.".".$upload->getFileExtension();
		$banner = $upload->FileName.".".$upload->getFileExtension();
	} 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();
	}
}
//* Uitgeschakeld *//
if ( empty($url) ) { $url = $homepage; }
$sql   = "
	INSERT INTO ".$db->prefix("adresses_adresses")." SET
	lid=$newid,
	cid=$cid,
	title='$title',
	description='$description',
	url='$url',
	homepage='$homepage',
	adres='$adres',
	zip='$zip',
	city='$city',
	country='$country',
	phone='$phone',
	mobile='$mobile',
	fax='$fax',
	email='$email',
	opentime='$opentime',
	banner='$banner',
	logourl='$logourl',
	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 />"._WHENAPPROVED."");
	exit();
} else {
	if ( !$xoopsUser && empty($adressesConfig['anon_add']) ) {
		redirect_header(XOOPS_URL."/user.php", 2, _MUSTREGISTERFIRST);
		exit();
	}
include_once(XOOPS_ROOT_PATH."/header.php");
OpenTable();
echo "<b>"._MI_MYADRESSES_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 align="right" nowrap>*<b><?php echo _MD_ADRESSTITLE;?></b></td>
<td><input type="text" class="text" name="title" size="60" maxlength="100"></td>
</tr><!--<tr>
<td align="right" valign="top" nowrap>*<b><?php echo _DOWNLOADURL;?></b></td>
<td><input type="text" class="text" name="url" size="50" maxlength="255" value="http://">
</td>
</tr> --><tr>
<td align="right" nowrap><b><?php echo _CATEGORY;?></b></td>
<td><?php echo $mytree->makeMySelBox("title", "title");?></td>
</tr><tr>
<td align="right" nowrap><b>*<?php echo _MD_ADRESC;?></b></td>
<td><input type="text" class="text" name="adres" size="60" maxlength="100"></td>
</tr><tr>
<td align="right" nowrap><b>*<?php echo _MD_ZIPC;?></b></td>
<td><input type="text" class="text" name="zip" size="15" maxlength="15"></td>
</tr><tr>
<td align="right" nowrap><b>*<?php echo _MD_CITYC;?></b></td>
<td><input type="text" class="text" name="city" size="60" maxlength="80"></td>
</tr><tr>
<td align="right" nowrap><b>*<?php echo _MD_COUNTRYC;?></b></td>
<td><input type="text" class="text" name="country" size="60" maxlength="80"></td>
</tr><tr>
<td align="right" nowrap><b><?php echo _MD_PHONEC;?></b></td>
<td><input type="text" class="text" name="phone" size="40" maxlength="50"></td>
</tr><tr>
<td align="right" nowrap><b><?php echo _MD_MOBILEC;?></b></td>
<td><input type="text" class="text" name="mobile" size="40" maxlength="50"></td>
</tr><tr>
<td align="right" nowrap><b><?php echo _MD_FAXC;?></b></td>
<td><input type="text" class="text" name="fax" size="40" maxlength="50"></td>
</tr><tr>
<td align="right" nowrap><b><?php echo _EMAIL.':';?></b></td>
<td><input type="text" class="text" name="email" size="60" maxlength="80"></td>
</tr><tr>
<td align="right" 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 colspan="2">&nbsp;</td>
</tr><tr>
<td align="right" Valign="top" nowrap><b><?php echo _MD_OPENTIMEC;?></b></td>
<td><textarea cols="40" rows="4" class="text" name="opentime"></textarea></td>
</tr><tr>
<td align="right" valign="top" nowrap>*<b><?php echo _DESCRIPTION.':';?></b></td>
<td>
<?php
$desc = new XoopsFormDhtmlTextArea('', 'filedesc', '', 10, 50);
echo $desc->render();
?>
</td>
</tr><tr>
<td align="right" nowrap><b><?php echo _MD_SHOTIMAGEC;?></b></td>
<td><input type="text" class="text" name="logourl" size="60" maxlength="255" value="http://"></td>
</tr><tr>
<td>&nbsp;</td>
<td><?php echo _MD_SHOTSUBMIT;?></td>
</tr><tr>
<td align="right" nowrap><b><?php echo _MD_BANNERC;?></b></td>
<td>
<?php
$upload = new Upload();
$upload->printFormField("image");
?>
</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");
?>
