www.gusucode.com > weenCompany闻名企业网站系统 4.0.0 繁体中英文 UTF8源码程序 > admin/comments.php

    <?php
define('MOD_ACCESS', true);
define('IN_ADMIN', true);
define('IN_WEENCOMPANY', true);

$rootpath = "./../";

include($rootpath . 'includes/core.php');

PrintHeader('評論管理');

function UpdateComment()
{
  global $DB;

  $commentid  = $_POST['commentid'];
  $comments   = $_POST['comment'];
  $username   = $_POST['username'];

  if($_POST['deletecomment'] == 1)
  {
    $DB->query("DELETE FROM " . TABLE_PREFIX . "comments WHERE commentid = '$commentid'");
  }
  else
  {
    $DB->query("UPDATE " . TABLE_PREFIX . "comments SET comment  = '$comments',
                                                        username = '$username'
                                                                                                    WHERE commentid = '$commentid'");
  }

  PrintRedirect('comments.php', 1);
}

function DeleteComments()
{
  global $DB;

  // get post vars
  $commentids = $_POST['commentids'];

  for($i = 0; $i < count($commentids); $i++)
  {
    $DB->query("DELETE FROM " . TABLE_PREFIX . "comments WHERE commentid = '".$commentids[$i]."'");
  }

  PrintRedirect('comments.php', 1);
}

function TranslateObjectID($moduleid, $objectid)
{
  global $DB;
  $modulepath = $DB->query_first("SELECT modulepath FROM " . TABLE_PREFIX . "modules WHERE moduleid = $moduleid");
  $modulename = explode ("/", $modulepath['modulepath']);
  
  if (strspn("news", $modulename[0])>0)
  {
          $title = $DB->query_first("SELECT title FROM " . TABLE_PREFIX . "$modulename[0] WHERE articleid = $objectid");
          $title = $title[0];
  }
  elseif (strspn("files", $modulename[0])>0)
  {
          $title = $DB->query_first("SELECT title FROM " . TABLE_PREFIX . "$modulename[0] WHERE fileid = $objectid");
          $title = $title[0];
  }
  elseif (strspn("products", $modulename[0])>0)
  {
          $title = $DB->query_first("SELECT title FROM " . TABLE_PREFIX . "$modulename[0] WHERE imageid = $objectid");
          $title = $title[0];
  }
  elseif (strspn("advert", $modulename[0])>0)
  {
          $title = $DB->query_first("SELECT title FROM " . TABLE_PREFIX . "$modulename[0] WHERE ad_id = $objectid");
          $title = $title[0];
  }
  else{
          $title = '未知 (ID ' . $objectid . ')';
  }
  
  
  return $title;
}

function DisplayComment($commentid)
{
  global $DB, $rootpath, $userinfo;

  $comment = $DB->query_first("SELECT *, m.name as modulename FROM " . TABLE_PREFIX . "comments c
                                                           LEFT JOIN " . TABLE_PREFIX . "modules m
                                                           ON m.moduleid = c.moduleid
                               WHERE commentid = '$commentid'");

  PrintSection('編輯評論');


  echo '<form method="post" action="comments.php">
        <input type="hidden" name="commentid"  value="'.$commentid.'" />
                <input type="hidden" name="action" value="updatecomment" />

        <table width="100%" border="0" cellpadding="5" cellspacing="0">
                <tr>
            <td class="tdrow2" width="15%"><b>刪除評論:</b></td>
            <td class="tdrow3" width="75%" valign="top">
              <input type="checkbox" name="deletecomment"  value="1"> 是否刪除此條評論?
            </td>
        </tr>
                <tr>
          <td class="tdrow2" width="15%"><b>所屬模塊:</b></td>
          <td class="tdrow3" width="75%" valign="top">'.$comment['modulename'].'
          </td>
        </tr>
                <tr>
          <td class="tdrow2" width="15%"><b>所屬主題:</b></td>
          <td class="tdrow3" width="75%" valign="top">'.TranslateObjectID($comment['moduleid'], $comment['objectid']).'
          </td>
        </tr>
                <tr>
          <td class="tdrow2" width="15%"><b>發表人:</b></td>
          <td class="tdrow3" width="75%" valign="top">
            <input type="text" name="username" value="'.CleanFormValue($comment['username']).'" />
          </td>
        </tr>
        <tr>
          <td class="tdrow2" width="15%" valign="top"><b>評論內容:</b></td>
          <td class="tdrow3" width="75%" valign="top">
            <textarea name="comment" cols="54" rows="5">'.$comment['comment'].'</textarea>
          </td>
        </tr>
        <tr>
          <td colspan="2" align="center" class="tdrow1">
            <input type="submit" value=" 保存更新 " />
                  </td>
        </tr>
        </table>
        </form>';
  EndSection();

}

function DisplayModuleCounts()
{
  global $DB;

  $getcomments = $DB->query("SELECT m.moduleid, m.name AS modulename, COUNT(*) As count FROM " . TABLE_PREFIX . "comments c
                                   LEFT JOIN " . TABLE_PREFIX . "modules m
                                                           ON m.moduleid = c.moduleid
                                                           GROUP BY m.moduleid
                                                           ORDER BY count DESC");

  PrintSection('模塊評論統計');

  echo '<table width="100%" border="0" cellpadding="5" cellspacing="0">
        <tr>
          <td class="tdrow1">模塊名稱</td>
          <td class="tdrow1">評論數量</td>
        </tr>';

  while($comment = $DB->fetch_array($getcomments))
  {
    echo '<tr>
            <td class="tdrow2"><a href="comments.php?action=displaycomments&moduleid=' . $comment['moduleid']. '">' .$comment['modulename'].'</a></td>
            <td class="tdrow3">'.$comment['count'].'</td>
          </tr>';
  }

  echo '</table>';

  EndSection();

}


// ######################### Instructions ##########################

function PrintInstructions()
{
  PrintSection('關於評論管理');
  echo '<table width="100%" border="0" cellpadding="5" cellspacing="0">
        <tr>
          <td class="tdrow2">
          weenCompany聞名企業網站系統有些模塊(包括其複製模塊)允許用戶發表評論, 此"評論管理"工具可對這些評論進行集中管理.
          </td>
        </tr>
        </table>';
  EndSection();
}

function DisplayComments($moduleid)
{
  global $DB;

  if($moduleid == -1)
  {
    // Latest Comments
        $title = '最新評論';
        $getcomments = $DB->query("SELECT c.*, m.name AS modulename FROM " . TABLE_PREFIX . "comments c
                                     LEFT JOIN " . TABLE_PREFIX . "modules m
                                                                 ON m.moduleid = c.moduleid
                                                                 ORDER BY date DESC LIMIT 0,20");
  }
  else
  {
    $title = $DB->query_first("SELECT name FROM " . TABLE_PREFIX . "modules
                                            WHERE moduleid = $moduleid");

        $title = $title[0] . '_評論條目';

    $getcomments = $DB->query("SELECT * FROM " . TABLE_PREFIX . "comments
                                                           WHERE moduleid = '$moduleid'
                                                           ORDER BY date DESC");
  }

  PrintSection($title);

  echo '<form action="comments.php" method="POST"  name="deletecommentsform">
        <input type="hidden" name="action" value="deletecomments">

        <table width="100%" border="0" cellpadding="5" cellspacing="0">
        <tr>
          <td class="tdrow1">評論內容</td>';
  if($moduleid == -1)
    echo '<td class="tdrow1">所屬模塊</td>';

  echo   '<td class="tdrow1">所屬主題</td>
          <td class="tdrow1">發表人</td>
          <td class="tdrow1">日期</td>
          <td class="tdrow1" width="150"><input type="checkbox" checkall="group" onclick="javascript: return select_deselectAll(\'deletecommentsform\', this, \'group\');">刪除</td></tr>';

  while($comment = $DB->fetch_array($getcomments))
  {
    $comment['comment'] = ShortTitle($comment['comment'], 40);
	
    echo '<tr>
            <td class="tdrow2"><a href="comments.php?action=displaycomment&commentid=' . $comment['commentid']. '">' . $comment['comment'] . '</a></td>';

        if($moduleid == -1)
          echo '<td class="tdrow3">'.$comment['modulename'].'</td>';

        echo   '<td class="tdrow2">'.ShortTitle(TranslateObjectID($comment['moduleid'], $comment['objectid']), 40).'</td>
            <td class="tdrow3">'.$comment['username'].'</td>
                        <td class="tdrow2">'.DisplayDate($comment['date']).'</td>
            <td class="tdrow3"><input type="checkbox" name="commentids[]" value="'.$comment['commentid'].'" checkme="group"></td>
          </tr>';
  }

  echo '<tr>
          <td class="tdrow1" bgcolor="#FCFCFC" colspan="6" align="center">
           <input type="submit" value=" 刪除評論 " />
          </td>
        </tr>
        </table>

        </form>';

  EndSection();
}

// display the default page
function DisplayDefault()
{
  global $DB;
  global $moduleid;

  PrintInstructions();

  DisplayModuleCounts();

  DisplayComments(-1);
}


$action    = isset($_POST['action'])        ? $_POST['action']   : (isset($_GET['action']) ? $_GET['action'] : '');
$commentid = is_numeric($_GET['commentid']) ? $_GET['commentid'] : 0;
$moduleid  = is_numeric($_GET['moduleid'])  ? $_GET['moduleid']  : 0;

// ############################# Select Function ############################

switch($action)
{
  case 'displaycomment':
    DisplayComment($commentid);
  break;

  case 'displaycomments':
    DisplayComments($moduleid);
  break;

  case 'deletecomments':
    DeleteComments();
  break;

  case 'updatecomment':
    UpdateComment();
  break;

  default:
    DisplayDefault();
}