<?
if(!(isset($_SESSION))){session_start();}
$mId=$_SESSION["mId"];
include("../db.php");
include("../function.php");
putenv("NLS_LANG=TRADITIONAL CHINESE_TAIWAN.AL32UTF8");
check_login();
if($mId!=''){
?>
<!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" />
<title>JUME(Join You And Me)揪咪揪團活動網</title>
<link href="../member/style/history.css" rel="stylesheet" type="text/css" media="screen" />
<link rel="stylesheet" href="../tab/themes/flora/history.all.css" type="text/css" media="screen"/>
<script type="text/javascript" src="../jQuery/jquery-1.2.6.js"></script>		
<script type="text/javascript" src="../tab/ui/ui.core.js"></script>			
<script type="text/javascript" src="../tab/ui/ui.tabs.js"></script>
<script>
	$(document).ready(function(){
		$("#tabsEx1 > ul").tabs({ //event:'mouseover'
		}); 
	});
</script>
<style type="text/css">
<!--
.style6 {color: #FF0000}
-->
</style>
</head>

<body>
<div id="header">
	<? 
		include("header2.php"); 
		$dtoday=date("Y-m-d");
	?><br>
</div>

<div id="content">


<div id="showdetail">
 <div id="activitydetail" align="center">
  <div id="tabsEx1" class="tab"> 
    <br>
   
    <ul style="height: 30px;"> 
        <li ><a href="#fragment-1"><span>  發表過的活動記錄  </span></a></li> 
		<li ><a href="#fragment-2"><span>  發起過的揪團記錄  </span></a></li> 
        <li ><a href="#fragment-3"><span>  參加過的揪團記錄  </span></a></li> 	   
	</ul>
    

<!--發佈的活動-->  
<div id="fragment-1" class="fragment"> 

<h2 align="center">活動列表</h2>
<table width="400" align="center" id="temp"> 
<tr><th>活動名稱</th><th>揪團數</th></tr>
<?


$str = oci_parse($conn,"select * FROM ACTIVITY where END_DATE>='$dtoday' and MID='$mId'") or die('Insert error');
oci_execute($str);

   $num1=oci_fetch_all($str,$result);
   $i=0;
   while($i<10&&$i<$num1)
   {
   oci_execute($str);
   		$row=oci_fetch_object($str);
    	echo "<tr><td align='center'>
		<a href=../activity/activity_show_detail.php?aId=".$row->AID.">".$row->ANAME."</td>";
		
		$str_2 = oci_parse($conn,"select * from RAISE left outer join ACTIVITY on RAISE.AID=ACTIVITY.AID where ACTIVITY.AID='$row->AID'") or die('Insert error');
oci_execute($str_2);
	
   		$take_num=oci_fetch_all($str_2,$result);
				echo"<td align='center'>$take_num</td></tr>";
 		$i++;
   }
?>
</table>
<h2 align="center">歷史活動列表</h2>
<table width="400" align="center" id="temp"> 
<tr><th class="past">活動名稱</th><th class="past">揪團數</th></tr>
<?

$str3 = oci_parse($conn,"select * FROM ACTIVITY where END_DATE<'$dtoday' and MID='$mId'") or die('Insert error');
oci_execute($str3);
 
	$num2=oci_fetch_all($str3,$result);
	$j=0;
   	while($j<10&&$j<$num2)
     {
	 oci_execute($str3);
	 	$row_3=oci_fetch_object($str3);
    	echo "<tr><td align='center'>
		<a href=../activity/activity_show_detail.php?aId=".$row_3->AID.">".$row_3->ANAME."</td>";
		
		$str4 = oci_parse($conn,"select * from RAISE left outer join ACTIVITY on RAISE.AID=ACTIVITY.AID where ACTIVITY.AID='$row_3->AID'") or die('Insert error');
oci_execute($str4);
		     
		$num_2=oci_fetch_all($str4,$result);
		echo"<td align='center'>$num_2</td></tr>";
     	$j++;
	 }
?>
</table>
<? 	if($num1>5||$num2>5){echo "<a href='../member/show_all_act.php'>".More."</a>";} ?>
</div><!--end div id="fragment-1" -->




<!--主揪的揪團-->
<div id="fragment-2" class="fragment"> 
<?
	/*$str5 = oci_parse($conn,"SELECT SCORE,RAISE.RID,RAISE.MID FROM SCORE INNER JOIN RAISE ON SCORE.RID=RAISE.RID WHERE RAISE.MID='$mId'") or die('Insert error');
oci_execute($str5);


$total_raise=0;
while($row_5=oci_fetch_object($str5))
{
	$total_raise+=$row->SCORE;
}*/
?>
<!--<h2 align="center">目前的總評價:<?=$total_raise?></h2>-->
<h2 align="center">揪團列表</h2>


<table width="400"  align="center">
 <tr><th align="center">發起的揪團</th></tr>
<?

	$str6 = oci_parse($conn,"select * from MEMBER natural join RAISE where MID='$mId' and RDATE>='$dtoday'") or die('Insert error');
oci_execute($str6);
	
    $num3=oci_fetch_all($str6,$result);
	$k=0;
	oci_execute($str6);
	while($k<$num3&&$k<10){
	
		$row_6=oci_fetch_object($str6);
		$tmp = oci_parse($conn,"select * from ACTIVITY where AID='$row_6->AID'") or die('Insert error');
oci_execute($tmp);
$atmp=oci_fetch_object($tmp);
    	echo "<tr><td align='center'>
		<a href=../raise/ad_main.php?rId=".$row_6->RID.">活動 ".$atmp->ANAME." 的揪團</td>";
	   	 $k++;
    }
		
?>
</table>

<br>
<h2 align="center">已過期揪團</h2>
<table width="400" id="temp" align="center">
 <tr><th class="past">發起的揪團</th>  
  	 <!--<th class="past">此揪團目前的總評價</th>-->
<!--	 <th class="past">點我給評價</th>-->
	 </tr>
<? 

$str_1 = oci_parse($conn,"select * from MEMBER natural join RAISE where MID='$mId' and RDATE<'$dtoday' ") or die('Insert error');
oci_execute($str_1);
  //已過期揪團
	$num4=oci_fetch_all($str_1,$result);
	$x=0;
	oci_execute($str_1);
	while($x<$num4&&$x<10){//已過期揪團數
	
		$row_1=oci_fetch_object($str_1);
		
		$tmp = oci_parse($conn,"select * from ACTIVITY where AID='$row_1->AID'") or die('Insert error');
oci_execute($tmp);
$atmp=oci_fetch_object($tmp);
    	echo "<tr><td align='center'>
		<a href=../raise/ad_main.php?rId=".$row_1->RID.">活動 ".$atmp->ANAME." 的揪團</a></td>";
	   	 $x++;
		 /*
		 $str_2 = oci_parse($conn,"SELECT SUM(SCORE) AS SUM FROM SCORE where RID='$row_1->RID' ") or die('Insert error');
oci_execute($str_2);
		 //計算總評價
		while($row_2=oci_fetch_object($str_2))
		{
			$j=0;
			$j+=$row_2->SUM;
		}//end of while
		if($j==0){
			echo "<td>".$j."</td>";}
		else{
			echo"<td><a href=view_rscore_detail.php?rId=".$row_1->RID.">".$j."</td>";
			}// end of else
			*/
			$str11 = oci_parse($conn,"SELECT * FROM RAISE INNER JOIN TAKES ON RAISE.rId=TAKES.rIdRIDwhere TAKES.RID='$row_1->RID'") or die('Insert error');
oci_execute($str11);
	//計算是否有人參加
		$num_take=oci_fetch_all($str11,$result);
		if($num_take!=0){
	
		
		
			echo "<td><a href=mraise_show_detail.php?rId=".$row_1->RID.">活動 ".$atmp->ANAME." 的揪團</td></tr>";}
		else{
			echo "<td>抱歉，無人參加。</td></tr>";
    	}
	}	

?>
</table>
<? 	if($num3>5||$num4>5){echo "<a href='../member/show_all_raise.php'>".More."</a>";} ?>
</div><!--end div id="fragment-2" -->

<!--參加的揪團-->


<div id="fragment-3" class="fragment"> 
<?
/*
$str=mysql_query("SELECT * FROM grade WHERE gGetmid='$mId'");
$total_take=0;
while($row=oci_fetch_object($str))
{
	$total_take+=$row->gGive;
}*/
?>
<!--
<h2 align="center">目前的總評價:<?=$total_take?></h2>-->
<h2 align="center">揪團列表</h2>
<table width="400" align="center" id="temp"> 
<tr align="center">
  <th>參加的揪團</th>
  </tr>
<?
$str = oci_parse($conn,"SELECT * from RAISE inner join TAKES on RAISE.RID = TAKES.RID where TAKES.MID='$mId' and RDATE>='$dtoday'") or die('Insert error');
oci_execute($str);


   	$num5=oci_fetch_all($str,$result);
	$y=0;
	oci_execute($str);
	while($y<$num5&&$y<10){
		$row=oci_fetch_object($str);
		$tmp = oci_parse($conn,"select * from ACTIVITY where AID='$row->AID'") or die('Insert error');
oci_execute($tmp);
$atmp=oci_fetch_object($tmp);
		//$str2=mysql_query("SELECT * from grade WHERE rId='$row->rId' AND gGetmid='$mId'");
		//$row2=oci_fetch_object($str2);
    	echo "<tr><td align='center'><a href=mtake_show_detail.php?rId=".$row->RID.">活動 ".$atmp->ANAME." 的揪團</td>";
		$y++;
	}
		
?>
</table>
<br>
<h2 align="center">已過期揪團</h2>
<table width="400"  align="center" id="temp"> 
<tr align="center">
  <th class="past">參加的揪團</th>
  <!--<th class="past">主揪給你的評價</th>-->
  </tr>
<?

$str = oci_parse($conn,"SELECT * from RAISE inner join TAKES on RAISE.RID = TAKES.RID  where TAKES.MID='$mId' and RDATE<'$dtoday'") or die('Insert error');
oci_execute($str);

   	echo $num6=oci_fetch_all($str,$result);
		$z=0;
		while($z<$num6&&$z<10){
		oci_execute($str);
			$row=oci_fetch_object($str);
			//$str2=mysql_query("SELECT * from grade WHERE rId='$row->rId' AND gGetmid='$mId'");
			//$row2=oci_fetch_object($str2);
			$tmp = oci_parse($conn,"select * from ACTIVITY where AID='$row->AID'") or die('Insert error');
oci_execute($tmp);
$atmp=oci_fetch_object($tmp);
			
    		echo "<tr><td align='center'>
			<a href=mtake_show_detail.php?rId=".$row->RID.">活動 ".$atmp->ANAME." 的揪團</td>";
			$z++;
			/*
			if($row2->gGetmid=="")
				{echo "<td>主揪還沒給你評價喔</td>";}
			else{ 
				if($row2->gGive==1){echo "<td>主揪給你:<img src='./starPic/good.gif'></td>";}
				else if($row2->gGive==0){echo "<td>主揪給你:<img src='./starPic/normal.gif'></td>";}
				else{echo "<td>主揪給你::<img src='./starPic/bad.gif'></td>";}
			}*/
	 	}
	
?>
</table>
<? if($num5>10||$num6>10){echo "<a href='../member/show_all_take.php?$mId=$mId'>More</a>";}?>
 </div><!-- END #activitydetail-->
</div><!--end #content-->
</div>
</div>
</div>

<div id="footer">   
  <div id="footer-in" align="center">
<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 -->

</body>
</html>
<?
}else{echo "請先登入";}
?>