<?php

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

 whatsnew.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');
}

if (!isset($GLOBALS["gsLanguage"])) { Header("Location: ".$GLOBALS["rootdp"]."module.php?link=".$GLOBALS["modules_home"]."/whatsnew/whatsnew.php"); }

$module_subdirectory	= 'whatsnew';
$module_language_file	= 'whatsnew';
$module_script_name	= 'whatsnew';

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"].'whatsnew/',$GLOBALS["gsLanguage"],"lang_whatsnew.php");

if (!isset($HTTP_POST_VARS["topgroupname"])) $HTTP_POST_VARS["topgroupname"] = $HTTP_GET_VARS["topgroupname"];
if (!isset($HTTP_POST_VARS["groupname"])) $HTTP_POST_VARS["groupname"] = $HTTP_GET_VARS["groupname"];
if (!isset($HTTP_POST_VARS["subgroupname"])) $HTTP_POST_VARS["subgroupname"] = $HTTP_GET_VARS["subgroupname"];

$SAVE_VARS["topgroupname"] = $HTTP_GET_VARS["topgroupname"];
$SAVE_VARS["groupname"] = $HTTP_GET_VARS["groupname"];
$SAVE_VARS["subgroupname"] = $HTTP_GET_VARS["subgroupname"];


define('include_new',0);
define('include_updated',1);
define('include_expired',2);


if (!$HTTP_POST_VARS["Submit"]) {
	// Set a few default values
	$HTTP_POST_VARS["include_array"] = array(include_new,include_updated);
	$HTTP_POST_VARS["number"] = 1;
	$HTTP_POST_VARS["period"] = "d";
}

SubFormHeader('WhatsNew');
?>
<table border="1" cellpadding="1" cellspacing="0" align="center" valign="top" width="100%" class="headercontent">
	<tr><td class="header"><?php echo $GLOBALS["module_title"]; ?></td>
	</tr>
	<tr><td class="tablecontent">
			<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr><td width="25%" align="<?php echo $GLOBALS["right"]; ?>" valign="top"><b><?php echo $GLOBALS["whats_New"]; ?>:</b>&nbsp;</td>
					<td width="25%" valign="top"><input type="checkbox" name="include_array[]" value="<?php echo include_new; ?>"<?php if ((isset($HTTP_POST_VARS["include_array"])) && (in_array(include_new, $HTTP_POST_VARS["include_array"]))) echo " checked"; ?>></td>
					<td width="25%" align="<?php echo $GLOBALS["right"]; ?>" valign="middle"><b><?php echo $GLOBALS["whatsnew_period"]; ?>:</b>&nbsp;</td>
					<td width="25%" valign="top">
						<select name="number">
							<option value="1"<?php if ($HTTP_POST_VARS["number"] == 1) echo " selected"; ?>>1</option>
							<option value="2"<?php if ($HTTP_POST_VARS["number"] == 2) echo " selected"; ?>>2</option>
							<option value="3"<?php if ($HTTP_POST_VARS["number"] == 3) echo " selected"; ?>>3</option>
							<option value="4"<?php if ($HTTP_POST_VARS["number"] == 4) echo " selected"; ?>>4</option>
							<option value="5"<?php if ($HTTP_POST_VARS["number"] == 5) echo " selected"; ?>>5</option>
							<option value="6"<?php if ($HTTP_POST_VARS["number"] == 6) echo " selected"; ?>>6</option>
							<option value="7"<?php if ($HTTP_POST_VARS["number"] == 7) echo " selected"; ?>>7</option>
						</select>
						&nbsp;&nbsp;
						<select name="period">
							<option value="d"<?php if ($HTTP_POST_VARS["period"] == "d") echo " selected"; ?>><?php echo $GLOBALS["whatsnew_days"]; ?></option>
							<option value="w"<?php if ($HTTP_POST_VARS["period"] == "w") echo " selected"; ?>><?php echo $GLOBALS["whatsnew_weeks"]; ?></option>
							<option value="m"<?php if ($HTTP_POST_VARS["period"] == "m") echo " selected"; ?>><?php echo $GLOBALS["whatsnew_months"]; ?></option>
						</select>
					</td>
				</tr>
				<tr><td width="25%" align="<?php echo $GLOBALS["right"]; ?>" valign="top"><b><?php echo $GLOBALS["whats_Updated"]; ?>:</b>&nbsp;</td>
					<td width="75%" colspan=3 valign="top"><input type="checkbox" name="include_array[]" value="<?php echo include_updated; ?>"<?php if ((isset($HTTP_POST_VARS["include_array"])) && (in_array(include_updated, $HTTP_POST_VARS["include_array"]))) echo " checked"; ?>></td>
				</tr>
				<tr><td width="25%" align="<?php echo $GLOBALS["right"]; ?>" valign="top"><b><?php echo $GLOBALS["whats_Expired"]; ?>:</b>&nbsp;</td>
					<td width="75%" colspan=3 valign="top"><input type="checkbox" name="include_array[]" value="<?php echo include_expired; ?>"<?php if ((isset($HTTP_POST_VARS["include_array"])) && (in_array(include_expired, $HTTP_POST_VARS["include_array"]))) echo " checked"; ?>></td>
				</tr>
			</table>
		</td>
	</tr>
	<tr><td class="header"><input type="Submit" name="Submit" value="<?php echo $GLOBALS["whatsnew_button"]; ?>"></td>
	</tr>
</table>
<?php
SubFormFooter();


$strQuery = "SELECT * FROM ".$GLOBALS["eztbContents"]." WHERE ";

$timenow = time();
$isodate = strftime("%Y-%m-%d",$timenow)." 00:00:00";
$whatsnewisodate = strftime("%Y-%m-%d",DateSub($HTTP_POST_VARS["period"],$HTTP_POST_VARS["number"],$timenow))." 00:00:00";

$newquery = "(publishdate >= '$whatsnewisodate')";
$updatedquery = "(updatedate >= '$whatsnewisodate')";
$expiredquery = "((expiredate >= '$whatsnewisodate') AND (expiredate <= '$isodate'))";

$whereset = false;
if (isset($HTTP_POST_VARS["include_array"])) {
	$strQuery .= '(';
	if (in_array(include_new, $HTTP_POST_VARS["include_array"])) {
		$strQuery .= "$newquery";
		$whereset = true;
	}
	if (in_array(include_updated, $HTTP_POST_VARS["include_array"])) {
		if ($whereset) { $strQuery .= " OR "; }
		$strQuery .= $updatedquery;
		$whereset = true;
	}
	if (in_array(include_expired, $HTTP_POST_VARS["include_array"])) {
		if ($whereset) { $strQuery .= " OR "; }
		$strQuery .= $expiredquery;
		$whereset = true;
	}
	$strQuery .= ") AND contentactive='1'";
}

if ($whereset == false) {
	?>
	<table border="1" cellpadding="1" cellspacing="0" align="center" valign="top" width="100%" class="headercontent">
		<tr><td class="tablecontent">&nbsp;<br /><?php echo $GLOBALS["eEnterWhatsnew"]; ?><br />&nbsp;</td>
		</tr>
	</table>
	<?php
	if (($GLOBALS["gsUseFrames"] == 'Y') && ($EZ_SESSION_VARS["noframesbrowser"] != True)) {
		?>
		</body>
		</html>
		<?php
	} else {
		?>
		</td></tr>
		</table>
		<?php
	}
	exit;
}

if ($GLOBALS["gsLanguage"] == $GLOBALS["gsDefault_language"]) { $strQuery .= " AND language='".$GLOBALS["gsLanguage"]."' ORDER BY contentname";
} else {
	$lOrder = '';
	if ($GLOBALS["gsLanguage"] > $GLOBALS["gsDefault_language"]) { $lOrder = ' DESC'; }
	$strQuery .= " AND (language='".$GLOBALS["gsLanguage"]."' OR language='".$GLOBALS["gsDefault_language"]."') ORDER BY contentname,language".$lOrder;
}


?>
<center>
<?php
$result = dbRetrieve($strQuery,true,0,0);
$results_found = dbRowsReturned($result);
$results_displayed = 0;
if ($results_found != 0) {
	$iNew     = lsimagehtmltag($GLOBALS["modules_home"].$module_subdirectory.'/','new.gif',$GLOBALS["gsLanguage"],$GLOBALS["whats_New"],0);
	$iUpdated = lsimagehtmltag($GLOBALS["modules_home"].$module_subdirectory.'/','updated.gif',$GLOBALS["gsLanguage"],$GLOBALS["whats_Updated"],0);
	$iExpired = lsimagehtmltag($GLOBALS["modules_home"].$module_subdirectory.'/','expired.gif',$GLOBALS["gsLanguage"],$GLOBALS["whats_Expired"],0);

	$nContentName = '';
	while ($rsContent = dbFetch($result)) {
		if ($rsContent["contentname"] != $nContentName) {
			if (ModArticleSecurity($nContentName,$rsContent)) {
				if ((in_array(include_updated, $HTTP_POST_VARS["include_array"])) && ($rsContent["updatedate"] >= $whatsnewisodate)) { $whatsnewstat = 'updated'; }
				if ((in_array(include_new, $HTTP_POST_VARS["include_array"])) && ($rsContent["publishdate"] >= $whatsnewisodate)) { $whatsnewstat = 'new'; }
				if ((in_array(include_expired, $HTTP_POST_VARS["include_array"])) && ($rsContent["expiredate"] >= $whatsnewisodate) && ($rsContent["expiredate"] <= '$isodate')) { $whatsnewstat = 'expired'; }
				switch ($whatsnewstat) {
					case 'new'     : $rsContent["title"] = $iNew.'&nbsp;&nbsp;'.$rsContent["title"];
									 break;
					case 'updated' : $rsContent["title"] = $iUpdated.'&nbsp;&nbsp;'.$rsContent["title"];
									 break;
					case 'expired' : $rsContent["title"] = $iExpired.'&nbsp;&nbsp;'.$rsContent["title"];
									 break;
				}
				ShowArticle($rsContent);
				$results_displayed++;
			}
			$nContentName = $rsContent["contentname"];
		}
	} // end while
} // if ($results_found != 0)


if ($results_displayed == 0) {
	?>
	<table border="1" cellpadding="1" cellspacing="0" align="center" valign="top" width="100%" class="headercontent">
		<tr><td class="tablecontent">&nbsp;<br /><?php echo $GLOBALS["eNoResults"]; ?><br />&nbsp;</td></tr>
	</table>
	<?php
} // if ($results_displayed == 0)
?>
</center>
<?php

dbFreeResult($result);

$HTTP_GET_VARS["topgroupname"] = $SAVE_VARS["topgroupname"];
$HTTP_GET_VARS["groupname"] = $SAVE_VARS["groupname"];
$HTTP_GET_VARS["subgroupname"] = $SAVE_VARS["subgroupname"];

?>
