<?php
/*********************************************************      
 文件说明:         
    功能说明:prepaid parameter configuration

    调用关系:
    变量说明:

作者:
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
$DEBUG=0;

adjust_head();
adjust_title_head();
echo "<FORM NAME=\"downForm\">";
echo "<table id=\"table_up\" border=\"0\" width=\"100%\">";
	echo "<tr>";
		echo "<td width=\"50%\">";
		echo "Template > Pub parameters";
		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>";

//=====================================
//变量定义
//=====================================
$db='OMC_PUB';
$tableName='omcPubVarConf';

//=====================================
//输入变量
//=====================================
//保存修改的参数
if($_REQUEST['actMode']== 'save'){
	$sql = " SELECT * FROM $tableName";
	if($DEBUG) echo "<br>sql=$sql";
	$res = @mysqli_query($pubConn,$sql);

	while($row = @mysqli_fetch_array($res)){
		$name=$row[pubVarName];
		$value=$_REQUEST[''.$name];
		$remark=$_REQUEST[$name.'_remark'];

		$sql = " UPDATE $tableName SET
				pubVarValue='$value',
				remark='$remark'
				WHERE pubVarName='$name'
			 ";
		if($DEBUG) echo "<br>sql=$sql";
		mysqli_query($pubConn,$sql);
		
		if(strcmp($row[pubVarName],"globalFTPUserName") == 0)
		{
			$updatesql="update OMC_PUB.sysSubsConf set ftpLoginName='$value' ";
			@mysqli_query($pubConn,$updatesql);
		}
		else if(strcmp($row[pubVarName],"globalFTPPassword") == 0)
		{
			$updatesql="update OMC_PUB.sysSubsConf set ftpLoginPwd='$value' ";
			@mysqli_query($pubConn,$updatesql);
		}
		else if(strcmp($row[pubVarName],"ExternalRCM") == 0)
		{
			$updatesql="update OMC_PUB.sysSubsConf set ExternalRCM='$value' ";
			@mysqli_query($pubConn,$updatesql);
			
			if($value == 0)
			{
				$updatesql="update OMC_PUB.sysMenuConf set privilege='-1' where level_1=3 and level_2=21 and level_3=0; ";
				@mysqli_query($pubConn,$updatesql);
				$updatesql="update OMC_PUB.sysMenuConf set privilege='2' where level_1=3 and level_2=20 and level_3=0; ";
				@mysqli_query($pubConn,$updatesql);
				
				$updatesql="update OMC_PUB.sysMenuConf set privilege='-1' where level_1=5 and level_2=3 and level_3=0; ";
				@mysqli_query($pubConn,$updatesql);
				$updatesql="update OMC_PUB.sysMenuConf set privilege='3' where level_1=5 and level_2=2 and level_3=0; ";
				@mysqli_query($pubConn,$updatesql);
				
				$updatesql="update OMC_PUB.sysMenuConf set privilege='-1' where level_1=7 and level_2=4 and level_3=2; ";
				@mysqli_query($pubConn,$updatesql);
				$updatesql="update OMC_PUB.sysMenuConf set privilege='4' where level_1=7 and level_2=4 and level_3=1; ";
				@mysqli_query($pubConn,$updatesql);
				
				$updatesql="update OMC_PUB.sysCsvConf set db_name='PPS_DB' where menu_name_2='card_info'";
				@mysqli_query($pubConn,$updatesql);
				$updatesql="update OMC_PUB.sysCsvConf set if_enable=1 where menu_name_2='used_card_info'";
				@mysqli_query($pubConn,$updatesql);

				$updatesql="update SMCLI.sysCmdDef set serverStr='pps',sysTypeNo=360,tmpTable='OBJ_360.tmpSubsData_1',srcTable='PPS_DB.card_info' where objectStr='ppscard'";
				@mysqli_query($pubConn,$updatesql);
			}
			else
			{
				$updatesql="update OMC_PUB.sysMenuConf set privilege='2' where level_1=3 and level_2=21 and level_3=0; ";
				@mysqli_query($pubConn,$updatesql);
				$updatesql="update OMC_PUB.sysMenuConf set privilege='-1' where level_1=3 and level_2=20 and level_3=0; ";
				@mysqli_query($pubConn,$updatesql);
				
				$updatesql="update OMC_PUB.sysMenuConf set privilege='3' where level_1=5 and level_2=3 and level_3=0; ";
				@mysqli_query($pubConn,$updatesql);
				$updatesql="update OMC_PUB.sysMenuConf set privilege='-1' where level_1=5 and level_2=2 and level_3=0; ";
				@mysqli_query($pubConn,$updatesql);
				
				$updatesql="update OMC_PUB.sysMenuConf set privilege='4' where level_1=7 and level_2=4 and level_3=2; ";
				@mysqli_query($pubConn,$updatesql);
				$updatesql="update OMC_PUB.sysMenuConf set privilege='-1' where level_1=7 and level_2=4 and level_3=1; ";
				@mysqli_query($pubConn,$updatesql);

				$updatesql="update OMC_PUB.sysCsvConf set db_name='RCM_RC_DB' where menu_name_2='card_info'";
				@mysqli_query($pubConn,$updatesql);
				$updatesql="update OMC_PUB.sysCsvConf set if_enable=0 where menu_name_2='used_card_info'";
				@mysqli_query($pubConn,$updatesql);

				$updatesql="update SMCLI.sysCmdDef set serverStr='rcm',sysTypeNo=395,tmpTable='OBJ_395.tmpSubsData_1',srcTable='RCM_RC_DB.card_info' where objectStr='ppscard'";
				@mysqli_query($pubConn,$updatesql);
			}
		}
	}
	echo "<br>Save OK!";
}

?>

<form name="listForm" method="POST" action="<?php echo"$PHP_SELF";?>">
<table border="1" width="100%" cellpadding="2" cellspacing="0"  bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF"  >
<?php
echo "<tr><td width=\"100%\" colspan=\"12\" align=\"center\" bgcolor=\"#E6E6E6\">";
echo "<font size=2><b>Public Var Define</b></font>";
echo "</td></tr>";

$sql = " SELECT * FROM $tableName ORDER BY instance asc";
if($DEBUG) echo "<br>sql=$sql";
$res = @mysqli_query($pubConn,$sql);

while($row = @mysqli_fetch_array($res)){
	echo "<tr>";		
	echo "<td width=\"20%\">&nbsp;{$row[pubVarName]}</td>";
	echo "<td width=\"40%\">&nbsp;";
	echo "<input type=text name=\"{$row[pubVarName]}\" value=\"{$row[pubVarValue]}\" size=50 class=\"text\">";
	echo "</td>";
	echo "<td width=\"40%\">&nbsp;";
	echo "<input type=text name=\"{$row[pubVarName]}_remark\" value=\"{$row[remark]}\" size=50 class=\"text\"></td>";
	echo "</tr>";
}
?>
</table>
<br>&nbsp;&nbsp;&nbsp;&nbsp;
<input type="submit" value="save" name="actMode" class="button">
&nbsp;&nbsp;&nbsp;&nbsp;
</form>
<?php
adjust_content_tail();
?>
</body>
</html>
