<?php
/*********************************************************      
 文件说明:         
    功能说明:修改基本费率

    调用关系:调用:header.inc  
             被调用:实现各个功能模块的页面        
    变量说明:

作者:
NO.1      
姓名：         
时间：  
修改说明：
/*********************************************************/ 
require("../../inc/header.inc");
/*********************************************************/ 
function pps_get_shm($offset,$count)
{              
      // define("Semaphore_Key",440,1); 
       define("SharedMem_Key",0x61230000,1); 
       define("SharedMem_Size",1024,1); //共享内存大小 
       $SharedMemID = @shmop_open(SharedMem_Key,"c",0666,SharedMem_Size);
              
       //将指定共享内存存入变量
        $Read_str= shmop_read($SharedMemID,$offset,$count);
         
       return($Read_str);
 }

 function pps_set_shm($offset,$str)
   {     
       define("SharedMem_Key",0x61230000,1); 
       define("SharedMem_Size",1024,1); //共享内存大小  
              
       $SharedMemID = @shmop_open(SharedMem_Key,"c",0666,SharedMem_Size);
       
       $sharemen_sign = 0;
              
       //将指定变量存入共享内存 
       if(shmop_write($SharedMemID,$str,$offset))
           $sharemen_sign++;         
      
       if($sharemen_sign == 1){
		return(1);
       }else{
		return(-1);
       }      
    }


/*********************************************************/ 

$ppsDb='PPS_DB';
$tableName='recover';
$strPageTitle=$strTitleAdvanced.$strTitleSpace."PPS".$strTitleSpace.$strCurrentTariff.$strTitleSpace.$strMultiServices;
	if($start){
		$delSql = "DELETE FROM  $tableName";
		mysqli_query($pubConn,$delSql);
		$editSql = " INSERT into $tableName set start_time='$startTime',end_time='$endTime',digital_6='$digital_6',digital_8='$digital_8',cc='$cc',ndc='$ndc',ip_address='$ip_address';";
		mysqli_query($pubConn,$editSql);
		echo mysqli_error($pubConn);

		pps_set_shm(0,'1');
		$command_status=pps_get_shm(0,1);
		$command_status=pps_get_shm(0,1);
		$remark = pps_get_shm(1,40);	 
/*
		if($command_status == '1')
        {
			if($start%4==0)
				$remark = "........";
			else if($start%4==1)
				$remark = "......";
			else if($start%4==2)
				$remark = "....";
			else if($start%4==3)
				$remark = "..";
		}
*/
		if($command_status == '3' || $command_status=='4'){	  
	 	   pps_set_shm(0,'0');
	  	   pps_set_shm(1,0);
	  	   $start = 0;
		}
		$start++;
    }	
$sql="SELECT * FROM $tableName";
//if(!$start)
{
$result=mysqli_query($pubConn,$sql);
$rows=mysqli_fetch_array($result);
echo mysqli_error($pubConn);
}
?>
<body>
<?php
  echo "Recover PPS account balance for system abnormal shutdown";
  echo "<p></p>";

/*
//没有纪录时，显示无记录提示
  if(!$rows){
	echo "$strNotFindRecord";
	exit();
  }
 */
?>
<form name="editform" action="/wxc2_omc/account/ppsRecover/recoverIndex.php?id=1&mode=edit" method="POST">
<table border="1" width="500" cellpadding="2" cellspacing="0"  bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF"  >
<?php
	echo "<tr bgcolor=\"#E6E6E6\">";
	echo "<td width=\"34%\">Item</td>";
	echo "<td align =\"left\" width=\"33%\">Value</td>";
	echo "<td align =\"left\" width=\"33%\">Example</td>";
	echo "</tr>";

	$arr_editfieldAmount = array("Start time","End time","First 6 digits of 12-digit recharge card","First 8 digits of 16-digit recharge card","Country code","Natinal destination code","IP address","Progress");
	$arr_remark = array("2003-06-30","2003-06-30 10:25:30","229000","22900001","86","755","172.18.98.1");
	$startTime = $rows[start_time];
	$endTime = $rows[end_time];
	$digital_6 = $rows[digital_6];
	$digital_8 = $rows[digital_8];
	$cc = $rows[cc];
	$ndc = $rows[ndc];
	$ip_address = $rows[ip_address];
	{
		echo "<tr>";
		echo "<td align=\"left\">$arr_editfieldAmount[0]</td>";
		echo "<td align=\"right\">";
		echo "<input type=\"input\" name=\"startTime\" value=\"$startTime\">";
		echo "<td align=\"left\">$arr_remark[0]</td>";
		echo "</tr>";
	}

	{
		echo "<tr>";
		echo "<td align=\"left\">$arr_editfieldAmount[1]</td>";
		echo "<td align=\"right\">";
		echo "<input type=\"input\" name=\"endTime\" value=\"$endTime\">";
		echo "<td align=\"left\">$arr_remark[1]</td>";
		echo "</tr>";
	}

	{
		echo "<tr>";
		echo "<td align=\"left\">$arr_editfieldAmount[2]</td>";
		echo "<td align=\"right\">";
		echo "<input type=\"input\" name=\"digital_6\" value=\"$digital_6\">";
		echo "<td align=\"left\">$arr_remark[2]</td>";
		echo "</tr>";
	}
	{
		echo "<tr>";
		echo "<td align=\"left\">$arr_editfieldAmount[3]</td>";
		echo "<td align=\"right\">";
		echo "<input type=\"input\" name=\"digital_8\" value=\"$digital_8\">";
		echo "<td align=\"left\">$arr_remark[3]</td>";
		echo "</tr>";
	}
	{
		echo "<tr>";
		echo "<td align=\"left\">$arr_editfieldAmount[4]</td>";
		echo "<td align=\"right\">";
		echo "<input type=\"input\" name=\"cc\" value=\"$cc\">";
		echo "<td align=\"left\">$arr_remark[4]</td>";
		echo "</tr>";
	}
	{
		echo "<tr>";
		echo "<td align=\"left\">$arr_editfieldAmount[5]</td>";
		echo "<td align=\"right\">";
		echo "<input type=\"input\" name=\"ndc\" value=\"$ndc\">";
		echo "<td align=\"left\">$arr_remark[5]</td>";
		echo "</tr>";
	}
	{
		echo "<tr>";
		echo "<td align=\"left\">$arr_editfieldAmount[6]</td>";
		echo "<td align=\"right\">";
		echo "<input type=\"input\" name=\"ip_address\" value=\"$ip_address\">";
		echo "<td align=\"left\">$arr_remark[6]</td>";
		echo "</tr>";
	}
	{
		$progress++;
		echo "<tr>";
		echo "<td align=\"left\">$arr_editfieldAmount[7]</td>";
		echo "<td colspan=\"2\" align=\"left\">";
		echo "$remark&nbsp";
		echo "</td>";
		echo "</tr>";
	}
/*
    <meta http-equiv="refresh" content="4 url=./recoverIndex.php?start=<?php echo start;?>">
*/
?>
</table><br> 
	<input type="submit" name="start" value="Recover" style="width:60" class="button">&nbsp;
</form>	
</body>
<b>Remarks:</b><br><br>
This facility is used to recover PPS account balance of abnormal shutdown time. The PPS saves memory data to harddisk at 4:00 am every day. When abnormal shutdown occurs, the PPS account balance data of the current day will be lost without being saved in harddisk. This facility helps recover the account balance by debiting all PPS account according to the CDR of the current day. <br>
<b><i>Start time:</b></i> The date when abnormal shutdown occurs.<br>
<b><i>End time:</b></i> The time at which abnormal shutdown occurs.<br>
<b><i>IP address:</b></i> IP address of either PPS 0 (172.18.98.1) or PPS 1 (172.18.99.1). <br>
To recover PPS account balance, fill in the above forms, click on Recover button and run a script cdrRestore under the path /usr/local/omc/tools/ in the OMC.
</html>   
