// Check if edit timeframe is still valid $t2 = $CONF_FORUM['allowed_editwindow']; $time = time(); if (time() - $t2 < $edittopic['date']) { $editAllowed = true; } } else { $editAllowed = true; } } } elseif (DB_getItem($_TABLES['gf_attachments'], 'tempfile', "id={$deleteid}") == 1) { $editAllowed = true; } // Moderator or logged-in User is editing their topic post if ($editAllowed) { forum_delAttachment($deleteid); } else { COM_errorLog("Forum warning, invalid attempt to delete an attachment - topic:{$topic}, user:{$_USER['uid']}"); } $template = new Template($_CONF['path_layout'] . 'forum/layout'); $template->set_file('attachfile', 'attachment.thtml'); $template->set_var('attachments', gf_showattachments($topic, 'edit')); $template->set_var('LANG_attachments', $LANG_GF10['attachments']); $template->set_var('LANG_maxattachments', sprintf($LANG_GF10['maxattachments'], $CONF_FORUM['maxattachments'])); // Check and see if the filemgmt plugin is installed and enabled if (function_exists('filemgmt_buildAccessSql')) { // Generate the select dropdown HTML for the filemgmt categories $template->set_var('filemgmt_category_options', gf_makeFilemgmtCatSelect($_USER['uid'])); $template->set_var('LANG_usefilemgmt', $LANG_GF10['usefilemgmt']); $template->set_var('LANG_description', $LANG_GF10['description']); $template->set_var('LANG_category', $LANG_GF10['category']);
$postCount = DB_Count($_TABLES['gf_topic'], 'forum', $forum); DB_query("UPDATE {$_TABLES['gf_forums']} SET topic_count=topic_count-1,post_count={$postCount} WHERE forum_id={$forum}"); $query = DB_query("SELECT MAX(id)as maxid FROM {$_TABLES['gf_topic']} WHERE forum={$forum}"); list($last_topic) = DB_fetchArray($query); if ($last_topic > 0) { DB_query("UPDATE {$_TABLES['gf_forums']} SET last_post_rec={$last_topic} WHERE forum_id={$forum}"); } else { DB_query("UPDATE {$_TABLES['gf_forums']} SET last_post_rec=0 WHERE forum_id={$forum}"); } } else { // Need to check for any attachments and delete if required $q1 = DB_query("SELECT id FROM {$_TABLES['gf_topic']} WHERE id={$msgid}"); while ($A = DB_fetchArray($q1)) { $q2 = DB_query("SELECT id FROM {$_TABLES['gf_attachments']} WHERE topic_id={$A['id']}"); while ($B = DB_fetchArray($q2)) { forum_delAttachment($B['id']); } } DB_query("UPDATE {$_TABLES['gf_topic']} SET replies=replies-1 WHERE (id='{$topicparent}')"); DB_query("DELETE FROM {$_TABLES['gf_topic']} WHERE (id='{$msgid}')"); DB_query("UPDATE {$_TABLES['gf_forums']} SET post_count=post_count-1 WHERE forum_id={$forum}"); // Get the post id for the last post in this topic $query = DB_query("SELECT MAX(id)as maxid FROM {$_TABLES['gf_topic']} WHERE forum={$forum}"); list($last_topic) = DB_fetchArray($query); if ($last_topic > 0) { DB_query("UPDATE {$_TABLES['gf_forums']} SET last_post_rec={$last_topic} WHERE forum_id={$forum}"); } } if ($topicparent == 0) { $topicparent = $msgid; } else {
/** * Delete forum post(s) * * This function will delete the requested forum post and update all the * topic / forum counters. * * @param int $topic_id Topic ID to delete * @param int $topic_parent_id Parent ID of topic * @param int $forum_id Forum ID where topic exists * * @return string HTML to display confirmation */ function moderator_deletePost($topic_id, $topic_parent_id, $forum_id) { global $_CONF, $_USER, $_TABLES, $_FF_CONF, $LANG_GF02; $retval = ''; $topicparent = DB_getItem($_TABLES['ff_topic'], "pid", "id=" . (int) $topic_id); if ($topicparent == 0) { // Need to check for any attachments and delete if required $q1 = DB_query("SELECT id FROM {$_TABLES['ff_topic']} WHERE pid=" . (int) $topic_id . " OR id=" . (int) $topic_id); while ($A = DB_fetchArray($q1)) { $q2 = DB_query("SELECT id FROM {$_TABLES['ff_attachments']} WHERE topic_id=" . (int) $A['id']); while ($B = DB_fetchArray($q2)) { forum_delAttachment($B['id']); } PLG_itemDeleted($A['id'], 'forum'); } DB_query("DELETE FROM {$_TABLES['ff_topic']} WHERE id=" . (int) $topic_id); DB_query("DELETE FROM {$_TABLES['ff_topic']} WHERE pid=" . (int) $topic_id); DB_query("DELETE FROM {$_TABLES['subscriptions']} WHERE (type='forum' AND id=" . (int) $topic_id . ")"); $postCount = DB_Count($_TABLES['ff_topic'], 'forum', (int) $forum_id); $topicsQuery = DB_query("SELECT id FROM {$_TABLES['ff_topic']} WHERE forum=" . (int) $forum_id . " AND pid=0"); $topicCount = DB_numRows($topicsQuery); DB_query("UPDATE {$_TABLES['ff_forums']} SET topic_count=" . (int) $topicCount . ",post_count=" . (int) $postCount . " WHERE forum_id=" . (int) $forum_id); // Remove any lastviewed records in the log so that the new updated topic indicator will appear DB_query("DELETE FROM {$_TABLES['ff_log']} WHERE topic=" . (int) $topicparent); } else { // Need to check for any attachments and delete if required $q1 = DB_query("SELECT id FROM {$_TABLES['ff_topic']} WHERE id=" . (int) $topic_id); while ($A = DB_fetchArray($q1)) { $q2 = DB_query("SELECT id FROM {$_TABLES['ff_attachments']} WHERE topic_id=" . (int) $A['id']); while ($B = DB_fetchArray($q2)) { forum_delAttachment($B['id']); } } DB_query("UPDATE {$_TABLES['ff_topic']} SET replies=replies-1 WHERE id=" . (int) $topicparent); DB_query("DELETE FROM {$_TABLES['ff_topic']} WHERE id=" . (int) $topic_id); $postCount = DB_Count($_TABLES['ff_topic'], 'forum', (int) $forum_id); DB_query("UPDATE {$_TABLES['ff_forums']} SET post_count=" . (int) $postCount . " WHERE forum_id=" . (int) $forum_id); $sql = "SELECT count(*) AS count FROM {$_TABLES['ff_topic']} topic left join {$_TABLES['ff_attachments']} att ON topic.id=att.topic_id WHERE (topic.id=" . (int) $topicparent . " OR topic.pid=" . (int) $topicparent . ") and att.filename <> ''"; $result = DB_query($sql); if (DB_numRows($result) > 0) { list($attCount) = DB_fetchArray($result); DB_query("UPDATE {$_TABLES['ff_topic']} SET attachments=" . (int) $attCount . " WHERE id=" . (int) $topicparent); } PLG_itemDeleted($topic_id, 'forum'); } if ($topicparent == 0) { $topicparent = $topic_id; gf_updateLastPost($forum_id); } else { gf_updateLastPost($forum_id, $topicparent); } CACHE_remove_instance('forumcb'); if ($topicparent == $topic_id) { $link = $_CONF['site_url'] . '/forum/index.php?forum=' . $forum_id; $retval .= FF_statusMessage($LANG_GF02['msg55'], $link, $LANG_GF02['msg55'], true, $forum_id, true); } else { $link = $_CONF['site_url'] . '/forum/viewtopic.php?showtopic=' . $topicparent; $retval .= FF_statusMessage($LANG_GF02['msg55'], $link, $LANG_GF02['msg55'], true, $forum_id, true); } return $retval; }