<?php
error_reporting(0); 
include("../../config/qiantai.php");
session_start();
if(!isset($_SESSION['username'])){echo "<script>alert('请重新登录!')</script><script>top.location.href='/index$dshz'</script>";exit;}
$username=$_SESSION['username'];
$type="where name='$username'";
$user=queryall(user,$type);
$userid=$user['userid'];
if(!$user){echo "<script>alert('请重新登录!')</script><script>top.location.href='/index$dshz'</script>";exit;}
if(ubo($_POST)){
$cz=$_POST['cz'];
$bjs=$_POST['bjs'];
$postid=ubo($_POST['id']);
$postname=ubo(iconv("UTF-8","GB2312",$_POST['name']));  
$postlink=ubo(iconv("UTF-8","GB2312",$_POST['link']));
if($cz=='shanchu2'){
$type="id='$postid'";
dbdel(tlink,$type);
echo json_encode(array('zt'=>"1"));
}elseif($cz=='bj'){
if($postname==null){
$err=iconv("GB2312","UTF-8","站点名称不能为空");
echo json_encode(array('zt'=>"0",'msg'=>$err));
}else{
$type="name='$postname',bjs='$bjs' where id='$postid'";
upalldt(wangzhan,$type);
echo json_encode(array('zt'=>"1"));
}
}elseif($cz=='xg'){
if($postname==null){
$err=iconv("GB2312","UTF-8","广告词不能为空");
echo json_encode(array('zt'=>"0",'msg'=>$err));
}elseif($postlink==null){
$err=iconv("GB2312","UTF-8","推广链接不能为空");
echo json_encode(array('zt'=>"0",'msg'=>$err));
}else{
$type="link='$postlink',name='$postname' where id='$postid'";
upalldt(tlink,$type);
echo json_encode(array('zt'=>"1"));
}
}elseif($cz=='fb'){
$biaoshi=ubo($_POST['biaoshi']);
$pic=ubo($_POST['pic']);
if($postname==null){
$err=iconv("GB2312","UTF-8","广告词不能为空");
echo json_encode(array('zt'=>"0",'msg'=>$err));
}elseif($postlink==null){
$err=iconv("GB2312","UTF-8","推广链接不能为空");
echo json_encode(array('zt'=>"0",'msg'=>$err));
}else{
$type="where name='$postname'";
$tlink=queryall(tlink,$type);
if(!$tlink){
$type="(`id`, `userid`, `biaoshi`, `link`, `name`,`zt`, `bk`, `ztdx`, `xg`, `xgto`, `pic`) VALUES (null,'$userid','$biaoshi','$postlink','$postname','$zt','$bk','$ztdx','$xg','$xgto','$pic')"; 
dbinsert(tlink,$type);
}
echo json_encode(array('zt'=>"1"));
}
}elseif($cz=='wzfb'){
$biaoshi=random(100);
$type="where name='$postname'";
$wangzhan=queryall(wangzhan,$type);
if($postname==null){
$err=iconv("GB2312","UTF-8","站点名称不能为空");
echo json_encode(array('zt'=>"0",'msg'=>$err));
}elseif($wangzhan){
$err=iconv("GB2312","UTF-8","记录已经存在");
echo json_encode(array('zt'=>"0",'msg'=>$err));
}else{
$type="(`id`, `userid`, `name`, `biaoshi`,`bjs`) VALUES (null,'$userid','$postname','$biaoshi','$bjs')"; 
dbinsert(wangzhan,$type);
echo json_encode(array('zt'=>"1"));
}
}elseif($cz=='shanchu'){
$type="where id='$postid'";
$wangzhan=queryall(wangzhan,$type);
$userid=$wangzhan['userid'];
$type="userid='$userid'";
dbdel(tlink,$type);
$type="id='$postid'";
dbdel(wangzhan,$type);
echo json_encode(array('zt'=>"1"));
}elseif($cz=='shanchu3'){
$type="id='$postid'";
dbdel(lishi,$type);
echo json_encode(array('zt'=>"1"));

}elseif($cz=='dr'){
$biaoshi=iconv("UTF-8","GB2312",$_POST['biaoshi']); 
$sql = mysql_query("SELECT* FROM daili where  userid='$userid' and zt='已审核'");
$xinxi = mysql_num_rows($sql);
if($xinxi){
$query = mysql_query("SELECT * FROM daili where  userid='$userid' and zt='已审核'");
while($a = mysql_fetch_array($query)) {
$bjs='#'.randColor();
$ddhtz2=md5($a['zykey']);
$ddhtz=substr($ddhtz2,0,10);
$jjjjkkkkbbbburl='http://'.$url."/wx".random($size)."/".$a[zykey].$ddhtz.'ubodl';
$jjjjkkkkbbbb=urlencode($jjjjkkkkbbbburl);
$postlink=dwz($jjjjkkkkbbbb,$dwzjk);  
$type="where name='$a[name]'";
$tlink=queryall(tlink,$type);
if(!$tlink){
$type="(`id`, `userid`, `biaoshi`, `link`, `name`,`zt`, `bk`, `ztdx`, `xg`, `xgto`, `pic`) VALUES (null,'$userid','$biaoshi','$postlink','$a[name]','#ffffff','$bjs','18','1','1','$a[pic]')"; 
dbinsert(tlink,$type);
}
}
echo json_encode(array('zt'=>"1"));
}else{
$err=iconv("GB2312","UTF-8","暂无链接导入");
echo json_encode(array('zt'=>"0",'msg'=>$err));
}
}
}else{
$code=$_SERVER["REQUEST_URI"];
$html ='<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">';
$html.='<html><head>';
$html.='<meta charset="gb2312">';
$html.='<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />';
$html.='<title>404 Not Found</title>';
$html.='</head><body>';
$html.='<h1>Not Found</h1>';
$html.='<p>The requested URL '.$code.' was not found on this server.</p>';
$html.='</body>';
$html.='</html>';
echo $html;
exit;
}
?>
