<?php

/*网站设置*/
@ require ('writable/set/set_area.php');
@ require ('readonly/function/confirm_power.php');
define('POWER', confirm_power());

if (POWER != 5) {
  err('该命令必须以基本管理员身份登陆！请重登陆');
}
  
if (!preg_match('/^[\x80-\xff\w]{3,45}$/', $_POST['manager'])) {
  err('基础管理员名称不能空且请用汉字、数字、英文及下划线组成！长度范围为3-45字符！');
}
$_POST['manager'] = strtolower($_POST['manager']);
$_POST['password'] = strtolower($_POST['password']);

if ($_POST['password'] == '') {
  $psw = $web['password'];
} else {
  if (preg_match('/[\s\r\n]+/', $_POST['password'])) {
    err('基础管理员密码不能有空格。');
  }
  if (strlen($_POST['password']) > 30 || strlen($_POST['password']) < 3) {
    err('基础管理员密码长度是3-30字符。');
  }
  $psw = md162100($_POST['password']);
}

if (empty($_POST['cssfile'])) {
  $_POST['cssfile'] = 'default/0';
}
$style_cookie_unset = $style_set_unset = '';
if (isset($_COOKIE['myStyle']) && $_POST['cssfile'] != $_COOKIE['myStyle']) {
  $style_cookie_unset = '<script> document.cookie=\'myStyle=; path=/;\'; </script>';
}
if ($_POST['cssfile'] != $web['cssfile']) {
  @ require ('writable/set/set_html.php');
  if ($web['html'] == true) {
    $style_set_unset = '<div style="background-color:#FF6600; color:#FFF;">你对系统风格进行了更改，因为你开启了全静态，为刷新所有静态文件风格样式，请进行<a href="?post=manager_html_open">一键生成全静态</a>
</div>';
  }
}

function md162100($str) {
  return substr(sha1(md5($str)), 4, 32);
}
@ require ('readonly/function/filter.php');

/*
$sbar = @glob('readonly/js/search_bar_*.js');
$sbar_n = @count($sbar);
*/
$sbar_n = 3;

$text = '<?php
@ini_set(\'default_charset\', \'utf-8\');
@ini_set(\'display_errors\', false);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
if (PHP_VERSION < \'4.1.0\') {
  $_GET = &$HTTP_GET_VARS;
  $_POST = &$HTTP_POST_VARS;
  $_COOKIE = &$HTTP_COOKIE_VARS;
  $_SERVER = &$HTTP_SERVER_VARS;
  $_ENV = &$HTTP_ENV_VARS;
  $_FILES = &$HTTP_POST_FILES;
}

/* ----------【网站设置】能不用尽量不要用特殊符号，如 \ / : ; * ? \' < > | ，必免导致错误--------- */

//基本设置：
$web[\'code_author\'] = \'\'; //base64_decode(\'IC0gUG93ZXJlZCBieSAxNjIxMDAuY29t\');

$web[\'manager\'] = \''.$_POST['manager'].'\';  //基础管理员名称
$web[\'password\'] = \''.$psw.'\';  //基础管理员密码，注：系统出现一切故障时以基础管理员名称和密码为准

$web[\'sitehttp\'] = \'http://\'.(!empty($_SERVER[\'HTTP_X_FORWARDED_HOST\']) ? $_SERVER[\'HTTP_X_FORWARDED_HOST\'] : $_SERVER[\'HTTP_HOST\']).\'/\';  //站点网址
$web[\'path\'] = dirname(trim($web[\'sitehttp\'], \'/\').$_SERVER[\'REQUEST_URI\'].\'.abc\').\'/\';  //路径
$web[\'sitename\'] = \''.(!empty($_POST['sitename']) ? filter1($_POST['sitename']) : '我的网站').'\';  //站点名称
$web[\'sitename2\'] = \''.(!empty($_POST['sitename2']) ? filter1($_POST['sitename2']) : '我的网站').'\';  //站点简称
$web[\'description\'] = \''.filter1($_POST['description']).'\';  //站点描述
$web[\'keywords\'] = \''.filter1($_POST['keywords']).'\';  //关键字
$web[\'slogan\'] = \''.filter1($_POST['slogan']).'\';  //口号
$web[\'link_type\'] = '.($_POST['link_type'] != 1 ? 0 : 1).';  //通过export.php?url=链接路径 中转链接
$web[\'login_key\'] = '.var_export($_POST['login_key'], true).';
$web[\'login_key_show\'] = '.($_POST['login_key_show'] != 1 ? 0 : 1).';  //1首页显示各接口小图标

$web[\'chmod\'] = \''.(!preg_match('/^0?([0-7]{3})$/', $_POST['chmod'], $matches_chmod) ? '777' : $matches_chmod[1]).'\';  //权限
if (empty($web[\'chmod\']) || $web[\'chmod\'] < 755) {
  $web[\'chmod\'] = 755;
}
$web[\'time_pos\'] = \''.$_POST['time_pos'].'\';  //服务器时区调整
$web[\'cssfile\'] = \''.$_POST['cssfile'].'\';  //站点默认风格
$web[\'search_bar\'] = '.(abs($_POST['search_bar']) > abs($sbar_n) ? 1 : abs($_POST['search_bar'])).';  //默认搜索引擎样式

$web[\'stop_reg\'] = '.($_POST['stop_reg'] != 1 && $_POST['stop_reg'] != 2 ? 0 : $_POST['stop_reg']).';  //用户注册 1禁止 0不禁止 2注册需审核
$web[\'mail_send\'] = '.(abs((int)$_POST['mail_send']) != 1 ? 0 : 1).';  //1发送邮件 0不发送
$web[\'stop_login\'] = '.abs($_POST['stop_login']).';  //用户登录密码错误限数 0不限

$web[\'addfunds\'] = '.(abs((int)$_POST['addfunds']) != 1 || !file_exists('addfunds.php') ? 0 : 1).';  //1开启用户创收模式
$web[\'loginadd\'] = '.round((float)$_POST['loginadd'], 3).';  //用户登陆（含注册）、推广URL来访本站赠送货币值
$web[\'loginadd2\'] = '.round((float)$_POST['loginadd2'], 4).';  //从上线分成
$web[\'loginadd_limit_ip\'] = '.abs($_POST['loginadd_limit_ip']).';  //每IP每日限注册次数计赠货币值
$web[\'cash\'] = '.round((float)$_POST['cash'], 2).';  //用户提现需达到

?>';


$sqlaccess = '';
if ($_POST['manager'] != $web['manager'] || $psw != $web['password']) {
  if (!isset($sql['db_err'])) {
    db_conn();
  }
  if ($sql['db_err'] == '') {
    if (@mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' SET username="'.$_POST['manager'].'",password="'.$psw.'" WHERE username="'.$web['manager'].'" LIMIT 1', $db)) {
	
    //if (@mysql_affected_rows() > 0) {
	//echo 'mysql:'.mysql_errno().':'.mysql_error();
      if ($_POST['manager'] != $web['manager']) {
        @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载财务数据的表名'].' SET username="'.$_POST['manager'].'" WHERE username="'.$web['manager'].'"', $db);
      }
      $sqlaccess = '<div style="background-color:#FF6600; color:#FFF;">数据库管理员名称和密码副本同时更新成功。由于管理员信息被改动，建议重新登陆以使新设置生效！</div>
      <script language="javascript" type="text/javascript">
      <!--
      var expiration=new Date((new Date()).getTime()-86400000);
      document.cookie="usercookie="+""+"; expires="+expiration.toGMTString()+"; path="+"/"+";";
      -->
      </script>';
    }
  }
  @mysql_close();
  if ($sqlaccess == '') {
    err('由于基础管理员信息(如名称或密码)有变，但数据库连接不成功！拒绝此次修改。请先<a href="?get=sql">连接数据库</a>');
  }
}

@ require ('readonly/function/write_file.php');
write_file('writable/set/set.php', $text);


if (($text_s = @file_get_contents('readonly/js/main.js')) && is_writable('readonly/js/main.js')) {
  $text_s = preg_replace('/\/\* time_pos \*\/.+\/\* \/time_pos \*\//isU', '/* time_pos */
  var timePos = '.floatval($_POST['time_pos']).'; //时区
  /* /time_pos */', $text_s);
  write_file('readonly/js/main.js', $text_s);
}
unset($text_s);

if (!empty($_POST['search_type_id'])) {
  $search_edit = false;
  list($search_type, $search_id) = @explode('-', $_POST['search_type_id']);
  //if (preg_match('/^(shangpin|wangye|tupian|yinyue|shipin|xinwen|youxi|ditu)$/i', $search_type)) {
  if ($search_type && $search_id) {
    if ($text_s = @file_get_contents('writable/js/search.js')) {
      $text_s = preg_replace('/\/\* search_default_bar \*\/.+\/\* \/search_default_bar \*\//isU', '/* search_default_bar */
var search_default_type = \''.$search_type.'\';
var search_default_id = \''.$search_id.'\';
/* /search_default_bar */', $text_s);
      write_file('writable/js/search.js', $text_s);
      $search_edit = true;
    }
    unset($text_s);
  }
  if ($search_edit == false) {
    $sqlaccess .= '<div style="background-color:#FF6600; color:#FFF;">默认搜索类型设置失败！</div>';
  }
}

if (isset($_POST['referrer_top'])) {
  if ($_POST['referrer_top'] == 1) {
    @ copy('writable/css/referrer_top.js', 'writable/js/referrer_top.js');
  } else {
    @ unlink('writable/js/referrer_top.js');
  }
}

if (isset($_POST['newinfo'])) {
  if ($_POST['newinfo'] == 1) {
    @ copy('writable/css/newinfo.php', 'writable/require/newinfo.php');
  } else {
    @ unlink('writable/require/newinfo.php');
  }
}

if (!empty($_POST['index_mod'])) {
  if (file_exists('./index_'.$_POST['index_mod'].'.php')) {
    @ copy('index_'.$_POST['index_mod'].'.php', 'index.php');
  }
}

/*
if ($_POST['index_mod'] == 'search') {
  if (filesize('index_search.php') != filesize('index.php'))
    @ copy('index_search.php', 'index.php');
} else {
  if (filesize('index_complete.php') != filesize('index.php'))
    @ copy('index_complete.php', 'index.php');
}
*/



reset_indexhtml('index.php', 'index.html');

if ($style_set_unset != '') {
  err('设置系统参数成功！'.$sqlaccess.$style_cookie_unset.$style_set_unset, 'ok');
} else {
  alert('设置系统参数成功！'.$sqlaccess.$style_cookie_unset, 'webmaster_central.php?get=set');
}



?>