<?php
require_once ('inc/logincheck.php');
CommTool::checkIncludeByAdminPhp();

if ('modify' == $action)
{
    if (empty($abouttitle) || ADMIN_TITLE_LENGTH_FORMAT < strlen($abouttitle))
    {
        promptMessage("javascript:history.go(-1)", $promptAddCorrectTitleFormat, $configJumpTime);
        exit();
    }
    
    if(empty($sortnum))
    {
        promptMessage("javascript:history.go(-1)", $promptEditCorrectSortNumFormat, $configJumpTime);
        exit();
    }

    
    if($kuWebsiteTemplateSelected == $skin)$skin = "";
    $strSql = "update {$configTableHead}about set abouttitle='{$abouttitle}', aboutcontent='{$aboutcontent}', 
              aboutkeywords='{$aboutkeywords}', aboutdesc='{$aboutdesc}', banner='{$banner}', 
              skin='{$skin}', lang='{$lang}' where id={$id};";
    if ($dbInstance->query($strSql))
    {
        if($configIsLog)CommTool::writeLog("{$_SESSION['adminuser']} modify an about ".CommTool::utf8ToGbk($abouttitle));         
        promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=about&menu=about_action&menuid={$menuid}", $promptEditDataSuccess, $configJumpTime);
        exit();
    }
    else
    {
        promptMessage("javascript:history.go(-1)", $promptEditDataFail, $configJumpTime);
        exit();
    }
}
else if ('delete' == $action)
{
    if (empty($id) || ereg("/^d+$/", $id))
    {
        promptMessage("javascript:history.go(-1)", $promptDeleteEmptyId, $configJumpTime);
        exit();
    }
    else
    {
        if (is_array($id))
        {
            foreach ( $id as $key => $value )
            {
                $sql = "delete from {$configTableHead}about where id='{$value}'";
                if (! $flag = $dbInstance->query($sql))
                {
                    promptMessage("javascript:history.go(-1)", $prompBatchDeleteFail, $configJumpTime);
                    exit();
                }
            }
            if($configIsLog)CommTool::writeLog("{$_SESSION['adminuser']} batch delete about");         
            promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=about&menu=about_action&menuid={$menuid}", $prompBatchDeleteSuccess, $configJumpTime);
            exit();
        }
        else
        {
            $sql = "delete from {$configTableHead}about where id='{$id}'";
            if ($dbInstance->query($sql))
            {
                if($configIsLog)CommTool::writeLog("{$_SESSION['adminuser']} delete a about");         
                promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=about&menu=about_action&menuid={$menuid}", $promptDeleteDataSuccess, $configJumpTime);
                exit();
            }
            else
            {
                promptMessage("javascript:history.go(-1)", $promptDeleteDataFail, $configJumpTime);
                exit();
            }
        }
    }
}


$sql = "select count(*) as amount from {$configTableHead}about where lang='{$kuWebsiteEditVersionLanguage}' and type1={$menuid};";
$result = $dbInstance->query($sql);
$row = $dbInstance->fetchArray($result);
$totalNumber = $row ['amount']; //总记录数
$maxNum = $adminPagingPageNumber; //每页显示的记录数 
!empty($page) ? ($page = intval($page)) : $page = 1;
$actionDisplayNumber = $adminPagingActionsDisplayNumber; //活动显示页数 
$type = $adminPagingType; //分页样式0-5 
$isAlwaysShowFirstOrLast = $adminPagingIsAlwaysShowFirstOrLast; //是否绍终显示第一页和最后一页
$startNum = ($page - 1) * $maxNum; //记录查询起始
$sql = "select * from {$configTableHead}about where lang='{$kuWebsiteEditVersionLanguage}' and type1={$menuid} order by id desc limit $startNum, $maxNum";
$result = $dbInstance->query($sql);
while($arr = $dbInstance->fetchArray($result))
{
    $aboutList [] = $arr;
}
$strSql = "select id, menutitle from {$configTableHead}menu where fatherid={$menuid} and lang='{$kuWebsiteEditVersionLanguage}'";
$result = $dbInstance->query($strSql);
while($arrSecondNav = $dbInstance->fetchArray($result))
{
    $aboutSecondNavList [] = $arrSecondNav;
}

include_once template('about_manage.html', $adminTemplateName);
?>