<?php
require_once '../inc/common.inc.php';

if(empty($menuid)){echo "<script>window.location.href='$kuHttpPath';</script>";exit;}

$moduleId = 7;
$moduleName = $arrAllModule[$moduleId];


$menuid = intval($menuid);
$strSql = "select * from {$configTableHead}menu where id='{$menuid}' and lang='{$kuWebsiteCurrLanguage}';";
$result = $dbInstance->query($strSql);
$messageRow = $dbInstance->fetchArray($result);
$kuBlockMessageTitle = $messageRow['menutitle'];                                     
$kuWebsitePageTitle = $kuBlockMessageTitle.' - '.$kuWebsiteTitleKeyWords.' - '.$kuWebsiteTitle.$kuPostfix;
$kuWebsiteKeyWords = $row['menukeywords'] ? $row['menukeywords'] : $kuWebsiteKeyWords;
$kuWebsiteDescription = $row['menudesc'] ? $row['menudesc'] : $kuWebsiteDescription;


$arrMenuInfo = getMenuIdInfo($menuid);

$topMenuId = '';
if(count($kuMenuList[$arrMenuInfo[type3]]))$topMenuId = $arrMenuInfo[type3];
else if(count($kuMenuList[$arrMenuInfo[type2]]))$topMenuId = $arrMenuInfo[type2];
else if(count($kuMenuList[$arrMenuInfo[type1]]))$topMenuId = $arrMenuInfo[type1];


$kuPositionId = $menuid;


$strSqlTotal = '';
if(1 == $kuWebsiteMessageRevertAudit)      //需要审核才能显示
{
    if(1 == $arrMenuInfo['level'])$strSqlTotal = "select count(*) as amount from {$configTableHead}message where lang='{$kuWebsiteCurrLanguage}' and type1={$menuid} and status=1;";
    else if(2 == $arrMenuInfo['level'])$strSqlTotal = "select count(*) as amount from {$configTableHead}message where lang='{$kuWebsiteCurrLanguage}' and type1={$arrMenuInfo[type1]} and type2={$arrMenuInfo[type2]} and status=1;";
    else if(3 == $arrMenuInfo['level'])$strSqlTotal = "select count(*) as amount from {$configTableHead}message where lang='{$kuWebsiteCurrLanguage}' and type1={$arrMenuInfo[type1]} and type2={$arrMenuInfo[type2]} and type3={$arrMenuInfo[type3]} and status=1;";
    else echo "<script>window.location.href='$kuHttpPath';</script>";
}
else
{
    if(1 == $arrMenuInfo['level'])$strSqlTotal = "select count(*) as amount from {$configTableHead}message where lang='{$kuWebsiteCurrLanguage}' and type1={$arrMenuInfo[type1]};";
    else if(2 == $arrMenuInfo['level'])$strSqlTotal = "select count(*) as amount from {$configTableHead}message where lang='{$kuWebsiteCurrLanguage}' and type1={$arrMenuInfo[type1]} and type2={$arrMenuInfo[type2]};";
    else if(3 == $arrMenuInfo['level'])$strSqlTotal = "select count(*) as amount from {$configTableHead}message where lang='{$kuWebsiteCurrLanguage}' and type1={$arrMenuInfo[type1]} and type2={$arrMenuInfo[type2]} and type3={$arrMenuInfo[type3]};";
    else echo "<script>window.location.href='$kuHttpPath';</script>";
}
$result = $dbInstance->query($strSqlTotal);
$row = $dbInstance->fetchArray($result);
$totalNumber = $row ['amount']; //总记录数
!empty($page) ? ($page = intval($page)) : $page = 1; //当前页
$actionDisplayNumber = $frontendPagingActionsDisplayNumber; //活动显示页数 
$type = $frontendPagingType; //分页样式0-5 
$isAlwaysShowFirstOrLast = $frontendPagingIsAlwaysShowFirstOrLast; //是否绍终显示第一页和最后一页
$instancePage = new Pages($totalNumber, $page, $kuWebsitePagingNumbermessage, $actionDisplayNumber, $type, $isAlwaysShowFirstOrLast, $kuCaptionPagingFirstPage, $kuCaptionPagingPreviousPage, $kuCaptionPagingNextPage, $kuCaptionPagingLastPage);
$kuPageLinks = $instancePage->disp('page', $kuHttpPath."message/index.php?lang={$kuWebsiteCurrLanguage}&menuid={$menuid}"); 


$startNum = ($page - 1) * $kuWebsitePagingNumbermessage;
$strOrder = getSqlOrderByOfSortType($kuWebsitePagingSortTypemessage);
if(1 == $kuWebsiteMessageRevertAudit)      
{
    if(1 == $arrMenuInfo['level'])$strSql = "select * from {$configTableHead}message where lang='{$kuWebsiteCurrLanguage}' and type1={$arrMenuInfo[type1]} and status=1 order by {$strOrder} limit $startNum, $kuWebsitePagingNumbermessage;";
    else if(2 == $arrMenuInfo['level'])$strSql = "select * from {$configTableHead}message where lang='{$kuWebsiteCurrLanguage}' and type1={$arrMenuInfo[type1]} and type2={$arrMenuInfo[type2]} and status=1 order by {$strOrder} limit $startNum, $kuWebsitePagingNumbermessage;";
    else if(3 == $arrMenuInfo['level'])$strSql = "select * from {$configTableHead}message where lang='{$kuWebsiteCurrLanguage}' and type1={$arrMenuInfo[type1]} and type2={$arrMenuInfo[type2]} and type3={$arrMenuInfo[type3]} and status=1 order by {$strOrder} limit $startNum, $kuWebsitePagingNumbermessage;";
    else echo "<script>window.location.href='$kuHttpPath';</script>";
}
else
{
    if(1 == $arrMenuInfo['level'])$strSql = "select * from {$configTableHead}message where lang='{$kuWebsiteCurrLanguage}' and type1={$arrMenuInfo[type1]} order by {$strOrder} limit $startNum, $kuWebsitePagingNumbermessage;";
    else if(2 == $arrMenuInfo['level'])$strSql = "select * from {$configTableHead}message where lang='{$kuWebsiteCurrLanguage}' and type1={$arrMenuInfo[type1]} and type2={$arrMenuInfo[type2]} order by {$strOrder} limit $startNum, $kuWebsitePagingNumbermessage;";
    else if(3 == $arrMenuInfo['level'])$strSql = "select * from {$configTableHead}message where lang='{$kuWebsiteCurrLanguage}' and type1={$arrMenuInfo[type1]} and type2={$arrMenuInfo[type2]} and type3={$arrMenuInfo[type3]} order by {$strOrder} limit $startNum, $kuWebsitePagingNumbermessage;";
    else echo "<script>window.location.href='$kuHttpPath';</script>";
}

$kuArrMessageList = array();
$result = $dbInstance->query($strSql);
while($messageRow = $dbInstance->fetchArray($result))
{
  $messageRow['messageurl'] = $kuHttpPath."message/message.php?lang={$kuWebsiteCurrLanguage}&itemid={$messageRow['id']}";
  $messageRow['updatetime'] = substr($messageRow['updatetime'], 0, 10);
  $messageRow['addtime'] = substr($messageRow['addtime'], 0, 10);
  $kuArrMessageList[] = $messageRow;
  $kuMessageTitle = CommTool::cutstrutf8($messageRow['messagetitle'], 70);
  $kuStrMessageList .= "<li><span class=\"right\">{$messageRow['updatetime']}</span><a href=\"{$messageRow['messageurl']}\" title=\"{$messageRow['messagetitle']}\">{$kuMessageTitle}</a></li>";
}
$kuMessageSendUrl = $kuHttpPath."message/add.php?lang={$kuWebsiteCurrLanguage}&menuid={$menuid}";




$topNavId = $arrMenuInfo[type1];
$kuStrBlockSideNav = $kuSideNav[$topNavId];


$kuStrBlockContact = $kuBlock[2];

include_once KUWEBS_ABSOLUTE_PATH."inc/headermenu.php"; 
include_once KUWEBS_ABSOLUTE_PATH."inc/footer.php";
include_once template('messagelist');


?>