<HTML>
<HEAD>
	<TITLE>{siteTitle}</TITLE>
	<meta http-equiv=content-type content="text/html; charset=gb2312">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<LINK href="../CSS/Android.css" type=text/css rel=stylesheet>
    <script type="text/javascript" src="../Offline/common/string.js.php"></script>
    <script type="text/javascript" src="../Offline/script/animation.js"></script>
	<script type="text/javascript" src="../Offline/common/jquery-1.6.2.min.js.php"></script>
	<SCRIPT type=text/javascript>
	if( rexseeScreen.getScreenHeight() < 500 || rexseeScreen.getScreenWidth() < 500 )
	{
		rexseeScreen.setScreenOrientation('landscape');
		document.write('<LINK href="../Offline/resources/phone.css" type=text/css rel=stylesheet>');
	}
	else
	{
		document.write('<LINK href="../Offline/resources/pad10.css" type=text/css rel=stylesheet>');
	}
	window.onRexseeReady = function(){
			rexseeMenu.setOptionsMenuId("mainOptionsMenu1");
			rexseeTitleBar.setStyle('visibility:hidden;');
			rexseeStatusBar.setStyle('visibility:hidden;');
			
			rexseeSpecialKey.enableBackKeyListener(false);
			//rexseeSpecialKey.enableVolumeKeyListener(false);
			//rexseeBrowserStyle.setStyle('browser-zoom-button:visible;');
			
			//正在加载信息
			rexseeDialog.toast("正在努力为您加载信息...");
	}
	var theHomeURL = (rexseeApplication.getHome() == '' ) ? rexseeApplication.getDeveloperHome() : rexseeApplication.getHome();
	var remoteXMLURL = str_replace('default.html','bulidClient.xml',theHomeURL);
	var remoteServer = str_replace('Offline/default.html','',theHomeURL);
	var ser_version = rexseeClient.getLatestVersion(remoteXMLURL);
	var cli_version = rexseeClient.getVersion('bulidClient.xml');
	function updateClientVersion()
	{
		document.getElementById('updateBtn').disabled = true;

		//更新本地数据库
		sql = " SELECT * FROM eq_survey_list ORDER BY surveyID DESC; ";
		var surveyRow = eval('('+getDbRows(sql,'rexsee:enableq.db')+')');
		if( count(surveyRow.rows) != 0 )
		{
			for( var tmp in surveyRow.rows )
			{
				//修改原有记录表
				if( rexseeDatabase.tableExists('eq_response_'+surveyRow.rows[tmp][0],'rexsee:enableq.db') )
				{
					var dataCheckRow = eval('('+ getDbRows('SELECT * FROM eq_response_'+surveyRow.rows[tmp][0]+' WHERE responseID =0 LIMIT 1','rexsee:enableq.db')+')');
					if( ! in_array('submitTime',dataCheckRow.columns) )
					{
						sql = " ALTER TABLE eq_response_"+surveyRow.rows[tmp][0]+" ADD submitTime int(11) NOT NULL default '0' ";
						rexseeDatabase.exec(sql,'rexsee:enableq.db');
					}
					if( ! in_array('taskID',dataCheckRow.columns) )
					{
						sql = " ALTER TABLE eq_response_"+surveyRow.rows[tmp][0]+" ADD taskID int(30) NOT NULL default '0' ";
						rexseeDatabase.exec(sql,'rexsee:enableq.db');
					}
					dataCheckRow = null;
					/*var dataCheckRow = eval('('+ getDbRows("SELECT COUNT(*) as num FROM sqlite_master where tbl_name='eq_response_"+surveyRow.rows[tmp][0]+"' and sql LIKE '%submitTime%'",'rexsee:enableq.db')+')');
					if( parseInt(dataCheckRow.rows[0][0]) == 0 )
					{
						sql = " ALTER TABLE eq_response_"+surveyRow.rows[tmp][0]+" ADD submitTime int(11) NOT NULL default '0' ";
						rexseeDatabase.exec(sql,'rexsee:enableq.db');
					}*/			
				}
			}
		}
		
		var theUploadURL = remoteServer+'Offline/UserAction.php';
		var postData = eval('({surveyID: "0", userId: "{userId}",nickName: "{nickName}",actionMess:"下载客户端新版本程序",actionType:5})');
		$.ajaxSetup({async:false});
		$.post(theUploadURL, postData);			 

		if( cli_version == -1 )
		{
			rexseeBrowser.clearCache();
			rexseeBrowser.clearHistory();
			buildClient();
		}
		else
		{
			if (ser_version > cli_version)
			{
				rexseeBrowser.clearCache();
				rexseeBrowser.clearHistory();
				buildClient();
			}
			else
			{
				rexseeDialog.toast('客户端程序已经是最新版本!');
			}		
		}
	}
	function buildClient()
	{
		rexseeDialog.toast('正在创建客户端到本地...');
		rexseeClient.build(remoteXMLURL);
		rexseeFile.putContent(rexseeClient.getRoot('bulidClient.xml')+'script/user.js','var nickUserName ="{nickUserName}";var nickUserId ="{userId}";','GBK');
		rexseeClient.launch(remoteXMLURL);
	}
	function Init()
	{
		if (ser_version > cli_version)
		{
			document.getElementById('updateBtn').disabled = false;
			document.getElementById("infocontent").innerHTML = "&nbsp;<img src=\"..\/Images\/check_yes.gif\" width=\"16px\" height=\"16px\">&nbsp;<font color=green><b>可以更新客户端程序</b></font>";
		}
		else
		{
			document.getElementById('updateBtn').disabled = true;
			document.getElementById("infocontent").innerHTML = "&nbsp;<img src=\"..\/Images\/check_no.gif\" width=\"16px\" height=\"16px\">&nbsp;<font color=red><b>客户端程序已经是最新版本</b></font>";
		}
	}
	</SCRIPT>
</HEAD>
<body style="background:#e5e5e5;color:#666" onload="javascript:Init();">

<div class="titlebar">
 <table width=100%>
   <tr><td width=85><a id="rtnURL"><img src="../Images/return.png" width=85 height=30 border=0></a></td>
   <td align=center width=* class="pageTitle">程序更新</td>
   <td width=85><a href="Logout.php"><img src="../Images/lout.png" width=85 height=30 border=0></a></td>
 </table>
</div>

<div class="notesInfo">【说明】欢迎您，{nickName}，更新客户端程序版本。</div>

<div class="invertedshiftdown">
	<ul>
	<li><a href="javascript:animationLoad('DownSurveyList.php');">下载问卷</a></li>
	<li><a href="javascript:animationLoad('DownTaskList.php');">任务下载</a></li>
	<li><a href="javascript:animationLoad('UploadSurveyData.php');">数据上行</a></li>
	<li><a href="javascript:animationLoad('AbnormalSurveyList.php');">异常处理</a></li>
	<li><a href="javascript:animationLoad('DeleSurveyList.php');">问卷删除</a></li>
	<li class="current"><a href="javascript:animationLoad('CheckServerVersion.php');">程序更新</a></li>
	</ul>
</div>

<div id="androidList" style="padding-left:10px;padding-right:10px;padding-top:5px;background: #e5e5e5;">
 <form name="form" id="form" method="post">
 <table width=100% style="border:#d9d9d9 2px solid;margin-bottom:5px;margin-top:5px;background:#ffffff">
   <tr>
      <td height=70 width=* valign=center style="border-bottom:#ddd 1px solid;padding-left:20px;" class="actioninfo">服务器端程序版本：</td>
	  <td align=right style="border-bottom:#ddd 1px solid" class="actioninfo">&nbsp;<script>document.write(ser_version)</script>&nbsp;</td>
   </tr>
   <tr>
      <td height=70 width=* valign=center class="actioninfo">当前客户端程序版本：</td>
	  <td align=right class="actioninfo">&nbsp;<script>document.write(cli_version)</script>&nbsp;</td>
   </tr>
 </table>
 <table width=100%>
   <tr><td><input type="button" name="updateBtn" id="updateBtn" class=btnclass value="开始更新" onclick="javascript:updateClientVersion();">&nbsp;&nbsp;<span id="infocontent"></span>
   </td></tr>
 </table>
 
 </form>
</div>
<script>
	$('#rtnURL').attr('href',"javascript:animationLoad('"+rexseeClient.getRoot('bulidClient.xml')+"index.html');");
</script>
<script>scroll(0, 0);</script>
</body>
</html>