<?php


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

$title = '首页';

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

$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="24" height="24" />';
  } 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="width:24px; height:24px; line-height:24px; font-size:24px; background-color:'.$bg.';">'.$step.'</span>';
  }
}

function get_e($row) {
  global $article_url;
  return '
<div class="e_list" title="首页图文推荐">
  <div class="e_text">
    <span class="e_thumb"><a href="'.eval('return '.$article_url.';').'" target="_blank"><img src="obj.php?title='.$row['thumb'].'" /></a></span>
    <h6><a href="'.eval('return '.$article_url.';').'" target="_blank">'.$row['title'].'</a></h6>
    '.cutstr(strip_tags($row['text']), 150).'
  </div>
</div>';
}

//处理伪静态
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_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;
    }
  }
}
@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>';
    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); //
  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">
  <div class="area__">
    <div class="area_title" style="position:relative;"><span class="area_logo"><a href="'.eval('return '.$list_url_area.';').'">'.get_area_logo($area_id_root).'</a></span>
      <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><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>
      <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>
    </div>
    <div class="area_li">'.(isset($thumb_area[$area_id_root]) ? $thumb_area[$area_id_root] : '').''.@implode(' ', $area[$area_id_root]).'</div>
  </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="side"><div class="title">点击排行</div><ul class="text">';
  $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 .= '<li><b style="color:'.($step_readrank <= 3 ? '#FF9900;' : '#9999FF;').';">'.$step_readrank.'.</b> <a href="'.eval('return '.$article_url.';').'" title="'.$row['title'].'" target="_blank">'.cutstr($row['title'], 45).'</a> <span class="ar">[<a href="'.eval('return '.$list_url_area.';').'">'.$row['area_name'].'</a> '.$row['city'].']</span></li>';
      unset($row);
    }
  } else {
    $text_readrank .= '没有记录';
  }
  $text_readrank .= '</ul></div>';
  @mysql_free_result($result);

  //点评排行 10条
  $count = 10;
  $text_reply = '<div class="side"><div class="title">点评排行</div><ul class="text">';
  $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.topdate DESC LIMIT '.$count.'', $db);
  if (@mysql_num_rows($result) > 0) {
    $step_readrank = 0;
    while ($row = @mysql_fetch_assoc($result)) {
      $step_readrank++;
      $text_reply .= '<li><b style="color:'.($step_readrank <= 3 ? '#FF9900;' : '#9999FF;').';">'.$step_readrank.'.</b> <a href="'.eval('return '.$article_url.';').'" title="'.$row['title'].'" target="_blank">'.cutstr($row['title'], 45).'</a> <span class="ar">[<a href="'.eval('return '.$list_url_area.';').'">'.$row['area_name'].'</a> '.$row['city'].']</span></li>';
      unset($row);
    }
  } else {
    $text_reply .= '没有记录';
  }
  $text_reply .= '</ul></div>';
  @mysql_free_result($result);

//}
//@ksort($option);

//取短信
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'); //在线

@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">
<style type="text/css">
<!--
body { width:1200px; }
-->
</style>
<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><div id="description"><?php echo $web['description']; ?>——<?php echo @file_get_contents('inc/css/'.$GLOBALS['this_mode'].'/title2.txt'); ?></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');
  }
}
?>
    <?php eval('return '.$ann_e.';'); ?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" id="logo">
  <tr>
    <td width="300"><img src="<?php echo $web['sitelogo']; ?>" /></td>
    <td width="600"><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:525px; 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:8px; 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>
<?php @include ('inc/css/'.$GLOBALS['this_mode'].'/ad_index_top.txt'); ?>
<div class="body">
  <div class="left_">
    <div id="wrap"><?php echo !empty($text) ? $text : '<div class="text_err">栏目为空</div>';?></div>
  </div>
</div>


<div class="body">
  <table width="100%" border="0" cellspacing="0" cellpadding="0" id="bottom">
    <tr valign="top">
      <td width="375" style="border-right:1px #DDDDDD solid;"><?php echo $text_readrank; unset($text_readrank); ?></td>
      <td width="375" style="border-right:1px #DDDDDD solid;"><?php echo $text_reply; unset($text_reply); ?></td>
      <td><?php @include ('inc/require/company_update.txt'); ?></td>
      <td width="220"><div class="hot">
        <div class="title">热门标签</div><div class="text">
        <?php @include ('inc/require/hot_mark.txt'); ?></div>
      </div></td>
    </tr>
  </table>
</div>

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

<div class="friend_link"> <a><b class="greenword">友情链接</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 = 4; //列数。必须大于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>
