Ok i'm back with another problem, i've installed about 35 hacks on my forum, so functions.php has changed A LOT. I just noticed that I haven't done this hack! :-/
But my code has changed, I'll paste it here, please can someone show me what to do so whenver a post is deleted, a thread is deleted, or a forum pruned, post counts do NOT go down, infact I never want postcounts to go down.
Code:
// ###################### Start delete thread #######################
function deletethread($threadid,$countposts=1) {
global $DB_site;
// decrement users post counts
if ($threadinfo=getthreadinfo($threadid)) {
$postids="";
$attachmentids="";
$posts=$DB_site->query("SELECT userid,attachmentid,postid FROM post WHERE threadid='$threadid'");
while ($post=$DB_site->fetch_array($posts)) {
if ($countposts) {
if (!isset($userpostcount["$post[userid]"])) {
$userpostcount["$post[userid]"] = -1;
} else {
$userpostcount["$post[userid]"]--;
}
}
$postids.=$post['postid'].",";
if ($post['attachmentid'] != 0) {
$attachmentids .= $post['attachmentid'].",";
}
unindexpost($post['postid']);
}
if ($attachmentids != '' ) {
// make sure you don't remove attachments that are already in use!
$checkattachments=$DB_site->query("SELECT DISTINCT attachmentid FROM post WHERE attachmentid IN ($attachmentids"."0) AND threadid<>'$threadid'");
$omitattachmentids="";
while ($omitattach=$DB_site->fetch_array($checkattachments)) {
$omitattachmentids.=$omitattach['attachmentid'].",";
}
$DB_site->query("DELETE FROM attachment WHERE attachmentid IN ($attachmentids"."0) AND NOT attachmentid IN ($omitattachmentids"."0)");
}
$storeadmin = $DB_site->query_first("SELECT * FROM storeadmin");
$storemin=$storeadmin[newthread];
$DB_site->query("UPDATE user SET storep=storep-'$storemin' WHERE userid='$postuserid'");
if ($postids!="") {
$DB_site->query("DELETE FROM post WHERE postid IN ($postids"."0)");
}
if ($threadinfo['pollid']!=0) {
$DB_site->query("DELETE FROM poll WHERE pollid='$threadinfo[pollid]'");
$DB_site->query("DELETE FROM pollvote WHERE pollid='$threadinfo[pollid]'");
}
$DB_site->query("DELETE FROM thread WHERE threadid='$threadid'");
$DB_site->query("DELETE FROM thread WHERE open=10 AND pollid='$threadid'"); // delete redirects
$DB_site->query("DELETE FROM threadrate WHERE threadid='$threadid'");
$DB_site->query("DELETE FROM subscribethread WHERE threadid='$threadid'");
}
}
// ###################### Start delete post #######################
function deletepost($postid,$countposts=1,$threadid=0) {
global $DB_site;
// decrement user post count
if ($postinfo=getpostinfo($postid)) {
$storeadmin = $DB_site->query_first("SELECT * FROM storeadmin");
$storem=$storeadmin[newreply];
$DB_site->query("UPDATE user SET storep=storep-'$storem' WHERE userid='$postinfo[userid]'");
if ($postinfo['attachmentid']) {
// make sure you don't remove attachments still in use
$otherattachs=$DB_site->query("SELECT attachmentid FROM post WHERE attachmentid=$postinfo[attachmentid] AND threadid<>'$postinfo[threadid]'");
if ($DB_site->num_rows($otherattachs)==0) {
$DB_site->query("DELETE FROM attachment WHERE attachmentid=$postinfo[attachmentid]");
$DB_site->query("UPDATE thread SET attach = attach - 1 WHERE threadid = '$threadid'");
}
}
$DB_site->query("DELETE FROM post WHERE postid='$postid'");
}
}
// ###################### Start make login code #######################
|