]> git.vanrenterghem.biz Git - www.vanrenterghem.biz.git/blob - phpBB2/includes/functions_admin.php
Add a bit more information about me on the main page.
[www.vanrenterghem.biz.git] / phpBB2 / includes / functions_admin.php
1 <?php
2 /***************************************************************************
3  *                            functions_admin.php
4  *                            -------------------
5  *   begin                : Saturday, Feb 13, 2001
6  *   copyright            : (C) 2001 The phpBB Group
7  *   email                : support@phpbb.com
8  *
9  *   $Id: functions_admin.php,v 1.5.2.5 2005/09/14 19:16:21 acydburn Exp $
10  *
11  *
12  ***************************************************************************/
14 /***************************************************************************
15  *
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.
20  *
21  *
22  ***************************************************************************/
24 //
25 // Simple version of jumpbox, just lists authed forums
26 //
27 function make_forum_select($box_name, $ignore_forum = false, $select_forum = '')
28 {
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)) )
38         {
39                 message_die(GENERAL_ERROR, 'Couldn not obtain forums information', '', __LINE__, __FILE__, $sql);
40         }
42         $forum_list = '';
43         while( $row = $db->sql_fetchrow($result) )
44         {
45                 if ( $is_auth_ary[$row['forum_id']]['auth_read'] && $ignore_forum != $row['forum_id'] )
46                 {
47                         $selected = ( $select_forum == $row['forum_id'] ) ? ' selected="selected"' : '';
48                         $forum_list .= '<option value="' . $row['forum_id'] . '"' . $selected .'>' . $row['forum_name'] . '</option>';
49                 }
50         }
52         $forum_list = ( $forum_list == '' ) ? '<option value="-1">-- ! No Forums ! --</option>' : '<select name="' . $box_name . '">' . $forum_list . '</select>';
54         return $forum_list;
55 }
57 //
58 // Synchronise functions for forums/topics
59 //
60 function sync($type, $id = false)
61 {
62         global $db;
64         switch($type)
65         {
66                 case 'all forums':
67                         $sql = "SELECT forum_id
68                                 FROM " . FORUMS_TABLE;
69                         if ( !($result = $db->sql_query($sql)) )
70                         {
71                                 message_die(GENERAL_ERROR, 'Could not get forum IDs', '', __LINE__, __FILE__, $sql);
72                         }
74                         while( $row = $db->sql_fetchrow($result) )
75                         {
76                                 sync('forum', $row['forum_id']);
77                         }
78                         break;
80                 case 'all topics':
81                         $sql = "SELECT topic_id
82                                 FROM " . TOPICS_TABLE;
83                         if ( !($result = $db->sql_query($sql)) )
84                         {
85                                 message_die(GENERAL_ERROR, 'Could not get topic ID', '', __LINE__, __FILE__, $sql);
86                         }
88                         while( $row = $db->sql_fetchrow($result) )
89                         {
90                                 sync('topic', $row['topic_id']);
91                         }
92                         break;
94                 case 'forum':
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)) )
99                         {
100                                 message_die(GENERAL_ERROR, 'Could not get post ID', '', __LINE__, __FILE__, $sql);
101                         }
103                         if ( $row = $db->sql_fetchrow($result) )
104                         {
105                                 $last_post = ( $row['last_post'] ) ? $row['last_post'] : 0;
106                                 $total_posts = ($row['total']) ? $row['total'] : 0;
107                         }
108                         else
109                         {
110                                 $last_post = 0;
111                                 $total_posts = 0;
112                         }
114                         $sql = "SELECT COUNT(topic_id) AS total
115                                 FROM " . TOPICS_TABLE . "
116                                 WHERE forum_id = $id";
117                         if ( !($result = $db->sql_query($sql)) )
118                         {
119                                 message_die(GENERAL_ERROR, 'Could not get topic count', '', __LINE__, __FILE__, $sql);
120                         }
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) )
128                         {
129                                 message_die(GENERAL_ERROR, 'Could not update forum', '', __LINE__, __FILE__, $sql);
130                         }
131                         break;
133                 case 'topic':
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)) )
138                         {
139                                 message_die(GENERAL_ERROR, 'Could not get post ID', '', __LINE__, __FILE__, $sql);
140                         }
142                         if ( $row = $db->sql_fetchrow($result) )
143                         {
144                                 if ($row['total_posts'])
145                                 {
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))
152                                         {
153                                                 message_die(GENERAL_ERROR, 'Could not update topic', '', __LINE__, __FILE__, $sql);
154                                         }
155                                 }
156                                 else
157                                 {
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)))
165                                         {
166                                                 message_die(GENERAL_ERROR, 'Could not get topic ID', '', __LINE__, __FILE__, $sql);
167                                         }
169                                         if ($row = $db->sql_fetchrow($result))
170                                         {
171                                                 if (!$row['topic_moved_id'])
172                                                 {
173                                                         $sql = 'DELETE FROM ' . TOPICS_TABLE . " WHERE topic_id = $id";
174                         
175                                                         if (!$db->sql_query($sql))
176                                                         {
177                                                                 message_die(GENERAL_ERROR, 'Could not remove topic', '', __LINE__, __FILE__, $sql);
178                                                         }
179                                                 }
180                                         }
182                                         $db->sql_freeresult($result);
183                                 }
184                         }
185                         break;
186         }
187         
188         return true;
191 ?>