<?php

/*********************************************************      

 程序说明:         

    功能说明:所有已知系统列表



    调用关系:调用: connectdb.inc，inc/header.inc     

              被调用:      

 

    变量说明:$device_table;

              $language_type是公共变量在config.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 > Alarm 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>";

$DEBUG = 0;
$mode = $_REQUEST['mode'];
if($DEBUG) echo "<br>mode=$mode";
$sysTypeNo = $_REQUEST['sysTypeNo'];
$compCode = $_REQUEST['compCode'];
$alarmCode = $_REQUEST['alarmCode'];
$alarmDesc_1 = $_REQUEST['alarmDesc_1'];
$alarmDesc_2 = $_REQUEST['alarmDesc_2'];
$alarmType = $_REQUEST['alarmType'];
$alarmLevel = $_REQUEST['alarmLevel'];
$alarmNote_1 = $_REQUEST['alarmNote_1'];
$alarmNote_2 = $_REQUEST['alarmNote_2'];
$level_1 = $_REQUEST['level_1'];
$level_2 = $_REQUEST['level_2'];
$instanceNo = $_REQUEST['instanceNo'];
$EventCode = $_REQUEST['EventCode'];
$SendAlert = $_REQUEST['SendAlert'];




$sysConfTable		= 'OMC_PUB.sysConf';

$alarmDefTable	= 'OMC_PUB.sysAlarmConf';

$pubDb				='OMC_PUB';



if(isset($_POST['save']) && $_POST['save'] != '-1'){

	if($mode=='add'){

		$saveSql = "REPLACE INTO $alarmDefTable

			(sysTypeNo,compCode,alarmCode,alarmDesc_1,alarmDesc_2,alarmType,alarmLevel,

				alarmNote_1,alarmNote_2,level_1 ,level_2,instanceNo,EventCode,SendAlert  )

			VALUES

			('$sysTypeNo','$compCode','$alarmCode','$alarmDesc_1','$alarmDesc_2','$alarmType','$alarmLevel',

				'$alarmNote_1','$alarmNote_2','$level_1','$level_2','$instanceNo' ,'$EventCode', '$SendAlert')

			";

	}else{// $mode=='edit'

		$saveSql = "REPLACE INTO $alarmDefTable

			(sysTypeNo,compCode,alarmCode,alarmDesc_1,alarmDesc_2,alarmType,alarmLevel,

				alarmNote_1,alarmNote_2,level_1 ,level_2,instanceNo,EventCode, SendAlert  )

			VALUES

			('$sysTypeNo','$compCode','$alarmCode','$alarmDesc_1','$alarmDesc_2','$alarmType','$alarmLevel',

				'$alarmNote_1','$alarmNote_2','$level_1','$level_2','$instanceNo' ,'$EventCode', '$SendAlert')

			";

	}

	

	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($_POST['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($_POST['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 ,level_1 ,level_2,instanceNo,EventCode, SendAlert

				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>";





	//level_1

	echo "<tr>";

	echo "<td  width=\"25%\">level_1</td>";

	echo "<td>";

	echo  "<input type=\"text\" size=\"60\" name=\"level_1\" value=\"$listRows[level_1]\" class=\"text\">";

	echo "</td></tr>";



	//level_2

	echo "<tr>";

	echo "<td  width=\"25%\">level_2</td>";

	echo "<td>";

	echo  "<input type=\"text\" size=\"60\" name=\"level_2\" value=\"$listRows[level_2]\" class=\"text\">";

	echo "</td></tr>";

	

	//instanceNo

	echo "<tr>";

	echo "<td  width=\"25%\">instanceNo</td>";

	echo "<td>";

	echo  "<input type=\"text\" size=\"3\" name=\"instanceNo\" value=\"$listRows[instanceNo]\" class=\"text\">";

	echo "</td></tr>";





		

	//EventCode

	echo "<tr>";

	echo "<td  width=\"25%\">EventCode</td>";

	echo "<td>";

	echo  "<input type=\"text\" size=\"3\" name=\"EventCode\" value=\"$listRows[EventCode]\" class=\"text\">";

	echo "</td></tr>";
	
	//alert

	echo "<tr>";

	echo "<td  width=\"25%\">SendAlert</td>";

	echo "<td>";

	echo  "<input type=\"text\" size=\"3\" name=\"SendAlert\" value=\"$listRows[SendAlert]\" class=\"text\">";

	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>";
adjust_content_tail();
?>
