<?php
/**
 * Fireboard Latest Posts module
 * written by David Geens
 * mail : sniper_david at hotmail dot com
 * 
 * GNU/GPL, see LICENSE.php
 * mod_fb_latestposts is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 */
class modLatestPosts
{
    
    function getLatestPosts( $params )
    { 

      // Load module parameters
         $postings = $params->get( 'postNr' );
         $language = $params->get( 'language' );
         $layout = $params->get('layout', 'hor');
         $UserLink = $params->get('UserProfil');

       // Language file         

       $fireboard_adm_path = JPATH_ADMINISTRATOR.'/components/com_fireboard';
       $fireboard_language_file= $fireboard_adm_path.'/language/'.$language.'';

       // search for language file

       if (file_exists($fireboard_language_file))
       {
        require_once($fireboard_language_file);
       } 
      else
       {
        $fire_language_file= "$fireboard_adm_path/language/english.php";  
        if (file_exists($fireboard_language_file))
        require_once($fireboard_language_file);
       }
 
        //get database
	$database =& JFactory::getDBO();

        // Get menu item ID of the forum
        
        $database -> setQuery( "SELECT id FROM #__menu WHERE link LIKE '%com_fireboard%'"  );
        $ItemIDrows = $database->loadObjectList();
        $ItemIDforum = $ItemIDrows[0]->id;

        // Get latest post from the DBase

	$query = ' SELECT id, catid,name, userid, subject, time, topic_emoticon FROM #__fb_messages ORDER BY time DESC LIMIT '.$postings.'';
        $database -> setQuery( $query );
        $rows = $database -> loadObjectList();
      
        // Topic Emoticons

        $topic_emoticons[0] = 'default.gif';
        $topic_emoticons[1] = 'exclam.gif';
        $topic_emoticons[2] = 'question.gif';
        $topic_emoticons[3] = 'arrow.gif';
        $topic_emoticons[4] = 'love.gif';
        $topic_emoticons[5] = 'grin.gif';
        $topic_emoticons[6] = 'shock.gif';
        $topic_emoticons[7] = 'smile.gif';

        // Link to User Profil yes or no
    /*   
       if ($UserLink == 1) {
          $link = '<a href="'.JURI::base().'index.php?option=com_fireboard&itemid='.$ItemIDforum.'&func=fbprofile&task=showprf&userid='.$item->userid.'">'.$item->name.'</a>';
       }      
*/
       // Template

       require(JModuleHelper::getLayoutPath('mod_fb_latestposts', $layout));



/*
        echo '<table cellspacing="0" cellpadding="0" width="100%">';
           if ($row = $rows) {
             foreach ($row as $item) {
        echo '<tr> ';
        echo '<td><img src="'.JURI::base().'components/com_fireboard/template/default/images/english/emoticons/'.$topic_emoticons[$item->topic_emoticon].'"></td>';
        echo '<td><a href="index.php?option=com_fireboard&itemid='.$ItemIDforum.'&func=view&id='.$item->id.'&catid='.$item->catid.'">'.$item->subject.'</a></td>';
        echo ' <td>'.date(_DATETIME,$item->time).' '.JText::_('_GEN_BY').' <a href="'.JURI::base().'index.php?option=com_fireboard&itemid='.$ItemIDforum.'&func=fbprofile&task=showprf&userid='.$item->userid.'">'.$item->name.'</a></td>';
        echo ' </tr>';           
             }
           }
        echo '</table>'; */
    }
}
