<?php
require_once("../../modules/newbb/class/class.util.php");

include "header.php";
// this page uses smarty template
// this must be set before including main header.php
$xoopsOption['template_main_path'] = XOOPS_ROOT_PATH . '/modules/newbb/templates/newbb_response.html';
include XOOPS_ROOT_PATH."/header.php";

$xoopsTpl->assign('lang_topic', _MD_TOPIC);
$xoopsTpl->assign('lang_response', _MD_RESPONSE);
$xoopsTpl->assign('lang_date', _MD_DATE);
$xoopsTpl->assign('forum_name', '対応状況一覧');

$sql = 'SELECT topic_id, topic_title, topic_response, topic_last_post_id, forum_id,  from_unixtime(topic_time) as topic_time, uname FROM xoops_bb_topics as tpc left join xoops_users as usr on tpc.topic_response_uid = usr.uid ORDER BY topic_response, topic_id DESC';
if ( !$result = $xoopsDB->query($sql) ) {
    redirect_header('index.php',2,_MD_ERROROCCURED);
    exit();
}

// Read topic 'lastread' times from cookie, if exists
$topic_lastread = newbb_get_topics_viewed();
while ( $myrow = $xoopsDB->fetchArray($result) ) {
	$fix = getFixName($myrow['forum_id']);

	$sql_tmp = "SELECT p.post_id FROM ".$xoopsDB->prefix('bb_posts')." p WHERE p.pid = 0 AND p.topic_id = ".$myrow['topic_id'];
	$result_tmp = $xoopsDB->query($sql_tmp);
	$myrow_tmp = $xoopsDB->fetchArray($result_tmp);
	$myrow['post_id'] = $myrow_tmp['post_id'];
	
	$topiclink = 'viewtopic.php?topic_id='.$myrow['topic_id'].'&amp;forum='.$myrow['forum_id'];
	
	$xoopsTpl->append('topics', array(
								'topic_id'=>$myrow['topic_id'],
								'forum_id'=>$myrow['forum_id'],
								'topic_link'=>$topiclink,
								'topic_fix'=>$fix,
								'topic_number'=>$myrow['post_id'],
								'topic_title'=>$myrow['topic_title'],
								'topic_response'=>$myrow['topic_response'],
								'topic_response_user'=>$myrow['uname'],
								'topic_time'=>$myrow['topic_time']));
}

// 対応状況
$xoopsTpl->assign('arrResponse', $arrResponse);

include XOOPS_ROOT_PATH."/footer.php";
?>