<?
if(!(isset($_SESSION))){session_start();}
require_once ("../function.php");
check_login();
$mAccount=$_SESSION['mAccount'];
$mId=$_SESSION['mId'];
include("../db.php");
putenv("NLS_LANG=TRADITIONAL CHINESE_TAIWAN.AL32UTF8");

if(isset($_POST['del'])){
if(!(empty($_POST['delmsg']))){
$del=$_POST['delmsg'];
foreach($del as $value){

$del_str[]="IID='".$value."'";

}

$sql_str=implode(" or ",$del_str);

$delm = oci_parse($conn,"delete from MESSAGE where $sql_str") or die('Insert error');
                 oci_execute($delm);


}
}

if(isset($_GET['show'])){
$show=$_GET['show'];}

if(isset($_POST['show'])){
 $show=$_POST['show'];
}

echo $show;
if($show=='new'){


$mes="select * from MESSAGE where IGET='$mId' and IREAD='1' order by ITIME desc";

$mres = oci_parse($conn,$mes) or die('Insert error');
                 oci_execute($mres);

}else if ($show=='old'){


	 $mes="select * from MESSAGE where IGET='$mId' and ISEND<>'0' order by ITIME desc";

	$mres = oci_parse($conn,$mes) or die('Insert error');
                 oci_execute($mres);
	
	}else if ($show=='send'){
	echo  $mes="select * from MESSAGE where ISEND='$mId' order by ITIME desc";

	$mres = oci_parse($conn,$mes) or die('Insert error');
                 oci_execute($mres);
	
	}else if ($show=='sys'){
	$mes="select * from MESSAGE where IGET='$mId' and ISEND='0' order by ITIME desc";

	$mres = oci_parse($conn,$mes) or die('Insert error');
                 oci_execute($mres);
	
	}


?>


<!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 rel="stylesheet" type="text/css" media="screen,projection" href="mlib/main01.css" />
<link href="style/message.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" src="../jQuery/jquery-1.2.6.js"></script>
<script type="text/javascript" src="mlib/jquery.tablesorter.js"></script>

<script type="text/javascript" src="mlib/pro08.js"></script>
<script type="text/javascript" src="../thick/thickbox.js"></script>
<link rel="stylesheet" href="../thick/thickbox.css" type="text/css" media="screen" />
<style type="text/css" media="all">@import "../thick/thickbox.css";</style>

</head>

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

</div>
<div id=content>

<div id="form1">
<form name="form1" method="post" action="message.php">

<br><br>

<table border="1" width="61%" id="table2" cellspacing="0" cellpadding="5" style=" margin: 0px auto;">
<caption><? 

if($show=='new'){
echo "未讀訊息|<a href=message.php?show=old>全部訊息</a>|<a href=message.php?show=send>已發訊息</a>|<a href=message.php?show=sys>系統訊息</a>";
}else if($show=='old') {
echo "<a href=message.php?show=new>未讀訊息</a>|全部訊息|<a href=message.php?show=send>已發訊息</a>|<a href=message.php?show=sys>系統訊息</a>";
} else if($show=='send'){
echo "<a href=message.php?show=new>未讀訊息</a>|<a href=message.php?show=old>全部訊息</a>|已發訊息|<a href=message.php?show=sys>系統訊息</a>";

}else if($show=='sys'){

echo "<a href=message.php?show=new>未讀訊息</a>|<a href=message.php?show=old>全部訊息</a>|<a href=message.php?show=send>已發訊息</a>|系統訊息";
}



?></caption>
<thead>
	<tr>
	    <th width="25"></td>
		<?
		if($show!='send'){
		?>
		<th width="50">來自 </td>
		<?
		}else if ($show=='send'){
		?>
		<th width="50" >發送到</td>
		<?
		}
		?>
		<th width="183">主旨</td>
		<!--<th width="94" >揪團</td>-->
		<th width="94" >時間</td>
		<!--<th>動作</td>-->
	</tr>
	</thead>
	<tbody>
	<?
	$newm=oci_fetch_all($mres,$result);
	if($newm!=0&&$show!='send'){
	$tr=1;
	 oci_execute($mres);
 while($m_row=oci_fetch_object($mres)){
 
 $msgId=$m_row->IID;
  $r_rId=$m_row->RID;
 
 if($m_row->ISEND=='0'){
 $m_acc[0]="揪咪";
 }else{
 $r_mId=$m_row->ISEND;
 
 
	$m_astr= oci_parse($conn,"select MACCOUNT from MEMBER where MID='$m_row->ISEND'") or die('Insert error');
                 oci_execute($m_astr);

  $m_acc=oci_fetch_row($m_astr);
 }
 $m_re=$m_row->IREPLY;
 
$r_str= oci_parse($conn,"select ACTIVITY.ANAME from RAISE inner join ACTIVITY on RAISE.AID=ACTIVITY.AID where RAISE.RID='$m_row->RID'") or die('Insert error');
                 oci_execute($r_str);
 

  $r_name=oci_fetch_row($r_str);
  
	echo "
	<tr id='n_$m_row->IID'>
	<td><input type=\"checkbox\" name=\"delmsg[]\" value=\"$m_row->IID\" /></td>
		<td >".$m_acc[0]."</td>
		<td ><a href=# id='$m_row->IID' name='$tr'>".$m_row->ITITLE."</a>";
		if($m_re==1){echo "<a href=\"reply_msg_show.php?height=260&width=350&mId=$r_mId&rId=$r_rId&iId=$msgId\" class=\"thickbox\" title=\"回覆給'$m_acc[0]'的訊息\"><img src='../images/re.gif' border='0'></a>";}

		if($m_row->RID!='0'){echo "<br>
		From: 活動".$r_name[0]."的揪團<div id='wait_$m_row->IID' style=\"display:none\"><img src=mlib/loading6.gif></div></td>";}else {echo "</td>";}
    echo "<td>".$m_row->ITIME."</td>";
      echo "
	</tr>
	<tr id='n_$m_row->IID' name='0'>
		<td colspan=3>".$m_row->ICONTENT."</td><td><input id=\"Btn\" type=\"button\" value=\"刪除\" onclick=\"delmsg($m_row->IID);\">";
		if($m_row->ISEND!='0'){
		echo "<a href=\"reply_msg.php?height=260&width=370&mId=$r_mId&rId=$r_rId&iId=$msgId&show=$show\" class=\"thickbox\" title=\"回覆訊息給'$m_acc[0]'\"><input type='button' value='回覆'></a>";
		//echo "<input type='button' value='回覆'  class=\"thickbox\" title=\"回覆訊息給'$m_acc[0]'\" onClick=\"javascript:location.href='reply_msg.php?height=260&width=350&mId=$r_mId&rId=$r_rId&iId=$msgId&show=$show'\">;";
		}
		echo "<input id=\"Btn\" type=\"button\" value=\"隱藏\" onclick=\"hide_msg(0);\"></td>
		
	</tr>";
	$tr=$tr+2;}
}else if($newm!=0&&$show=='send'){
	$tr=1;
	oci_execute($mres);
 while($m_row=oci_fetch_object($mres)){
 
 $msgId=$m_row->IID;
 $r_rId=$m_row->RID;
 $r_mId=$m_row->IGET;
 //$m_re=$m_row->iReply;
 
 $m_astr = oci_parse($conn,"select MACCOUNT from MEMBER where MID='$m_row->IGET'") or die('Insert error');
                 oci_execute($m_astr);

 $m_acc=oci_fetch_row($m_astr);
 

 $r_str = oci_parse($conn,"select ACTIVITY.ANAME from RAISE inner join ACTIVITY on RAISE.AID=ACTIVITY.AID where RAISE.RID='$m_row->RID'") or die('Insert error');
                 oci_execute($r_str);
  $r_name=oci_fetch_row($r_str);
  
	echo "
	<tr id='n_$m_row->IID'>
	<td><input type=\"checkbox\" name=\"delmsg[]\" value=\"$m_row->IID\" /></td>
		<td >".$m_acc[0]."</td>
		<td ><a href=# id='$m_row->IID' name='$tr'>".$m_row->ITITLE."</a>";
		//if($m_re==1){echo "<img src='../images/re.gif'>";}
		
		if($m_row->RID!='0'){echo "
		<br>From: 活動".$r_name[0]."的揪團<div id='wait_$m_row->IID' style=\"display:none\"><img src=mlib/loading6.gif></div></td>
    ";}else {echo "</td>";}
    	echo "<td>".$m_row->ITIME."</td>
	</tr>
	<tr id='n_$m_row->IID' name='0'>
		<td colspan=3>".$m_row->ICONTENT."</td><td><input id=\"Btn\" type=\"button\" value=\"刪除\" onclick=\"delmsg($m_row->IID);\">
		
		<input id=\"Btn\" type=\"button\" value=\"隱藏\" onclick=\"hide_msg(0);\"></td>
		
	</tr>";
	$tr=$tr+2;}
}
	?>
	</tbody>
</table>
<input type="hidden" name="show" value=<?=$show?>  />
<input type="hidden" name="del" value="del" />
	<? 
	if(oci_fetch_all($mres,$result)!=0){
		?>
<input type="submit" name="Submit" value="刪除" />
<? } ?>
<br>

</form>
</div>
</div>

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