2 /***************************************************************************
5 * begin : Saturday, Feb 13, 2001
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
9 * $Id: functions_admin.php,v 1.5.2.3 2002/07/19 17:03:47 psotfx Exp $
12 ***************************************************************************/
14 /***************************************************************************
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
22 ***************************************************************************/
25 // Simple version of jumpbox, just lists authed forums
27 function make_forum_select($box_name, $ignore_forum = false, $select_forum = '')
29 global $db, $userdata;
31 $is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata);
33 $sql = "SELECT forum_id, forum_name
34 FROM " . FORUMS_TABLE . "
35 ORDER BY cat_id, forum_order";
36 if ( !($result = $db->sql_query($sql)) )
38 message_die(GENERAL_ERROR, 'Couldn not obtain forums information', '', __LINE__, __FILE__, $sql);
42 while( $row = $db->sql_fetchrow($result) )
44 if ( $is_auth_ary[$row['forum_id']]['auth_read'] && $ignore_forum != $row['forum_id'] )
46 $selected = ( $select_forum == $row['forum_id'] ) ? ' selected="selected"' : '';
47 $forum_list .= '<option value="' . $row['forum_id'] . '"' . $selected .'>' . $row['forum_name'] . '</option>';
51 $forum_list = ( $forum_list == '' ) ? '<option value="-1">-- ! No Forums ! --</option>' : '<select name="' . $box_name . '">' . $forum_list . '</select>';
57 // Synchronise functions for forums/topics
59 function sync($type, $id = false)
66 $sql = "SELECT forum_id
67 FROM " . FORUMS_TABLE;
68 if ( !($result = $db->sql_query($sql)) )
70 message_die(GENERAL_ERROR, 'Could not get forum IDs', '', __LINE__, __FILE__, $sql);
73 while( $row = $db->sql_fetchrow($result) )
75 sync('forum', $row['forum_id']);
80 $sql = "SELECT topic_id
81 FROM " . TOPICS_TABLE;
82 if ( !($result = $db->sql_query($sql)) )
84 message_die(GENERAL_ERROR, 'Could not get topic ID', '', __LINE__, __FILE__, $sql);
87 while( $row = $db->sql_fetchrow($result) )
89 sync('topic', $row['topic_id']);
94 $sql = "SELECT MAX(post_id) AS last_post, COUNT(post_id) AS total
95 FROM " . POSTS_TABLE . "
96 WHERE forum_id = $id";
97 if ( !($result = $db->sql_query($sql)) )
99 message_die(GENERAL_ERROR, 'Could not get post ID', '', __LINE__, __FILE__, $sql);
102 if ( $row = $db->sql_fetchrow($result) )
104 $last_post = ( $row['last_post'] ) ? $row['last_post'] : 0;
105 $total_posts = ($row['total']) ? $row['total'] : 0;
113 $sql = "SELECT COUNT(topic_id) AS total
114 FROM " . TOPICS_TABLE . "
115 WHERE forum_id = $id";
116 if ( !($result = $db->sql_query($sql)) )
118 message_die(GENERAL_ERROR, 'Could not get topic count', '', __LINE__, __FILE__, $sql);
121 $total_topics = ( $row = $db->sql_fetchrow($result) ) ? ( ( $row['total'] ) ? $row['total'] : 0 ) : 0;
123 $sql = "UPDATE " . FORUMS_TABLE . "
124 SET forum_last_post_id = $last_post, forum_posts = $total_posts, forum_topics = $total_topics
125 WHERE forum_id = $id";
126 if ( !$db->sql_query($sql) )
128 message_die(GENERAL_ERROR, 'Could not update forum', '', __LINE__, __FILE__, $sql);
133 $sql = "SELECT MAX(post_id) AS last_post, MIN(post_id) AS first_post, COUNT(post_id) AS total_posts
134 FROM " . POSTS_TABLE . "
135 WHERE topic_id = $id";
136 if ( !($result = $db->sql_query($sql)) )
138 message_die(GENERAL_ERROR, 'Could not get post ID', '', __LINE__, __FILE__, $sql);
141 if ( $row = $db->sql_fetchrow($result) )
143 $sql = ( $row['total_posts'] ) ? "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" : "DELETE FROM " . TOPICS_TABLE . " WHERE topic_id = $id";
144 if ( !$db->sql_query($sql) )
146 message_die(GENERAL_ERROR, 'Could not update topic', '', __LINE__, __FILE__, $sql);