<?php
//栏目分类设置


function filter($text) {
  $text = trim($text);
  $text = stripslashes($text);
  //$text = htmlspecialchars($text);
  $text = preg_replace('/[\r\n\'\"\s\<\>]+/', '', $text);
  $text = str_replace('|', '&#124;', $text);
  //$text = str_replace('/', '&#47;', $text);
  return $text;
}
@ require ('readonly/function/confirm_power.php');
define('POWER', confirm_power());

if (POWER != 5) {
  err('<script> alert("该命令必须以基本管理员身份登陆！请重登陆"); </script>');
}
@ require ('writable/set/set_area.php');
if ($_GET['column_id'] && !array_key_exists($_GET['column_id'], $web['area'])) {
  err('<script> alert("始发分类参数缺失或错误"); </script>');
}
if ($_GET['class_id'] && !array_key_exists($_GET['class_id'], $web['area'][$_GET['column_id']])) {
  err('<script> alert("始发栏目参数缺失或错误"); </script>');
}
$_GET['class_title'] = filter(htmlspecialchars($_GET['class_title']));
if(empty($_GET['class_title'])){
  err('<script> alert("始发频道名不能空！"); </script>');
}
$_GET['detail_title'] = filter(htmlspecialchars($_GET['detail_title']));
if(empty($_GET['detail_title'])){
  err('<script> alert("始发专题名不能空！"); </script>');
}

list($column_id,$class_id)=@explode('_',$_POST['siteclass']);
if(@!array_key_exists($column_id,$web['area']))
  err('<script> alert("大类参数出错！"); </script>');
if(@!array_key_exists($class_id,$web['area'][$column_id]))
  err('<script> alert("小类参数出错！"); </script>');

$_POST['sitetitle']=filter(htmlspecialchars(urldecode($_POST['sitetitle'])));
if(empty($_POST['sitetitle'])){
  err('<script> alert("频道不能空！"); </script>');
}


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

if (@mysql_num_rows(@mysql_query('SELECT id FROM `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` WHERE column_id="'.$column_id.'" AND class_id="'.$class_id.'" AND (class_title="'.$_POST['sitetitle'].'" AND http_name_style="") AND detail_title LIKE "'.$_GET['detail_title'].'|%"', $db)) > 0) {
  err('<script> alert("彼岸同名专题已存在！"); </script>');
}


@mysql_query('UPDATE `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` SET column_id="'.$column_id.'",class_id="'.$class_id.'",class_title="'.addslashes($_POST['sitetitle']).'" WHERE column_id="'.$_GET['column_id'].'" AND class_id="'.$_GET['class_id'].'" AND class_title="'.$_GET['class_title'].'" AND (http_name_style="" AND class_priority<>"") AND detail_title LIKE "'.$_GET['detail_title'].'|%"', $db); //更新专题引导

@mysql_query('UPDATE `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` SET column_id="'.$column_id.'",class_id="'.$class_id.'" WHERE column_id="'.$_GET['column_id'].'" AND class_id="'.$_GET['class_id'].'" AND detail_title LIKE "'.$_GET['detail_title'].'|%"', $db); //更新专题附属


//if (@mysql_affected_rows() > 0) {
  $result = mysql_query('SELECT detail_title FROM `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` WHERE column_id="'.$column_id.'" AND class_id="'.$class_id.'" AND class_title="'.$_POST['sitetitle'].'" AND (http_name_style="" AND class_priority<>"") AND detail_title LIKE "'.$_GET['detail_title'].'|%" LIMIT 1', $db);
  $row = @mysql_fetch_assoc($result);
  list($detail_title, $dpy, $dside) = @explode('|', $row['detail_title']);
  unset($row);
  @mysql_free_result($result);

  if ($dpy) {
    $url = $dpy.'.html';
    $result = mysql_query('SELECT id,http_name_style FROM `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` WHERE column_id="'.$_GET['column_id'].'" AND class_id="'.$_GET['class_id'].'" AND class_title LIKE "'.$_GET['class_title'].'|%" AND detail_title="" LIMIT 1', $db); //从原来的栏目列表中去除专题
    if ($row = @mysql_fetch_assoc($result)) {
      $row['http_name_style'] = preg_replace('/.*'.preg_quote($url, '/').'\|[^\r\n]+[\r\n]+/', '', $row['http_name_style']);
      @mysql_query('UPDATE `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` SET http_name_style="'.addslashes($row['http_name_style']).'" WHERE id="'.$row['id'].'"', $db);
      unset($row);
    }
    @mysql_free_result($result);

    $result = mysql_query('SELECT id,http_name_style FROM `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` WHERE column_id="'.$column_id.'" AND class_id="'.$class_id.'" AND class_title LIKE "'.$_POST['sitetitle'].'|%" AND detail_title="" LIMIT 1', $db); //将专题加入新的栏目列表中
    if ($row = @mysql_fetch_assoc($result)) {
      $row['http_name_style'] = preg_replace('/.*'.preg_quote($url, '/').'\|[^\r\n]+[\r\n]+/', '', $row['http_name_style']);
      $row['http_name_style'] = $row["http_name_style"]."".$url."|".$_GET['detail_title']."||\n";
      @mysql_query('UPDATE `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` SET http_name_style="'.addslashes($row['http_name_style']).'" WHERE id="'.$row['id'].'"', $db);
      unset($row);
    }
    @mysql_free_result($result);
  }

//}

@mysql_close();
@ require ('readonly/function/write_file.php');
reset_indexhtml('class.php', $web['area'][$_GET['column_id']]['name'][1].'_'.$web['area'][$_GET['column_id']][$_GET['class_id']][1].'.html');
$_GET['column_id'] = $column_id;
$_GET['class_id'] = $class_id;
reset_indexhtml('class.php', $web['area'][$_GET['column_id']]['name'][1].'_'.$web['area'][$_GET['column_id']][$_GET['class_id']][1].'.html');
err('<script> alert("转移完毕"); try { var pC = parent.$("'.$_GET['column_id'].'_'.$_GET['class_id'].'_'.urlencode($_GET['class_title']).'_'.urlencode($_GET['detail_title']).'"); pC.parentNode.removeChild(pC); parent.$("chanto").style.display="none"; } catch (e) {} </script>');
















?>