#!/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`"
if [ "${CGI_agpid}" = "" ]; then
	for agpid in `${FLOWEYE} agp list | awk '{print $1}'`
	do
		CGI_agpid="${agpid}"
		break
	done
fi

echo -n "
<script type=\"text/javascript\" src=\"/img/common.js\"></script>
<script languate=javascript>
function onAddAgp()
{
	window.location.href = \"/cgi-bin/Protocol/usragp_add\";
}
function onEditAgp(agpid)
{
	window.location.href = \"/cgi-bin/Protocol/usragp_edit?agpid=\" + agpid;
}
function onDeleteAgp(agpid)
{
	if (confirm(\"ɾЭ飬ôͬЭйصĲԶɾ,ȷҪɾ?\")) 
		window.location.href = \"${myself}?action=delete\" + \"&agpid=\" + agpid;
}
</script>
";
if [ "${CGI_action}" = "delete" ]; then
	errmsg=`${FLOWEYE} agp remove ${CGI_agpid}`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "ִ:${errmsg}"
	else
		afm_dialog_msg "ɹ!"
		CGI_agpid=""
		for agpid in `${FLOWEYE} agp list | grep "^usr " | awk '{print $2}'`
		do
			CGI_agpid="${agpid}"
			break
		done
	fi
fi

echo -n "
<body>
"; cgi_show_title "Զ->ԶЭ" 
echo -n "
<br>
<table width=900 border=0 cellspacing=1 cellpadding=1>
<tr id=tblhdr height=22>
	<td width=150 align=center>Э</td>
        <td width=620 align=center>Աб</td>
        <td width=*   align=center>
		<input type=button style=\"width:90;height:21px\" value=\"Э>>\" onclick=\"onAddAgp()\"></input>
	</td>
</tr>
";
tbid="row1"
${FLOWEYE} agp list | while read grpid grpname applist
do
	echo "<tr id=${tbid}>"
	echo "<td align=center><a style=\"color:#0000ff\" href=\"javascript:onEditAgp('${grpid}')\">${grpname}</a></td>"
	echo "<td align=center>${applist}</td>"
	echo "<td align=center>"
	echo "<a style=\"color:#0000ff\" href=\"javascript:onEditAgp('${grpid}')\">Ա༭</a>&nbsp;&nbsp;&nbsp;"
	echo "<a style=\"color:#0000ff\" href=\"javascript:onDeleteAgp('${grpid}')\">ɾ</a></td>"
	echo "</tr>"
	if [ "${tbid}" = "row1" ]; then
		tbid="row2"
	else
		tbid="row1"
	fi
done

echo -n "
</table>
</body>
</html>
";