home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 April / PCWorld_2005-04_cd.bin / akce / web / unitednuke / unitednuke.exe / html / includes / functions_admin.php < prev    next >
Encoding:
PHP Script  |  2004-01-10  |  8.9 KB  |  192 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. * phpbb2 forums port version 2.0.5 (c) 2003 - Nuke Cops (http://nukecops.com)
  15. *
  16. * Ported by Nuke Cops to phpbb2 standalone 2.0.5 Test
  17. * and debugging completed by the Elite Nukers and site members.
  18. *
  19. * You run this package at your sole risk. Nuke Cops and affiliates cannot
  20. * be held liable if anything goes wrong. You are advised to test this
  21. * package on a development system. Backup everything before implementing
  22. * in a production environment. If something goes wrong, you can always
  23. * backout and restore your backups.
  24. *
  25. * Installing and running this also means you agree to the terms of the AUP
  26. * found at Nuke Cops.
  27. *
  28. * This is version 2.0.5 of the phpbb2 forum port for PHP-Nuke. Work is based
  29. * on Tom Nitzschner's forum port version 2.0.6. Tom's 2.0.6 port was based
  30. * on the phpbb2 standalone version 2.0.3. Our version 2.0.5 from Nuke Cops is
  31. * now reflecting phpbb2 standalone 2.0.5 that fixes some bugs and the
  32. * invalid_session error message.
  33. ***************************************************************************/
  34. /***************************************************************************
  35.  *   This file is part of the phpBB2 port to Nuke 6.0 (c) copyright 2002
  36.  *   by Tom Nitzschner (tom@toms-home.com)
  37.  *   http://bbtonuke.sourceforge.net (or http://www.toms-home.com)
  38.  *
  39.  *   As always, make a backup before messing with anything. All code
  40.  *   release by me is considered sample code only. It may be fully
  41.  *   functual, but you use it at your own risk, if you break it,
  42.  *   you get to fix it too. No waranty is given or implied.
  43.  *
  44.  *   Please post all questions/request about this port on http://bbtonuke.sourceforge.net first,
  45.  *   then on my site. All original header code and copyright messages will be maintained
  46.  *   to give credit where credit is due. If you modify this, the only requirement is
  47.  *   that you also maintain all original copyright messages. All my work is released
  48.  *   under the GNU GENERAL PUBLIC LICENSE. Please see the README for more information.
  49.  *
  50.  ***************************************************************************/
  51. /***************************************************************************
  52.  *
  53.  *   This program is free software; you can redistribute it and/or modify
  54.  *   it under the terms of the GNU General Public License as published by
  55.  *   the Free Software Foundation; either version 2 of the License, or
  56.  *   (at your option) any later version.
  57.  *
  58.  *
  59.  ***************************************************************************/
  60.  
  61. //
  62. // Simple version of jumpbox, just lists authed forums
  63. //
  64. function make_forum_select($box_name, $ignore_forum = false, $select_forum = '')
  65. {
  66.         global $db, $userdata;
  67.  
  68.         $is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata);
  69.  
  70.         $sql = "SELECT forum_id, forum_name
  71.                 FROM " . FORUMS_TABLE . "
  72.                 ORDER BY cat_id, forum_order";
  73.         if ( !($result = $db->sql_query($sql)) )
  74.         {
  75.                 message_die(GENERAL_ERROR, 'Couldn not obtain forums information', '', __LINE__, __FILE__, $sql);
  76.         }
  77.  
  78.         $forum_list = '';
  79.         while( $row = $db->sql_fetchrow($result) )
  80.         {
  81.                 if ( $is_auth_ary[$row['forum_id']]['auth_read'] && $ignore_forum != $row['forum_id'] )
  82.                 {
  83.                         $selected = ( $select_forum == $row['forum_id'] ) ? ' selected="selected"' : '';
  84.                         $forum_list .= '<option value="' . $row['forum_id'] . '"' . $selected .'>' . $row['forum_name'] . '</option>';
  85.                 }
  86.         }
  87.  
  88.         $forum_list = ( $forum_list == '' ) ? '<option value="-1">-- ! No Forums ! --</option>' : '<select name="' . $box_name . '">' . $forum_list . '</select>';
  89.  
  90.         return $forum_list;
  91. }
  92.  
  93. //
  94. // Synchronise functions for forums/topics
  95. //
  96. function sync($type, $id = false)
  97. {
  98.         global $db;
  99.  
  100.         switch($type)
  101.         {
  102.                 case 'all forums':
  103.                         $sql = "SELECT forum_id
  104.                                 FROM " . FORUMS_TABLE;
  105.                         if ( !($result = $db->sql_query($sql)) )
  106.                         {
  107.                                 message_die(GENERAL_ERROR, 'Could not get forum IDs', '', __LINE__, __FILE__, $sql);
  108.                         }
  109.  
  110.                         while( $row = $db->sql_fetchrow($result) )
  111.                         {
  112.                                 sync('forum', $row['forum_id']);
  113.                         }
  114.                            break;
  115.  
  116.                 case 'all topics':
  117.                         $sql = "SELECT topic_id
  118.                                 FROM " . TOPICS_TABLE;
  119.                         if ( !($result = $db->sql_query($sql)) )
  120.                         {
  121.                                 message_die(GENERAL_ERROR, 'Could not get topic ID', '', __LINE__, __FILE__, $sql);
  122.                         }
  123.  
  124.                         while( $row = $db->sql_fetchrow($result) )
  125.                         {
  126.                                 sync('topic', $row['topic_id']);
  127.                         }
  128.                         break;
  129.  
  130.                   case 'forum':
  131.                         $sql = "SELECT MAX(post_id) AS last_post, COUNT(post_id) AS total
  132.                                 FROM " . POSTS_TABLE . "
  133.                                 WHERE forum_id = $id";
  134.                         if ( !($result = $db->sql_query($sql)) )
  135.                         {
  136.                                 message_die(GENERAL_ERROR, 'Could not get post ID', '', __LINE__, __FILE__, $sql);
  137.                         }
  138.  
  139.                         if ( $row = $db->sql_fetchrow($result) )
  140.                         {
  141.                                 $last_post = ( $row['last_post'] ) ? $row['last_post'] : 0;
  142.                                 $total_posts = ($row['total']) ? $row['total'] : 0;
  143.                         }
  144.                         else
  145.                         {
  146.                                 $last_post = 0;
  147.                                 $total_posts = 0;
  148.                         }
  149.  
  150.                         $sql = "SELECT COUNT(topic_id) AS total
  151.                                 FROM " . TOPICS_TABLE . "
  152.                                 WHERE forum_id = $id";
  153.                         if ( !($result = $db->sql_query($sql)) )
  154.                         {
  155.                                 message_die(GENERAL_ERROR, 'Could not get topic count', '', __LINE__, __FILE__, $sql);
  156.                         }
  157.  
  158.                         $total_topics = ( $row = $db->sql_fetchrow($result) ) ? ( ( $row['total'] ) ? $row['total'] : 0 ) : 0;
  159.  
  160.                         $sql = "UPDATE " . FORUMS_TABLE . "
  161.                                 SET forum_last_post_id = $last_post, forum_posts = $total_posts, forum_topics = $total_topics
  162.                                 WHERE forum_id = $id";
  163.                         if ( !$db->sql_query($sql) )
  164.                         {
  165.                                 message_die(GENERAL_ERROR, 'Could not update forum', '', __LINE__, __FILE__, $sql);
  166.                         }
  167.                         break;
  168.  
  169.                 case 'topic':
  170.                         $sql = "SELECT MAX(post_id) AS last_post, MIN(post_id) AS first_post, COUNT(post_id) AS total_posts
  171.                                 FROM " . POSTS_TABLE . "
  172.                                 WHERE topic_id = $id";
  173.                         if ( !($result = $db->sql_query($sql)) )
  174.                         {
  175.                                 message_die(GENERAL_ERROR, 'Could not get post ID', '', __LINE__, __FILE__, $sql);
  176.                         }
  177.  
  178.                         if ( $row = $db->sql_fetchrow($result) )
  179.                         {
  180.                                 $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";
  181.                                 if ( !$db->sql_query($sql) )
  182.                                 {
  183.                                         message_die(GENERAL_ERROR, 'Could not update topic', '', __LINE__, __FILE__, $sql);
  184.                                 }
  185.                         }
  186.                         break;
  187.         }
  188.  
  189.         return true;
  190. }
  191.  
  192. ?>