<?php
error_reporting(0);
session_start();
include_once '../comm/config.php';
include_once '../comm/checkpostandget.php';
include_once '../comm/wjt.php';
include_once 'check.php';
include_once 'page.class.php';
include '../data/expression.php';

$shai_set=include '../data/shai.php';
$shaicat_arr=$shai_set['shai_cat'];

$keyword=$_GET["keyword"]; 
$act=$_GET['act']?$_GET['act']:'share';
$page = !($_GET['page'])?'1':intval($_GET['page']);
$pagesize=5;
$page2=($page-1)*$pagesize;
	
if($act=='shai'){
	$sql="select a.item_title,a.seller_nick,a.num_iid,a.pay_price,a.fxje,b.image,b.id,b.catid,b.hart,b.hits,b.trade_id,b.click_url from ".$BIAOTOU."tradelist as a,".$BIAOTOU."shai as b where b.xs='shai' and a.outer_code='".$_SESSION["dduserid"]."' and a.Id=b.trade_id";
	$rs = mysql_query($sql);
	$total = mysql_num_rows($rs);	
	$sql="select a.item_title,a.seller_nick,a.num_iid,a.pay_price,a.fxje,b.image,b.id,b.catid,b.hart,b.hits,b.trade_id,b.click_url from ".$BIAOTOU."tradelist as a,".$BIAOTOU."shai as b where b.xs='shai' and a.outer_code='".$_SESSION["dduserid"]."' and a.Id=b.trade_id order by a.Id desc limit $page2,$pagesize";
	$rs = mysql_query($sql);
}
	
if($act=='share'){
	$sql="select id,title,image,price,fxje,catid,hits,hart,url,click_url,tao_id from ".$BIAOTOU."shai where dduserid='".$_SESSION["dduserid"]."' and xs='share'";
	$rs = mysql_query($sql);
	$total = mysql_num_rows($rs);	
	$sql="select id,title,keywords,image,price,fxje,catid,hits,hart,url,click_url,tao_id from ".$BIAOTOU."shai where dduserid='".$_SESSION["dduserid"]."' and xs='share' order by id desc limit $page2,$pagesize";
	$rs = mysql_query($sql);
}

if($_SESSION["dduserlevel"]<$shai_set['limit_level']){
    $buyid=0;
}
else{
    $buyid=1;
}

$tag="center";
$current='baobei';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>我的晒单分享 - 用户中心</title>
<link href="../template/<?=MOBAN?>/css/usercss.css" rel="stylesheet" type="text/css">
<link href="../template/<?=MOBAN?>/css/redirect.css" rel="stylesheet" type="text/css" />
<link href="../template/<?=MOBAN?>/css/common.css" rel="stylesheet" type="text/css">
<style type="text/css">
#newPreview{filter: progid: DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);}
#apDiv022{width: 715px;height: 88px;border-bottom-width: 1px;border-bottom-style: dashed;border-bottom-color: #CCCCCC;margin-top: 10px;float: left;}
#apDiv25{width: 70px;height: 70px;padding: 5px;float: left;border: 1px dotted #CCCCCC;margin-bottom: 5px;}
#apDiv066{width: 620px;height: 85px;float: right;}
#apDiv199{height: 40px;line-height: 40px;overflow: hidden;margin-right: 5px;}
</style>
<script type="text/javascript" src="../template/<?=MOBAN?>/js/jquery.js"></script>
</head>

<body>
<?php
include("../template/".MOBAN."/header.tpl.php");
?>
<?php
include("../template/".MOBAN."/nav.tpl.php");
?>
<script>
commentDefaultVal='说说你对这件宝贝的评价吧';

function addExpression(myField, myValue)
{
    myField = document.getElementById(myField);
	if(myField.value==commentDefaultVal) myField.value='';
    //IE
    if (document.selection)
    {
        myField.focus();
        sel = document.selection.createRange();
        myValue = myValue;
        sel.text = myValue;
        sel.select();
    }
    //MOZILLA
    else if (myField.selectionStart || myField.selectionStart == '0')
    {
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;
        // save scrollTop before insert
        var restoreTop = myField.scrollTop;
        myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos,myField.value.length);
        if (restoreTop > 0)
        {
            // restore previous scrollTop
            myField.scrollTop = restoreTop;
        }
        myField.focus();
        myField.selectionStart = startPos + myValue.length;
        myField.selectionEnd = startPos + myValue.length;
    }
    else
    {
        myField.value += myValue;
        myField.focus();
    }
}

$.ajaxSetup ({
    cache: false //关闭AJAX相应的缓存
});
msgErr=new Array();
msgErr[5]='您已经分享过这件商品';
msgErr[6]='您没有购买过商品，不能评论';
msgErr[7]='您提交的信息不全';
msgErr[8]='评论不能为空或者含有敏感词';
msgErr[9]='必须添加图片';

function closeShare(){
    $('.LightBox').hide();
	$('#jumpbox2').hide();
	$('#title').val('');
	$('#url').val('');
	$('#price').val('');
	$('#tao_img').val('');
	$('#keywords').val('');
	$('#comment').val(commentDefaultVal);
	$('#J_ImgBooth').attr('src','images/ad.jpg');
	$('#num').text(80);
}

/*这里开始时UrlEncode和UrlDecode函数*/
function UrlEncode(str){
var ret="";
var strSpecial="!\"#$%&'()*+,/:;<=>?[]^`{|}~%";
var tt= "";

for(var i=0;i<str.length;i++){
var chr = str.charAt(i);
var c=str2asc(chr);
tt += chr+":"+c+"n";
if(parseInt("0x"+c) > 0x7f){
ret+="%"+c.slice(0,2)+"%"+c.slice(-2);
}else{
if(chr==" ")
ret+="+";
else if(strSpecial.indexOf(chr)!=-1)
ret+="%"+c.toString(16);
else
ret+=chr;
}
}
return ret;
}
function UrlDecode(str){
var ret="";
for(var i=0;i<str.length;i++){
var chr = str.charAt(i);
if(chr == "+"){
ret+=" ";
}else if(chr=="%"){
var asc = str.substring(i+1,i+3);
if(parseInt("0x"+asc)>0x7f){
ret+=asc2str(parseInt("0x"+asc+str.substring(i+4,i+6)));
i+=5;
}else{
ret+=asc2str(parseInt("0x"+asc));
i+=2;
}
}else{
ret+= chr;
}
}
return ret;
}

function getTaoItem(url){
    if(url==''){
		alert('网址不能为空！');
	}
	else{
		if (!url.match(regExp)){
		    alert('这不是一个淘宝网址！');
		}
		else{
			$('#J_ImgBooth').attr('src','<?=$navheadurl?>images/wait.gif');
		    $.post("<?=$navheadurl?>a.php",{'fun':'get_tao_img','url':url,'xs':'share'},function(data){//alert(data);
		        var data= eval("(" + data + ")");
				$('#radio'+data.cid).attr("checked",true);
		        $('#title').val(data.title);
				$('#price').val(data.price);
				$('#url').val(url);
			    $('#J_ImgBooth').attr('src',data.img);
				$('#tao_img').val(data.img);
			    $('#dopic').hide('normal');
				clickUrl=data.clickUrl;
				nick=data.nick;
		    });
		}
	}
}

regExp = /(.*\.?taobao.com(\/|$))|(.*\.?tmall.com(\/|$))/i;
$(function(){
    $('.close').click(closeShare);
	$('#noShare').click(function(){alert('您的等级不足，不能分享宝贝！');});
	$('#startShare').click(function(){
		dduserid=<?=$_SESSION['dduserid']?$_SESSION['dduserid']:0?>;
		if(dduserid>0){
		    $('.LightBox').show();
			$('#jumpbox2').show();
			$('#jiantou').css('left','118px');
		    $('#tishi').html('在此直接粘贴宝贝的链接地址');
			$('#dopic').show('normal');
			$('#tao_url').val('');
		}
		else{
		    alert('登陆后才可分享商品！');
			window.location='user/login.php?url='+encodeURIComponent(location.href);
		}
	    
	});
	/*$('#url').blur(function(){
		var url=$('#url').val();
		if(url!=''){
		    getTaoItem(url);
		}
	});*/
	$('#get_tao_img').click(function(){
	    var url=$('#tao_url').val();
		var f=$(this).attr('f');
		if(f=='html'){
			getTaoItem(url);
		}
		else if(f=='jpg'){
			if(url==''){
		        alert('网址不能为空！');
	        }
			else{
			    $('#J_ImgBooth').attr('src',url);
			    $('#tao_img').val(url);
			    $('#dopic').hide('normal');
			}
		} 
	});
	$('#shaiForm').submit(function(){
        var title=$('#title').val();
		var url=$('#url').val();
		var price=$('#price').val();
		var tao_img=$('#tao_img').val();
		var keywords=jQuery.trim($('#keywords').val());
		var comment=$('#comment').val();
		//temp = comment.replace(/{.*?}/gim,""); //过滤表情字符
		var catid = $("input[name='shaicat'][type='radio']:checked").val();
        var l=keywords.split(/\s+/).length;
		var num=parseInt($('#num').text());
		var regExp = /(.*\.?taobao.com(\/|$))|(.*\.?tmall.com(\/|$))/i;
		if(title==''){
		    alert('填写商品名称！');
			$('#title').focus();
		}
		else if(url==''){
		    alert('填写商品网址！');
			$('#url').focus();
		}
		else if (!url.match(regExp)){
		    alert('这不是一个淘宝网址！');
			$('#url').focus();
		}
		else if(price==''){
		    alert('填写商品价格！');
			$('#price').focus();
		}
		else if(tao_img=='' || tao_img=='images/wait.gif' || tao_img=='_310x310.jpg'){
		    alert('商品加载失败！');
			/*$('#jiantou').css('left','80px');
		    $('#tishi').html('在此直接粘贴宝贝的链接地址');
			$('#picFun').show();
		    $('#dopic').show('normal');*/
		}
		else if(typeof catid=='undefined'){
		    alert('选择分类');
		}
		/*else if(temp==''){
		    alert('说点什么吧，不要只发表情哦');
		}*/
		else if(num<0){
		    alert('内容超限！');
			$('#comment').focus();
		}
		else if(comment=='' || comment==commentDefaultVal){
		    alert('请添加评论内容！');
			$('#comment').focus();
		}
		else if(l>5){
		    alert('最多填写5个关键词');
			$('#keywords').focus();
		}
		else{
			$('#subShare').attr('disabled','disabled');
		    $.post("<?=$navheadurl?>a.php",{fun:'save_share',title:title,url:url,price:price,image:tao_img,keywords:keywords,comment:comment,catid:catid,'click_url':clickUrl,'nick':nick},function(data){//$('#title').val(data);
				var data= eval("(" + data + ")");
				if(data.err==0){
				    alert('提交成功');
					$('#subShare').attr('disabled','');
					document.execCommand('Refresh');//closeShare();
				}
				else{
				    alert(msgErr[data.msg]);
					$('#subShare').attr('disabled','');
				}
		    });
		}
		return false;
	});
	$('#comment').bind('focus keyup input paste',function(){  //采用几个事件来触发（已增加鼠标粘贴事件）   
	     $('#num').text(80-$(this).attr("value").length)  //获取评论框字符长度并添加到ID="num"元素上  
	});
	$('.picfunc a:not(#openem)').click(function(){
	    var left=$(this).attr('left');
		var tishi=$(this).attr('val');
		var f=$(this).attr('f');
		if(f=='jpg'){$('#tao_url').val('');}
		$('#jiantou').css('left',left);
		$('#tishi').html(tishi);
		$('#dopic').show('normal');
		$('#get_tao_img').attr('f',f);
	});
})
</script><DIV style="MARGIN-TOP: 25px"></DIV>
<div id="main"><DIV class=white_top>
<DIV class=white_top_left></DIV>
<DIV class=white_top_middle></DIV>
<DIV class=white_top_right></DIV></DIV>
<DIV class=white_bg_rl>
<?php
include("left.php");
?>
<div class="contain">
  <h2 class="left_nav2">我的晒单分享 <span><input <?php if($buyid==1){?> id="startShare" <?php }else{?> id="noShare" <?php }?> type="button" style="background:url('../images/shaib.gif'); border:none; width:100px; height:28px; color:#FFF; font-weight:bold; cursor:pointer" value="分享我喜欢的" /></span></h2>
    <div class="order">
      <div class="title">
          <ul>
  			<li><a style="MARGIN-LEFT: 10px" <?php if($act=='share') echo "class=\"current\"";?> href="baobei.php?act=share">我分享的宝贝</a></li>
  			<li><a style="MARGIN-LEFT: 10px" <?php if($act=='shai') echo "class=\"current\"";?> href="baobei.php?act=shai">我的晒单宝贝</a></li>
          </ul>
      </div>  
    
    <?php if($act=='shai'){?>
<?php while($row=mysql_fetch_array($rs)){?>
<div id="apDiv022">
<div id="apDiv25"><a href="../baobei.php?id=<?=$row["id"]?>" target="_blank"><img src="<?=$row["image"]?>" width="70" height="70" /></a></div>
<div id="apDiv066">
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="color:#999999;">
  <tr>
    <td width="35%" height="40">&nbsp;<a href="../baobei.php?id=<?=$row["id"]?>" target="_blank"><?=$row["item_title"]?></a></td>
    <td width="21%">&nbsp;原价：<?=$row["pay_price"]?></td>
    <td width="22%">&nbsp;点击：<?=$row["hits"]?></td>
    <td width="22%">&nbsp;类别：<?=$shaicat_arr[$row["catid"]]?></td></tr>
  <tr>
    <td height="40"><div id="apDiv199">&nbsp;掌柜：<a href="../shop.php?nick=<?=urlencode($row["seller_nick"])?>"><?=$row["seller_nick"]?></a></div></td>
    <td><div id="apDiv199">&nbsp;返现：<?=$row["fxje"]?></div></td>
    <td colspan="2">&nbsp;红心：<?=$row["hart"]?></td>
    </tr>
</table>
</div></div>
<?php }?>
    <?php }?>
    
    <?php if($act=='share'){?>
<?php while($row=mysql_fetch_array($rs)){?>
<div id="apDiv022">
<div id="apDiv25"><a href="../baobei.php?id=<?=$row["id"]?>" target="_blank"><img src="<?=$row["image"]?>" width="70" height="70" /></a></div>
<div id="apDiv066">
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="color:#999999;">
  <tr>
    <td width="35%" height="40">&nbsp;<a href="../baobei.php?id=<?=$row["id"]?>" target="_blank"><?=$row["title"]?></a></td>
    <td width="21%">&nbsp;原价：<?=$row["price"]?></td>
    <td width="22%">&nbsp;点击：<?=$row["hits"]?></td>
    <td width="22%">&nbsp;类别：<?=$shaicat_arr[$row["catid"]]?></td></tr>
  <tr>
    <td height="40"><div id="apDiv199">&nbsp;标签：<?=$row["keywords"]?></div></td>
    <?php
	if($row['fxje']>0){
        if(WEBTYPE==1){
	        $gotoitem="../view.php?iid=".$row['tao_id'];
	    }
	    else{
	        $gotoitem="../list.php?iid=".$row['tao_id'];
	    }
    }
    else{
        $gotoitem="http://item.taobao.com/item.htm?id=".$row['tao_id'];
    }
	?>
    <td><div id="apDiv199">&nbsp;网址：<a target="_blank" href="<?=$gotoitem?>">点击连接</a></div></td>
    <td colspan="2">&nbsp;红心：<?=$row["hart"]?></td>
    </tr>
</table>
</div></div>
<?php }?>

    <?php }?>
    
	</div>
</div>
<?php if($act!='add'){?>
<div class="megas512" style="clear:both"><?php pageft($total,$pagesize,1,1,0,10,"baobei.php?act=".$act."");	echo $pagenav;?></div>
<?php }?>
</div>
<?php
include("../template/".MOBAN."/footer.tpl.php");
mysql_close();
?>
<div id="jumpbox2" class="jumpbox2" ><div class="top_left"></div><div class="top_center"></div><div class="top_right"></div><div class="middle_left"></div>
  <div class="middle_center">
    <div class="close"><a style="cursor:pointer"></a></div>
    <div class="w" style=" margin-top:0px; ">
    <div style="height:30px;">
    <div class="shaicat" style="margin-top:15px; margin-left:10px">
      <ul>
        <?php foreach($shaicat_arr as $k=>$v){?>
        <li><input name="shaicat" value="<?=$k?>" type="radio" id="radio<?=$k?>"> <label for="radio<?=$k?>"><?=$v?></label></li>
        <?php }?>
      </ul>
    </div>
    </div>
    <div class="form" style="width:540px; height:80px; margin-top:10px; position:relative; left:15px; z-index:999; clear:both;">
      <form id="shaiForm" style="position:relative; z-index:99">
      <div id="expression" style="left:0px">
      <ul>
		<?php foreach($expression as $k=>$v){?>
        <li><img src="<?=$navheadurl?>images/emoticons/<?=$k?>.gif" style="cursor:pointer" onclick="addExpression('comment','{<?=$v?>}');"/></li>
		<?php }?>
      </ul>
      <div style=" float:left; margin-left:2px;cursor:pointer; width:30px" onclick="$('#expression').fadeOut('slow');">关闭</div>
      </div>
        <div style="float:left; width:446px; height:62px;">
          <textarea id="comment" onfocus="if(this.value==commentDefaultVal){this.value=''};" style="width:440px; height:12px; line-height:12px; padding-top:5px; padding-bottom:40px; padding-left:4px; color:#999999; border:2px solid #F64B78"><?php if($buyid==0){?>您的等级不足，不能分享宝贝！<?php }else{?>说说你对这件宝贝的评价吧<?php }?></textarea>
        </div>
        <div style="float:left; margin-left:3px; width:80px; height:62px; margin-top:1px">
          <input id="subShare" type="submit" style="background:none; border:0; font-size:18px; width:80px; height:36px; background:#EE373C; color:#FFF; font-weight:bold; cursor:pointer" value="发 布" <?php if($buyid==0){?> disabled="disabled"<?php }?>/>
        </div>
        <input type="hidden" value="" id="trade_id" />
        <input type="hidden" value="" id="tao_img" />
        <div style="clear:both"></div>
      </form>
      <div style="width:444px;margin-top:5px; position:relative;" class="picfunc">
        <div class="picfunc" style="float:left; width:300px;">
          <a onclick="$('#expression').fadeIn('slow');" left="19px" id="openem" style="background:url(<?=$navheadurl?>images/icons.gif) no-repeat; padding-left:18px; width:57px; height:18px; line-height:18px; display:block; float:left">添加表情 | </a> 
          <a f='html' left="118px" val="在此直接粘贴宝贝的链接地址" style="background:url(<?=$navheadurl?>images/icons.gif) no-repeat 0px -17px; padding-left:18px; width:57px; height:18px; line-height:18px; display:block; float:left; margin-left:5px">宝贝链接 </a> 
        </div>
        <div style="float:right; width:130; color:#666">还可以输入<b id="num" style="font-size:14px; color:#EF363C">80</b>个字</div>
      </div>
      <div id="dopic" style="position:absolute; width:394px; height:68px; top:79px; left:0px; z-index:99; display:none">
        <div style="height:6px; overflow:hidden"><div id="jiantou" style="background:url(<?=$navheadurl?>images/icon.gif) -74px -103px; width:10px; height:6px; z-index:2; position:relative;"></div></div>
        <div style="background:url(<?=$navheadurl?>images/shai-bg.gif); width:394px; height:62px; margin-top:-1px; _margin-top:0px; z-index:1">
          <div style="position:relative; left:12px; top:12px; width:374px; height:42px">
            <div style="height:15px">
              <div style="float:left; width:200px; color:#656565" id="tishi"></div>
              <div onclick="$('#dopic').hide('normal');" style="float:right; width:12px; height:12px; background:url(<?=$navheadurl?>images/icon.gif) -56px -105px; cursor:pointer"></div>
            </div>
            <form style="height:25px; margin-top:2px">
              <div style="width:326px; float:left ">
                <input id="tao_url" type="text" style="width:324px; height:20px; border:1px solid #CFCFCF;background:#FFF; line-height:20px" />
              </div>
              <div style="float:left; height:25px; margin-left:3px;">
                <input f='html' id="get_tao_img" type="button" style="border:1px solid #CFCFCF; background:#F7F7F7; width:40px; height:24px; text-align:center; line-height:24px; color:#000; cursor:pointer" value="确定" />
              </div>
            </form>
            
          </div>
        </div>
      </div>
    </div>
    <div style="clear:both"></div>
    <div id="goodsinfo" style="margin-top:15px; margin-left:15px; width:540px; height:120px">
        <div style="float:left; width:120px;"><img id="J_ImgBooth" src="<?=$navheadurl?>images/no_news.gif" width="120" height="120" /></div>
        <div style="float:left; width:330px; height:150px; margin-left:5px">
          <div style="font-size:14px; padding-top:1px">名称：<input readonly="readonly" id="title" type="text" style=" width:250px; height:20px; border:0; line-height:20px" /></div>
          <div style="font-size:14px; padding-top:1px; margin-top:5px;">链接：<input readonly="readonly" id="url" type="text" style=" width:250px; height:20px; border:0; line-height:20px" /></div>
          <div style=" font-size:14px; padding-top:1px; margin-top:5px;">价格：<input readonly="readonly" type="text" style=" width:30px; height:20px; border:0; line-height:20px" id="price" /> 元</div>
          <div style=" font-size:14px; color:#666666; margin-top:15px;">
            <div style=" font-size:12px;"><b style="color:#333">打标签：</b>填写商品关键字，用空格隔开</div>
            <div style="margin-top:5px"><input id="keywords" type="text" style=" width:316px; height:20px; border:1px solid #9A9B9B; line-height:20px" /></div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="middle_right"></div><div class="end_left"></div><div class="end_center"></div><div class="end_right"></div></div><DIV class=white_bottomm>
<DIV class=white_bottom_left></DIV>
<DIV class=white_bottom_middle></DIV>
<DIV class=white_bottom_right></DIV></DIV></div>
</body>
</html>