<?php

/* ========================================================================
 * $Id: index.php 3830 2017-06-12 16:42:33Z onez $
 * 
 * Email: www@onez.cn
 * QQ: 6200103
 * HomePage: http://www.onezphp.com
 * ========================================================================
 * Copyright 2016-2017 佳蓝科技.
 * 
 * ======================================================================== */

!defined('IN_ONEZ') && exit('Access Denied');
$G['title']=$group['name'];
include_once(dirname(__FILE__).'/header.php');
echo onez('ui')->css($baseurl.'/images/home.css');

/*
      $T=$G['this']->data()->open('member')->one("`grade`='admin'");
      if(!$T){
        $arr=array();
        $arr['nickname']='超级管理员';
        $arr['username']='admin';
        $arr['password']=md5('admin');
        $arr['grade']='admin';
        $G['this']->data()->open('member')->insert($arr);
      }
*/

$groupid=(int)onez()->gp('groupid');
$upid=(int)onez()->gp('upid');
$categorys=array();
$categorys['0']='全部';
$C=$G['this']->data()->open('group_category')->record("1 order by step,id");
foreach($C as $r){
  $categorys[$r['id']]=$r['name'];
}
if($upid){
  $xxx.=" and upid='$upid'";
}

$record=$G['this']->data()->open('group')->page("1$xxx order by step desc,id desc");
?>
<section class="home">
  <div class="container" style="padding: 50px 0">
      <p style="text-align: center;padding-bottom: 30px"><img src="<?php echo $baseurl?>/images/logo.png"></p>
    <div class="row well">
      <div class="" style="padding-bottom: 10px">
        <div class="pull-left">
<?php  foreach($categorys as $k=>$v){ ?>
      <a href="<?php echo onez()->href('/index.php')?>&upid=<?php echo $k?>" class="btn btn-<?php echo $k==$upid?'info':'default'?>">
        <?php echo $v?>
      </a>
<?php  } ?>
        </div>
        <div class="pull-right">
          <?php if($G['userid']){?>
          <img src="<?php echo onez('chat.group.common')->avatar($G['userid'])?>" width="32" height="32" style="border-radius: 50%" />
          <?php echo $G['user']['nickname']?>,你好！
          <?php if($G['user']['grade']=='admin'){?>
            <a href="<?php echo onez()->href('/admin/index.php')?>" class="btn btn-warning">超级管理中心</a>
          <?php }?>
          <a href="<?php echo onez()->href('/exit.php')?>" class="btn btn-danger">退出</a>
        <?php }else{?>
          <a href="<?php echo onez()->href('/login.php')?>" class="btn btn-success">登录</a>
          <a href="<?php echo onez()->href('/register.php')?>" class="btn btn-success">注册</a>
        <?php }?>
        </div>
        <div class="clearfix"></div>
      </div>
      <div class="panel panel-primary">
      	<div class="panel-heading">
          请选择您要参与聊天的群组
          <div class="pull-right"></div>
        </div>
        <div class="panel-body">

      <table class="table table-striped">
        <thead>
          <tr>
            <th>分类</th>
            <th>群组名称</th>
            <th>群简介</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody class="todo-list">
          <?php foreach($record[0] as $rs){ ?>
<?php $C=$G['this']->data()->open('group_category')->one("id='$rs[upid]'"); ?>
          <tr>
            <td><?php echo $C['name']?></td>
            <td>
              <img src="<?php echo onez('chat.group.common')->avatar_group($rs)?>" height="16" /> <?php echo $rs['name']?>
            </td>
            <td>
              <?php echo $rs['summary']?>
            </td>
            <td>
              <a href="<?php echo onez()->href('/group.php?groupid='.$rs['id'])?>" data-width="960" data-height="700" data-title="<img src=<?php echo onez('chat.group.common')->avatar_group($rs)?> height=20 /> <?php echo $rs['name']?>" data-bgcolor="<?php echo $rs['bgcolor']?>" class="onez-miniwin btn btn-xs btn-info">
                进入
              </a>
            </td>
          </tr>
          <?php }?>
        </tbody>
      </table>
      
    <div class="box-footer clearfix">
      <?php echo $record[1]?>
    </div>
      
        </div>
      </div>
    </div>
  </div>
</section>
<?php if($groupid){?>
<script type="text/javascript">
$(function(){
  openWin('<?php echo onez()->href('/group.php?groupid='.$groupid)?>','<?php echo $group['name']?>',960,700,'<?php echo $group['bgcolor']?>');
});
</script>
<?php }
$modalclass='modal-home';
include_once(dirname(__FILE__).'/footer.php');