<?php
// ------------------------------------------------------------------------- //
//                XOOPS - PHP Content Management System                      //
//                       <http://www.xoops.org/>                             //
// ------------------------------------------------------------------------- //
//  This program 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.                                      //
//                                                                           //
//  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 //
// ------------------------------------------------------------------------- //
include("header.php");
$myts =& MyTextSanitizer::getInstance();
if($xoopsConfig['startpage'] == "xoopsfaq"){
	$xoopsOption['show_rblock'] =1;
	include(XOOPS_ROOT_PATH."/header.php");
	make_cblock();
}else{
	$xoopsOption['show_rblock'] =0;
	include(XOOPS_ROOT_PATH."/header.php");
}

OpenTable();
$cat_id = intval($HTTP_GET_VARS['cat_id']);
if (empty($cat_id)) {
    	echo "<h4 style='text-align:left;'>"._XD_DOCS."</h4><table width='100%' cellpadding='4' cellspacing='0' border='0'><tr><td><b>" ._XD_CATEGORIES."</b></td></tr><tr><td>";
	$result = $xoopsDB->query("SELECT category_id, category_title FROM ".$xoopsDB->prefix("xoopsfaq_categories")." ORDER BY category_order ASC");
	while ( list($cat_id, $category) = $xoopsDB->fetchRow($result) ) {
		$category = $myts->makeTboxData4Show($category);
		echo "&nbsp;&nbsp;<img src='".XOOPS_URL."/modules/xoopsfaq/images/folder.gif' width='14' height='14' border='0' />&nbsp;<a href='index.php?cat_id=".$cat_id."'>".$category."</a>";
		$sql = "SELECT contents_id, contents_title FROM ".$xoopsDB->prefix("xoopsfaq_contents")." WHERE contents_visible=1 AND category_id='".$cat_id."' ORDER BY contents_order ASC";
		$result2 = $xoopsDB->query($sql);
		$list = "";
		$count = 0;
		while ( $myrow = $xoopsDB->fetchArray($result2) ) {
			$list .= "<li><a href='index.php?cat_id=".$cat_id."#".$myrow['contents_id']."'>".$myts->makeTboxData4Show($myrow['contents_title'])."</a></li>";
			$count += 1;
		}
		if ($count > 0) {
			echo "<ul style='list-style-image:url(images/question.gif);'>".$list."</ul>";
		} else {
			echo "<br />";
		}
    	}
	echo"</td></tr></table>";    	
} else {
	$result = $xoopsDB->query("SELECT category_title FROM ".$xoopsDB->prefix("xoopsfaq_categories")." WHERE category_id='".$cat_id."'");
	list($category) = $xoopsDB->fetchRow($result);
	$category = $myts->makeTboxData4Show($category);
	echo "<h4 style='text-align:left;'>"._XD_DOCS."</h4><a id='top' name='top'><a href='index.php'>" ._XD_MAIN."</a>&nbsp;<span style='font-weight:bold;'>&raquo;&raquo;</span>&nbsp;<b>".$category."</b><br /><br />";
	$filename = XOOPS_ROOT_PATH."/modules/xoopsfaq/cache/doc".$cat_id.".php";
	if (file_exists($filename)) {
		include($filename);
	}
	echo "<br /><br /><div><b>[ <a href='index.php'>" ._XD_BACKTOINDEX."</a> ]</b></div>";
}
CloseTable();
include (XOOPS_ROOT_PATH."/footer.php");
?>