<?php
//引入模块公共方法文件
require("foundation/arecent_affair.php");
require("foundation/aanti_refresh.php");
require("foundation/module_share.php");
require("foundation/aintegral.php");
require("foundation/adata_count.php");

//引入语言包
$s_langpackage=new sharelp;

//变量声明区
	$user_id=get_sess_userid();
	$user_name=get_sess_username();
	$userico=get_sess_userico();
  $s_comment=short_check(get_argp('comment'));  
	$s_type=short_check(get_argg('s_type'));
	$s_content_id=short_check(get_argg('share_content_id'));
	$title_data=short_check(get_argp('title_data'));
	$re_link=short_check(get_argp('re_link'));
	$re_thumb=get_session('m_thumb');
	$re_m_link=get_session('m_link');

  //数据表定义
  $t_blog=$tablePreStr."blog";
  $t_album=$tablePreStr."album";
  $t_photo=$tablePreStr."photo";
  $t_group=$tablePreStr."groups";
  $t_subject=$tablePreStr."group_subject";
  $t_poll=$tablePreStr."poll";
  $t_share=$tablePreStr."share";
  
  //初始化数据库操作对象
  $dbo=new dbex;
	dbtarget('r',$dbServs);
	if(empty($re_link)){
		$col=" and for_content_id='$s_content_id' ";
	}else{
		$col=" and out_link= '$re_link' ";
	}
	$sql="select s_id from $t_share where user_id=$user_id and type_id=$s_type $col";
	$is_share=$dbo->getRow($sql);
	if(!empty($is_share)){
		echo $s_langpackage->s_is_share;exit;
	}
	
	switch($s_type){
		case "0":
		$sql="select user_id , user_name , log_title , log_content from $t_blog where log_id=$s_content_id";
		$rs=$dbo->getRow($sql);
		if($rs['user_id']==$user_id){
			echo $s_langpackage->s_no_share;
		}else{
			$share_id=share_act($dbo,$s_type,$user_id,$user_name,$userico,$s_content_id,$title_data,$re_link,'','');
			$is_suc=set_blog_share_log($dbo,$user_id,$user_name,$userico,$ushare_inner_blog_affair_log,$rs['user_id'],$rs['user_name'],$s_content_id,$rs['log_title'],$rs['log_content'],$s_comment,$share_id);
			if($is_suc){
				increase_integral($dbo,$int_share,$user_id);
				update_count($dbo,$user_id,"share_num",1);
				echo "success";
			}else{
				echo $s_langpackage->s_share_los;
			}
	}
		break;

		case "1":
		$sql="select add_userid , group_name , group_creat_name , group_resume from $t_group where group_id=$s_content_id";
		$rs=$dbo->getRow($sql);
		if($rs['add_userid']==$user_id){
			echo $s_langpackage->s_no_share;
		}else{
			$share_id=share_act($dbo,$s_type,$user_id,$user_name,$userico,$s_content_id,$title_data,$re_link,'','');
			$is_suc=set_group_share_log($dbo,$user_id,$user_name,$userico,$ushare_inner_group_affair_log,$rs['add_userid'],$rs['group_creat_name'],$s_content_id,$rs['group_name'],$rs['group_resume'],$s_comment,$share_id);
			if($is_suc){
				increase_integral($dbo,$int_share,$user_id);
				update_count($dbo,$user_id,"share_num",1);
				echo "success";
			}else{
				echo $s_langpackage->s_share_los;
			}
		}
		break;
		
		case "2":
		$sql="select album_name , user_id , user_name , album_skin from $t_album where album_id=$s_content_id";
		$rs=$dbo->getRow($sql);
		if($rs['user_id']==$user_id){
			echo $s_langpackage->s_no_share;
		}else{
			$share_id=share_act($dbo,$s_type,$user_id,$user_name,$userico,$s_content_id,$title_data,$re_link,'','');
			$is_suc=set_album_share_log($dbo,$user_id,$user_name,$userico,$ushare_inner_album_affair_log,$rs['user_id'],$rs['user_name'],$s_content_id,$rs['album_name'],$rs['album_skin'],$s_comment,$share_id);
			if($is_suc){
				increase_integral($dbo,$int_share,$user_id);
				update_count($dbo,$user_id,"share_num",1);
				echo "success";
			}else{
				echo $s_langpackage->s_share_los;
			}			
		}	
		break;
		
		case "3":
		$sql="select p.user_id ,p.photo_thumb_src , p.photo_information , a.user_name , a.album_id from $t_photo as p join $t_album as a on(p.album_id=a.album_id) where photo_id=$s_content_id";
		$rs=$dbo->getRow($sql);
		if($rs['user_id']==$user_id){
			echo $s_langpackage->s_no_share;
		}else{
			$share_id=share_act($dbo,$s_type,$user_id,$user_name,$userico,$s_content_id,$title_data,$re_link,'','');
			$is_suc=set_photo_share_log($dbo,$user_id,$user_name,$userico,$ushare_inner_photo_affair_log,$rs['user_id'],$rs['user_name'],$s_content_id,$rs['photo_thumb_src'],$rs['album_id'],$rs['photo_information'],$s_comment,$share_id);
			if($is_suc){
				increase_integral($dbo,$int_share,$user_id);
				update_count($dbo,$user_id,"share_num",1);
				echo "success";
			}else{
				echo $s_langpackage->s_share_los;
			}		
		}
		break;
		
		case "4":
		$sql="select user_id , username , subject , `option` , multiple from $t_poll where p_id=$s_content_id";
		$rs=$dbo->getRow($sql);
		if($rs['user_id']==$user_id){
			echo $s_langpackage->s_no_share;
		}else{
			$input_type='radio';
			if($rs['multiple']==1){
				$input_type='checkbox';
			}
			$option_array=unserialize($rs['option']);
			$option_str="<input type=".$input_type." disabled />".$option_array[0]."<br /><input type=".$input_type." disabled />".$option_array[1]."<br />......";
			$share_id=share_act($dbo,$s_type,$user_id,$user_name,$userico,$s_content_id,$title_data,$re_link,'','');
			$is_suc=set_poll_share_log($dbo,$user_id,$user_name,$userico,$ushare_inner_poll_affair_log,$rs['user_id'],$rs['username'],$s_content_id,$rs['subject'],$option_str,$s_comment,$share_id);
			if($is_suc){
				increase_integral($dbo,$int_share,$user_id);
				update_count($dbo,$user_id,"share_num",1);
				echo "success";
			}else{
				echo $s_langpackage->s_share_los;
			}
		}
		break;
		
		case "5":
		$share_id=share_act($dbo,$s_type,$user_id,$user_name,$userico,0,$title_data,$re_link,'','');
		$is_suc=set_link_share_log($dbo,$user_id,$user_name,$userico,$ushare_outer_link_affair_log,$title_data,$re_link,$s_comment,$share_id);
		if($is_suc){
			increase_integral($dbo,$int_share,$user_id);
			update_count($dbo,$user_id,"share_num",1);
			echo "success";
		}else{
			echo $s_langpackage->s_share_los;
		}		
		break;
		
		case "6":
		$share_id=share_act($dbo,$s_type,$user_id,$user_name,$userico,0,$title_data,$re_link,'','');
		$is_suc=set_music_share_log($dbo,$user_id,$user_name,$userico,$ushare_outer_music_affair_log,$title_data,$re_link,$s_comment,$share_id);
		if($is_suc){
			increase_integral($dbo,$int_share,$user_id);
			update_count($dbo,$user_id,"share_num",1);
			echo "success";
		}else{
			echo $s_langpackage->s_share_los;
		}		
		break;
		
		case "7":
		if($s_content_id!=0){
			$sql="select * from $t_share where s_id=$s_content_id";
			$share_row=$dbo->getRow($sql);
			$re_thumb=$share_row['movie_thumb'];
			$re_m_link=$share_row['movie_link'];
		}
		$share_id=share_act($dbo,$s_type,$user_id,$user_name,$userico,$s_content_id,$title_data,$re_link,$re_thumb,$re_m_link);
		$is_suc=set_movie_share_log($dbo,$user_id,$user_name,$userico,$ushare_outer_movie_affair_log,$title_data,$re_link,$re_thumb,$re_m_link,$s_comment,$share_id);
		if($is_suc){
			increase_integral($dbo,$int_share,$user_id);
			update_count($dbo,$user_id,"share_num",1);
			echo "success";
		}else{
			echo $s_langpackage->s_share_los;
		}		
		break;
		
		case "8":
		$sql="select group_id,user_id,user_name,title,content  from $t_subject where subject_id=$s_content_id";
		$subject_row=$dbo->getRow($sql);
		$share_id=share_act($dbo,$s_type,$user_id,$user_name,$userico,0,$title_data,'','','');
		$is_suc=set_subject_share_log($dbo,$user_id,$user_name,$userico,$ushare_inner_subject_affair_log,$subject_row['user_id'],$subject_row['user_name'],$subject_row['group_id'],$s_content_id,$subject_row['title'],$subject_row['content'],$s_comment,$share_id);
		if($is_suc){
			increase_integral($dbo,$int_share,$user_id);
			update_count($dbo,$user_id,"share_num",1);
			echo "success";
		}else{
			echo $s_langpackage->s_share_los;
		}
		break;
	}

?>