home *** CD-ROM | disk | FTP | other *** search
/ PC Advisor 2006 January / PCA126_DVD.iso / ADVISORS / phpBB-2.0.17 / phpBB2 / includes / functions_admin.php < prev    next >
Encoding:
PHP Script  |  2005-07-19  |  4.6 KB  |  155 lines

  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.3 2002/07/19 17:03:47 psotfx Exp $
  10.  *
  11.  *
  12.  ***************************************************************************/
  13.  
  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.  ***************************************************************************/
  23.  
  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;
  30.  
  31.     $is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata);
  32.  
  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)) )
  37.     {
  38.         message_die(GENERAL_ERROR, 'Couldn not obtain forums information', '', __LINE__, __FILE__, $sql);
  39.     }
  40.  
  41.     $forum_list = '';
  42.     while( $row = $db->sql_fetchrow($result) )
  43.     {
  44.         if ( $is_auth_ary[$row['forum_id']]['auth_read'] && $ignore_forum != $row['forum_id'] )
  45.         {
  46.             $selected = ( $select_forum == $row['forum_id'] ) ? ' selected="selected"' : '';
  47.             $forum_list .= '<option value="' . $row['forum_id'] . '"' . $selected .'>' . $row['forum_name'] . '</option>';
  48.         }
  49.     }
  50.  
  51.     $forum_list = ( $forum_list == '' ) ? '<option value="-1">-- ! No Forums ! --</option>' : '<select name="' . $box_name . '">' . $forum_list . '</select>';
  52.  
  53.     return $forum_list;
  54. }
  55.  
  56. //
  57. // Synchronise functions for forums/topics
  58. //
  59. function sync($type, $id = false)
  60. {
  61.     global $db;
  62.  
  63.     switch($type)
  64.     {
  65.         case 'all forums':
  66.             $sql = "SELECT forum_id
  67.                 FROM " . FORUMS_TABLE;
  68.             if ( !($result = $db->sql_query($sql)) )
  69.             {
  70.                 message_die(GENERAL_ERROR, 'Could not get forum IDs', '', __LINE__, __FILE__, $sql);
  71.             }
  72.  
  73.             while( $row = $db->sql_fetchrow($result) )
  74.             {
  75.                 sync('forum', $row['forum_id']);
  76.             }
  77.                break;
  78.  
  79.         case 'all topics':
  80.             $sql = "SELECT topic_id
  81.                 FROM " . TOPICS_TABLE;
  82.             if ( !($result = $db->sql_query($sql)) )
  83.             {
  84.                 message_die(GENERAL_ERROR, 'Could not get topic ID', '', __LINE__, __FILE__, $sql);
  85.             }
  86.  
  87.             while( $row = $db->sql_fetchrow($result) )
  88.             {
  89.                 sync('topic', $row['topic_id']);
  90.             }
  91.             break;
  92.  
  93.           case 'forum':
  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)) )
  98.             {
  99.                 message_die(GENERAL_ERROR, 'Could not get post ID', '', __LINE__, __FILE__, $sql);
  100.             }
  101.  
  102.             if ( $row = $db->sql_fetchrow($result) )
  103.             {
  104.                 $last_post = ( $row['last_post'] ) ? $row['last_post'] : 0;
  105.                 $total_posts = ($row['total']) ? $row['total'] : 0;
  106.             }
  107.             else
  108.             {
  109.                 $last_post = 0;
  110.                 $total_posts = 0;
  111.             }
  112.  
  113.             $sql = "SELECT COUNT(topic_id) AS total
  114.                 FROM " . TOPICS_TABLE . "
  115.                 WHERE forum_id = $id";
  116.             if ( !($result = $db->sql_query($sql)) )
  117.             {
  118.                 message_die(GENERAL_ERROR, 'Could not get topic count', '', __LINE__, __FILE__, $sql);
  119.             }
  120.  
  121.             $total_topics = ( $row = $db->sql_fetchrow($result) ) ? ( ( $row['total'] ) ? $row['total'] : 0 ) : 0;
  122.  
  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) )
  127.             {
  128.                 message_die(GENERAL_ERROR, 'Could not update forum', '', __LINE__, __FILE__, $sql);
  129.             }
  130.             break;
  131.  
  132.         case 'topic':
  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)) )
  137.             {
  138.                 message_die(GENERAL_ERROR, 'Could not get post ID', '', __LINE__, __FILE__, $sql);
  139.             }
  140.  
  141.             if ( $row = $db->sql_fetchrow($result) )
  142.             {
  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) )
  145.                 {
  146.                     message_die(GENERAL_ERROR, 'Could not update topic', '', __LINE__, __FILE__, $sql);
  147.                 }
  148.             }
  149.             break;
  150.     }
  151.     
  152.     return true;
  153. }
  154.  
  155. ?>