<?xml version="1.0"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:output method="html" indent="yes" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"/>
	<xsl:param name="message"/>
	<xsl:param name="pageTitle">IP Destination</xsl:param>
	<xsl:param name="function"/>
	<xsl:param name="destipaddr" />
	<xsl:param name="destport" />
	<xsl:include href="namedtemplates.xsl"/>

	<xsl:template match="/configuration/iptv/iptv_destination[dest_ip_addr=$destipaddr and dest_port=$destport]/programs" mode="iptv">
		<xsl:for-each select="program_reference">
			iptv_assign.push( new TIptvAssignment(<xsl:value-of select="source_port" />,<xsl:value-of select="source_program_number" />));
		</xsl:for-each>
	</xsl:template>

	<xsl:template name="src">
		<!--iptv_avail.push( new TIptvAvail(1,2,test));-->
		<xsl:for-each select="/configuration/port/program_remap/program">
			iptv_avail.push( new TIptvAvail(<xsl:value-of select="../../@index"/>,<xsl:value-of select="@program_number_in"/>,<xsl:value-of select="program_number_out"/>,&quot;<xsl:value-of select="name_out"/>&quot;, <xsl:choose><xsl:when test="../../portstate = 'Disabled'">1</xsl:when><xsl:otherwise>0</xsl:otherwise></xsl:choose>) );
		</xsl:for-each>
	</xsl:template>

	<xsl:template name="head">
			<head>
				<title>
					<xsl:value-of select="$web_title"/>
				</title>	
				<xsl:if test="configuration/user_data/auto_logout_time != 0">
					<xsl:element name="meta">
						<xsl:attribute name="http-equiv">refresh</xsl:attribute>
						<xsl:attribute name="content"><xsl:value-of select="(configuration/user_data/auto_logout_time * 60)+ 5"/>;URL=ip_destinations.py</xsl:attribute>
					</xsl:element>
				</xsl:if>
				<xsl:call-template name="common_imports"/>
				<script language="JavaScript" type="text/javascript" src="/javascript/destination.js"/>
				<script type="text/javascript" src="/javascript/inputs.js" language="JavaScript"/>
				<script type="text/javascript" src="/javascript/add_validate.js" language="JavaScript"/>
				<script type="text/javascript" >

function showassign ()
	{
	var assignments ="";
	// loop through the assigned array.
	for (i=0; i &lt; iptv_assign.length; i++)
		{
		name = iptv_assign[i].source_port+","+iptv_assign[i].source_pn;
		for (j=0; j &lt; iptv_avail.length; j++ )
			{
			val = iptv_avail[j].source_port+","+iptv_avail[j].source_pn;
			if (name == val)
				{
				if (iptv_avail[j].disabled) {
					assignments = assignments + "&lt;span class=\"inactive-program\"&gt;"+ iptv_avail[j].source_name + " (disabled)&lt;/span&gt;&lt;br /&gt;";
				} else {
					assignments = assignments + "&lt;span&gt;"+ iptv_avail[j].source_name + "&lt;/span&gt;&lt;br /&gt;";
				}
				//console.log(assignments);
				}
			}		
		}
	document.getElementById("asg").innerHTML=assignments;  
	}

function TIptvAssignment(port, pn_in)
	{
	this.source_port = port;
	this.source_pn = pn_in;
	}

<!-- Avails are programs that have been routed, so they have a pn_out. -->
function TIptvAvail(port, pn_in, pn_out, name, disabled)
	{
	this.source_port = port;
	this.source_pn = pn_in;
	this.pn_out = pn_out;
	this.source_name = name;
	this.disabled = disabled;
	}

var iptv_avail = new Array(); 
var iptv_assign = new Array();   // list of TIptvDestination


function load()
	{
	showassign();
	}
				  
				  <xsl:text /><xsl:apply-templates mode="iptv"/>
			  <xsl:text /><xsl:call-template name="src"/>
				  
				</script>  

			</head>
	</xsl:template>
	
	<xsl:template match="/configuration/iptv/iptv_destination[dest_ip_addr=$destipaddr and dest_port=$destport]">
		<html>
			<xsl:call-template name="head" />
			<body onload="window.defaultStatus=''; StartFloat(); load();">
				<xsl:call-template name="initROPage">
					<xsl:with-param name="pageName">ip_destinations.py</xsl:with-param>
					<xsl:with-param name="message" select="$message"/>
				</xsl:call-template>
				<div id="displayresults">
					<form action="ip_destinations.py" method="post" name="applyform">
						<input type="hidden" name="action" value="apply"/>
						<h1 class="display">IP Destination:</h1> 
						<div class="adddest"><a href="ip_destinations.py">Back</a></div>
						<table width="700">
							<tr>
								<td>
									<table>
										<tr>
											<td><div class="blacktab">General</div></td>
										</tr>
										<tr>
											<td>
												<table class="boxholder">
													<tr>
														<td><b>Name:</b></td>
														<td>
															<xsl:choose> 
																<xsl:when test="name = ''">
																	<xsl:value-of select="dest_ip_addr" />:<xsl:value-of select="dest_port" />
																</xsl:when>
																<xsl:otherwise>	 
																	<xsl:value-of select="name"/>
																</xsl:otherwise>
															</xsl:choose> 
														</td>
														<!-- ipa needs to be unique ahp  -->
														<td><b>IPA:</b></td>
														<td>
															<xsl:value-of select="dest_ip_addr"/>
														</td>
														<td><b>Port:</b></td>
														<td>
															<xsl:value-of select="dest_port"/>
														</td>
														<td><b>Src Port:</b></td>
														<td>
															<xsl:value-of select="src_port"/>
														</td>
													</tr>
													<tr>
														<td><b>Modulation Target:</b></td>
														<td>
															<xsl:value-of  select="modulation_target"/>
														</td>
														<td><b>Bit Rate:</b></td>
														<td>
															<!-- this field is determined by framing mode and mod target unless mod target is manual--> 
															<xsl:value-of select="constant_bit_rate"/>
														</td>
														<td><b>IP TTL:</b></td>
														<td>
															<xsl:value-of select="opt_ip_ttl"/>
														</td>
														<td><b>State:</b></td>
														<td>
															<xsl:value-of select="@state"/>
														</td>
													</tr>
												</table>
											</td>
										</tr>
									</table>
								</td>
							</tr>
							<tr>
								<td>
									<table>
										<tr>
											<td><div class="blacktab">Programs</div></td>
										</tr>
										<tr>
											<td>
												<table class="boxholder">
													<tr>
														<td>Assigned:
															<br/>
															<div name="asg" id="asg" />
														</td>
													</tr>
												</table>
											</td>
										</tr>
									</table>
								</td>
							</tr>
							<tr>
								<td>
									<table>
										<tr>
											<td><div class="blacktab">Tables</div></td>
										</tr>
										<tr>
											<td>
												<table class="boxholder">
													<tr>
														<td valign="top">Type: </td>
														<td valign="top" width="350px">
															<b>
																<xsl:choose>
																	<xsl:when test="nit/enable = 'Yes'">
																		DVB-NIT
																	</xsl:when>
																	<xsl:otherwise>
																		MPEG
																	</xsl:otherwise>
																</xsl:choose>
															</b>
														</td>
														<td style="border-left:1px solid black;"></td>
														<td>
															<b>PAT Rate: </b>
															<xsl:value-of select="pat_rate"/> tenths
														</td>
														<td>
															<b>Transport Stream ID: </b>
															<xsl:value-of select="nit/transport_stream/@id"/>
														</td>
													</tr>
												</table>
											</td>
										</tr>
									</table>
								</td>
							</tr>
							<tr id="DVB">
								<xsl:attribute name="style">
									<xsl:if test="nit/enable = 'No'">
										<xsl:text>display: none</xsl:text>
									</xsl:if>
								</xsl:attribute>
								<td>
									<table>
										<tr>
											<td><div class="blacktab">DVB-NIT</div></td>
										</tr>
										<tr>
											<td>
												<table class="boxholder">
													<tr>
														<td>
															Network Name:
														</td>
														<td>
															<xsl:value-of select="nit/network_name"/>
														</td>
														<td>
															Nit Rate:
														</td>
														<td>
															<xsl:value-of select="nit/rate"/>
														</td>
													</tr>
													<tr>
														<td>
															Network ID:
														</td>
														<td>
															<xsl:value-of select="nit/network_id"/>
														</td>
														<td>
															Symbol Rate:
														</td>
														<td>
															<xsl:value-of select="nit/transport_stream/symbol_rate"/>
														</td>
													</tr>
													<tr>
														<td>
															Original Network ID:
														</td>
														<td>
															<xsl:value-of select="nit/original_network_id"/>
														</td>
														<td>
															RF Frequency:
														</td>
														<td>
															<xsl:value-of select="nit/transport_stream/frequency"/>
														</td>
													</tr>
												</table>
											</td>
										</tr>
									</table>
								</td>
							</tr>
						</table>
					</form>
				</div>
			</body>
		</html>
	</xsl:template>
	
	<xsl:template match="text()">
	</xsl:template>
	<xsl:template match="text()" mode="iptv">
	</xsl:template>
</xsl:stylesheet>
