<?php

/***************************************************************************

 submit_links.php
 ----------------
 copyright : (C) 2002-2003 The ezContents Development Team

 ***************************************************************************/

/***************************************************************************
 The ezContents Development Team offers no warranties on this script.
 The owner/licensee of the script is solely responsible for any problems
 caused by installation of the script or use of the script.

 All copyright notices regarding ezContents must remain intact on the
 scripts and in the HTML for the scripts.

 For more info on ezContents,
 visit http://www.ezcontents.org/

/***************************************************************************

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the License which can be found within the
 *   zipped package.
 *
 ***************************************************************************/


global $HTTP_SERVER_VARS;
if ( (substr($HTTP_SERVER_VARS["PHP_SELF"],-11) == 'control.php') ||
	 (substr($HTTP_SERVER_VARS["PHP_SELF"],-10) == 'module.php') ||
	 (substr($HTTP_SERVER_VARS["PHP_SELF"],-16) == 'showcontents.php') ) {
	 require_once('./modules/moduleSec.php');
} else {
	require_once('../moduleSec.php');
}

// Localisation variables (used for default values)
// Change these to suit your site preferences
//
$expiryperiod = 'm';			// Time period to calculate the banner expiry date (based on today's date)
$expirynumber = 1;


$GLOBALS["ModuleName"] = 'links';

include_once ($GLOBALS["language_home"].$GLOBALS["gsLanguage"]."/lang_admin.php");
include_once ($GLOBALS["language_home"].$GLOBALS["gsLanguage"]."/lang_main.php");
include_languagefile ($GLOBALS["modules_home"].$GLOBALS["ModuleName"].'/',$GLOBALS["gsLanguage"],"lang_".$GLOBALS["ModuleName"].".php");

$validentry = True;
if ($GLOBALS["scLoginRequired"] == 'Y') {
	$validentry = VerifySubmoduleLogin($GLOBALS["tSubmitLinks"]);
}


if ($validentry) {
	$timenow = time();			// Calculate the default expiry date
	$GLOBALS["DefExpDate"] = date('Y-m-d H:i:s',DateAdd($expiryperiod,$expirynumber,$timenow));

	if ($HTTP_POST_VARS["submitted"] == "yes") {
		AddLinks();
		SubModuleReturn('showlinks.php', $GLOBALS["tLinksPage"],'');
	} else {
		frmLinksForm();
	}
}


function frmLinksForm()
{
	global $EZ_SESSION_VARS, $HTTP_POST_VARS;

	SubModFormHeader();
	adminformtitle(2,$GLOBALS["tSubmitFormTitle"]);
	$GLOBALS["specialedit"] = True;

	if ($GLOBALS["scUseCategories"] == 'Y') {
		?>
		<tr class="tablecontent">
			<?php FieldHeading("Category","catcode"); ?>
			<td valign="top" class="content">
				<select name="catcode" size="1">
					<option value="0">
					<?php RenderCategories($GLOBALS["gsCatCode"]); ?>
				</select>
			</td>
		</tr>
		<?php
	} else {
		?><input type="hidden" name="catcode" value="0"><?php
	}
	?>
	<tr class="tablecontent">
		<?php FieldHeading("PublishDate","PublishDay"); ?>
		<td valign="top" class="content">
			<?php admindatedisplay('Publish',$GLOBALS["gsPublishDate"]); ?>
		</td>
	</tr>
	<tr class="tablecontent">
		<?php FieldHeading("WebURL","webURL"); ?>
		<td valign="top" class="content">
			<input type="text" name="webURL" size="50" value="<?php echo htmlspecialchars($GLOBALS["gsWeb_Page"]); ?>" maxlength=255<?php echo $GLOBALS["fieldstatus"]; ?>>
		</td>
	</tr>
	<tr class="tablecontent">
		<?php FieldHeading("Description","descr"); ?>
		<td valign="top" class="content">
			<?php
			EditButtons("Description","descr");
			?>
			<textarea rows="4" id="descr" name="descr" cols="44"<?php echo $GLOBALS["fieldstatus"]; ?>><?php echo htmlspecialchars($GLOBALS["gsDescr"]); ?></textarea>
			<?php
			admintagdisplay('descr');
			admintagdisplay2('descr');
			?>
		</td>
	</tr>
	<?php SubModFormFooter(2); ?>
	<input type="hidden" name="LinksID" value="<?php echo $HTTP_POST_VARS["LinksID"]; ?>">
	<?php modformclose($GLOBALS["tSubmitLink"]); ?>
	</td></tr></table>
	</form>
	</td></tr></table>
   <?php
} // function frmLinksForm()


function AddLinks()
{
	global $HTTP_POST_VARS;

	$publishisodate = dbDateTime(sprintf("%04d-%02d-%02d 00:00:00", $HTTP_POST_VARS["PublishYear"], $HTTP_POST_VARS["PublishMonth"], $HTTP_POST_VARS["PublishDay"]));
	$updateisodate  = dbDateTime(sprintf("%04d-%02d-%02d %02d:%02d:%02d", strftime("%Y"), strftime("%m"), strftime("%d"), strftime("%H"), strftime("%M"), strftime("%S")));
	$authorid = lGetAuthorID();

	$sWebURL  = trim($HTTP_POST_VARS["webURL"]);
	$sDescr = trim(dbString($HTTP_POST_VARS["descr"]));

	if ($GLOBALS["scValidate"] == 'Y') { $scValid = 0; } else { $scValid = 1; }
	$sCatId = $HTTP_POST_VARS["catcode"];

	$strQuery = "INSERT INTO ".$GLOBALS["scTable"]." VALUES('', '".$publishisodate."', '".$sWebURL."', '".$sDescr."', '".$scValid."', '".$authorid."', '".$updateisodate."', '".$HTTP_POST_VARS["catcode"]."')";
	$result = dbExecute($strQuery,true);
	dbCommit();
} // function AddLinks()

ModuleJavaFunctions();

?>
