<%@ page contentType="text/html; charset=UTF-8" %>

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>JTopCMS安装 - 系统配置</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
<!--<script type="text/javascript" src="js/jquery-1.11.0.min.js"></script>-->
<script type="text/javascript" src="../core/javascript/commonUtil_src.js"></script>
<script type="text/javascript" src="../core/style/blue/js/jquery-1.7.2.min.js"></script>
		<script type="text/javascript" src="../core/javascript/dialog/lhgdialog.min.js?skin=iblue"></script>
<script type="text/javascript">


	if('true' != '${sessionScope.ORDER_SUCC}')
	{
		window.location = 'installFirst.jsp';
	}



var FancyForm=function(){
	return{
		inputs:".FancyForm input, .FancyForm textarea",
		setup:function(){
			var a=this;
			this.inputs=$(this.inputs);
			a.inputs.each(function(){
				var c=$(this);
				a.checkVal(c)
			});
			a.inputs.live("keyup blur",function(){
				var c=$(this);
				a.checkVal(c);
			});
		},checkVal:function(a){
			a.val().length>0?a.parent("p").addClass("val"):a.parent("p").removeClass("val")
		}
	}
}();
</script>
</head>

<body>
<br/>
<div class="main">
  <div class="main-title">
    <div class="logo">JTopCms 安装向导</div>
    <ul class="ul-list">
      <li><strong>1</strong>使用协议</li>
      <li class="active"><strong>2</strong>系统配制</li>
      <li><strong>3</strong>完成安装</li>
    </ul>
  </div>
  <!--content-->
  <div class="content">
    
    
    <p class="red">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>特别提示：</strong>若选择初始化数据选项，其过程可能要花费数分钟，请耐心等待结束。</p>
    
    <div class="input-box">
      <form id="dbForm" name="dbForm" action="../setup/installDb.cmd" method="post">
        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table FancyForm">
          <tr>
            <td colspan="3">
              <input type="radio"  name="initDb" type="radio" value="true" checked >
              <label for="radio">初始化数据</label>
              <input type="radio" name="initDb" type="radio" value="false" >
              <label for="radio2">只配制连接</label>
              <label for="radio2" style="padding-left:20px; font-size:12px; color:#ccc;">初始化数据库会还原所有存在数据，只配置连接则会保留数据库中原有数据。</label>
            </td>
          </tr>
          
          <tr>
            <td>
              <p>
                <input type="text"  name="dbUrl" id="dbUrl" value="127.0.0.1" class="stext">
                <label class="label-input">服务器地址</label>
			     <span class="fff"></span>
              </p>
            </td>
            <td colspan="2"><span class="text">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;服务器完整域名或IP地址</span></td>
          </tr>
          <tr>
            <td>
            <p>
              <input type="text" name="dbPort" id="dbPort" value="3306" class="stext">
              <label class="label-input">服务器端口</label>
			   <span class="fff"></span>
            </p>
            </td>
            <td colspan="2"><span class="text">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;数据库使用的对外端口</span></td>
          </tr>
          
          <tr>
            <td>
            <p>
              <input type="text" name="dbName" id="dbName" value="jtopcmsv1_beta" class="stext">
              <label class="label-input">数据库名称</label>
			   <span class="fff"></span>
            </p>
            </td>
            <td colspan="2"><span class="text">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;若数据库名称不填写，将自动创建默认数据库</span></td>
          </tr>
          <tr>
            <td>
            <p>
              <input type="text" name="userName" id="userName" value="" class="stext">
              <label class="label-input">用户名</label>
			   <span class="fff"></span>
            </p>
            </td>
            <td colspan="2"><span class="text">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;访问数据库的用户名称</span></td>
          </tr>
          <tr>
            <td>
            <p>
              <input type="password" name="password" id="password" value="" class="stext">
              <label class="label-input">密码</label>
			   <span class="fff"></span>
            </p>
            </td>
            <td colspan="2"><span class="text">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;访问数据库的密码</span></td>
          </tr>
          
        </table>
      </form>
    </div>
  </div>
  <div class="button-box">
    <a id="tdbBtn" href="javascript:checkDbStatus();"class="btn btn-link">测试连接</a>
   
    <a id="subBtn" href="javascript:installDb();"class="btn btn-primary">确认安装</a>
  </div>
</div>
<div class="footer"></div>

<script type="text/javascript">
$(document).ready(function() {
	FancyForm.setup();
});


function installDb()
{
    
   var status = checkDb();
	
	if(1 == status)
	{
	
        var dialog = $.dialog({ 
   					title :'提示',
    				width: '180px', 
    				height: '60px', 
                    lock: true, 
    				icon: '32X32/i.png', 
    				
                    content: '您确认执行安装流程吗？',
                    
                    ok: function () 
                    { 
                    	$('#subBtn').addClass('disabled');
                   	 	$('#subBtn').attr("disabled","disabled");
                   	 	
                   	 	$('#tdbBtn').addClass('disabled');
                   	 	$('#tdbBtn').attr("disabled","disabled");
                    
                   	 	$.dialog.tips('正在执行安装，请等待',9600000000,'loading.gif');

                   	 	
                        var url = "../setup/installDb.cmd";
 					
	 					var postData = encodeURI($("#dbForm").serialize());
	 		 
	 				    $.ajax({
				      		type: "POST",
				       		url: url,
				       		data:postData,
				   
				       		success: function(msg)
				            {       
				               if('success' == msg)
				               {
				               		
				               		window.location = 'installThird.jsp';
				               } 	
				               else
				               {  
				               	    $.dialog({ 
							   					title :'提示',
							    				width: '160px', 
							    				height: '60px', 
							                    lock: true, 
							    				icon: '32X32/fail.png', 
							    				
							                    content: '本次安装失败！', 
							       ok: true 
							                    
								
								 });
				               }   
				            }
				     	});	
				 		
       
    				}, 
    				cancel: true
    				
   		});
		
	} 	
	else
	{
		$.dialog({ 
	   					title :'提示',
	    				width: '200px', 
	    				height: '60px', 
	                    lock: true, 
	    				icon: '32X32/fail.png', 
	    				
	                    content: '数据库连接无效，无法执行安装！', 
	       ok: true 
	                    
		
		 });
	}   

	

}


function checkDbStatus()
{
	var status = checkDb();
	 
	if(1 == status)
	{
			               		
		$.dialog({ 
	   					title :'提示',
	    				width: '150px', 
	    				height: '60px', 
	                    lock: true, 
	    				icon: '32X32/succ.png', 
	    				
	                    content: '数据库连接成功！', 
	       ok: true 
	                    
		
		 });
	} 	
	else
	{
		$.dialog({ 
	   					title :'提示',
	    				width: '145px', 
	    				height: '60px', 
	                    lock: true, 
	    				icon: '32X32/fail.png', 
	    				
	                    content: '数据库连接无效！', 
	      ok: true  
	                    
		
		 });
	}   


}

function checkDb()
{
				 
					var url = "../setup/checkDb.cmd?dbTarget="+$('#dbName').val();
 					
 					var postData = encodeURI($("#dbForm").serialize());
 		 
 					var status = 0;
			 		$.ajax({
			      		type: "POST",
			      		async:false,
			       		url: url,
			       		data:postData,
			   
			       		success: function(msg)
			            {     
			               if('1' == msg)
			               {
			               		
			               		status = 1;
			               } 	
			               else
			               {  
			               	    status = 0;
			               }   
			            }
			     	});	
			     	
			      
			     	 return status;

}
</script>
</body>
</html>
