<?php

// include WordPress
require_once('../../../wp-load.php');

// filter query date
function filter_where($where = '') {
	$ts = $_GET['timespan'];
	if ($ts) {
		if ($ts == 'today') $where .= " AND post_date >= '".date('Y-m-d')."'";
		if ($ts == 'week1') $where .= " AND post_date >= '".date('Y-m-d', strtotime('-1 week'))."'";
		if ($ts == 'week2') $where .= " AND post_date >= '".date('Y-m-d', strtotime('-2 weeks'))."'";
		if ($ts == 'week3') $where .= " AND post_date >= '".date('Y-m-d', strtotime('-3 weeks'))."'";
		if ($ts == 'day30') $where .= " AND post_date >= '".date('Y-m-d', strtotime('-30 days'))."'";
		if ($ts == 'day60') $where .= " AND post_date >= '".date('Y-m-d', strtotime('-60 days'))."'";
		if ($ts == 'day90') $where .= " AND post_date >= '".date('Y-m-d', strtotime('-90 days'))."'";
		if ($ts == 'year1') $where .= " AND post_date >= '".date('Y-m-d', strtotime('-1 year'))."'";
		if ($ts == 'year2') $where .= " AND post_date >= '".date('Y-m-d', strtotime('-2 years'))."'";
		return $where;
	}
}

// only process filter if $ts exists
if ($_GET['timespan']) {
	add_filter('posts_where', 'filter_where');
}

// uncomment for debugging
//echo $_SERVER['QUERY_STRING'];

?>

	<!--
	#
	#	set the query
	#
	// -->
	<?php query_posts($_SERVER['QUERY_STRING']); if (have_posts()) { ?>
	<?php dt_news_pagination(); ?>
	<table class="table_fields">
	<tr class="table_fields_top">
		<td style="width:70%"><?php _e('Story','news'); ?></td>
		<td style="width:10%"><?php _e('Views','news'); ?></td>
		<td style="width:10%"><?php _e('Comments','news'); ?></td>
		<td style="width:10%"><?php _e('Rating','news'); ?></td>
	</tr>
	<!--
	#
	#	loop thru posts
	#
	// -->
	<?php $i = 0; while (have_posts()) : the_post(); $i++; ?>
	<tr>
		<td style="text-align:left">
			<div class="story_thumb"><?php dt_thumb('width=100&height=70'); ?></div>
			<div>
				<div style="margin: 0 0 5px 0"><?php the_time('j M Y g:ia'); ?></div>
				<span style="font-weight:bold;line-height:16px;"><a href="<?php the_permalink(); ?>"><?php dt_posttype(); the_title(); ?></a></span>
			</div>
		</td>
		<td><?php dt_views_number_mode2(); ?></td>
		<td><?php comments_popup_link('0','1','%','','Off'); ?></td>
		<td><?php dt_votes_number_mode2(); ?></td>
	</tr>
	<?php dt_table_ads(); ?>
	<?php endwhile; ?>
	</table>
	<?php dt_news_pagination(); ?>
	<!--
	#
	#	end the query
	#
	// -->
	<?php } else { ?>
	<?php dt_news_pagination(); ?>
	<table class="table_fields">
	<tr class="table_fields_top">
		<td style="width:70%"><?php _e('Story','news'); ?></td>
		<td style="width:10%"><?php _e('Views','news'); ?></td>
		<td style="width:10%"><?php _e('Comments','news'); ?></td>
		<td style="width:10%"><?php _e('Rating','news'); ?></td>
	</tr>
	<tr>
		<td colspan="5"><?php _e('Please widen your criteria. Your current search returned no news to display.','news'); ?></td>
	</tr>
	<?php } ?>
	
<script type="text/javascript">
(function($) {

	$(".table_fields").corner("top 7px");

}) (jQuery);
</script>