#!/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 languate=javascript>
function onSelectApp(obj)
{
	window.location.href = \"/cgi-bin/Protocol/sysapp_list?group=${CGI_group}&groupname=${CGI_groupname}&appid=\" + obj.value; 
}
function onShowApp(appid, appname) {
	var url;
	url = \"/cgi-bin/Monitor/appview_topip?appid=\" + appid + \"&appname=\" + appname;
	ShowWindow(url, \"scrollbars=1,resizable=0\", 650, 800);
}
function beforeEditApp(frm) {
        var flowttl  = document.getElementsByName(\"flowttl\")[0];
        var nodewttl = document.getElementsByName(\"nodettl\")[0];
        flowttl.value = TrimAll(flowttl.value);
        if (!IsDigitIn(flowttl.value, 30, 65535)) {
                alert(\"ڱ30~65535!\");
                flowttl.select();
                return false;
        }
        nodettl.value = TrimAll(nodettl.value);
        if (!IsDigitIn(flowttl.value, 30, 65535)) {
                alert(\"ڵڱ30~65535!\");
                nodettl.select();
                return false;
        }
        return true; 
}
</script>
";
if [ "${REQUEST_METHOD}" = "POST" ]; then
	errmsg=`${FLOWEYE} app set ${CGI_appid} flowttl=${CGI_flowttl} nodettl=${CGI_nodettl} cachesn=${CGI_cachesn}`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "òʧ:${errmsg}"
	else
		afm_dialog_msg "ɹ!"
	fi
else
	if [ "${CGI_appid}" = "" ]; then
		for appid in `${FLOWEYE} app list2 | grep "^${CGI_group}" | awk '{print $2}'`
		do
			CGI_appid="${appid}"
			break
		done
	fi
fi

echo -n "
<body>
"; cgi_show_title "ӦЭ->${CGI_appname}" 
echo -n "
<br>
<form method=post onsubmit=\"return beforeEditApp(this)\" action=\"${myself}\">
"; 
if [ "${CGI_appid}" = "" ]; then
	echo "</body></html>"
	exit 0
fi
output=`${FLOWEYE} app get ${CGI_appid}`
if [ "${output}" = "" ]; then
	afm_dialog_msg "Э${CGI_appid}!"
	echo "</body></html>"
	exit 0
fi
for nameval in ${output}; do
	eval "${nameval}"
done
CGI_appname="${name}"
CGI_appcname="${cname}"
CGI_flowttl="${flowttl}"
CGI_nodettl="${nodettl}"
CGI_cachesn="${cachesn}"

echo -n "
<table width=600 border=0 cellspacing=1 cellpadding=2> 
<tr id=row1>
        <td width=40></td>
        <td width=80></td>
        <td width=* align=left>
                <input type=text name=flowttl value=\"${CGI_flowttl}\" style=\"width:80;height:21\"></input>
                &nbsp;(,ΧΪ30~65535)
        </td>
</tr>
<tr id=row1>
        <td></td>
        <td>ڵ</td>
        <td>
                <input type=text name=nodettl value=\"${CGI_nodettl}\" style=\"width:80;height:21\"></input>
                &nbsp;(,ΧΪ30~65535)
        </td>
</tr>
<tr id=row1>
        <td></td>
	<td>ڵѡ</td>
	<td><select name=cachesn value=\"${CGI_cachesn}\" style=\"width:80;height=21\"> ";
        if [ "${CGI_cachesn}" = "yes" ]; then
                echo "<option value=yes selected></option>"
                echo "<option value=no></option>"
        else
                echo "<option value=yes></option>"
                echo "<option value=no selected></option>"
        fi
echo -n "
	</td>
</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=hidden name=group value=\"${CGI_group}\"\"></input>
		<input type=hidden name=groupname value=\"${CGI_groupname}\"\"></input>
        </td>
</tr>
</table>
</form>
</body>
</html>
";