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

/* 成员管理执行 */
/* 162100源码 - 162100.com */


if (POWER == 0) {
  err('请<a href="./login.php">登陆</a>。');
}

function filter($text) {
  return (!preg_match('/[\s\"\']|^$/', $text) && $text != '');
}

if (!$limit = @$_GET['limit']) {
  $limit = @$_POST['limit'];
}

$_REQUEST['id'] = @array_unique((array)$_REQUEST['id']);
$_REQUEST['id'] = @array_filter($_REQUEST['id'], 'filter');

if (count($_REQUEST['id']) == 0) {
  err('参数出错！<br />问题分析：<br />1、您可能未点选<br />2、参数传递出错。');
}

@ require ('inc/function/write_file.php');
@ require ('inc/function/deldir.php');

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

$result = @mysql_query('SELECT username,power,point,writecount,replycount,mess,mess_num FROM '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' WHERE username="'.$session[0].'" LIMIT 1', $db);
$row_member = @mysql_fetch_assoc($result);
if (empty($row_member['username'])) {
  err('你不是合法成员！数据库中查不到你。');
}
@mysql_free_result($result);

$id_key = '(id="'.implode('" OR id="', $_REQUEST['id']).'")';

$dataname = $_REQUEST['dataname'];
$out = '';

if ($dataname == 'listdata') {
  //兑现悬赏
  if ($limit == 'reward_cash') {
    $_REQUEST['id'] = $_REQUEST['id'][0];
    //取文章
    $result = @mysql_query('SELECT A.*,B.area_index FROM '.$sql['pref'].''.$sql['data']['承载主题文章的表名'].' A LEFT JOIN '.$sql['pref'].''.$sql['data']['承载版区分类的表名'].' B ON B.area_id=SUBSTRING_INDEX(A.area_id,"_",1) WHERE A.id="'.$_REQUEST['id'].'" AND A.author_ip="'.$session[0].'" LIMIT 1', $db);
    if ($row = @mysql_fetch_assoc($result)) {
      if (strstr($row['reward'], '（已兑现）')) {
        err('该文已经兑现完毕。');
      }
      if (floatval($row['reward']) <= 0) {
        err('该文无悬赏！出错。');
      }
      $area_mode = get_li_mode($row['area_index']);
    } else {
      err('未查到此记录！可能参数传递出错或已被删除。');
    }
    @mysql_free_result($result);
    
    $rer = array();
    $F = @array_filter($_POST['f']);
    $step = 0;
    foreach ($F as $key => $val) {
      $_POST['r_author'][$key] = str_replace('.', '&#46;', $_POST['r_author'][$key]);
      if (array_key_exists($_POST['r_author'][$key], $rer))
        $rer[$_POST['r_author'][$key]] += $val;
      else
        $rer[$_POST['r_author'][$key]] = $val;
      $step += 10;
      //给回复者加悬赏
      $eval_run_replydata .= '
      @mysql_query(\'UPDATE `'.$sql['pref'].''.$sql['data']['承载回复评论的表名'].'` SET reward="'.$val.'" WHERE id="'.$_POST['r_id'][$key].'" AND author_ip="'.$_POST['r_author'][$key].'"\', $db);
      if (@mysql_affected_rows() > 0) {
        @mysql_query(\'INSERT INTO `'.$sql['pref'].''.$sql['data']['承载财务数据的表名'].'` (`username`,`type`,`description`,`money`,`date`,`other`) VALUES ("'.$_POST['r_author'][$key].'","0","获得悬赏","'.$val.'",DATE_ADD(UTC_TIMESTAMP(), INTERVAL '.(floatval($web['time_pos']) *3600 + $step).' SECOND), "文章ID：<a href=\"article.php?mode='.$area_mode.'&id='.$_REQUEST['id'].'#reply_'.$_POST['r_id'][$key].'\" target=\"_blank\">'.$_REQUEST['id'].'#'.$_POST['r_id'][$key].'</a>")\', $db);
      }
';
    }
    if ($rer[$session[0]]) {
      unset($rer[$session[0]]);
    }
    if (count($rer) == 0) {
      err('程序经过处理，没发现有可悬赏之人！注：自己不能悬赏自己。');
    }
    if (floatval($row['reward']) != @array_sum($rer)) {
      err('提交被拒绝！分数总和不对！注：自己不能悬赏自己。');
    }
    eval($eval_run_replydata);

    //结帖确认
    @mysql_query('UPDATE `'.$sql['pref'].''.$sql['data']['承载主题文章的表名'].'` SET reward=CONCAT_WS("",reward,"（已兑现）") WHERE id="'.$_REQUEST['id'].'" AND author_ip="'.$session[0].'"', $db);

    //给作者加信誉值
    if (floatval($web['reward_cash_add_credit']) > 0) {
      @mysql_query('INSERT INTO `'.$sql['pref'].''.$sql['data']['承载财务数据的表名'].'` (`username`,`type`,`description`,`money`,`date`,`other`) VALUES ("'.$session[0].'","1","兑现悬赏","'.floatval($web['reward_cash_add_credit']).'",DATE_ADD(UTC_TIMESTAMP(), INTERVAL '.floatval($web['time_pos']).' HOUR), "文章ID：<a href=\"article.php?mode='.$area_mode.'&id='.$_REQUEST['id'].'\" target=\"_blank\">'.$_REQUEST['id'].'</a>")', $db);
    }


  } elseif ($limit == 'color') {
    if (empty($_POST['subject_color_color']) && empty($_POST['subject_backgroundColor_color'])) {
      err('文字颜色和背景颜色不能空！');
    }
    if (!empty($_POST['subject_color_color']) && !preg_match('/^[a-zA-Z]+$/', $_POST['subject_color_color'])) {
      err('文字颜色数值不对！必须为字母。');
    }
    if (!empty($_POST['subject_backgroundColor_color']) && !preg_match('/^[a-zA-Z]+$/', $_POST['subject_backgroundColor_color'])) {
      err('背景颜色数值不对！必须为字母。');
    }
    /*
    if (strtolower($_POST['subject_color_color']) == 'white' && empty($_POST['subject_backgroundColor_color'])) {
      err('请再设一下背景色。因为系统认为：背景颜色没有设置则文字颜色不能为白。');
    }
    */
    if (strtolower($_POST['subject_color_color']) == strtolower($_POST['subject_backgroundColor_color'])) {
      err('题目文字颜色和背景颜色不能相同！');
    }
    if (POWER < 4) {
      //求和货币值
      $result = @mysql_query('SELECT SUM(money) AS total FROM '.$sql['pref'].''.$sql['data']['承载财务数据的表名'].' WHERE username="'.$session[0].'" AND type="0"', $db);
      $row = @mysql_fetch_assoc($result);
      $total = (float)$row['total'];
      unset($row);
      @mysql_free_result($result);

      if (count($_REQUEST['id']) * abs($web['addcolordel']) > $total) {
        err('你的货币值不足！你要着色'.count($_REQUEST['id']).'条（要'.(count($_REQUEST['id']) * $web['addcolordel']).'）,而您目前货币值余'.$total.'（能着色'.floor($total / $web['addcolordel']).'条）。');
      }
      @mysql_query('INSERT INTO `'.$sql['pref'].''.$sql['data']['承载财务数据的表名'].'` (`username`,`type`,`description`,`money`,`date`,`other`) VALUES ("'.$session[0].'","0","题目着色","-'.(count($_REQUEST['id']) * $web['addcolordel']).'",DATE_ADD(UTC_TIMESTAMP(), INTERVAL '.floatval($web['time_pos']).' HOUR),"文章ID：'.implode('，', $_REQUEST['id']).'")', $db);

    }

    if (!empty($_POST['subject_color_color'] ) && empty($_POST['subject_backgroundColor_color'])) {
      $set_eval = 'IF(SUBSTRING(title_style,9,6)="color:",INSERT(title_style,15,INSTR(title_style,";")-15,"'.$_POST['subject_color_color'].'"),(IF(SUBSTRING(title_style,9,6)="backgr",REPLACE(title_style," style=\""," style=\"color:'.$_POST['subject_color_color'].';")," style=\"color:'.$_POST['subject_color_color'].';\"")))';
    } elseif (empty($_POST['subject_color_color'] ) && !empty($_POST['subject_backgroundColor_color'])) {
      $set_eval = 'IF(INSTR(title_style,"background-color")>9,INSERT(title_style,INSTR(title_style,"background-color"),LENGTH(title_style),"background-color:'.$_POST['subject_backgroundColor_color'].';\""),(IF(INSTR(title_style,"color")=9,INSERT(title_style,LENGTH(title_style)-1,1,"background-color:'.$_POST['subject_backgroundColor_color'].';\"")," style=\"background-color:'.$_POST['subject_backgroundColor_color'].';\"")))
';
    } else {
      $set_eval = '" style=\"color:'.$_POST['subject_color_color'].';background-color:'.$_POST['subject_backgroundColor_color'].';\""';
    }

    @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载主题文章的表名'].' SET title_style='.$set_eval.' WHERE '.$id_key.' AND author_ip="'.$session[0].'"', $db); // AND area_check=""

  //下架
  } elseif ($limit == 'warehouse') {
    @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载主题文章的表名'].' SET area_check="3" WHERE '.$id_key.' AND author_ip="'.$session[0].'" AND area_check=""', $db); // AND area_check=""

  //上架
  } elseif ($limit == 'again') {
    @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载主题文章的表名'].' SET area_check="0" WHERE '.$id_key.' AND author_ip="'.$session[0].'" AND area_check="3"', $db); // AND area_check=""
    if ($_REQUEST['m'] == 1) {
      err('<script> var obj=parent.$(\'check_'.$_REQUEST['id'][0].'\'); var par=obj.parentNode; par.removeChild(obj); obj.style.display=\'none\'; </script>');
    }

  //刷新
  } elseif ($limit == 'refresh') {
    if (POWER < 4) {
      //求和货币值
      $result = @mysql_query('SELECT SUM(money) AS total FROM '.$sql['pref'].''.$sql['data']['承载财务数据的表名'].' WHERE username="'.$session[0].'" AND type="0"', $db);
      $row = @mysql_fetch_assoc($result);
      $total = (float)$row['total'];
      unset($row);
      @mysql_free_result($result);

      if (count($_REQUEST['id']) * abs($web['refreshdel']) > $total) {
        err('你的货币值不足！你要刷新'.count($_REQUEST['id']).'条（要'.(count($_REQUEST['id']) * $web['refreshdel']).'）,而您目前货币值余'.$total.'（能刷新'.floor($total / $web['refreshdel']).'条）。');
      }
	  $scc_num = array();
	  foreach ($_REQUEST['id'] as $id) {
        @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载主题文章的表名'].' SET topdate=DATE_ADD(UTC_TIMESTAMP(), INTERVAL '.floatval($web['time_pos']).' HOUR) WHERE id='.$id.' AND author_ip="'.$session[0].'" AND topdate<DATE_ADD(UTC_TIMESTAMP(), INTERVAL '.floatval($web['time_pos']).' HOUR) AND area_check="0"', $db);
		$scc = @mysql_affected_rows();
		if ($scc > 0) {
	      $scc_num[] = $id;
	    }
		unset($id);
	  }
	  $scc_nums = count($scc_num);
	  
	  if ($scc_nums > 0) {
        @mysql_query('INSERT INTO `'.$sql['pref'].''.$sql['data']['承载财务数据的表名'].'` (`username`,`type`,`description`,`money`,`date`,`other`) VALUES ("'.$session[0].'","0","刷新文章","-'.($scc_nums * $web['refreshdel']).'",DATE_ADD(UTC_TIMESTAMP(), INTERVAL '.floatval($web['time_pos']).' HOUR),"文章ID：'.implode('，', $scc_num).'")', $db);
	  } else {
        err('没有刷新成功的文章！可能该篇已置顶');
      }
    }
    if ($_REQUEST['m'] == 1) {
      err('<script> var obj=parent.$(\'check_'.$_REQUEST['id'][0].'\'); var par=obj.parentNode; par.removeChild(obj); obj.style.display=\'none\'; </script>');
    }

  //首页图文展示
  } elseif ($limit == 'ess_index') {
    //求和信誉值
    $result = @mysql_query('SELECT SUM(money) AS total FROM '.$sql['pref'].''.$sql['data']['承载财务数据的表名'].' WHERE username="'.$session[0].'" AND type="1"', $db);
    $row = @mysql_fetch_assoc($result);
    $total1 = (float)$row['total'];
    unset($row);
    @mysql_free_result($result);
    //求和货币值
    $result = @mysql_query('SELECT SUM(money) AS total FROM '.$sql['pref'].''.$sql['data']['承载财务数据的表名'].' WHERE username="'.$session[0].'" AND type="0"', $db);
    $row = @mysql_fetch_assoc($result);
    $total2 = (float)$row['total'];
    unset($row);
    @mysql_free_result($result);

    require ('inc/function/ess_index_mx.php');
    $may_ess_index_num = ess_index_mx($total1);
    if (POWER < 4) {
      if (!(is_numeric($_POST['ess_index_topdate']) && $_POST['ess_index_topdate'] >= abs($web['ess_index_expires_member']))) {
        err('设置首页图文展示时限要填大于起订天数（'.$web['ess_index_expires_member'].'）的数字。');
      }
      $result = @mysql_query('SELECT COUNT(id) AS total FROM '.$sql['pref'].''.$sql['data']['承载上传数据的表名'].' WHERE title LIKE "thumb-%" AND username="'.$session[0].'"', $db);
      $row = @mysql_fetch_assoc($result);
      $n_ = (int)$row['total'];
      @mysql_free_result($result);
      $now_ess_index_num = $may_ess_index_num - $n_;
      if (count($_REQUEST['id']) > $now_ess_index_num) {
        err('你的信誉值所限，只能再进行首页图文展示'.$now_ess_index_num.'条，已展示'.$n_.'/'.$may_ess_index_num.'条。');
      }
      $total_point = count($_REQUEST['id']) * $_POST['ess_index_topdate'] * abs($web['ess_index_point']);
      if ($total2 < $total_point) {
        err('你目前货币值为'.$total2.'！总计需'.$total_point.'，差'.($total_point - $total2).'。货币值不足！请修改。');
      }
      @mysql_query('INSERT INTO `'.$sql['pref'].''.$sql['data']['承载财务数据的表名'].'` (`username`,`type`,`description`,`money`,`date`,`other`) VALUES ("'.$session[0].'","0","首页图文展示文章","-'.$total_point.'",DATE_ADD(UTC_TIMESTAMP(), INTERVAL '.floatval($web['time_pos']).' HOUR),"文章ID：'.implode('，', $_REQUEST['id']).'")', $db);

      $datetime = gmdate("Y-m-d H:i:s", time() + floatval($web["time_pos"]) * 3600 + $_POST['ess_index_topdate'] * 24 * 3600);
    } else {
      $datetime = '2037-'.gmdate("m-d H:i:s", time() + (floatval($web["time_pos"]) * 3600));
    }
    //@mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载主题文章的表名'].' SET topdate=DATE_ADD(UTC_TIMESTAMP(), INTERVAL '.(floatval($web['time_pos']) + $_POST['topdate'] * 24).' HOUR) WHERE '.$id_key.' AND author_ip="'.$session[0].'" AND area_check="0"', $db);

    @ require ('inc/function/img.php');
    foreach ($_REQUEST['id'] as $k => $v) {
      $result = @mysql_query('SELECT * FROM `'.$sql['pref'].''.$sql['data']['承载主题文章的表名'].'` WHERE id="'.$v.'" AND author_ip="'.$session[0].'" AND title_mark LIKE "%图%"', $db);
      if ($row = @mysql_fetch_assoc($result)) {
        //首页图文推荐，生成缩略图1.4+加
          $temp_thumb = 'thumb';
          if (preg_match('/<img [^>]*src[\s\r\n]*=(?![\s\r\n]*\"?('.preg_quote($web['path'], '/').')?inc\/images\/)[^>]*>/i', $row['text'], $mi)) {
            $thumb = preg_replace('/.+src[\s\r\n]*=[\s\r\n]*(\"|\')?([^\"\>\s]+\.(gif|jpg|png)).+/i', '$2', $mi[0]);
            $thumb_format = strtolower(ltrim(strrchr($thumb, '.'), '.'));
            $thumb_here = '__temp__/temp/'.$temp_thumb.'-'.$v.'.'.$thumb_format.'';
            if (stristr($thumb, 'obj.php?title=')) {
              $thumb = substr($thumb, 14);
              if (file_exists('__temp__/temp/'.$thumb)) {
                $thumb_contents = @file_get_contents('__temp__/temp/'.$thumb);
              } else {
                $result_e = @mysql_query('SELECT `text` FROM `'.$sql['pref'].''.$sql['data']['承载上传数据的表名'].'` WHERE title LIKE "thumb-'.$v.'.%" LIMIT 1', $db);
                if ($row_e = @mysql_fetch_assoc($result_e)) {
                  $thumb_contents = $row_e['text'];
                  unset($row_e);
                }
                @mysql_free_result($result_e);
              }
            } else {
              $thumb_contents = @file_get_contents($thumb);
            }
            if ($thumb_contents) {
              write_file($thumb_here, $thumb_contents);
              //if (run_img_resize($thumb_here, $thumb_here, 120, false, 75)) {
              run_img_resize($thumb_here, $thumb_here, 120, false, 75);
                $thumb_here = typeto($thumb_here, 'jpg');
                if ($thumb_content = @file_get_contents($thumb_here)) {
                  @mysql_query('REPLACE INTO `'.$sql['pref'].''.$sql['data']['承载上传数据的表名'].'` (`title`,`text`,`type`,`username`,`date`) VALUES ("'.basename($thumb_here).'","'.addslashes($thumb_content).'","image/jpeg","'.$row['author_ip'].'","'.$datetime.'")', $db);
                  unset($thumb, $thumb_format, $thumb_here, $thumb_contents, $thumb_content);
                }
              //}
            }
          }
        //over
        unset($row);
      }
      @mysql_free_result($result);
    }






  //置顶
  } elseif ($limit == 'top') {
    //求和信誉值
    $result = @mysql_query('SELECT SUM(money) AS total FROM '.$sql['pref'].''.$sql['data']['承载财务数据的表名'].' WHERE username="'.$session[0].'" AND type="1"', $db);
    $row = @mysql_fetch_assoc($result);
    $total1 = (float)$row['total'];
    unset($row);
    @mysql_free_result($result);
    //求和货币值
    $result = @mysql_query('SELECT SUM(money) AS total FROM '.$sql['pref'].''.$sql['data']['承载财务数据的表名'].' WHERE username="'.$session[0].'" AND type="0"', $db);
    $row = @mysql_fetch_assoc($result);
    $total2 = (float)$row['total'];
    unset($row);
    @mysql_free_result($result);

    require ('inc/function/top_mx.php');
    $may_top_num = top_mx($total1);
    if (POWER < 4) {
      if (!(is_numeric($_POST['topdate']) && $_POST['topdate'] >= abs($web['top_expires_member']))) {
        err('置顶时限要填大于起订天数（'.$web['top_expires_member'].'）的数字。');
      }
      $result = @mysql_query('SELECT COUNT(id) AS total FROM '.$sql['pref'].''.$sql['data']['承载主题文章的表名'].' WHERE author_ip="'.$session[0].'" AND topdate>DATE_ADD(UTC_TIMESTAMP(), INTERVAL '.floatval($web['time_pos']).' HOUR)', $db);
      $row = @mysql_fetch_assoc($result);
      $n_ = (int)$row['total'];
      @mysql_free_result($result);
      $now_top_num = $may_top_num - $n_;
      if (count($_REQUEST['id']) > $now_top_num) {
        err('你的信誉值所限，只能再置顶'.$now_top_num.'条，已置顶'.$n_.'/'.$may_top_num.'条。');
      }
      $total_point = count($_REQUEST['id']) * $_POST['topdate'] * abs($web['top_point']);
      if ($total2 < $total_point) {
        err('你目前货币值为'.$total2.'！总计需'.$total_point.'，差'.($total_point - $total2).'。货币值不足！请修改。');
      }
      @mysql_query('INSERT INTO `'.$sql['pref'].''.$sql['data']['承载财务数据的表名'].'` (`username`,`type`,`description`,`money`,`date`,`other`) VALUES ("'.$session[0].'","0","置顶文章","-'.$total_point.'",DATE_ADD(UTC_TIMESTAMP(), INTERVAL '.floatval($web['time_pos']).' HOUR),"文章ID：'.implode('，', $_REQUEST['id']).'")', $db);

    } else {
      $_POST['topdate'] = $web['top_expires'];
    }
    @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载主题文章的表名'].' SET topdate=DATE_ADD(UTC_TIMESTAMP(), INTERVAL '.(floatval($web['time_pos']) + $_POST['topdate'] * 24).' HOUR) WHERE '.$id_key.' AND author_ip="'.$session[0].'" AND area_check="0"', $db);

  //删帖——审核中
  } elseif ($limit == 'del_check') {
    //清理上传夹
    foreach ($_REQUEST['id'] as $id) {
      @mysql_query('DELETE FROM '.$sql['pref'].''.$sql['data']['承载上传数据的表名'].' WHERE (title LIKE "info-'.$id.'-%" OR title LIKE "reply-'.$id.'_%" OR title LIKE "thumb-'.$id.'.%" OR title LIKE "thuml-'.$id.'.%") AND username="'.$session[0].'"', $db);
      foreach ((array)@glob('__temp__/temp/{info-'.$id.'-,reply-'.$id.'_,thumb-'.$id.'.,thuml-'.$id.'.}*', GLOB_BRACE) as $f) @unlink($f);
    }

    @mysql_query('DELETE '.$sql['pref'].''.$sql['data']['承载主题文章的表名'].','.$sql['pref'].''.$sql['data']['承载关键词的表名'].' FROM '.$sql['pref'].''.$sql['data']['承载主题文章的表名'].' LEFT JOIN '.$sql['pref'].''.$sql['data']['承载关键词的表名'].' ON '.$sql['pref'].''.$sql['data']['承载关键词的表名'].'.id='.$sql['pref'].''.$sql['data']['承载主题文章的表名'].'.id WHERE ('.$sql['pref'].''.$sql['data']['承载主题文章的表名'].'.id="'.implode('" OR '.$sql['pref'].''.$sql['data']['承载主题文章的表名'].'.id="', $_REQUEST['id']).'") AND author_ip="'.$session[0].'" AND area_check<>"0"', $db);

  //删帖
  } elseif ($limit == 'del') {
    //清理上传夹
    foreach ($_REQUEST['id'] as $id) {
      @mysql_query('DELETE FROM '.$sql['pref'].''.$sql['data']['承载上传数据的表名'].' WHERE (title LIKE "info-'.$id.'-%" OR title LIKE "reply-'.$id.'_%" OR title LIKE "thumb-'.$id.'.%" OR title LIKE "thuml-'.$id.'.%") AND username="'.$session[0].'"', $db);
      foreach ((array)@glob('__temp__/temp/{info-'.$id.'-,reply-'.$id.'_,thumb-'.$id.'.,thuml-'.$id.'.}*', GLOB_BRACE) as $f) @unlink($f);
    }

    $step = 0;
    foreach ($_REQUEST['id'] as $id) {
      @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']['承载主题文章的表名'].'.id="'.$id.'" AND '.$sql['pref'].''.$sql['data']['承载主题文章的表名'].'.author_ip="'.$session[0].'"', $db);
      if (@mysql_affected_rows() > 0) {
        $step++;
        $area_d_arr[get_arearoot($_POST['area_id'][$id])]++;
      }
    }
    $now_point = '"point=IF(point-'.($step * $web['writeadd']).'>0,point-'.($step * $web['writeadd']).',\"0\"),writecount=IF(writecount-'.$step.'>0,writecount-'.$step.',\"0\")"';
    $now_point_session = '"".($row_member["point"] - '.($step * $web['writeadd']).' > 0 ? $row_member["point"] - '.($step * $web['writeadd']).' : 0).""';
	
    //更新统计
    require ('inc/function/area_statistics.php');
    foreach ((array)$area_d_arr as $k => $v) {
      add_total($k, $db, '-'.$v.'');
    }
    require ('inc/function/hot_mark.php');

  if (file_exists('get_newinfo_for162100_run.php')) {
    include ('get_newinfo_for162100_run.php');
  }

  } else {
    err('命令错误！');
  }


//回帖管理
} elseif ($dataname == 'reply') {

  if ($web['re_del'] != 1 && POWER < 4) {
    err('系统设置为：不允许用户删除自己的回复。');
  }

  //删帖——审核中
  if ($limit == 'del_check_reply') {
    //清理上传夹
    foreach ($_REQUEST['id'] as $id) {
      @mysql_query('DELETE FROM '.$sql['pref'].''.$sql['data']['承载上传数据的表名'].' WHERE title LIKE "reply-'.$_POST['url'][$id].'_'.$id.'-%" AND username="'.$session[0].'"', $db);
      foreach ((array)@glob('__temp__/temp/reply-'.$_POST['url'][$id].'_'.$id.'-*') as $f) @unlink($f);
    }
    @mysql_query('DELETE FROM '.$sql['pref'].''.$sql['data']['承载回复评论的表名'].' WHERE '.$id_key.' AND author_ip="'.$session[0].'" AND area_check_reply<>""', $db);

  //删帖
  } elseif ($limit == 'del') {
    //清理上传夹
    foreach ($_REQUEST['id'] as $id) {
      @mysql_query('DELETE FROM '.$sql['pref'].''.$sql['data']['承载上传数据的表名'].' WHERE title LIKE "reply-'.$_POST['url'][$id].'_'.$id.'-%" AND username="'.$session[0].'"', $db);
      foreach ((array)@glob('__temp__/temp/reply-'.$_POST['url'][$id].'_'.$id.'-*') as $f) @unlink($f);
    }
    //@mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载回复评论的表名'].' SET `text`="**** **** 此条已被作者删除" WHERE '.$id_key.' AND author_ip="'.$session[0].'"', $db);
    @mysql_query('DELETE FROM '.$sql['pref'].''.$sql['data']['承载回复评论的表名'].' WHERE '.$id_key.' AND author_ip="'.$session[0].'"', $db);
    $now_point = '"point=IF(point-".($end * '.$web['replyadd'].').">0,point-".($end * '.$web['replyadd'].').",\"0\"),replycount=IF(replycount-".$end.">0,replycount-".$end.",\"0\")"';
    $now_point_session = '"".($row_member["point"] - $end * '.$web['replyadd'].' > 0 ? $row_member["point"] - $end * '.$web['replyadd'].' : 0).""';
  } else {
    err('命令错误！');
  }


//短信管理
} elseif ($dataname == 'messbox') {

  $messlist = explode("\n", trim($row_member['mess']));
  $mess = $row_member['mess_num']; //显示中的未读
  unset($row_member);
  //时间|来信人|主题|内容|||已读状态

  if ($limit == 'messdel') {
    $messlist = preg_replace('/^('.implode('|', $_REQUEST['id']).')\|.+/', '', $messlist);
  } elseif ($limit == 'messover') {
    $messlist = preg_replace('/^(('.implode('|', $_REQUEST['id']).')\|[^\r\n]+)\|\s*$/', '$1|o', $messlist);
  } else {
    err('命令错误！');
  }
  $messlist = array_filter($messlist);
  $read_arr = preg_grep('/\|\s*$/', $messlist);
  $read_n = count($read_arr); //实际未读
  //if ($read_n != $mess) {
    $eval = ',mess_num="'.$read_n.'/'.count($messlist).'"'; //更新未读短信
  //}
  $newline = addslashes(@implode("\n", $messlist)."\n");

  //清理上传夹
  foreach ($_REQUEST['id'] as $id) {
    @mysql_query('DELETE FROM '.$sql['pref'].''.$sql['data']['承载上传数据的表名'].' WHERE title LIKE "mess-'.$id.'-%" AND username="'.$session[0].'"', $db);
    foreach ((array)@glob('__temp__/temp/mess-'.$id.'-*') as $f) @unlink($f);
  }

  @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' SET mess="'.$newline.'"'.$eval.' WHERE username="'.$session[0].'"', $db);


//加入我的收藏
} elseif ($dataname == 'myaccount') {
  if ($limit == 'collect_listdata') {
    $description = '';
    $runeval = '@mysql_query(\'INSERT INTO `'.$sql['pref'].''.$sql['data']['承载财务数据的表名'].'` (`username`,`type`,`description`,`money`,`date`) VALUES ("'.$session[0].'","2","'.$description.'","\'.$id.\'",DATE_ADD(UTC_TIMESTAMP(), INTERVAL '.floatval($web['time_pos']).' HOUR))\', $db);';
  } elseif ($limit == 'collect_reply') {
    $description = 'reply';
    $runeval = '@mysql_query(\'INSERT INTO `'.$sql['pref'].''.$sql['data']['承载财务数据的表名'].'` (`username`,`type`,`description`,`money`,`date`) VALUES ("'.$session[0].'","2","'.$description.'","\'.$id.\'",DATE_ADD(UTC_TIMESTAMP(), INTERVAL '.floatval($web['time_pos']).' HOUR))\', $db);';
  } elseif ($limit == 'del_collect_listdata') {
    $description = '';
  } elseif ($limit == 'del_collect_reply') {
    $description = 'reply';
  } elseif ($limit == 'fundssum') {

    //明细数量，看需不需要汇总余额
    $result = @mysql_query('SELECT COUNT(id) AS n FROM '.$sql['pref'].''.$sql['data']['承载财务数据的表名'].' WHERE (username="'.$session[0].'" AND type="0")', $db);
    if ($row = @mysql_fetch_assoc($result)) {
      $n = $row['count'] ? $row['count'] : 0;
      unset($row);
    }
    @mysql_free_result($result);

    if ($n < 100) {
      err('明细数量不多，可不必汇总！');
    } else {
      $m = 0;
      $result = @mysql_query('SELECT * FROM '.$sql['pref'].''.$sql['data']['承载财务数据的表名'].' WHERE (username="'.$session[0].'" AND type="0")', $db);
      while ($row = @mysql_fetch_assoc($result)) {
        $m += $row['money'];
        $text .= "".$row["description"]."|".$row["money"]."|".$row["date"]."\n";
	    unset($row);
      }
      @mysql_free_result($result);
      $funds_sum_file = 'fundssum-'.urlencode($session[0]).'-'.gmdate('YmdHis', time() + (floatval($web['time_pos']) * 3600)).'.txt';

      @mysql_query('DELETE FROM '.$sql['pref'].''.$sql['data']['承载财务数据的表名'].' WHERE (username="'.$session[0].'" AND type="0")', $db);
      @mysql_query('INSERT INTO '.$sql['pref'].''.$sql['data']['承载财务数据的表名'].' (`username`,`type`,`description`,`money`,`date`,`other`) VALUES ("'.$session[0].'","0","汇总余额","'.$m.'",DATE_ADD(UTC_TIMESTAMP(), INTERVAL '.floatval($web['time_pos']).' HOUR),"汇总日志：<a href=\"__temp__/temp/'.urlencode($funds_sum_file).'\" target=\"_blank\">'.$funds_sum_file.'</a>")', $db);
      write_file('__temp__/temp/'.$funds_sum_file.'', $text); //日志
      $out .= '请尽快将备份存到自己电脑中，以免在临时目录中被误删。';
    }

  } elseif ($limit == 'del_fundssum') {
    //foreach ($_REQUEST['id'] as $id) {
      @unlink('__temp__/temp/'.$_REQUEST['id'][0].'');
    //}
    err('<script> var obj=parent.$(\'fundsbackup_'.$_REQUEST['id'][0].'\'); var par=obj.parentNode; par.removeChild(obj); obj.style.display=\'none\'; </script>');

  } else {
    err('命令错误！');
  }

  if (isset($description)) {
    foreach ($_REQUEST['id'] as $id) {
      @mysql_query('DELETE FROM `'.$sql['pref'].''.$sql['data']['承载财务数据的表名'].'` WHERE username="'.$session[0].'" AND type="2" AND description="'.$description.'" AND money="'.$id.'.00"', $db);
      eval($runeval);
    }
  }
  if ($_REQUEST['m'] == 1) {
    err('<script> alert("操作成功！"); <'.'/'.'script>');
  }


} else {
  err('数据库名错误！');
}


$end = @mysql_affected_rows();

if ($end > 0) {
  if (isset($now_point)) { //把分减掉
    @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' SET '.eval('return '.$now_point.';').' WHERE username="'.$session[0].'"', $db);
    $cookie_time = time() + (floatval($web['time_pos']) * 3600);
    setcookie('usercookie', $session[0].'|'.$session[1].'|'.$session[2].'|'.(isset($now_point_session) ? eval('return '.$now_point_session.';') : $row_member['point']).'|'.$row_member['power'].'|'.$session[5].'|'.$session[6].'|'.$web['path'], (!empty($session[5]) && is_numeric($session[5]) && $session[5] > $cookie_time ? $session[5] : $cookie_time), '/', '.'.$web['root']);
    setcookie('usercookie', $session[0].'|'.$session[1].'|'.$session[2].'|'.(isset($now_point_session) ? eval('return '.$now_point_session.';') : $row_member['point']).'|'.$row_member['power'].'|'.$session[5].'|'.$session[6].'|'.$web['path'], (!empty($session[5]) && is_numeric($session[5]) && $session[5] > $cookie_time ? $session[5] : $cookie_time), '/');
  }
  alert('执行成功！'.$out, $_SERVER['HTTP_REFERER']);
} else {
  err('执行完毕（程序执行不完全或不成功。例如：1、未做更改；2、未通过审核的文章无法刷新或置顶等）。');
}
@mysql_close();


?>