From cb97372773a384860d64642b0770c4730186ad1a Mon Sep 17 00:00:00 2001 From: "Paul S. Owen" Date: Sun, 10 Mar 2002 00:27:24 +0000 Subject: These are formed from breaking up functions ... modified functions is not yet in CVS and these do nothing right now git-svn-id: file:///svn/phpbb/trunk@2286 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_admin.php | 166 +++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 phpBB/includes/functions_admin.php (limited to 'phpBB/includes/functions_admin.php') diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php new file mode 100644 index 0000000000..99b82df504 --- /dev/null +++ b/phpBB/includes/functions_admin.php @@ -0,0 +1,166 @@ +sql_query($sql)) ) + { + message_die(GENERAL_ERROR, 'Couldn not obtain forums information', '', __LINE__, __FILE__, $sql); + } + + $forum_list = ''; + while( $row = $db->sql_fetchrow($result) ) + { + if ( $is_auth_ary[$row['forum_id']]['auth_read'] && $ignore_forum != $row['forum_id'] ) + { + $forum_list .= ''; + } + } + + $forum_list = ( $forum_list == '' ) ? '' : ''; + + return $forum_list; +} + +// +// Synchronise functions for forums/topics +// +function sync($type, $id) +{ + global $db; + + switch($type) + { + case 'all forums': + $sql = "SELECT forum_id + FROM " . FORUMS_TABLE; + if ( !$result = $db->sql_query($sql) ) + { + message_die(GENERAL_ERROR, 'Could not get forum IDs', '', __LINE__, __FILE__, $sql); + } + + while( $row = $db->sql_fetchrow($result) ) + { + sync("forum", $row['forum_id']); + } + break; + + case 'all topics': + $sql = "SELECT topic_id + FROM " . TOPICS_TABLE; + if ( !$result = $db->sql_query($sql) ) + { + message_die(GENERAL_ERROR, 'Could not get topic ID', '', __LINE__, __FILE__, $sql); + } + + while( $row = $db->sql_fetchrow($result) ) + { + sync("topic", $row['topic_id']); + } + break; + + case 'forum': + $sql = "SELECT MAX(post_id) AS last_post, COUNT(post_id) AS total + FROM " . POSTS_TABLE . " + WHERE forum_id = $id"; + if ( !$result = $db->sql_query($sql) ) + { + message_die(GENERAL_ERROR, 'Could not get post ID', '', __LINE__, __FILE__, $sql); + } + + if ( $row = $db->sql_fetchrow($result) ) + { + $last_post = ( $row['last_post'] ) ? $row['last_post'] : 0; + $total_posts = ($row['total']) ? $row['total'] : 0; + } + else + { + $last_post = 0; + $total_posts = 0; + } + + $sql = "SELECT COUNT(topic_id) AS total + FROM " . TOPICS_TABLE . " + WHERE forum_id = $id + AND topic_status <> " . TOPIC_MOVED; + if ( !$result = $db->sql_query($sql) ) + { + message_die(GENERAL_ERROR, 'Could not get topic count', '', __LINE__, __FILE__, $sql); + } + + if ( $row = $db->sql_fetchrow($result) ) + { + $total_topics = ($row['total']) ? $row['total'] : 0; + } + else + { + $total_topics = 0; + } + + $sql = "UPDATE " . FORUMS_TABLE . " + SET forum_last_post_id = $last_post, forum_posts = $total_posts, forum_topics = $total_topics + WHERE forum_id = $id"; + if ( !$result = $db->sql_query($sql) ) + { + message_die(GENERAL_ERROR, "Could not update forum $id", '', __LINE__, __FILE__, $sql); + } + break; + + case 'topic': + $sql = "SELECT MAX(post_id) AS last_post, MIN(post_id) AS first_post, COUNT(post_id) AS total_posts + FROM " . POSTS_TABLE . " + WHERE topic_id = $id"; + if ( !$result = $db->sql_query($sql) ) + { + message_die(GENERAL_ERROR, "Could not get post ID", '', __LINE__, __FILE__, $sql); + } + + if ( $row = $db->sql_fetchrow($result) ) + { + $sql = "UPDATE " . TOPICS_TABLE . " + SET topic_replies = " . ( $row['total_posts'] - 1 ) . ", topic_first_post_id = " . $row['first_post'] . ", topic_last_post_id = " . $row['last_post'] . " + WHERE topic_id = $id"; + if ( !($result = $db->sql_query($sql)) ) + { + message_die(GENERAL_ERROR, "Could not update topic $id", '', __LINE__, __FILE__, $sql); + } + } + + break; + } + + return true; +} + +?> \ No newline at end of file -- cgit v1.2.1