Index: trunk/CHANGELOG
===================================================================
--- trunk/CHANGELOG	(revision 599)
+++ trunk/CHANGELOG	(revision 600)
@@ -14,6 +14,7 @@
 26-Jan-2008 Matthias Gallas
 +	Added keywords to files where they are missing
 26-Jan-2008 Thomas Hornik
++	module news: added publish_until field to control the visibility of a news-posting by date and time
 !	added strongly "condensed" fonts with many intersections for ttf-CAPTCHA as default fonts.
 	It should be very difficult for spam-bots to recognize intersected characters.
 25-Jan-2008 Christian Sommer
Index: trunk/wb/upgrade-script.php
===================================================================
--- trunk/wb/upgrade-script.php	(revision 599)
+++ trunk/wb/upgrade-script.php	(revision 600)
@@ -473,11 +473,15 @@
 //Start of upgrade script for the news modul
 //******************************************************************************
 
-echo "<BR><B>Adding new field to database table mod_news_posts</B><BR>";
+echo "<BR><B>Adding new fields to database table mod_news_posts</B><BR>";
 if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_news_posts` ADD `published_when` INT NOT NULL AFTER `commenting`")) {
 	echo 'Database Field published_when added successfully<br />';
 }
 echo mysql_error().'<br />';
+if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_news_posts` ADD `published_until` INT NOT NULL AFTER `published_when`")) {
+	echo 'Database Field published_until added successfully<br />';
+}
+echo mysql_error().'<br />';
 
 // UPDATING DATA INTO FIELDS
 echo "<BR>";
Index: trunk/wb/modules/news/search.php
===================================================================
--- trunk/wb/modules/news/search.php	(revision 599)
+++ trunk/wb/modules/news/search.php	(revision 600)
@@ -34,6 +34,7 @@
 	$result = false;
 
 	// fetch all active news-posts (from active groups) in this section.
+	$t = time();
 	$table_posts = TABLE_PREFIX."mod_news_posts";
 	$table_groups = TABLE_PREFIX."mod_news_groups";
 	$query = $func_database->query("
@@ -40,6 +41,7 @@
 		SELECT p.post_id, p.title, p.content_short, p.content_long, p.link, p.posted_when, p.posted_by
 		FROM $table_posts AS p LEFT OUTER JOIN $table_groups AS g ON p.group_id = g.group_id
 		WHERE p.section_id='$func_section_id' AND p.active = '1' AND ( g.active IS NULL OR g.active = '1' )
+		AND (published_when = '0' OR published_when <= $t) AND (published_until = 0 OR published_until >= $t)
 		ORDER BY p.post_id DESC
 	");
 	// now call print_excerpt() for every single post
Index: trunk/wb/modules/news/view.php
===================================================================
--- trunk/wb/modules/news/view.php	(revision 599)
+++ trunk/wb/modules/news/view.php	(revision 600)
@@ -109,7 +109,11 @@
 	}
 	
 	// Query posts (for this page)
-	$query_posts = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_posts WHERE section_id = '$section_id' AND active = '1' AND title != ''$query_extra ORDER BY position DESC".$limit_sql);
+	$t = time();
+	$query_posts = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_posts
+		WHERE section_id = '$section_id' AND active = '1' AND title != ''$query_extra
+		AND (published_when = '0' OR published_when <= $t) AND (published_until = 0 OR published_until >= $t)
+		ORDER BY position DESC".$limit_sql);
 	$num_posts = $query_posts->numRows();
 	
 	// Create previous and next links
@@ -256,7 +260,11 @@
 	}
 	
 	// Get post info
-	$query_post = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_posts WHERE post_id = '".POST_ID."' AND active = '1'");
+	$t = time();
+	$query_post = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_posts
+		WHERE post_id = '".POST_ID."' AND active = '1'
+		AND (published_when = '0' OR published_when <= $t) AND (published_until = 0 OR published_until >= $t)
+	");
 	if($query_post->numRows() > 0) {
 		$post = $query_post->fetchRow();
 		if(isset($groups[$post['group_id']]['active']) AND $groups[$post['group_id']]['active'] != false) { // Make sure parent group is active
@@ -282,7 +290,7 @@
 			$post_long = ($post['content_long']);
 		}
 	} else {
-		header("Location: ".WB_URL.PAGES_DIRECTORY."");
+		$wb->print_error($MESSAGE['FRONTEND']['SORRY_NO_ACTIVE_SECTIONS'], "javascript: history.go(-1);", false);
 		exit(0);
 	}
 	
@@ -298,7 +306,7 @@
 	echo str_replace($vars, $values, $setting_post_footer);
 	
 	// Show comments section if we have to
-	if($post['commenting'] == 'private' AND isset($admin) AND $admin->is_authenticated() == true OR $post['commenting'] == 'public') {
+	if(($post['commenting'] == 'private' AND isset($wb) AND $wb->is_authenticated() == true) OR $post['commenting'] == 'public') {
 		
 		// Print comments header
 		echo str_replace('[ADD_COMMENT_URL]', WB_URL.'/modules/news/comment.php?id='.POST_ID.'&sid='.$section_id, $setting_comments_header);
Index: trunk/wb/modules/news/modify.php
===================================================================
--- trunk/wb/modules/news/modify.php	(revision 599)
+++ trunk/wb/modules/news/modify.php	(revision 600)
@@ -82,7 +82,7 @@
 				}
 				?>
 			</td>
-			<td width="80">
+			<td width="120">
 				<?php echo $TEXT['COMMENTS'].': ';
 				// Get number of comments
 				$query_title = $database->query("SELECT title FROM ".TABLE_PREFIX."mod_news_comments WHERE post_id = '".$post['post_id']."'");
@@ -93,6 +93,22 @@
 				<?php echo $TEXT['ACTIVE'].': '; if($post['active'] == 1) { echo $TEXT['YES']; } else { echo $TEXT['NO']; } ?>
 			</td>
 			<td width="20">
+			<?php
+			$start = $post['published_when'];
+			$end = $post['published_until'];
+			$t = time();
+			$icon = '';
+			if($start<=$t && $end==0)
+				$icon=ADMIN_URL.'/images/noclock_16.png';
+			elseif(($start<=$t || $start==0) && $end>=$t)
+				$icon=ADMIN_URL.'/images/clock_16.png';
+			else
+				$icon=ADMIN_URL.'/images/clock_red_16.png';
+			?>
+			<a href="<?php echo WB_URL; ?>/modules/news/modify_post.php?page_id=<?php echo $page_id; ?>&section_id=<?php echo $section_id; ?>&post_id=<?php echo $post['post_id']; ?>" title="<?php echo $TEXT['MODIFY']; ?>">
+				<img src="<?php echo $icon; ?>" border="0" alt="" />
+			</td>
+			<td width="20">
 			<?php if($post['position'] != $num_posts) { ?>
 				<a href="<?php echo WB_URL; ?>/modules/news/move_down.php?page_id=<?php echo $page_id; ?>&section_id=<?php echo $section_id; ?>&post_id=<?php echo $post['post_id']; ?>" title="<?php echo $TEXT['MOVE_UP']; ?>">
 					<img src="<?php echo ADMIN_URL; ?>/images/up_16.png" border="0" alt="^" />
Index: trunk/wb/modules/news/modify_post.php
===================================================================
--- trunk/wb/modules/news/modify_post.php	(revision 599)
+++ trunk/wb/modules/news/modify_post.php	(revision 600)
@@ -50,7 +50,7 @@
 }
 
 // include jscalendar-setup
-$jscal_use_time = false; // whether to use a clock, too
+$jscal_use_time = true; // whether to use a clock, too
 require_once(WB_PATH."/include/jscalendar/wb-setup.php");
 // override some vars: (normally, there is no need to change this)
 //$jscal_lang = "en"; //- calendar-language (default: wb-backend-language)
@@ -121,12 +121,21 @@
 	</td>
 </tr>
 <tr>
-	<td><?php echo $TEXT['DATE']; ?>:</td>
+	<td><?php echo $TEXT['PUBL_START_DATE']; ?>:</td>
 	<td>
-	<input type="text" id="publishdate" name="publishdate" value="<?php if($fetch_content['published_when']==0) print ""; else print date($jscal_format, $fetch_content['published_when'])?>" style="width: 120px;" />
-	<img src="<?php echo WB_URL ?>/include/jscalendar/img.gif" id="publishdate_trigger" style="cursor: pointer; border: 1px solid red;" title="Calendar" onmouseover="this.style.background='red';" onmouseout="this.style.background=''" />
+	<input type="text" id="publishdate" name="publishdate" value="<?php if($fetch_content['published_when']==0) print date($jscal_format, time()); else print date($jscal_format, $fetch_content['published_when']);?>" style="width: 120px;" />
+	<img src="<?php echo ADMIN_URL ?>/images/clock_16.png" id="publishdate_trigger" style="cursor: pointer;" title="Calendar" onmouseover="this.style.background='lightgrey';" onmouseout="this.style.background=''" />
+	<img src="<?php echo ADMIN_URL ?>/images/clock_del_16.png" style="cursor: pointer;" title="delete date" onmouseover="this.style.background='lightgrey';" onmouseout="this.style.background=''" onclick="document.modify.publishdate.value=''" />
 	</td>
 </tr>
+<tr>
+	<td><?php echo $TEXT['PUBL_END_DATE']; ?>:</td>
+	<td>
+	<input type="text" id="enddate" name="enddate" value="<?php if($fetch_content['published_until']==0) print ""; else print date($jscal_format, $fetch_content['published_until'])?>" style="width: 120px;" />
+	<img src="<?php echo ADMIN_URL ?>/images/clock_16.png" id="enddate_trigger" style="cursor: pointer;" title="Calendar" onmouseover="this.style.background='lightgrey';" onmouseout="this.style.background=''" />
+	<img src="<?php echo ADMIN_URL ?>/images/clock_del_16.png" style="cursor: pointer;" title="delete date" onmouseover="this.style.background='lightgrey';" onmouseout="this.style.background=''" onclick="document.modify.enddate.value=''" />
+	</td>
+</tr>
 </table>
 
 <table class="row_a" cellpadding="2" cellspacing="0" border="0" width="100%">
@@ -179,6 +188,21 @@
 			step        : 1
 		}
 	);
+	Calendar.setup(
+		{
+			inputField  : "enddate",
+			ifFormat    : "<?php echo $jscal_ifformat ?>",
+			button      : "enddate_trigger",
+			firstDay    : <?php echo $jscal_firstday ?>,
+			<?php if(isset($jscal_use_time) && $jscal_use_time==TRUE) { ?>
+				showsTime   : "true",
+				timeFormat  : "24",
+			<?php } ?>
+			date        : "<?php echo $jscal_today ?>",
+			range       : [1970, 2037],
+			step        : 1
+		}
+	);
 </script>
 
 <br />
Index: trunk/wb/modules/news/comment.php
===================================================================
--- trunk/wb/modules/news/comment.php	(revision 599)
+++ trunk/wb/modules/news/comment.php	(revision 600)
@@ -50,6 +50,7 @@
 	define('POST_TITLE', $post_title);
 	
 	// don't allow commenting if its disabled, or if post or group is inactive
+	$t = time();
 	$table_posts = TABLE_PREFIX."mod_news_posts";
 	$table_groups = TABLE_PREFIX."mod_news_groups";
 	$query = $database->query("
@@ -56,6 +57,7 @@
 		SELECT p.post_id
 		FROM $table_posts AS p LEFT OUTER JOIN $table_groups AS g ON p.group_id = g.group_id
 		WHERE p.post_id='$post_id' AND p.commenting != 'none' AND p.active = '1' AND ( g.active IS NULL OR g.active = '1' )
+		AND (p.published_when = '0' OR p.published_when <= $t) AND (p.published_until = 0 OR p.published_until >= $t)
 	");
 	if($query->numRows() == 0) {
 		header("Location: ".WB_URL.PAGES_DIRECTORY."");
Index: trunk/wb/modules/news/save_post.php
===================================================================
--- trunk/wb/modules/news/save_post.php	(revision 599)
+++ trunk/wb/modules/news/save_post.php	(revision 600)
@@ -45,7 +45,8 @@
 	$title = $admin->add_slashes($admin->get_post('title'));
 	$short = $admin->add_slashes($admin->get_post('short'));
 	$long = $admin->add_slashes($admin->get_post('long'));
-	$publishedwhen = strtotime($admin->get_post('publishdate'));	
+	$publishedwhen = strtotime($admin->get_post('publishdate'));
+	$publisheduntil = strtotime($admin->get_post('enddate'));
 	$commenting = $admin->get_post('commenting');
 	$active = $admin->get_post('active');
 	$old_link = $admin->get_post('link');
@@ -102,7 +103,7 @@
 }
 
 // Update row
-$database->query("UPDATE ".TABLE_PREFIX."mod_news_posts SET group_id = '$group_id', title = '$title', link = '$post_link', content_short = '$short', content_long = '$long', commenting = '$commenting', active = '$active', published_when = '$publishedwhen', posted_when = '".mktime()."', posted_by = '".$admin->get_user_id()."' WHERE post_id = '$post_id'");
+$database->query("UPDATE ".TABLE_PREFIX."mod_news_posts SET group_id = '$group_id', title = '$title', link = '$post_link', content_short = '$short', content_long = '$long', commenting = '$commenting', active = '$active', published_when = '$publishedwhen', published_until = '$publisheduntil', posted_when = '".mktime()."', posted_by = '".$admin->get_user_id()."' WHERE post_id = '$post_id'");
 
 // Check if there is a db error, otherwise say successful
 if($database->is_error()) {
Index: trunk/wb/modules/news/install.php
===================================================================
--- trunk/wb/modules/news/install.php	(revision 599)
+++ trunk/wb/modules/news/install.php	(revision 600)
@@ -38,11 +38,12 @@
 					 . '`content_short` TEXT NOT NULL ,'
 					 . '`content_long` TEXT NOT NULL ,'
 					 . '`commenting` VARCHAR(7) NOT NULL DEFAULT \'\','
-					. '`published_when` INT NOT NULL DEFAULT \'0\','
-		   	    	 . '`posted_when` INT NOT NULL DEFAULT \'0\','
+					 . '`published_when` INT NOT NULL DEFAULT \'0\','
+					 . '`published_until` INT NOT NULL DEFAULT \'0\','
+					 . '`posted_when` INT NOT NULL DEFAULT \'0\','
 					 . '`posted_by` INT NOT NULL DEFAULT \'0\','
 					 . 'PRIMARY KEY (post_id)'
-                . ' )';
+					 . ' )';
 	$database->query($mod_news);
 	
 	$database->query("DROP TABLE IF EXISTS `".TABLE_PREFIX."mod_news_groups`");
