<?php
// we need the next 2 lines to send the right header
header('Content-type: text/javascript');
include($_SERVER['DOCUMENT_ROOT'].'/sys/common/tools/siteconfig.php');
global $CONFIG;
$ObjDebtcclient = new  DebtCCServer;
$BlogObj=new ClBlogs($DBObj,'');
$ForumRow=$ObjDebtcclient->FnGetLatestForumTopics();
$RecentTopicRows = '<table border="0">';
for($i=0;$i<sizeof($ForumRow);$i++)
{
        $ForumID=$ForumRow[$i][1];
        $RecentTopicRows .= '<tr><td valign="top" height="20"><font class="bull">&bull;</font> </td><td valign="top" height="20">';
        if($ForumRow[$i][4]!="")
        {
                $RecentTopicRows .= '<a href="http://'.$CONFIG['SyndicationURL'].$ForumRow[$i][4].'">';
        }
        else
        {
                $RecentTopicRows .= '<a href="http://'.$CONFIG['SyndicationURL'].'/forums/about'.$ForumID.'.html">';
        }
	$TopicText = (strlen(preg_replace("/\'/","\'",$ForumRow[$i][0]))>17)?substr(preg_replace("/\'/","\'",$ForumRow[$i][0]), 0, 17)."...": preg_replace("/\'/","\'",$ForumRow[$i][0]);
        $RecentTopicRows .= $TopicText."</a></td></tr>";
}
$RecentTopicRows .= '</table>';

$BlogTopicRows = '<table border="0">';

$BlogRow=$BlogObj->FnGetLatestPost();
$BlogRowSize=sizeof($BlogRow);
for($i=0;$i<$BlogRowSize;$i++)
{
        $Post=$BlogRow[$i]['Post'];
        $Url=$BlogRow[$i]['Url'];
        if($Post!="About")
        {
                if($Post!='' && $Url!='')
                {
                        $BlogTopicRows .= '<tr><td valign="top"><font class="bull">&bull;</font> </td><td>';
                        $BlogTopicRows .= '<a href="'.$Url.'">';
			$BlogPostText = (strlen(preg_replace("/\'/","\'",$BlogRow[$i]['Post']))>17)?substr(preg_replace("/\'/","\'",$BlogRow[$i]['Post']), 0, 17)."...":preg_replace("/\'/","\'",$BlogRow[$i]['Post']);
                        $BlogTopicRows .= $BlogPostText."</a></td></tr>";
                        if($i==9)
                        {
                                break;
                        }
                }
        }
}
$BlogTopicRows .= '</table>';
?>
function showToolTab(idValue)
{
        var i=0;
        for(i=1;i<=2;i++)
        {
                if(i==idValue) continue;
                document.getElementById('ToolTab'+i).className = '';
                document.getElementById('ToolBox'+i).style.display = 'none';
        }
        document.getElementById('ToolTab'+idValue).className = 'active';
        document.getElementById('ToolBox'+idValue).style.display = '';
}

function FnShowInitialTableForTopicTool()
{
        if(document.getElementById('TopicHomeLink')=='http://<?php echo $CONFIG['SyndicationURL']; ?>/')
        {
                var InitialTable = '<style type="text/css">body{text-align:left;}</style>';
                InitialTable += '<div id="ToolMainContainer">';
                InitialTable += '<h4><font size="1">Latest Topics</font></h4>';
                InitialTable += '<ul id="ToolTabMenu">';
                InitialTable += '<li><a id="ToolTab1" class="active" href="javascript:showToolTab(1);">In Forums</a></li>';
                InitialTable += '<li><a id="ToolTab2" href="javascript:showToolTab(2);">Blogged</a></li></ul>';

                InitialTable += '<div id="ToolContentContainer">';
                InitialTable += '<div id="ToolBox1"><? echo $RecentTopicRows; ?></div>';
                InitialTable += '<div id="ToolBox2" style="display:none;"><? echo $BlogTopicRows; ?></div>';
                InitialTable += '</div>';
                InitialTable += '</div>';
                document.getElementById('TopicInitialSection').innerHTML = InitialTable;
       }
        else
        {
                var message="<?php echo $CONFIG['SyndicationText'];?>";
                document.getElementById('TopicSectionMain').innerHTML = message;
        }
}

function FnGetStyleCodeForTopicTool()
{
    var StyleCode = '<link rel="stylesheet" type="text/css" href="http://<?php echo $CONFIG['SyndicationURL']; ?>/syndicate/syndication-tab.css"  />';
    document.write(StyleCode);
    document.getElementById('TopicHomeLink').className = 'syndicate';
    setTimeout("FnShowInitialTableForTopicTool()",500);
}
FnGetStyleCodeForTopicTool();