#! /bin/sh
#Function:set app
#Writer:liutiansi
#Mail:lliutiansi@gmail.com
#Date:2007-11-21 00:25

#参数文件及验证登录
source config
source checkonline

#返回子程序运行状态临时文件，0为失败，1为成功。
add_app_tempfile=`add_app_tempfile 2>/dev/null` || add_app_tempfile=/tmp/add_app$main_pid

#运行状态标记
returncode=0

#统计参数个数
checkkey=0

#读取app表
app_result=`$mysql_bin -h $mysql_host -u$mysql_user -p$mysql_passwd -e "select * from sysadmin.ty_server_app;" | awk 'NR>1 {print NR,$0}'|awk '{print $2" "$3" off"}'`
#根据$returncode的值判断是否退出或继续循环，=1 or =250时退出。
while test $returncode != 1 && test $returncode != 250
do
exec 3>&1

#弹出选择对话框
value=`dialog --clear  --colors --backtitle "$copyright_info" --title "$system_info" \
--radiolist "\n\n选择应用类型：" 25 70 14 \
$app_result \
2>&1 1>&3`

#获取输入对话框的运行结果值给returncode
returncode=$?
exec 3>&-
	#对returncode值进行选择分支，0为点击[OK]按钮；*为点击[Cancel]按钮或其它中断。
	case $returncode in
	0)				
		#输出选择app类型标志到临时文件；
		echo "$value" > $add_app_tempfile
		exit
		;;
	*)
		dialog \
     	--clear \
     	--title "$system_info" \
     	--yesno "\n\n确定要取消操作吗？" 10 30
     	case $? in
     	0)
					echo "0" > $add_app_tempfile
					break
					;;
     	1)
					returncode=99
					;;
		esac
		;;
	esac
done
