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.5 2005/09/14 19:16:21 acydburn 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 f.forum_id, f.forum_name
34 FROM ' . CATEGORIES_TABLE . ' c, ' . FORUMS_TABLE . ' f
35 WHERE f.cat_id = c.cat_id
36 ORDER BY c.cat_order, f.forum_order';
37 if ( !($result = $db->sql_query($sql)) )
39 message_die(GENERAL_ERROR, 'Couldn not obtain forums information', '', __LINE__, __FILE__, $sql);
43 while( $row = $db->sql_fetchrow($result) )
45 if ( $is_auth_ary[$row['forum_id']]['auth_read'] && $ignore_forum != $row['forum_id'] )
47 $selected = ( $select_forum == $row['forum_id'] ) ? ' selected="selected"' : '';
48 $forum_list .= '<option value="' . $row['forum_id'] . '"' . $selected .'>' . $row['forum_name'] . '</option>';
52 $forum_list = ( $forum_list == '' ) ? '<option value="-1">-- ! No Forums ! --</option>' : '<select name="' . $box_name . '">' . $forum_list . '</select>';
58 // Synchronise functions for forums/topics
60 function sync($type, $id = false)
67 $sql = "SELECT forum_id
68 FROM " . FORUMS_TABLE;
69 if ( !($result = $db->sql_query($sql)) )
71 message_die(GENERAL_ERROR, 'Could not get forum IDs', '', __LINE__, __FILE__, $sql);
74 while( $row = $db->sql_fetchrow($result) )
76 sync('forum', $row['forum_id']);
81 $sql = "SELECT topic_id
82 FROM " . TOPICS_TABLE;
83 if ( !($result = $db->sql_query($sql)) )
85 message_die(GENERAL_ERROR, 'Could not get topic ID', '', __LINE__, __FILE__, $sql);
88 while( $row = $db->sql_fetchrow($result) )
90 sync('topic', $row['topic_id']);
95 $sql = "SELECT MAX(post_id) AS last_post, COUNT(post_id) AS total
96 FROM " . POSTS_TABLE . "
97 WHERE forum_id = $id";
98 if ( !($result = $db->sql_query($sql)) )
100 message_die(GENERAL_ERROR, 'Could not get post ID', '', __LINE__, __FILE__, $sql);
103 if ( $row = $db->sql_fetchrow($result) )
105 $last_post = ( $row['last_post'] ) ? $row['last_post'] : 0;
106 $total_posts = ($row['total']) ? $row['total'] : 0;
114 $sql = "SELECT COUNT(topic_id) AS total
115 FROM " . TOPICS_TABLE . "
116 WHERE forum_id = $id";
117 if ( !($result = $db->sql_query($sql)) )
119 message_die(GENERAL_ERROR, 'Could not get topic count', '', __LINE__, __FILE__, $sql);
122 $total_topics = ( $row = $db->sql_fetchrow($result) ) ? ( ( $row['total'] ) ? $row['total'] : 0 ) : 0;
124 $sql = "UPDATE " . FORUMS_TABLE . "
125 SET forum_last_post_id = $last_post, forum_posts = $total_posts, forum_topics = $total_topics
126 WHERE forum_id = $id";
127 if ( !$db->sql_query($sql) )
129 message_die(GENERAL_ERROR, 'Could not update forum', '', __LINE__, __FILE__, $sql);
134 $sql = "SELECT MAX(post_id) AS last_post, MIN(post_id) AS first_post, COUNT(post_id) AS total_posts
135 FROM " . POSTS_TABLE . "
136 WHERE topic_id = $id";
137 if ( !($result = $db->sql_query($sql)) )
139 message_die(GENERAL_ERROR, 'Could not get post ID', '', __LINE__, __FILE__, $sql);
142 if ( $row = $db->sql_fetchrow($result) )
144 if ($row['total_posts'])
146 // Correct the details of this topic
147 $sql = 'UPDATE ' . TOPICS_TABLE . '
148 SET topic_replies = ' . ($row['total_posts'] - 1) . ', topic_first_post_id = ' . $row['first_post'] . ', topic_last_post_id = ' . $row['last_post'] . "
149 WHERE topic_id = $id";
151 if (!$db->sql_query($sql))
153 message_die(GENERAL_ERROR, 'Could not update topic', '', __LINE__, __FILE__, $sql);
158 // There are no replies to this topic
159 // Check if it is a move stub
160 $sql = 'SELECT topic_moved_id
161 FROM ' . TOPICS_TABLE . "
162 WHERE topic_id = $id";
164 if (!($result = $db->sql_query($sql)))
166 message_die(GENERAL_ERROR, 'Could not get topic ID', '', __LINE__, __FILE__, $sql);
169 if ($row = $db->sql_fetchrow($result))
171 if (!$row['topic_moved_id'])
173 $sql = 'DELETE FROM ' . TOPICS_TABLE . " WHERE topic_id = $id";
175 if (!$db->sql_query($sql))
177 message_die(GENERAL_ERROR, 'Could not remove topic', '', __LINE__, __FILE__, $sql);
182 $db->sql_freeresult($result);