<?php
/**
 * pragmaMx Integration
 * Copyright (C) 2007 by A.Ellsel (Tora) - http://pragmaMx.org
 * 
 * This file 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.
 * 
 * $Source: /home/www/dps3311/home/cvsroot/pragmamx4/SMF-port/html/blocks/block-smf_Center.php,v $
 * $Revision: 1.10 $
 * $Author: tora60 $
 * $Date: 2007/03/16 15:04:43 $
 */

if (!defined("mxMainFileLoaded")) die ("You can't access this file directly...");

/**
 * // //////////  EINSTELLUNGEN DES BLOCKS //////////////////////////////////// 
 */
// der Modulname (Ordner des Moduls)
$boardname = 'Forum';
// Anzahl der angezeigten neuesten Threads
$num_threads = 10;
// Boards die nicht angezeigt werden sollen, als Array
$exclude_boards = array(22,11,12,13,52,49,21,53,51,50,64,81);
// Thread-Icons in Liste anzeigen
$show_icons = 1;
// Anzahl, wie oft gelesen, in Liste anzeigen
$show_views = 1;
// Anzahl der Antworten in Liste anzeigen
$show_replies = 1;
// Name des Themenstarters in Liste anzeigen
$show_starter = 1;
// kleine Forumsstatistik anzeigen
$show_stats = 1;
// User-Onlinestatistik anzeigen
$show_online = 1;
// in Onlinestatistik die Buddies extra listen
$show_buddies = 1;
// Farben des Blocks
global $bgcolor1, $bgcolor2, $bgcolor3, $textcolor1, $textcolor2;
// Rahmen um die Liste
$color['border'] = "#BCBCBC";
// Hintergrund Überschriften
$color['row1'] = $bgcolor1;
// Hintergrund normaler Thread
$color['row2'] = $bgcolor3;
// Textfarbe Überschriften
$color['txtrow1'] = $textcolor1;
// Textfarbe normaler Thread
$color['txtrow2'] = $textcolor2;
/**
 * //////////  ENDE DER EINSTELLUNGEN ///////////////////////////////////////// 
 */

/**
 * versch. globale Variablen vorher initialisieren, weil in Funktionen aufgerufen 
 */
global $db_prefix, $settings, $context, $scripturl, $mxsmf;

/**
 * die SSI-Datei includen 
 */
@include(dirname(dirname(__FILE__)) . '/modules/' . $boardname . '/mx_SSI.php');
if (!defined('SMF')) {
    // falls Bridge nicht installiert, oder Datei nicht gefunden, hier beenden
    return $content = @$mx_ssi_content;
} 

/**
 * Boardstatistik 
 */
$boardstats = ssi_boardStats('array');
$boardstats = '
' . $txt[330] . ': ' . $boardstats['topics'] . ' |
' . $txt[95] . ': ' . $boardstats['posts'] . ' |
' . $txt[331] . ': <a href="modules.php?name=' . $boardname . '&amp;action=mlist" title="' . $txt['332'] . '">' . $boardstats['members'] . '</a>
';
// Anzahl der Spalten, abhaengig der Einstellungen
$colspan = intval($show_icons) + intval($show_views) + intval($show_replies) + intval($show_starter) + 2;
// Wer ist Online?
if ($show_online) {
    $whoonline = ssi_whosOnline('array');
    $whoonline_out = '' . $whoonline['guests'] . ' ' . (($whoonline['guests'] == 1) ? $txt['guest'] : $txt['guests']) . ', ' . $whoonline['num_users'] . ' ' . (($whoonline['num_users'] == 1) ? $txt['user'] : $txt['users']); 
    // Hidden users. or buddies?
    if ($whoonline['hidden'] > 0 || $show_buddies)
        $whoonline_out .= ' (' . ($show_buddies ? ($whoonline['buddies'] . ' ' . (($whoonline['buddies'] == 1) ? $txt['buddy'] : $txt['buddies'])) : '') . ($show_buddies && $whoonline['hidden'] ? ', ' : '') . (!$whoonline['hidden'] ? '' : $whoonline['hidden'] . ' ' . $txt['hidden']) . ')';
    if (count($whoonline['users'])) {
        $whoonline_list = '';
        foreach ($whoonline['users'] as $user)
        $whoonline_list .= (($user['hidden']) ? '<i>' . $user['link'] . '</i>' : $user['link']) . (($user['is_last']) ? '' : '. ');
    } 
} 
// die Threads und Posts
$posts = ssi_recentTopics(intval($num_threads), $exclude_boards, 'array');
if ($show_starter || $show_replies || $show_views) {
    // / alle Thread-ID's vorher auslesen, für Datenbankbedingung
    foreach ($posts as $post) {
        $topics[$post['topic']] = $post['topic'];
    } 
    if (isset($topics)) {
        // / zusätzliche Daten, die nicht von SSI bereitgestellt werden ermitteln
        $qry = "SELECT DISTINCT m.ID_MEMBER, m.posterName, t.numReplies, t.numViews, t.ID_TOPIC
				FROM {$db_prefix}topics AS t
				LEFT JOIN {$db_prefix}messages AS m ON ( m.ID_MSG = t.ID_FIRST_MSG )
				WHERE t.ID_TOPIC IN (" . implode(',', $topics) . ")
				LIMIT " . intval($num_threads) . "";
        $result = sql_query($qry); 
        // / die zusätzlichen Daten sind dann über den Index des Arrays ansprechbar, dieser index entspricht der Thread-ID
        while ($row = sql_fetch_assoc($result)) {
            $row['link'] = (empty($row['ID_MEMBER'])) ? $row['posterName'] : '<a href="modules.php?name=' . $boardname . '&amp;action=profile;u=' . $row['ID_MEMBER'] . '" title="' . $txt[92] . ' ' . $row['posterName'] . '">' . $row['posterName'] . '</a>';
            $posts_more[$row['ID_TOPIC']] = $row;
        } 
    } 
} 
// Der Tabellenkopf für die Threads und Posts
$content = '<table width="100%" border="0" cellspacing="1" cellpadding="2" style="background: ' . $color['border'] . ';">
<tr valign="top" style="background: ' . $color['row1'] . '; color: ' . $color['txtrow1'] . ';">';
$content .= '<th colspan="' . (($show_icons) ? 2 : 1) . '">' . $txt['319'] . '</th>'; # Thema
if ($show_starter)
    $content .= '<th>' . $txt['109'] . '</th>'; # Themenstarter
if ($show_replies)
    $content .= '<th>' . $txt['110'] . '</th>'; # Antworten
if ($show_views)
    $content .= '<th>' . $txt['301'] . '</th>'; # Aufrufe
$content .= '<th>' . $txt['111'] . '</th>'; # Letzter Beitrag
$content .= '
</tr>
';
// die Hauptliste der einzelnen Threads
foreach ($posts as $post) {
    $new = (!$post['new']) ? ' <a href="modules.php?name=' . $boardname . '&amp;topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt[302] . '" border="0" align="right"></a> ': '';
    $content .= '<tr style="background: ' . $color['row2'] . '; color: ' . $color['txtrow2'] . ';">';
    if ($show_icons)
        $content .= '<td width="1%" align="center" style="background: ' . $color['row1'] . ';">' . $post['icon'] . '</td>';
    $content .= '<td>' . $new . '<a href="' . str_replace(';topicseen', '', $post['href']) . '">' . $post['subject'] . '</a><br /><em>' . $txt['smf88'] . ' ' . $post['board']['link'] . '</em></td>';
    if ($show_starter)
        $content .= '<td width="1%" style="white-space: nowrap;">' . ((isset($posts_more[$post['topic']]['link'])) ? $posts_more[$post['topic']]['link'] : '') . '</td>';
    if ($show_replies)
        $content .= '<td width="1%" align="center">' . ((isset($posts_more[$post['topic']]['numReplies'])) ? $posts_more[$post['topic']]['numReplies'] : 0) . '</td>';
    if ($show_views)
        $content .= '<td width="1%" align="center">' . ((isset($posts_more[$post['topic']]['numViews'])) ? $posts_more[$post['topic']]['numViews'] : 0) . '</td>';
    $content .= '<td>' . $post['time'] . '<br />' . $txt[525] . ' ' . $post['poster']['link'] . '</td>';
    $content .= '</tr>';
} 
// Boardstatistik anzeigen
if ($show_stats)
    $content .= '
		<tr style="background: ' . $color['row1'] . '; color: ' . $color['txtrow1'] . ';">
		<td colspan="' . $colspan . '" align="center"><div class="content">' . $boardstats . '</div></td>
		</tr>';
// Wer ist Online anzeigen
if ($show_online)
    $content .= '
		<tr style="background: ' . $color['row2'] . '; color: ' . $color['txtrow2'] . ';">
		<td colspan="' . $colspan . '" align="center"><div class="content">' . $txt['who_title'] . ':&nbsp;&nbsp;' . $whoonline_out . '</div></td>
		</tr>';
// Wer ist Online anzeigen, die Liste der einzelnen User
if ($show_online && !empty($whoonline_list))
    $content .= '
		<tr style="background: ' . $color['row1'] . '; color: ' . $color['txtrow1'] . ';">
		<td colspan="' . $colspan . '"><div class="content">' . $whoonline_list . '</div></td>
		</tr>';
// Der Tabellenfuss für die Threads und Posts
$content .= '</table>';
// Den Output für pragmaMx aufbereiten (links usw. anpassen)
$content = mxSmfPrepareOutput($content);

?>