<!doctype html>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" >
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="Content-Language" content="zh-cn"/>
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
<title><?php echo $Title . ' - ' . $Powered; ?></title>
<link rel="stylesheet" href="./css/install.css?v=v1.0" />
<script src="/theme/qmsoft/js/jquery-1.11.2.min.js"></script>
<script src="/theme/layui/layer.js"></script>
</head>
<body>
<section class="section" style="    position: absolute;
    top: 50%;
    margin-top: -350px;
    left: 50%;
    margin-left: -340px;">
  <form id="install_form" action="index.php?step=2" method="post">
    <input type="hidden" name="force" value="0" />
    <div class="server">
      <h1 style="padding:30px 0;">安装向导</h1>
      <table width="100%" id="table" border="0" cellspacing="1" cellpadding="4">
        <tr>
          <td class="tar">数据库地址</td>
          <td><input type="text" name="dbhost" id="dbhost" value="localhost" class="input">
            <div id="install_tip_dbhost"><span class="gray">一般为127.0.0.1 或 localhost</span></div></td>
        </tr>
        <tr>
          <td class="tar">数据库端口</td>
          <td><input type="text" name="dbport" id="dbport" value="3306" class="input">
            <div id="install_tip_dbport"><span class="gray">一般为3306</span></div></td>
        </tr>
        <tr>
          <td class="tar">数据库名</td>
          <td><input type="text" name="dbname" id="dbname" value="" class="input" onBlur="TestDbPwd(0)">
            <div id="install_tip_dbname"></div></td>
        </tr>
        <tr>
          <td class="tar">数据库用户名</td>
          <td><input type="text" name="dbuser" id="dbuser" value="root" class="input">
            <div id="install_tip_dbuser"></div></td>
        </tr>
        <tr>
          <td class="tar">数据库密码</td>
          <td><input type="password" name="dbpw" id="dbpw" value="" class="input" autoComplete="off" onBlur="TestDbPwd(0)">
            <div id="install_tip_dbpw"></div></td>
        </tr>
        <tr>
          <td class="tar">数据库表前缀</td>
          <td><input type="text" name="dbprefix" id="dbprefix" value="qmcrm_" class="input" >
            <div id="install_tip_dbprefix"><span class="gray">推荐使用&nbsp;qmcrm_</span></div></td>
        </tr>
      </table>
      <table width="100%" id="table" border="0" cellspacing="1" cellpadding="4">
        <tr>
          <td class="tar">设置管理员帐号</td>
          <td><input type="text" name="manager" id="manager" value="admin" class="input">
            <div id="install_tip_manager"></div></td>
        </tr>
        <tr>
          <td class="tar">设置管理员密码</td>
          <td><input type="password" name="manager_pwd" id="manager_pwd" class="input" autoComplete="off">
            <div id="install_tip_manager_pwd"><span class="gray">密码长度至少6位</span></div></td>
        </tr>
        <tr>
          <td class="tar">确认管理员密码</td>
          <td><input type="password" name="manager_ckpwd" id="manager_ckpwd" class="input" autoComplete="off">
            <div id="install_tip_manager_ckpwd"><span class="gray">密码长度至少6位</span></div></td>
        </tr>
        <tr>
          <td colspan="2" style="padding:0 0 0 230px;"><input id="tiaokuan" name="tiaokuan" type="checkbox" style="width: 16px;
    height: 16px;
    line-height: 16px;
    float: none;
    margin-right: 1px;" checked>
            我已阅读并同意<a href="https://www.100926.com/users/tiaokuan" target="_blank">《软件使用条款》</a></td>
        </tr>
        <tr>
          <td colspan="2" style="padding:0 0 0 230px;"><button type="button" onClick="checkForm();" class="btn btn_submit install_btn">开始安装</button></td>
        </tr>
      </table>
      <div id="J_response_tips" style="display:none;"></div>
    </div>
  </form>
</section>
<div  style="width:0;height:0;overflow:hidden;"> <img src="./images/pop_loading.gif"> </div>
<script src="./js/validate.js"></script>
<script src="./js/ajaxForm.js"></script>
<script>

  function TestDbPwd(connect_db)
  {
      var dbHost = $('#dbhost').val();
      var dbUser = $('#dbuser').val();
      var dbPwd = $('#dbpw').val();
      var dbName = $('#dbname').val();
      var dbport = $('#dbport').val();
      var demo  =  $('#demo').val();
      data={'dbHost':dbHost,'dbUser':dbUser,'dbPwd':dbPwd,'dbName':dbName,'dbport':dbport,'demo':demo};
      var url =  "<?php echo $_SERVER['PHP_SELF']; ?>?step=1&testdbpwd=1";
      $.ajax({
          type: "POST",
          url: url,
          data: data,
          dataType:'JSON',
          beforeSend:function(){
          },
          success: function(res){
              if(res.errcode == 1)
              {
                  if(connect_db == 1)
                  {
                    $("#install_form").submit(); // ajax 验证通过后再提交表单
                  }
                  $('#install_tip_dbpw').html(res.dbpwmsg);
                  $('#install_tip_dbname').html(res.dbnamemsg);
              }
              else if(res.errcode == -1)
              {
                  $('#install_tip_dbpw').html(res.dbpwmsg);
              }
              else if(res.errcode == -2)
              {
                  $('#install_tip_dbname').html(res.dbnamemsg);
              }
              else
              {
                  $('#install_tip_dbpw').html(res.dbpwmsg);
              }
          },
          complete:function(){
          },
          error:function(){
              $('#install_tip_dbpw').html('<span for="dbname" generated="true" class="tips_error" style="">数据库连接失败，请重新设定</span>');
          }
      });
  }

  function beforeSubmit()
  {
      var flag = false;
      var dbHost = $('#dbhost').val();
      var dbUser = $('#dbuser').val();
      var dbPwd = $('#dbpw').val();
      var dbName = $('#dbname').val();
      var dbport = $('#dbport').val();
      data={'dbHost':dbHost,'dbUser':dbUser,'dbPwd':dbPwd,'dbName':dbName,'dbport':dbport};
      var url =  "<?php echo $_SERVER['PHP_SELF']; ?>?step=1&check=1";
      $.ajax({
          type: "POST",
          url: url,
          async: false,
          data: data,
          dataType:'JSON',
          beforeSend:function(){
          },
          success: function(res){
              if (-1 == res.code) {
                  layer.closeAll();
                  layer.alert(res.msg, {icon: 5});
              } else {
                  flag = true;
              }
          },
          complete:function(){
          },
          error:function(){
              layer.closeAll();
              layer.alert('网络失败，请刷新页面后重试', {icon: 5});
          }
      });

      return flag;
  }

  function checkForm()
  {
      manager = $.trim($('#manager').val());        //用户名表单
      manager_pwd = $.trim($('#manager_pwd').val());        //密码表单
      manager_ckpwd = $.trim($('#manager_ckpwd').val());    //密码提示区

      if(manager.length == 0 )
      {
        layer.alert('管理员账号不能为空', {icon: 5});
        return false;
      }
      if(manager_pwd.length < 6 )
      {
        layer.alert('管理员密码必须6位数以上', {icon: 5});
        return false;
      }
      if(manager_ckpwd !=  manager_pwd)
      {
        layer.alert('两次密码不一致', {icon: 5});
        return false;
      }
      if($('#tiaokuan').is(':checked')==false)
      {
        layer.alert('请阅读并同意《软件使用条款》', {icon: 5});
        return false;
      }
      layer_loading('正在安装');
      if (!beforeSubmit()) {
        return false;
      }
      TestDbPwd(1);
  }

  /**
   * 封装的加载层
   */
  function layer_loading(msg){
      var loading = layer.msg(
      msg+'...<img src="./images/loading-0.gif"/>&nbsp;请勿刷新页面',
      {
          icon: 1,
          time: 3600000, //1小时后后自动关闭
          shade: [0.2] //0.1透明度的白色背景
      });

      return loading;
  }
</script>

<!--企孟CRM客户管理系统 www.100926.com 版权所有，侵权必究！-->
</body>
</html>