<?php require 'authentication_manager.php'; ?>
<?php
@set_time_limit(0);  //若配置为 0 则不限定最久时间

if (POWER != 5) {
  err('该命令必须以基本管理员身份登陆！请重登陆');
}

@ require 'readonly/function/write_file.php';

if ($_POST['act'] == 'close') {

  if ($_POST['act2'] == 'del') {
    if (!get_ide()) {
      err('商业版才能进行此项！请手动到网站根目录删除静态页文件（404.html和about_blank.html不要删除）');
    }
  } else {
    write_file('writable/set/set_html.php', '<?php
$web[\'html\'] = false;
?>');
    @unlink('index.html');

    //$id = gmdate('YmdHis', time() + (floatval($web['time_pos']) * 3600));
    //write_file('writable/require/browse_reload.txt', $id);
    err('已关闭静态。<br />
<br /><ul style="width:50%;text-align:left;">以首页为起始，再次进入各分类页面时为动态分类页面<br />对于用不到的静态页面的处理：<li>仍然保留</li><li><form action="?post=html" method="post" style="display:inline;"><input type="hidden" name="act" value="close" /><input type="hidden" name="act2" value="del" /><button type="submit" style=" letter-spacing:0; background:none; color:#667788;">我想全部删除它们</button></form></li></ul><br /><br />', 'ok');

  }


} else {

  @ require 'writable/set/set_area.php';

  $persistent = 1;

  chunk_echo('
<div style="background-color:#FF6600; color:#FFF;">正在'.(isset($SET_RELOAD)?'更新':'生成').'静态页面...</div>
<script>
timeS = setInterval(function(){document.getElementById("run_html").scrollTop = 150000;}, 100);
</script>
<p id="run_html" style="padding-left:40px; text-align:left; height:150px; overflow:auto;">
  <span class="grayword">首页 - index.html生成中...</span> ');

  $web['html'] = true;
  chunk_echo(reset_indexhtml('index.php', 'index.html') ? '成功<br />' : '失败<br /><br />');

  unset($_GET);

  $column_py = '';

  foreach ((array)$web['area'] as $column_id => $column) {
    //$column = (array)$column;
    $_GET['column_id'] = $column_id;
    $column_py = $column['name'][1];
    
    chunk_echo('<span class="grayword">频道<b>'.$column['name'][0].'</b> - '.$column_py.'.html生成中...</span> ');

    $web['html'] = true;
    chunk_echo(reset_indexhtml('column.php', $column_py.'.html') ? '成功<br />' : '失败<br />');

    $web['area'][$_GET['column_id']]['name'][0] = $column['name'][0];
    $web['area'][$_GET['column_id']]['name'][1] = $column['name'][1];
    unset($column['name']);
    foreach ($column as $class_id => $class) {
      $_GET['class_id'] = $class_id;
      chunk_echo('<span class="grayword">栏目<b>'.$class[0].'</b> - '.$column_py.'_'.$class[1].'.html生成中...</span> ');

      $web['html'] = true;
      chunk_echo(reset_indexhtml('class.php', $column_py.'_'.$class[1].'.html') ? '成功<br />' : '失败<br />');
    }
    //unset($_GET, $column_py);
  }

  //生成专题
  $priority_arr = array();
  if (!isset($sql['db_err'])) {
    $db = db_conn();
  }
  if ($sql['db_err'] == '') {

    db_query($db, "SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''))");
    $result = db_query($db, 'SELECT * FROM `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` WHERE detail_title<>"" AND http_name_style="" GROUP BY detail_title');// AND LENGTH(class_priority)>0
    if ($result != false) {
      while ($row = db_fetch($db, $result)) {
        //if (array_key_exists($row['column_id'], $web['area']) && array_key_exists($row['class_id'], $web['area'][$row['column_id']])) {
        if (isset($web['area'][$row['column_id']]) && isset($web['area'][$row['column_id']][$row['class_id']])) {
          $priority_arr[$row['column_id'].'_'.$row['class_id'].'_'.$row['detail_title']] = 1;
        }
        unset($row);
      }
    }
    $result = NULL;

  }/* else {
    $err .= $sql['db_err'];
  }*/
  db_close($db);

  unset($_GET);
  if (count($priority_arr) > 0) {
    chunk_echo('<br /><b>正在生成专题...</b><br />');

    foreach ($priority_arr as $priority_key => $priority_val) {
      list($_GET['column_id'], $_GET['class_id'], $detail_title) = @explode('_', $priority_key);
      list($_GET['detail_title'], $detail_py, ) = @explode('|', $detail_title);
      $web['html'] = true;
	  chunk_echo('<span class="grayword">专题<b>'.$_GET['detail_title'].'</b> - '.$detail_py.'.html生成中...</span>');
      chunk_echo(reset_indexhtml('detail.php', $detail_py.'.html') ? '成功<br />' : '失败<br />');
      unset($_GET, $detail_title ,$detail_py);
    }
  }

  write_file('writable/set/set_html.php', '<?php
$web[\'html\'] = true;
?>');

  chunk_echo('</p>

  <script>
  function scrollToBottom() {
    clearInterval(timeS);
    document.getElementById("run_html").scrollTop = 150000;
    //window.scrollTo(0, document.body.offsetHeight);
    location.href="#htmlend";
  }
  addEvent(window,\'load\',scrollToBottom)
  </script>');


  if (!isset($SET_RELOAD)) {
    alert('全站静态执行完毕。<br />
· 如果生成未完全成功，请<a href="javascript:location.reload();">刷新一下本页面</a>）<a name="htmlend" id="htmlend"></a>', 'webmaster_central.php?get=html');
  }
}






?>