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


if("basic" == $action)                                  //处理网站基本设置
{
  $kuWebsiteSupportEn = $_POST['kuWebsiteSupportEn'];
  if(empty($kuWebsiteSupportEn)){$kuWebsiteSupportEn = 0;}else{$kuWebsiteSupportEn = 1;}
  $kuWebsiteSupportSimplifiedOrTraditional = $_POST['kuWebsiteSupportSimplifiedOrTraditional'];
  if(empty($kuWebsiteSupportSimplifiedOrTraditional)){$kuWebsiteSupportSimplifiedOrTraditional = 0;}else{$kuWebsiteSupportSimplifiedOrTraditional = 1;}
  include_once('system/saveconfig.php');
  if($configIsLog)CommTool::writeLog("{$_SESSION['adminuser']} change the basic settings");         
  promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=system&menu=basic", $promptEditDataSuccess, $configJumpTime);
}
else if("skin" == $action)                              //处理网站风格设置
{
  include_once('system/saveconfig.php');
  if($configIsLog)CommTool::writeLog("{$_SESSION['adminuser']} change the skin settings");         
  promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=system&menu=skin", $promptEditDataSuccess, $configJumpTime);  
}
else if("img" == $action)                                //处理图片设置  
{
  (isset($kuWebsiteImgBigWate) && 'on' == $_POST['kuWebsiteImgBigWate']) ? $kuWebsiteImgBigWate = "1" : $kuWebsiteImgBigWate = "0";
  (isset($kuWebsiteImgThumbWate) && 'on' == $_POST['kuWebsiteImgThumbWate']) ? $kuWebsiteImgThumbWate = "1" : $kuWebsiteImgThumbWate = "0";
  include_once('system/saveconfig.php');
  if($configIsLog)CommTool::writeLog("{$_SESSION['adminuser']} change the Image settings");         
  promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=system&menu=img", $promptEditDataSuccess, $configJumpTime);  
}
else if("flash" == $action)                              //处理flash设置
{
  $kuWebsiteFlashStartFlag = $_POST['kuWebsiteFlashStartFlag'];
  include_once('system/saveconfig.php');
  if($configIsLog)CommTool::writeLog("{$_SESSION['adminuser']} change the banner settings");         
  promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=system&menu=flash", $promptEditDataSuccess, $configJumpTime);  
}
else if("indexconfig" == $action)                              //处理主页参数
{
  $kuWebsiteIndexFriendLinkShow = $_POST['kuWebsiteIndexFriendLinkShow'];
  include_once('system/saveconfig.php');
  if($configIsLog)CommTool::writeLog("{$_SESSION['adminuser']} change the index settings");         
  promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=system&menu=indexconfig", $promptEditDataSuccess, $configJumpTime);  
}
else if("flashindex" == $action)                              //处理flash设置
{
  $kuWebsiteFlashIndexStartFlag = $_POST['kuWebsiteFlashIndexStartFlag'];
  include_once('system/saveconfig.php');
  if($configIsLog)CommTool::writeLog("{$_SESSION['adminuser']} change the index banner settings");         
  promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=system&menu=flashindex", $promptEditDataSuccess, $configJumpTime);  
}
else if("mail" == $action)
{
  include_once('system/saveconfig.php');
  if($configIsLog)CommTool::writeLog("{$_SESSION['adminuser']} change the Mail settings");         
  promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=system&menu=mail", $promptEditDataSuccess, $configJumpTime);  
}
else if("server" == $action)                            //处理在线客服设置
{
  if('add' ==  $operate)
  {
    if('' == $enable){$enable = 0;}
    $strSql = "insert into {$configTableHead}server (servername, lang, qqnum, msn, taobao, skype, sortnum, enable) value   ('{$clientName}', '{$lang}', '{$qq}', '{$msn}', '{$taobao}', '{$skype}', '{$sortnum}', {$enable});";  
    if($dbInstance->query($strSql))
    {
      if($configIsLog)CommTool::writeLog("{$_SESSION['adminuser']} add an server: ".CommTool::utf8ToGbk($clientName));         
      promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=system&menu=server", $promptAddDataSuccess, $configJumpTime);  
    }
    else
    {
      promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=system&menu=server", $promptAddDataFail, $configJumpTime);
    }
  }
  else if('modify' == $operate)
  {
    if('' == $enable){$enable = 0;}
    $strSql = "update {$configTableHead}server set servername='{$clientName}', lang='{$lang}', qqnum='{$qq}', msn='{$msn}', taobao='{$taobao}', skype='{$skype}', sortnum='{$sortnum}', enable={$enable} where id={$serverid};";
    if($dbInstance->query($strSql))
    {
      if($configIsLog)CommTool::writeLog("{$_SESSION['adminuser']} modify an server: ".CommTool::utf8ToGbk($clientName));         
      promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=system&menu=server", $promptEditDataSuccess, $configJumpTime);  
    }
    else
    {
      promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=system&menu=server", $promptEditDataFail, $configJumpTime);
    }
  }
  else if('delete' == $operate)
  {
    if(empty($serverid))
    {
      promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=system&menu=server", $prompEmptyServerId, $configJumpTime);  
    }
    $strSql = "delete from {$configTableHead}server where id ={$serverid};";  
    if($dbInstance->query($strSql))
    {
      if($configIsLog)CommTool::writeLog("{$_SESSION['adminuser']} delete an server: ".CommTool::utf8ToGbk($clientName));         
      promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=system&menu=server", $promptDeleteDataSuccess, $configJumpTime);  
    }
    else
    {
      promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=system&menu=server", $promptDeleteDataFail, $configJumpTime);
    }
  }
  promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=system&menu=flash", $promptEditDataSuccess, $configJumpTime);  
}
else if("seo" == $action)                                //处理SEO设置                                
{
  include_once('system/saveconfig.php');
  if($configIsLog)CommTool::writeLog("{$_SESSION['adminuser']} change the seo settings");         
  promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=system&menu=seo", $promptOperateSuccess, $configJumpTime);  
}
else if("foot" == $action)                              //处理foot设置
{
  include_once('system/saveconfig.php');
  if($configIsLog)CommTool::writeLog("{$_SESSION['adminuser']} change the footer settings");         
  promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=system&menu=foot", $promptOperateSuccess, $configJumpTime);  
}
else if("block" == $action)                          //处理首页配置设置                        
{
  if('add' == $operate)
  {
    $strSql = "insert into {$configTableHead}block (id, blocktitle, lang, blockcontent) value ({$id}, '{$blocktitle}', '{$kuWebsiteEditVersionLanguage}', '{$blockcontent}');";  
    if($dbInstance->query($strSql))
    {
      if($configIsLog)CommTool::writeLog("{$_SESSION['adminuser']} add an block: ".CommTool::utf8ToGbk($blocktitle));         
      promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=system&menu=block_add&id={$id}", $promptAddDataSuccess, $configJumpTime);
    }
    else
    {
      promptMessage("javascript:history.go(-1)", $promptAddDataFail, $configJumpTime);
    }
  }
  else if('modify' == $operate)
  {
    $strSql = "update {$configTableHead}block set blocktitle='{$blocktitle}', lang='{$kuWebsiteEditVersionLanguage}', blockcontent='{$blockcontent}' where id='{$id}' and lang='{$kuWebsiteEditVersionLanguage}';";
    if($dbInstance->query($strSql))
    {
      if($configIsLog)CommTool::writeLog("{$_SESSION['adminuser']} modify an block: ".CommTool::utf8ToGbk($blocktitle));         
      promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=system&menu=block_add&id={$id}", $promptEditDataSuccess, $configJumpTime);
    }
    else
    {
      promptMessage("javascript:history.go(-1)", $promptEditDataFail, $configJumpTime);
    }
  }
  else if('saveparameter' == $operate)
  {
    for($i = $kuWebsiteIndexNumber+1; $i <= 5; $i++)
    {
      $tempVarTitle = 'kuWebsiteIndexPageTitle'.$i;
      $$tempVarTitle = "";
    }
    include_once('system/saveconfig.php');
    if($configIsLog)CommTool::writeLog("{$_SESSION['adminuser']} change the block setting");         
    promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=system&menu=block", $promptOperateSuccess, $configJumpTime);  
  }
}
else if("" == $action)                                  //判断是否登陆
{
  $userName = trim($_POST['username']);
  $password = $_POST['pass'];
  if(1 > strlen($userName) || 1 > strlen($password))
  {
    promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=login&menu=login", $promptNonLogin, $configJumpTime);
    exit;
  }
  $userPassword = CommTool::encryptMd5($password, $configEncryptTimes);
  $strSql = "select id, adminuser, adminpassword from {$configTableHead}admin where adminuser = '$userName' and adminpassword = '$userPassword';";
  $row = $dbInstance->getOne($strSql);
  if(1 > $row['id'])
  {
    promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=login&menu=login", $promptLoginFail, $configJumpTime);
    exit;
  }
  else
  {
    $_SESSION['adminid'] = $row['id'];
    $_SESSION['adminuser'] = $row['adminuser'];
    $_SESSION['adminpassword'] = $row['adminpassword'];
    if($configIsLog)CommTool::writeLog("{$_SESSION['adminuser']} login to system");
    promptMessage($adminHttpPath.'index.php', $promptLoginSuccess, $configJumpTime);
    exit;
  }
}   