<?php
/*********************************************************
Description:
    Function£ºCalling prefix parameter edit.
    Invoke£ºheader.inc     
	Author: Lilong
	Date: 4/28/2004
      
Modification notes£º      
NO.1
	Name£º
	Date£º
	Description£º
*********************************************************/  
require("../../inc/header.inc");
$DEBUG = 0;

$sysTypeNo_0 = "111";

if($thisOmcType==10){
	$sysTypeNo_1 = "251";
}else{
	$sysTypeNo_1 = "322";
}

$db_0 = "OBJ_".$sysTypeNo_0;
$db_1 = "OBJ_".$sysTypeNo_1;

$tb_0 = "param_0";
$tb_1 = "param_1";
$tb_2 = "param_99";

$temTb = ${tb_.$sNum};
$subSysNo = floor($pNum/8);
if($DEBUG)echo "<br>subSysNo=$subSysNo";
$portNo = $pNum%8;
if($DEBUG)echo "<br>portNo=$portNo";

//Calling Number manipulation
$oidPas = "2.1.8"; 
$pPas = explode(".",$oidPas);
$i = 0;
$wAnd = '';
while(isset($pPas[$i])){
	$lNum = $i+1;
	if($DEBUG) echo "<br>pPas[$i]=$pPas[$i]";
	$wAnd = $wAnd." AND level_$lNum = $pPas[$i] ";
	$i++;
}
if($DEBUG)	echo "<br>wAnd=$wAnd";

//<!--*********************    DEFINE START:: variable arrays   **********************-->

$prefixFlagArr=array(
	array('num' => '0',  'remark' => 'N', 'color' => '#FF0000'),
	array('num' => '1',  'remark' => 'Y', 'color' => '#0000FF')
);
$tonArr=array(
	array('num' => '0',  'remark' => 'Spare',		'color' => '#FF0000'),
	array('num' => '1',  'remark' => 'MSISDN',		'color' => '#0000FF'),
	array('num' => '2',  'remark' => 'Unknown',		'color' => '#0000FF'),
	array('num' => '3',  'remark' => 'NDD',			'color' => '#0000FF'),
	array('num' => '4',  'remark' => 'IDD',			'color' => '#0000FF'),
	array('num' => '5',  'remark' => 'Spare',		'color' => '#0000FF')
);

$trkDelCArr=array(
	array('num' => '0',  'remark' => 'Delete none',		'color' => '#FF0000'),
	array('num' => '1',  'remark' => 'Delete first one','color' => '#FF0000'),
	array('num' => '2',  'remark' => 'Delete first two','color' => '#FF0000'),
	array('num' => '3',  'remark' => 'Delete first three','color' => '#FF0000'),
	array('num' => '4',  'remark' => 'Delete first four','color' => '#FF0000'),
	array('num' => '5',  'remark' => 'Delete first five','color' => '#FF0000'),
	array('num' => '6',  'remark' => 'Delete first six','color' => '#FF0000'),
	array('num' => '7',  'remark' => 'Delete first seven','color' => '#FF0000'),
	array('num' => '8',  'remark' => 'Delete first eight','color' => '#FF0000')
);

$trkInsCArr=array(
	array('num' => '0',  'remark' => 'Insert none',		'color' => '#FF0000'),
	array('num' => '1',  'remark' => 'Insert first one','color' => '#FF0000'),
	array('num' => '2',  'remark' => 'Insert first two','color' => '#FF0000'),
	array('num' => '3',  'remark' => 'Insert first three','color' => '#FF0000'),
	array('num' => '4',  'remark' => 'Insert first four','color' => '#FF0000'),
	array('num' => '5',  'remark' => 'Insert first five','color' => '#FF0000'),
	array('num' => '6',  'remark' => 'Insert first six','color' => '#FF0000'),
	array('num' => '7',  'remark' => 'Insert first seven','color' => '#FF0000'),
	array('num' => '8',  'remark' => 'Insert first eight','color' => '#FF0000')
);
//<!--*********************    DEFINE END :: variable arrays   **********************-->

if($set || $add)
{	
	$field_0 = omc_keep_length($prefixDigit,E,8,0);
	if($DEBUG)	echo "$field_0=$field_0<br>";

	$field_1 = DecHex($outTon).DecHex($inTon);
	$field_1 = omc_keep_length($field_1,0,2);
	if($DEBUG)	echo "<br>field_1=$field_1";

	$field_2 = DecHex($insNum).DecHex($delNum);
	$field_2 = omc_keep_length($field_2,0,2);
	if($DEBUG)	echo "<br>field_2=$field_2";

	$field_3 = omc_keep_length($insDigit,E,8,0);	
	if($DEBUG)	echo "<br>field_3=$field_3";

	$initValue	= $field_0.$field_1.$field_2.$field_3;
	if($DEBUG)	echo "<br>initValue=$initValue";

	$updateSql = " UPDATE $tb_2 
			set initValue = '$initValue' 
			WHERE subSysNo = '99' AND instanceNo = '$tNum' $wAnd "; 
	if($DEBUG)	echo "<br>updateSql=$updateSql";
	$updateRes = @mysqli_query($pubConn,$updateSql);
	echo mysqli_error($pubConn);

	echo "<script LANGUAGE=\"JavaScript\">";
	echo "window.opener.location.href='./callingPrefixConf.php?scroll_x=$scroll_x&scroll_y=$scroll_y';";		
	echo "\n window.close();";
	echo "\n </script>";
}

/************select value to see************/
//Attributes of TG
$defaultValue[7]	= "EEEEEEEE2200EEEEEEEE";
$dispSql = " SELECT level_3,instanceNo,initValue,editValue,readValue 
			FROM $tb_2 
			WHERE subSysNo = '99' AND instanceNo = '$tNum' ".$wAnd; 
if($DEBUG)	echo "<br>dispSql=$dispSql";
$dispRes = @mysqli_query($pubConn,$dispSql);
$dispRow = @mysqli_fetch_array($dispRes);
echo mysqli_error($pubConn);

do{
	$level_3 = $dispRow[level_3];
	$instanceNo = $dispRow[instanceNo];
	$initValue = $dispRow[initValue];
	if($DEBUG)	echo "<br>initValue=$initValue";
	
	if($initValue == $defaultValue[$level_3]){
		$andShow[$level_3][$instanceNo] = 0;
	}else{
		$andShow[$level_3][$instanceNo] = 1;
	}
	if($DEBUG)	echo "<br>andShow[$level_3][$instanceNo]={$andShow[$level_3][$instanceNo]}";
	
	$prefixDigit	= substr($initValue,0,8);
	$pDigit		= explode("E",$prefixDigit);
	$prefixDigit	= $prefixArr[$instanceNo][0] = $pDigit[0];
	if($DEBUG)	echo "<br>prefixArr[$instanceNo][0]={$prefixArr[$instanceNo][0]}";

	$inTon	= substr($initValue,9,1);
	$outTon	= substr($initValue,8,1);
	if($DEBUG)	echo "<br>inTon=$inTon, outTon=$outTon";

	$delNum		= substr($initValue,11,1);
	$insNum		= substr($initValue,10,1);
	if($DEBUG)	echo "<br>delNum=$delNum, insNum=$insNum";

	$insDigit	= substr($initValue,12,8);
	$pDigit		= explode("E",$insDigit);
	$insDigit	= $insDigitArr[$instanceNo][0] = $pDigit[0];
	if($DEBUG)	echo "<br>insDigitArr[$instanceNo][0]={$insDigitArr[$instanceNo][0]}";

}while($dispRow = @mysqli_fetch_array($dispRes));


echo "<form method=\"POST\" name=\"confForm\" action=\"$PHP_SELF\">";
echo "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">";

//if "ADD", oType == 1
if($oType){
	$preFlagSql = " SELECT instanceNo,initValue,editValue,readValue 
		FROM $tb_2 
		WHERE subSysNo = '99' $wAnd "." ORDER BY instanceNo "; 
	//if($DEBUG)	
		echo "<br>preFlagSql=$preFlagSql,db=$db_1";
	$preFlagRes = @mysqli_query($pubConn,$preFlagSql);
	$preFlagRow = @mysqli_fetch_array($preFlagRes);
	echo mysqli_error($pubConn);
	do
	{
		$instanceNo = $preFlagRow[instanceNo];
		$initValue = $preFlagRow[initValue];
		if($DEBUG)echo "<br>initValue=$initValue";

		$hex_6 = substr($initValue,12,2);
		if($DEBUG)echo "<br>hex_6=$hex_6";
		$bin_6 = omc_keep_length(DecBin(HexDec($hex_6)),0,8);
		if($DEBUG)echo "<br>bin_6=$bin_6";

		$prefixFlag = $prefixFlagArr[$instanceNo][0] = BinDec(substr($bin_6,1,1));
		//echo "<br>prefixFlag=$prefixFlag";
	}while($preFlagRow = @mysqli_fetch_array($preFlagRes));
	
	
	echo "<tr>";
	echo "<td colspan=\"4\"><b>Add Dailing prefix</b></td>";
	echo "</tr>";

	
	echo "<tr>";
	echo "<td width=\"60\" valign=middle><nobr>Prefix no.</nobr></td>";
	echo "<td colspan=\"2\">";
	echo "<select style=\"font-family: Verdana; font-size: 8pt\" size=\"1\" name=\"tNum\" id=\"tNum\">";
	for($i=0;$i<256;$i++)
	{
		//if(!$prefixFlagArr[$i][0])
			echo "<option value=\"$i\">$i</option>";
	}
	echo "</select>";
	echo "</td>";
	echo "</tr>";


}else{
	echo "<tr>";
	echo "<td colspan=\"4\"><b>Calling number manipulation #$tNum</b></td>";
	echo "</tr>";
}

echo "<tr>";
echo "<td width=\"60\" valign=middle><nobr>8-digit prefix for calling number</nobr></td>";
echo "<td colspan=\"2\"><input type=\"text\" name=\"prefixDigit\" size=\"8\" value=\"$prefixDigit\" maxLength=\"8\"></td>";
echo "</tr>";

echo "<tr>";
echo "<td width=\"60\" valign=middle><nobr>TON for incoming call</nobr></td>";
echo "<td colspan=\"2\">";
echo "<select style=\"font-family: Verdana; font-size: 8pt\" size=\"1\" name=\"inTon\" id=\"inTon\">";
for($i=0;$i<6;$i++){
	if($inTon == $i)
		echo "<option value=\"$i\" selected>{$tonArr[$i][remark]}</option>";
	else
		echo "<option value=\"$i\">{$tonArr[$i][remark]}</option>";
}
echo "</select>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td width=\"60\" valign=middle><nobr>TON for outgoing call</nobr></td>";
echo "<td colspan=\"2\">";
echo "<select style=\"font-family: Verdana; font-size: 8pt\" size=\"1\" name=\"outTon\" id=\"outTon\">";
for($i=0;$i<6;$i++){
	if($outTon == $i)
		echo "<option value=\"$i\" selected>{$tonArr[$i][remark]}</option>";
	else
		echo "<option value=\"$i\">{$tonArr[$i][remark]}</option>";
}
echo "</select>";
echo "</td>";
echo "</tr>";


echo "<tr>";
echo "<td width=\"60\" valign=middle><nobr>Out trunk deletion count</nobr></td>";
echo "<td colspan=\"2\">";
echo "<select style=\"font-family: Verdana; font-size: 8pt\" size=\"1\" name=\"delNum\" id=\"delNum\">";
for($i=0;$i<9;$i++){
	if($delNum == $i)
		echo "<option value=\"$i\" selected>{$trkDelCArr[$i][remark]}</option>";
	else
		echo "<option value=\"$i\">{$trkDelCArr[$i][remark]}</option>";
}
echo "</select>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td width=\"60\" valign=middle><nobr>Out trunk insertion count</nobr></td>";
echo "<td colspan=\"2\">";
echo "<select style=\"font-family: Verdana; font-size: 8pt\" size=\"1\" name=\"insNum\" id=\"insNum\">";
for($i=0;$i<9;$i++){
	if($insNum == $i)
		echo "<option value=\"$i\" selected>{$trkInsCArr[$i][remark]}</option>";
	else
		echo "<option value=\"$i\">{$trkInsCArr[$i][remark]}</option>";
}
echo "</select>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td width=\"60\" valign=middle><nobr>Inserted digits (0 - 99,999,999)</nobr></td>";
echo "<td colspan=\"2\"><input type=\"text\" name=\"insDigit\" size=\"8\" value=\"$insDigit\" maxLength=\"8\"></td>";
echo "</tr>";

echo "</table>";

echo "<br>";
if($oType){
	echo "<input type=\"submit\" name=\"add\" value = \"Add\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">"; 
}else{
	echo "<input type=\"submit\" name=\"set\" value = \"Set\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">"; 
	echo "<input type=\"hidden\" name=\"tNum\" value =\"$tNum\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
}
echo "<input type=\"reset\" name=\"Reset\" value =\"Reset\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
echo "<input type=\"hidden\" name=\"scroll_x\" value =\"$scroll_x\">";
echo "<input type=\"hidden\" name=\"scroll_y\" value =\"$scroll_y\">";

echo "</form>";
?>
<b>Remarks:</b><br><br>
byte4: type of number(TON)
bit0-3: TON for incoming call, specified by the originating node for the terminating node to route this call with proper dialed number manipulation.0=spare,1=MSISDN,2=unknown,3=NDD,4=IDD,other=spare,this setup is invalid for prefix 252 to 255
bit4-7: TON for outgoing call, used to specify the type of an outgoing call for the terminating node to route this call with proper dialed number digit mannipulation.0=spare,1=MSISDN,2=unknown,3=NDD,4=IDD,other=spare
</body>
</html>