<?php
/*
  www.oscGold.com (C) Kamelia-Net Jacek Krysiak
  modul oscGold wer 4.0
*/
?>
<table border="0" width="100%" cellspacing="0" cellpadding="0">

	<!-- Naglowek BOF -->
	<tr>
		<td style="padding-bottom:1px">
			<?php
			$info_box_contents = array();
			$info_box_contents[] = array('text' => sprintf(TABLE_HEADING_NEWSDESK));
			new contentBoxHeading($info_box_contents);
			?>
		</td>
	</tr>
	<!-- Naglowek EOF -->

	<?php
	$newsdesk_var_query = tep_db_query('select p.newsdesk_id, pd.language_id, pd.newsdesk_article_name, pd.newsdesk_article_description, pd.newsdesk_article_shorttext, pd.newsdesk_article_url, pd.newsdesk_article_url_name,  p.newsdesk_image, p.newsdesk_image_two, p.newsdesk_image_three, p.newsdesk_date_added, p.newsdesk_last_modified, pd.newsdesk_article_viewed, p.newsdesk_date_available, p.newsdesk_status  from ' . TABLE_NEWSDESK . ' p, ' . TABLE_NEWSDESK_DESCRIPTION . '  pd WHERE pd.newsdesk_id = p.newsdesk_id and p.newsdesk_date_available <= now() and pd.language_id = "' . $languages_id . '" and newsdesk_status = 1 and p.newsdesk_sticky = 0 ORDER BY newsdesk_date_added DESC LIMIT ' . MAX_DISPLAY_NEWSDESK_NEWS);

	if (!tep_db_num_rows($newsdesk_var_query)) { // there is no news
	?>
		<tr>
			<td style="padding-bottom:5px">
				<table border="0" width="100%" cellspacing="0" cellpadding="2" class="TableFrame">
					<tr>
						<td class="main"><?php echo TEXT_NO_NEWSDESK_NEWS; ?></td>
					</tr>
				</table>
			</td>
		</tr>
	<?php
	} else {
	
		echo '<tr><td style="padding-bottom:5px"><table border="0" width="100%" cellspacing="0" cellpadding="2" class="TableFrame">';

		$row = 0;
		$ilosc_art = (int)tep_db_num_rows($newsdesk_var_query);
		while ($newsdesk_var = tep_db_fetch_array($newsdesk_var_query)) {

			if ( DISPLAY_NEWSDESK_IMAGE ) {
				if ($newsdesk_var['newsdesk_image'] != '') {
					$insertm_image = '
					<table border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td>
								<a href="' . tep_href_link(FILENAME_NEWSDESK_INFO, 'newsdesk_id=' . $newsdesk_var['newsdesk_id']) . '">' . tep_image(DIR_WS_IMAGES . $newsdesk_var['newsdesk_image'], '', '') . '</a>
							</td>
						</tr>
					</table>';
				}
			}
			if ( DISPLAY_NEWSDESK_IMAGE_TWO ) {
				if ($newsdesk_var['newsdesk_image_two'] != '') {
					$insertm_image_two = '
					<table border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td>
								<a href="' . tep_href_link(FILENAME_NEWSDESK_INFO, 'newsdesk_id=' . $newsdesk_var['newsdesk_id']) . '">' . tep_image(DIR_WS_IMAGES . $newsdesk_var['newsdesk_image_two'], '', '') . '</a>
							</td>
						</tr>
					</table>';
				}
			}
			if ( DISPLAY_NEWSDESK_IMAGE_THREE ) {
				if ($newsdesk_var['newsdesk_image_three'] != '') {
					$insertm_image_three = '
					<table border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td>
								<a href="' . tep_href_link(FILENAME_NEWSDESK_INFO, 'newsdesk_id=' . $newsdesk_var['newsdesk_id']) . '">' . tep_image(DIR_WS_IMAGES .$newsdesk_var['newsdesk_image_three'], '', '') . '</a>
							</td>
						</tr>
					</table>';
				}
			}
			if ( DISPLAY_NEWSDESK_VIEWCOUNT ) {
				$insertm_viewcount = ((strlen($newsdesk_var['newsdesk_article_description']) > 10) ? '<small>' . TEXT_NEWSDESK_VIEWED . $newsdesk_var['newsdesk_article_viewed'] . '</small>' : '');
			}
			if ( DISPLAY_NEWSDESK_READMORE ) {
				$insertm_readmore_s = '';
				if (strlen($newsdesk_var['newsdesk_article_description']) > 10) {
					$insertm_readmore_s = '
					<tr>
						<td class="smallText" style="padding-top:5px">
							<a class="smallText" href="' . tep_href_link(FILENAME_NEWSDESK_INFO, 'newsdesk_id=' . $newsdesk_var['newsdesk_id']) . '">[' . TEXT_NEWSDESK_READMORE . ']</a>
						</td>
					</tr>
					';
				}
			}
			if ( DISPLAY_NEWSDESK_SUMMARY ) {
				$insertm_summary = '
				<tr>
					<td class="smallText">'. $newsdesk_var['newsdesk_article_shorttext'] . '</td>
				</tr>';
			}
			if ( DISPLAY_NEWSDESK_HEADLINE ) {
				$insertm_headline = tep_image(DIR_WS_TEMPLATES . 'images/infobox/menu.gif').'&nbsp;<b> <a class="smallText" href="' . tep_href_link(FILENAME_NEWSDESK_INFO, 'newsdesk_id=' . $newsdesk_var['newsdesk_id']) . '">' . $newsdesk_var['newsdesk_article_name'] . '</a></b>';
			}
			if ( DISPLAY_NEWSDESK_DATE ) {
				$insertm_date = ' <small>' . tep_date_long($newsdesk_var['newsdesk_date_added']) . '</small><br>';
			}
			?>
			<tr>
				<td>
					<table border="0" width="100%" cellspacing="0" cellpadding="2" >
						<?php
						echo '
						<tr><td colspan="2">
							<table border="0" width="100%"><tr>
							<td class="smallText">' . $insertm_headline . '</td>
							<td class="smallText" align="right">' . $insertm_date . $insertm_viewcount . '</td>
							</tr></table>
						</td></tr>

						<tr>
							<td valign="top" width="100%">
								<table border="0" width="100%" cellspacing="3" cellpadding="0">
									' . $insertm_summary . '
									' . $insertm_readmore_s . '
								</table>
							</td>
							<td valign="top">
								' . $insertm_image . '
								' . $insertm_image_two . '
								' . $insertm_image_three . '
							</td>
						</tr>';
						if (($ilosc_art-1) > $row) {
							echo '<tr><td colspan="2">'.tep_draw_separator('pixel_silver.gif', '100%', '1').'</td></tr>';	
						}
					$row++;
					?>
					</table>
				</td>
			</tr>
			<?php
			// WE need a better solution for my fudge code below ...
			$insertm_image = '';
			$insertm_image_two ='';
			$insertm_image_three = '';
		}
		
		echo '</table></td></tr>';
	}
?>
</table>
