<?php
/*********************************************************      
 程序说明：         
    功能说明：列表显示被叫计费号码信息
              
    调用关系：调用: header.inc   
              被调用:        
 
    变量说明

作者:崔体存    2004-04-13 
      
修改注释：      
NO.1      
姓名：         
时间:     
修改说明：          
*********************************************************/
$DEBUG = 0;
require("../../inc/header.inc");
?>
<base>
<body leftmargin="15" rightmargin="10" onload="javascript:adjust();" onresize="javascript:adjust();" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">
<form method="POST" name="selectform" action="<?php echo "$PHP_SELF";?>">
<?php
adjust_head();
adjust_title_head();
$helpId = "2.2.3.2";
global $OMC_server,$pubConn;
$tariff_id=$_REQUEST['tariff_id'];
$where=$_REQUEST['where'];
$sort_field=$_REQUEST['sort_field'];
$return_tariff_id=$_REQUEST['return_tariff_id'];
$keep_id=$_REQUEST['keep_id'];

$db='PPS_DB';
$srcDataConn = mysqli_connect($OMC_server[0]['host'],$OMC_server[0]['user'],$OMC_server[0]['password'], $db);

$table_name='pre_mt_tariff';
$strThisPage=$strTitleAdvanced.$strTitleSpace.$strTariffPlan.$strTitleSpace."MT tariff";
$arr_mode=array("edit","add");

if(!$sort_field){
	$sort_field        = 'bill_id';        //排序所依赖的字段名
}
$sort_direction            = 'ASC ';       //排序顺序
$moneyPara = getMoneyPara();			   //显示的货币单位是最小货币单位的倍数

//echo "<br>moneyPara = $moneyPara";

if($add_area){
	echo " <meta http-equiv=\"refresh\" content=\"0; url=./rate_modify.php?add_area=1\"> ";
	exit();
}

//编辑后保持对应tariff_id的页面
if ($keep_id != 1){
	$tariff_id=isset($tariff_id)?$tariff_id:'00';
}
else {$tariff_id=$return_tariff_id;}
if($DEBUG) {echo "<br>keep_id=$keep_id<br>tariff_id=$return_tariff_id<br>";}

$where=" WHERE tariff_id=$tariff_id ";
//echo "<br>where=$where";
$str_sql ="SELECT  count(*) FROM $table_name ".$where;
// echo "<br>str_sql=$str_sql";
$result=mysqli_query($srcDataConn,$str_sql);
$record = mysqli_fetch_array($result);
$number_of_records = $record[0];

$order  = " ORDER BY $sort_field   $sort_direction ";
$sel_sql ="SELECT * FROM $table_name ".$where.$order;
//echo "<br>sel_sql=$sel_sql";
$result = @mysqli_query($srcDataConn,$sel_sql);
$rows = @mysqli_fetch_array($result);
echo mysqli_error($srcDataConn);

?>

<?php
	echo "<table id=\"table_up\" border=\"0\" width=\"100%\">";
	echo "<tr>";
	echo "<td width=\"50%\" align=\"left\">";
	echo "$strThisPage";
	echo "</td>";
	echo "<td width=\"50%\" align=\"right\" title=\"Help\">";
	showHelp($helpId);
	echo "</td>";
	echo "</tr>";
	echo "<tr>";
	echo "<td align=\"left\">&nbsp;";
	echo "</td>";
	echo "<td align=\"right\">";
	
	 echo "$strResideZone:&nbsp;"; 
   $maxCosSql = " SELECT pubVarValue FROM OMC_PUB.omcPubVarConf WHERE pubVarName = 'maxCOSNumber' ";
   $maxCosRes = @mysqli_query($pubConn,$maxCosSql);
   $maxCosRow = @mysqli_fetch_array($maxCosRes);
   $maxCosNum = $maxCosRow[pubVarValue];
   echo "<select size=\"1\" name=\"tariff_id\" onChange=\"javascript:selectTitle()\">";       
   for($i=0;$i<$maxCosNum;$i++){
	   $m=($i<10?"0":"").$i;       
       if($m != $tariff_id){
		   echo "<option value=\"$m\">$m</option>";       
        }else{
			echo "<option value=\"$m\" selected>$m</option>";
        }       
   }       
   echo "</select>";
   
	echo "</td>";
	echo "</tr>";
	echo "</table>";
adjust_title_tail();
adjust_content_head();
echo "<br>";
?>

<script LANGUAGE="JavaScript">  
function selectTitle(){      
	var base_url,url_add,url; 
	base_url='<?php echo "$PHP_SELF?tariff_id=";?>';
	url_add=document.selectform.tariff_id.options[document.selectform.tariff_id.selectedIndex].value;    
	url=base_url+url_add;
	window.location=url;
}
</script>


<table border="0" width="100%"  cellpadding="1" cellspacing="2"  bordercolor="#666666" bordercolordark="#FFFFFF">
 <tr>
  <td width="3%">
   <a href="./mttariff.php" target="_self"><img align=absBottom border="0" src="../../images/list.gif" width="16" height="16"><?php echo "$strList"; ?></a></td> 
  <td width="30%">
  <?php 
  $maxMoPrefixNumCosSql = " SELECT pubVarValue FROM OMC_PUB.omcPubVarConf WHERE pubVarName = 'maxMoPrefixNumPerCOS' ";
	$maxMoPrefixNumCosRes = @mysqli_query($pubConn,$maxMoPrefixNumCosSql);
	$maxMoPrefixNumCosRow = @mysqli_fetch_array($maxMoPrefixNumCosRes);
	$maxMoPrefixNumCosNum = $maxMoPrefixNumCosRow[pubVarValue];
  echo "Total records:$number_of_records&nbsp&nbsp&nbsp&nbspMax records:$maxMoPrefixNumCosNum";
  ?>
  </td>
  <td width="12%">
  <?php
	  echo "<a href=\"mttariffEdit.php?mode=$arr_mode[1]&number_of_records=$number_of_records&tariff_id=$tariff_id\" target=\"_self\">";
  ?>
  <img align="absBottom" border="0" src="../../images/add.gif" width="16" height="16"><?php echo "$strAdd"; ?></a></td> 
  </td>  
  <td align="right">
   &nbsp
 	</td>
 </tr>
</table> 

<?php
echo "<br>";
//没有纪录时，显示无记录提示
  if(!$rows)
  {
  	echo "<br>&nbsp;";
	echo "$strTariffNoRecords $tariff_id"."!"; 
  	exit();
  }
?>
 <table border="1" width="100%"  cellpadding="1" cellspacing="0"  bordercolor="#666666" bordercolordark="#FFFFFF">
  <tr bgcolor="#E6E6E6" valign="top">
    <?php
   // echo "<td>$strResideZone</td>";
    echo "<td><a href=\"$PHP_SELF?tariff_id=$tariff_id&where=$where&sort_field=bill_id\"  target=\"_self\">$strChargingPrefix</a></td>";
    echo "<td><a href=\"$PHP_SELF?tariff_id=$tariff_id&where=$where&sort_field=area\" target=\"_self\">$strCountryDistrict</a></td>";
	echo "<td >$strCallType</td>";
	echo "<td >$strDiscountID</td>";
	echo "<td >$strUnitChargingTimeSecond</td>";
    echo "<td >$strFreeChargeUnit</td>";
    echo "<td >$strMinimumChargingUnit</td>";
    //echo "<td >$strBasicFee($moneyPara)</td>";
    //echo "<td >$strBasicLongDistance($moneyPara)</td>";
    echo "<td >$strBasicInitial($moneyPara)</td>";
    echo "<td >Tier Level</td>";
    ?>
  </tr>    
<?php
do{
	echo "<tr>";
    // echo "<td>$rows[tariff_id]</td>";
	if(''==$rows[bill_id])
		echo "<td><a href=\"./mttariffEdit.php?id=$rows[bill_id]&tariffID=$rows[tariff_id]&mode=$arr_mode[0]\">--</a></td>";
	else
		echo "<td><a href=\"./mttariffEdit.php?id=$rows[bill_id]&tariffID=$rows[tariff_id]&mode=$arr_mode[0]\">$rows[bill_id]</a></td>";
    echo "<td>$rows[area]&nbsp</a></td>";
	if($rows[call_type]==4)
		echo "<td>Local call in</td>";
	elseif($rows[call_type]==5)
		echo "<td>Trunk call in</td>";
	else
		echo "<td align=\"right\">---</td>";
	echo "<td align=\"right\">$rows[discount_id]&nbsp;</td>";
	echo "<td align=\"right\">$rows[unit_time]</td>";
    echo "<td align=\"right\">$rows[free_time]</td>";
    echo "<td align=\"right\">$rows[mini_time]</td>";
	//echo "<td align=\"right\">$rows[base_fee]</td>";
	//echo "<td align=\"right\">$rows[long_distance_fee]</td>";
	echo "<td align=\"right\">$rows[adjustment]</td>";
	echo "<td align=\"right\">$rows[tier_level]</td>";
 /*   $base_fee=$rows[base_fee]/$moneyPara;
	if($moneyPara < 10){
		printf("<td align=\"right\">%5.0f</td>",$base_fee); 
	}
	elseif($moneyPara < 100){
		printf("<td align=\"right\">%5.1f</td>",$base_fee); 
	}
    else{
		printf("<td align=\"right\">%5.2f</td>",$base_fee); 
	}
    
	$long_distance_fee=$rows[long_distance_fee]/$moneyPara;
 	if($moneyPara < 10){
		printf("<td align=\"right\">%5.0f</td>", $long_distance_fee);
	}
	elseif($moneyPara < 100){
		printf("<td align=\"right\">%5.1f</td>", $long_distance_fee);
	}
	else{
		printf("<td align=\"right\">%5.2f</td>", $long_distance_fee);
	}
	
	$adjustment_fee=$rows[adjustment]/$moneyPara;
 	if($moneyPara < 10){
		printf("<td align=\"right\">%5.0f</td>", $adjustment_fee);
	}
	elseif($moneyPara < 100){
		printf("<td align=\"right\">%5.1f</td>", $adjustment_fee);
	}
	else{
		printf("<td align=\"right\">%5.2f</td>", $adjustment_fee);
	}*/
	 echo "</tr>";
}while($rows = mysqli_fetch_array($result));
?>  
</table>




<?php

//--------MMS Retrieve--------------
echo "<br><b>MMS Retrieve</b><p>";
echo "<table border=\"1\" width=\"100%\"  cellpadding=\"1\" cellspacing=\"0\"  bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\">";
echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td align=\"center\">ID</td>";
echo "<td align=\"center\">Prefix</td>";
echo "<td align=\"center\">Call type</td>";
echo "<td align=\"center\">Dest name</td>";
echo "<td align=\"center\">Discount ID</td>";
echo "<td align=\"center\">Charge fee</td>";
echo "<td align=\"center\">Cap flag</td>";
echo "</tr>";


$tableName="PPS_DB.pre_vas_mms_retrieve_tariff";
$sql="select * from $tableName where tariff_id=$tariff_id order by mms_retrieve_id asc ";
$res=@mysqli_query($srcDataConn,$sql);
$num=@mysqli_num_rows($res);
$mms_retrieve_cap_flag_label=array(0=>"Disable",1=>"Enable");
$mms_retrieve_call_type_label=array(4=>"Local call in",5=>"Trunk call in");

for($i=0;$i<$num;$i++)
{
	$row=@mysqli_fetch_array($res);
	echo "<tr>";
	//ID
	$mms_retrieve_id=$row[mms_retrieve_id];
	echo "<td align=\"center\">";
	echo "<a href=\"./mmsRetrieveEdit.php?record_id={$row[mms_retrieve_id]}&mode=$arr_mode[0]&tariffID=$tariff_id\">$mms_retrieve_id</a>";
	echo "</td>";
	
	//Prefix
	echo "<td align=\"center\">";
	if(trim($row[prefix]) == "")
		echo "--";
	else
		echo "{$row[prefix]}";
	echo "</td>";
	
	//Call type
	echo "<td align=\"center\">";
	echo "{$mms_retrieve_call_type_label[$row[call_type]]}&nbsp;";
	echo "</td>";
	
	//Dest name
	echo "<td align=\"center\">";
	if(trim($row[dest_name]) == "")
		echo "--";
	else
		echo "{$row[dest_name]}";
	echo "</td>";
	
	//Discount ID
	echo "<td align=\"center\">";
	echo "{$row[discount_id]}&nbsp;";
	echo "</td>";
	
	//Charge fee
	echo "<td align=\"center\">";
	echo "{$row[charge_fee]}&nbsp;";
	echo "</td>";
	
	//Cap flag
	echo "<td align=\"center\">";
	echo "{$mms_retrieve_cap_flag_label[$row[cap_flag]]}&nbsp;";
	echo "</td>";
		
	echo "</tr>";
}
//echo "tariff_id=$tariff_id<br>";
echo "</table>";

?>



<?php

//--------MMS Email--------------
echo "<br><b>MMS Email</b><p>";
echo "<table border=\"1\" width=\"100%\"  cellpadding=\"1\" cellspacing=\"0\"  bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\">";
echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td align=\"center\">ID</td>";
echo "<td align=\"center\">Prefix</td>";
echo "<td align=\"center\">Call type</td>";
echo "<td align=\"center\">Dest name</td>";
echo "<td align=\"center\">Discount ID</td>";
echo "<td align=\"center\">Charge fee</td>";
echo "<td align=\"center\">Cap flag</td>";
echo "</tr>";


$tableName="PPS_DB.pre_vas_mms_email_tariff";
$sql="select * from $tableName where tariff_id=$tariff_id order by email_id asc ";
$res=@mysqli_query($srcDataConn,$sql);
$num=@mysqli_num_rows($res);
$email_cap_flag_label=array(0=>"Disable",1=>"Enable");
$email_call_type_label=array(4=>"Local call in",5=>"Trunk call in");

for($i=0;$i<$num;$i++)
{
	$row=@mysqli_fetch_array($res);
	echo "<tr>";
	//ID
	$email_id=$row[email_id];
	echo "<td align=\"center\">";
	echo "<a href=\"./mmsEmailEdit.php?record_id={$row[email_id]}&mode=$arr_mode[0]&tariffID=$tariff_id\">$email_id</a>";
	echo "</td>";
	
	//Prefix
	echo "<td align=\"center\">";
	if(trim($row[prefix]) == "")
		echo "--";
	else
		echo "{$row[prefix]}";
	echo "</td>";
	
	//Call type
	echo "<td align=\"center\">";
	echo "{$email_call_type_label[$row[call_type]]}&nbsp;";
	echo "</td>";
	
	//Dest name
	echo "<td align=\"center\">";
	if(trim($row[dest_name]) == "")
		echo "--";
	else
		echo "{$row[dest_name]}";
	echo "</td>";
	
	//Discount ID
	echo "<td align=\"center\">";
	echo "{$row[discount_id]}&nbsp;";
	echo "</td>";
	
	//Charge fee
	echo "<td align=\"center\">";
	echo "{$row[charge_fee]}&nbsp;";
	echo "</td>";
	
	//Cap flag
	echo "<td align=\"center\">";
	echo "{$email_cap_flag_label[$row[cap_flag]]}&nbsp;";
	echo "</td>";
		
	echo "</tr>";
}
//echo "tariff_id=$tariff_id<br>";
echo "</table>";

?>



</form>
<?php
adjust_content_tail();
?>
</body>
</html>   
