<?php
/*********************************************************      
 程序说明:         
    功能说明:本程序实现对数据表中的菜单结构的编辑

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

    返回值:无

 作者:     
      
修改注释:      
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 > Log Management > Log Source";
		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>";
$DEBUG = 0;

$keyId			= isset($keyId)?$keyId:1;
$dbName			= 'OMC_PUB';
$tableName		= 'sysLogSourceConf';
$maxLevelNum	= 5;

//选择语言版本
if($selectedLanguage == 'eng'){
	$nameField=name_2; //语种2
}else{	
	$nameField=name_1; //语种1(默认语种)
}
//keyId sysTypeNo sysNo subSysNo dataTypeNo isEnable isIncremental preObjId maxRecNumOfBuf maxRecNumOfDay dataDefineTable dataStoreTable menuName 
    


/**************************************删除一条记录***********************************************/
if($delete){
	$delSql = "DELETE FROM $tableName WHERE keyId = '$keyId'";
	$delResult = mysqli_query($pubConn ,$delSql);
	echo mysqli_error($pubConn);
	if($delResult){
		echo $strDeleteSuccess;
	 }else{
		echo $strDeleteFailure;
	}
	//插入日志
	//缺！！

} //end if($delete) 

/*****************************添加,修改记录*******************************************/
if($save){
	if($keyId == 'new'){//add
		$addSql = "REPLACE INTO $tableName 
					(keyId,sysTypeNo,sysNo,subSysNo,dataTypeNo,isEnable,isIncremental,
					  preObjId,maxSizeOfRec,maxRecNumOfBuf,maxRecNumOfDay,dataStoreTable,menuName)
					VALUES
					('$keyId','$sysTypeNo','$sysNo','$subSysNo','$dataTypeNo','$isEnable','$isIncremental',
					 '$preObjId','$maxSizeOfRec','$maxRecNumOfBuf','$maxRecNumOfDay','$dataStoreTable','$menuName')
					";
		if($DEBUG) echo "<br>$addSql";
		$result = mysqli_query($pubConn ,$addSql);
		echo mysqli_error($pubConn);
		if($result > 0){
			$getKeyIdSql =" SELECT keyId FROM $tableName 
							WHERE sysTypeNo = '$sysTypeNo' 
								AND sysNo = '$sysNo'  AND subSysNo = '$subSysNo' 
								AND dataTypeNo='$dataTypeNo'
								AND isEnable='$isEnable'
						  ";
			if($DEBUG) echo "<br>$getKeyIdSql";
			$result = mysqli_query($pubConn,$getKeyIdSql);
			echo mysqli_error($pubConn);
			$rows = mysqli_fetch_array($result);
			$keyId = $rows[keyId];
			echo "<br>ADD OK";
		}else{
			echo "<br>ADD Failed";
		}
	}else{//update
		$updateSql = "UPDATE $tableName SET 
					sysTypeNo='$sysTypeNo',sysNo = '$sysNo',subSysNo = '$subSysNo',
					dataTypeNo='$dataTypeNo',isEnable='$isEnable',preObjId='$preObjId',
					maxSizeOfRec = '$maxSizeOfRec',
					maxRecNumOfBuf='$maxRecNumOfBuf',maxRecNumOfDay='$maxRecNumOfDay',
					dataStoreTable='$dataStoreTable',menuName='$menuName'
					WHERE keyId = '$keyId'";
		if($DEBUG) echo "<br>updateSql = $updateSql";
		$updateResult = mysqli_query($pubConn,$updateSql);
		echo mysqli_error($pubConn);
		if($updateResult){
			echo "<br>UPDATE OK";
		}else{
			echo "<br>UPDATE Failed";
		}
	}
}
/*****************************显示一个菜单的定义*****************************/
?>


<script LANGUAGE="JavaScript"> 
function chgMenu()
{      
	var baseUrl,urlAdd,url;      
	baseUrl='<?php echo"$PHP_SELF?keyId=";?>';
	urlAdd=document.confForm.keyId.options[document.confForm.keyId.selectedIndex].value;      
	url = baseUrl+urlAdd;
	window.location=url;      
}
</script>

<form method="POST" name=confForm action="<?php echo"$PHP_SELF";?>" >
<table  border="1" width="100%" cellpadding="2" cellspacing="0"  bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#E6E6E6" > 
	<tr bgcolor="#E6E6E6">    
	<td width="100%" colspan="2" align="center">
		<font size=3><b><?php echo "OMC Log Source Define"; ?></b></font>
	</td>
    </tr>
	<tr>
    <td width="30%">
		<?php echo "Select:"; ?>
    </td>
    <td width="70%">
		
      <select size="1" name="keyId" onChange="javascript:chgMenu()">
		<?php
		$orderBy = 'sysTypeNo';
		$getMenuSql = "SELECT keyId,menuName FROM $tableName ORDER BY $orderBy ";
		$menuResult = mysqli_query($pubConn,$getMenuSql);
		
		if($DEBUG) echo "<br>selected Id = $keyId"; 
		if($DEBUG) echo "<br>getMenuSql = $getMenuSql";
		if($DEBUG) echo mysqli_error($pubConn);

		//显示选择菜单类型下拉菜单
		echo"<option value=\"new\">------------------New------------------</option>";
		$i=1;
		while($menuRows = mysqli_fetch_array($menuResult)){
			echo "<option value=\"$menuRows[keyId]\" ";
			if($menuRows[keyId] == $keyId && $keyId > 0){
				echo "selected";
			}
			echo ">";
			echo "$i -> $menuRows[menuName]";
			echo"</option>";
			$i++;
		}
		?>
		</select>
		<?php 

		?>
     </td>
     </tr>
	 <?php
	 		$menuSql = "SELECT * FROM $tableName WHERE keyId = '$keyId'";
			$menuResult = mysqli_query($pubConn ,$menuSql);
			$menuRows = @mysqli_fetch_array($menuResult);
	 ?>
	 <?php //------menuName----------- ?>
	 <tr>    
     <td width="30%"><?php echo "menuName"; ?>:</td>
     <td width="70%"> 
		<input type="text" name="menuName" size="50" value="<?php echo"$menuRows[menuName]";?>" ></td>
     </tr>
	 <?php //------isEnable----------- ?>
	 <tr>    
     <td width="30%"><?php echo "isEnable "; ?>:</td>
     <td width="70%"> 
		<input type="text" name="isEnable" size="50" value="<?php echo"$menuRows[isEnable]";?>" ></td>
     </tr> 
	 <?php //------sysTypeNo----------- ?>
	 <tr>    
     <td width="30%"><?php echo "sysTypeNo "; ?>:</td>
     <td width="70%"> 
		<input type="text" name="sysTypeNo" size="50" value="<?php echo"$menuRows[sysTypeNo]";?>" ></td>
     </tr>
	 <?php //------sysNo----------- ?>
	 <tr>    
     <td width="30%"><?php echo "sysNo "; ?>:</td>
     <td width="70%"> 
		<input type="text" name="sysNo" size="50" value="<?php echo"$menuRows[sysNo]";?>" ></td>
     </tr> 
	 <?php //------subSysNo----------- ?>
	 <tr>    
     <td width="30%"><?php echo "subSysNo "; ?>:</td>
     <td width="70%"> 
		<input type="text" name="subSysNo" size="50" value="<?php echo"$menuRows[subSysNo]";?>" ></td>
     </tr> 
	 <?php //------dataTypeNo----------- ?>
	 <tr>    
     <td width="30%"><?php echo "dataTypeNo "; ?>:</td>
     <td width="70%"> 
		<input type="text" name="dataTypeNo" size="50" value="<?php echo"$menuRows[dataTypeNo]";?>" ></td>
     </tr>
	 <?php //------preObjId----------- ?>
	 <tr>    
     <td width="30%"><?php echo "preObjId "; ?>:</td>
     <td width="70%"> 
		<input type="text" name="preObjId" size="50" value="<?php echo"$menuRows[preObjId]";?>" ></td>
     </tr>
	 <?php //------maxSizeOfRec----------- ?>
	 <tr>    
     <td width="30%"><?php echo "maxSizeOfRec "; ?>:</td>
     <td width="70%"> 
		<input type="text" name="maxSizeOfRec" size="50" value="<?php echo"$menuRows[maxSizeOfRec]";?>" ></td>
     </tr>
	 <?php //------maxRecNumOfBuf----------- ?>
	 <tr>    
     <td width="30%"><?php echo "maxRecNumOfBuf "; ?>:</td>
     <td width="70%"> 
		<input type="text" name="maxRecNumOfBuf" size="50" value="<?php echo"$menuRows[maxRecNumOfBuf]";?>" ></td>
     </tr>
	 <?php //------maxRecNumOfDay----------- ?>
	 <tr>    
     <td width="30%"><?php echo "maxRecNumOfDay"; ?>:</td>
     <td width="70%"> 
		<input type="text" name="maxRecNumOfDay" size="50" value="<?php echo"$menuRows[maxRecNumOfDay]";?>" ></td>
     </tr>
	 <?php //------dataStoreTable----------- ?>
	 <tr>    
     <td width="30%"><?php echo "dataStoreTable "; ?>:</td>
     <td width="70%"> 
		<input type="text" name="dataStoreTable" size="50" value="<?php echo"$menuRows[dataStoreTable]";?>" ></td>
     </tr>
	 </table>
<p>

<?php
	echo "<input type=\"submit\" value=\"$strSave\" name=\"save\" class=\"button\"> ";
	echo "<input type=\"reset\" value=\"$strCancel\" name=\"reset\" class=\"button\"> ";
	echo "<input type=\"submit\" value=\"$strDeleteMode\" name=\"delete\" class=\"button\"> ";

?>
</p>
<!--
<input type="button" value="按钮" name="a1"
style="border-left: 1px solid rgb(255,255,255); border-right: 1px solid rgb(255,255,255); border-top: 1px solid rgb(255,255,255); border-bottom: 1px solid rgb(255,255,255)">
-->
</form>
<?php
adjust_content_tail();
?>
</body>
</html>