<? include "verify.php" ?>
<html>
<head>
	<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
	<title>Auth2DB</title>
</head>
<body>

<? include "header.php" ?>

<p class="itemsMenu001"></p>

<div class="bloque">
<p class="title">Alerts Config</p>
<p class="itemsMenu001"></p>
</div>

<div class="centerbox">

<form action="alert_action.php" method="POST">
<?

include "conn.php";
	
$id = $_GET["id"];
$action = $_GET["action"];
$alert_type = "custom";


if($action == "new")
{
?>
	Create Custom Alert 
	<br><br>
	
	Alert Name: <input name="name" type="text" value="<? echo $rs->name ?>">
	<br><br>

	<table border="0" cellpadding="4" cellspacing="1" >
		<tr>
			<td align="right" >LogType&nbsp;:</td>
			<td >
				<select class="field" style="width: 200px;" name="log_type" size="1" >
						<? 
							$sql = "SELECT distinct(tipo) as tipo from login";
							$result = mysql_query($sql);
							while( $rs_tipo = mysql_fetch_object($result) ) { 
						?>
							<option value="<? echo $rs_tipo->tipo ?>" <? if ($rs->log_type == $rs_tipo->tipo ) echo "selected" ?> ><? echo $rs_tipo->tipo ?></option>
					<? } ?>
				</select>
			</td>
			<td> </td>
		</tr>
		<tr>
			<td align="right" >LogAction&nbsp;:</td>
			<td >
				<select class="field" style="width: 200px;" name="log_action" size="1" >
						<? 
							$sql = "SELECT distinct(action) as action from login";
							$result = mysql_query($sql);
							while( $rs_action = mysql_fetch_object($result) ) { 
						?>
							<option value="<? echo $rs_action->action ?>" <? if ($rs->log_action == $rs_action->action ) echo "selected" ?> ><? echo $rs_action->action ?></option>
					<? } ?>
				</select>
			</td>
			<td> </td>
		</tr>
		<tr>
			<td align="right" >LogGroup&nbsp;:</td>
			<td>
					<select class="field" style="width: 200px;" name="log_group" size="1" >
						<? 
							$arrayGroup = array('ip', 'usuario');
							for($i=0;$i<=sizeof($arrayGroup) - 1;$i++)
							{
						?>
							<option value="<? echo $arrayGroup[$i]  ?>" <? if ($rs->log_group == $arrayGroup[$i] ) echo "selected" ?> ><? echo $arrayGroup[$i] ?></option>
						<? } ?>
					</select>
			</td>
			<td> </td>
		</tr>
		<tr>
			<td align="right" >Severity&nbsp;:</td>
			<td>
					<select class="field" style="width: 200px;" name="severity" size="1" >
						<? 
							$arraySeverity = array('Critical', 'Emergency', 'Error', 'Warning', 'Alert', 'Notice', 'Information', 'Debug', 'Success', 'Failure' );
							for($i=0;$i<=sizeof($arraySeverity) - 1;$i++)
							{
						?>
							<option value="<? echo $arraySeverity[$i]  ?>" <? if ($rs->severity == $arraySeverity[$i] ) echo "selected" ?> ><? echo $arraySeverity[$i] ?></option>
						<? } ?>
					</select>
			</td>
			<td> </td>
		</tr>
		<tr>
			<td align="right" >Log message contains&nbsp;:</td>
			<td><input name="log_contains" value="<? echo $rs->log_contains ?>" ><br></td>
			<td></td>
		</tr><tr>
			<td align="right" >Exclude&nbsp;:&nbsp;</td>
			<td><input name="log_exclude" value="<? echo $rs->log_exclude ?>" ></td>
			<td></td>
		</tr><tr>
			<td></td>
			<td></td>
			<td></td>
		</tr><tr>
			<td align="right" >Number of occurrences&nbsp;:&nbsp;</td>
			<td>
				<input type="text" name="occurrences_number" size="5" value="<? echo $rs->occurrences_number ?>"  > &nbsp; time(s)</td>
			</td>
			<td></td>
		</tr>
		<tr>
			<td align="right" >Occurring within &nbsp;:</td>
			<td>
				<input type="text" name="occurrences_within" size="5" maxlength="6" value="<? echo $rs->occurrences_within ?>"  >&nbsp;minute(s)&nbsp;
			</td>
			<td></td>
		</tr>
	</table>
	<br><br>
	

	<table border="0" cellpadding="1" cellspacing="0" >
	<tr>
		<td >Define Actions : </td>
	</tr>
	<tr>
		<td height="7"></td>
	</tr>
	<tr>
		<td align="left" nowrap="nowrap">
			Criticality &nbsp;:&nbsp;
			<select class="field" name="criticality" size="1" >
				<? 
					$arrayCriticality = array('High', 'Medium', 'Low' );
					for($i=0;$i<=sizeof($arrayCriticality) - 1;$i++)
					{
				?>
						<option value="<? echo  $arrayCriticality[$i] ?>" <? if ($rs->criticality == $arrayCriticality[$i] ) echo "selected" ?> ><? echo $arrayCriticality[$i] ?></option>
				<? } ?>
			</select>
			<span class="helpTxt">&nbsp;Choose the criticality of the alert</span>
		</td>
	</tr>
</table>
	
<br><br>

<input class="field" name="active_email" value="1" align="left" type="checkbox" <? if($rs->active_email == 1) echo "checked" ?>>Notify by E-mail
	<br>
	<br>
	&nbsp;E-mail Address :  <input name="email" value="<? echo $rs->email?>" size="45" type="text">
	<br>
	<br>


<?

} else if ($action == "edit") {
	
	$sql = "SELECT * FROM alert_config WHERE id = $id ";
	$result = mysql_query($sql);
	$rs = mysql_fetch_object($result);
	
	
?>
	Edit Custom Alert 
	<br><br>
	Alert Name: <input name="name" type="text" value="<? echo $rs->name ?>">
	<br><br>

	<table border="0" cellpadding="4" cellspacing="1" >
		<tr>
			<td align="right" >LogType&nbsp;:</td>
			<td >
				<select class="field" style="width: 200px;" name="log_type" size="1" >
						<? 
							$sql = "SELECT distinct(tipo) as tipo from login";
							$result = mysql_query($sql);
							while( $rs_tipo = mysql_fetch_object($result) ) { 
						?>
							<option value="<? echo $rs_tipo->tipo ?>" <? if ($rs->log_type == $rs_tipo->tipo ) echo "selected" ?> ><? echo $rs_tipo->tipo ?></option>
					<? } ?>
				</select>
			</td>
			<td> </td>
		</tr>
		<tr>
			<td align="right" >LogAction&nbsp;:</td>
			<td >
				<select class="field" style="width: 200px;" name="log_action" size="1" >
						<? 
							$sql = "SELECT distinct(action) as action from login";
							$result = mysql_query($sql);
							while( $rs_action = mysql_fetch_object($result) ) { 
						?>
							<option value="<? echo $rs_action->action ?>" <? if ($rs->log_action == $rs_action->action ) echo "selected" ?> ><? echo $rs_action->action ?></option>
					<? } ?>
				</select>
			</td>
			<td> </td>
		</tr>
		<tr>
			<td align="right" >LogGroup&nbsp;:</td>
			<td>
					<select class="field" style="width: 200px;" name="log_group" size="1" >
						<? 
							$arrayGroup = array('usuario', 'ip');
							for($i=0;$i<=sizeof($arrayGroup) - 1;$i++)
							{
						?>
							<option value="<? echo $arrayGroup[$i]  ?>" <? if ($rs->log_group == $arrayGroup[$i] ) echo "selected" ?> ><? echo $arrayGroup[$i] ?></option>
						<? } ?>
					</select>
			</td>
			<td> </td>
		</tr>
		<tr>
			<td align="right" >Severity&nbsp;:</td>
			<td>
					<select class="field" style="width: 200px;" name="severity" size="1" >
						<? 
							$arraySeverity = array('Critical', 'Emergency', 'Error', 'Warning', 'Alert', 'Notice', 'Information', 'Debug', 'Success', 'Failure' );
							for($i=0;$i<=sizeof($arraySeverity) - 1;$i++)
							{
						?>
							<option value="<? echo $arraySeverity[$i]  ?>" <? if ($rs->severity == $arraySeverity[$i] ) echo "selected" ?> ><? echo $arraySeverity[$i] ?></option>
						<? } ?>
					</select>
			</td>
			<td> </td>
		</tr>
		<tr>
			<td align="right" >Log message contains&nbsp;:</td>
			<td><input name="log_contains" value="<? echo $rs->log_contains ?>" ><br></td>
			<td></td>
		</tr><tr>
			<td align="right" >Exclude&nbsp;:&nbsp;</td>
			<td><input name="log_exclude" value="<? echo $rs->log_exclude ?>" ></td>
			<td></td>
		</tr><tr>
			<td></td>
			<td></td>
			<td></td>
		</tr><tr>
			<td align="right" >Number of occurrences&nbsp;:&nbsp;</td>
			<td>
				<input type="text" name="occurrences_number" size="5" value="<? echo $rs->occurrences_number ?>"  > &nbsp; time(s)</td>
			</td>
			<td></td>
		</tr>
		<tr>
			<td align="right" >Occurring within &nbsp;:</td>
			<td>
				<input type="text" name="occurrences_within" size="5" maxlength="6" value="<? echo $rs->occurrences_within ?>"  >&nbsp;minute(s)&nbsp;
			</td>
			<td></td>
		</tr>
	</table>
	<br><br>
	

	<table border="0" cellpadding="1" cellspacing="0" >
	<tr>
		<td >Define Actions : </td>
	</tr>
	<tr>
		<td height="7"></td>
	</tr>
	<tr>
		<td align="left" nowrap="nowrap">
			Criticality &nbsp;:&nbsp;
			<select class="field" name="criticality" size="1" >
				<? 
					$arrayCriticality = array('High', 'Medium', 'Low' );
					for($i=0;$i<=sizeof($arrayCriticality) - 1;$i++)
					{
				?>
						<option value="<? echo  $arrayCriticality[$i] ?>" <? if ($rs->criticality == $arrayCriticality[$i] ) echo "selected" ?> ><? echo $arrayCriticality[$i] ?></option>
				<? } ?>
			</select>
			<span class="helpTxt">&nbsp;Choose the criticality of the alert</span>
		</td>
	</tr>
</table>
	
<br><br>

<input class="field" name="active_email" value="1" align="left" type="checkbox" <? if($rs->active_email == 1) echo "checked" ?>>Notify by E-mail
<br><br>
&nbsp;E-mail Address: <input name="email" value="<? echo $rs->email?>" size="45" type="text">
<br>
<br>


<? } ?>



<input type="hidden" name="id" value="<? echo $id?>">
<input type="hidden" name="action" value="<? echo $action?>">
<input type="submit" value="save alert">
</form>

</div>
</html>
