<?php
/// $Id: mod_newsflash.php,v 1.7 2003/12/03 20:56:34 rcastley Exp $
/**
* Newsflash Module
* @package Mambo Open Source
* @Copyright (C) 2000 - 2003 Miro International Pty Ltd
* @ All rights reserved
* @ Mambo Open Source is Free Software
* @ Released under GNU/GPL License : http://www.gnu.org/copyleft/gpl.html
* @version $Revision: 1.7 $
**/

defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
global $gid, $mosConfig_offset;
// load the html drawing class, MUST include the option for components
//require_once( $mainframe->getPath( 'front_html', 'com_newsflash' ) );
$access = !$mainframe->getCfg( 'shownoauth' );

$now = date( "Y-m-d H:i:s", time()+$mosConfig_offset*60*60 );

$database->setQuery( "SELECT COUNT(*) AS numrows"
."\nFROM #__newsflash"
."\nWHERE published=1"
."\nAND access <= $gid "
."\nAND (publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now') "
."\nAND (publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now')"
);

$numrows = $database->loadResult();
if ($numrows > 1) {
	mt_srand( (double) microtime()*1000000 );
	$flashnum = mt_rand( 0, --$numrows );
} else {
	$flashnum = 0;
}

$database->setQuery( "SELECT content"
."\nFROM #__newsflash"
."\nWHERE published=1"
."\nAND access <= $gid "
."\nAND (publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now') "
."\nAND (publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now')"
."\n	LIMIT $flashnum,1"
);

$row = null;

if ($database->loadObject( $row )) {
	newsflash_html::WriteNewsflash( $row );
}

class newsflash_html {
	function WriteNewsflash( &$row ) {
		?>
		<table cellpadding="4" cellspacing="0" border="0">
	 	 <tr>
		   <td class="newsflash"><?php echo $row->content; ?></td>
		 </tr>
		</table>
		<?php
	}
}
?>
