<?php

/* ========================================================================
 * $Id: design.php 5677 2020-07-08 18:17:59Z onez $
 * 
 * Email: www@onez.cn
 * QQ: 6200103
 * HomePage: http://www.onez.cn
 * ========================================================================
 * Copyright 2016-2017 佳蓝科技.
 * 
 * ======================================================================== */

!defined('IN_ONEZ') && exit('Access Denied');
# design
#请求数据
if($MODE=='$post'){
  $action=onez()->gp('action');
  if($action=='data'){
    $ac=onez()->gp('ac');
    if($ac=='updateCache'){
      $G['this']->siteUpdate();
      @unlink(ONEZ_CACHE_PATH.'/plugins/bs/sites/infos/'.$G['site']['id'].'.build');
      return $this->ok('更新缓存成功','reload2');
    }elseif($ac=='export'){
      $file='/bs/'.$G['userid'].'/export.zip';
      $site=onez('bs')->loadSite($G['site'],1);
      $db=$G['this']->data()->open('products')->db;
      $data_table=$G['this']->data()->open('products')->data_table;
      $namespace='data'.$G['site']['data'];
      $T=$db->record($data_table,"tablename","`namespace`='$namespace' order by id");
      $tablenames=array();
      foreach($T as $r){
        $tablenames[$r['tablename']]=$r['tablename'];
      }
      $data=array();
      foreach($tablenames as $tablename){
        $T=$G['this']->data()->open($tablename)->record("1 order by id");
        foreach($T as $rs){
          unset($rs['namespace']);
          unset($rs['tablename']);
          unset($rs['appid']);
          unset($rs['siteid']);
          $data['tables'][$tablename][]=$rs;
        }
      }
      $admins=array();
      $T=$G['this']->userdb()->open('member')->record("1 order by id");
      foreach($T as $rs){
        unset($rs['namespace']);
        unset($rs['tablename']);
        unset($rs['appid']);
        unset($rs['siteid']);
        if($rs['key1']=='admin'){
          if($rs['key2']=='onez'){
            continue;
          }
          $admins[]=$rs['id'];
        }
        $data['tables']['member'][]=$rs;
      }
      $data['admins']=$admins;
      #print_r($G['site']['data']);exit();
      $data=json_encode($data);
      $data=onez()->strcode($data,'ENCODE','onez');
      $data=base64_decode($data);
      $files=array();
      $files['datas.default.db']=$data;
      onez()->write(ONEZ_CACHE_PATH.$file,onez('zip')->zip($files)->data);
      $A['url']=ONEZ_CACHE_URL.$file;
      return $A;
    }
    $pagedata=array();
    
    
    $infos=array();
    $infos[]=array('name'=>'网站编号','value'=>$G['site']['id'],);
    $infos[]=array('name'=>'网站名称','value'=>$G['site']['name'],);
    $infos[]=array('name'=>'网站状态','value'=>$G['this']->siteStatus($G['site']['status']),);
    #$infos[]=array('name'=>'核心功能','value'=>$G['this']->siteTypes($G['site']['type']),);
    
    $T=$G['this']->data()->open('datas')->one("id='{$G['site']['data']}'");
    $infos[]=array('name'=>'数据体系','value'=>$T['name'],);
    
    $T=$G['this']->data()->open('users')->one("id='{$G['site']['user']}'");
    $infos[]=array('name'=>'用户体系','value'=>$T['name'],);
    
    if(!$G['site']['plugins']){
      $infos[]=array('name'=>'安装插件','value'=>'未安装任何插件',);
    }else{
      $names=array();
      foreach($G['site']['plugins'] as $v){
        $names[]=$v['name'];
      }
      $infos[]=array('name'=>'安装插件','value'=>implode(', ',$names),);
    }
    if($G['site']['lockPlugin']){
      $infos[]=array('name'=>'锁定插件','value'=>'<span style="color:red">'.$G['site']['lockPlugin'].'</span>',);
    }
    
    $infos[]=array('name'=>'备注','value'=>$G['site']['summary']?$G['site']['summary']:'(无)',);
    
    $pagedata['infos']=$infos;
    
    $homepage=onez()->homepage();
    $domains=array();
    $bs=$G['this']->data()->open('bs')->one("userid='$G[userid]'");
    if($bs['pandomain']){
      $tmp=str_replace('*',dechex($G['site']['id']+10000),$bs['pandomain']);
      $G['site']['domains']="$tmp\n".$G['site']['domains'];
    }
    foreach(explode("\n",$G['site']['domains']) as $v){
      $v=str_replace(array('http://','http://','/'),'',$v);
      $v=trim($v);
      if($v){
        if(strpos($homepage,$v)===false){
          $domains[]=$v;
        }
      }
    }
    $pagedata['domains']=$domains;
    
    $pagedata['title']='网站信息';
    $pagedata['buttons']=array();
    $G['this']->slot('/design/home',$pagedata);
    
    $A['pagedata']=$pagedata;
  }
  return;
}
$this->add(array(
  'type'=>'breadcrumb',
  'name'=>'面包屑导航',
  'data'=>'pagedata',
));

?>

<section class="content">
<div class="box box-info main-infos">
  <div class="box-header with-border">
    <h3 class="box-title">快捷操作</h3>
  </div>
  <div class="box-body">
    <button type="button" class="btn btn-info" @click="remote('updateCache')">更新缓存</button>
    <button type="button" class="btn btn-info" @click="remote('export')">导出数据</button>
    <button type="button" class="btn btn-info" :class="item.classname" v-if="pagedata.buttons" v-for="item in pagedata.buttons" @click="remote(item.token)" v-html="item.name"></button>
  </div>
</div>
<div class="row">
  <div class="col-md-6 col-xs-12">
    <div class="panel panel-default">
      <div class="panel-heading">基本信息</div>
      <div class="panel-body table-responsive no-padding" style="height: 370px">
<table class="table">
	<tbody>
  	<tr v-for="item in pagedata.infos">
  		<td width="100" v-html="item.name"></td>
  		<td v-html="item.value"></td>
  	</tr>
	</tbody>
</table>
      </div>
    </div>
  </div>
  <div class="col-md-6 col-xs-12">
    <div class="panel panel-default">
      <div class="panel-heading">绑定域名</div>
      <div class="panel-body table-responsive no-padding" style="height: 370px">
<table class="table">
	<tbody>
  	<tr v-for="item in pagedata.domains">
  		<td>
        <a target="_blank" :href="'http://'+item+'/'" islink v-html="item" ></a>
      </td>
  	</tr>
	</tbody>
</table>
      </div>
    </div>
  </div>
</div>
</section>
<?php 
