<?php
/*********************************************************      
 程序说明:         
    功能说明:所有已知系统列表

    调用关系:调用: connectdb.inc，inc/header.inc     
              被调用:      
 
    变量说明:$device_table;
              $language_type是公共变量在config.inc文件定义

     返回值:无

 作者:     
      
修改注释:      
NO.1      
姓名:            
时间:      
修改说明:      
*********************************************************/    
require("../../inc/header.inc");
$DEBUG = 0;
if($DEBUG) echo "<br>mode=$mode";

$sysConfTable		= 'OMC_PUB.sysConf';
$alarmDefTable	= 'OMC_PUB.sysAlarmConf';
$pubDb				='OMC_PUB';

if(isset($save) && $save != '-1'){
	if($mode=='add'){
		$saveSql = "REPLACE INTO $alarmDefTable
			(sysTypeNo,compCode,alarmCode,alarmDesc_1,alarmDesc_2,alarmType,alarmLevel,
				alarmNote_1,alarmNote_2)
			VALUES
			('$sysTypeNo','$compCode','$alarmCode','$alarmDesc_1','$alarmDesc_2','$alarmType','$alarmLevel',
				'$alarmNote_1','$alarmNote_2')
			";
	}else{// $mode=='edit'
		$saveSql = "REPLACE INTO $alarmDefTable
			(sysTypeNo,compCode,alarmCode,alarmDesc_1,alarmDesc_2,alarmType,alarmLevel,
				alarmNote_1,alarmNote_2)
			VALUES
			('$sysTypeNo','$compCode','$alarmCode','$alarmDesc_1','$alarmDesc_2','$alarmType','$alarmLevel',
				'$alarmNote_1','$alarmNote_2')
			";
	}
	
	if($DEBUG) echo "<br>saveSql = $saveSql";
	$result = mysqli_query($pubConn,$saveSql);
	echo mysqli_error($pubConn);
	$mode = 'edit';
	if($result > 0){
		echo "<br>OK!";
	}else{
		echo "<br>Error!";
	}
	echo " <meta http-equiv=\"refresh\" content=\"1; url=./alarmDefList.php?sysTypeNo=$sysTypeNo\"> ";
	exit();
}elseif($mode =='delete'){
	if($sureDel == 'Yes'){
		$delSql = "DELETE FROM $alarmDefTable
					WHERE sysTypeNo='$sysTypeNo' AND compCode = '$compCode'
						AND alarmCode = '$alarmCode' 
					";
		if($DEBUG) echo "<br>delSql = $delSql";
		mysqli_query($pubConn,$delSql);
		echo "<br><font size=3 color=blue>Delete ok</font>";
		echo " <meta http-equiv=\"refresh\" content=\"1; url=./alarmDefList.php?sysTypeNo=$sysTypeNo\"> ";
		exit();
	}elseif($sureDel == 'No'){
		echo "<br><font size=3 color=blue>Delete Canceled</font>";
		$mode='edit';
	}else{
		echo "<font size=3 color=black>Are you sure to delete this alarm?</font>";
		echo "<br><font size=3 color=blue>compCode	=$compCode</font>";
		echo "<br><font size=3 color=blue>alarmCode	=$alarmCode</font>";
		echo "<form method=\"POST\"  name=\"confForm\" action=\"$PHP_SELF\">";
		echo "<input type=\"submit\" name=\"sureDel\" value=\"Yes\">";
		echo "<input type=\"submit\" name=\"sureDel\" value=\"No\">";
		echo "<input type=\"hidden\" name=\"mode\" value=\"delete\">";
		echo "<input type=\"hidden\" name=\"sysTypeNo\" value=\"$sysTypeNo\">";
		echo "<input type=\"hidden\" name=\"compCode\" value=\"$compCode\">";
		echo "<input type=\"hidden\" name=\"alarmCode\" value=\"$alarmCode\">";
		echo "</form>";
		exit();
	}
}

if($mode == 'edit'){
	$listSql = "SELECT sysTypeName,$alarmDefTable.sysTypeNo,compCode,alarmCode,alarmDesc_1,alarmDesc_2,
						alarmType,alarmLevel,alarmNote_1,alarmNote_2 
				FROM $sysConfTable,$alarmDefTable
				WHERE $sysConfTable.sysTypeNo = $alarmDefTable.sysTypeNo
					AND $alarmDefTable.sysTypeNo = '$sysTypeNo'
					AND $alarmDefTable.compCode	 = '$compCode'
					AND $alarmDefTable.alarmCode = '$alarmCode'
				";
	if($DEBUG) echo "<br><br>listSql = $listSql";
	$listResult = mysqli_query($pubConn,$listSql);
	echo mysqli_error($pubConn);
	$listRows= @mysqli_fetch_array($listResult);
}

?>

<form method="POST" name=confForm action="<?php echo"$PHP_SELF";?>" >
<table  border="1" width="100%" cellpadding="2" cellspacing="0"  bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF" > 
 <tr bgcolor="#E6E6E6">    
	<td width="100%" colspan="2" align="center">
		<font size=3><b>
		<?php 
		if($mode == 'edit'){
			echo "Edit Alarm Define"; 
		}else{
			echo "Add Alarm Define"; 
		}
		?></b></font>
	</td>
  </tr>
<?php
	//sysTypeNo
	echo "<tr>";
	echo "<td  width=\"25%\">sysTypeNo</td>";
	echo "<td> <input type=\"input\" size=\"3\" name=\"sysTypeNo\" value=\"$sysTypeNo\" class=\"text\"></td>";
	echo "</tr>";
	
	//compCode
	echo "<tr>";
	echo "<td  width=\"25%\">compCode</td>";
	echo "<td>";
	echo  "<input type=\"text\" size=\"3\" name=\"compCode\" value=\"$listRows[compCode]\" class=\"text\">";
	echo "</td></tr>";

	//alarmCode
	echo "<tr>";
	echo "<td  width=\"25%\">alarmCode</td>";
	echo "<td>";
	echo  "<input type=\"text\" size=\"3\" name=\"alarmCode\" value=\"$listRows[alarmCode]\" class=\"text\">";
	echo "</td></tr>";

	//alarmLevel
	echo "<tr>";
	echo "<td  width=\"25%\">alarmLevel</td>";
	echo "<td>$alarmLevel";
	$alarmLevel=$listRows[alarmLevel];
	echo "<select  name=\"alarmLevel\" size=\"1\">";
	for($i=1;$i<sizeof($alarmLevelDefArr);$i++){
		$realValue	=$alarmLevelDefArr[$i][value];
		$showName	=$alarmLevelDefArr[$i][remark];
		if($realValue == $alarmLevel){
			echo "<option value=\"$realValue\" selected>$showName</option>";
		}else{
			echo "<option value=\"$realValue\">$showName</option>";
		}
	}
	echo "</select>";
	echo "</td></tr>";

	//alarmType
	//echo "<tr>";
	//echo "<td  width=\"25%\">alarmType</td>";
	//echo "<td>";
	//echo  "<input type=\"text\" size=\"3\" name=\"alarmType\" value=\"$listRows[alarmType]\" class=\"text\">";
	//echo "</td></tr>";

	//alarmDesc_1
	echo "<tr>";
	echo "<td  width=\"25%\">alarmDesc_1</td>";
	echo "<td>";
	echo  "<input type=\"text\" size=\"60\" name=\"alarmDesc_1\" value=\"$listRows[alarmDesc_1]\" class=\"text\">";
	echo "</td></tr>";

	//alarmDesc_2
	echo "<tr>";
	echo "<td  width=\"25%\">alarmDesc_2</td>";
	echo "<td>";
	echo  "<input type=\"text\" size=\"60\" name=\"alarmDesc_2\" value=\"$listRows[alarmDesc_2]\" class=\"text\">";
	echo "</td></tr>";


	//alarmNote_1
	echo "<tr>";
	echo "<td  width=\"25%\">alarmNote_1</td>";
	echo "<td>";
	echo "<textarea rows=\"5\" name=\"alarmNote_1\" cols=\"60\">{$listRows[alarmNote_1]}</textarea>";
	echo "</td></tr>";

	//alarmNote_2
	echo "<tr>";
	echo "<td  width=\"25%\">alarmNote_2</td>";
	echo "<td>";
	echo "<textarea rows=\"5\" name=\"alarmNote_2\" cols=\"60\">{$listRows[alarmNote_2]}</textarea>";
	echo "</td></tr>";

	echo "</table>";
echo "&nbsp;&nbsp;";
echo "<input type=\"submit\" name=\"save\"		value=\"Save\">&nbsp;&nbsp;";
echo "<input type=\"hidden\" name=\"mode\"		value=\"$mode\">";
echo "</FROM>";
?>