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

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

 作者：
      
修改注释：      
NO.1      
姓名：      
时间：  
修改说明： 
*********************************************************/  
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;

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

}else{

}

//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'=>'imei',		'inputName'=>'imei'),
	array('fieldName'=>'status',	'inputName'=>'status')
);

//For operation log use
{
	$status_def=array(
		"01"=>"BlackListed","1"=>"BlackListed",
		"02"=>"GreyListed","2"=>"GreyListed"
	);
}

$logFieldDef=array(
	'status',
);

if($_SERVER['REQUEST_METHOD'] == "POST"){
	//system("echo '-------------------------------------'>>/tmp/test.txt");
	$preValueInfo="Change $pre_keyvalue ";
	$isChangeFlag=0;
	for($i=0;$i<sizeof($logFieldDef);$i++){
		$inputName	=$logFieldDef[$i];
		$inputValue	=${$inputName};
		$ppName=$inputName."_ppvalue";
		$ddName=$inputName."_ddef";
		$cdName=$inputName."_cdef";
		$nnName=$inputName."_name";
		if(strlen($inputValue)){
			//echo "<br>$inputName	= $inputValue";
			if(isset($$ddName))
			{
				$tmpv=$$ppName;
				$val1=${$$ddName}[$tmpv];
				$val2=${$$ddName}[$inputValue];
				if(strlen($$ppName) == 0)
					$val1="NoValue";
				
				if(strcasecmp($val1,$val2) != 0)
				{
					$isChangeFlag=1;
					$preValueInfo.="[{$$nnName},{$val1}->{$val2}]";
					//system("echo '[{$$nnName},{$val1}->{$val2}]' >>/tmp/test.txt");
				}
			}
			else if(isset($$cdName))
			{
				$newValue="";
				for($iii=0;$iii<sizeof(${$$cdName});$iii++)
				{
					$chkname=${$$cdName}[$iii][0];
					if($$chkname == '1')
						$newValue.=${$$cdName}[$iii][2].",";
				}
				$newValue=substr($newValue,0,strlen($newValue)-1);
				if(strcasecmp($$ppName,$newValue) != 0)
				{
					$isChangeFlag=1;
					$preValueInfo.="[{$$nnName},({$$ppName})->({$newValue})]";
					//system("echo '[{$$nnName},({$$ppName})->({$newValue})]' >>/tmp/test.txt");
				}
			}
			else
			{
				if(strlen($$ppName) == 0)
					$$ppName="NoValue";
				if(strcasecmp($$ppName,$inputValue) != 0)
				{
					$isChangeFlag=1;
					$preValueInfo.="[{$$nnName},{$$ppName}->$inputValue]";
					//system("echo '[{$$nnName},{$$ppName}->$inputValue]'>>/tmp/test.txt");
				}
			}
		}else{
			//echo "<br>Can not find $inputName's value";
		}
	}
	if($isChangeFlag==1)
	{
		$preValueInfo.=" in {$log_sysTypeName}_{$log_sysNo}_{$log_subSysNo}";
		insertLog($preValueInfo);
	}
}

//处理各个的输入单元的值，组成各个需要编辑的字段值
if($_SERVER['REQUEST_METHOD'] == "POST"){
	//$status=$status;

	//格式化每个需要保存的字段，以便数据处理模块处理
	$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		= "imei,status";
} 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");

//==========================================================
//输出并显示数据
//==========================================================
$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='IMEI';
	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="" 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=""  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=\"\"  class=\"button\" onClick=\"javascript:document.update.isChange.value=1;\">";
		else
			echo "<input type=\"submit\" disabled value=\"Set\" name=\"change\" title=\"\"  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>
<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="25%">Name</td>   
<td width="20%">Value</td>     
<td width="50%">Description</td>    
</tr>
<?
//imei
if($isTryCreate > 0){
	$imei=$tmpRow[imei];
	echo "\n <tr>";
	echo "<td> $seqNo </td>";
	$seqNo++;
	echo "<td>IMEI</td>";
	echo "<td>";
	echo "<input type=\"text\" name=\"imei\" maxlength=\"16\" size=\"20\" value=\"$imei\" class=\"text\">";
	echo "</td>";
	echo "<td>International mobile station equipment identity and software version Number (IMEISV), as defined in TS GSM 03.03, is a 16-digit decimal number composed of four distinct elements:<br>- 6-digit Type Approval Code (TAC)<br>- 2-digit Final Assembly Code (FAC)<br>- 6-digit Serial Number (SNR)<br>- 2-digit Software Version Number (SVN)</td>";
	echo "</tr>";
}else{
	echo "<input type=\"hidden\" name=\"imei\" value=\"$keyValue\">";
}

echo "<input type=\"hidden\" name=\"log_sysTypeName\" value=\"$sysTypeName\">";
echo "<input type=\"hidden\" name=\"log_sysNo\" value=\"$sysNo\">";
echo "<input type=\"hidden\" name=\"log_subSysNo\" value=\"$subSysNo\">";
echo "<input type=\"hidden\" name=\"pre_keyvalue\" value=\"{$keyValue}'s\">";


//status     
$status=$tmpRow[status];
echo "\n <tr>";
echo "<td> $seqNo </td>";
$seqNo++;
echo "<td>Service status</td>";
echo "<td><nobr>";
if($status > 1){
	echo "<input type=\"radio\" name=\"status\" value=\"01\"> BlackListed &nbsp;&nbsp;&nbsp;&nbsp;";
	echo "<input type=\"radio\" name=\"status\" value=\"02\" checked> GreyListed";
}else{
	echo "<input type=\"radio\" name=\"status\" value=\"01\" checked>BlackListed &nbsp;&nbsp;&nbsp;&nbsp;";
	echo "<input type=\"radio\" name=\"status\" value=\"02\">GreyListed";

}
echo "</nobr></td>";
echo "<input type=\"hidden\" name=\"status_name\" value=\"Service status\">";
echo "<input type=\"hidden\" name=\"status_ppvalue\" value=\"$status\">";
echo "<input type=\"hidden\" name=\"status_ddef\" value=\"status_def\">";
echo "<td>The ME has the following three states:<br>White list: It is composed of all number series of equipment identities that are permitted for use<br>Black list: It contains all equipment identities that belong to equipment that need to be barred<br>Grey list: Equipments on the grey list are not barred (unless on the black list or not on the white list), but are tracked by the network for evaluation or other purposes<br>The EIR only store the MEs that has the Blacklisted or Greylisted state, the Whitelisted MEs are defined by the system parameter. 1=BlackListed, 2=GreyListed.</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();
?>