<?php
/*********************************************************      
 程序说明：         
    功能说明：列表显示账号信息，默认显示第一页用户资料
              
    调用关系：调用: header.inc    
              被调用:        
 
    变量说明：

    作者：    
      
修改注释：      
NO.1      
姓名：Cui Ticun          
时间：2004-8-29
修改说明：Support OMC8.0,modify the PPS subscriber filed
*********************************************************/
require("../../inc/header.inc");
$DEBUG = 0;
if($DEBUG) echo "<br>正在调试中！！";
//==========================================================
//变量定义
//==========================================================
$pubDb				= 'OMC_PUB';
$sysSubsConfTable	= 'OMC_PUB.sysSubsConf';
$systemConfTable	= 'OMC_PUB.sysConf';
$numberPerPage		= 100;		//每页纪录数

$nReadComm		= 1;
$nChangeComm	= 2;
$nCreateComm	= 3;
$nDeleteComm	= 4;
$nLoadIndexComm	= 5;

//确定告警内容显示语言种类
if($language=='eng'){
	$alarmDesc	= alarmDesc_1;
}else{
	$alarmDesc	= alarmDesc_2;
}

//==========================================================
//输入变量
//==========================================================
if($DEBUG) echo "<br>sysTypeNo=$sysTypeNo";
$dataTypeNo = $_REQUEST['dataTypeNo'];
$sysTypeNo = $_REQUEST['sysTypeNo'];

$bgnNo = $_REQUEST['bgnNo'];
if($DEBUG) echo "<br>dataTypeNo=$dataTypeNo";
$commType = $_REQUEST['commType'];
$keyValue = $_REQUEST['keyValue'];
//if(1) echo "<br>sysTypeNo=$sysTypeNo";
if ($_REQUEST['sysId'])
{
	$sysId =   $_REQUEST['sysId'];
	if($DEBUG) echo "<br>sysId=$sysId";
	$sysIdArr=explode('_',$sysId);
	$sysTypeNo=$sysIdArr[0];
	$sysNo=$sysIdArr[1];
	//	echo "sysTypeNo=$sysTypeNo,sysNo=$sysNo";
}


if(!isset($sysNo))
	$sysNo=0;
//echo "<br>sysId=$sysId";
//根据sysTypeNo,dataTypeNo获取数据表名，索引字段名
if($sysTypeNo==390){
	if(!isset($sysId))
		$sysId='390_0_0';
	$sysIdArr=explode('_',$sysId);
	$sysNo=$sysIdArr[1];
	$getConfSql="SELECT indexFieldName,subsDataTable,tmpDataTable  
				FROM $sysSubsConfTable
				WHERE sysTypeNo='$sysTypeNo' 
				AND dataTypeNo='$dataTypeNo'
				AND sysNo='$sysNo'
				";
}else{
	$getConfSql="SELECT indexFieldName,subsDataTable,tmpDataTable  
				FROM $sysSubsConfTable
				WHERE sysTypeNo='$sysTypeNo' 
				AND dataTypeNo='$dataTypeNo'
				";
}
if($DEBUG) echo "<br>getConfSql=$getConfSql";
$getConfResult=mysqli_query($pubConn,$getConfSql);
echo mysqli_error($pubConn);
$getConfRows=mysqli_fetch_array($getConfResult);
$tableName		=$getConfRows[subsDataTable];
$keyFieldName	=$getConfRows[indexFieldName];


if($DEBUG) echo "<br>tableName=$tableName";
if($DEBUG) echo "<br>keyFieldName=$keyFieldName";
//排序所依赖的字段名
if(!isset($orderByField)){
	$orderByField  = $keyFieldName;	
}
if($DEBUG) echo "<br>orderByField=$orderByField";

//排序字符串
$orderByStr = " $orderByField";
if($DEBUG) echo "<br>orderByStr=$orderByStr";


//==========================================================
//数据处理
//==========================================================
//处理删除命令返回
if($commType  == $nDeleteComm){
	$delSql = "DELETE FROM $tableName WHERE $keyFieldName = '$keyValue'";
	if($DEBG) echo "<br>delSql=$delSql";
	mysqli_query($srcDataConn,$delSql);
	echo mysqli_error($srcDataConn);
}
//echo "a=$sysTypeNo";
//定义各个系统的变量
switch($sysTypeNo){
	case '330':
		$sysTypeName='HLR';
		$canSetNum='all';
		$tableWidth='100%';
		$selectFieldList = "imsi,inter_msisdn,used_flag,nam,camel_flag";
		$showNameList="IMSI,MSISDN,Used flag,Network Access mode,Camel flag";
		$targetPage="./hlrSubsConf.php";
		//$targetPage="./subscriberConfig.php";
		break;
	case '325':
		$sysTypeName='VLR';
		$canSetNum='all';
		$tableWidth='100%';
		$selectFieldList = "IMSI,MSISDN,IMSIDetachFlag,LAI,O_CSI";
		$showNameList = "IMSI,MSISDN,Attach,LAI (MCC-MNC-LAC),O_CSI Flag";
		$targetPage="./vlrSubsConf.php";
		//$targetPage="./subscriberConfig.php";
		break;
	case '360':
		$pssCardMinCount = getPubVar('pssCardMinCount') - 0;
		$dotLen = strLen($pssCardMinCount) - 1;
		$fmtBit = "%01.".$dotLen."f";

		if($dataTypeNo == 0){
			$sysTypeName='PPS';
			$canSetNum='all';
			$tableWidth='100%';
			$selectFieldList = "msisdn,status,balance,mo_expiration_date,mt_expiration_date,cug_id,access_date";
			$showNameList= "MSISDN,Status,Balance,Expiration(MO),Expiration(MT),CUG,Active since";
			$targetPage="./ppsSubsConf.php";
			//$targetPage="./subscriberConfig.php";
		}else{
			$sysTypeName='Prepaid Card';
			$canSetNum='all';
			$tableWidth='100%';
			$selectFieldList ="card_no,face_value,card_status,expiry_date,valid_time,updated_date,msisdn_used";
			$showNameList="Card no.,Face value,Status,Expiry date,Valid days,Updated date,MSISDN";
			$targetPage="./ppsCardConf.php";
		}
		break;
	case '395':
		$pssCardMinCount = getPubVar('pssCardMinCount') - 0;
		$dotLen = strLen($pssCardMinCount) - 1;
		$fmtBit = "%01.".$dotLen."f";

		if($dataTypeNo == 0){
			$sysTypeName='RCM';
			$canSetNum='all';
			$tableWidth='100%';
			$selectFieldList = "msisdn,status,balance,mo_expiration_date,mt_expiration_date,cug_id,access_date";
			$showNameList= "MSISDN,Status,Balance,Expiration(MO),Expiration(MT),CUG,Active since";
			$targetPage="./rcmSubsConf.php";
		}else{
			$sysTypeName='Prepaid Card';
			$canSetNum='all';
			$tableWidth='100%';
			$selectFieldList ="card_no,face_value,card_status,expiry_date,valid_time,updated_date,msisdn_used";
			$showNameList="Card no.,Face value,Status,Expiry date,Valid days,Updated date,MSISDN";
			$targetPage="./rcmCardConf.php";
		}
		break;
	case '370':
		$sysTypeName='MNP';
		$canSetNum='all';
		$tableWidth='100%';
		$selectFieldList = "msisdn,status,routing_number,donor,recipient,date";
		$showNameList = "MSISDN,Status,Routing number,Donor,Recipient,Date";
		$targetPage="./mnpSubsConf.php";
		break;
	case '375':
		$sysTypeName='OPPS';
		$canSetNum='all';
		$tableWidth='100%';
		//$selectFieldList = "msisdn,imei,imsi,oprFlag,type,status";
		$selectFieldList = "msisdn,imsi,imei,oprFlag,class";
		//$showNameList="MSISDN,Imei,Imsi,Opr Flag,type,Status";
		$showNameList="MSISDN,IMSI,IMEI,User Status,Class";
		$targetPage="./oprSubsConf.php";
		//$targetPage="./subscriberConfig.php";
		break;	
	case '378':
		$sysTypeName='iPALIM';
		$canSetNum='all';
		$tableWidth='100%';
		$selectFieldList = "imsi,msisdn,msisdn_extern,tmsi,lai,type";
		$showNameList = "IMSI,MSISDN Public,MSISDN Private,TMSI,MCC-MNC-LAC-CI,Type";
		$targetPage="./ipalimSubsConf.php";
		break;
	case '340':
		$sysTypeName='AUC';
		$canSetNum='all';
		$tableWidth='100%';
		$selectFieldList = "key_imsi,a3a8_version,status";
		$showNameList = "IMSI,A3A8 version,Service Status";
		$targetPage="./aucSubsConf.php";
		//$targetPage="./subscriberConfig.php";
		break;
	case '380':
		$sysTypeName='EIR';
		$canSetNum='all';
		$tableWidth='50%';
		$selectFieldList = "imei,status";
		$showNameList= "IMEI,Status";
		$targetPage="./eirSubsConf.php";
		//$targetPage="./subscriberConfig.php";
		break;
	case '390':
		$sysTypeName='VMS';
		$canSetNum='all';
		$tableWidth='100%';
		$selectFieldList = "msisdn,mailboxID,promo_language,greeting,pwdValue";
		$showNameList= "MSISDN,Mailbox No.,Language,Greeting type,Password";
		$targetPage="./vmsSubsConf.php";
		//$targetPage="./subscriberConfig.php";
		break;
	case '253':
		$sysTypeName='SN-HLR';
		$canSetNum='all';
		$tableWidth='100%';
		$selectFieldList = "imsi,msisdn,used_flag,lac";
		$showNameList= "imsi,msisdn,used_flag,lac";
		$targetPage="./snHlrSubsConf.php";
		break;
	default:
		echo "Unknown sysTypeNo";
		exit(1);
}
global $OMC_server;
$srcDataConn = mysqli_connect($OMC_server[0]['host'],$OMC_server[0]['user'],$OMC_server[0]['password'], $sysTypeName."_DB");

//获取活动的系统id
if($sysTypeNo==390)
	$getSysIdSql = "SELECT sysNo,subSysNo FROM OMC_PUB.sysInfo 
				WHERE sysTypeNo='$sysTypeNo' AND sysNo='$sysNo'  
				ORDER BY baseStat DESC,updateTime DESC";
else
	$getSysIdSql = "SELECT sysNo,subSysNo FROM OMC_PUB.sysInfo 
				WHERE sysTypeNo='$sysTypeNo' 
				ORDER BY baseStat DESC,updateTime DESC";
//if($DEBUG)
// debug_log("/tmp/debug.txt",$getSysIdSql);
$getSysIdResult=mysqli_query($pubConn,$getSysIdSql);
// debug_log("/tmp/debug.txt",$getSysIdResult);
echo mysqli_error($pubConn);
//debug_log("/tmp/debug.txt",mysqli_num_rows($getSysIdResult));
if(mysqli_num_rows($getSysIdResult) > 0 ||$sysTypeNo==330){
	
	$getSysIdRows=mysqli_fetch_array($getSysIdResult);
	$sysNo		= $getSysIdRows[sysNo];
	$subSysNo	= $getSysIdRows[subSysNo];
	$sysId = $sysTypeNo.'_'.$sysNo.'_'.$subSysNo;
}else{
	?>
	<body leftmargin="15" rightmargin="10" onload="javascript:adjust_frame('down');" onresize="javascript:adjust_frame('down');" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">

<?php
adjust_head_frame("down");
adjust_title_head_frame("down");
adjust_title_tail_frame("down");
adjust_content_head_frame("down");

	echo "<br><font size=3 color=red>Can not find this system's IP in system List,";
	echo "Please add it!</font>";
adjust_content_tail("down");
	exit(0);
}

$showFieldArr=explode(',',$selectFieldList);
$showNameArr=explode(',',$showNameList);

//根据上部页面传来的变量，生成查询条件
//debug_log("/tmp/debug.txt",$selKeyFieldName);
//debug_log("/tmp/debug.txt",$selKeyValue);
$selKeyFieldName = $_REQUEST['selKeyFieldName'];
$selKeyValue = $_REQUEST['selKeyValue'];
if(strlen($selKeyFieldName) > 0 && strlen($selKeyValue) > 0){
	$whereStr = "WHERE $selKeyFieldName like '%$selKeyValue%'";
}

if(strlen($selKeyFieldName) > 0 && strlen($selKeyValue) > 0 &&$sysTypeNo==330){
	$whereFlag=" and $selKeyFieldName like '%$selKeyValue%'";
}

if($DEBUG)echo "sysTypeNo=$sysTypeNo,opps_type_sel=$opps_type_sel<br>";
if($sysTypeNo == 375)
{
	if(!isset($opps_type_sel))
		$opps_type_sel=0;
	if($opps_type_sel == 1)
	{
		$whereStr="WHERE oprFlag>=0 and oprFlag<=3 ";
	}
	else if($opps_type_sel == 2)
	{
		$whereStr="WHERE oprFlag>=4 and oprFlag<=5 ";
	}
	if(strlen($selKeyFieldName) > 0 && strlen($selKeyValue) > 0)
	{
		$whereStr.="and $selKeyFieldName like '%$selKeyValue%'";
	}
	//0-3,4-5	
}
//查询基本条件
if(strlen($whereStr) > 10){
	$bascWhereStr ="";
}else{
	$bascWhereStr ="";
}

//首次查询，查出符合条件的纪录条数，并在以后的页面跳转中传递。
$numberOfRecords = $_REQUEST['numberOfRecords'];
$numberOfFlagRecords = $_REQUEST['numberOfFlagRecords'];

if(!$numberOfRecords){
	$bgnNo=0;
	$countSql="SELECT  count(*) as totalNum
				FROM $tableName
				$whereStr
				$bascWhereStr
				";
	if($DEBUG) echo "<br>countSql=$countSql";
	//debug_log("/tmp/debug.txt",$countSql);
	$result=mysqli_query($srcDataConn,$countSql);
	//debug_log("/tmp/debug.txt",$result);
	echo mysqli_error($srcDataConn);
	$record = @mysqli_fetch_array($result);
	//debug_log("/tmp/debug.txt",$record);
	$numberOfRecords = $record[0];
	if($DEBUG) echo "<br>numberOfRecords=$numberOfRecords";
	//debug_log("/tmp/debug.txt",$numberOfRecords);

	if($sysTypeNo==330){
		$selUsedFlagSql="SELECT  count(*) as totalFlag
		FROM $tableName
		WHERE used_flag = '01'
		$whereFlag
		$bascWhereStr
		";
		if($DEBUG) echo "<br>selUsedFlagSql=$selUsedFlagSql";
		$flagResult=mysqli_query($pubConn,$selUsedFlagSql);
		echo mysqli_error($pubConn);
		$flagRecord = @mysqli_fetch_array($flagResult);
		$numberOfFlagRecords = $flagRecord[0];
	}

	if($numberOfRecords > 0){
		//debug_log("/tmp/debug.txt","test2");
		//插入日志
		//insertLog("search $sysTypeName subscriber: $selKeyValue ");
	}else{
		//debug_log("/tmp/debug.txt","test3");
		//插入日志
		//insertLog("search $sysTypeName subscriber: $selKeyValue not found");
		?>
		<body leftmargin="15" rightmargin="10" onload="javascript:adjust_frame('down');" onresize="javascript:adjust_frame('down');" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">

		<?php
adjust_head_frame("down");
adjust_title_head_frame("down");
adjust_title_tail_frame("down");

adjust_content_head_frame("down");	
echo "<br>";
		echo "<br>$strNotFindRecord";
adjust_content_tail("down");
		exit();
	}
}
//debug_log("/tmp/debug.txt","test");
//找到需要显示的纪录
if($numberOfRecords > 0){ 
	$showSql=" SELECT  $selectFieldList
				FROM $tableName
				$whereStr
				$bascWhereStr
				ORDER BY $orderByStr
				LIMIT $bgnNo, $numberPerPage
			";
	if($DEBUG) echo "<br>showSql=$showSql";
	$result=@mysqli_query($srcDataConn,$showSql);
	echo mysqli_error($srcDataConn);
	$rows=@mysqli_fetch_array($result);

	//下面是控制分页显示需要传递的变量传递变量  
	if ($numberOfRecords >= 1) {
		$nextBgnNo = $bgnNo + $numberPerPage;  //本页的结束数目  
		if ($nextBgnNo > $numberOfRecords){  
			$nextBgnNo = $numberOfRecords;  
		}  
		$t1 = $bgnNo + 1;  
		$prevBgnNo = $bgnNo - $numberPerPage;  
		if ($prevBgnNo < 0) {  
			$prevBgnNo = 0;  
		}
		if($sysTypeNo==390)
			$basePageLink	="sysTypeNo=$sysTypeNo&sysId=$sysId&dataTypeNo=$dataTypeNo&numberOfRecords=$numberOfRecords&orderByField=$orderByField";
		else if($sysTypeNo==330)
		$basePageLink	="sysTypeNo=$sysTypeNo&sysId=$sysId&dataTypeNo=$dataTypeNo&numberOfRecords=$numberOfRecords&numberOfFlagRecords=$numberOfFlagRecords";
		else
			$basePageLink	="sysTypeNo=$sysTypeNo&dataTypeNo=$dataTypeNo&numberOfRecords=$numberOfRecords&orderByField=$orderByField";

		$basePageLink	.="&selKeyFieldName=$selKeyFieldName&selKeyValue=$selKeyValue";
		$prePageLink	="bgnNo=$prevBgnNo";
		$nextPageLink	="bgnNo=$nextBgnNo";
	}  
	$showBgnNo=$bgnNo+1;
}

//==========================================================
//输出并显示数据
//==========================================================
?>

<script LANGUAGE="JavaScript">  
function gotoPage(){
		var pageUrl,bgnNo,numberPerPage;
		pageNo=document.selectform.pageNo.value;
		numberPerPage='<?php echo "$numberPerPage";?>';
		bgnNo=numberPerPage*(pageNo-1);
		baseUrl='<?php echo "$PHP_SELF?$basePageLink";?>';
		pageUrl="&bgnNo="+bgnNo;
		window.location.href=baseUrl+pageUrl;     
}      
</script>

<body leftmargin="15" rightmargin="10" onload="javascript:adjust_frame('down');" onresize="javascript:adjust_frame('down');" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">

<form name="selectform">

<!--   subscriber overview     -->
<?php
require("./subsOverview.php");
?>

<?php 
adjust_head_frame("down");
adjust_title_head_frame("down");
adjust_title_tail_frame("down");
adjust_content_head_frame("down");	
echo "<br>";

echo "<TABLE  border=\"0\" width=\"100%\" cellpadding=\"2\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\">      
";
echo "<TR><TD>";
echo "$strDisplayRecords<FONT color=#0000ff>&nbsp;$showBgnNo - $nextBgnNo</FONT>, ";
if($sysTypeNo==330){
	echo "($strTotal:$numberOfRecords,IMSI Enabled:$numberOfFlagRecords)";   
}else{
	echo "($strTotal:$numberOfRecords)";   
}
echo "</TD>";
echo "<TD align=\"right\">";		
	// NEW: Display a link for the previous set of records.  
	if ($bgnNo != 0) {  
		echo "<a href=\"$PHP_SELF?$basePageLink&$prePageLink\">"; 
		echo "Previous&nbsp;<IMG alt=$strPreviousPage align=absBottom border=0  src=../../images/left.gif ></a>&nbsp;"; 
	}else{
		echo "<font color=\"#808080\">Previous&nbsp;</font><IMG alt=$strPreviousPage align=absBottom border=0  src=../../images/left_1.gif ></a>&nbsp;"; 
	} 

	//根据纪录条数，算出页码数，本页页码
	if($numberOfRecords > 0){
		$totalPageNum = ceil($numberOfRecords / $numberPerPage );
		$pageNo = $bgnNo / $numberPerPage + 1;
	}

	echo "<SELECT size=\"1\" name=\"pageNo\" onChange=\"javasript:gotoPage()\">"; 
	for($i=1;$i<=$totalPageNum;$i++){
		$listBgnNo	=($i-1)*$numberPerPage+1;
		$listEndNo	=$i*$numberPerPage;
		$listShow	=$listBgnNo.'-'.$listEndNo;
		if($i== $pageNo){
			echo "<option  selected  value=\"$i\" >$listShow</option>";
		}else{
			echo "<option value=\"$i\">$listShow</option>";
		}
	}
	echo "</SELECT>";

	// NEW: Display a link for the next set of records.  
	if ($nextBgnNo != $numberOfRecords && $numberOfRecords >0) {  
		echo "<a href=\"$PHP_SELF?$basePageLink&$nextPageLink\">";  
		echo "<IMG alt=$strNextPage align=absBottom border=0  src=../../images/right.gif >&nbsp;Next</a>";  
	}else{
		echo "<IMG alt=$strNextPage align=absBottom border=0  src=../../images/right_1.gif ><font color=\"#808080\">&nbsp;Next</font>";  
	} 
?>
	</TD>
  </TR>  
</TABLE> 

<?php
echo "<TABLE  border=\"1\" width=\"$tableWidth\" cellpadding=\"1\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\">";
echo "<tr bgcolor=\"#E6E6E6\">";
for($i=0;$i<sizeof($showFieldArr);$i++){
	echo "<td align=\"center\">";
	echo "<a href=\"$PHP_SELF?sysTypeNo=$sysTypeNo&dataTypeNo=$dataTypeNo&orderByField=$showFieldArr[$i]&selKeyFieldName=$selKeyFieldName&selKeyValue=$selKeyValue\">";
	echo "$showNameArr[$i]</a>";
	echo "</td>";
}
?>
  </tr>

<?php 
switch($sysTypeNo){
	case '375':
		do{
			echo "<tr>";
			$nPos=0;
			$msisdn=$rows[$nPos++];
			if(trim($msisdn)=="")
				continue;
			echo "<td align=\"center\">";
			echo "<a href=\"$targetPage?sysId=$sysId&dataTypeNo=$dataTypeNo&";
			echo "keyValue={$rows[$keyFieldName]}&canSetNum=$canSetNum&isRead=1\">&nbsp;$msisdn</a>";
			echo "</td>";
			
			//imsi
			$imsi=$rows[$nPos++];
			echo "<td align=\"center\">";
			echo "&nbsp;$imsi";
			echo "</td>";
			
			//IMEI
			$imei=$rows[$nPos++];
			echo "<td align=\"center\">";
			echo "&nbsp;$imei";
			echo "</td>";
			
			//oprFlag
			$oprFlag_label=array(
				0=>"OPR-0",//0=>"Not Registered",
				1=>"OPR-1",//1=>"OprStateWithoutRoamingAgreement",
				2=>"OPR-2a",//2=>"OprStateWithRoamingAgreement",
				3=>"OPR-2b",//3=>"RoamingState",
				4=>"IMDX-P1",
				5=>"IMDX-P2",
				6=>"IMDX-H");
			$oprFlag=$rows[$nPos++]+0;
			echo "<td align=\"center\">";
			echo "&nbsp;{$oprFlag_label[$oprFlag]}";
			echo "</td>";

			$oprClass_label=array(
                                0=>"Ordinary",
                                1=>"Premium",
                                2=>"VIP"
                              );
                        $oprClass=$rows[$nPos++]+0;
                        echo "<td align=\"center\">";
                        echo "&nbsp;{$oprClass_label[$oprClass]}";
                        echo "</td>";

			//type
			/*
			$type_label=array(0=>"Trial",1=>"Normal");
			$type=$rows[$nPos++]+0;
			echo "<td align=\"center\">";
			echo "&nbsp;{$type_label[$type]}";
			echo "</td>";
			*/
			/*
			//status
			$status_label=array(0=>"Idle",1=>"Msisdn Allocated",2=>"Msisdn Registered");
			$status=$rows[$nPos++]+0;
			echo "<td align=\"center\">";
			echo "&nbsp;{$status_label[$status]}";
			echo "</td>";
			echo "</tr>";
			*/
		}while($rows=mysqli_fetch_array($result));
		break;
	case '378':
		do{
			echo "<tr>";
			$nPos=0;
			$imsi=$rows[$nPos++];
			if(trim($imsi)=="")
				continue;
			echo "<td align=\"center\">";
			echo "<a href=\"$targetPage?sysId=$sysId&dataTypeNo=$dataTypeNo&";
			echo "keyValue={$rows[$keyFieldName]}&canSetNum=$canSetNum&isRead=1\">&nbsp;$imsi</a>";
			echo "</td>";
			$ipalim_type=$rows[5]+0;
			$msisdn=$rows[$nPos++];
			if($ipalim_type == 0)
				$msisdn="N/A";
			echo "<td align=\"center\">";
			echo "&nbsp;$msisdn";
			echo "</td>";

			$msisdn_extern=$rows[$nPos++];
			if($ipalim_type == 1)
				$msisdn_extern="N/A";
                        echo "<td align=\"center\">";
                        echo "&nbsp;$msisdn_extern";
                        echo "</td>";

                        $tmsi=$rows[$nPos++];
                        echo "<td align=\"center\">";
                        echo "&nbsp;$tmsi";
                        echo "</td>";

                        $lai=$rows[$nPos++];
			$lai_mcc=substr($lai,0,3);
			$lai_mnc=substr($lai,3,3);
			$lai_lai=substr($lai,6,4);
			$lai_ci=substr($lai,10,4);
                        echo "<td align=\"center\">";
                        echo "&nbsp;$lai_mcc-$lai_mnc-$lai_lai-$lai_ci";
                        echo "</td>";


			$ipalim_type_label=array(0=>"Private",1=>"Public",2=>"Hybrid");
			$ipalim_type=$rows[$nPos++]+0;
			echo "<td align=\"center\">";
			echo "&nbsp;{$ipalim_type_label[$ipalim_type]}";
			echo "</td>";
		}while($rows=mysqli_fetch_array($result));
		break;
	case '330':
		//$selectFieldList = "imsi,inter_msisdn,used_flag,nam,CamelFlag";
		do{
			echo "<tr>";
			//$imsi=substr($rows[imsi],1);
			
			$imsi=$rows[imsi];
			echo "<td align=\"center\">";
			echo "<a href=\"$targetPage?sysId=$sysId&dataTypeNo=$dataTypeNo&";
			echo "keyValue={$rows[$keyFieldName]}&canSetNum=$canSetNum&isRead=1\">&nbsp;$imsi</a>";
			//echo "keyValue={$rows[$keyFieldName]}&canSetNum=$canSetNum&isRead=1\">&nbsp;$targetPage?sysId=$sysId&dataTypeNo=$dataTypeNo&keyValue={$rows[$keyFieldName]}&canSetNum=$canSetNum&isRead=1</a>";
			echo "</td>";
			//inter_msisdn
			//$inter_msisdn=decodeTelNumber($rows[inter_msisdn]);
			$inter_msisdn=$rows[inter_msisdn];

			echo "<td align=\"center\">";
			echo "&nbsp;$inter_msisdn";
			echo "</td>";
			//used_flag
			$used_flag=$rows[used_flag];
			echo "<td align=\"center\">";
			if($used_flag > '00'){
				echo "Enable";
			}else{
				echo "Disable";
			}
			echo "</td>";
			//nam
			$netAcsModeDef=array('Both','Non-GPRS only','GPRS only');
			$nam=$rows[nam] - 0;
			echo "<td align=\"center\">{$netAcsModeDef[$nam]}</td>";
			
			//CamelFlag
			$CamelFlag=HexDec(substr($rows[camel_flag],0,1))&0x8;
			echo "<td align=\"center\">";
			if($CamelFlag > 0){
				echo "Enable";
			}else{
				echo "Disable";
			}
			echo "</td>";

			echo "</tr>";
		}while($rows=mysqli_fetch_array($result));
		break;
	case '325':
		//$selectFieldList = "IMSI,MSISDN,TMSI,LMSI";
		do{
			echo "<tr>";
			$IMSI=$rows[IMSI];
			echo "<td align=\"center\">";
			echo "<a href=\"$targetPage?sysId=$sysId&dataTypeNo=$dataTypeNo&";
			echo "keyValue={$rows[$keyFieldName]}&canSetNum=$canSetNum&isRead=1\">&nbsp;$IMSI</a>";
			echo "</td>";
			//MSISDN
			$MSISDN=str_replace('F','',$rows[MSISDN]); 
			echo "<td align=\"center\">";
			echo "&nbsp;$MSISDN";
			echo "</td>";
			
			//IMSIDetachFlag
			$IMSIDetachFlag=$rows[IMSIDetachFlag];
			echo "<td align=\"center\">";
			if($IMSIDetachFlag > 0){
				echo "N";
			}else{
				echo "Y";
			}
			echo "</td>";

			//LAI(MCC+MNC+LAC)
			$LAI=$rows[LAI];
			echo "<td align=\"center\">";

			$MCC=substr($LAI,0,2);
			$MCC=strrev($MCC);
			$MCC=$MCC.strrev(substr($LAI,2,2));
			$MCC=str_replace("F","",$MCC);
			$MNC=substr($LAI,4,2);
			$MNC=strrev($MNC);
			$MNC=str_replace("F","",$MNC);
			$LAC=substr($LAI,-4);
			//$LAC=str_replace("F","",$LAC);
			echo "$MCC-$MNC-$LAC";
			echo "</td>";
			
			//O_CSI Flag
			$O_CSI=$rows[O_CSI];
			echo "<td align=\"center\">";
			if(strlen($O_CSI) > 0){
				echo "Y";
			}else{
				echo "N";
			}
			echo "</td>";

			echo "</tr>";
		}while($rows=mysqli_fetch_array($result));
		break;
	case '360':		//PPS
		if($dataTypeNo == 0){
			//$selectFieldList = "msisdn,status,balance,expiration_date(MO),expiration_date(MT),first_used_date";
			do{
				echo "<tr>";
				//msisdn
				$msisdn=$rows[msisdn];
				echo "<td align=\"right\">";
				echo "<a href=\"$targetPage?sysId=$sysId&dataTypeNo=$dataTypeNo&";
				echo "keyValue={$rows[$keyFieldName]}&canSetNum=$canSetNum&isRead=1\">&nbsp;$msisdn</a>";
				echo "</td>";

/*
				//overdraft
				$overdraft=$rows[overdraft] / $pssCardMinCount;
				$overdraft = sprintf ("$fmtBit", $overdraft);
				$overdraft=showComma($overdraft);
				echo "<td align=\"right\">";
				echo "&nbsp;$overdraft";
				echo "</td>";
*/				

				//status
				$statusDef=array(array('00','fresh'),array('01','used'),array('02','suspended'),
								array('03','black list'),array('04','released'),array('05','OPR trial')
							);
				$status=$rows[status];
				echo "<td align=\"center\">";
				for($i=0;$i<sizeof($statusDef);$i++){
					if($statusDef[$i][0] == $status){
						echo "{$statusDef[$i][1]}";
						break;
					}elseif($i == sizeof($statusDef)-1){
						echo "unknown";
					}
				}
				echo "</td>";

				//balance
				$balance=$rows[balance] ;// $pssCardMinCount;
				$balance=sprintf ("$fmtBit", $balance);
				$balance=showComma($balance);
				echo "<td align=\"right\">";
				echo "&nbsp;$balance";
				echo "</td>";
				
				//mo_expiration_date
				$expiration_date=substr($rows[mo_expiration_date],0,8);
				echo "<td align=\"right\">";
				echo "&nbsp;$expiration_date";
				echo "</td>";
				
				//mt_expiration_date
				$expiration_date=substr($rows[mt_expiration_date],0,8);
				echo "<td align=\"right\">";
				echo "&nbsp;$expiration_date";
				echo "</td>";

				//Close user group
				$sCugId=substr($rows[cug_id],0,8);
				echo "<td align=\"right\">";
				echo "&nbsp;$sCugId";
				echo "</td>";

				//first_used_date
				$first_used_date=substr($rows[access_date],0,8);
				echo "<td align=\"right\">";
				echo "&nbsp;$first_used_date";
				echo "</td>";
				
				echo "</tr>";
			}while($rows=mysqli_fetch_array($result));
		}else{
			//$selectFieldList ="card_no,card_hrn,face_value,card_status,expiry_date,valid_time,updated_date";
			do{
				echo "<tr>";
				//card_no
				$card_no=$rows[card_no];
				echo "<td align=\"right\">";
				echo "<a href=\"$targetPage?sysId=$sysId&dataTypeNo=$dataTypeNo&";
				echo "keyValue=$card_no&canSetNum=$canSetNum&isRead=1\">&nbsp;$card_no</a>";
				echo "</td>";
				
				//face_value
				$face_value=$rows[face_value]; // $pssCardMinCount;
				$face_value=sprintf ("$fmtBit", $face_value);
				echo "<td align=\"right\">";
				echo "&nbsp;$face_value";
				echo "</td>";
				
				//card_status
				$card_status=$rows[card_status];
				echo "<td align=\"center\">";
				if($card_status == 0){
					echo "fresh";
				}else if($card_status == 1){
					echo "used";
				}else if($card_status == 2){
					echo "suspended";
				}
				echo "</td>";
				
				//expiry_date
				$expiry_date=substr($rows[expiry_date],0,8);
				echo "<td align=\"right\">";
				echo "&nbsp;$expiry_date";
				echo "</td>";
				
				//valid_time
				$valid_time=$rows[valid_time];
				echo "<td align=\"right\">";
				echo "&nbsp;$valid_time";
				echo "</td>";
				
				//updated_date
				$updated_date=substr($rows[updated_date],0,8);
				echo "<td align=\"right\">";
				echo "&nbsp;$updated_date";
				echo "</td>";

				//MSISDN_used
				$msisdn=$rows[msisdn_used]?$rows[msisdn_used]:'--';
				echo "<td align=\"right\">";
				echo "&nbsp;$msisdn";
				echo "</td>";

				echo "</tr>";
			}while($rows=mysqli_fetch_array($result));
		}
		break;
	case '395':
		if($dataTypeNo == 0){
			//$selectFieldList = "msisdn,status,balance,expiration_date(MO),expiration_date(MT),first_used_date";
			do{
				echo "<tr>";
				//msisdn
				$msisdn=$rows[msisdn];
				echo "<td align=\"right\">";
				echo "<a href=\"$targetPage?sysId=$sysId&dataTypeNo=$dataTypeNo&";
				echo "keyValue={$rows[$keyFieldName]}&canSetNum=$canSetNum&isRead=1\">&nbsp;$msisdn</a>";
				echo "</td>";

/*
				//overdraft
				$overdraft=$rows[overdraft] / $pssCardMinCount;
				$overdraft = sprintf ("$fmtBit", $overdraft);
				$overdraft=showComma($overdraft);
				echo "<td align=\"right\">";
				echo "&nbsp;$overdraft";
				echo "</td>";
*/				

				//status
				$statusDef=array(array('00','fresh'),array('01','used'),array('02','suspended'),
								array('03','black list'),array('04','released'),array('05','OPR trial')
							);
				$status=$rows[status];
				echo "<td align=\"center\">";
				for($i=0;$i<sizeof($statusDef);$i++){
					if($statusDef[$i][0] == $status){
						echo "{$statusDef[$i][1]}";
						break;
					}elseif($i == sizeof($statusDef)-1){
						echo "unknown";
					}
				}
				echo "</td>";

				//balance
				$balance=$rows[balance] ;// $pssCardMinCount;
				$balance=sprintf ("$fmtBit", $balance);
				$balance=showComma($balance);
				echo "<td align=\"right\">";
				echo "&nbsp;$balance";
				echo "</td>";
				
				//mo_expiration_date
				$expiration_date=substr($rows[mo_expiration_date],0,8);
				echo "<td align=\"right\">";
				echo "&nbsp;$expiration_date";
				echo "</td>";
				
				//mt_expiration_date
				$expiration_date=substr($rows[mt_expiration_date],0,8);
				echo "<td align=\"right\">";
				echo "&nbsp;$expiration_date";
				echo "</td>";

				//Close user group
				$sCugId=substr($rows[cug_id],0,8);
				echo "<td align=\"right\">";
				echo "&nbsp;$sCugId";
				echo "</td>";

				//first_used_date
				$first_used_date=substr($rows[access_date],0,8);
				echo "<td align=\"right\">";
				echo "&nbsp;$first_used_date";
				echo "</td>";
				
				echo "</tr>";
			}while($rows=mysqli_fetch_array($result));
		}else{
			//$selectFieldList ="card_no,card_hrn,face_value,card_status,expiry_date,valid_time,updated_date";
			do{
				echo "<tr>";
				//card_no
				$card_no=$rows[card_no];
				echo "<td align=\"right\">";
				echo "<a href=\"$targetPage?sysId=$sysId&dataTypeNo=$dataTypeNo&";
				echo "keyValue=$card_no&canSetNum=$canSetNum&isRead=1\">&nbsp;$card_no</a>";
				echo "</td>";
				
				//face_value
				$face_value=$rows[face_value]; // $pssCardMinCount;
				$face_value=sprintf ("$fmtBit", $face_value);
				echo "<td align=\"right\">";
				echo "&nbsp;$face_value";
				echo "</td>";
				
				//card_status
				$card_status=$rows[card_status];
				echo "<td align=\"center\">";
				if($card_status == 0){
					echo "fresh";
				}else if($card_status == 1){
					echo "used";
				}else if($card_status == 2){
					echo "suspended";
				}
				echo "</td>";
				
				//expiry_date
				$expiry_date=substr($rows[expiry_date],0,8);
				echo "<td align=\"right\">";
				echo "&nbsp;$expiry_date";
				echo "</td>";
				
				//valid_time
				$valid_time=$rows[valid_time];
				echo "<td align=\"right\">";
				echo "&nbsp;$valid_time";
				echo "</td>";
				
				//updated_date
				$updated_date=substr($rows[updated_date],0,8);
				echo "<td align=\"right\">";
				echo "&nbsp;$updated_date";
				echo "</td>";

				//MSISDN_used
				$msisdn=$rows[msisdn_used]?$rows[msisdn_used]:'--';
				echo "<td align=\"right\">";
				echo "&nbsp;$msisdn";
				echo "</td>";

				echo "</tr>";
			}while($rows=mysqli_fetch_array($result));
		}
		break;
	case '370':
		do{
			echo "<tr>";
			$msisdn=$rows[msisdn];
			echo "<td align=\"center\">";
			echo "<a href=\"$targetPage?sysId=$sysId&dataTypeNo=$dataTypeNo&";
			echo "keyValue={$rows[$keyFieldName]}&canSetNum=$canSetNum&isRead=1\">&nbsp;$msisdn</a>";
			//echo "keyValue={$rows[$keyFieldName]}&canSetNum=$canSetNum&isRead=1\">&nbsp;$targetPage?sysId=$sysId&dataTypeNo=$dataTypeNo&keyValue={$rows[$keyFieldName]}&canSetNum=$canSetNum&isRead=1</a>";
			echo "</td>";
			//status
			$status=$rows[status];
			echo "<td align=\"center\">";
			if($status == '02'){
				echo "own ported out";
			}else if($status == '03'){
				echo "foreign ported in";
			}else{
				echo "foreign ported to third party";
			}
			echo "</td>";
			
			$routing_number=$rows[routing_number];
			echo "<td align=\"center\">$routing_number</td>";
			
			$donor=$rows[donor];
			echo "<td align=\"center\">$donor</td>";

			$recipient=$rows[recipient];
			echo "<td align=\"center\">$recipient</td>";
			
			$date=$rows[date];			
			$year=substr($date,0,4);
			$month=substr($date,4,2);
			$day=substr($date,6,2);

			echo "<td align=\"center\">$year-$month-$day</td>";


			echo "</tr>";
		}while($rows=mysqli_fetch_array($result));
		break;
	case '340':
		//$selectFieldList = "key_imsi,a3a8_version,status";
		do{
			echo "<tr>";
			$key_imsi=substr($rows[key_imsi],1);
			echo "<td align=\"right\">";
			echo "<a href=\"$targetPage?sysId=$sysId&dataTypeNo=$dataTypeNo&";
			echo "keyValue={$rows[$keyFieldName]}&canSetNum=$canSetNum&isRead=1\">&nbsp;$key_imsi</a>";
			echo "</td>";
			//a3a8_version
			$a3a8_version=hexdec($rows[a3a8_version]);
			echo "<td align=\"right\">";
			echo "&nbsp;$a3a8_version";
			echo "</td>";
			//status
			$status=$rows[status];
			echo "<td align=\"center\">";
			if($status == 0){
				echo "Inactive";
			}else{
				echo "Active";
			}
			echo "</td>";

			echo "</tr>";
		}while($rows=mysqli_fetch_array($result));
		break;
	case '380':
		//$selectFieldList = "imei,status";
		do{
			echo "<tr>";
			//imei
			$imei=$rows[imei];
			echo "<td align=\"right\">";
			echo "<a href=\"$targetPage?sysId=$sysId&dataTypeNo=$dataTypeNo&";
			echo "keyValue={$rows[$keyFieldName]}&canSetNum=$canSetNum&isRead=1\">&nbsp;$imei</a>";
			echo "</td>";
			//status
			$status=$rows[status];
			echo "<td align=\"center\">";
			if($status == 1){
				echo "Black-Listed";
			}else{//==2
				echo "Grey-Listed";
			}
			echo "</td>";

			echo "</tr>";
		}while($rows=mysqli_fetch_array($result));
		break;
	case '390':
		//$selectFieldList = "enableFlag,msisdn,mailboxNo,promptLanguage,greetingFlag,newMessageNum,oldMessageNum";
		do{
			echo "<tr>";
			
			//msisdn
			$msisdn=$rows[msisdn];
			echo "<td align=\"center\">";
			echo "<a href=\"$targetPage?sysId=$sysId&dataTypeNo=$dataTypeNo&";
			echo "keyValue={$rows[$keyFieldName]}&canSetNum=$canSetNum&isRead=1\">&nbsp;$msisdn</a>";
			echo "</td>";
			
			//mailboxNo
			$mailboxID=hexdec($rows[mailboxID]);
			echo "<td align=\"center\">";
			echo "$mailboxID";
			echo "</td>";
			//promptLanguage
			$promo_language=$rows[promo_language];
			echo "<td align=\"center\">";
			echo "$promo_language";
			echo "</td>";
			
			//greetingFlag
			$greetingDefArr=array(
					array('00','System'),
					array('01','Host name'),
					array('02','Personal'),
					array('80','Temporary')
				);
			$greeting=$rows[greeting];
			echo "<td align=\"center\">";
			for($i=0;$i<sizeof($greetingDefArr);$i++){
				if($greeting == $greetingDefArr[$i][0]){
					echo "{$greetingDefArr[$i][1]}";
				}
			}
			echo "</td>";
/*
			//pwdEnable
			$pwdFlag=$rows[pwdFlag];
			echo "<td align=\"center\">";
			if($pwdFlag == 1){
				echo "Y";
			}else{
				echo "N";
			}
			echo "</td>";
*/
			//pwdValue
			$pwdValue=$rows[pwdValue];
			echo "<td align=\"center\">";
			echo "$pwdValue";
			echo "</td>";
			echo "</tr>";
		}while($rows=mysqli_fetch_array($result));
		break;
	case '253':
		//$selectFieldList = "imsi,msisdn,used_flag,lac";
		do{
			echo "<tr>";
			$imsi=$rows[imsi];
			echo "<td align=\"center\">";
			echo "<a href=\"$targetPage?sysId=$sysId&dataTypeNo=$dataTypeNo&";
			echo "keyValue={$rows[$keyFieldName]}&canSetNum=$canSetNum&isRead=1\">&nbsp;$imsi</a>";
			echo "</td>";
			//msisdn
			$msisdn=str_replace('E','',$rows[msisdn]);
			echo "<td align=\"center\">";
			echo "&nbsp;$msisdn";
			echo "</td>";
			//used_flag
			$used_flag=$rows[used_flag];
			echo "<td align=\"center\">";
			if($used_flag > '00'){
				echo "Enable";
			}else{
				echo "Disable";
			}
			echo "</td>";
			//lac
			$lac=hexdec($rows[lac]);
			echo "<td align=\"center\">";
			echo "&nbsp;$lac";
			echo "</td>";
			echo "</tr>";
		}while($rows=mysqli_fetch_array($result));
		break;
	default:
		echo "Unknown sysTypeNo";
		exit(1);
}  
?>
</table>
</form>
&nbsp;
<?php
adjust_content_tail("down");
?>
</body>
</html>
