<?php
//
// Copyright (C) 2003 Jan de Graaff
// All rights reserved.
//
// This program uses parts of the original Simpleboard Application
// 0.7.0b written by Josh Levine; http://www.joshlevine.net
//
// This source file is part of the SimpleBoard Component, a Mambo 4.5
// custom Component By Jan de Graaff - http://tsmf.jigsnet.com
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// Please note that the GPL states that any headers in files and
// Copyright notices as well as credits in headers, source files
// and output (screens, prints, etc.) can not be removed.
// You can extend them with your own credits, though...
//
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
// The "GNU General Public License" (GPL) is available at
// http://www.gnu.org/copyleft/gpl.html.
//
// Dont allow direct linking
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
// topic emoticons

$topic_emoticons=array();
$topic_emoticons[0]=$sbs.'/emoticons/default.gif';
$topic_emoticons[1]=$sbs.'/emoticons/exclam.gif';
$topic_emoticons[2]=$sbs.'/emoticons/question.gif';
$topic_emoticons[3]=$sbs.'/emoticons/arrow.gif';
$topic_emoticons[4]=$sbs.'/emoticons/love.gif';
$topic_emoticons[5]=$sbs.'/emoticons/grin.gif';
$topic_emoticons[6]=$sbs.'/emoticons/shock.gif';
$topic_emoticons[7]=$sbs.'/emoticons/smile.gif';
$tabclass = array("sectiontableentry1", "sectiontableentry2");
if (count($messages[0]) > 0) {
?>
         <table width="100%" border="0" cellpadding="0" width="100%" class="sb_contentpane">
            <tr>
               <?php if ($sbConfig['showNew'] && $my->id !=0){echo '<td class="sectiontableheader" width="10">&nbsp;</td>';}?>
               <!--<td class="sectiontableheader" width="5" align="center">&nbsp;</td>
               <td class="sectiontableheader" width="5" align="center">&nbsp;</td>-->
               <?php if ( $my_id == 0 ) { echo '<td class="sectiontableheader" width="5" align="center">&nbsp;</td>';} ?>
               <td class="sectiontableheader" align="center"><strong><?php echo _GEN_TOPIC;?></strong></td>
               <td class="sectiontableheader" align="center"  width="20"><strong><?php echo _GEN_REPLIES;?></strong></td>
               <td class="sectiontableheader" align="center"  width="20"><strong><?php echo _GEN_HITS;?></strong></td>
               <td class="sectiontableheader" width="15%" align="center"><strong><?php echo _GEN_AUTHOR;?></strong></td>
               <td class="sectiontableheader" width="110" align="center"><strong><?php echo _GEN_LAST_POST;?></strong></td>
            </tr>
            <?php $k=0;
            foreach($messages[0] as $leaf){
                $k=1-$k; //used for alternating colours
				//$leaf->subject = htmlspecialchars($leaf->subject);
				$leaf->name    = htmlspecialchars($leaf->name   );
				$leaf->email   = htmlspecialchars($leaf->email  );
             ?>
            <tr class="<?php echo $tabclass[$k];?>">
            <?php
            if ($sbConfig['showNew'] && $my->id !=0 && ! $leaf->moved){
               if (($prevCheck<$last_reply[$leaf->id]->time) && !in_array($last_reply[$leaf->id]->thread, $read_topics)){
                  //new post(s) in topic
                  echo '<td width="1%" class="sb_new">';
                  echo $sbIcons['unreadmessage'] ? '<img src="'.$mls.'/modules/mod_sbicons/'.$sbIcons['unreadmessage'].'" border="0" alt="'._GEN_UNREAD.'" title="'._GEN_UNREAD.'"/>' : $sbConfig['newChar'];
                  echo '</td>';
               }
               else{
                  //no new posts in topic
                  echo '<td width="1%" class="sb_notnew">';
                  echo $sbIcons['readmessage'] ? '<img src="'.$mls.'/modules/mod_sbicons/'.$sbIcons['readmessage'].'" border="0" alt="'._GEN_NOUNREAD.'" title="'._GEN_NOUNREAD.'"/>' : $sbConfig['newChar'];
                  echo '</td>';
               }
            } else {
					echo '<td>&nbsp;</td>';
				}?>
               <!--<td align="center"  width="5">
                  <?php
                  if ($leaf->ordering==0) {
                     if($leaf->locked==0) {
                       echo "&nbsp;";
                     }
                     else{
                        echo $sbIcons['topiclocked'] ? '<img src="'.$mls.'/modules/mod_sbicons/'.$sbIcons['topiclocked'].'" border="0" alt="'._GEN_LOCKED_TOPIC.'" />' : '<img src="'.$sbs.'/emoticons/lock.gif" width="15" height="15" alt="'._GEN_LOCKED_TOPIC.'" title="'._GEN_LOCKED_TOPIC.'" />';
                        $topicLocked=1;
                     }
                  }
                  else {
                     echo $sbIcons['topicsticky'] ? '<img src="'.$mls.'/modules/mod_sbicons/'.$sbIcons['topicsticky'].'" border="0" alt="'._GEN_ISSTICKY.'" />' : '<img src="'.$sbs.'/emoticons/pushpin.gif" width="15" height="15" alt="'._GEN_ISSTICKY.'" title="'._GEN_ISSTICKY.'" />';
                     $topicSticky=1;
                  }
                  ?>
               </td>-->
					<?php
					if ($leaf->moved ==0) {
						?>
		               	<!--<td align="center" width="5"><a href="#<?php echo $id;?>"></a><?php echo $leaf->topic_emoticon==0?"<img src=\"$sbs/tree-blank.gif\" width=\"15\" height=\"15\" alt=\"\" />":"<img src=\"".$topic_emoticons[$leaf->topic_emoticon]."\" alt=\"emo\" />";?></td> -->
        		        <td><a href="<?php echo sefRelToAbs('index.php?option=com_simpleboard&amp;Itemid='.$Itemid.'&amp;func=view&amp;id='.$leaf->id.$viewstr.'&amp;catid='.$catid);?>"><?php echo stripslashes($leaf->subject);?></a>
						<?php
					} else {
						//this thread has been moved, get the new location
						$newURL=""; //init
						$database->setQuery("SELECT `message` FROM #__sb_messages_text WHERE `mesid`='".$leaf->id."'");
						$newURL=$database->loadResult();
						?>
               	<td align="center" width="5"><a href="#<?php echo $id;?>"></a><img src="<?php echo $sbs;?>/emoticons/arrow.gif" width="19" height="19" alt="emo" /></td>
                <td><a href="<?php echo sefRelToAbs('index.php?option=com_simpleboard&amp;Itemid='.$Itemid.'&amp;func=view&amp;'.$newURL);?>"><?php echo stripslashes($leaf->subject);?></a>
						<?php
					}
              			
               		$totalMessages=$thread_counts[$leaf->id];
               		if ($totalMessages > $sbConfig['messages_per_page'])
               		{
               			$threadPages= ceil($totalMessages/ $sbConfig['messages_per_page']);
               			echo ("<br />[");
               			echo _PAGE;
               			echo '<a href="'.sefRelToAbs('index.php?option=com_simpleboard&amp;Itemid='.$Itemid.'&amp;func=view&amp;id='.$leaf->id.$viewstr.'&amp;catid='.$catid).'">1</a>';
               			if ($threadPages>3)
               			{
               				echo ("...");
               				$startPage=$threadPages-2;
               			}
               			else
               			{
               				echo (",");
               				$startPage=2;
               			}
               			$noComma=true;
               			for ($hopPage=$startPage; $hopPage<=$threadPages; $hopPage++)
               			{
               				if ($noComma) $noComma=false; else echo(",");
               				echo '<a href="' . sefRelToAbs('index.php?option=com_simpleboard&amp;Itemid='.$Itemid.'&amp;func=view&amp;id='.$leaf->id.'&amp;catid='.$catid.'&amp;limit='.$sbConfig['messages_per_page'].'&amp;limitstart='.(($hopPage-1)*$sbConfig['messages_per_page'])) . '">'.$hopPage.'</a>';
               			}
               			echo ("]");
               		}
               ?>
               </td>
               <td align="center"><?php echo $leaf->moved ? "" :(int)$thread_counts[$leaf->id];?></td>
               <td align="center"><?php echo $leaf->moved ? "" :(int)$hits[$leaf->id];?></td>
               <td><small><?php echo $leaf->email!=""&&$my_id>0&&$sbConfig['showemail']=='1'?"<a href=\"mailto:".stripslashes($leaf->email)."\">".stripslashes($leaf->name)."</a>":stripslashes($leaf->name);?><small></td>
               <td>
                  <table border="0" cellspacing="0" cellpadding="0" width="110">
                     <tr bgcolor="<?php echo $bgcolor;?>">
                        <td colspan="2">
                        	
                        <small>
                        	<?php echo $leaf->moved ? "" :date(_DATETIME , $last_reply[$leaf->id]->time);?>
                        <a href="<?php echo sefRelToAbs('index.php?option=com_simpleboard&amp;Itemid='.$Itemid.'&amp;func=view&amp;catid='.$catid.'&amp;id='.$last_reply[$leaf->id]->id).'#'.$last_reply[$leaf->id]->id;?>">
                        <?php 
								if ( ! $leaf->moved ) {
									echo $sbIcons['latestpost'] ? '<img src="'.$mls.'/modules/mod_sbicons/'.$sbIcons['latestpost'].'" border="0" alt="'._SHOW_LAST.'" />' : '  <img src="'.$sbs.'/emoticons/icon_newest_reply.gif" border="0"  width="18" height="9" alt="'._SHOW_LAST.'" title="'._SHOW_LAST.'" />';
									}
									?>
                        </a>
                        	<br />
                        	<?php echo $leaf->moved ? "" :_GEN_BY.' '.stripslashes($last_reply[$leaf->id]->name);?>
                        </small>
                        </td>
                     </tr>
                  </table>
               </td>
            </tr>
            <?php } ?>
         </table>
<?php
}
else{
   echo "<p align=\"center\">"._VIEW_NO_POSTS."</p>";
}
?>
