<?php


/* 首页 - 分类信息风格模式 */
/* 162100源码 - 162100.com - download.162100.com */

$title = '首页';

$GLOBALS['this_mode'] = 'a';

$text_city = $city_sql = '';
$city_sql_pre = 'B.';
@ include ('inc/city/getcity.php');
if (file_exists('inc/css/'.$GLOBALS['this_mode'].'/city.php')) {

  @ include ('inc/css/'.$GLOBALS['this_mode'].'/city.php');
}

//自动获取图标背景
function get_area_logo($area_id) {
  static $step = 0;
  if (file_exists('inc/css/'.$GLOBALS['this_mode'].'/area_logo_'.$area_id.'.gif')) {
    return '<img src="inc/css/'.$GLOBALS['this_mode'].'/area_logo_'.$area_id.'.gif" width="40" height="40" />';
  } else {
    $bg = array_rand(array("Black" => "黑色", "Sienna" => "赭色", "DarkOliveGreen" => "暗橄榄绿色", "DarkGreen" => "暗绿色", "DarkSlateBlue" => "暗灰蓝色", "Navy" => "海军色", "Indigo" => "靛青色", "DarkSlateGray" => "墨绿色", "DarkRed" => "暗红色", "DarkOrange" => "暗桔黄色", "Olive" => "橄榄色", "Green" => "绿色", "Teal" => "水鸭色", "Blue" => "蓝色", "SlateGray" => "灰石色", "DimGray" => "暗灰色", "Red" => "红色", "SandyBrown" => "沙褐色", "YellowGreen" => "黄绿色", "SeaGreen" => "海绿色", "MediumTurquoise" => "间绿宝石", "RoyalBlue" => "皇家蓝", "Purple" => "紫色", "Gray" => "灰色", "Magenta" => "红紫色", "Orange" => "橙色", "Yellow" => "黄色", "Lime" => "酸橙色", "Cyan" => "青色", "DeepSkyBlue" => "深天蓝色", "DarkOrchid" => "暗紫色", "Silver" => "银色", "Pink" => "粉色", "Wheat" => "浅黄色", "PaleGreen" => "苍绿色", "PaleTurquoise" => "苍宝石绿", "LightBlue" => "亮蓝色", "Plum" => "洋李色"));
    $step++;
    return '<span class="area_logo_mark" style="background-color:'.$bg.';">'.$step.'</span>';
  }
}

//处理伪静态
if ($web['url_html_list'] == 1) {
  $list_         = 'list.'.$GLOBALS['this_mode'].'...1.html';
  $list_url_area = '"list.'.$GLOBALS['this_mode'].'.".$row["area_id"]."..1.html"';
} else {
  $list_         = 'list.php?mode='.$GLOBALS['this_mode'].'';
  $list_url_area = '"list.php?mode='.$GLOBALS['this_mode'].'&area_id=".$row["area_id"].""';
}
if ($web['url_html_article'] == 1) {
  $article_url   = '"article.'.$GLOBALS['this_mode'].'.".$row["id"].".1.html"';
} else {
  $article_url   = '"article.php?mode='.$GLOBALS['this_mode'].'&id=".$row["id"].""';
}

$n = $mess = $c = $reply = $member = 0;
$area = $area_root = $area_second = $area_statistics = $area_name = $area_style = $total = $today = $thumb_area = array();
$date = gmdate('md', time() + (floatval($web['time_pos']) * 3600));
$text = '';


if (!isset($sql['db_err'])) {
  db_conn();
}

if ($sql['db_err'] != '') {
  die($sql['db_err']);
}


//取该模板所分配的分类

$result = @mysql_query('SELECT * FROM '.$sql['pref'].''.$sql['data']['承载版区分类的表名'].' WHERE area_id REGEXP "^[0-9]+\-[0-9]+$" AND area_index LIKE "%'.$GLOBALS['this_mode'].'%"', $db);
if (@mysql_num_rows($result) > 0) {
  while ($row = @mysql_fetch_assoc($result)) {
    $area_id_root = $row['area_id'];
    $area_root[$area_id_root] = 1;
    $area_sql_forlistdata[abs($area_id_root)] = 1;
    //$mark[$area_id_root] = $row['area_mark'];
    $area_name[$area_id_root] = $row['area_name'];
    $area_style[$area_id_root] = $row['area_style'];
    $area_description[$area_id_root] = $row['area_description'];
    $total[$area_id_root] = $row['area_total'];
    if (substr($row['area_today'], 0, 4) == $date) {
      $today[$area_id_root] = substr($row['area_today'], 4);
    } else {
      $today[$area_id_root] = 0;
    }
    $result_statistics = @mysql_query('SELECT COUNT(id) AS n FROM '.$sql['pref'].''.$sql['data']['承载版区分类的表名'].' WHERE (area_id LIKE "'.$area_id_root.'\_%") ', $db);
    $row_statistics = @mysql_fetch_assoc($result_statistics);
    $area_statistics[$area_id_root] = $row_statistics['n'] + 1;
    @mysql_free_result($result_statistics);
  }
}
@mysql_free_result($result);

$tongyoung_sql = ' (B.area_id LIKE "'.@implode('-%" OR B.area_id LIKE "', array_keys($area_sql_forlistdata)).'-%") ';

$result = @mysql_query('SELECT area_id,area_name,area_style FROM '.$sql['pref'].''.$sql['data']['承载版区分类的表名'].' WHERE (area_id REGEXP "^('.@implode('|', array_keys($area_sql_forlistdata)).')-[0-9]+_[0-9]+$") ', $db);
//if (@mysql_num_rows($result) > 0) {
  while ($row = @mysql_fetch_assoc($result)) {
    $area_id_root = get_arearoot($row['area_id']);
    $area[$area_id_root][substr($row['area_id'],strlen($area_id_root)+1)] = '<a href="'.eval('return '.$list_url_area.';').'"'.$row['area_style'].'>'.$row['area_name'].'</a>';
    $area_second[$area_id_root] ++;
    unset($row, $area_id_root);
  }
  @mysql_free_result($result);

  //取首页图文推荐
  $result = @mysql_query('SELECT A.title AS thumb,A.id AS i,A.date,B.id,B.area_id,B.title,B.text FROM '.$sql['pref'].''.$sql['data']['承载上传数据的表名'].' A,'.$sql['pref'].''.$sql['data']['承载主题文章的表名'].' B WHERE A.title LIKE "thumb-%" AND B.id=ABS(SUBSTRING(A.title,7)) AND '.$tongyoung_sql.''.$city_sql.'', $db); //
  //$result = @mysql_query('SELECT A.title AS thumb,B.id,B.area_id,B.title,B.text FROM '.$sql['pref'].''.$sql['data']['承载上传数据的表名'].' A,'.$sql['pref'].''.$sql['data']['承载主题文章的表名'].' B WHERE A.title LIKE "thumb-%" AND A.title=CONCAT("thumb-",B.id,".jpg") AND '.$tongyoung_sql.''.$city_sql.'', $db); //
  if (@mysql_num_rows($result) > 0) {
    $datetime = gmdate("Y-m-d H:i:s", time() + (floatval($web["time_pos"]) * 3600));
    while ($row = @mysql_fetch_assoc($result)) {
      if ($row['date'] > $datetime) {
        $area_id_root = get_arearoot($row['area_id']);
        $thumb_area[$area_id_root] .= get_e($row);
      } else {
        @mysql_query('DELETE FROM '.$sql['pref'].''.$sql['data']['承载上传数据的表名'].' WHERE id="'.$row['i'].'"', $db);
      }
      unset($row, $area_id_root);
    }
  }
  @mysql_free_result($result);
  @uksort($area_root, 'strnatcmp');

  if (count($area_root) > 0) {
  foreach (array_keys($area_root) as $area_id_root) {
    $row['area_id'] = $area_id_root;
    @ksort($area[$area_id_root]);

    $text .= '<div class="area"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="area__">
    <tr valign="top">
      <td class="area_logo"><a href="'.eval('return '.$list_url_area.';').'">'.get_area_logo($area_id_root).'</a></td>
      <td style="position:relative;"><span class="area_name"><a href="'.eval('return '.$list_url_area.';').'"'.($area_description[$area_id_root]?' title="'.$area_description[$area_id_root].'"':'').''.$area_style[$area_id_root].'>'.$area_name[$area_id_root].'</a></span><br />
        <span class="area___">文章数（<a title="今日文章" class="hand'.($today[$area_id_root]>0?' redword" href="'.eval('return '.$list_url_area.';').'&list_type=today"':'"').'>'.$today[$area_id_root].'</a>/<a title="文章总计" class="hand"'.($total[$area_id_root]>0?' href="'.eval('return '.$list_url_area.';').'&list_type=total"':'').'>'.$total[$area_id_root].'</a>） 分类数（<span class="hand" title="二级分类">'.$area_second[$area_id_root].'</span>/<span class="hand" title="全部分类">'.$area_statistics[$area_id_root].'</span>）</span>
<button title="发表" type="button" class="large" onclick="window.open(\'write.php?mode='.$GLOBALS['this_mode'].'&area_id='.$area_id_root.'\',\'_blank\');"><b><div class="send_write"></div></b></button><img class="eli" src="inc/css/'.$GLOBALS['this_mode'].'/eli.gif" /> 
        </td>
    </tr>
  </table>'.(isset($thumb_area[$area_id_root]) ? $thumb_area[$area_id_root] : '').'
  <div class="area_li">'.@implode(' ', $area[$area_id_root]).'</div></div>';
    $option[$area_id_root] = '<option value="'.$area_id_root.'">'.$area_name[$area_id_root].'</option>';
    unset($row, $area_id_root);
  }

  } else {
  $text .= '没有栏目分类！';
  }

  //阅读排行 10条
  $count = 10;
  $text_readrank = '<div class="title">阅读排行</div>';
  $result = @mysql_query('SELECT B.id,B.title,B.city,B.area_id,C.area_name FROM `'.$sql['pref'].''.$sql['data']['承载主题文章的表名'].'` B LEFT JOIN `'.$sql['pref'].''.$sql['data']['承载版区分类的表名'].'` C ON B.area_id=C.area_id WHERE '.$tongyoung_sql.' AND B.area_check="" ORDER BY B.views DESC LIMIT '.$count.'', $db);
  if (@mysql_num_rows($result) > 0) {
    $step_readrank = 0;
    while ($row = @mysql_fetch_assoc($result)) {
      $step_readrank++;
      $text_readrank .= '<b style="color:'.($step_readrank <= 3 ? '#FF9900;' : '#9999FF;').';">'.$step_readrank.'.</b> <a href="'.eval('return '.$article_url.';').'" title="来自：['.$row['area_name'].' '.$row['city'].']" target="_blank">'.cutstr($row['title'], 40).'</a><br />';
      unset($row);
    }
  } else {
    $text_readrank .= '记录为空';
  }
  @mysql_free_result($result);
  //最新发表 10 条
  $count = 10;
  $text_top = '<div class="title"><a href="'.$list_.'" class="more">更多&gt;&gt;</a>最新发表</div>';
  $result = @mysql_query('SELECT B.id,B.title,B.city,B.area_id,C.area_name FROM `'.$sql['pref'].''.$sql['data']['承载主题文章的表名'].'` B LEFT JOIN `'.$sql['pref'].''.$sql['data']['承载版区分类的表名'].'` C ON B.area_id=C.area_id WHERE '.$tongyoung_sql.' AND B.area_check="" ORDER BY B.id DESC LIMIT '.$count.'', $db);
  if (@mysql_num_rows($result) > 0) {
    while ($row = @mysql_fetch_assoc($result)) {
      $text_top .= '<a href="'.eval('return '.$article_url.';').'" title="来自：['.$row['area_name'].' '.$row['city'].']" target="_blank">'.cutstr($row['title'], 40).'</a><br />';
      unset($row);
    }
  } else {
    $text_top .= '记录为空';
  }
  @mysql_free_result($result);

  //评论数
  $result = @mysql_query('SELECT COUNT(A.id) AS n FROM
'.$sql['pref'].''.$sql['data']['承载回复评论的表名'].' A
LEFT JOIN
'.$sql['pref'].''.$sql['data']['承载主题文章的表名'].' B
ON A.r_id=B.id WHERE '.$tongyoung_sql.'
', $db);
  $row = @mysql_fetch_assoc($result);
  $reply = abs($row['n']);
  unset($row);
  @mysql_free_result($result);
//}
//@ksort($option);

function get_e($row) {
  global $article_url;
  return '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="e_list" title="首页图文推荐">
  <tr valign="top">
    <td width="130"><div class="e_thumb"><a href="'.eval('return '.$article_url.';').'" target="_blank"><img src="obj.php?title='.$row['thumb'].'" /></a></div></td>
    <td><h6><a href="'.eval('return '.$article_url.';').'" target="_blank">'.$row['title'].'</a></h6><div class="e_text">'.cutstr(strip_tags($row['text']), 150).'</div></td>
  </tr>
</table>';
}



//成员数
$result = @mysql_query('SELECT COUNT(id) AS n FROM '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].'', $db);
$row = @mysql_fetch_assoc($result);
$member = abs($row['n']);
unset($row);
@mysql_free_result($result);
//新成员
$result = @mysql_query('SELECT username,regdate FROM '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' ORDER BY id DESC LIMIT 1', $db);
$row = @mysql_fetch_assoc($result);
$member_new = $row['username'];
$member_regdate = substr($row['regdate'], 0, 16);
unset($row);
@mysql_free_result($result);
//取短信
if (POWER >= 1) {
  $result = @mysql_query('SELECT mess_num FROM `'.$sql['pref'].''.$sql['data']['承载成员档案的表名'].'` WHERE username="'.$session[0].'" LIMIT 1', $db); //短信
  $row = @mysql_fetch_assoc($result);
  $mess = '<span class="area_statistics">'.preg_replace('/^\d+/', '<span>$0</span>', $row['mess_num']).'</span>';
  @mysql_free_result($result);
  unset($row);
}
@ require ('inc/function/add_online.php'); //在线
//总数
$result = mysql_query('SELECT COUNT(id) AS total FROM '.$sql['pref'].''.$sql['data']['承载在线统计的表名'].'',$db);
$row = @mysql_fetch_assoc($result);
$n_online = abs($row['total']);
@mysql_free_result($result);
unset($row);

$n_online_member = 0;
$text_online .= '';
$result = mysql_query('SELECT * FROM `'.$sql['pref'].''.$sql['data']['承载在线统计的表名'].'` WHERE memberye>0 ORDER BY memberye DESC,utime DESC', $db);
while ($row = @mysql_fetch_assoc($result)) {
  $n_online_member++;
  $text_online .= '<a href="user.php?get=card&username='.urlencode($row['username']).'" target="_blank">'.$row['username'].' '.$row['userface'].'</a>　'; //$row['userface']
}
@mysql_free_result($result);
unset($row);


@mysql_close();
@ksort($option);

?><!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 $web['sitename'], $web['code_author'];
?></title>
<meta name="Description" content="<?php echo $web['description']; ?>" />
<meta name="keywords" content="<?php echo $web['keywords']; ?>" />
<link id="my_style" rel="stylesheet" type="text/css" href="inc/css/<?php echo $GLOBALS['this_mode']; ?>/style.css">
<script language="javascript" src="inc/js/main.js" type="text/javascript"></script>
</head>
<body>
<div id="session" class="session"><div id="city"><?php
echo $text_city;
?></div><?php $power_text .= '<style> .session_in .login_key { display:inline; } </style>';
@ include ('inc/require/head.txt'); ?></div>
<?php
if ($web['siteclose'] > 0) {
  if ($web['siteclose'] == 1) {
    $ann_e = 'include ("inc/require/siteclose_why.txt")';
  } else {
    @include ('inc/require/siteclose_why.txt');
  }
}
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" id="logo">
  <tr>
    <td width="200"><img src="<?php echo $web['sitelogo']; ?>" /></td>
    <td width="500" align="center"><form action="search.php?action=search" method="get" style="position:relative; text-align:right;" target="_blank" onsubmit="return ($('keyword').value!=''&&$('keyword').value!='关键词')||false;">
      <input style="width:400px; padding-left:5px; font-size:14px; color:#999999;" type="text" id="keyword" name="keyword" class="large" onfocus="if(this.value=='关键词'){this.value=''}" onkeydown="if(event.keyCode==13&&this.value!=''){this.form.submit();}" value="关键词" />
      <select name="area_id" style="position:absolute; top:7px; right:52px;">
        <option value="all">所有类目</option>
        <?php echo @implode('', $option); ?>
      </select>
      <button class="large" type="submit" id="submit" name="submit"><b>搜索</b></button>
      <input type="hidden" name="action" value="search" />
    </form></td>
    <td align="right"><button type="button" onclick="location.href='write.php?mode=<?php echo $GLOBALS['this_mode']; ?>'" class="large"><b>
      <div class="send_write">免费发布文章</div>
      </b></button>
      <a href="member.php?get=list" class="send2">修改删除文章</a></td>
  </tr>
</table>
<div id="banner"> <a class="column_is">首页</a> <a href="list_company.php">商号</a> <a href="list_member.php">成员</a> <a href="list_online.php">在线</a> <a href="help.php">帮助</a>
    <?php @include ('inc/css/'.$GLOBALS['this_mode'].'/banner.txt'); ?>
</div>
<div class="column">
  <h5><a href="rss.php?mode=<?php echo $GLOBALS['this_mode']; ?>" class="dingyue" title="订阅">&nbsp;<img src="inc/images/rss.gif" width="14" height="14" /></a> <a href="<?php echo $list_; ?>" class="dingyue">全部文章</a><?php echo $web['description']; ?>——<?php echo @file_get_contents('inc/css/'.$GLOBALS['this_mode'].'/title2.txt'); ?></h5>

  <div class="column_in"> 文章（<a title="今日"<?php echo array_sum($today)>0?' class="hand redword" href="'.$list_.'&list_type=today"':' class="hand"'; ?>><?php echo array_sum($today); ?></a>/<a href="<?php echo $list_; ?>&list_type=total"><?php echo array_sum($total); ?></a>） 评论（<span class="hand"><?php echo $reply; ?></span>） 成员（<a href="list_member.php" target="_blank"><?php echo $member; ?></a>） 新成员（<a href="user.php?get=card&username=<?php echo urlencode($member_new); ?>" target="_blank"><?php echo $member_new; ?></a> <?php echo $member_regdate; ?>）
    <?php eval('return '.$ann_e.';'); ?>
  </div>
</div>
<?php @include ('inc/css/'.$GLOBALS['this_mode'].'/ad_index_top.txt'); ?>
<table border="0" cellpadding="0" cellspacing="0" class="body">
  <tr valign="top">
  <td class="left"><div class="left_">
    <div id="wrap"><?php echo !empty($text) ? $text : '<div class="text_err">栏目为空</div>';?></div></div>
  </td>
  <td class="right">
    <div class="side">
      <?php
echo $text_readrank;
unset($text_readrank);
?>
    </div>
    <div class="side">
      <?php
echo $text_top;
unset($text_top);
?>
    </div>
    <?php @include ('inc/require/company_update.txt'); ?>
    <div class="hot">
      <div class="title">热门标签</div>
      <?php
      @include ('inc/require/hot_mark.txt');
	  ?>
    </div>
    <div class="ad_side"><?php @include ('inc/css/'.$GLOBALS['this_mode'].'/ad_index_side.txt'); ?></div>
  </td>
  </tr>
</table>
<div class="online"> <a class="greenword"><b>站内在线</b></a>
    <?php echo $text_online; ?> <?php echo $n_online - $n_online_member > 0 ? '<a href="list_online.php?act=guest" class="grayword" target="_blank">'.($n_online - $n_online_member).'位访客…</a>' : ''; ?> </div>


<div class="friend_link"> <a class="greenword"><b>常用工具</b></a>
    <?php @include ('inc/css/'.$GLOBALS['this_mode'].'/tools.txt'); ?>
</div>

<div class="friend_link"> <a class="greenword"><b>友情链接</b></a>
    <?php @include ('inc/css/'.$GLOBALS['this_mode'].'/friendlink.txt'); ?>
</div>

<?php @include ('inc/css/'.$GLOBALS['this_mode'].'/ad_index_bottom.txt'); ?>

<div id="foot">
  <?php @include ('inc/css/'.$GLOBALS['this_mode'].'/foot.txt'); ?>
  <a style="COLOR: #666666" href="http://www.miibeian.gov.cn/" target="_blank"><?php @include ('inc/require/icp.txt'); ?></a>
</div>
<script language="JavaScript" type="text/javascript">
<!--
try{$('new_mess').innerHTML='<?php echo $mess; ?>';}catch(err){}
-->
</script>
<script type="text/javascript">
function Sort(wrap) {
  var n = 2; //列数。必须大于0的整数
  var columnW = wrap.offsetWidth/n; //列宽
  var icolumnT = [];
  for (var k = 0; k < n; k++) {
    icolumnT[k] = 0;
  }
  var minHK;
  var box = wrap.childNodes;
  if (box.length > 0) {
    for(var i = 0; i < box.length; i++) {
	  if (box[i].nodeType == 1) {
		minHK = MK(icolumnT);
		icolumnT[minHK[0]] = minHK[1];
        box[i].style.position = 'absolute';
        box[i].style.top = icolumnT[minHK[0]] + 'px';
        box[i].style.left = (minHK[0] * columnW) + 'px';
        icolumnT[minHK[0]] += box[i].offsetHeight;
	  }
	}
    wrap.style.height = (Math.max.apply({},icolumnT))+'px';
  }
};

function MK(arr) {
  var minArr;
  var minV = arr[0];
  minArr = new Array(0, minV);
  for(var i=1; i<arr.length; i++) {
    if (arr[i] < minV) {
	  minV = arr[i];
	  minArr = new Array(i, arr[i]);
	}
  }
  return minArr;
}



window.onload = function() {
  Sort($("wrap"));
};
</script>

</body>
</html>