<?php

/* ========================================================================
 * $Id: index.php 5019 2020-05-31 09:40:08Z onez $
 * 
 * Email: www@onez.cn
 * QQ: 6200103
 * HomePage: http://www.onez.cn
 * ========================================================================
 * Copyright 2016-2017 佳蓝科技.
 * 
 * ======================================================================== */

!defined('IN_ONEZ') && exit('Access Denied');
# index
#请求数据
if($MODE=='$post'){
  $action=onez()->gp('action');
  if($action=='data'){
    $data=array();
    $data['title']='管理首页';
    $data['isHome']='1';
    $data['infos']=array();
    $data['infos'][]=array(
      'name'=>'网站数量',
      'num'=>$G['this']->data()->open('sites')->rows("userid='$G[userid]'"),
      'icon'=>'fa fa-sitemap',
      'href'=>'/develop/sites/sites.php',
      'bg'=>'bg-aqua',
    );
    $data['infos'][]=array(
      'name'=>'用户总数',
      'num'=>$G['this']->data()->open('member')->rows("index12='$G[userid]'"),
      'icon'=>'fa fa-users',
      'href'=>'/develop/members/members.php',
      'bg'=>'bg-green',
    );
    $data['infos'][]=array(
      'name'=>'插件数量',
      'num'=>$G['this']->data()->open('plugins')->rows("userid='$G[userid]'"),
      'icon'=>'fa fa-heart',
      'href'=>'/develop/plugins/plugins.php',
      'bg'=>'bg-yellow',
    );
    $data['infos'][]=array(
      'name'=>'消息数量',
      'num'=>$G['this']->data()->open('message')->rows("userid='$G[userid]'"),
      'icon'=>'fa fa-envelope-o',
      'href'=>'/develop/message/message.php',
      'bg'=>'bg-red',
    );
    #数据表
    $data['blocks']=array();
    
    $block=array();
    $datatable=$this->load('datatable');
    $datatable->set('fields','id');
    $datatable->add('网站名','name',array(
      'event'=>array(
        'token'=>'open',
        'action'=>'index.php?siteId=${id}#/design/design.php',
      ),
    ));
    #$datatable->add('核心功能','type',array('options'=>$G['this']->siteTypes(),'faq'=>'什么是核心功能？'));
    $datatable->add('域名','domains');
    $datatable->add('状态','status',array('options'=>$G['this']->siteStatus()));
    $datatable->output($block,array(
      'table'=>'sites',
      'where'=>"userid='$G[userid]' order by id desc",
      'pagesize'=>10,
      'noContent'=>1,
      'noPage'=>1,
      'caption'=>'最新网站列表',
    ));
    $data['blocks'][]=$block;
    
    $block=array();
    $datatable=$this->load('datatable');
    $datatable->set('fields','id,namespace,index12');
    $datatable->set('colFunc',function(&$rs,&$fields){
      global $G;
      $rs['grade']=$rs['key1'];
      $rs['username']=$rs['key2'];
      #$rs['password']=$rs['key3'];
      $rs['nickname']=$rs['key4'];
      !$rs['nickname'] && $rs['nickname']=$rs['key2'];
      $rs['createType']=$rs['key5'];
      $rs['email']=$rs['key6'];
      $rs['mobile']=$rs['key7'];
      $rs['ownerUid']=$rs['index11'];
      $rs['siteId']=$rs['index12'];
      $rs['avatar']=$G['this']->avatarU(substr($rs['namespace'],4));
    });
    $datatable->add('用户编号','id');
    $datatable->add('所属网站','sitename',array('function'=>function($rs){
      global $G;
      return $G['this']->site($rs['siteId'],'name');
    }));
    $datatable->add('显示昵称','nickname',array('function'=>function($rs){
      global $G;
      return '<img src="'.$rs['avatar'].'" style="width:16px;height:16px;"> '.$rs['nickname'];
    }));
    $datatable->add('登录账号','username');
    $datatable->add('注册时间','addtime',array('type'=>'time'));
    $r=$G['this']->user_before();
    $datatable->output($block,array(
      'query'=>"select * from $r[tablename] where tablename='member' and $r[where]$x order by id desc",
      'pagesize'=>10,
      'noContent'=>1,
      'noPage'=>1,
      'caption'=>'最近注册用户',
    ));
    $G['this']->user_after();
    $data['blocks'][]=$block;
    
    
    $A['pagedata']=$data;
  }elseif($action=='remote'){
    $ac=onez()->gp('ac');
    if($ac=='updateCache'){
      $G['this']->siteUpdate();
      @unlink(ONEZ_CACHE_PATH.'/plugins/bs/system.build');
      return $this->ok('更新缓存成功','reload2');
    }
  }
  return;
}
$this->add(array(
  'type'=>'breadcrumb',
  'name'=>'面包屑导航',
  'data'=>'pagedata',
));
?>
<section class="content">
<div class="row">
  <div class="col-lg-3 col-xs-6" v-for="item in pagedata.infos">
    <!-- small box -->
    <div class="small-box" :class="item.bg||'bg-aqua'">
      <div class="inner">
        <h3>{{item.num}}</h3>
        <p>{{item.name}}</p>
      </div>
      <div class="icon">
        <i :class="item.icon"></i>
      </div>
      <a :href="item.href" class="small-box-footer">查看详情 <i class="fa fa-arrow-circle-right"></i></a>
    </div>
  </div>
  <!-- ./col -->
</div>
<div class="box box-info main-infos">
  <div class="box-header with-border">
    <h3 class="box-title">快捷操作</h3>
  </div>
  <div class="box-body">
    <a href="#/develop/sites/edit" class="btn btn-success" args="width=800&height=600&title=新建站点">新建网站</a>
    <button type="button" class="btn btn-info" @click="remote('updateCache')">更新缓存</button>
  </div>
</div>
<div class="row main-tables">
  <div class="col-lg-6 col-xs-12" v-for="item in pagedata.blocks">
    <onez-datatable :data="item" />
  </div>
  <!-- ./col -->
</div>
</section>