<?php

//session_start();
//error_reporting(E_ALL);
error_reporting(E_ERROR);                                                      
set_magic_quotes_runtime(0);                                                          
$mTime = explode(' ', microtime());                                                    
$kuwebsStartTime = $mTime[1] + $mTime[0];
$nowTime = date("Y-m-d H:i:s");  

if(function_exists('date_default_timezone_set')){date_default_timezone_set('Hongkong');}


function filterChar($array)
{
  foreach($array as $key => $value)
  {
    if(!is_array($value))
    {
      $value = str_replace("&#x", "& # x", $value);                                    
      $value = preg_replace("/eval/i", 'eva l', $value);                              
      //$value = htmlspecialchars($value);
      !get_magic_quotes_gpc() && $value = addslashes($value);
      $array[$key] = $value;
    }
    else
    {
      $array[$key] = filterChar($array[$key]);
    }
  }
  return $array;
}


if(PHP_VERSION < '4.1.0') 
{
  $_GET = &$HTTP_GET_VARS;
  $_POST = &$HTTP_POST_VARS;
  $_COOKIE = &$HTTP_COOKIE_VARS;
  $_SERVER = &$HTTP_SERVER_VARS;
  $_ENV = &$HTTP_ENV_VARS;
  $_FILES = &$HTTP_POST_FILES;
}


$_POST = filterChar($_POST);
$_GET = filterChar($_GET);
$_COOKIE = filterChar($_COOKIE);

if(!ini_get('register_globals'))
{
  @extract($_COOKIE, EXTR_SKIP);
  @extract($_FILES, EXTR_SKIP);
}


foreach(array('_COOKIE', '_POST', '_GET') as $_request)
{
  foreach($$_request as $_key => $_value)
  {
    $key{0} != '_' && $$_key = daddslashes($_value);
  }
}


$kuServerRoot = substr(dirname(__FILE__), 0, -4).'/';            
define('KUWEBS_ABSOLUTE_PATH', $kuServerRoot);                  
define('KUWEBS_TEMPLATE_PATH', $kuServerRoot.'template');        
define('KUWEBS_COMPILED_PATH', $kuServerRoot.'inc/compiled/');   
$kuHostName = $_SERVER['HTTP_HOST'];                             
 
$rootLen = strlen($_SERVER['DOCUMENT_ROOT']);
if(substr($_SERVER['DOCUMENT_ROOT'], $rootLen-1, 1) == '/')$rootLen = $rootLen-1;
$kuServerRelativPath = substr($kuServerRoot, $rootLen, strlen($kuServerRoot)-$rootLen);

$kuHttpPath = str_replace('\\', '/', "http://{$kuHostName}{$kuServerRelativPath}"); 
$kuAbsolutePath = str_replace('\\', '/', KUWEBS_ABSOLUTE_PATH); 


require_once(KUWEBS_ABSOLUTE_PATH.'config/configsys.inc.php');                  
require_once(KUWEBS_ABSOLUTE_PATH.'config/config.db.php');                    
require_once(KUWEBS_ABSOLUTE_PATH.'config/config.inc.php');                 


if(5 <= strlen($lang))unset($lang);
empty($lang) ? $lang = $kuWebsiteDefauleIndexLanguage : $lang;
include_once(KUWEBS_ABSOLUTE_PATH.'config/config.'.$lang.'.inc.php');
include_once(KUWEBS_ABSOLUTE_PATH.'config/frontend.'.$lang.'.inc.php');
include_once(KUWEBS_ABSOLUTE_PATH.'config/caption.'.$lang.'.inc.php');

require_once(KUWEBS_ABSOLUTE_PATH.'inc/mysql.class.php');                    
require_once(KUWEBS_ABSOLUTE_PATH.'inc/pages.class.php');                  
require_once(KUWEBS_ABSOLUTE_PATH.'inc/commonfunc.inc.php');                  
require_once(KUWEBS_ABSOLUTE_PATH.'inc/frontend.inc.php');                  


$kuTemplateName = $kuWebsiteTemplateSelected;


$kuTemplatePath = 'template/'.$kuTemplateName.'/';
$kuCssPath = 'template/'.$kuTemplateName.'/css/';
$kuJsPath = 'template/'.$kuTemplateName.'/js/';
$kuImgPath = 'template/'.$kuTemplateName.'/images/';


$kuHttpTemplatePath = $kuHttpPath.'template/'.$kuTemplateName.'/';
$kuHttpCssPath = $kuHttpPath.'template/'.$kuTemplateName.'/css/';
$kuHttpJsPath = $kuHttpPath.'template/'.$kuTemplateName.'/js/';
$kuHttpImgPath = $kuHttpPath.'template/'.$kuTemplateName.'/images/';
$kuUploadPath = $kuHttpPath."upload/";   

$adminDebugFile = $adminServerRoot.'debug.txt';                                          
$kuPostfix = "--Powe"."red "."by "."kuwe"."bs.com";                                      

 
if(!file_exists(KUWEBS_ABSOLUTE_PATH."/inc/install.lock"))    
{
  echo "<script language=\"javascript\"> setTimeout(\"window.location.href='".$kuHttpPath.'install/index.php'."'\", 10); </script>";
  exit;
}

if(is_dir(KUWEBS_ABSOLUTE_PATH."/install"))    
{
  echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
  echo "<script language='javascript'> alert('{$kuCaptionRenameInstallPath}'); </script>";
}
if(is_dir(KUWEBS_ABSOLUTE_PATH."/admin"))    
{
  echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
  echo "<script language='javascript'> alert('{$kuCaptionRenameAdminPath}'); </script>";
}

$dbInstance = new DatabaseMysql();                                                      
$dbInstance->connect($configDBHost, $configDBUser, $configDBPassword, $configDBName);    


function daddslashes($string, $force = 0) 
{
  !defined('MAGIC_QUOTES_GPC') && define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
  if(!MAGIC_QUOTES_GPC || $force) 
  {
    if(is_array($string)) 
    {
      foreach($string as $key => $val) 
      {
        $string[$key] = daddslashes($val, $force);
      }
    } 
    else 
    {
      $string = addslashes($string);
    }
  }
  return $string;
}


if(empty($lang)){$kuWebsiteCurrLanguage = $kuWebsiteDefauleIndexLanguage;}
else {$kuWebsiteCurrLanguage = $lang;}


$kuBlock = array();
$kuArrayBlock = array();
$strSql = "select * from {$configTableHead}block where lang='$kuWebsiteCurrLanguage';";
//echo $strSql;
$arrBlock = $dbInstance->getList($strSql);
foreach($arrBlock as $blockInfo)
{
    $strBlock = "";
    $blockId = $blockInfo['id'];
    $blockInfo['blocktitle'] = stripslashes($blockInfo['blocktitle']);
    $blockInfo['blockcontent'] = stripslashes($blockInfo['blockcontent']);
    $strBlock = "<div class='divBlock block{$kuWebsiteCurrLanguage}{$blockId}'>\n<div class='title blockt{$kuWebsiteCurrLanguage}{$blockId}'>{$blockInfo['blocktitle']}</div>\n<div class='content blockc{$kuWebsiteCurrLanguage}{$blockId}'>{$blockInfo['blockcontent']}</div>\n</div>";
    $kuBlock[$blockId] = $strBlock;
    $kuArrayBlock[$blockId] = $blockInfo;
}


$strSql = "select * from {$configTableHead}menu where lang='{$kuWebsiteCurrLanguage}' order by sortnum asc;";
$result = $dbInstance->query($strSql);
while($row = $dbInstance->fetchArray($result))
{
  if(1 == $row['menutype'] && !empty($row['menumodule']))
  {
    switch ($row['menumodule'])
    {
      case 1 : $kuFileName = 'about.php'; $kuFolderName='about';  break;
      case 2 : $kuFileName = 'news.php'; $kuFolderName='news';  break;
      case 3 : $kuFileName = 'product.php'; $kuFolderName='product';  break;
      case 4 : $kuFileName = 'img.php'; $kuFolderName='img';  break;
      case 5 : $kuFileName = 'download.php'; $kuFolderName='download';  break;
      case 6 : $kuFileName = 'job.php'; $kuFolderName='job';  break;
      case 7 : $kuFileName = 'message.php'; $kuFolderName='message';  break;
      case 8 : $kuFileName = 'faq.php'; $kuFolderName='faq';  break;
    }
        
    if('about' == $kuFolderName)$row[menuurl] = $kuHttpPath.$kuFolderName.'/index.php?lang='.$kuWebsiteCurrLanguage.'&menuid='.$row['id'];
    else $row[menuurl] = $kuHttpPath.$kuFolderName.'/index.php?lang='.$kuWebsiteCurrLanguage.'&menuid='.$row['id'].'&page=1';
    if(1 == $row[blankwindow]){$row[blank] = '_blank';}else{$row[blank] = '_self';}
    $kuMenuList[$row[id]] = $row;
  }
  else if(2 == $row['menutype'])
  {
    $row[menuurl] = $row['otherurl'];
    if(1 == $row[blankwindow]){$row[blank] = '_blank';}else{$row[blank] = '_self';}
    $kuMenuList[$row[id]] = $row;
  }
}


$arrAllModule = array("1"=>"about", "2"=>"news", "3"=>"product", "4"=>"img", "5"=>"download", "6"=>"job", "7"=>"message", "8"=>"faq"); 
//print_r($arrAllModule);


$kuStrSearchUrl = "{$kuHttpPath}search.php?lang={$kuWebsiteCurrLanguage}";
$kuStrSiteMapUrl = "{$kuHttpPath}sitemap.php?lang={$kuWebsiteCurrLanguage}";


$kuStrIndexUrl = "{$kuHttpPath}index.php?lang={$kuWebsiteCurrLanguage}";
$kuStrIndexUrlcn = "{$kuHttpPath}index.php?lang=cn";
$kuStrIndexUrlen = "{$kuHttpPath}index.php?lang=en";


$sql = "select id, menutitle from {$configTableHead}menu order by id asc;";
$result = $dbInstance->query($sql);
while($row = $dbInstance->fetchArray($result))
{
  $menuList[$row['id']] = $row['menutitle'];
}


$kuStrMainNav1 = "";
$kuStrMainNav2 = "";
$kuArrMainNav = array();
$strSql = "select * from {$configTableHead}menu where (navshow=2 or navshow=4) and lang='{$kuWebsiteCurrLanguage}' order by sortnum asc;";
$arrTopNav = $dbInstance->getList($strSql);
foreach($arrTopNav as $topInfo)
{
  $strMainNav2 = "";
  $topId = $topInfo['id'];
  $menuType = $topInfo['menutype'];
  $menuModule = $topInfo['menumodule'];
  $menuTitle = $topInfo['menutitle'];
  $strBlank = ($topInfo['blankwindow'] == 1 ? " target='_blank' " : "");
  
  if(2 == $menuType)$urlNav1 = $topInfo['otherurl'];
  else if(1 == $menuModule)$urlNav1 = $kuHttpPath.$arrAllModule[$menuModule]."/index.php?lang={$kuWebsiteCurrLanguage}&menuid={$topId}";
  else $urlNav1 = $kuHttpPath.$arrAllModule[$menuModule]."/index.php?lang={$kuWebsiteCurrLanguage}&menuid={$topId}&page=1";
  $kuStrMainNav1 .= "<li class='mainMenu nav{$topId}'>\n<a href=\"{$urlNav1}\" $strBlank><span>{$menuTitle}</span></a>\n</li>\n";
  $strMainNav2 = "<li class='mainMenu nav{$topId}'>\n<a href=\"{$urlNav1}\" $strBlank><span>{$menuTitle}</span></a>\n";

  $topInfo['menuurl'] = $urlNav1;
  $topInfo['blank'] = $strBlank;
  $kuArrMainNav[$topId] = $topInfo;

  $strSql2 = "select * from {$configTableHead}menu where fatherid={$topId} and lang='{$kuWebsiteCurrLanguage}' order by sortnum asc;";
  //echo $strSql2;
  $arrSecondNav = $dbInstance->getList($strSql2);
  if(0 < count($arrSecondNav))
  {
      $strMainNav2 .= "<ul id='subOne{$topId}'>\n";
      foreach($arrSecondNav as $secondInfo)
      {
          $secondId = $secondInfo['id'];
          $menuType2 = $secondInfo['menutype'];
          $menuModule2 = $secondInfo['menumodule'];
          $menuTitle2 = $secondInfo['menutitle'];
          $strBlank = ($secondInfo['blankwindow'] == 1 ? " target='_blank' " : "");
          
          if(2 == $menuType)$urlNav2 = $topInfo['otherurl'];
          else if(1 == $menuModule)$urlNav2 = $kuHttpPath.$arrAllModule[$menuModule]."/index.php?lang={$kuWebsiteCurrLanguage}&menuid={$secondId}";
          else $urlNav2 = $kuHttpPath.$arrAllModule[$menuModule]."/index.php?lang={$kuWebsiteCurrLanguage}&menuid={$secondId}&page=1";
          $strMainNav2 .= "<li class='subMenu nav{$topId}'><a href=\"{$urlNav2}\" $strBlank><span>{$menuTitle2}</span></a></li>\n";
      }
      $strMainNav2 .= "\n</ul>\n";
  }
  $strMainNav2 .= "\n</li>\n";
  $kuStrMainNav2 .= $strMainNav2;
}


$kuStrFooterNav1 = '';
$kuArrFooterNav = array();
$strSql = "select * from {$configTableHead}menu where (navshow=3 or navshow=4) and lang='{$kuWebsiteCurrLanguage}' order by sortnum asc;";
$arrTopNav = $dbInstance->getList($strSql);
foreach($arrTopNav as $topInfo)
{
  $topId = $topInfo['id'];
  $menuType = $topInfo['menutype'];
  $menuModule = $topInfo['menumodule'];
  $menuTitle = $topInfo['menutitle'];
  $strBlank = ($topInfo['blankwindow'] == 1 ? " target='_blank' " : "");
  
  if(2 == $menuType)$urlNav1 = $topInfo['otherurl'];
  else if(1 == $menuModule)$urlNav1 = $kuHttpPath.$arrAllModule[$menuModule]."/index.php?lang={$kuWebsiteCurrLanguage}&menuid={$topId}";
  else $urlNav1 = $kuHttpPath.$arrAllModule[$menuModule]."/index.php?lang={$kuWebsiteCurrLanguage}&menuid={$topId}&page=1";
  $kuStrFooterNav1 .= "<li class='mainMenu nav{$topId}'><a href=\"{$urlNav1}\" $strBlank><span>{$menuTitle}</span></a></li>\n";

  $topInfo['menuurl'] = $urlNav1;
  $topInfo['blank'] = $strBlank;
  $kuArrFooterNav[$topId] = $topInfo;
}
        

$kuSideNav = array();
$strSql = "select * from {$configTableHead}menu where fatherid=0 and lang='{$kuWebsiteCurrLanguage}' order by sortnum asc;";
//echo $strSql;
$arrTopNav = $dbInstance->getList($strSql);
foreach($arrTopNav as $topInfo)
{
    $strTopNav = "";
    $topId = $topInfo['id'];
    $menuModule = $topInfo['menumodule'];
    $menuTitle = $topInfo['menutitle'];
    $strBlank = ($topInfo['blankwindow'] == 1 ? " target='_blank' " : "");
    if(1 == $menuModule)$urlNav1 = $kuHttpPath.$arrAllModule[$menuModule]."/index.php?lang={$kuWebsiteCurrLanguage}&menuid={$topId}";
    else $urlNav1 = $kuHttpPath.$arrAllModule[$menuModule]."/index.php?lang={$kuWebsiteCurrLanguage}&menuid={$topId}&page=1";
    
    $strSql2 = "select * from {$configTableHead}menu where fatherid={$topId} and lang='{$kuWebsiteCurrLanguage}' order by sortnum asc;";
    //echo $strSql2;
    $arrSecondNav = $dbInstance->getList($strSql2);
    if(0 < count($arrSecondNav))
    {
        $strTopNav = "<div class='commonSide nav{$topId}'>\n<div class='title nav{$topId}'><a href=\"{$urlNav1}\"><span>{$menuTitle}</span></a></div>\n<div class='content nav{$topId}'><ul class='content nav{$topId}'>";
        foreach($arrSecondNav as $secondInfo)
        {
            $secondId = $secondInfo['id'];
            $menuModule2 = $secondInfo['menumodule'];
            $menuTitle2 = $secondInfo['menutitle'];
            if(1 == $menuModule)$urlNav2 = $kuHttpPath.$arrAllModule[$menuModule]."/index.php?lang={$kuWebsiteCurrLanguage}&menuid={$secondId}";
            else $urlNav2 = $kuHttpPath.$arrAllModule[$menuModule]."/index.php?lang={$kuWebsiteCurrLanguage}&menuid={$secondId}&page=1";

            $strTopNav .= "<li class='nav2'><a href=\"{$urlNav2}\">{$menuTitle2}</a></li>";
            
            
            $strSql3 = "select * from {$configTableHead}menu where fatherid={$secondId} and lang='{$kuWebsiteCurrLanguage}' order by sortnum asc;";
            $arrThirdNav = $dbInstance->getList($strSql3);
            if(0 < count($arrThirdNav))//三级
            {
                $strTopNav .= "\n<ul class='content nav{$topId}'>";
                foreach($arrThirdNav as $thirdInfo)
                {
                    $thirdId = $thirdInfo['id'];
                    $menuModule3 = $thirdInfo['menumodule'];
                    $menuTitle3 = $thirdInfo['menutitle'];
                    $urlNav3 = $kuHttpPath.$arrAllModule[$menuModule]."/index.php?lang={$kuWebsiteCurrLanguage}&menuid={$thirdId}&page=1";

                    $strTopNav .= "<li class='nav3'><a href=\"{$urlNav3}\">{$menuTitle3}</a></li>";
                }
                $strTopNav .= "<div class='divClear'></div>\n</ul>\n";
            }
            
        }
        $strTopNav .= "<div class='divClear'></div>\n</ul><div class='divClear'></div></div>\n</div>\n";
    }

    $kuSideNav[$topId] = $strTopNav;
}


$kuMenuPosition = array();
$strSql = "select * from {$configTableHead}menu where lang='{$kuWebsiteCurrLanguage}' order by id asc;";
$arrNav = $dbInstance->getList($strSql);
foreach($arrNav as $menuInfo)
{
    $strPosition = "";
    $menuId = $menuInfo['id'];
    $fatherId = $menuInfo['fatherid'];
    $menuModule = $menuInfo['menumodule'];
    $menuTitle = $menuInfo['menutitle'];
    $strBlank = ($menuInfo['blankwindow'] == 1 ? " target='_blank' " : "");
    
    if(1 == $menuModule)$urlNav1 = $kuHttpPath.$arrAllModule[$menuModule]."/index.php?lang={$kuWebsiteCurrLanguage}&menuid={$menuId}";
    else $urlNav1 = $kuHttpPath.$arrAllModule[$menuModule]."/index.php?lang={$kuWebsiteCurrLanguage}&menuid={$menuId}&page=1";
    
    if(0 == $fatherId)//如果是一级目录
    {
        $strPosition = "<a href='{$kuHttpPath}'>{$kuCaptionIndexMenuHome}</a>&gt;<a href='{$urlNav1}' {$strBlank}>$menuTitle</a>";
        $kuMenuPosition[$menuId] = $strPosition;
        continue;
    }
    else
    {
        $strSql2 = "select * from {$configTableHead}menu where lang='{$kuWebsiteCurrLanguage}' and id='{$fatherId}';";
        $arrNav2 = $dbInstance->getOne($strSql2);
        $menuId2 = $arrNav2['id'];
        $fatherId2 = $arrNav2['fatherid'];
        $menuModule2 = $arrNav2['menumodule'];
        $menuTitle2 = $arrNav2['menutitle'];
        $strBlank2 = ($arrNav2['blankwindow'] == 1 ? " target='_blank' " : "");

        if(1 == $menuModule2)$urlNav2 = $kuHttpPath.$arrAllModule[$menuModule2]."/index.php?lang={$kuWebsiteCurrLanguage}&menuid={$menuId2}";
        else $urlNav2 = $kuHttpPath.$arrAllModule[$menuModule2]."/index.php?lang={$kuWebsiteCurrLanguage}&menuid={$menuId2}&page=1";

        if(0 != $fatherId2)
        {
            $strSql3 = "select * from {$configTableHead}menu where lang='{$kuWebsiteCurrLanguage}' and id='{$fatherId2}';";
            $arrNav3 = $dbInstance->getOne($strSql3);
            $menuId3 = $arrNav3['id'];
            $fatherId3 = $arrNav3['fatherid'];
            $menuModule3 = $arrNav3['menumodule'];
            $menuTitle3 = $arrNav3['menutitle'];
            $strBlank3 = ($arrNav3['blankwindow'] == 1 ? " target='_blank' " : "");

            if(1 == $menuModule3)$urlNav3 = $kuHttpPath.$arrAllModule[$menuModule3]."/index.php?lang={$kuWebsiteCurrLanguage}&menuid={$menuId3}";
            else $urlNav3 = $kuHttpPath.$arrAllModule[$menuModule3]."/index.php?lang={$kuWebsiteCurrLanguage}&menuid={$menuId3}&page=1";
            
            if(empty($strPosition))$strPosition = "<a href='{$kuHttpPath}'>{$kuCaptionIndexMenuHome}</a>&gt;<a href='{$urlNav3}' {$strBlank3}>{$menuTitle3}</a>";
        }
        
        if(empty($strPosition))$strPosition = "<a href='{$kuHttpPath}'>{$kuCaptionIndexMenuHome}</a>&gt;<a href='{$urlNav2}' {$strBlank2}>{$menuTitle2}</a>";
        else $strPosition .= "&gt;<a href='{$urlNav2}' {$strBlank2}>{$menuTitle2}</a>";
    }
    
    if(empty($strPosition))$strPosition = "<a href='{$kuHttpPath}'>{$kuCaptionIndexMenuHome}</a>&gt;<a href='{$urlNav1}' {$strBlank}>{$menuTitle}</a>";
    else $strPosition .= "&gt;<a href='{$urlNav1}' {$strBlank}>{$menuTitle}</a>";
    
    $kuMenuPosition[$menuId] = $strPosition;
}


$kuStrTextLink = '';
$kuStrImageLink = '';
$kuArrTextLink = array();
$kuArrImageLink = array();
$strSql = "select * from {$configTableHead}friendlink where status=1 and lang='{$kuWebsiteCurrLanguage}' order by sortnum asc;";
$arrLink = $dbInstance->getList($strSql);
foreach($arrLink as $item)
{
  if(1 == $item['friendlinktype'])
  {
    $kuStrTextLink .= "<li class='textlink link{$item[id]}'><a href=\"{$item[friendlinkurl]}\" title='{$item[friendlinkkeyword]}' target='_blank'><span>{$item[friendlinktitle]}</span></a></li>\n";
    array_push($kuArrTextLink, $item);
  }
  else
  {
    $kuStrImageLink .= "<li class='textlink link{$item[id]}'><a href=\"{$item[friendlinkurl]}\" title='{$item[friendlinkkeyword]}' target='_blank'><span><img src='{$item[friendlinklogo]}' alt='{$item[friendlinkkeyword]}' /></span></a></li>\n";
    array_push($kuArrImageLink, $item);
  }
}


$kuArrServerList = array();
$strSql = "select * from {$configTableHead}server where enable =1 and lang='{$kuWebsiteDefauleIndexLanguage}' order by sortnum asc;";
$result = $dbInstance->query($strSql);
while($row = $dbInstance->fetchArray($result))
{
  $kuArrServerList[] = $row;
}
?>