<?php
/*************************
IMDM subscriber management
**************************/
require("../../inc/header.inc");
$DEBUG = 0;
//==========================================================
//变量定义
//==========================================================
$canwrite_flag=checkWritePrivilege();
$pubDb				= 'OMC_PUB';
$sysSubsConfTable	= 'OMC_PUB.sysSubsConf';
$systemConfTable	= 'OMC_PUB.sysConf';

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

$maxLevelNum = 10;

$nInteger	= 2;
$nAscStr	= 3;
$nHexStr	= 4;
//==========================================================
//输入变量
//==========================================================
$canSetNum = isset($canSetNum) ? $canSetNum : 'all';
//显示用户数据编辑页面，需要的变量
if($DEBUG) 
{
	echo "<br>sysId=$sysId";
	echo "<br>canSetNum=$canSetNum";
	echo "<br>keyValue=$keyValue";
	echo "<br>sysTypeNo=$sysTypeNo";
	echo "<br>sysNo=$sysNo";
	echo "<br>subSysNo=$subSysNo";
	echo "<br>dataTypeNo=$dataTypeNo";
}
//操作类型变量
if($DEBUG)
{
	echo "<br>isRead=$isRead";
	echo "<br>isChange=$isChange";
	echo "<br>isCreate=$isCreate";
	echo "<br>isDelete=$isDelete";
	echo "<br>isLoadIndex=$isLoadIndex";
	
	//保存用户数据修改的数据
	echo "<br>bgnNo=$bgnNo";	
	echo "<br>endNo=$endNo";	
}



//---------定义需要编辑保存的字段-------
//$showAttrDef=array(array('fieldName'=>'','inputName'=>'');
$showAttrDef=array(
	array('fieldName'=>'msisdn',			'inputName'=>'iMsisdn'),
	array('fieldName'=>'imsi',	'inputName'=>'iImsi'),
	array('fieldName'=>'imei',			'inputName'=>'iImei'),
	array('fieldName'=>'oprFlag',				'inputName'=>'iOprFlag'),
	array('fieldName'=>'class','inputName'=>'iClass')
	//array('fieldName'=>'type',			'inputName'=>'iType'),
	//array('fieldName'=>'status',				'inputName'=>'iStatus')
	);
//检查各个需要编辑的输入单元
if($DEBUG && $_SERVER['REQUEST_METHOD'] == "POST")
{
	for($i=0;$i<sizeof($showAttrDef);$i++)
	{
		$inputName	=$showAttrDef[$i][inputName];
		$inputValue	=${$inputName};
		echo "<br>$inputName,$inputValue";
		if(strlen($inputValue))
		{
			echo "<br>$inputName	= $inputValue";
		}
		else
		{
			echo "<br>Can not find $inputName's value";
		}
	}
	exit();
}	
//处理每个输入单元的值，组成各个需要编辑的字段值
if($_SERVER['REQUEST_METHOD'] == "POST")
{
	$msisdn				= $iMsisdn;
	$imei				= $iImei;
	$imsi		= $iImsi;
	$oprFlag				= $iOprFlag;
	$type			= $iType;
	$status				= $iStatus;
	$oprClass = $iClass;

	//格式化每个需要保存的字段，以便数据处理模块处理
	$bgnNo=0;
	$endNo=0;
	for($i=$bgnNo;$i<sizeof($showAttrDef);$i++)
	{
		if($oldFieldName == $showAttrDef[$i][fieldName])
		{
			continue;
		}
		$oldFieldName = $showAttrDef[$i][fieldName];
		${'checkBox_'.$endNo} =1;
		${'fieldName_'.$endNo}=$oldFieldName;
		${'editValue_'.$endNo}=${$oldFieldName};
		if($DEBUG)
		{
			echo "<br>checkBox_$endNo	= ${'checkBox_'.$endNo}";
			echo "<br>fieldName_$endNo	= ${'fieldName_'.$endNo}";
			echo "<br>editValue_$endNo	= ${'editValue_'.$endNo}";
		}
		$endNo++;
	}
}
//==========================================================
//数据处理
//==========================================================
if (1 == $isLoadIndex) 
{
	$fieldNameList		= "msisdn,imei,imsi,oprFlag,class";
} 
else 
{
	$fieldNameList		= "ALL";
}
if ($DEBUG) echo "fieldNameList=$fieldNameList<br>";
?>
<base target="_self">

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

<?
require("../pubSubsMng/sendComm.inc");
//exit();
require("../pubSubsMng/dataProc.inc");
//==========================================================
//输出并显示数据
//==========================================================
$seqNo=0;
?>

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

adjust_content_head_frame("down");	
echo "<br>";
//**********************************编辑参数时所用javascript*****************************************
?>
<script LANGUAGE="JavaScript">
function selCheckBox(thisCheckBox)
{
	if(thisCheckBox.checked == true)
	{
		thisCheckBox.value=1;
	}
	else
	{
		thisCheckBox.value=0;
	}
}

function askSureToDel(keyName,keyId)
{
	var answer = confirm("Are you sure to delete this subscriber( "+keyName+"="
                          + keyId + ") from <?php echo"$sysTypeName";?> server?");
    if (answer == true)
    {
		window.location.href = "<?php echo "$PHP_SELF?sysId=$sysId&dataTypeNo=$dataTypeNo&bufferNo=$bufferNo&keyValue=$keyValue&isDelete=1";?>";
		//alert('Try to send delete command');
	}
	else
	{
		return(false);
	}
}
</script>
<FORM method="POST" name="update" action="<?php echo"$PHP_SELF";?>" >
<!--***************** TABLE  START:: DISPLAY SELECT HEADER    **************-->
<TABLE border="0" cellpadding="0" cellspacing="0" width="100%">
    <TR>
		<TD><NOBR>Server ID:
		<SELECT name="sysId" size="1">
			<?php
			$selSysIdSql="SELECT sysNo,subSysNo,sysTypeName 
						FROM sysInfo,sysConf 
						WHERE sysInfo.sysTypeNo='$sysTypeNo' AND sysConf.sysTypeNo='$sysTypeNo'
						ORDER BY baseStat DESC,updateTime DESC
						";
			if($DEBUG) echo "<br>$selSysIdSql";
			$sysIdResult=mysqli_query($pubConn,$selSysIdSql);
			echo mysqli_error($pubConn);
			while($sysIdRows=mysqli_fetch_array($sysIdResult)){
				echo "<option value=\"$sysTypeNo"."_$sysIdRows[sysNo]"."_$sysIdRows[subSysNo]\"";		
				if(($sysNo == $sysIdRows[sysNo]) && ($subSysNo == $sysIdRows[subSysNo]))
					echo " selected";
				echo " >$sysIdRows[sysTypeName]"."_$sysIdRows[sysNo]"."_$sysIdRows[subSysNo]";
				echo "</option>";
			}			
			?>
		</SELECT>
		</NOBR></TD>
		<TD><NOBR>
			<?php
			$showkeyValue= $keyValue;
			$keyValueName='msisdn';
			echo "&nbsp;&nbsp;$keyValueName:$showkeyValue";
			?>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		</NOBR></TD>
		
		<?php 
		if($isTryCreate > 0)
		{
		?>
		<TD>
			<input type="submit" value="Create in <?php echo "$sysTypeName"?>" name="create" title="Add a new subscriber" class="button" onClick="javascript:document.update.isCreate.value=1;">
			<input type="hidden" value="0" name="isCreate">
			<input type="hidden" value="0" name="isChange">
		</TD>
		<?php
			$myPrivilege = $userInfo[privilege];
			if($myPrivilege >=4)
			{
		?>
		<TD>
			&nbsp;&nbsp;&nbsp;
			<input type="submit" value="Create in OMC" name="create" title=""  class="button" onClick="javascript:document.update.isCreate.value=2;">
		</TD>
		<?php
			}
		?>
		<?php
		}
		else
		{
		?>
		<TD>
			<input type="submit" value="Get" name="read" title="Read this subscriber"  class="button" onClick="javascript:document.update.isRead.value=1;">
			<input type="hidden" value="0" name="isRead">
		</TD>

		<TD>
			<?php
			if($canwrite_flag)
				echo "<input type=\"submit\" value=\"Set\" name=\"change\" title=\"Change this subscriber\"  class=\"button\" onClick=\"javascript:document.update.isChange.value=1;\">";
			else
				echo "<input type=\"submit\" disabled value=\"Set\" name=\"change\" title=\"Change this subscriber\"  class=\"button\" onClick=\"javascript:document.update.isChange.value=1;\">";
			?>
			<input type="hidden" value="0" name="isChange">
			<input type="hidden" value="0" name="isCreate">
		</TD>
		
		<TD>
			<?php
			if($canwrite_flag)
				echo "<input type=\"button\" value=\"Delete\" name=\"delete\" title=\"Delete this subscriber\"  class=\"button\" onClick=\"askSureToDel('$keyValueName','$keyValue');\">";
			else
				echo "<input type=\"button\" disabled value=\"Delete\" name=\"delete\" title=\"Delete this subscriber\"  class=\"button\" onClick=\"askSureToDel('$keyValueName','$keyValue');\">";
			?>
			<input type="hidden" value="0" name="isDelete">
		</TD>
	<?php
		}
	?>
  <TD width="100%">&nbsp;</TD>
  	</TR>  
</TABLE>
<!--*****************  TABLE END:: DISPLAY SELECT HEADER    **************  -->
<BR>

<!--***************** TABLE  START:: DISPLAY USER DETAILS    ************** -->
<TABLE border="1" width="100%" cellpadding="2" cellspacing="0"  bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF">    
<TR bgcolor="#E6E6E6"> 
<TD width="5%"> No.</TD>   
<TD width="25%">Name</TD>   
<TD width="20%">Value</TD>     
<TD width="50%">Description</TD>    
</TR>
<?php
//msisdn
if($isTryCreate > 0){
//	echo "$tmpRow[msisdn],$tmpRow[msisdn],$tmpRow[msisdn]<br>";
	$msisdn=$tmpRow[msisdn];
	echo "\n <TR>";
	echo "<TD> $seqNo </TD>";
	$seqNo++;
	echo "<TD>MSISDN</TD>";
	echo "<TD>";
	echo "<input type=\"text\" name=\"iMsisdn\" maxlength=\"16\" size=\"28\" value=\"\" class=\"text\">";
	echo "</TD>";
	echo "<TD>MSISDN=CC+NDC+SN</TD>";
	echo "</TR>";
}else{
	echo "<input type=\"hidden\" name=\"iMsisdn\" value=\"$keyValue\">";
}





//imsi
$iImsi=$tmpRow[imsi];
echo "\n <TR>";
echo "<TD> $seqNo </TD>";
$seqNo++;
echo "<TD>IMSI</TD>";
echo "<TD>";
echo "<input type=\"text\" name=\"iImsi\" maxlength=\"15\" value=\"$iImsi\" size=\"28\" class=\"text\">";
echo "</TD>";
echo "<TD>";
echo "15-digit IMSI";
echo "</TD>";
echo "</TR>";

//imei
$iImei=$tmpRow[imei];
echo "\n <TR>";
echo "<TD> $seqNo </TD>";
$seqNo++;
echo "<TD>IMEI</TD>";
echo "<TD>";
echo "<input type=\"text\" name=\"iImei\" maxlength=\"15\" value=\"$iImei\" size=\"28\" class=\"text\">";
echo "</TD>";
echo "<TD>";
echo "15-digit IMEI (For OPR use only)";
echo "</TD>";
echo "</TR>";

//opr Flag
$oprFlagDef=array(
		array('00','OPR-0'),//array('00','Not Registered'),
		array('01','OPR-1'),//array('01','OprStateWithoutRoamingAgreement'),
		array('02','OPR-2a'),//array('02','OprStateWithRoamingAgreement'),
		array('03','OPR-2b'),//array('03','RoamingState'),
		array('04','IMDX-P1'),
		array('05','IMDX-P2'),
		array('06','IMDX-H')
				);
$oprFlag =$tmpRow[oprFlag];
echo "\n <TR>";
echo "<TD> $seqNo </TD>";
$seqNo++;
echo "<TD>User Status</TD>";
echo "<TD>";
echo "<select  name=\"iOprFlag\" size=\"1\">";
for($i=0;$i<sizeof($oprFlagDef);$i++)
{
	if($oprFlagDef[$i][0] == $oprFlag)
	{
		echo "<option value=\"{$oprFlagDef[$i][0]}\" selected>{$oprFlagDef[$i][1]}</option>";
	}
	else
	{
		echo "<option value=\"{$oprFlagDef[$i][0]}\">{$oprFlagDef[$i][1]}</option>";
	}
}
echo "</select>";
echo "</TD>";
echo "<TD>";
	echo "OPR-0 = Not in use (Fresh)<br>";//"Initial status of a new created or imported OPR account. The associated MSISDN will be allocated to an auto-registered subscriber.<br>";
	echo "OPR-1 = In use: without roaming agreement<br>";//"OPR subscriber is from PLMN without roaming agreement. <br>";
	echo "OPR-2a = In use: with roaming agreement (OPR)<br>";//"OPR subscriber is from PLMN with roaming agreement. <br>";
	echo "OPR-2b = In use: with roaming agreement (Roaming)<br>";//"OPR subscriber is from PLMN with roaming agreement. But its current application status is switched to roaming mode.";
	echo "IMDX-P1 = IMDX Private Ordinary<br>";
	echo "IMDX-P2 = IMDX Private Premium<br>";
	echo "IMDX-H = IMDX Hybrid<br>";
echo "</TD>";
echo "</TR>";


//class
$oprClass_label=array(0=>"Ordinary",1=>"Premium",2=>"VIP");
$oprClass =$tmpRow['class'];
echo "\n <TR>";
echo "<TD> $seqNo </TD>";
$seqNo++;
echo "<TD>Class</TD>";
echo "<TD>";
echo "{$oprClass_label[$oprClass]}";
echo "</TD>";
echo "<TD>";
echo "Class";
echo "</TD>";
echo "</TR>";
//type
/*
$typeDef=array(
		array('00','Trial'),
		array('01','Normal')
				);
$type =$tmpRow[type];
echo "\n <TR>";
echo "<TD> $seqNo </TD>";
$seqNo++;
echo "<TD>Type</TD>";
echo "<TD>";
echo "<select  name=\"iType\" size=\"1\">";
for($i=0;$i<sizeof($typeDef);$i++)
{
	if($typeDef[$i][0] == $type)
	{
		echo "<option value=\"{$typeDef[$i][0]}\" selected>{$typeDef[$i][1]}</option>";
	}
	else
	{
		echo "<option value=\"{$typeDef[$i][0]}\">{$typeDef[$i][1]}</option>";
	}
}
echo "</select>";
echo "</TD>";
echo "<TD>&nbsp;</TD>";
echo "</TR>";
*/
/*
//status
$statusDef=array(
		array('00','Idle'),
		array('01','Msisdn Allocated'),
		array('02','Msisdn Registered')
				);
$status =$tmpRow[status];
echo "\n <TR>";
echo "<TD> $seqNo </TD>";
$seqNo++;
echo "<TD>MSISDN Status</TD>";
echo "<TD>";
echo "<select  name=\"iStatus\" size=\"1\">";
for($i=0;$i<sizeof($statusDef);$i++)
{
	if($statusDef[$i][0] == $status)
	{
		echo "<option value=\"{$statusDef[$i][0]}\" selected>{$statusDef[$i][1]}</option>";
	}
	else
	{
		echo "<option value=\"{$statusDef[$i][0]}\">{$statusDef[$i][1]}</option>";
	}
}
echo "</select>";
echo "</TD>";
echo "<TD>&nbsp;</TD>";
echo "</TR>";
*/
?>
</TABLE> 

<?php
//*****************************************隐藏输入框,用于传递值****************************************
echo "\n<input type=\"hidden\" name=\"dataTypeNo\"		value=\"$dataTypeNo\">";
echo "\n<input type=\"hidden\" name=\"keyFieldName\"	value=\"$indexFieldName\">";
echo "\n<input type=\"hidden\" name=\"keyValue\"		value=\"$keyValue\">";
?>

</form>
&nbsp;
<?php
adjust_content_tail("down");
?>
</body>

</html>

<?php
flush();
?>
