<?php
require ('authentication_manager.php');
?>
<?php

/* 栏目类别设置 */
/* 162100源码 - 162100.com */


if (POWER != 5) {
  err('<script>alert("该命令必须以基本管理员身份登陆！请重登陆。"); parent.delSubmitSafe(); </script>');
}

$_GET['area_id'] = (string)$_GET['area_id'];

if (!$_GET['area_id']) {
  $_GET['area_id'] = (string)$_POST['area_id'];
}

if (!empty($_GET['area_id'])) {
  $area_id_root = get_arearoot($_GET['area_id']);

  if (!preg_match('/^(root\_\d+\-)|(\d+\-\d+(\_\d+)*)$/i', $_GET['area_id'])) {
    err('<script>alert("分类参数'.$_GET['area_id'].'不合法！应该诸如（数字-数字_数字_数字...）"); parent.delSubmitSafe(); </script>');
  }
}
@ require ('inc/function/area_statistics.php');

if (!isset($sql['db_err'])) {
  db_conn();
}
if ($sql['db_err'] != '') {
  err('<script>alert("'.$sql['db_err'].'"); location="forsql.html";</script>');
}

function confirm_mode($m) {
  global $web;
  //$m = str_replace('/', '', $m);
  if ($m && file_exists('inc/css/'.$m.'/index.php') && file_exists('inc/css/'.$m.'/list.php') && file_exists('inc/css/'.$m.'/article.php')) {
    return $m;
  }
  //return $web['sitemode'];
  return false;
}

//列表模式
if ($_GET['act'] == 'area_mode') {
  if ($_POST['area_mode'] == '1' || $_POST['area_mode'] == '2' || $_POST['area_mode'] == '3') {
    $to_ = $_POST['area_mode'];
  } else {
    $to_ = '0';
  }
  @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载版区分类的表名'].' SET area_mode="'.$to_.'" WHERE area_id="'.$area_id_root.'"', $db);
  err('<script> alert("执行'.(@mysql_affected_rows() > 0 ? '成功！' : '不成功！\n（'.mysql_errno().':'.mysql_error().'）').'"); parent.delSubmitSafe(); </script>');


} elseif ($_GET['act'] == 'upd') {
  if (!confirm_mode($_GET['mode'])) { 
    err('<script> alert("模板出错！"); parent.delSubmitSafe(); </script>');
  }
  if (file_exists('inc/css/'.$_GET['mode'].'/area_logo_'.$area_id_root.'.gif')) {
    echo '<script> parent.$("upl_'.$area_id_root.'").src=""; parent.$("upl_'.$area_id_root.'").alt="未上传"; alert("图标删除成功。"); parent.delSubmitSafe(); </script>';
    @unlink('inc/css/'.$_GET['mode'].'/area_logo_'.$area_id_root.'.gif');
    exit;
  } else {
    err('<script> alert("图标本来不存在！"); parent.delSubmitSafe(); </script>');
    
  }


} elseif ($_GET['act'] == 'upl') {
  if (!confirm_mode($_GET['mode'])) { 
    err('<script> alert("模板出错！"); parent.delSubmitSafe(); </script>');
  }
  $upload_dir = 'inc/css/'.$_GET['mode'].'';
  eval('@chmod(\''.$upload_dir.'\', 0'.$web['chmod'].');');
  $inis = ini_get_all();
  $uploadmax = $inis['upload_max_filesize'];
/*
[global_value] => 2M
[local_value] => 2M
[access] => 6
*/
  if (!is_array($_FILES['uploadfile']) || !$_FILES['uploadfile']['size']) {
    err('<script> alert("上传出现空值！原因分析：1、上传图片为空 2、图片超过系统最大上传限量'.$uploadmax['global_value'].'（'.$uploadmax['local_value'].'）"); parent.delSubmitSafe(); </script>');
  } else {
    $max_size = 30 * 10000;
    if ($_FILES['uploadfile']['size'] > $max_size) {
      err('<script> alert("上传的图片请小于'.($max_size/1000).'KB"); parent.delSubmitSafe(); </script>');
    }else{
      if (!preg_match('/\.(jpg|jpeg|gif|png)$/i', $_FILES['uploadfile']['name'], $im)) {
        err('<script> alert("请选择(jpg|jpeg|gif|png)图片！这么简单的事系统不自行处理"); parent.delSubmitSafe(); </script>');
      } else {
        $upload_filename = 'area_logo_'.$area_id_root.$im[0];

        if (@move_uploaded_file($_FILES['uploadfile']['tmp_name'], $upload_dir.'/'.$upload_filename)) {
          if (preg_match('/<\?php|eval|POST|base64_decode|base64_encode/i', @file_get_contents($upload_dir.'/'.$upload_filename))) {
            @unlink($upload_dir.'/'.$upload_filename);
            err('<script> alert("上传失败！文件含有禁止的代码"); parent.delSubmitSafe(); </script>');
          }
          require_once ('inc/function/img.php');

          $f = typeto($upload_dir.'/'.$upload_filename, 'gif');
          run_img_resize($f, $f, 60, 60, $web['pic_quality']);
          err('<script> alert("图标上传成功！图片路径为：\n '.$f.'"); parent.$("upl_'.$area_id_root.'").src="'.$f.'?'.time().'"; parent.$("upl_'.$area_id_root.'").alt=""; parent.delSubmitSafe(); </script>');
        } else {
          err('<script> alert("上传出现错误！请暂时停止上传"); parent.delSubmitSafe(); </script>');
        }
      }
    }
  }


//版主
} elseif ($_GET['act'] == 'admin') {
  $_POST['username'] = trim($_POST['username'], ',');
  //提交版主
  if (!empty($_POST['username'])) {
    if (!preg_match('/^([^\x00-\x7f]|\w|\.|\,){3,45}$/', $_POST['username'])) {
      err('<script> alert("提交被拒绝！用户名请用汉字、数字、英文及字符 _ 或 . 组成！长度范围为3-40字符。如多个版主请用 , 分隔"); parent.delSubmitSafe(); </script>');
    }
    $_POST['username'] = str_replace('.', '&#46;', $_POST['username']);
    @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' SET `power`=REPLACE(`power`,"('.$area_id_root.')","") WHERE `power` LIKE "%('.$area_id_root.')%"', $db);
    $admins = @explode(',', $_POST['username']);
    $admins = array_filter(array_unique((array)$admins));
    foreach((array)$admins as $key => $username) {
      @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' SET `power`=CONCAT(REPLACE(`power`,"('.$area_id_root.')",""),"('.$area_id_root.')") WHERE username="'.$username.'" AND (`power`="" OR `power` REGEXP "(\([0-9]+\-[0-9]+\))+")', $db);
      if (!(@mysql_affected_rows() > 0)) {
        $err[] = $username;
        unset($admins[$key]);
      }
    }
    @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载版区分类的表名'].' SET area_admin="'.@implode(',', $admins).'" WHERE area_id="'.$area_id_root.'"', $db);

//print_r($err);
//echo mysql_errno().':'.mysql_error();

  //清空版主
  } else {
    @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' SET `power`=REPLACE(power,"('.$area_id_root.')","") WHERE `power` LIKE "%('.$area_id_root.')%"', $db);
    @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载版区分类的表名'].' SET area_admin="" WHERE area_id="'.$area_id_root.'"', $db);
  }
  echo '<script> alert("设置版主执行完毕。'.(count($err) > 0 ? '\\n（其中：'.@implode('，', $err).'设置为版主失败！）\\n原因可能为：\\n1、该成员没有注册\\n2、该成员权限受限\\n3、该成员已是栏目版主或管理员' : '').'"); parent.delSubmitSafe(); </script>';
  @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载版区分类的表名'].' SET area_mark='.get_area_mark().' WHERE area_id="'.$area_id_root.'"', $db);


//字体样式
} elseif ($_GET['act'] == 'add_style') {
  if ($_GET['style'] != 'redword' && $_GET['style'] != 'greenword' && $_GET['style'] != 'grayword' && $_GET['style'] != 'boldword') {
    $_GET['style'] = '';
  }
  $style = $_GET['style'] != '' ? ' class=\"'.$_GET['style'].'\"' : '';
  @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载版区分类的表名'].' SET area_style="'.$style.'" WHERE area_id="'.$_GET['area_id'].'"', $db);
  err('<script> parent.$("area_name_'.$_GET['area_id'].'").className="'.$_GET['style'].'"; alert("样式设置'.(@mysql_affected_rows() > 0 ? '成功！' : '不成功！\n（'.mysql_errno().':'.mysql_error().'）').'"); parent.delSubmitSafe(); </script>');


//开启多城市
} elseif ($_GET['act'] == 'citysopen') {
  if (!confirm_mode($_GET['mode'])) { 
    err('<script> alert("模板出错！"); parent.delSubmitSafe(); </script>');
  }
  $num = isset($_GET['number']) && $_GET['number'] == 2 ? 2 : '';
  err('<script> alert("开启多城市'.(@copy('inc/city/city'.$num.'.php', 'inc/css/'.$_GET['mode'].'/city.php') ? '成功！' : '不成功！').'"); parent.delSubmitSafe(); </script>');

//关闭多城市
} elseif ($_GET['act'] == 'citysclose') {
  if (!confirm_mode($_GET['mode'])) { 
    err('<script> alert("模板出错！"); parent.delSubmitSafe(); </script>');
  }
  err('<script> alert("关闭多城市'.(@unlink('inc/css/'.$_GET['mode'].'/city.php') ? '成功！' : '不成功！').'"); parent.delSubmitSafe(); </script>');

//栏目分配
} elseif ($_GET['act'] == 'index') {
  $_POST['area_index'] = array_filter(array_unique((array)$_POST['area_index']));
  if (count($_POST['area_index']) == 0) {
    $c = '清空';
  } else {
    $c = '分配';
  }
    foreach ($_POST['area_index'] as $mode) {
      if (!file_exists('inc/css/'.$mode)) {
        err('<script> alert("模式不存在！"); parent.delSubmitSafe(); </script>');
      }
      $index_str .= $mode.'|';
    }
    $index_str = trim($index_str, '|');

  @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载版区分类的表名'].' SET area_index="'.$index_str.'" WHERE area_id="'.$area_id_root.'"', $db);
  err('<script> alert("栏目'.$index_str.''.$c.''.(@mysql_affected_rows() > 0 ? '成功！' : '不成功！\n（'.mysql_errno().':'.mysql_error().'）').'"); parent.delSubmitSafe(); </script>');


//发表审核
} elseif ($_GET['act'] == 'check') {
  if ($_POST['check'] == '1') {
    $to_ = '1';
    $say = '开启';
  } else {
    $to_ = '0';
    $say = '关闭';
  }
  @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载版区分类的表名'].' SET area_check="'.$to_.'" WHERE area_id="'.$area_id_root.'"', $db);
  $over = @mysql_affected_rows();
  @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载版区分类的表名'].' SET area_mark='.get_area_mark().' WHERE area_id="'.$area_id_root.'"', $db);
  echo '<script> alert("发表审核功能'.$say.''.($over > 0 ? '成功！' : '不成功！\n（'.mysql_errno().':'.mysql_error().'）').'"); parent.delSubmitSafe(); </script>';


//回复审核
} elseif ($_GET['act'] == 'check_reply') {
  if ($_POST['check_reply'] == '1') {
    $to_ = '1';
    $say ='开启';
  } else {
    $to_ = '0';
    $say ='关闭';
  }
  @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载版区分类的表名'].' SET area_check_reply="'.$to_.'" WHERE area_id="'.$area_id_root.'"', $db);
  err('<script> alert("回复审核功能'.$say.''.(@mysql_affected_rows() > 0 ? '成功！' : '不成功！\n（'.mysql_errno().':'.mysql_error().'）').'"); parent.delSubmitSafe(); </script>');


//各种权限
} elseif ($_GET['act'] == 'write' || $_GET['act'] == 'read' || $_GET['act'] == 'reply') {
  if ($_POST[$_GET['act']] == '1') {
    if (!(is_numeric($_POST['p_point']) && $_POST['p_point'] > 0)) {
      err('<script> alert("你输入的值不对，只允许输入大于0的数字！"); parent.delSubmitSafe(); </script>');
    }
    $to_ = $_POST['p_point'];
  } elseif ($_POST[$_GET['act']] == '-1') {
    $to_ = '-1';
  } else {
    $to_ = '0';
  }
  @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载版区分类的表名'].' SET area_power_'.$_GET['act'].'="'.$to_.'" WHERE area_id="'.$area_id_root.'"', $db);
  $over = @mysql_affected_rows();
  @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载版区分类的表名'].' SET area_mark='.get_area_mark().' WHERE area_id="'.$area_id_root.'"', $db);
  echo '<script> alert("保存'.($over > 0 ? '成功！' : '不成功！\n（'.mysql_errno().':'.mysql_error().'）').'"); parent.delSubmitSafe(); </script>';


//文章时效
} elseif ($_GET['act'] == 'expires') {
  $_POST['expires'] = abs($_POST['expires']);
  if ($_POST['expires'] > 0) {
    $say = '设定';
  } else {
    $say = '取消';
  }
  @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载版区分类的表名'].' SET area_expires="'.$_POST['expires'].'" WHERE area_id="'.$area_id_root.'"', $db);
  $over = @mysql_affected_rows();
  @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载版区分类的表名'].' SET area_mark='.get_area_mark().' WHERE area_id="'.$area_id_root.'"', $db);
  echo '<script> alert("'.$say.'文章时效'.($over > 0 ? '成功！' : '不成功！\n（'.mysql_errno().':'.mysql_error().'）').'"); parent.delSubmitSafe(); </script>';


//更改类名
} elseif ($_GET['act'] == 'edit') {
  if (!confirm_mode($_GET['mode'])) { 
    err('<script> alert("模板出错！"); parent.delSubmitSafe(); </script>');
  }
  if (empty($_GET['area_name'])) {
    err('<script> alert("新栏目名不能空值！"); parent.delSubmitSafe(); </script>');
  }
  require ('inc/function/filter.php');
  $area_name_new = filter1($_GET['area_name']);
  @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载版区分类的表名'].' SET area_name="'.$area_name_new.'" WHERE area_id="'.$_GET['area_id'].'"', $db);
  err('<script> alert("编辑栏目名执行完毕！"); try{ parent.document.getElementById(\'area_name_'.$_GET['area_id'].'\').innerHTML=\''.$area_name_new.'\'; parent.delSubmitSafe(); } catch(err) { parent.location="webmaster_central.php?get=area&mode='.$_GET['mode'].'&reload='.time().'"; } </script>');

//更改SEO
} elseif ($_GET['act'] == 'seo') {
  err('<script> alert("非商业版未开通此功能！请联系162100官方购买，谢谢支持"); try{ parent.delSubmitSafe(); } catch(err) { parent.location="webmaster_central.php?get=area&mode='.$_GET['mode'].'&reload='.time().'"; } </script>');


//删除类
} elseif ($_GET['act'] == 'del') {
  if (!confirm_mode($_GET['mode'])) { 
    err('<script> alert("模板出错！"); parent.delSubmitSafe(); </script>');
  }
  @mysql_query('DELETE FROM '.$sql['pref'].''.$sql['data']['承载版区分类的表名'].' WHERE area_id="'.$_GET['area_id'].'" OR area_id LIKE "'.$_GET['area_id'].'\_%"', $db);
  //if ($_GET['listdel'] == 'yes') {
    echo '<script> parent.document.getElementById("submit_safe_in").innerHTML="数 据 删 除 中 ， 勿 关 闭 窗 口 …"; </script>';
    @mysql_query('DELETE '.$sql['pref'].''.$sql['data']['承载主题文章的表名'].','.$sql['pref'].''.$sql['data']['承载关键词的表名'].','.$sql['pref'].''.$sql['data']['承载回复评论的表名'].' FROM '.$sql['pref'].''.$sql['data']['承载主题文章的表名'].' LEFT JOIN ('.$sql['pref'].''.$sql['data']['承载关键词的表名'].','.$sql['pref'].''.$sql['data']['承载回复评论的表名'].') ON '.$sql['pref'].''.$sql['data']['承载关键词的表名'].'.id='.$sql['pref'].''.$sql['data']['承载主题文章的表名'].'.id AND '.$sql['pref'].''.$sql['data']['承载回复评论的表名'].'.r_id='.$sql['pref'].''.$sql['data']['承载主题文章的表名'].'.id WHERE '.$sql['pref'].''.$sql['data']['承载主题文章的表名'].'.area_id="'.$_GET['area_id'].'" OR '.$sql['pref'].''.$sql['data']['承载主题文章的表名'].'.area_id LIKE "'.$_GET['area_id'].'\_%"', $db);
  //}
  if (!is_numeric($_GET['area_id'])) {
    //更新统计
    add_total($area_id_root, $db);
    add_today($area_id_root, $db);
  }
  err('<script> try{ parent.areaDELp("'.$_GET['area_id'].'"); alert("删除执行完毕！"); } catch(err) { /*parent.location="webmaster_central.php?get=area&mode='.$_GET['mode'].'&reload='.time().'";*/ } </script>');
  

//转移类
} elseif ($_GET['act'] == 'mov') {
  if (!confirm_mode($_GET['mode'])) { 
    err('<script> alert("模板出错！"); parent.delSubmitSafe(); </script>');
  }
  if (!preg_match('/^\d+\-\d+(\_\d+)*$/', $_GET['area_id_new'])) {
    err('<script> alert("分类参数不合法！应该为数字（间隔可含下划线）"); parent.areaMOV("'.$_GET['area_id'].'"); parent.delSubmitSafe(); </script>');
  }
  if (strlen($_GET['area_id_new']) > 250) {
    err('<script> alert("分类参数太长！设这么长干什么？别大于250"); parent.areaMOV("'.$_GET['area_id'].'"); parent.delSubmitSafe(); </script>');
  }
  $result = @mysql_query('SELECT COUNT(id) AS o_n FROM '.$sql['pref'].''.$sql['data']['承载版区分类的表名'].' WHERE `area_id`="'.$_GET['area_id_new'].'"', $db);
  $row = @mysql_fetch_assoc($result);
  @mysql_free_result($result);
  if (isset($row['o_n']) && abs($row['o_n']) > 0) {
    err('<script> alert("分类'.$_GET['area_id_new'].'已经存在！"); parent.areaMOV("'.$_GET['area_id'].'"); parent.delSubmitSafe(); </script>');
  }
  unset($row);
  if ($_GET['area_id'] == $area_id_root && strpos($_GET['area_id_new'], $_GET['area_id'].'_') === 0) {
    err('<script> alert("根类'.$_GET['area_id'].'无法向平级或下级转移！"); parent.areaMOV("'.$_GET['area_id'].'"); parent.delSubmitSafe(); </script>');
  }
  $base = $_GET['area_id_new'];
  while (strpos($base, '_') !== false) {
    $base = preg_replace('/\_\d+$/', '', $base);
    $result = mysql_query('SELECT * FROM `'.$sql['pref'].''.$sql['data']['承载版区分类的表名'].'` WHERE `area_id`="'.$base.'"', $db);
    if (!mysql_num_rows($result) > 0) {
      err('<script> alert("上级分类'.$base.'不存在！"); parent.areaMOV("'.$_GET['area_id'].'"); parent.delSubmitSafe(); </script>');
    }
  }

  @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载版区分类的表名'].' SET area_id=REPLACE(area_id,"'.$_GET['area_id'].'","'.$_GET['area_id_new'].'") WHERE area_id="'.$_GET['area_id'].'" OR area_id LIKE "'.$_GET['area_id'].'\_%"', $db);
  if ($_GET['area_id_new'] == get_arearoot($_GET['area_id_new'])) {
    @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载版区分类的表名'].' SET area_mark="'.get_area_mark().'" WHERE area_id="'.$_GET['area_id_new'].'"', $db);
  }

  if ($_GET['listmov'] == 'yes') {
    echo '<script> parent.document.getElementById("submit_safe_in").innerHTML="数 据 转 移 中 ， 勿 关 闭 窗 口 …"; </script>';
    @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载主题文章的表名'].' SET area_id=REPLACE(area_id,"'.$_GET['area_id'].'","'.$_GET['area_id_new'].'") WHERE area_id="'.$_GET['area_id'].'" OR area_id LIKE "'.$_GET['area_id'].'\_%"', $db);
    $n = @mysql_affected_rows();
    if ($n > 0 && get_arearoot($_GET['area_id_new']) != $area_id_root) {
      //更新统计
      add_total(get_arearoot($_GET['area_id_new']), $db);
      add_today(get_arearoot($_GET['area_id_new']), $db);
      add_total($area_id_root, $db);
      add_today($area_id_root, $db);
    }
  } else {
    if (get_arearoot($_GET['area_id_new']) != $area_id_root) {
      //更新统计
      add_total(get_arearoot($_GET['area_id_new']), $db);
      add_today(get_arearoot($_GET['area_id_new']), $db);
      add_total($area_id_root, $db);
      add_today($area_id_root, $db);
    }
  }
  echo '<script> alert("移动类别执行完毕！"); parent.delSubmitSafe(); parent.location="webmaster_central.php?get=area&mode='.$_GET['mode'].'&area_id='.get_arearoot($_GET['area_id_new']).'&reload='.time().'"; </script>';


//增加类
} elseif ($_GET['act'] == 'add') {
  if (!confirm_mode($_GET['mode'])) { 
    err('<script> alert("模板出错！"); parent.delSubmitSafe(); </script>');
  }
  if (strlen($_GET['area_id']) > 250) {
    err('<script> alert("分类参数太长！设这么长干什么？别大于250"); parent.delSubmitSafe(); </script>');
  }
  if (strpos($_GET['area_id'], 'root') === 0) {
    list($r, $root_pre) = @explode('_', $_GET['area_id']);
    if (empty($root_pre) || !preg_match('/^\d+\-$/', $root_pre)) {
      err('<script> alert("根目前缀缺失或出错！"); parent.delSubmitSafe(); </script>');
    }
    $result = @mysql_query('SELECT * FROM `'.$sql['pref'].''.$sql['data']['承载版区分类的表名'].'` WHERE area_id REGEXP "^'.$root_pre.'[0-9]+$"', $db);
    if (mysql_num_rows($result) > 0) {
      $aarr = array();
      while ($r = @mysql_fetch_assoc($result)) {
        $aarr[$r['area_id']] = 1;
        unset($r);
      }
      uksort($aarr, "strnatcmp");
      end($aarr);
      $new_area_po = preg_replace('/^'.$root_pre.'/', '', key($aarr));
      $new_area_id = $root_pre.''.(abs($new_area_po) + 1);
	} else {
      $new_area_id = $root_pre.'1';
    }
    @mysql_free_result($result);
    $new_area_po = 'NULL';
    $new_root_eval = '@mysql_query(\'REPLACE INTO `'.$sql['pref'].''.$sql['data']['承载版区分类的表名'].'` (`area_id`,`area_name`,`area_mark`) VALUES ("'.$new_area_id.'","\'.$area_name_new.\'","<del class=\"area_mark\" title=\"可匿名发表\"><span>匿</span></del><del class=\"area_mark area_mark_\" title=\"本版发表审核：关闭\"><span>审</span></del><del class=\"area_mark area_mark_\" title=\"本版未设信息时效期\"><span>效</span></del><del id=\"read_mark\" class=\"area_mark\" title=\"阅览公开\"><span>阅</span></del><del class=\"area_mark\" title=\"本版评论回复：过客可评论回复\"><span>评</span></del><del class=\"area_mark\" title=\"本版栏目未设版主，管理员直接管理\"><span>管</span></del>")\');';
    //$outjs = 'parent.location=parent.location.replace(/(\#.*)?$/g,"")+"#editbase_'.$new_area_id.'";';
    $outjs = 'parent.location=parent.location.href.toString().replace(/(&(area_id|reload)\=[^&]*)?/ig,"").replace(/(\#.*)?$/,"")+"&reload='.time().'#foot"; ';
  } else {

    $result = @mysql_query('SELECT * FROM `'.$sql['pref'].''.$sql['data']['承载版区分类的表名'].'` WHERE area_id LIKE "'.$_GET['area_id'].'\_%"', $db);
    if (mysql_num_rows($result) > 0) {
      $aarr = array();
      while ($r = @mysql_fetch_assoc($result)) {
        $aarr[$r['area_id']] = 1;
        unset($r);
      }
      uksort($aarr, "strnatcmp");
      end($aarr);
      $new_area_po = key($aarr);
      $new_area_id = preg_replace('/^('.preg_quote($_GET['area_id']).'_)(\d+).*$/e', '"$1".(abs("$2") + 1).""', $new_area_po);
	} else {
      $new_area_po = $_GET['area_id'];
      $new_area_id = $_GET['area_id'].'_1';
    }
    @mysql_free_result($result);
    $new_root_eval = '@mysql_query(\'REPLACE INTO `'.$sql['pref'].''.$sql['data']['承载版区分类的表名'].'` (`area_id`,`area_name`,`area_mark`) VALUES ("\'.$new_area_id.\'","\'.$area_name_new.\'","")\');';
    $outjs = 'parent.areaADDp("'.$_GET['area_id'].'", "'.$new_area_id.'", "'.$new_area_po.'");';
  }
  require ('inc/function/filter.php');
  $area_name_new = filter1($_GET['area_name']);
  if ($area_name_new == '') {
    err('<script> alert("新栏目名不能空值！"); parent.delSubmitSafe(); </script>');
  }
  
  eval($new_root_eval);
  $n_a = @mysql_affected_rows();
  err('<script> try{ alert("增加'.$_GET['area_id'].'类别'.($n_a > 0 ? '成功！' : '不成功！\n（'.mysql_errno().':'.mysql_error().'）').'"); '.$outjs.' } catch (err) { } </script>');



} else {
  err('<script> alert("命令出错！"); </script>');

}
@mysql_close();

?>