<?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 ) *****

// +----------------------------------------------------------------------+
// | phpBB 1.4.x Forum For MPN 188_8                                      |
// |                                                                      |
// | -> Posts Since Your Last Visit                                       |
// +----------------------------------------------------------------------+
// | VERSION: 0.1 Alpha                                                   |
// +----------------------------------------------------------------------+
// | LICENSE: GPL 2.0 (see docs/LICENSE_GPL)                              |
// |                                                                      |
// | This file is part of phpBB 1.4.x Forum For MPN 188_8.                |
// |                                                                      |
// | phpBB 1.4.x Forum For 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.                                                       |
// |                                                                      |
// | phpBB 1.4.x Forum For 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 phpBB 1.4.x Forum For 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 Developer of the Original Code is Eric Haddix.           |
// |                                                                      |
// | Portions created by Eric Haddix or Kiril Threndor                    |
// | <support@mpn.illearth.net> are                                       |
// | Copyright (C) 2003 Eric Haddix.  All Rights Reserved.                |
// +----------------------------------------------------------------------+
// | HISTORICAL AUTHORS & COPYRIGHTS:                                     |
// |                                                                      |
// | Portions created by Richard Tirtadji or King Richard                 |
// | <rtirtadji@hotmail.com> are                                          |
// | Copyright (C) 2001 Richard Tirtadji.  All Rights Reserved.           |
// |                                                                      |
// | Portions created by Hutdik Hermawan or hotFix                        |
// | <hutdik76@hotmail.com> are                                           |
// | Copyright (C) 2001 Hutdik Hermawan.  All Rights Reserved.            |
// |                                                                      |
// | Portions created by Nathan Codding, Hombergs, or Francisco Burzi     |
// | are Copyright (C) 2001 Francisco Burzi.  All Rights Reserved.        |
// |                                                                      |
// | Portions created by Philip Mayer                                     |
// | are Copyright (C) 2001 Philip Mayer.  All Rights Reserved.           |
// |                                                                      |
// | Portions created by Paul Baldowski                                   |
// | are Copyright (C) 2003 Paul Baldowski.  All Rights Reserved.         |
// +----------------------------------------------------------------------+
// | CONTRIBUTOR(s):                                                      |
// |                                                                      |
// |                                                                      |
// +----------------------------------------------------------------------+
// | MODIFICATIONS:                                                       |
// |                                                                      |
// |                                                                      |
// +----------------------------------------------------------------------+
// | REQUIRED FILES: functions.php                                        |
// |                                                                      |
// +----------------------------------------------------------------------+
// | NOTES:                                                               |
// |   The MPN 188_8 forum is nearly a complete, and in some cases entire,|
// |   recode of the phpNuke 4.4 forum which was based on phpBB 1.4.x.    |
// +----------------------------------------------------------------------+
// | SUPPORT:                                                             |
// |   WEB:   http://myphpnuke.com/                                       |
// |   EMAIL: support@mpn.illearth.net                                    |
// +----------------------------------------------------------------------+

/**
 * MPN_188_8_Modules
 *
 * @package MPN_188_8_Modules
 * @subpackage forum
 * @version $Id: lastview.php,v 1.6.2.7 2004/03/28 18:53:55 kirilt Exp $
 *
 * @author Kiril Threndor <support@mpn.illearth.net>
 * @copyright Mixed
 * @license http://www.gnu.org/licenses/gpl.html GPL 2.0
 * @support http://myphpnuke.com/
 * @todo finish CSS & XHTML conversion
 * @todo reformat old style formatted code to new coding style
 * @todo finish recode
 *
 * @tutorial
 * @filesource
 */

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

@( include_once __ROOT__ . 'core_ForumEntry.php' )
  OR goBack( translate( 'Include Error' ) );

// Select order specified ??

if (!isset($selorder)) $selorder = "las24";
if (!isset($nodays)) $nodays = 3;

// String and language Stuff, adjust if you like:

 $las24_msg = "".translate("Last 24 hours")."";
 $today_msg = "".translate("Today")."";
 $yestr_msg = "".translate("Yesterday")."";
 $lweek_msg = "".translate("Last week")."";
 $laday_msg = "".translate("Last")." $nodays ".translate("days")."";

 $show      = "".translate("Show posts:")."";
 $showing   = "".translate("Currently showing")."";

 $last      = "".translate("Last")."";
 $days      = "".translate("Days")."";

 $posticon = "images/forum/icons/posticon.gif";

/* Select orders are:

 las24   Last 24 Hours
 today   Today
 yestr   Yesterday
 lweek   Last week
 laday   Last days, number specified in $nodays

*/

// SQLs:

$part1 = "SELECT t.topic_id as id FROM ".$mpnTables['forums']." f, ".$mpnTables['forumtopics']." t WHERE f.forum_id = t.forum_id AND f.forum_type != 1 AND ";
$part2 = " ORDER BY t.topic_time DESC";

$lastweeksql  = $part1."TO_DAYS(NOW()) - TO_DAYS(t.topic_time) < 8".$part2;
$yesterdaysql = $part1."TO_DAYS(NOW()) - TO_DAYS(t.topic_time) = 1".$part2;
$todaysql     = $part1."TO_DAYS(NOW()) - TO_DAYS(t.topic_time) = 0".$part2;

$last24hsql   = $part1."t.topic_time > DATE_SUB(NOW(), INTERVAL 1 DAY)".$part2;
$lastXdsql    = $part1."t.topic_time > DATE_SUB(NOW(), INTERVAL $nodays DAY)".$part2;

switch ($selorder) {

 case "las24" : $sql = $last24hsql; $msg = $las24_msg; break;
 case "today" : $sql = $todaysql; $msg = $today_msg; break;
 case "yestr" : $sql = $yesterdaysql; $msg = $yestr_msg; break;
 case "lweek" : $sql = $lastweeksql; $msg = $lweek_msg; break;
 case "laday" : $sql = $lastXdsql; $msg = $laday_msg; break;

}

  if(!$r = mysql_query($sql)) echo "".translate("Error...")."";

  // all data ready for displaying...


@( include_once __ROOT__ . 'header.php' )
  OR goBack( translate( 'Include Error' ) );

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

echo '<h1>' . translate( 'Listing Posts For' ) . ' <i>' . $msg . '</i></h1><br />' . "\n";

echo '<form name="form1" method="get" action="">' . "\n";

    echo '<p align="center" /><span class="label">' . "\n";
    echo $show;
    ?>
    [ <a href="<?php echo $_SERVER['PHP_SELF']; ?>?selorder=lweek">
    <?php echo $lweek_msg; ?>
    </a> ] [ <a href="<?php echo $_SERVER['PHP_SELF']; ?>?selorder=yestr">
    <?php echo $yestr_msg; ?>
    </a> ] [ <a href="<?php echo $_SERVER['PHP_SELF']; ?>?selorder=las24">
    <?php echo $las24_msg; ?>
    </a> ] [ <a href="<?php echo $_SERVER['PHP_SELF']; ?>?selorder=today">
    <?php echo $today_msg; ?>
    </a> ] [
    <?php echo $last; ?>
    <input type="text" name="nodays" size="2" value="<?php echo $nodays; ?>" maxlength="3">
    <input type="hidden" name="selorder" value="laday">
    <a href="javascript:document.form1.submit();">
    <?php echo $days; ?>
    </a> ] <br />
    </span>
<?php
echo '</form>' . "\n";

echo '<hr class="w80" /><br />' . "\n";

$rowcount = mysql_num_rows( $r );

if ( $rowcount == 0 )
{
    echo "<h1>" . translate( 'No New Topics Found Since Your Last Visit' ) . "</h1><br /><br />\n";

    echo getFooterNav();

    @( include_once __ROOT__ . 'footer.php' )
      OR goBack( translate( 'Include Error' ) );
    exit;
}

?>

<TABLE BORDER="0" CELLPADDING="1" CELLSPACING="1" WIDTH="100%">
<TR BGCOLOR="<?php echo $bgcolor2?>" ALIGN="LEFT">
       <TD ALIGN="CENTER" WIDTH="50%"><span class="content" style="font-size: 110%; line-height: 200%; font-weight: bold"><?php echo translate("Topic");?></span></TD>
        <TD ALIGN="CENTER" WIDTH="15%"><span class="content" style="font-size: 110%; line-height: 200%; font-weight: bold"><?php echo translate("Forum");?></span></TD>
        <TD ALIGN="CENTER" WIDTH="15%"><span class="content" style="font-size: 110%; line-height: 200%; font-weight: bold"><?php echo translate("Author");?></span></TD>
        <TD ALIGN="CENTER" WIDTH="20%"><span class="content" style="font-size: 110%; line-height: 200%; font-weight: bold"><?php echo translate("Posted");?></span></TD>
</TR>
   <?php

    while($g = mysql_fetch_array($r))
    {
        $sql = "SELECT p.post_time, f.forum_id, f.forum_name, t.topic_id, t.topic_title, count(p.post_id) AS total, u.uid, u.uname
                FROM ".$mpnTables['posts']." p, ".$mpnTables['users']." u, ".$mpnTables['forums']." f, ".$mpnTables['forumtopics']." t
                WHERE p.topic_id = " . $g['id'] . " AND f.forum_id = t.forum_id AND p.poster_id = u.uid AND f.forum_type != 1 AND p.topic_id = t.topic_id
                GROUP BY topic_id
                ORDER BY post_time DESC
                LIMIT 1";

        $r00 = mysql_query($sql);

        if ( (bool)FALSE == ( $m = mysql_fetch_array( $r00 ) ) )
        {
            continue;
        }
       ?>

           <TR BGCOLOR="<?php echo $bgcolor1; ?>">
        <TD ALIGN="LEFT" WIDTH="50%" BGCOLOR="<?php echo $bgcolor1; ?>"><span class="content" style="line-height: 160%; margin-left: 5px"><a href="<?php echo "viewtopic.php?topic=" . $m['topic_id'] . "&forum=" . $m['forum_id']; ?>"><?php echo stripslashes($m['topic_title']); ?></a></span>
        <?php
   if($m['total'] > $forumconfig['posts_per_page'])
   {
     echo "&nbsp;&nbsp;&nbsp;<span class=\"tiny\">(<img src=\"$posticon\" width=12 height=12> ";
     $times = 1;
     for($x = 0; $x < $m['total']; $x += $forumconfig['posts_per_page']) {
        if($times > 4) {
           if(($x + $forumconfig['posts_per_page']) >= $m['total']) {
          echo " ... <a href=\"viewtopic.php?topic=" . $m['topic_id'] . "&forum=" . $m['forum_id'] . "&start=$x\">$times</a>";
           }
        }
        else {
           if($times != 1)
         echo ", ";
           echo "<a href=\"viewtopic.php?topic=" . $m['topic_id'] . "&forum=" . $m['forum_id'] . "&start=$x\">$times</a>";
        }
        $times++;
     }
     echo ")</span>";
      }

      $msg_time = getDisplayTime( $m['post_time'], 'forumdatestring2' );

      ?>
        </TD>
        <TD ALIGN="CENTER" WIDTH="15%"><span class="content" style="line-height: 160%"><a href="<?php echo "viewforum.php?forum=" . $m['forum_id']; ?>"><?php echo stripslashes($m['forum_name']); ?></a></span></TD>
       <TD ALIGN="CENTER" WIDTH="15%"><span class="content" style="line-height: 160%"><a href="<?php echo "user.php?op=userinfo&uname=" . $m['uname']; ?>"><?php echo $m['uname']; ?></a></span></TD>
        <TD ALIGN="CENTER" WIDTH="20%"><span class="content" style="line-height: 160%"><?php echo $msg_time; ?></span></TD>
        </TR>

<?php

    }

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

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

echo getFooterNav();

@( include_once __ROOT__ . 'footer.php' )
  OR goBack( translate( 'Include Error' ) );


// ##### HISTORICAL NOTICES #####


// *************************************************************

// Script Title: The latest posts (for phpBB 1.x)
// by Philip Mayer
// Email: webmaster@phpbb.de

// Modified for mPN 1.8.8 by Paul Baldowski
// http://www.scifivine.com

// *************************************************************

// STYLE NOTE: Script uses 'content' and 'tiny' styles. Check your style.css for these.
// 'content' should be the size of standard article text, while 'tiny' should be 1px smaller.

// BACKGROUND NOTE: Script uses bgcolor1 and bgcolor2. You should check these won't clash or make text unreadable.
// If there are problems, alter the bgcolor values to a combination that works.

?>