<?php

/* ========================================================================
 * $Id: bs.install.php 1450 2020-07-07 15:02:52Z onez $
 * 
 * Email: www@onez.cn
 * QQ: 6200103
 * HomePage: http://www.onez.cn
 * ========================================================================
 * Copyright 2016-2017 佳蓝科技.
 * 
 * ======================================================================== */

!defined('IN_ONEZ') && exit('Access Denied');
#名称：佳蓝智能系统在线安装
#标识：bs.install

class onezphp_bs_install extends onezphp{
  function __construct(){
    
  }
  function init(){
    global $G;
    $hasDB=false;
    if(file_exists(ONEZ_BS_SITE_FILE)){
      $G['ERROR']='为了安全起见，请手动删除config/site.php，然后刷新此页面，才可以继续安装~';
    }
    if(file_exists(ONEZ_ROOT.'/config/db.default.php')){
      $info=include(ONEZ_ROOT.'/config/db.default.php');
      
    }
    if(!$hasDB){#无数据库模式
      define('IS_ONEZ_NODB',1);
    }
    $G['title']='佳蓝应用安装向导';
    $G['this']=onez('bs');
    $G['this']->init();
    onez('vue')->init(__FILE__);
    onez('vue')->addPath($this->path.'/www');
    $G['footer'].=onez('vant')->head(1);
    $G['footer'].=onez('ui')->js($this->url.'/www/js/app.js');
    $buildFile=ONEZ_CACHE_PATH.'/plugins/bs/system.build';
    $_update=onez()->gp('_update');
    if($_update|| !file_exists($buildFile)){
      onez('vue')->build();
      @touch($buildFile);
    }
    onez('vue')->pc('index');
    exit();
  }
  function local_writeable($dir) {
  	$writeable = 0;
  	if(!is_dir($dir)) {
  		@mkdir($dir, 0777);
  	}
  	if(is_dir($dir)) {
  		if($fp = fopen("$dir/test.txt", 'w')) {
  			fclose($fp);
  			unlink("$dir/test.txt");
  			$writeable = 1;
  		} else {
  			$writeable = 0;
  		}
  	}
  	return $writeable;
  }
}