<?php
@ require ('readonly/function/confirm_power.php');
define('POWER', confirm_power());

if (POWER == 0) {
  err('<script> alert("请登陆或注册帐号！先"); </script>');
}
@ require ('readonly/function/filter.php');
$_REQUEST['linkhttp'] = preg_replace('/^(https?:\/\/[^\/]+)\/?$/', '$1/', filter1($_REQUEST['linkhttp']));
$_REQUEST['linkname'] = filter1(strip_tags($_REQUEST['linkname']));
if (!empty($_REQUEST['linkhttp']) && !empty($_REQUEST['linkname'])) {
  $text = '<span><a onclick="addM(this)" href="'.$_REQUEST['linkhttp'].'">'.$_REQUEST['linkname'].'</a></span>';

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

  $result = @mysql_query('SELECT *,LENGTH(collection)+0 AS l FROM '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' WHERE username="'.$session[0].'" LIMIT 1', $db);
  $row = @mysql_fetch_assoc($result);
  @mysql_free_result($result);

  if ($row['l'] + strlen($text) > 40000) {
    err('<script> alert("自定义收藏数据量过大（大于40000字节）！请减小数据库的数据量"); </script>');
  }


  //操作前再深层判断一下权限，v3.3加
  if ($session[1].'|'.$session[2] != $row['session_key']) {
    err('<script> alert("经系统检验权限，你的身份密钥不符，关键操作！请重登陆修正！"); </script>');
  }

  if (@mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' SET collection=CONCAT(collection,"'.addslashes($text).'") WHERE username="'.$session[0].'" AND collection NOT REGEXP "<a [^>]*=\"'.preg_quote($_REQUEST['linkhttp'], '/').'\"[^>]*>"', $db)) {

  //if (@mysql_affected_rows() > 0) {
    err('<script> alert("OK！已加入首页“收藏”中"); if (top.$("collection")!=null){try{top.doXMLHTTP("collection", "member.php?post=member_collection_show");}catch(err){}} </script>');
  } else {
    err('<script> alert("添加不成功！数据库中已存在该记录"); </script>');
  }

  @mysql_close();

} else {

  err('<script> alert("参数传递出错！"); </script>');

}


?>