<?php
/*********************************************************      
 程序说明：         
    功能说明：列表显示账号信息，默认显示第一页用户资料
    调用关系：调用: header.inc    
              被调用:        
    变量说明：
    作者：   
修改注释：      
NO.1      
姓名：lilong    
时间：6/4/2004
修改说明：display subscriber while read subscriber.
*********************************************************/
$DEBUG = 0;
//echo "sysId=$sysId, sysTypeNo=$sysTypeNo<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;
}

//==========================================================
//输入变量
//==========================================================
//列表所需基本变量
if($DEBUG) echo "<br>sysTypeNo=$sysTypeNo";
if($DEBUG) echo "<br>dataTypeNo=$dataTypeNo";

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

//根据sysTypeNo,dataTypeNo获取数据表名，索引字段名
if($sysTypeNo==390){
	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 '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 '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':
		if($dataTypeNo == 0){
			$sysTypeName='RCM';
			$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='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 '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;
	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;
	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 '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,promo_Language,greeting";
		$showNameList= "MSISDN,Enable,Mailbox No,Language,GreetingFlag";
		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;
	default:
		echo "Uaaaknown sysTypeNo";
		exit(1);
}
$showFieldArr=explode(',',$selectFieldList);
$showNameArr=explode(',',$showNameList);

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

//查询基本条件
if(strlen($whereStr) > 10){
	$bascWhereStr ="";
}else{
	$bascWhereStr ="";
}

//首次查询，查出符合条件的纪录条数，并在以后的页面跳转中传递。
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($numberOfRecords > 0){
		//插入日志
		insertLog("search $sysTypeName subscriber: $selKeyValue ");
	}else{
		//插入日志
		insertLog("search $sysTypeName subscriber: $selKeyValue not found");
		echo "<br>No Found";
		return;
		//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;  
		}
		$basePageLink	="sysTypeNo=$sysTypeNo&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" bgcolor="#FFFFFF">      
  <TR >     
    <TD >
<?php 
	echo "$strDisplayRecords<FONT color=#0000ff>&nbsp;$showBgnNo - $nextBgnNo</FONT>, ";
	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">
  <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&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;
