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

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

 作者：
      
修改注释：      
NO.1      
姓名：      
时间：  
修改说明： 
*********************************************************/  
require("../../inc/header.inc");
$DEBUG = 0;

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

//==========================================================
//变量定义
//==========================================================
$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;

//------------选择语言版本----------
if($language == 'eng'){

}else{

}

$userTypeDef=array(
		//array('Name',		'offset','remark'),
		array('rent01',		'00.0'	,'rent01'),
		array('rent02',		'00.1'	,'rent02'),
		array('rent03',		'00.2'	,'rent03'),
		array('rent04',		'00.3'	,'rent04'),
		array('rent05',		'00.4'	,'rent05'),
		array('rent06',		'00.5'	,'rent06'),
		array('rent07',		'00.6'	,'rent07'),
		array('rent08',		'00.7'	,'rent08')
);

//select sum(balance) from user_info
//==========================================================
//输入变量
//==========================================================
$canSetNum = isset($canSetNum)?$canSetNum:'all';
//显示用户数据编辑页面，需要的变量
if($DEBUG) echo "<br>sysId=$sysId";
if($DEBUG) echo "<br>canSetNum=$canSetNum";
if($DEBUG) echo "<br>keyValue=$keyValue";
if($DEBUG) echo "<br>sysTypeNo=$sysTypeNo";
if($DEBUG) echo "<br>sysNo=$sysNo";
if($DEBUG) echo "<br>subSysNo=$subSysNo";
if($DEBUG) echo "<br>dataTypeNo=$dataTypeNo";
//例如：
//$canSetNum =1; // 或= 'all'
//$sysId='330_0_0';
//$keyValue= '0460022157127016';

//操作类型变量
if($DEBUG) echo "<br>isRead=$isRead";
if($DEBUG) echo "<br>isChange=$isChange";
if($DEBUG) echo "<br>isCreate=$isCreate";
if($DEBUG) echo "<br>isDelete=$isDelete";
if($DEBUG) echo "<br>isLoadIndex=$isLoadIndex";

//保存用户数据修改的数据
if($DEBUG) echo "<br>bgnNo=$bgnNo";	
if($DEBUG) echo "<br>endNo=$endNo";	

//---------定义需要编辑保存的字段-------


//$showAttrDef=array(array('fieldName'=>'','inputName'=>'');
$showAttrDef=array(
	array('fieldName'=>'card_no',		'inputName'=>'cardNo'),
	array('fieldName'=>'card_hrn',		'inputName'=>'password'),
	array('fieldName'=>'face_value',	'inputName'=>'faceValue'),
	array('fieldName'=>'card_status',	'inputName'=>'cardStatus'),
	array('fieldName'=>'expiry_date',	'inputName'=>'expiryDate'),
	array('fieldName'=>'valid_time',	'inputName'=>'validTime'),
	array('fieldName'=>'msisdn_used',	'inputName'=>'msisdnUsed'),
	array('fieldName'=>'update_date',	'inputName'=>'updateDate')
);

//检查各个需要编辑的输入单元
if($DEBUG && $_SERVER['REQUEST_METHOD'] == "POST"){
	for($i=0;$i<sizeof($showAttrDef);$i++){
		$inputName	=$showAttrDef[$i][inputName];
		$inputValue	=${$inputName};
		if(strlen($inputValue)){
			echo "<br>$inputName	= $inputValue";
		}else{
			echo "<br>Can not find $inputName's value";
		}
	}
}

//处理各个的输入单元的值，组成各个需要编辑的字段值
if($_SERVER['REQUEST_METHOD'] == "POST"){
	$card_no		=$cardNo;
	$card_hrn		=$password;
	$face_value		=$faceValue;
	$card_status	=$cardStatus;
	$expiry_date	=$expiryDate;
	$valid_time		=$validTime;
	$msisdn_used	=$msisdnUsed;
	$update_date	=$updateDate;

	//格式化每个需要保存的字段，以便数据处理模块处理
	$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}";
		if($DEBUG) echo "<br>fieldName_$endNo	= ${'fieldName_'.$endNo}";
		if($DEBUG) echo "<br>editValue_$endNo	= ${'editValue_'.$endNo}";
		$endNo++;
	}
}
//==========================================================
//数据处理
//==========================================================
if (1 == $isLoadIndex) {
	$fieldNameList		= "card_no,face_value,card_status,expiry_date,valid_time,updated_date,msisdn_used";
} 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");
require("../pubSubsMng/dataProc.inc");

//添加用户时，各个值置为缺省值
if(strlen($keyValue) == 0){
	for($i=0;$i<sizeof($showAttrDef);$i++){
		$tmpRow[$showAttrDef[$i][fieldName]]=$showAttrDef[$i][defaultValue];
		if($DEBUG) echo "<br>tmpRow[{$showAttrDef[$i][fieldName]}]={$showAttrDef[$i][defaultValue]}";
	}
}

//==========================================================
//输出并显示数据
//==========================================================
$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";?>" >
  <?php
	//显示用户参数编辑页面
	?>
  <table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
	<td><nobr>
	<?php echo "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='Card No.';
	echo "&nbsp;&nbsp;$keyValueName:$showkeyValue";
	?>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	</nobr></td>
		<td>
		<input type="submit" value="Get" name="read" title=""  class="button" onClick="javascript:document.update.isRead.value=1;">

		<input type="hidden" value="0" name="isRead">
		</td>
  <td width="100%">&nbsp;</td>
  </tr>  
</table>
<br>
<?php
//将已取出的用户数据显示出来
//$tmpRow[fieldName]

?>
<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="35%">Name</td>   
<td width="20%">Value</td>     
<td width="40%">Description</td>    
</tr>
<?
//cardNo
$cardNo=$tmpRow[card_no];
echo "\n <tr>";
echo "<td> $seqNo </td>";
$seqNo++;
echo "<td>Card no.</td>";
echo "<td>";
echo "&nbsp;$cardNo";
echo "</td>";
echo "<td>&nbsp;</td>";
echo "</tr>";

//password
$password=$tmpRow[card_hrn];
echo "\n <tr>";
echo "<td> $seqNo </td>";
$seqNo++;
echo "<td>Password</td>";
echo "<td>";
echo "&nbsp;$password";
echo "</td>";
echo "<td>&nbsp;</td>";
echo "</tr>";

//faceValue
$faceValue=$tmpRow[face_value];
echo "\n <tr>";
echo "<td> $seqNo </td>";
$seqNo++;
echo "<td>Face value</td>";
echo "<td>";
echo "&nbsp;$faceValue";
echo "</td>";
echo "<td>&nbsp;</td>";
echo "</tr>";

//card_status
$cardStatus=$tmpRow[card_status];
echo "\n <tr>";
echo "<td> $seqNo </td>";
$seqNo++;
echo "<td>Card status</td>";
echo "<td>";
if($cardStatus == 0){
	echo "&nbsp;fresh";
}else if($cardStatus == 1){
	echo "&nbsp;used";
}else if($cardStatus == 2){
	echo "&nbsp;suspended";
}
//echo "&nbsp;$cardStatus";
echo "</td>";
echo "<td>&nbsp;</td>";
echo "</tr>";

//expiry_date
$expiryDate=$tmpRow[expiry_date];
echo "\n <tr>";
echo "<td> $seqNo </td>";
$seqNo++;
echo "<td>Expiry date</td>";
echo "<td>";
echo "&nbsp;$expiryDate";
echo "</td>";
echo "<td>&nbsp;</td>";
echo "</tr>";

//valid_time
$validTime=$tmpRow[valid_time];
echo "\n <tr>";
echo "<td> $seqNo </td>";
$seqNo++;
echo "<td>Valid days</td>";
echo "<td>";
echo "&nbsp;$validTime";
echo "</td>";
echo "<td>&nbsp;</td>";
echo "</tr>";

//msisdn_used
$msisdn_used=$tmpRow[msisdn_used];
echo "\n <tr>";
echo "<td> $seqNo </td>";
$seqNo++;
echo "<td>MSISDN charged</td>";
echo "<td>";
echo "&nbsp;$msisdn_used";
echo "</td>";
echo "<td>&nbsp;</td>";
echo "</tr>";

//update_date
$updateDate=$tmpRow[update_date];
echo "\n <tr>";
echo "<td> $seqNo </td>";
$seqNo++;
echo "<td>Update date</td>";
echo "<td>";
echo "&nbsp;$updateDate";
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();
?>