<?php
require("../../inc/header.inc");
?>
<script language="JavaScript">
function change_sms_flag(sms_flag_id,msisdn_id)
{
	if(document.getElementById(sms_flag_id).value == 1)
	{
		document.getElementById(msisdn_id).disabled=0;
		document.getElementById(msisdn_id).style.background="#FFFFFF";
	}
	else
	{
		document.getElementById(msisdn_id).disabled=1;
		document.getElementById(msisdn_id).style.background="#e8e8e8";
	}
}
</script>
<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 "<FORM NAME=\"downForm\" action=\"./cdrNotifyConf.php\" method=\"post\">";
echo "<table id=\"table_up\" border=\"0\" width=\"100%\">";
	echo "<tr>";
		echo "<td width=\"50%\">";
		echo "Maintenance > Control Panel > CDR Alarm Note";
		echo "</td>";
		echo "<td width=\"50%\" align=\"right\" title=\"Help\">";
		$helpId="1.2.2";
		//showHelp($helpId);
		echo "</td>";
	echo "</tr>";
	echo "<tr>";
		echo "<td width=\"50%\">";
		echo "&nbsp;";
		echo "</td>";
		echo "<td width=\"50%\" align=\"right\" title=\"Clear\">&nbsp;";
		//echo "<a href=# onClick=\"javascript:clearAll();\"><img align=absBottom border=0 src=\"../../images/delete.gif\" width=\"14\" height=\"14\">$strClear</a>";
		echo "</td>";
	echo "</tr>";
echo "</table>";
adjust_title_tail();
adjust_content_head();

if($Save == "Save")
{
	$sqlstr = "SELECT * FROM OMC_PUB.cdrNotifyConf ";
	$res = @mysqli_query($pubConn,$sqlstr);
	$num=mysqli_num_rows($res);
	for($index=0;$index<$num;$index++)
	{
		$row = @mysqli_fetch_array($res);
		$sysTypeNo=$row[sysTypeNo];
		
		$name="{$sysTypeNo}_need_alarm";
		$sms_alarm_value=$$name;
		
		$name="{$sysTypeNo}_need_sms";
		$sms_sms_value=$$name;
		
		$name="{$sysTypeNo}_msisdn";
		$msisdn_value=$$name;
		
		$exp=explode(",",$msisdn_value);
		if(count($exp)>4 || (trim($msisdn_value) == "" && $sms_sms_value == 1))
		{
			echo "<font color=\"#ff0000\"> Warning: {$row[sysTypeName]}'s MSISDN invalid<br></font>";
			break;
		}
		
		$sqlstr="update OMC_PUB.cdrNotifyConf set need_alarm={$sms_alarm_value},need_sms={$sms_sms_value},sms_receiver='{$msisdn_value}' where sysTypeNo={$sysTypeNo};";
		@mysqli_query($pubConn,$sqlstr);
	}
	if($index == $num)
		echo "<font color=\"#0000ff\">Update OK!<br></font>";
	
}

echo "<br>";
echo "<center><font size=2 color=\"blue\">CDR Alarm Notification</font></center>";
echo "<table border=\"1\" width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#ffffff\">";
echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td width=60>System</td>";
echo "<td width=100>Need Alarm</td>";
echo "<td width=100>Need SMS Note</td>";
echo "<td>MSISDN List (MAX MSISDN Count=4)</td>";
echo "</tr>";

$sqlstr = "SELECT * FROM OMC_PUB.cdrNotifyConf ";
$res = @mysqli_query($pubConn,$sqlstr);
$num=mysqli_num_rows($res);
echo mysqli_error($pubConn);


for($index=0;$index<$num;$index++)
{
	$row = @mysqli_fetch_array($res);
	echo "<td>{$row[sysTypeName]}</td>";
	
	$sysTypeNo=$row[sysTypeNo];
	
	$flag=$row[need_alarm]-0;
	echo "<td>";
	echo "<select name=\"{$sysTypeNo}_need_alarm\">";
	if($flag == 0)
	{
		echo "<option value=\"0\" selected>No</option>";
		echo "<option value=\"1\">Yes</option>";
	}
	else
	{
		echo "<option value=\"0\">No</option>";
		echo "<option value=\"1\" selected>Yes</option>";
	}
	echo "</select>";
	echo "</td>";
	
	$flag=$row[need_sms]-0;
	echo "<td>";
	echo "<select name=\"{$sysTypeNo}_need_sms\" onchange=\"javascript:change_sms_flag('{$sysTypeNo}_need_sms','{$sysTypeNo}_msisdn');\">";
	if($flag == 0)
	{
		echo "<option value=\"0\" selected>No</option>";
		echo "<option value=\"1\">Yes</option>";
	}
	else
	{
		echo "<option value=\"0\">No</option>";
		echo "<option value=\"1\" selected>Yes</option>";
	}
	echo "</select>";
	echo "</td>";
	
	echo "<td>";
	echo "<input ";
	if($flag == 0)
		echo " disabled style=\"background:#e8e8e8;\" ";
	echo " type=text name=\"{$sysTypeNo}_msisdn\" class=text value=\"{$row[sms_receiver]}\" size=64>";
	echo "</td>";
	
	echo "</tr>";
}


echo "</table>";

echo "<table border=\"0\" width=\"100%\">";
	echo "<tr>";
		echo "<td width=\"100%\" align=\"left\">";
		echo "Note:  If the empty CDR file is generated, then it will issue an alarm and SMS notification. <br>Each MSISDN is separated by comma, 8675500001,8675500002 for example.<br>When the configuration is changed, it must restart omcd to become effective";
		echo "</td>";
	echo "</tr>";
echo "</table>";

echo "<input type=submit class=button name=Save value=Save>";

echo "</form>";

adjust_content_tail();
?>

