<?php 

// radisplayshow
// handle 

// A) displayshow?showoid=4628&date=05-31-2016
// B) displayshow?djoid=10529&date=05-29-2016
			
require_once __DIR__ . '/magpie/rss_fetch.inc';

global $wp_query;


$this_dj_oid = $wp_query->query_vars['radjoid'];;
$this_show_oid = $wp_query->query_vars['rashowoid'];;
$this_show_date = $wp_query->query_vars['rashowdate'];;

// Case 1
// Link like
// http://wmxm.org/last-10-days/displayshow?rashowoid=4628&rashowdate=06-01-2016
// Meaning we had a SHOW NAME and a DJ NAME
// in which case hit
// http://wmxm.radioactivity.fm/feeds/playlistrss.html?showoid=4628&date=05-30-2016
if (!$this_dj_oid) {
			 
			 
			 $link_to_pull = "http://wmxm.radioactivity.fm/feeds/playlistrss.html?showoid=" . $this_show_oid . "&date=" . $this_show_date; 
			 $rss = @fetch_rss($link_to_pull);
			 ?>
			 <!--<li>DEBUG: <?=$link_to_pull?> -->
			 <table border=1 width=600 cellpadding=1 cellspacing=1>
			 <?
			 
			 // Pull show name and so forth from the channel 
			 $show_name = $rss->channel['ra']['showname'];
			 $show_info = $rss->channel['ra']['showinfo'];
			 $show_dj 	= $rss->channel['ra']['showdj1'];
			 
			?>
			
			<tr>
				<td width=30%  text-align: left; border: 2px "><b>Show Name:</b></td>
				<td width=70% text-align: left;border: 2px "><b><?=$show_name?></b></td>
			</tr>		

			<tr>
				<td width=30%  text-align: left; border: 2px "><b>Show DJ:</b></td>
				<td width=70% text-align: left;border: 2px "><b><?=$show_dj?></b></td>
			</tr>	
			
			<tr>
				<td width=30% text-align: left; border: 2px ">Show Date:</td>
				<td width=70% text-align: left;border: 2px "><?=$this_show_date?></td>
			</tr>
				  	
			
			<?
			 /*
			  <description>RSS feed for WMXM show: Automation on 06-01-2016</description>
				<ra:showname>Automation</ra:showname>
				<ra:showinfo>The station's on automation.</ra:showinfo>
				<ra:showdj1>DJ Autobot</ra:showdj1>
				<language>en-us</language>
				<pubDate>Thu, 02 Jun 2016 19:58:02 EST</pubDate>
				
				<item><title>Play # 1</title>
				<guid><![CDATA[http://wmxm.radioactivity.fm/show.html?showoid=4628#1000]]></guid>
				<link><![CDATA[http://wmxm.radioactivity.fm/show.html?showoid=4628]]></link>
				<ra:time>06-01-2016 11:03:14 am</ra:time>
				<ra:track>Tonight</ra:track>
				<ra:artist>OMN</ra:artist>
				<ra:album>unknown</ra:album>
				<ra:label>unknown</ra:label>
				<ra:genre></ra:genre>
				<ra:playtype></ra:playtype>
				</item>
			 */
			 
			 $count=0;
			 foreach ($rss->items as $item) {
			 
					  $play_time		= $item['ra']['time'];
					  $play_track		= $item['ra']['track'];
					  $play_artist	= $item['ra']['artist'];
					  $play_album 	= $item['ra']['album'];
					  
					  // coloring adjustments
						$bgcolor="#A7E5FA"; if ($count%2) {$bgcolor="#ffffff";} 
						
						$time_bits = explode(" ",$play_time);
						$hour_only = $time_bits[1];
						?>
						
						<tr>
				  	<td width=30%  style="background-color:<?=$bgcolor?>; text-align: left; border: 2px ">
				  		<?=$hour_only?><?=$time_bits[2]?>
				  	</td>
				  	<td width=70%  style="background-color:<?=$bgcolor?>; text-align: left;border: 2px ">
				  		
				  		<? 
				  		// lets format intelligently
				  		if ($play_artist) {$display_string = $play_artist;}
				  		if ($play_track)  {$display_string .= " - " . $play_track;}
				  		if ($play_album)  {$display_string .= " - " . $play_album;}
				  		?>
				  		<?=$display_string?>
				  	</td>
				
						<?
						$count++;
				
				} // ends foreach on results
				
				?>
				</table>
			<?
 
}

// Case 2
// Link like
// http://wmxm.org/last-10-days/displayshow?radjoid=11310&rashowdate=05-31-2016
// meaning we had a DJ OID and a SHOW DATE
// in which case hit new URL like
// http://wmxm.radioactivity.fm/feeds/djdaterss.html?djoid=11310&date=05-24-2016


if ($this_dj_oid) {
 
 
 		
 				
 			 $link_to_pull = "http://wmxm.radioactivity.fm/feeds/djdaterss.html?djoid=" . $this_dj_oid . "&date=" . $this_show_date; 
 			
			 $rss = @fetch_rss($link_to_pull);
			 ?>
			 
			
			 
			 <table border=1 width=600 cellpadding=1 cellspacing=1>
			 <?
			 
			 // Pull show name and so forth from the channel 
			 $show_dj 	= $rss->channel['ra']['djname'];
			 
			 ?>
			 
					<tr>
						<td width=20% text-align: left; border: 2px "><b>Show DJ:</b></td>
						<td width=80% text-align: left;border: 2px "><b><?=$show_dj?></b></td>
					</tr>	
					
					<tr>
						<td width=20% text-align: left; border: 2px ">Show Date:</td>
						<td width=80% text-align: left;border: 2px "><?=$this_show_date?></td>
					</tr>

			 <?
			 
			  $count=0;
			  
			  // 11082016 getting sporadic invalid argument foreach warning here when clicking a show
			  
			  foreach ($rss->items as $item) {
			 
					  $play_time		= $item['ra']['time'];
					  $play_artist	= $item['ra']['artist'];
					  $play_track		= $item['ra']['track'];
					  $play_album 	= $item['ra']['album'];
					  
					  // coloring adjustments
						$bgcolor="#A7E5FA"; if ($count%2) {$bgcolor="#ffffff";} 
						
						$time_bits = explode(" ",$play_time);
						$hour_only = $time_bits[1];
						
						?>
						
						<tr>
				  	<td width=20%  style="background-color:<?=$bgcolor?>; text-align: left; border: 2px ">
				  		<?=$hour_only?><?=$time_bits[2]?>
				  	</td>
				  	<td width=80%  style="background-color:<?=$bgcolor?>; text-align: left;border: 2px ">
				  		<? 
				  		// lets format intelligently
				  		if ($play_artist) {$display_string = $play_artist;}
				  		if ($play_track)  {$display_string .= " - " . $play_track;}
				  		if ($play_album)  {$display_string .= " - " . $play_album;}
				  		?>
				  		<?=$display_string?>
				  	</td>
				
						<?
						$count++;
				
				} // ends foreach on results
				
			
			?>
			</table>
			<?
			
}


// fin

?>
