<?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(HEADING_NEWSDESK_STICKY));
			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, p.newsdesk_sticky 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 = 1 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 ( STICKY_IMAGE ) {
				if ($newsdesk_var['newsdesk_image'] != '') {
					$insert_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 ( STICKY_IMAGE_TWO ) {
				if ($newsdesk_var['newsdesk_image_two'] != '') {
					$insert_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 ( STICKY_IMAGE_THREE ) {
				if ($newsdesk_var['newsdesk_image_three'] != '') {
					$insert_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 ( STICKY_NEWSDESK_VIEWCOUNT ) {
				$insert_viewcount = ((strlen($newsdesk_var['newsdesk_article_description']) > 10) ? '<small>' . TEXT_NEWSDESK_VIEWED . $newsdesk_var['newsdesk_article_viewed'] . '</small>' : '');
			}
			if ( STICKY_NEWSDESK_READMORE ) {
				$insert_readmore_s = '';
				if (strlen($newsdesk_var['newsdesk_article_description']) > 10) {
					$insert_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 ( STICKY_ARTICLE_SHORTTEXT ) {
				$insert_summary = '
				<tr>
					<td class="smallText">'. $newsdesk_var['newsdesk_article_shorttext'] . '</td>
				</tr>
				<tr>
					<td>' . tep_draw_separator('pixel_trans.gif', '100%', '5') . '</td>
				</tr>
				';
			}
			if ( STICKY_ARTICLE_DESCRIPTION ) {
				$insert_content = '
				<tr>
					<td class="smallText">'. $newsdesk_var['newsdesk_article_description'] . '</td>
				</tr>
				';
			}
			if ( STICKY_ARTICLE_NAME ) {
				$insert_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 ( STICKY_DATE_ADDED ) {
				$insert_date = ' <small>' . tep_date_long($newsdesk_var['newsdesk_date_added']) . '</small><br>';
			}		
			if ( STICKY_ARTICLE_URL ) {
				$insert_url = '<small><a href="'.$newsdesk_var['newsdesk_article_url'].'">' . $newsdesk_var['newsdesk_article_url'] . '</a></small>';
			}
			if ( STICKY_ARTICLE_URL_NAME ) {				
				$insert_url = '<small><a href="'.$newsdesk_var['newsdesk_article_url'].'">' . $newsdesk_var['newsdesk_article_url_name'] . '</a></small>';
			}
			?>
			<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">' . $insert_headline . '</td>
							<td class="smallText" align="right">' . $insert_date . $insert_viewcount . '</td></tr>'.
							(($insert_url != '') ? '<tr><td colspan="2" align="left" class="smallText">'.$insert_url.'</td></tr>' : '').
							'</table>
						</td></tr>

						<tr>
							<td valign="top" width="100%">
								<table border="0" width="100%" cellspacing="3" cellpadding="0">
									' . $insert_summary . '
									' . $insert_content . '
									' . $insert_readmore_s . '
								</table>
							</td>
							<td valign="top">
								' . $insert_image . '
								' . $insert_image_two . '
								' . $insert_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 ...
			$insert_image = '';
			$insert_image_two ='';
			$insert_image_three = '';
		}
		
		echo '</table></td></tr>';
	}
?>
</table>
