
<?php
require_once('../common.php');
require_once('head.php');
if ($userrow['xm']=="" or $userrow['xb']=="" or $userrow['xh']=="" or $userrow['ch']=="" or $userrow['sr']=="" or $userrow['zz']=="" or $userrow['phone']=="" or $userrow['mail']=="" or $userrow['xz']=="" or $userrow['ah']=="" or $userrow['tc']=="") {
  exit("<script language='javascript'>alert('请先完善资料！');window.location.href='xgzl.php';</script>");
}

if($do=$_POST['do']){
  $info=safestr($_POST['info']);
$time=date("Y-m-d H:i:s");
$qq=$userrow['qq'];
$user=$userrow['xm'];
if ($_POST['info']=="") {
 exit("<script language='javascript'>alert('发布的信息不能为空！！');window.location.href='lyb.php';</script>");
}
if ($db->query("insert into  ".C('DB_PREFIX')."lyb (qq,user,info,time) values ('$qq','$user','$info','$time')")) {
      exit("<script language='javascript'>alert('发布成功！');window.location.href='lyb.php';</script>");
    }else{
      exit("<script language='javascript'>alert('发布失败！');window.location.href='lyb.php';</script>");
    }

}

$p=is_numeric($_GET['p'])?$_GET['p']:'1';
$pp=$p+8;
$pagesize=5;
$start=($p-1)*$pagesize;

  $pages=ceil(get_count('lyb','1=1','id')/$pagesize);
  $ids=$db->get_results("select * from ".C('DB_PREFIX')."lyb order by id desc limit $start,$pagesize");

if($pp>$pages) $pp=$pages;
if($p==1){
  $prev=1;
}else{
  $prev=$p-1;
}
if($p==$pages){
  $next=$p;
}else{
  $next=$p+1;
}
?>

<!DOCTYPE html>
<title>留言板-<?=C('webname')?> </title>
<body>
<!--main content start-->
  <section id="container" class="">
      <section id="main-content">
          <section class="wrapper">
                 <div class="row">
 <div class="col-lg-12">
                   <section class="panel">
                          <form action="?" class="form-horizontal" method="post">
                <input type="hidden" name="do" value="update">
                              <textarea name="info" placeholder="你有什么想和小伙伴说的话吗，或者是想发表的心情？" rows="4" class="form-control input-lg p-text-area"></textarea>
                          
                          <footer class="panel-footer">
                              <button class="btn btn-danger pull-right">发布</button>
                              </form>
                          </footer>
                      </section>   
                </div>
      

   <div class="col-lg-12">
                      <section class="panel">
                          <header class="panel-heading">
                             留言板 
                          </header>
                          <div class="panel-body"> 
                          <article class="media">
                          <?php
      if($ids){foreach($ids as $id){?>

                                                  <a class="pull-left thumb p-thumb">
                                                      <img src="http://q1.qlogo.cn/g?b=qq&nk=<?=$id['qq']?>&s=160">

                                                  </a>
                                                  <p><?=$id['user']?></p>
                                                  <div class="media-body">
                                                      <p class="cmt-head"><?=$id['info']?></p>
                                                      <p> <i class="icon-time"></i><?=$id['time']?></p>
                                                  </div>
                                                   <hr> 
                                                   <?php }?> 
          <?php }?>

                    <? if($pagedo!='seach'){?>
      <div class="row" style="text-align:center;">
        <ul class="pagination pagination-lg">
          <li <?php if($p==1){echo'class="disabled"';}?>><a href="?p=1">首页</a></li>
          <li <?php if($prev==$p){echo'class="disabled"';}?>><a href="?p=<?=$prev?>">&laquo;</a></li>
          <?php for($i=$p;$i<=$pp;$i++){?>
          <li <?php if($i==$p){echo'class="active"';}?>><a href="?p=<?=$i?>"><?=$i?></a></li>
          <?php }?>
          <li <?php if($next==$p){echo'class="disabled"';}?>><a href="?p=<?=$next?>">&raquo;</a></li>
          <li <?php if($p==$pages){echo'class="disabled"';}?>><a href="?p=<?=$pages?>">末页</a></li>
        </ul>
      </div>
      <?php } ?>                              
                                                  
            
               
              </div>
                                                  
              

                   
          
     
<?php
require_once('foot.php');
?>
  </body>
</html>
