<?
if (!isset($_SESSION)) //判斷是否已經開啟SESSION
{
session_start();
}//開起SESSION}
$maccount=$_SESSION['mAccount'];
$mid=$_SESSION['mId'];
require_once("../function.php");

putenv("NLS_LANG=TRADITIONAL CHINESE_TAIWAN.AL32UTF8");

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>JUME(Join You And Me)揪咪揪團活動網</title>
<link href="../member/style/show_raise_detail.css" rel="stylesheet" type="text/css" media="screen" />

<!--瀏覽區顯示資料-->
<link rel="stylesheet" href="../tooltip/jquery.tooltip.css" />

<script src='../jQuery/jquery-1.2.6.js' type='text/javascript'></script>
<?
if($_SESSION['mId']!=''){
echo "<link rel=\"stylesheet\" href=\"../thick/jraise_thickbox.css\" type=\"text/css\" media=\"screen\" />
<style type=\"text/css\" media=\"all\">@import \"../thick/jraise_thickbox.css\";</style>";
}
?>
<?
if($_SESSION['mId']!='')
echo "<script type=\"text/javascript\" src=\"../thick/thickbox.js\"></script>";
?>
<script src="../jQuery/jquery.tooltip.pack.js" type="text/javascript"></script>

<script type="text/javascript">
//Q & A
	function showMsg() {
	
		//$(e.target).attr('disabled', true);
		/*
		$.post({
		url: 'add_qanda_act.php',
		data: {qContent:$('#qContent').val()},
			error: function(xhr) {
				alert('Ajax request 發生錯誤');
				//$(e.target).attr('disabled', false);
			},
			success: function(response) {
				$('#msg').html(response);
				//$('#msg').fadeIn();
			}
		});*/
   $.ajax({
   type: "POST",
   dataType:"json",
   url: "add_qanda_act.php",
   data: {qContent:$('#qContent').val(),mId:$('#mId').val(),rId:$('#rId').val(),mAccount:$('#mAccount').val()},
  beforeSend:function(){
  	if($('#qContent').val()==''){
  		
  		alert("請輸入問題!!");
  		return false;
  		
  		}
  	
  	
  	
  	
  	
  },
  complete: function (xhr) {
  eval("var res=("+xhr.responseText+")");
  for(var i=0;i<res.length;i++){
       var mPath="<img src=../member/"+res[i].mPath+" width='50' height='50' />";
        $('<tr><td>'+res[i].mAccount+mPath+'</td><td>'+res[i].qContent+'</td><td>'+res[i].qTime+'</td></tr>').appendTo('#msg');
  		//$('#msg').appendTo('<tr><td>'+res[i].mAccount+'<td></td>'+res[i].qContent+'<td></td>'+res[i].qTime+'</td></tr>');
		$('#noqanda').fadeOut();
  setTimeout(function(){
		
		$('#btn').attr('disabled', true);
		$('#btn').attr('disabled', false);
		}, 3000);	
								 
								 }
							}


   });	//return true;
		
	}

 $(document).ready(function(){
    $("#attend_member a").tooltip({
	track: true,
	delay: 0,
	showURL: false,
	extraClass: "right"
	});
 });
</script>


</head>

<body>
<div id="wrapper">

<div id="header">
<? include("../member/header2.php"); ?>
</div>

<div id="content">
<? 
require_once("../db.php");
//$str=mysql_query("SELECT * FROM `raise` NATURAL JOIN `take` WHERE rId='$rId'");
$rId=$rid=$_GET['rId'];
if($_SESSION['mAccount']==''){

url_session($rId,$c='rId');

}
url_session($rId,$c='rId');

$str = oci_parse($conn,"SELECT * FROM RAISE NATURAL JOIN MEMBER  WHERE RID='$rId'") or die('Insert error');
oci_execute($str);

$row=oci_fetch_object($str);

$str_5 = oci_parse($conn,"select * from ACTIVITY where AID='$row->AID'") or die('Insert error');
oci_execute($str_5);
$row_1=oci_fetch_object($str_5)

?>

<div id="raisetable">
<div id="raise_table">
<table border="0" align="center" >
  <tr>
    <th>主揪</th>
    <td><? 
	      echo "<a href=../member/show_member_detail.php?mId=$row->MID>".$row->MACCOUNT."";?>
	 <? 
	 /*
	 if($row->mPath==''){
		echo "<img src='../member/mpic/User.png' target='_blank' width='70' height='70' border='0'> </a>";
  
          	}else{
        echo " <img src='../member/$row->mPath' target='_blank' width='70' height='70' border='0'></a>" ; 
		
		}
		*/
		 ?>
		<?
		
	
	if($_SESSION['mId']!=''&&$_SESSION['mId']!=$row->MID){
		
		echo "<a href='../raise/send.php?height=260&width=350&mId=$row->MID' class=\"thickbox\" title=\"傳送訊息給$row->MACCOUNT\"><img src='../images/messenge.png' border='0'></a>";
		
		
		}
	?>
</td>
  </tr>
   <tr>
    <th scope="row" class="must">活動名稱</th>
    <td><?=$row_1->ANAME?></td>
  </tr>
    <tr>
    <th scope="row" class="must">活動時間</th>
    <td><?=$row_1->ATIME?>~<?=$row_1->END_DATE?></td>
  </tr>
 
  <tr>
    <th scope="row" class="must">集合地點</th>
    <td><?=$row->RPLACE?></td>
  </tr>
  <tr>
    <th scope="row" class="must">集合時間</th>
    <td>
	<?=$row->RTIME?>點
	</td>
  </tr>
  <tr>
    <th scope="row" class="must">集合日期</th>
    <td><?=$row->RDATE?></td>
  </tr>
  <tr>
    <th scope="row" class="must">備註</th>
    <td><?=$row->RELSE?></td>
  </tr>
    <tr>
    <th scope="row" class="must">參加人數上限</th>
    <td><? if($row->RLIMIT==$row->RLIMIT_1){ echo "<font color='red' font-weight='bold'>揪團已滿</font>";}
			else { echo $row->RLIMIT;}?></td>
  </tr>
  <?

  if($_SESSION['mId']!=''){
  $mtak1 = oci_parse($conn,"select * from TAKES where RID='$rid' and MID='$mid'") or die('Insert error');
oci_execute($mtak1);
$mtak=oci_fetch_all($mtak1,$result);
  oci_execute($mtak1);
   if($mtak!=0){
  ?>
  <tr>
    <th>主辦人電話</th>
    <td><?=$row->RPHONE?></td>
  </tr>
  <?
  }
  }
  ?>
   <tr>
    <th>主辦人E-mail</th>
    <td><?=$row->REMAIL?></td>
  </tr>
  <!--
  <tr>
    <th>主辦人msn</th>
    <td><?=$row->rMsn?></td>
  </tr>
  -->
 </table> 
<div id="button" align="center">
<?
$d0=date("Y-m-d");
	//判斷是否為主揪
 if(($row->MID)==$mid){ 
 
 	if($d0 <= $row->RDATE)//揪團集合日期比今天晚
 	{
   	   // echo "<a href='edit_raise.php?rId=$rId'>我要修改此揪團資料</a>";
		echo "<p>";
		echo "<a href='ad_main.php?rId=$rId'><img src='../member/images/management.png'  border='0'/></a><br>";
	}
	 //如果不是主揪，判斷登入者是不是有參加過揪團
 }
 else if($row->MACCOUNT!=$maccount){
 
 $check = oci_parse($conn,"SELECT MID FROM TAKES NATURAL JOIN MEMBER Where RID='$rId' and MID='$mid'") or die('Insert error');
oci_execute($check);
 	
	$row_2=oci_fetch_all($check,$result);
	//echo $row_2[0];
	if($row_2=='0'){ //未參加
		if($row->RSTATE!='0'){//判斷揪團狀態 沒有流團
		
			if($row->RSTATE=='2') //判斷揪團是否已滿，已滿
			{
				echo "<img src='../member/images/raise_full.png'><br>";
			}	
			else if($mid!=''){  //未滿，且已登入
				if($d0 <= $row->RDATE){
				echo "<a href='join_raise.php?height=350&width=500&rId=$rId' title=\"參加揪團囉~~\" class=\"thickbox\" ><img src='../member/images/go_raise.png' border='0'/></a>";
				}
			}
		}
		else{//有流團
		echo "<img src='../member/images/raise_cancle.png' border='0'/><br>";	
		}		
		//echo "<font size='+2'哈囉，".$maccount ."<br>您已參加此揪團</font>";//<img src='../member/images/join_yet.png'  border='0'/>
	}
}
?>
</div><!--end button-->
</div><!--end raise_table-->
</div><!--end raisetable-->
<div id="attend">
<div id="attend_member">
  <? 
$d0=date("Y-m-d");

 $str_2 = oci_parse($conn,"SELECT MID,MACCOUNT,TEMAIL,TRAFFIC,RID FROM TAKES NATURAL JOIN MEMBER where RID='$rId'") or die('Insert error');
oci_execute($str_2);

$row_2=oci_fetch_all($str_2,$result);
$i=0;

if($row_2!=0){
oci_execute($str_2);
	echo "<table border='5' align='center' caellpadding='3' cellspacing='3'><tr>";
	while(list($mId,$mAccount,$tEmail,$tTraffic,$trId)=oci_fetch_row($str_2)){
 		echo "<td><a href=../member/show_member_detail.php?mId=$mId title=\"會員：$mAccount<br/>Email：$tEmail<br/交通方式：$tTraffic\">" ;
	echo "$mAccount </a></td>";
	
	$i++;
		if($i==10){echo "</tr>"; } 
		if($i==10){echo "<tr>";$i=0;}
}
echo "</td></tr></table>";

}

?>

</div>
<!--end attend_member-->
</div>

<!-- Q AND A -->



<? 
/*<div id="q_and_a">
<div id="qanda">
	//判斷是否為主揪
if($d0 <= ($row_1->end_date)){

$str=mysql_query("SELECT member.mId,member.mPath,member.mAccount,qanda.qId,qanda.qContent,qanda.qTime FROM qanda NATURAL JOIN member WHERE qanda.rId='$rid'");
   echo "<table id='msg' align='center' border='1' border-color='#ffffff' width='680px' style=\" margin: 0px auto;\">";
   $num=mysql_num_rows($str);
   if($num!=0){//有發問
   echo "<tr><th width='100px'>帳號</th><th width='430px'>Q&A</th><th width='150px'>時間</th></tr>";
   while(list($mId,$mPath,$mAccount,$qId,$qContent,$qTime)=mysql_fetch_row($str)){
        
        $re_sql="select * from reply where qId='$qId'";
		$re_res=mysql_num_rows(mysql_query($re_sql));
		
   		$time1 = str_replace("-", "", $qTime);
   		$time2 = str_replace(" ","",$time1);
		$time3 = str_replace(":","",$time2);
		echo "<tr>";
		echo "<td>".$mAccount;
		if($mPath==''){//會員沒有自己的圖
			echo "<a href=../member/show_member_detail.php?mId=$mId>
			<img src='../member/mpic/User.png' target='_blank' width='50' height='50' border='0' /></a></td>";
  
        }else{//會員有自己的圖
        echo "<a href=../member/show_member_detail.php?mId=$mId>
		<img src='../member/$mPath' target='_blank' width='50' height='50' border='0'/></a></td>" ; }
		echo "<td>".$qContent."</td>";
		echo "<td>".$qTime."</td></tr>";
		if($re_res!=0){
		$re_row=mysql_fetch_object(mysql_query($re_sql));
		
		
		
		echo "<tr><td>回覆</td>";
   		echo "<td>".$re_row->rContent."</td>";
		echo "<td>".$re_row->rTime."</td></tr>";
		
		}
   }
   echo "</table>";
}else {echo "<table id='msg' align='center' style=\" margin: 0px auto;\"><tr style=display:none><th >帳號</th><th>Q&A</th><th>時間</th></tr>
                                                                 <tr colsapn='3' id='noqanda'><td>還沒有人發問喔</td></tr></table>";}//尚未發問
if($mid!=''){//會員已登入 
echo "
	<table align='center' style=\" margin: 0px auto;\"><form >
	<tr><td align='center'><img src='images/qanda.png'/></td></tr>
 	
		<tr><td><textarea name='qContent'  id='qContent' rows='5' cols='35'></textarea></td></tr>
		<input type='hidden' name='mId' id='mId' value='$mid'>
		<input type='hidden' name='rId' id='rId' value='$rid'>
		<input type='hidden' name='mAccount' id='mAccount' value='$maccount'>
	
      	<tr><td><input type='button' onclick='showMsg();' value='送出' id='btn'/></td></tr>
    	 
</form ></table>";
}
}</div><!--end qanda-->
</div><!--q_and_a-->
*/
?>



<div id="member">
<br><br>
<table border="1" width="730" align="center" id="temp" style="margin:0px auto">
<tr>
  <th colspan="10" >發布這個揪團的會員也揪過(最近5筆)</th></tr>
  <tr>
  
  <?
   $r_mem=$row->MID;
    $r_res = oci_parse($conn,"select RID,AID from RAISE where MID='$r_mem' and RID <> '$rId' order by RID desc") or die('Insert error');
oci_execute($r_res);

	$num_res=oci_fetch_all($r_res,$result);
	oci_execute($r_res);
	for($j=0;$j<5;$j++){
		if(list($r_rId,$r_aId)=oci_fetch_row($r_res)){
		 $str_20 = oci_parse($conn,"select PPATH from PICTURE where AID='$r_aId'") or die('Insert error');
oci_execute($str_20);
	
		$num_20=oci_fetch_all($str_20,$result);
		echo "<td><a href='show_raise_detail.php?rId=$r_rId'>"; 
		if($num_20=='0'){
				echo "<img src='../activity/picture/original.png' target='_blank' width='70' height='70' border='0'> <br>";
   		    	 	 }
		else{	
		oci_execute($str_20);
			while(list($pPath)=oci_fetch_row($str_20)){
        	echo " <img src='../activity/$pPath' target='_blank' width='70' height='70' border='0' ><br>" ; 
				}
			} 
		echo "<br>第".($J+1)."團</a></td>";
		}
	}
	
	?>
	
	</tr></table>




</div><!--end member--->

</div><!--end content-->


</center>
<div id="footer">   
  <div id="footer-in" align="center">
    <br>
<a href="../activity/activity_show.php"><? echo "<img src='../member/images/back_activity.png' border='0'/>" ; ?></a>
<br/><br/><br/>
<p>版權資訊</p>
    <p>國立中山大學  資訊管理學系  揪咪揪團網 <a href="mailto:jumemis@yahoo.com.tw">揪咪團隊<img src="../mail/send email.gif" border="0"/></a> 版權所有  Taiwan All Rights Reserved</p> 
  </div><!-- end #footer-in -->
</div><!-- end #footer -->
</div><!--end wrapper-->
</body>
</html>
