<?php
/*************************
ipalim subscriber management
**************************/
require("../../inc/header.inc");
?>
<script language="JavaScript">
function changeType()
{
	var type_value=document.update.iType.value;
	
	if(type_value == 0)
	{
		document.update.iMsisdn.readOnly=true;
		document.update.iMsisdn.value="N/A";
		document.update.iMsisdn_extern.readOnly=false;
	}
	else if(type_value == 1)
	{
		document.update.iMsisdn_extern.readOnly=true;
		document.update.iMsisdn_extern.value="N/A";
		document.update.iMsisdn.readOnly=false;
	}
	else
	{
		document.update.iMsisdn_extern.readOnly=false;
		document.update.iMsisdn.readOnly=false;
	}
}
</script>
<?
$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'=>'imsi',	'inputName'=>'iImsi'),
	array('fieldName'=>'msisdn',	'inputName'=>'iMsisdn'),
	array('fieldName'=>'msisdn_extern',    'inputName'=>'iMsisdn_extern'),
        array('fieldName'=>'tmsi',    'inputName'=>'iTmsi'),
        array('fieldName'=>'lai',    'inputName'=>'iLai'),
	array('fieldName'=>'type',	'inputName'=>'iType')
	);
//?????????????
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")
{
	$imsi		= $iImsi;
	$msisdn				= $iMsisdn;
	$type			= $iType;
	$msisdn_extern = $iMsisdn_extern;
        $tmsi = $iTmsi;
        $lai = $iLai;

	//????????????,??????????
	$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		= "imsi,msisdn,msisdn_extern,tmsi,lai,type";
} 
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;">
<?php
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='imsi';
			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


//imsi
if($isTryCreate > 0){
//	echo "$tmpRow[msisdn],$tmpRow[msisdn],$tmpRow[msisdn]<br>";
	$imsi=$tmpRow[imsi];
	echo "\n <TR>";
	echo "<TD> $seqNo </TD>";
	$seqNo++;
	echo "<TD>IMSI</TD>";
	echo "<TD>";
	echo "<input type=\"text\" name=\"iImsi\" maxlength=\"15\" size=\"28\" value=\"\" class=\"text\">";
	echo "</TD>";
	echo "<TD>";
	echo "15-digit IMSI";
	echo "</TD>";
	echo "</TR>";
}else{
	echo "<input type=\"hidden\" name=\"iImsi\" value=\"$keyValue\">";
}

$ipalimType =$tmpRow[type]+0;
//echo "ipalimType=$ipalimType<br>";

//msisdn
$iMsisdn=$tmpRow[msisdn];
echo "\n <TR>";
echo "<TD> $seqNo </TD>";
$seqNo++;
echo "<TD>MSISDN Public</TD>";
echo "<TD>";
//private do not have the MSISDN Public
if($ipalimType == 0)
	echo "<input readonly type=\"text\" name=\"iMsisdn\" maxlength=\"15\" value=\"N/A\" size=\"28\" class=\"text\">";
else
	echo "<input type=\"text\" name=\"iMsisdn\" maxlength=\"15\" value=\"$iMsisdn\" size=\"28\" class=\"text\">";
echo "</TD>";
echo "<TD>MSISDN=CC+NDC+SN</TD>";
echo "</TR>";

//msisdn extern
$iMsisdn_extern=$tmpRow[msisdn_extern];
echo "\n <TR>";
echo "<TD> $seqNo </TD>";
$seqNo++;
echo "<TD>MSISDN Private</TD>";
echo "<TD>";
if($ipalimType == 1)
	echo "<input type=\"text\" readonly name=\"iMsisdn_extern\" maxlength=\"15\" value=\"N/A\" size=\"28\" class=\"text\">";
else
	echo "<input type=\"text\" name=\"iMsisdn_extern\" maxlength=\"15\" value=\"$iMsisdn_extern\" size=\"28\" class=\"text\">";
echo "</TD>";
echo "<TD>&nbsp;</TD>";
echo "</TR>";

//tmsi
$iTmsi=$tmpRow[tmsi];
echo "\n <TR>";
echo "<TD> $seqNo </TD>";
$seqNo++;
echo "<TD>TMSI</TD>";
echo "<TD>";
echo "$iTmsi&nbsp;";
//echo "<input type=\"text\" name=\"iTmsi\" maxlength=\"15\" readonly value=\"$iTmsi\" size=\"28\" class=\"text\">";
echo "</TD>";
echo "<TD>&nbsp;</TD>";
echo "</TR>";

//lai
$iLai=$tmpRow[lai];
echo "\n <TR>";
echo "<TD> $seqNo </TD>";
$seqNo++;
echo "<TD>MCC-MNC-LAC-CI</TD>";
echo "<TD>";
$lai_mcc=substr($iLai,0,3);
$lai_mnc=substr($iLai,3,3);
$lai_lai=substr($iLai,6,4);
$lai_ci=substr($iLai,10,4);
echo "$lai_mcc-$lai_mnc-$lai_lai-$lai_ci&nbsp;";
//echo "<input type=\"text\" name=\"iLai\" maxlength=\"15\" readonly value=\"$iLai\" size=\"28\" class=\"text\">";
echo "</TD>";
echo "<TD>&nbsp;</TD>";
echo "</TR>";


//type
$ipalimTypeDef=array(
		array('0','Private'),
		array('1','Public'),
		array('2','Hybrid')
				);
$ipalimType =$tmpRow[type];
echo "\n <TR>";
echo "<TD> $seqNo </TD>";
$seqNo++;
echo "<TD>Type</TD>";
echo "<TD>";
echo "<select  name=\"iType\" size=\"1\" onChange=\"javascript:changeType();\">";
for($i=0;$i<sizeof($ipalimTypeDef);$i++)
{
	if($ipalimTypeDef[$i][0] == $ipalimType)
	{
		echo "<option value=\"{$ipalimTypeDef[$i][0]}\" selected>{$ipalimTypeDef[$i][1]}</option>";
	}
	else
	{
		echo "<option value=\"{$ipalimTypeDef[$i][0]}\">{$ipalimTypeDef[$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();
?>
