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

    作者：      
      
修改注释：      
NO.1      
姓名：Cui Ticun          
时间：2004-8-29
修改说明：Support OMC8.0,Modify the PPS subscriber field********************************************/

require("../../inc/header.inc");
?>
<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>";
//if($DEBUG) echo "<br>正在调试中！！";
//==========================================================
//变量定义
//==========================================================
$dbName				= 'OMC_PUB';
$sysSubsConfTable	= 'OMC_PUB.sysSubsConf';
$systemConfTable	= 'OMC_PUB.sysConf';
$numberPerPage		= 100;		//每页纪录数

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

//确定告警内容显示语言种类
if($selectedLanguage=='chn'){
	$alarmDesc	= alarmDesc_1;
}elseif($selectedLanguage=='eng'){
	$alarmDesc	= alarmDesc_2;
}
//==========================================================
//输入变量
//==========================================================
//列表所需基本变量
//fj
$DEBUG=0;
if($DEBUG) echo "<br>sysTypeNo=$sysTypeNo";
if($DEBUG) echo "<br>dataTypeNo=$dataTypeNo";

$dataTypeNo = $_REQUEST['dataTypeNo'];

if (strstr($userName, "student"))
{
	$commType = $_REQUEST['commType'];
	$keyValue = $_REQUEST['keyValue'];
}
if ($_REQUEST['sysTypeNo'])
{
	$sysTypeNo = $_REQUEST['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";
}
$bgnNo = $_REQUEST['bgnNo'];

//删除用户
if($DEBUG) echo "<br>commType =$commType";

//根据sysTypeNo,dataTypeNo获取数据表名，索引字段名
if($sysTypeNo==390 || $sysTypeNo==365 || $sysTypeNo==366){
	if(!isset($sysNo)){
		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($DEBUG) echo "<br>delSql=$delSql";
	$result=mysqli_query($pubConn,$delSql);
	echo mysqli_error($pubConn);
	if($result){
		echo "<br>Delete $keyValue OK!";
	}
}
switch($sysTypeNo){
	case '375':
		if(!isset($sysId)){
			$sysId='375_0_0';
		}
		$sysTypeName='OPPS';
		$canSetNum='all';
		$selectFieldList = "msisdn,imsi,imei,oprFlag,class,userType";
		$showNameList="MSISDN,IMSI,IMEI,User Status,Class,User Type";
		break;
	case '378':
		if(!isset($sysId)){
			$sysId='378_0_0';
		}
		$sysTypeName='iPALIM';
		$canSetNum='all';
		$selectFieldList = 'imsi,msisdn,msisdn_extern,tmsi,lai,type';
		$showNameList='IMSI,MSISDN Public,MSISDN Private,TMSI,MCC-MNC-LAC-CI,Type';
		break;
	case '330':
		if(!isset($sysId)){
			$sysId='330_0_0';
		}
		$sysTypeName='HLR';
		$canSetNum='all';
		$selectFieldList = "imsi,inter_msisdn,used_flag,nam,camel_flag";
		$showNameList="IMSI,MSISDN,usedFlag,NetworkAccessMode,CamelFlag";
		break;
	case '361':
	    if(!isset($sysId)){
	        $sysId='361_0_0';
	    }
	    $sysTypeName='MME';
	    $canSetNum='all';
	    $selectFieldList = "imsi,msisdn,mm_state,ecm_state,tai";
	    $showNameList="IMSI,MSISDN,MMState,ECMState,TAI";
	    break;
    case '362':
        if(!isset($sysId)){
            $sysId='362_0_0';
        }
        $sysTypeName='SPGW';
        $canSetNum='all';
        $selectFieldList = "imsi,s11_local_teid,s11_remote_teid,ue_ps_state,ue_ims_state,ps_ip,ims_ip,granted_bytes,used_bytes,ccr_update_threshold";
        $showNameList="IMSI,s11LocalTEID,s11RemoteTEID,uePSState,ueIMSState,psIP,imsIP,grantedBytes,used_bytes,ccrUpdateThreshold";
		break;
	case '363':
	        if(!isset($sysId)){
	            $sysId='363_0_0';
	        }
	        $sysTypeName='IMS';
	        $canSetNum='all';
	        $selectFieldList="msisdn,impu,barring,reg_state";
	        $showNameList="MSISDN,IMPU,Barring,regState";
		break;
	case '364':
	        if(!isset($sysId)){
	            $sysId='364_0_0';
	        }
	        $sysTypeName='RCS';
	        $canSetNum='all';
	        $selectFieldList = "imsi,tmsi,ptmsi,context_id,hnb_index,active_time";
	        $showNameList="IMSI,TMSI,P-TMSI,CONTEXT-ID,HNB-Index,ACTIVE-Time";
		break;
	case '365':
	        if(!isset($sysId)){
	            $sysId='365_0_0';
	        }
	        $sysTypeName='UDM';
	        $canSetNum='all';
	        //$selectFieldList = "supi,gpsis,internal_group_ids,subscribed_ue_ambr_temp,subscribed_snssais_temp,ue_usage_type";
	        //$showNameList="SUPI,GPSIS,INTERNAL-GROUP-IDS,SUBSCRIBED-UE-AMBR-TEMP,SUBSCRIBED-SNSSAIS-TEMP,UE-USAGE-TYPE";
	       $selectFieldList = "supi,gpsis,internal_group_ids,subscribed_ue_ambr_temp,subscribed_snssais_temp,ue_usage_type,rat_restriction,forbidden_areas_templ,service_area_restriction_templ,core_network_type_restriction,rfsp_index,periodic_registration_timer,mps_priority,mcs_priority,odb_packet_services,mico_mode,active_time,download_packet_count,subscribed_slice_selection_data_temp,subscribed_smf_selection_data_temp,subscribed_data,purge_flag,pei,ims_vops,guami,pdu_session_ids,single_nssais_str,dnns";
	        $showNameList="SUPI,GPSIS,INTERNAL-GROUP-IDS,SUBSCRIBED-UE-AMBR-TEMP,SUBSCRIBED-SNSSAIS-TEMP,UE-USAGE-TYPE,RAT-RESTRICTION,FORBIDDEN-AREAS-TEMPL,SERVICE-AREA-ERSTRICTION-TEMPL,CORE-NETWORK-TYPE-RESTRICTION,RFSP-INDEX,PERIODIC-REGISTRATION-TIMER,MPS-PRIORITY,MCS-PRIORITY,ODB-PACKET-SERVICES,MICO-MODE,ACTIVE-TIME,DOWNLOADED-PACKET-COUNT,SUBSCRIBED-SLIC-SELECTION-DATA-TEMP,SUBCRIBED-SMF-SELECTION-DATA-TEMP,SUBCRIBED-DATA,PURGE-FLAG,PEI,IMS-VOPS,GUAMI,PDU-SESSION-IDS,SINGLE-NSAIS-STR,DNNS";
		break;
	case '325':
		if(!isset($sysId)){
			$sysId='325_0_0';
		}
		$sysTypeName='VLR';
		$canSetNum='all';
		$selectFieldList = "IMSI,MSISDN,TMSI,LMSI";
		$showNameList = "IMSI,MSISDN,TMSI,LMSI";
		break;
	case '360':
		if($dataTypeNo == 0){
			$sysTypeName='PPS';
			$canSetNum='all';
			$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";
//			$selectFieldList = "msisdn,overdraft,status,balance,expiration_date,first_used_date,user_type";
//			$showNameList= "MSISDN,Overdraft,Status,Balance,Expiration Date,First used Date,User Type";
		}else{
			$sysTypeName='Prepaid Card';
			$canSetNum='all';
			$selectFieldList ="card_no,card_hrn,face_value,card_status,expiry_date,valid_time,updated_date";
			$showNameList="Card No,Card_hrn,Face Value,Status,Expiry Date,Valid Time,Updated Date";
		}
		if(!isset($sysId)){
			$sysId='360_0_0';
		}
		break;
	case '395':
		$sysTypeName='Recharge Card';
		$canSetNum='all';
		$selectFieldList ="card_no,card_hrn,face_value,card_status,expiry_date,valid_time,updated_date";
		$showNameList="Card No,Card_hrn,Face Value,Status,Expiry Date,Valid Time,Updated Date";
		
		if(!isset($sysId)){
			$sysId='395_0_0';
		}
		break;
	case '340':
		if(!isset($sysId)){
			$sysId='340_0_0';
		}
		$sysTypeName='AUC';
		$canSetNum='all';
		$selectFieldList = "key_imsi,a3a8_version,status";
		$showNameList = "IMSI,A3A8 version,status";
		break;
	case '380':
		if(!isset($sysId)){
			$sysId='380_0_0';
		}
		$sysTypeName='EIR';
		$canSetNum='all';
		$selectFieldList = "imei,status";
		$showNameList= "IMEI,Status";
		break;
	case '390':
		if(!isset($sysId)){
			$sysId='390_0_0';
		}
		$sysTypeName='VMS';
		$canSetNum='all';
		$selectFieldList = "msisdn,mailboxID,status,promo_language,greeting,optionFlag,pwdValue,acbTimeOut";
		$showNameList= "MSISDN,Mailbox No(Hex),Status,Language,Greeting,Option flag,Password,Acb timeout";
		break;
	case '253':
		if(!isset($sysId)){
			$sysId='253_0_0';
		}
		$sysTypeName='SN-HLR';
		$canSetNum='all';
		$selectFieldList = "imsi,msisdn,used_flag,lac";
		$showNameList= "imsi,msisdn,used_flag,lac";
		break;
	case '370':
		if(!isset($sysId)){
			$sysId='370_0_0';
		}
		$sysTypeName='MNP';
		$canSetNum='all';
		$selectFieldList = "msisdn,routing_number,status,donor,recipient,Date";
		$showNameList = "MSISDN,RN,status,Donor,Recipient,Date";
		break;
	break;
	default:
		echo "Uknown sysTypeNo: $sysTypeNo";
		exit(1);
}
$showFieldArr=explode(',',$selectFieldList);
$showNameArr=explode(',',$showNameList);

//根据上部页面传来的变量，生成查询条件
$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 &&$sysType==330){
	$whereFlag=" and $selKeyFieldName like '%$selKeyValue%'";
}
//查询基本条件
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";
	$result=mysqli_query($pubConn,$countSql);
	echo mysqli_error($pubConn);
	$record = @mysqli_fetch_array($result);
	$numberOfRecords = $record[0];
	if($DEBUG) echo "<br>numberOfRecords=$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){
		//插入日志
		insertLog("search $sysTypeName subscriber: $selKeyValue ");
	}else{
		//插入日志
		insertLog("search $sysTypeName subscriber: $selKeyValue not found");
		echo "<br>No Found";
		exit();
	}
}

//找到需要显示的纪录
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($pubConn,$showSql);
	echo mysqli_error($pubConn);
	$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==330){
			$basePageLink	="sysTypeNo=$sysTypeNo&sysId=$sysId&dataTypeNo=$dataTypeNo&numberOfRecords=$numberOfRecords&numberOfFlagRecords=$numberOfFlagRecords";

		}else{
			$basePageLink	="sysTypeNo=$sysTypeNo&sysId=$sysId&dataTypeNo=$dataTypeNo&numberOfRecords=$numberOfRecords";

		}
		$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>


<form name="selectform">
<TABLE  border="0" width="100%" cellpadding="2" cellspacing="0" bordercolor="#666666" bordercolordark="#FFFFFF">      
  <TR >     
    <TD >
<?php 
	echo "$strDisplayRecords<FONT color=#0000ff>&nbsp;$showBgnNo - $nextBgnNo</FONT>, ";
	if($sysTypeNo==330){
		echo "($strTotal:$numberOfRecords,IMSI Enabled:$numberOfFlagRecords)";   
	}else{
		echo "($strTotal:$numberOfRecords)";   
	}
?>

<TD>&nbsp;   
<?php /*      
	// NEW: Display a link for the previous set of records.  
	if ($bgnNo != 0) {  
		echo "<a href=\"$PHP_SELF?$basePageLink&$prePageLink\">"; 
		echo "<IMG alt=$strPreviousPage border=0  src=../../images/prePage.gif ></a>&nbsp;&nbsp;&nbsp;"; 
	}else{
		echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"; 
	}  
  
	// 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 border=0  src=../../images/nextPage.gif ></a>&nbsp;";  
	}else{
		echo "&nbsp;&nbsp;&nbsp;&nbsp;";  
	} 
	
	//根据纪录条数，算出页码数，本页页码
	if($numberOfRecords > 0){
		$totalPageNum = ceil($numberOfRecords / $numberPerPage );
		$pageNo = $bgnNo / $numberPerPage + 1;
	}*/
?>   
	</TD>  
	<TD align="right">
<?php
	
	// NEW: Display a link for the previous set of records.  
	if ($bgnNo != 0) {  
		echo "<a href=\"$PHP_SELF?$basePageLink&$prePageLink\">"; 
		echo "$strPrevious&nbsp;<IMG alt=$strPreviousPage align=absBottom border=0  src=../../images/left.gif ></a>&nbsp"; 
	}else{
		echo "<font color=\"#808080\">$strPrevious&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++){
		if($i== $pageNo){
			echo "<option  selected  value=\"$i\" >$i</option>";
		}else{
			echo "<option value=\"$i\">$i</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;$strNext</a>";  
	}else{
		echo "<IMG alt=$strNextPage align=absBottom border=0  src=../../images/right.gif ><font color=\"#808080\">&nbsp;$strNext</font>";  
	} 
?>
	</TD>
  </TR>  
</TABLE> 
<table border="1" width="100%"  cellpadding="1" cellspacing="0"  bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF">
  <tr bgcolor="#E6E6E6">
    <?php
	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  
	do{
		echo "<tr>";
		for($i=0;$i<sizeof($showFieldArr);$i++){
			echo "<td align=\"center\">";
			if ($i == "0"){
				echo "<a href=\"./subscriberConf.php?sysId=$sysId&dataTypeNo=$dataTypeNo&sysNo=$sysNo&keyValue={$rows[$keyFieldName]}&canSetNum=$canSetNum&isRead=1\">&nbsp;$rows[$i]</a>";
			}else{
				echo "&nbsp;$rows[$i]";
			}
			echo "</td>";
		}
	/*	echo "<td align=\"center\">";
		echo "<a href=\"./subscriberConf.php?sysId=$sysId&dataTypeNo=$dataTypeNo&keyValue=$rows[$keyFieldName]&canSetNum=$canSetNum&isRead=1\">edit</a>";
		echo "</td>";*/
		echo "</tr>";
	}while($rows=mysqli_fetch_array($result));
  
?>
</table>
</form>
&nbsp;
<?php
adjust_content_tail("down");
?>
</body>
</html>
