<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="gb2312">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="renderer" content="webkit">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<title>Ϣ²۰װ</title>
<style>
body {
background: #444;
font-family: "Lucida Sans Unicode", Helvetica, "Microsoft Yahei", "Microsoft JhengHei", STHei, "Meiryo UI";
height:100%;color:#fff
}
a{color:#fff}
.abt{border: 1px solid #EFEFEF;
border-radius: 5px;
padding: 6px;
cursor: pointer; background: #fff;color:#000}
.txt{}
.green{color:#28a745;}
.red{color:red;}
.ft{margin-top:80px;}
</style>
</head>
<body>
<div style="padding:60px 0 0 0;line-height:30px;max-width:750px;margin:0 auto">
<h1>ӭʹ</h1>
<p class="txt">Ϣ²һPHP+Sqliteϵͳ</p>
<?php
$install = isset($_GET['install'])?$_GET['install']:'0';
function endfoot(){
     echo '<p class="ft" align="center">Powered by <a href="https://7alk.com/" target="_blank">7alk</a> Talk ,  Design by <a href="https://www.4jax.net/" target="_blank">www.4jax.net</a></p>';
     exit('</div></body></html>');      
}
//function install(){
$cfg = ROOT_PATH.'app/class/cfg.php';
 if($install == '0'){ 
		  $err = 0;
		   
  if(PHP_VERSION>=5.4)
  {
   echo '<p class="green">ǰPHP汾'.PHP_VERSION.' []</p>';
  }
else
  {
    echo '<p class="red">PHP汾Ҫ5.4ǰ汾'.PHP_VERSION.'[]</p>';
    $err++;
  }


  if(is_writable(DB))
  {
  echo '<p class="green">ݿд[]</p>';
  }
else
  {
    echo '<p class="red">'.DB.'ݿⲻд[]</p>';
    $err++;
  }
  if(extension_loaded("pdo_sqlite")){
     echo '<p class="green">PDO_SQLITEã[]</p>';
  }else{
    echo '<p class="red">PDO_SQLITEݿⲻ֧֣[]</p>';
    $err++;
  }
if(is_writable($cfg))
  {
    echo '<p class="green">ļд[]</p>';
  }
else
  {
	echo '<p class="red">'.$cfg.'ļд[]</p>';
    $err++;
}     if($err>0){echo 'װ/Ȩ޲㣬޷ʹ';endfoot();}
		   echo '<a class="abt" href="?install=1">ʼװ</a>';
           endfoot();
      }
      $key =  md5(time().'XXGMSG');
      $db = substr($key,16,12);;
      $key = substr($key,10,6);	  
	  $f = file_get_contents($cfg);
	  $ckey = "define('KEY','$key');";
	  $cdb = "define('DB',ROOT_PATH.'app/db/$db.db');";
      $f = preg_replace("/define\('KEY','.+?'\);/i",$ckey,$f);
      $f = preg_replace("/define\('DB',.+?;/i",$cdb,$f);
	  $f = preg_replace("/\/\*install-start\*\/.+?\/\*install-end\*\//is",'/*installed*/',$f);
	  rename(DB,ROOT_PATH."app/db/".$db.".db");
	  $f = file_put_contents($cfg,$f);
	  $_SESSION[$key.'set'] = array();
          $_SESSION[$key.'admin'] = 1;
	  $p = 'admin';//.substr($key,2,4);
	  $webpss = md5($key.$p);
	  try{ 
            $dbh = new PDO('sqlite:'.ROOT_PATH."app/db/".$db.".db");
            $dbh->exec("update config set ver='v1.01',pass='{$webpss}' where id=1");
          }catch (PDOException $e)
          {
            exit('<p>ݿʧܣܿռ䲻֧pdo_sqlite</p>');
          }
          echo '<p>ϵͳʼɣΪ'.$p.'</p>' ;
	  echo '<p><a class="abt" href="?ok">ʼʹ</a></p>';
	  //echo '<script>alert("ϵͳʼɣ\r\n뵽ϵͳ\r\n´޷½");location.reload();</script>';
	  unlink('app/class/install.txt');
	  endfoot();   
//} 
?>