<?PHP
// File: $Id: comments.php,v 1.17 2001/12/04 13:07:46 jgm Exp $ $Name: $
// ----------------------------------------------------------------------
// POST-NUKE Content Management System
// Copyright (C) 2001 by the Post-Nuke Development Team.
// http://www.postnuke.com/
// ----------------------------------------------------------------------
// Based on:
// PHP-NUKE Web Portal System - http://phpnuke.org/
// Thatware - http://thatware.org/
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------
// Original Author of file:
// Purpose of file:
// ----------------------------------------------------------------------
if (!eregi("admin.php", $PHP_SELF)) { die ("Access Denied"); }
if (authorised(0, 'Comments::', '::', ACCESS_ADMIN)) {
modules_get_language();
/*********************************************************/
/* Comments Delete Function */
/*********************************************************/
/* Thanks to Oleg [Dark Pastor] Martos from http://www.rolemancer.ru */
/* to code the comments childs deletion function! */
function removeSubComments($tid) {
global $pntable, $dbconn;
csrfcheck();
$count = 0;
$column = &$pntable['comments_column'];
$result = $dbconn->Execute("SELECT $column[tid]
FROM $pntable[comments] WHERE $column[pid]='$tid'");
while (list($stid) = $result->fields) {
$result->MoveNext();
$count += removeSubComments($stid);
}
$dbconn->Execute("DELETE FROM $pntable[comments]
WHERE {$pntable[comments_column][tid]}=$tid");
return $count + 1;
}
function removeComment ($tid, $sid, $ok = 0) {
global $pntable, $dbconn;
csrfcheck();
if ($ok) {
// Call recursive delete function to delete the comment and all its childs.
// Returns total number of comments deleted.
$num_deleted = removeSubComments($tid);
// Update the number of comments in stories table
$column = &$pntable['stories_column'];
$dbconn->Execute("UPDATE $pntable[stories]
SET $column[comments]=$column[comments]-'$num_deleted'
WHERE $column[sid]='$sid'");
pnRedirect("modules.php?op=modload&name=News&file=article&sid=".$sid);
} else {
include("header.php");
GraphicAdmin($hlpfile);
OpenTable();
echo "<center><font class=\"pn-title\"><b>"._REMOVECOMMENTS."</b></font></center>";
CloseTable();
echo "<br>";
OpenTable();
echo "<center>"._SURETODELCOMMENTS."";
echo "<br><br>[ <a href=\"javascript:history.go(-1)\">"._NO."</a> | <a href=\"admin.php?op=RemoveComment&tid=$tid&sid=$sid&ok=1\">"._YES."</a> ]</center>";
CloseTable();
include("footer.php");
}
}
function removePollSubComments($tid) {
global $pntable, $dbconn;
csrfcheck();
$column = &$pntable['pollcomments_column'];
$result = $dbconn->Execute("SELECT $column[tid]
FROM $pntable[pollcomments]
WHERE $column[pid]='$tid'");
while (list($stid) = $result->fields) {
removePollSubComments($stid);
$result->MoveNext();
}
$dbconn->Execute("DELETE FROM $pntable[pollcomments]
WHERE {$pntable[pollcomments_column][tid]}=$tid");
}
function RemovePollComment ($tid, $pollID, $ok=0) {
if ($ok) {
removePollSubComments($tid);
$ModName = "NS-Polls"; // hardcoded $ModName
pnRedirect("modules.php?op=modload&name=".$ModName."&file=index&req=results&pollID=".$pollID);
exit;
} else {
include("header.php");
GraphicAdmin($hlpfile);
OpenTable();
echo "<center><font class=\"pn-title\"><b>"._REMOVECOMMENTS."</b></font></center>";
CloseTable();
echo "<br>";
OpenTable();
echo "<center>"._SURETODELCOMMENTS."";
echo "<br><br>";
echo "<table><tr><td>\n";
echo myTextForm("javascript:history.go(-1)", _NO);
echo "</td><td>\n";
echo myTextForm("admin.php?op=RemovePollComment&tid=$tid&pollID=$pollID&ok=1", _YES);
echo "</td></tr></table>\n";
CloseTable();
include("footer.php");
}
}
switch ($op) {
case "RemoveComment":
removeComment ($tid, $sid, $ok);
break;
case "removeSubComments":
removeSubComments($tid);
break;
case "removePollSubComments":
removePollSubComments($tid);
break;
case "RemovePollComment":
RemovePollComment($tid, $pollID, $ok);
break;
}
} else {
echo "Access Denied";
}
?>