<?php
/**
 * @version        $Id: guestbook_admin.php 1 8:38 2010年7月9日Z tianya $
 * @package        DedeCMS.Member
 * @copyright      Copyright (c) 2007 - 2010, DesDev, Inc.
 * @license        http://help.dedecms.com/usersguide/license.html
 * @link           http://www.dedecms.com
 */
require_once(dirname(__FILE__)."/config.php");
CheckRank(0,0);
$menutype = 'mydede';
$menutype_son = 'gu';
$pagesize = isset($pagesize) && is_numeric($pagesize) ? $pagesize : 8;
$pageno = isset($pageno) && is_numeric($pageno) ? max(1,$pageno) : 1;
if(empty($dopost)) $dopost = '';


//重载列表
if($dopost=='getlist')
{
    AjaxHead();
    GetList($dsql,$pageno,$pagesize);
    exit();
}

//删除留言
if($dopost=='del')
{
    if(!empty($aid))
    {
        $aid = intval($aid);
        $dsql->ExecuteNoneQuery("Delete FROM `#@__feedback` WHERE aid='$aid' And mid='".$cfg_ml->M_ID."'; ");
    }
    else if(!empty($ids))
    {
        $ids = preg_replace("#[^0-9,]#", '', $ids);
        if($ids!='')
        {
            $dsql->ExecuteNoneQuery("Delete FROM `#@__feedback` WHERE aid in($ids) And mid='".$cfg_ml->M_ID."'; ");
        }
    }
    AjaxHead();
    GetList($dsql, $pageno, $pagesize);
    exit();
}

//第一次进入这个页面
if($dopost=='')
{
    $row = $dsql->GetOne("SELECT COUNT(*) AS dd FROM `#@__feedback` WHERE mid='".$cfg_ml->M_ID."'; ");
    $totalRow = $row['dd'];
    include(dirname(__FILE__)."/templets/feedback_admin.htm");
}

/**
 *  获得特定的关键字列表
 *
 * @access    public
 * @param     object  $dsql  数据库操作类
 * @param     int  $pageno  页面数
 * @param     int  $pagesize  页面尺寸
 * @return    string
 */
function GetList(&$dsql, $pageno, $pagesize)
{
    global $cfg_phpurl,$cfg_ml;
    $pagesize = intval($pagesize);
    $pageno = intval($pageno);
    $start = ($pageno-1) * $pagesize;
    $dsql->SetQuery("SELECT * FROM `#@__feedback` WHERE mid='".$cfg_ml->M_ID."' ORDER BY aid DESC LIMIT $start,$pagesize ");
    $dsql->Execute();
    $line = '';
    while($row = $dsql->GetArray())
    {
$url=GetOneArchive($row['aid']);
        $line .= "<table width='100%' border='0' cellpadding='0' cellspacing='0' style='border-bottom:1px dashed gray;height:40px'>
            <tr>
              <td colspan='6'><strong style='float:left;padding-left: 5px;cursor:hand'><strong><font color='#FF3300'>网友</font><font color='#008080'>评论:</font></strong><a href='".$url['arcurl']."' target='_blank' style='color:#333'>".$row['arctitle']."</a></strong><span style='float:right'>";
//if(!empty($row['gid']))
//        {
//            $line .= " <a href='index.php?uid={$row['uname']}&action=infos' target='_blank' style='display:none'>资料</a><a href='index.php?uid={$row['uname']}' target='_blank' style='display:none'>空间</a><a href='index.php?uid={$row['uname']}&action=guestbook' target='_blank'><font color='green'>回复</font></a>";
//        }
$line .="<input name=\"ids\" type=\"checkbox\" id=\"ids\" value=\"".$row['aid']."\" style=\"display:none\"/>
              <a href='#' onclick='DelNote(".$row['aid'].")' style='color:#51300C;cursor:pointer;'>删除</a></span></td>
            </tr>
            <tr>
<td colspan='6' style='color:gray;'><strong style='float:left;padding-left: 5px;'>姓名:".$row['username']." </strong> <font color='#800000' onclick=\"javascript:alert(document.getElementById('c".$row['aid']."').innerHTML.replace('dddd','\\r\\n'));\" style='cursor:pointer;float:left;'>查看评论</font> <span style='float:right'>日期:".MyDate("Y-m-d",$row['dtime'])."</span>";

        $line .= "</td>
            </tr>
            <tr style='display:none'>
              <td colspan='2' style='padding-left: 5px;' id='c{$row['aid']}'>留言人:".$row['username']."dddd留言内容:".Text2Html($row['msg'])."</td>
            </tr>
          </tbody>
        </table>";
    }
    $line = $line == '' ? '暂无留言' : $line;
    echo $line;
}
function GetList_zzdel(&$dsql, $pageno, $pagesize)//修改备份的原留言列表
{
    global $cfg_phpurl,$cfg_ml;
    $pagesize = intval($pagesize);
    $pageno = intval($pageno);
    $start = ($pageno-1) * $pagesize;
    $dsql->SetQuery("SELECT * FROM `#@__feedback` WHERE mid='".$cfg_ml->M_ID."' ORDER BY aid DESC LIMIT $start,$pagesize ");
    $dsql->Execute();
    $line = '';
    while($row = $dsql->GetArray())
    {

        $line .= "<table width='100%' border='0' cellpadding='0' cellspacing='0' class='list'>
          <thead>
            <tr>
              <th colspan='6'><strong class='fLeft' style='padding-left: 5px;'>留言标题：".$row['title']."</strong><span class='fRight'>
              <input name=\"ids\" type=\"checkbox\" id=\"ids\" value=\"".$row['aid']."\" />
              <a href='#' onclick='DelNote(".$row['aid'].")' style='color:#29A5C9;'>删除</a></span></th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td width='18%' style='padding-left: 10px;'>用户称呼：".$row['uname']."</td>
              <td>时间：".MyDate("Y-m-d H:i",$row['dtime'])."&nbsp;IP地址：".$row['ip']."&nbsp;";

        if(!empty($row['gid']))
        {
            $line .= " <a href='index.php?uid={$row['uname']}&action=infos' target='_blank'>资料</a> <a href='index.php?uid={$row['uname']}' target='_blank'>空间</a> <a href='index.php?uid={$row['uname']}&action=guestbook' target='_blank'>回复</a> ";
        }
        $line .= "</td>
            </tr>
            <tr>
              <td colspan='2' style='padding-left: 10px;'>".Text2Html($row['msg'])."</td>
            </tr>
          </tbody>
        </table>";
    }
    $line = $line == '' ? '暂无留言' : $line;
    echo $line;
}