<?php

if ( ! @include_once( './mainfile.php' ) ) { exit( '!! INCLUDE ERROR. ACCESS DENIED !!' ); }
error_reporting( _E_VALUE );


/* vim: set expandtab tabstop=4 shiftwidth=4: */

// ***** BEGIN LICENSE BLOCK ( DO NOT REMOVE ) *****

// +----------------------------------------------------------------------+
// | MPN Article Topics                                                   |
// |                                                                      |
// | -> Displays most current articles in topics                          |
// +----------------------------------------------------------------------+
// | VERSION: 0.1 Alpha                                                   |
// +----------------------------------------------------------------------+
// | LICENSE: GPL 2.0 (see docs/LICENSE_GPL)                              |
// |                                                                      |
// | This file is part of myPHPNuke 188_8 ( MPN 188_8 ).                  |
// |                                                                      |
// | MPN 188_8 is free software; you can redistribute it and/or modify it |
// | under the terms of the GNU General Public License as published by    |
// | the Free Software Foundation; either version 2 of the License, or    |
// | (at your option) any later version.                                  |
// |                                                                      |
// | MPN 188_8 is distributed in the hope that it will be useful,         |
// | but WITHOUT ANY WARRANTY; without even the implied                   |
// | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     |
// | See the GNU General Public License for more details.                 |
// |                                                                      |
// | You should have received a copy of the GNU General Public License    |
// | along with MPN 188_8; if not, write to the                           |
// |                                                                      |
// | Free Software Foundation, Inc.                                       |
// | 59 Temple Place, Suite 330                                           |
// | Boston, MA 02111-1307  USA                                           |
// +----------------------------------------------------------------------+
// | AUTHOR(s):                                                           |
// |                                                                      |
// | The Original Code is the phpbb 1.4.4 Forum For MPN 188_8.            |
// | The Initial Developers of the Original Code are                      |
// | Eric Haddix and Arjan van Waay.                                      |
// |                                                                      |
// | Portions created by Eric Haddix or Kiril Threndor                    |
// | <support@mpn.illearth.net> are                                       |
// | Copyright (C) 2003 Eric Haddix.  All Rights Reserved.                |
// |                                                                      |
// | Portions created by Arjan van Waay or avw                            |
// | <arjan@vanwaay.net> are                                              |
// | Copyright (C) 2004 Arjan van Waay.  All Rights Reserved.             |
// +----------------------------------------------------------------------+
// | HISTORICAL AUTHORS & COPYRIGHTS:                                     |
// |                                                                      |
// | Portions created by Paul Baldowski <hutdik76@hotmail.com> are        |
// | Copyright (C) 2002 Paul Baldowsk.  All Rights Reserved.              |
// |                                                                      |
// | Portions created by Nathan Codding, Hombergs, or Francisco Burzi     |
// | are Copyright (C) 2001 Francisco Burzi.  All Rights Reserved.        |
// +----------------------------------------------------------------------+
// | CONTRIBUTOR(s):                                                      |
// |                                                                      |
// |                                                                      |
// +----------------------------------------------------------------------+
// | MODIFICATIONS:                                                       |
// |                                                                      |
// |                                                                      |
// +----------------------------------------------------------------------+
// | SUPPORT:                                                             |
// |   WEB:   http://myphpnuke.com/                                       |
// |   EMAIL: support@mpn.illearth.net                                    |
// +----------------------------------------------------------------------+

/**
 * MPN_188_8_Modules
 *
 * @package MPN_188_8_Modules
 * @subpackage topics
 * @version $Id: topics.php,v 1.4.2.8 2004/07/15 12:41:34 kirilt Exp $
 *
 * @author Kiril Threndor <support@mpn.illearth.net>
 * @copyright Copyright (C) 2004 Eric Haddix
 * @license http://www.gnu.org/licenses/gpl.html GPL 2.0
 * @support http://myphpnuke.com/
 *
 * @tutorial
 * @filesource
 */

// ***** END LICENSE BLOCK ( DO NOT REMOVE ) *****

define( '_MPN_PAGE_ID', 6 ); // Number Corresponds to position in style_list.txt, DO NOT QUOTE NUMBER

$sql = 'SELECT topicid, topicname, topicimage, topictext
        FROM ' . $mpnTables['topics'] . '
        ORDER BY topicname';

if ( ! @( $result = mysql_query( $sql ) ) && ! @mysql_data_seek( $result, 0 ) )
{
    goHome( translate( 'Sorry, No Topics Available' ) . '**' . __FILE__ . '***' .  __LINE__ );
    exit;
}

// Page Output

@( include_once 'header.php' )
  or goBack( translate( 'Failed To Include Required File' ) . '**' . __FILE__ . '***' .  __LINE__ );

echo '<div id="topics">' . "\n";

    echo '<h1>' . translate( 'Current Active Topics' ) . '</h1>' . "\n";
    echo '<h2>' . translate( 'Click on topic image to list all articles' ) . '</h2>' . "\n";
    echo '<hr class="w80" /><br />' . "\n";

    echo '<table summary="' . translate( 'News Topics' ) . '">' . "\n";

    while ( list( $topicid, $topicname, $topicimage, $topictext ) = mysql_fetch_row( $result ) )
    {
        $sql = 'SELECT sid, title, time
                FROM ' . $mpnTables['stories'] . '
                WHERE topic = ' . $topicid . '
                ORDER BY time DESC
                LIMIT 5';

        if ( ! @( $result2 = mysql_query( $sql ) ) || @mysql_data_seek( $result2, 0 ) == (bool)FALSE ) { continue; }

        echo '<tr><td><br />' . "\n";

            echo '<img class="bullet1" src="' . _IMG_AURI_23_ . 'triright.gif" alt="' . translate( 'Heading bullet' ) . '" />' . "&nbsp;\n";
            echo '<a href="' . _MPN_ROOT_URI . 'search.php?query=&amp;topic=' . $topicid . '">' . $topictext . '</a>' . "\n";
            echo '<br /><br />';

            echo '<div class="indent15">' . "\n";

            for ( $x = 0; $x< sizeof( $result2 ); $x++ )
            {
                $myrow = @mysql_fetch_assoc( $result2 );

                $sid = $myrow['sid'];
                $news = $_SERVER['F_LIB'] -> truncateString( $myrow['title'], 50 );

                // REF: getDisplayTime( $time, $strfmt = 'datestring4', $adj = TRUE )

                $when = getDisplayTime( $myrow['time'], 'linksdatestring' );

                if ( $news != '' )
                {
                    echo '<img class="bullet2" src="' . _IMG_AURI_23_ . 'bullet_01.gif" alt="' . translate( 'Bullet point' ) . '" />' . "\n";
                    echo $when . ' - <a href="' . _MPN_ROOT_URI . 'article.php?sid=' . $sid . '">' . $news . '</a>';
                }

                echo '<br />' . "\n";
            }

            echo '</div><br />' . "\n";

            echo '</td><td>' . "\n";

                echo '<a href="' . _MPN_ROOT_URI . 'search.php?query=&amp;topic=' . $topicid . '">';
                    echo '<img class="topicimg" src="' . _IMG_AURI_22_ . $topicimage . '" alt="' . $news . '" />';
                echo '</a>' . "\n";

            echo '</td>' . "\n";

        echo '</tr>' . "\n";
    }

    echo '</table>' . "\n";

echo '</div>' . "\n";

@mysql_free_result( $result );

@( include_once 'footer.php' )
  or goBack( translate( 'Failed To Include Required File' ) . '**' . __FILE__ . '***' .  __LINE__ );

?>