<?php

/* 频道 - 即大类 */

$self = 'column.php';

@ require 'writable/set/set.php';
if (!isset($sql)) {
  @ require 'writable/set/set_sql.php';
}
if (!isset($web['area'])) {
  @ require 'writable/set/set_area.php';
}
if (!isset($web['html'])) {
  @ require 'writable/set/set_html.php';
}


$text = $lazyload_note1 = $lazyload_note2 = '';
$tcolor = 0;
$array_color = array('red', 'orange', 'green', 'blue');
$list_class_title = '<a id="class_is" href="javascript:void(0);" onclick="showListClass(this,null);return false;"><b>全部</b></a>';
//惰性加载，元素数组
$lazyload = array();
if (file_exists('writable/js/lazyload.js')) {
  $lazyload_note1 = '<!--';
  $lazyload_note2 = '-->';
  $lazyload_note3 = 1;
}

if (isset($_GET['column_id'])) {
  @ $_GET['column_id'] = preg_replace('/[^\w]/', '', $_GET['column_id']);

  //if (!array_key_exists($_GET['column_id'], $web['area'])) {
  if (!isset($web['area'][$_GET['column_id']])) {
    die('&#20998;&#31867;&#73;&#68;&#38169;&#35823;&#25110;&#32570;&#22833;&#65281;&#35831;&#37325;<a href="./">&#39318;&#39029;</a>&#37325;&#26032;&#24320;&#22987;');
  }
/*
//转向静态页
if ($web['html'] == true && file_exists($web['area'][$_GET['column_id']]['name'][1].'.html')) {
  header('Location: '.$web['area'][$_GET['column_id']]['name'][1].'.html');
}
*/

  $title = $web['area'][$_GET['column_id']]['name'][0];
  $cssmark = $mark = 0;
  if (!isset($sql['db_err'])) {
    $db = db_conn();
  }
  if ($sql['db_err'] == '') {
    //$column_py = $web['area'][$_GET['column_id']]['name'][1];
    //unset($web['area'][$_GET['column_id']]['name']);
    foreach ($web['area'][$_GET['column_id']] as $class_id => $class) {
      if ($class_id === 'name') continue;
	  $cssmark++;
      $tcolor_key = $array_color[($tcolor + 4) % 4].'word';
      $tcolor ++;
      $column_title = get_class_html($_GET['column_id'], $class_id);
      $list_class_title .= '<a href="javascript:void(0);" onclick="showListClass(this,'.$cssmark.');return false;"'.(is_numeric($class[2])&&$class[2]>=1&&$class[2]<=9?' class="qd'.$class[2].'"':'').'>'.$class[0].'</a>';


      $lazyload[] = 'column_'.$cssmark.'';

	  $text .= '
      <div class="column" id="column_'.$cssmark.'"'.($cssmark==1?' style="margin-top:0;"':'').'><input type="hidden" name="column[]">
      '.$lazyload_note1.'
        <div class="column_title"><a onmouseover="addC(this)" onclick="addM(this)" href="'.$column_title.'" class="tcolor '.$tcolor_key.'">'.$class[0].'</a></div>';
      $result = db_query($db, 'SELECT * FROM `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` WHERE column_id="'.$_GET['column_id'].'" AND class_id="'.$class_id.'" AND detail_title="" ORDER BY id'); // AND class_title NOT LIKE "栏目置顶%"

      if ($result != false) {
        $_text = $text_ = '';
        $text .= '<div class="class">';
        while ($row = db_fetch($db, $result)) {
	      $mark++;
          list($class_title, , ) = @explode('|', $row['class_title']);
          if (trim($row['http_name_style']) == '') {
            $_text = '<div class="yingyong"><span><a href="'.$column_title.'#priority">栏目头栏</a></span></div>';
          } else {
            $n = count(@explode("\n", trim($row['http_name_style'])));
            $text_ .= '<span class="class_w_4"><a onmouseover="addC(this)" onclick="addM(this)" href="'.$column_title.'#class_title_'.$mark.'">'.$class_title.' <font style="color:#BBBBBB;">('.$n.')</font></a></span>';
          }
          unset($row, $n);
        }
        $text .= $_text.$text_;
	    $mark = 0;
        $text .= '</div>';
      } else {
        //$text .= $_GET['column_id'].' - '.$class_id.' 的数据为空或读取失败！';
      }
      $result = NULL;

      $text .= '
      
      '.$lazyload_note2.'</div>
';
      $text .= isset($lazyload_note3) ? '
<script>
<!--
  lazyloadObj = oIdFilter(\'column_'.$cssmark.'\');
-->
</script>' : '';
    }
  } else {
    $err = $sql['db_err'];
  }
  db_close($db);

} else {
  $title = '网站地图';
  $cssmark = 0;
  foreach ((array)$web['area'] as $column_id => $column) {
    $cssmark++;
    $tcolor_key = $array_color[($tcolor + 4) % 4].'word';
    $tcolor ++;
    $column = (array)$column;
    $list_class_title .= '<a href="javascript:void(0);" onclick="showListClass(this,'.$cssmark.');return false;">'.$column['name'][0].'</a>';
    $lazyload[] = 'column_'.$cssmark.'';
    $text .= '
  <div class="column" id="column_'.$cssmark.'"'.($cssmark==1?' style="margin-top:0;"':'').'><input type="hidden" name="column[]">
  '.$lazyload_note1.'
  
  <div class="column_title"><a onmouseover="addC(this)" onclick="addM(this)" href="'.get_column_html($column_id).'" class="tcolor '.$tcolor_key.'">'.$column['name'][0].'</a></div>
  <div class="class">';
    unset($column['name']);
    foreach ($column as $class_id => $class) {
      $text .= '<span class="class_w_4'.(is_numeric($class[2])&&$class[2]>=1&&$class[2]<=9?' qd'.$class[2].'':'').'"><a onmouseover="addC(this)" onclick="addM(this)" href="'.get_class_html($column_id, $class_id).'">'.$class[0].'</a></span>';
    }
    $text .= '
  </div>
  '.$lazyload_note2.'</div>
';
    $text .= isset($lazyload_note3) ? '
<script>
<!--
  lazyloadObj = oIdFilter(\'column_'.$cssmark.'\');
-->
</script>' : '';
  }
}

unset($lazyload_note1, $lazyload_note2, $lazyload_note3);

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?PHP echo $title.' - '.$web['sitename2'], $web['code_author']; ?></title>
<base target="_blank" />
<?php echo $web['slogan']; ?>
<link href="writable/css/style.css?<?php echo filemtime('writable/css/style.css'); ?>" rel="stylesheet" type="text/css" />
<link href="readonly/css/style.css?<?php echo filemtime('readonly/css/style.css'); ?>" rel="stylesheet" type="text/css" />
<link href="readonly/css/<?php echo $web['cssfile']; ?>/style.css?<?php echo filemtime('readonly/css/'.$web['cssfile'].'/style.css'); ?>" rel="stylesheet" type="text/css" title="<?php @ include 'writable/require/browse_reload.txt'; ?>" id="my_style" />
<script type="text/javascript" language="javascript" src="writable/js/main.js?<?php echo filemtime('writable/js/main.js'); ?>"></script>
<script type="text/javascript" language="javaScript">
<!--
function showListClass(o, sid) {
  if (o != null) {
    var o_old = $('class_is');
    if (o_old != null) {
      o_old.id = ''
    }
    o.id = 'class_is'
  }
  var allCheckBox = document.getElementsByName('column[]');
  if (allCheckBox != null && allCheckBox.length > 0) {
    if (sid == null) {
      for (var i = 1; i <= allCheckBox.length; i++) {
        if ($('column_' + i + '') != null) {
          $('column_' + i + '').style.display = 'block'
          $('column_' + i + '').innerHTML = $('column_' + i + '').innerHTML.replace(/<\!\-\-|\-\->/g, '');
          if (typeof Sort == "function") {
            Sort($('column_' + i + ''))
          }
        }
      }
    } else {
      for (var i = 1; i <= allCheckBox.length; i++) {
        if (i == sid) continue;
        if ($('column_' + i + '') != null) {
          $('column_' + i + '').style.display = 'none'
        }
      }
      if ($('column_' + sid + '') != null) {
        $('column_' + sid + '').style.display = 'block'
        $('column_' + sid + '').innerHTML = $('column_' + sid + '').innerHTML.replace(/<\!\-\-|\-\->/g, '');
        if (typeof Sort == "function") {
          Sort($('column_' + sid + ''))
        }
      }
    }
  }
}
-->
</script>
</head>
<body>

<?php @ include 'writable/require/notice.txt'; ?>
<?php @ include 'readonly/require/head.php'; ?>
<div id="top_title"><a href="./write_newsite.php" class="top_title_other">网站加入</a><a href="./member.php?get=collection" class="top_title_other">自定义网址</a><a href="./">首页</a><a id="top_title_is"><?php echo $title; ?></a></div>

<img src="readonly/images/star.gif" id="star" style="display:none" title="加入收藏" />
<iframe id="addPFrame" name="addPFrame" style="display:none"></iframe>
<?php
if (file_exists('writable/js/lazyload.js')) {
  echo '
<script type="text/javascript" language="javascript">
<!--
var lazyloadObj = \''.@implode(',', $lazyload).'\';

function oIdFilter(oThisId) {
  var oThis = $(oThisId);
  if (oThis != null) {
    var oT = oThis.getBoundingClientRect().top - screenT;
    if (oT < screenH) {
      oThis.innerHTML = oThis.innerHTML.replace(/<\!\-\-|\-\->/g, "");
      lazyloadObj = lazyloadObj.replace(new RegExp("\,*"+oThisId+"\,*", "i"), ",").replace(/^\,+|\,+$/, "");
    }
  }
  oThis = null;
  return lazyloadObj;
}
-->
</script>';
}
?>

<div class="body"><div id="list_class"><?php echo $list_class_title; ?></div></div><div class="body">
  <?php echo $text, $err; ?>
</div>
<?php
if (file_exists('writable/chuchuang/ad_bottom.txt')) {
  @ include 'writable/chuchuang/ad_bottom.txt';
}
?>
<?php @ include 'writable/require/foot.php'; ?>
<?php @ include 'writable/require/statistics.txt'; ?>

</body>
<?php
if (file_exists('writable/js/lazyload.js')) {
  echo '
<script type="text/javascript" language="javascript" src="writable/js/lazyload.js"></script>';
}
?>
</html>
