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

//栏目分类设置——拼音纠错
if (POWER != 5) {
  err('该命令必须以基本管理员身份登陆！请重登陆');
}

if (!isset($sql['db_err'])) {
  $db = db_conn();
}
if ($sql['db_err'] != '') {
  err($sql['db_err']);
}
$output = '执行完毕。';

//print_r($_POST);die;

@ require 'writable/set/set_area.php';
@ require 'readonly/function/write_file.php';

$_POST['detail_pinyin_cfid'] = array_filter(preg_replace('/^[^\d]+$/', '', $_POST['detail_pinyin_cfid']));
//$e1 = '(LIKE "%|'.implode('|%" OR LIKE "%|', $_POST['detail_correct']).'|%")';

$e1 = 'REGEXP "\|('.implode('|', $_POST['detail_correct']).')\|"';
$e2 = ' AND id NOT IN('.implode(',', $_POST['detail_pinyin_cfid']).')';

if (!empty($_POST['detail_correct']) && count($_POST['detail_correct']) > 0) {
  if (count($_POST['detail_correct']) > count(array_unique($_POST['detail_correct']))) {
    err('专题拼音不能空也不能有重名！');
  }
  if (count($_POST['detail_correct']) > count(array_filter(preg_replace('/^\s+|\s+$/', '', $_POST['detail_correct'])))) {
    err('专题拼音不能有空值！');
  }

  foreach($_POST['detail_correct'] as $k => $v) {
    $cf = '';
    list($column_id, $class_id, $class_title, $detail_title, $dpy) = @explode('_', $k);
    $result = db_query($db, 'SELECT * FROM `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` WHERE detail_title '.$e1.' AND http_name_style=""'.$e2.'');// AND LENGTH(class_priority)>0
    if ($result != false) {
      while ($row = db_fetch($db, $result)) {
        $cf .= '<div>'.$web['area'][$row['column_id']]['name'][0].'/'.$web['area'][$row['column_id']][$row['class_id']][0].'/'.$row['class_title'].'/'.preg_replace('/^([^\|]*\|'.$v.').*/', '$1', $row['detail_title']).'</div>';
        unset($row, $column_id, $class_id, $class_title, $detail_title, $dpy);
      }
    }
    $result = NULL;
    if ($cf != '') {
      err('专题拼音（'.$v.'）数据库中已存在了：<div style="border:1px #FF6600 solid; margin:0 10px; padding:5px; color:#333333; font-size:12px;">'.$cf.'</div>，请返回再行修改。');
    }

    list($_GET['column_id'], $_GET['class_id'], $_GET['class_title'], $_GET['detail_title'], $dpy_old) = @explode('_', $k);
    $_GET['class_title'] = urldecode($_GET['class_title']);
    $_GET['detail_title'] = urldecode($_GET['detail_title']);
    if (db_exec($db, 'UPDATE `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` SET detail_title=CONCAT("'.$_GET['detail_title'].'|'.$v.'|",SUBSTRING(detail_title,LOCATE("|",detail_title,INSTR(detail_title, "|")+1)+1)) WHERE column_id="'.$_GET['column_id'].'" AND class_id="'.$_GET['class_id'].'" AND class_title="'.$_GET['class_title'].'" AND detail_title LIKE "'.$_GET['detail_title'].'|'.$dpy_old.'|" AND http_name_style=""')) {// AND LENGTH(class_priority)>0
      $o = 1;
    }
    if ($o == 1) {
      $output .= '多音字校正完毕！专题['.$_GET['detail_title'].']已设置好。<br />';
      //reset_indexhtml('index.php', 'index.html');
      if ($dpy_old != $v) {
        $d_ = 'writable/__web__/images/'.$_GET['column_id'].'_'.$_GET['class_id'];
        //@chmod('writable/__web__', 0777);
        //@chmod('writable/__web__/images', 0777);
        //@chmod($d_, 0777);
        eval('@chmod(\'writable/__web__\', 0'.$web['chmod'].');');
        eval('@chmod(\'writable/__web__/images\', 0'.$web['chmod'].');');
        eval('@chmod($d_, 0'.$web['chmod'].');');
        if (file_exists($d_.'/'.$dpy_old.'.gif')) { @rename($d_.'/'.$dpy_old.'.gif', $d_.'/'.$v.'.gif'); }
        if (file_exists($d_.'/'.$dpy_old.'.jpg')) { @rename($d_.'/'.$dpy_old.'.jpg', $d_.'/'.$v.'.jpg'); }
        if (file_exists($d_.'/'.$dpy_old.'.png')) { @rename($d_.'/'.$dpy_old.'.png', $d_.'/'.$v.'.png'); }
        @unlink($dpy_old.'.html');
        db_exec($db, 'UPDATE `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` SET http_name_style=REPLACE(REPLACE(http_name_style,"'.$dpy_old.'.html","'.$v.'.html"),"'.$d_.'/'.$dpy_old.'.","'.$d_.'/'.$v.'.") WHERE column_id="'.$_GET['column_id'].'" AND class_id="'.$_GET['class_id'].'" AND class_title=(SELECT TEMP.class_title FROM (SELECT M.* FROM `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` M) TEMP WHERE TEMP.column_id="'.$_GET['column_id'].'" AND TEMP.class_id="'.$_GET['class_id'].'" AND TEMP.class_title="'.$_GET['class_title'].'" AND TEMP.detail_title LIKE "'.$_GET['detail_title'].'|%" AND TEMP.http_name_style="" LIMIT 1)');// AND LENGTH(TEMP.class_priority)>0
      }
      reset_indexhtml('detail.php', ''.$v.'.html');
    }
    unset($_GET['column_id'], $_GET['class_id'], $_GET['class_title'], $_GET['detail_title'], $img_, $dpy_old);
  }
}
db_close($db);

alert($output, 'webmaster_central.php?get=http');



?>