<?php
/*********************************************************      
 程序说明：         
    功能说明：本程序定义cdr配置信息

    调用关系：调用:header.inc     
              被调用:      
 
    变量说明：

     返回值：无

 作者：huangqingsen    2002-12-13     
      
修改注释：      
NO.1      
姓名        
时间
修改说明
*********************************************************/    
require("../../inc/header.inc");
?>
<body onload="javascript:adjust();" onresize="javascript:adjust();" leftmargin="15" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">

<?php
adjust_head();
adjust_title_head();
echo "<table id=\"table_up\" border=\"0\" width=\"100%\">";
	echo "<tr>";
		echo "<td width=\"50%\">";
		echo "Template > CDR Configuration";
		echo "</td>";
		echo "<td width=\"50%\" align=\"right\" title=\"Help\">";
		//showHelp($helpId);
		echo "</td>";
	echo "</tr>";
echo "</table>";
adjust_title_tail();
adjust_content_head();
echo "<br>";
$max_menu = 4;
$db=$cdr_db;
$sysTypeNo=isset($sysTypeNo)?$sysTypeNo:'320';
$sysType=omc_sys_code2type($sysTypeNo);
$recordTable	= "cdrFrom".$sysType;
$defineTable	= strtolower($sysType)."CdrDefine";
$sysNum=get_sys_total($sysType);
$selkey_sys_id=isset($selkey_sys_id)?$selkey_sys_id:'new';
$sysType=omc_sys_code2type($sysTypeNo);

/**************************************删除一个系统类型***********************************************/
if($delete){
	$delSql = "DELETE FROM $cdrdefine_table WHERE recordTable='$recordTable' AND key_sys_id='$selkey_sys_id'";
	$delRes = mysqli_query($pubConn,$delSql);
	//----------------
	//插入日志
	if ($delRes)
		$log_name = $user_info["account"]." delete ".$recordTable." from ".$cdrdefine_table." successful.";
	else
		$log_name = $user_info["account"]." delete ".$recordTable." from ".$cdrdefine_table." fail.";
	insertLog("$log_name");
	//------------
	if($delRes){
		echo "<font color=\"#0000ff\">$strDeleteSuccess</font>";
     }else{
		echo "<font color=\"#ff0000\">$strDeleteFailure</font>";
     }
}//end if($delete) 


/*****************************添加,保存一个类型*****************************/
if($save){
	if($selkey_sys_id == 'new')//插入一个新配置
	{
		//判断新添加的配置是否存在
		$judIndexSql = " SELECT COUNT(*) FROM $cdrdefine_table WHERE recordTable='$recordTable' AND key_sys_id ='$key_sys_id' ";
		$judIndexRes = @mysqli_query($pubConn,$judIndexSql);
		$judIndexRow = @mysqli_fetch_array($judIndexRes);
		echo mysqli_error($pubConn);
		if($judIndexRow[0])
		{
			echo "<br><font color=\"#FF0000\">Component always is existed!</font>";
			$noReplate='1';
		}
	}

	$replaceSql=" REPLACE INTO $cdrdefine_table VALUES('$isEnable','$oid','$bufSize','$headOid','$tailOid','$key_sys_id',$sysTypeNo,'$port','$recordTable','$defineTable','$csvPath','$backupMax','2') ";
	echo "<br>replaceSql=$replaceSql";
	if(!$noReplate)
	{
		$replaceRes = @mysqli_query($pubConn,$replaceSql);
		echo mysqli_error($pubConn);
		$selkey_sys_id=$key_sys_id;
	}
	//------------插入日志------------
	insertLog('CDR configuration',0,6);
	//------------
	if($replaceRes > 0){
		echo "<br><font color=\"#0000ff\" >$strSaveSuccess</font>";
    }else{
		echo "<br><font color=\"#ff0000\">$strSaveFailure</font>";
    }
} //end if($save) 
?>


<script LANGUAGE="JavaScript">  
function selType()      
 {      
    var base_url,sysTypeNo,url;      
    base_url='<?php echo"$PHP_SELF";?>?sysTypeNo=';
    sysTypeNo=document.selectform.sysTypeNo.value;   
    url=base_url+sysTypeNo;
    window.location=url;      
 }      

function selIndex()      
 {      
    var base_url,sysTypeNo,selkey_sys_id,url;      
    base_url='<?php echo"$PHP_SELF";?>?sysTypeNo=';
    sysTypeNo=document.selectform.sysTypeNo.value;   
	selkey_sys_id=document.selectform.selkey_sys_id.value;
    url=base_url+sysTypeNo+"&selkey_sys_id="+selkey_sys_id;
    window.location=url;      
 }      
</script>
<?php 
//echo "\n<script language=\"javascript\" src=\"../../inc/expand.js\" > </script>";  
?>
<form method="POST" name=selectform action="<?php echo"$PHP_SELF";?>" >
  <table  border="1" width="100%" cellpadding="2" cellspacing="0"  bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF" > 
<?php  
echo "<tr bgcolor=\"#E6E6E6\">";    
echo "<td width=\"100%\" colspan=\"2\">";
echo "<p align=\"center\"><b>$strCDRConfiguration</b></p></td></tr>";
echo "<tr>";    
echo "<td width=\"20%\">$strSystemType</td>";
echo "<td width=\"80%\">";


$typeSql		= " SELECT sysTypeNo,sysTypeName FROM $sysconf_table WHERE needCDR = '1' ORDER BY sysTypeNo ";
$typeRes		= @mysqli_query($pubConn,$typeSql);
$typeRow		= @mysqli_fetch_array($typeRes);
echo mysqli_error($pubConn);
//echo "<br>typeSql=$typeSql";

$indexSql		= " SELECT * FROM $cdrdefine_table WHERE recordTable = '$recordTable' ORDER BY key_sys_id ";
$indexRes		= @mysqli_query($pubConn,$indexSql);
$indexRow		= @mysqli_fetch_array($indexRes);
//echo "<br>indexSql=$indexSql";
echo mysqli_error($pubConn);

if($selkey_sys_id!='new')
{
	$confSql		= " SELECT * FROM $cdrdefine_table WHERE recordTable = '$recordTable' AND key_sys_id = '$selkey_sys_id'";
	$confRes		= @mysqli_query($pubConn,$confSql);
	$confRow		= @mysqli_fetch_array($confRes);
	echo mysqli_error($pubConn);

	$isEnable		= $confRow[isEnable];
	$oid			= $confRow[oid];
	$bufSize		= $confRow[bufSize];
	$headOid 		= $confRow[headOid];
	$tailOid 		= $confRow[tailOid];
	$key_sys_id		= $confRow[key_sys_id];
	$port 			= $confRow[port];
	$recordTable 	= $confRow[recordTable];
	$defineTable 	= $confRow[defineTable];
	$csvPath 		= $confRow[csvPath];
	$backupMax 		= $confRow[backupMax];
}

echo "<select size=\"1\" name=\"sysTypeNo\" onChange=\"javascript:selType()\">";
do
{
	if($sysTypeNo == $typeRow[sysTypeNo])
		echo "<option value=\"$typeRow[sysTypeNo]\" selected>$typeRow[sysTypeName]</option>";
	else
		echo "<option value=\"$typeRow[sysTypeNo]\">$typeRow[sysTypeName]</option>";
}while($typeRow = @mysqli_fetch_array($typeRes));
echo "</select></td></tr>";

echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td width=\"20%\">Existed ID</td>";
echo "<td width=\"80%\">";
echo "<select size=\"1\" name=\"selkey_sys_id\" onChange=\"javascript:selIndex()\">";
echo "<option value='new'>NEW</option>";
do
{
	if($selkey_sys_id == $indexRow[key_sys_id] && isset($indexRow[key_sys_id]))
		echo "<option value=\"$indexRow[key_sys_id]\" selected>$indexRow[key_sys_id]</option>";
	elseif(isset($indexRow[key_sys_id]))
		echo "<option value=\"$indexRow[key_sys_id]\">$indexRow[key_sys_id]</option>";
}while($indexRow = @mysqli_fetch_array($indexRes));
echo "</select></td></tr>";

echo "<tr>";
echo "<td width=\"20%\">System ID</td>";
echo "<td width=\"80%\">";
echo "<select name=\"key_sys_id\">";
for($i=0;$i<$sysNum;$i++)
{
	if($i==$key_sys_id){
		echo "<option value=\"$i\" selected>$i</option>";
	}else{
		echo "<option value=\"$i\">$i</option>";
	}
}
echo "</select>";
echo "</td>";
echo "</tr>";

echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td width=\"20%\">OID</td>";
echo "<td width=\"80%\">";
echo "<input type=text size=\"40\" name=\"oid\" value=\"$oid\">";
echo "</td>";
echo "</tr>";    

echo "<tr>";
echo "<td width=\"20%\">Head OID</td>";
echo "<td width=\"80%\">";
echo "<input type=text size=\"40\" name=\"headOid\" value=\"$headOid\">";
echo "</td>";
echo "</tr>";    

echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td width=\"20%\">Tail OID</td>";
echo "<td width=\"80%\">";
echo "<input type=text size=\"40\" name=\"tailOid\" value=\"$tailOid\">";
echo "</td>";
echo "</tr>";    

echo "<tr>";
echo "<td width=\"20%\">CSV path</td>";
echo "<td width=\"80%\">";
echo "<input type=text size=\"40\" name=\"csvPath\" value=\"$csvPath\">";
echo "</td>";
echo "</tr>";    

echo "<tr>";
echo "<td width=\"20%\">Buffer size</td>";
echo "<td width=\"80%\">";
echo "<input type=text size=\"4\"  maxlength=\"4\" name=\"bufSize\" value=\"$bufSize\">";
echo "</td>";
echo "</tr>";    

echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td width=\"20%\">Port</td>";
echo "<td width=\"80%\">";
echo "<input type=text size=\"4\" maxlength=\"4\" name=\"port\" value=\"$port\">";
echo "</td>";
echo "</tr>";    

echo "<tr>";
echo "<td width=\"20%\">Max backup days</td>";
echo "<td width=\"80%\">";
echo "<select name=\"backupMax\">";
for($i=1;$i<31;$i++)
{
	if($i==$backupMax){
		echo "<option value=\"$i\" selected>$i</option>";
	}else{
		echo "<option value=\"$i\">$i</option>";
	}
}
echo "</select>";
echo "</td>";
echo "</tr>";    

echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td width=\"20%\">$strEnable </td>";
echo "<td width=\"80%\">";
if($isEnable==1)
{
     echo "Yes<input type=radio value=\"1\" name=\"isEnable\" checked> ";
     echo "No<input type=radio value=\"0\" name=\"isEnable\">";
}
else
{
     echo "Yes<input type=radio value=\"1\" name=\"isEnable\"> ";
     echo "No<input type=radio value=\"0\" name=\"isEnable\" checked>";
}
echo "</td>";
echo "</tr>";    

echo "</table>";
?>
<p><input type="submit" value="<?php echo "$strSave"; ?>" name="save"> 
<input type="reset" value="<?php echo "$strCancel"; ?>" name="reset"> 
<input type="submit" value="<?php echo "$strDeleteMode"; ?>" name="delete">
</p>                
</form>
<?php
adjust_content_tail();
?>            
</body>                
</html>

