#!/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/Maintain/`basename $0`"

echo -n "
<script languate=\"javascript\">
function Validate(frm)
{
	var dbfile = document.getElementsByName(\"cfgfile\")[0];
	if (dbfile.value == \"\") {
		alert(\"ļ·!\");
		return false;
	}
	if (confirm(\"ȷҪϴļ?\"))
		return true;
	else
		return false;
}
</script>
";
if [ "${CGI_action}" = "upload" ]; then
	# Get a clean directory
	mkdir -p ${DATAPATH}/config
	rm -rf ${DATAPATH}/config/*
	# verify the file
	endcfg=`cat ${CGI_cfgfile} | grep "ENDCONFIG"`
	if [ "${endcfg}" = "" ]; then
		afm_dialog_msg "ļʹȷļ!"
		rm -rf ${CGI_cfgfile}
		afm_load_page 0 "${myself}"
		exit 0
	else
		# Mv the file to the directory
		mv ${CGI_cfgfile} ${DATAPATH}/config/panabit.conf
		afm_dialog_msg "ϴɹ!"
	fi
fi
if [ "${CGI_action}" = "import" ]; then
	# waiting for 15 seconds for scheduler.
	echo "import_config yes" >> ${EVENTFILE}
	echo "<br><p style=\"color:#0000ff\">ڵ,ҪӣԺ......</p>"
	afm_load_page 15 "${myself}?action=afterimport"
	exit 0
fi
if [ "${CGI_action}" = "afterimport" ]; then
	if [ ! -e ${DATAPATH}/config/panabit.conf ]; then
		afm_dialog_msg "óɹ!"
	else
		afm_dialog_msg "ʧ!"
	fi
fi
if [ "${CGI_action}" = "" ]; then
	if [ -e ${PGETC}/panabit.conf ]; then
		cp -f ${PGETC}/panabit.conf ${TMPPATH}/current.conf
	else
		echo "ENDCONFIG" > ${TMPPATH}/current.conf
	fi
fi

echo -n "
<body>
"; 
cgi_show_title "ù-->õ"
if [ "${CGI_action}" = "upload" ]; then
	echo "<table style=\"width:100%; border-bottom:1px #787882 solid; font:12px; color:#ff0000\">"
	echo "<tr><td align=left>˴<a style=\"color:#0000ff;font:bold  13px;\" href=\"${myself}?action=import\"><b>ϴļ</b></a>(ע⣬̻ж缸)</td></tr>"
	echo "</table>"
fi

echo -n "
<br>
<div style=\"color:#0000ff;font-size:13px\"><b>˵</b></div>
<table width=\"700\" border=0 cellspacing=1 cellpadding=3>
<tr>
    <td width=20></td>
    <td style=\"font:13px bold\" width=*>(1) һ: ϴļϵͳ֤ļ󣬻ʾ</td>
</tr>
<tr>
    <td></td>
    <td style=\"font:13px bold\" width=*>(2) ڶ: òЧ˹̻ỨѼʱ䣬ڴڼڣжϣ׼
</td>
</tr>
<tr>
    <td width=20></td>
    <td style=\"font:13px bold\" width=*>(3) ļв˿ڵĵַ</td>
</tr>
</table>
<form method=post onsubmit=\"return Validate(this)\" action=\"${myself}\" enctype=\"multipart/form-data\">
<table width=700 border=0 cellspacing=1 cellpadding=1 bgcolor=\"#ffffff\">
<tr height=22>
	<td width=20></td>
	<td width=160 style=\"font:13px bold\" align=left>ļ·:</td>
	<td width=* class=cssTDArial align=left>
		<input type=file name=cfgfile style=\"width:430px\">
	</td>
	<td align=right>
		<input type=hidden name=action value=upload></input>
		<input type=submit style=\"width:90\" value=\"ϴļ\"></input>
	</td>
</tr>
</table>
</form>
</body>
</html>
";