<?php
/*********************************************************      
 程序说明：         
    功能说明：pps用户数据维护专用页面
		1、将用户数据表的数据导入到临时参数表。
		2、修改的用户数据保存到临时参数表中，
		3、设置用户参数时,返回值将修改用户表和临时表。

    调用关系：调用: header.inc
 
    变量说明：
		输入变量：
			$keyValue	:由用户列表传来
			$sysId		:由用户列表传来或本页面指定
			$dataTypeNo	:数据类型，0=用户数据，1=冲值卡数据
			$language	:语言种类
			$canSetNum	:每次最多可以修改的字段个数

 作者：
      
修改注释：      
NO.1      
姓名：
修改说明：将过期时间（expiration_date）的改成只读模式。 
No.2
Name: Lilong
Date: Wednesday, March 24, 2004
Description: Modify supporting R7.0
No.3
Name: CuiTicun    Date:2004-04-09
Description: Modify supporting R7.0
No.4
Name: Lilong    Date:2004-7-2
Description: delete voice prompt 1
No.5
Name: CUiTicun    Date:2004-7-20
Description: Mofify "recharge failed times、overdraft、
			 access day、SM inquiry counter、favorite 
			 number counter"readonly
No.6
Name: CUiTicun    Date:2004-8-29
Description: 

*********************************************************
*	No.7
*	Name: Arwean	Date:2005-12-06
*	Description: Change the PPS Web into this MNP Web,
*				 Delete those items which MNP doesn't need.
*********************************************************
*********************************************************/  
require("../../inc/header.inc");
$DEBUG = 0;

if($DEBUG) echo "<br>正在调试中，给您的工作带来不便，请原谅！！^_^";

//==========================================================
//变量定义
//==========================================================
$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";
}
//例如：
//$canSetNum =1; // 或= 'all'
//$sysId='330_0_0';
//$keyValue= '0460022157127016';

//操作类型变量
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'=>'status',			'inputName'=>'iStatus'),
	array('fieldName'=>'routing_number',	'inputName'=>'iRoutingNumber'),
	array('fieldName'=>'donor',				'inputName'=>'iDonor'),
	array('fieldName'=>'recipient',			'inputName'=>'iRecipient'),
	array('fieldName'=>'date',				'inputName'=>'iDate')
	);
//检查各个需要编辑的输入单元
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;
	$status				= $iStatus;
	$routing_number		= $iRoutingNumber;
	$donor				= $iDonor;
	$recipient			= $iRecipient;
	$date				= $iDate;

	//格式化每个需要保存的字段，以便数据处理模块处理
	$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,status,routing_number,donor,recipient,date";
} 
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='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 = phone number of the subscriber. Includes the country code and area code,len should be 9-16</TD>";
	echo "</TR>";
}else{
	echo "<input type=\"hidden\" name=\"iMsisdn\" value=\"$keyValue\">";
}

//Subscriber status
$statusDef=array(
		array('02','own ported out'),
		array('03','foreign ported in'),
		array('04','foreign ported to third party')
				);
$status =$tmpRow[status];
echo "\n <TR>";
echo "<TD> $seqNo </TD>";
$seqNo++;
echo "<TD>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>2 = Own ported out<br>3 = Foreign ported in<br>4 = Foreign ported to third party</TD>";
echo "<TD>&nbsp;</TD>";
echo "</TR>";

//Routing number
$iRoutingNumber=substr($tmpRow[routing_number],0,8);
echo "\n <TR>";
echo "<TD> $seqNo </TD>";
$seqNo++;
echo "<TD>Routing number</TD>";
echo "<TD>";
echo "<input type=\"text\" name=\"iRoutingNumber\" maxlength=\"8\" value=\"$iRoutingNumber\" size=\"28\" class=\"text\">";
echo "</TD>";
echo "<TD>";
echo "Routing number, the length should be 1-8";
echo "</TD>";
echo "</TR>";

//Donor
$iDonor=substr($tmpRow[donor],0,16);
echo "\n<TR>";
echo "<TD> $seqNo </TD>";
$seqNo++;
echo "<TD> Donor </TD>";
echo "<TD>";
echo "<input type=\"text\" name=\"iDonor\" maxlength=\"16\" value=\"$iDonor\" size=\"28\" class=\"text\">";
echo "</TD>";
echo "<TD>";
echo "Donor network of the ported subscriber, <br>the length should be 1-16.";
echo "</TD>";
echo "</TR>";

//Recipient
$iRecipient=substr($tmpRow[recipient],0,16);
echo "\n<TR>";
echo "<TD> $seqNo </TD>";
$seqNo++;
echo "<TD> Recipient </TD>";
echo "<TD>";
echo "<input type=\"text\" name=\"iRecipient\" maxlength=\"16\" value=\"$iRecipient\" size=\"28\" class=\"text\">";
echo "</TD>";
echo "<TD>";
echo "Recipient network of the ported subscriber, <br>the length should be 1-16.";
echo "</TD>";
echo "</TR>";

//Date
if($isTryCreate>0)
{
	$iDate = date("YmdHis");
}
else
{
	$iDate = $tmpRow[date];
}
$iDate = substr($iDate,0,8);
echo "\n <TR>";
echo "<TD> $seqNo </TD>";
$seqNo++;
echo "<TD>Date</TD>";
echo "<TD>";
echo "<input type=\"text\" name=\"iDate\"  maxlength=\"14\" value=\"$iDate\" size=\"28\" class=\"text\">";
//echo "$date";
echo "</TD>";

echo "<td>Port date, the format is Year Month Day.<br>Such as 20050102 indicates 2005-01-02.</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();
?>