#!/bin/sh
#This script is created by ssparser automatically. The parser first created by MaoShouyan
printf "Content-type: text/html
Cache-Control: no-cache

"
echo -n ""; 
. ../common/common.sh 
myself="/cgi-bin/Protocol/`basename $0`"

echo -n "
<script type=\"text/javascript\" src=\"/img/common.js\"></script>
<script language=\"javascript\">
function beforeCommit(frm)
{
	var ipname = document.getElementsByName(\"ip\")[0];
	var ipname = document.getElementsByName(\"ipname\")[0];
	ip.value = TrimAll(ip.value);
	if (!IsIPAddr(ip.value)) {
		alert(\"IPַ!\");
		ip.select();
		return false;
	}
	ipname.value = TrimAll(ipname.value);
	if (ipname.value == \"\") {
		alert(\"ʶ!\");
		ipname.select();
		return false;
	}
	if (!IsName(ipname.value)) {
		alert(\"вܰ&ַ!\");
		ipname.select();
		return false;
	}
	return true;
}
function onCancel()
{
	window.location.href = \"/cgi-bin/Protocol/ipgrpname_list?ipgrp=${CGI_ipgrp}\";
}
</script>
";
if [ "${REQUEST_METHOD}" = "POST" ];  then
	operator_check "/cgi-bin/Protocol/ipgrpname_list?ipgrp=${CGI_ipgrp}"
	errmsg=`${FLOWEYE} ipobj setname ip=${CGI_ip} name=${CGI_ipname} grpid=${CGI_ipgrp}` 
	if [ "$?" != "0" ]; then
		afm_dialog_msg "ʧ:${errmsg}!"
	else
		afm_dialog_msg "ɹ!"
		afm_load_page 0 "/cgi-bin/Protocol/ipgrpname_list?ipgrp=${CGI_ipgrp}"
		exit 0
	fi
fi

echo -n "
<body>
"; 
if [ "${CGI_ip}" = "" ]; then
	cgi_show_title "->IPʶ->ӱʶ"
else
	cgi_show_title "->IPʶ->޸ıʶ"
fi
CGI_grpname=`${FLOWEYE} ipobj listgrpname | grep "^${CGI_ipgrp} " | awk '{print $2}'`

echo -n "
<br>
<form method=post onsubmit=\"return beforeCommit(this)\" action=\"${myself}\">
<table width=600 border=0 cellspacing=1 cellpadding=2>
<tr id=row1>
	<td width=40></td>
	<td width=80 align=left></td>
	<td width=* align=left>${CGI_grpname}<input type=hidden name=ipgrp value=\"${CGI_ipgrp}\"></input></td>
</tr>
<tr id=row1>
	<td></td>
	<td>IPַ</td>
	<td>
"; if [ "${CGI_ip}" != "" ]; then 
echo -n "
	${CGI_ip}<input type=hidden name=ip value=\"${CGI_ip}\"></input>
"; else 
echo -n "
	<input type=text name=ip value=\"${CGI_ip}\" style=\"width:120\"></input>
"; fi 
echo -n "
	</td>
</tr>
<tr id=row1>
	<td></td>
	<td>ʶ</td>
	<td>
		<input type=text name=ipname value=\"${CGI_ipname}\" style=\"width:120\"></input>
	</td>
</tr>
</table>
<table style=\"width:600; border-bottom:1px #787882 solid; color:#0000ff\">
<tr><td align=right>&nbsp;</td></tr>
</table>
<table style=\"width:600\">
<tr>
        <td align=right>
                <input type=submit style=\"width:90\" value=\"ύ\"></input>
                <input type=button style=\"width:90\" value=\"ȡ\" onclick=\"onCancel()\"></input>
        </td>
</tr>
</table>
</form>
</body>
</html>
";