<?php
	require("../../inc/header.inc");
	require("../sub_inc/operWebFunc.inc");
	require("param_comm.inc");
?>

<script language="JavaScript">
function selectAll(entries)
{
	var select_state=document.myform.cbSelectAll.checked;
	if(select_state==true)
	{
		for(i=1;i<entries;i++)
		{
			var cmd="document.myform.cb_"+i;
			if(eval(cmd) != null)
			{
				cmd="document.myform.cb_"+i+".checked=true";
				eval(cmd);
			}
		}
	}
	else
	{
		for(i=1;i<entries;i++)
		{
			var cmd="document.myform.cb_"+i;
			if(eval(cmd) != null)
			{
				cmd="document.myform.cb_"+i+".checked=false";
				eval(cmd);
			}
		}
	}
}
function closeWindow(sysId,table_id,table_level,instanceNo)
{
	window.opener.location.href="./param_show_table.php?sysId="+sysId+"&table_id="+table_id+"&table_level="+table_level+"&instanceNo="+instanceNo;
	window.close();
}
</script>

<?php
	//echo "sysId=$sysId,instanceNo=$instanceNo,oidStr=$oidStr,tableOid=$tableOid,opt=$opt<br>";
	$trunkTimeSlotEntriesFiled="trunkChannelEntries";
	//get the trunkTimeSlotEntries oid
	$sql="select level_1,level_2,level_3,level_4,level_5,level_6,level_7,level_8,level_9,level_10 from OBJ_320.paramConf where name_2='$trunkTimeSlotEntriesFiled' ";
	$res=@mysqli_query($pubConn,$sql);
	$num=@mysqli_num_rows($res);
	if($num == 0)
		exit($trunkTimeSlotEntriesFiled." do not exist!<br>");
	$pos=0;
	$row=@mysqli_fetch_array($res);
	$trunkTimeSlotEntriesOid="";
	while($row[$pos]!=0)
	{
		$trunkTimeSlotEntriesOid.="{$row[$pos]}.";
		$pos++;
	}
	$trunkTimeSlotEntriesOid=substr($trunkTimeSlotEntriesOid,0,strlen($trunkTimeSlotEntriesOid)-1);
	//echo "trunkTimeSlotEntriesOid=$trunkTimeSlotEntriesOid<br>";
	
	//get the trunkTimeSlotEntries value
	$oidWhere=getLevelWhere($trunkTimeSlotEntriesOid);
	$sql="select readValue from OBJ_320.param_99 where $oidWhere and instanceNo='$instanceNo' ";
	$res=@mysqli_query($pubConn,$sql);
	$row=@mysqli_fetch_array($res);
	$trunkTimeSlotEntriesValue=$row[0]+0;
	//echo "Entries={$row[0]} {$instanceNo}<br>";
	
	
	//show the title
	$split=explode(".",$instanceNo);
	$tgno=$split[0]+0;
	$tkno=$split[1]+0;
	echo "<b>MSC > Trunk Group $tgno > Trunk $tkno > Channel</b><p>"; 
	
	//set
	if($_SERVER['REQUEST_METHOD'] == "POST")
	{
		echo "Set parameter...<br>";
		//echo "trunkTimeSlotEntriesValue=$trunkTimeSlotEntriesValue";
		if($trunkTimeSlotEntriesValue==24)
			$totalNum=25;
		else if($trunkTimeSlotEntriesValue==32)
			$totalNum=32;
		for($i=1;$i<$totalNum;$i++)
		{
			$param="cb_".$i;
			$value=$$param;
			$index=0;
			if($value=="on")
			{
				$newInstanceNo=$instanceNo.".".omc_keep_length($i,"0",4);
				
				$tmpWhere=getLevelWhere("2.4.3.1.4");
				$updateSql="UPDATE OBJ_320.param_99 SET initValue=$typeValue WHERE $tmpWhere AND instanceNo='$newInstanceNo'";		
				mysqli_query($pubConn,$updateSql);
				//echo "typeValue=$typeValue,updateSql=$updateSql<p>";
				
				/*
				$commInfoArr[$index][sysId]=$sysId;
				$commInfoArr[$index][oid]="2.4.3.1.4";
				$commInfoArr[$index][instanceNo]=$newInstanceNo;
				$index++;
				*/
				$commIdStr=oidSysCommSend($sysId,3,"2.4.3.1.4",$selectedSysId=-1,$newInstanceNo);
				//checkState($commIdStr,"./param_show_table.php?sysId=$sysId&tableOid=$tableOid&instanceNo=$instanceNo");
				//echo "set $newInstanceNo<br>";
				
				echo "<img width=10 height=10 src=\"../../images/arrow.gif\">";
			}
		}
		echo "<br>";
		/*
		if($index > 0)
		{
			setParam($commInfoArr);
		}
		*/
		
		echo "<a href=\"javascript:closeWindow('$sysId','$table_id','$table_level','$instanceNo');\">Close</a>";
		exit("");
	}	
		
	echo "<form name=\"myform\" action=\"lockTimeSlot.php?sysId=$sysId&oidStr=$oidStr&instanceNo=$instanceNo&tableOid=$tableOid\" method=\"post\">";
	
	echo "Type <select size=1 name=\"typeValue\">";
	
	if($opt == 'lock')
	{
		echo "<option value=0>disable</option>";
		echo "<option value=1>incoming</option>";
		echo "<option value=2>outgoing</option>";
	}
	else if($opt == 'unlock')
	{
		echo "<option value=3>bidirectional</option>";
	}
	echo "</select><p>";
	
	
	
	if($trunkTimeSlotEntriesValue==24)
		$totalNum=25;
	else if($trunkTimeSlotEntriesValue==32)
		$totalNum=32;
	echo "<table border=0 width=50%>";
	echo "<tr bgcolor=#cecece>";
	echo "<td width=45%>Select All Time Slots</td>";
	echo "<td width=5%><input type=checkbox name=\"cbSelectAll\" onClick=\"javascript:selectAll('$totalNum');\">";
	echo "</tr>";
	//do not need time slot 0
	
	for($i=1;$i<$totalNum;$i++)
	{
		$cbname="cb_".$i;
		
		$newInstanceNo=$instanceNo.".".omc_keep_length($i,"0",4);
		$tmpWhere=getLevelWhere("2.4.3.1.4");
		$sql="select readValue from OBJ_320.param_99 where $tmpWhere and instanceNo='$newInstanceNo' ";
		$res=@mysqli_query($pubConn,$sql);
		$row=@mysqli_fetch_array($res);
		
		//do not set dchanal time slot
		if($row[readValue] != 5)
		{
			echo "<tr>";
			echo "<td width=40%>Time Slot-$i</td>";
			echo "<td width=10%><input type=checkbox name=\"$cbname\">";
			echo "</tr>";
		}
	}
	echo "</table>";
	
	echo "<p><input type=submit value=Set><p>";
	
	echo "<input type=\"hidden\" name=\"sysId\" value=\"$sysId\">";
	echo "<input type=\"hidden\" name=\"table_id\" value=\"$table_id\">";
	echo "<input type=\"hidden\" name=\"table_level\" value=\"$table_level\">";
	echo "<input type=\"hidden\" name=\"instanceNo\" value=\"$instanceNo\">";
	echo "</form>";
	
	echo "<b>Remark:</b><br>";
?>
