[comment]
ui_component: news
ui_component_type: content, vertical
ui_component_group: news
ui_component_label: News

news_type:
	label: Promotion type
	options: general=General, company=Company, products=Products 
	widget: select

matches:
	label: Number to show
	widget: select
	options: 1,2,3*,4,5,6,7,8,9,10

cols:
	label: Columns
	options: 1,2,3*,4
	widget: select

banner:
	label: Banner for top box
	default: News
	widget: text
	width: 40

timed:
    label: Use timed build
    widget: select
    help: Makes more efficient for large/busy catalogs
    options: 0=No, 5=5 minutes, 10=10 minutes, 20=20 minutes, 60=60 minutes, 1440=Daily
    advanced: 1
[/comment]

<!-- BEGIN COMPONENT [control component news] -->
[timed-build if="[control timed 60]" minutes="[control timed 60]"]
<table width="95%" align=center>
<tr class="categorybar"> 
  <td class="categorybar" align="left"><b>[control banner News]</b></td>
</tr>
<tr> 
  <td> 
	[query arrayref=main
		   sql="
		   	SELECT code,timed_news,start_date,finish_date
			FROM news
			WHERE featured = '[control news_type general]'
			ORDER BY posted_on DESC
			"][/query]
	[perl tables="news"]
		my @out;
		my $ref;
		my $db;
		my $count = 0;
		delete $Scratch->{news_codes};
		my $date = $Tag->time( { body => '%Y%m%d' } );
		$ref = $Tmp->{main} or return;
		my $matches = $Tag->control("matches",3);
		for(@$ref) {
			last if $count++ == $matches;
			my $line = $_;
			push(@out, $line->[0]), next if ! $line->[1];
			next if $line->[2] gt $date;
			next if $line->[3] lt $date;
			push @out, $line->[0];
		}
		$Scratch->{news_codes} = join(' ', @out);
		return;
	[/perl]
      <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
    [table-organize embed=1 pretty=1 cols="[control cols 2]"]
[loop
	random="[control matches 3]"
	list="[scratch news_codes]"
	 ] 
     <TD> 
	  <table border="0" cellspacing="0" cellpadding="0" width="100%">
	  <tr> 
		<td align="center" class="contentbar1">
		  <b>
		  [if-loop-data news blurb_begin]
			[loop-data news blurb_begin]
		  [else]
			[loop-data news title]
		  [/else]
		  [/if-loop-data]</b>
		</td>
	  </tr>
	  <tr> 
		<td align="left">
			<small>[convert-date][loop-data news posted_on][/convert-date]<br><br></small>
		</td>
	  </tr>
   
      [if-loop-data news banner_image]
	  <tr> 
		<td align="center"> 
		  <img src="[loop-data news banner_image]" height="80">
		</td>
	  </tr>
      [/if-loop-data]
	  <tr> 
		<td align="left"> 
		  <small>[filter 200][loop-data news body][/filter]</small>
		</td>
	  </tr>

	[if-loop-data news blurb_end]
	  <tr> 
		<td align="right">
		  <a href="[area href="news" arg="[loop-code]"]">[loop-data news blurb_end]</a>
		</td>
	  </tr>
	[else]
	  <tr> 
		<td align="right">
		  <a href="[area href="news" arg="[loop-code]"]">[loc]Read more[/loc]</a>...&nbsp;
		</td>
	  </tr>
	[/else]
	[/if-loop-data]
	  <tr> 
		<td align="center">&nbsp;</td>
	  </tr>
	  </table>
  	</TD>
[/loop]
[/table-organize]
      </table>

      <p>&nbsp;</p>

  </td>
</tr>
</table>
[/timed-build]
<!-- END COMPONENT [control component news] -->
