<?
  $today_date = date("Y-m-d");
?>
<?
  $status = $_GET["selStatus"];
  if( $status=="" ){
    $status=0;
	$event=0;
  }else{
    $event=$_GET["selEvent"];
  }
?>
<?
  $qtea = "SELECT * FROM xoops_adm_teacher WHERE id!='admin'";
  $rtea = mysql_query($qtea);
  $ntea = mysql_num_rows($rtea);
  $i=0;
  while($i<$ntea){
  
    $id = mysql_result($rtea,$i,"id");
    $ename = mysql_result($rtea,$i,"ename");
	if( strlen($ename)>20 ){
	  $ename = substr($ename,0,19) . "...";
	}
    $cname = mysql_result($rtea,$i,"cname");
  
    $arrTea[$id] = $cname . " " . $ename;
  
    $i++;
  }
?>
<?
  $qevent = "SELECT * FROM xoops_pc_remarkevent";
  $revent = mysql_query($qevent);
  $nevent = mysql_num_rows($revent);
  $i=0;
  while($i<$nevent){
  
    $id = mysql_result($revent,$i,"id");
	$tevent = mysql_result($revent,$i,"event");
	$arrEvent[$id] = $tevent;
  
    $i++;
  }
?>
<center>
<form action="main.php" method="get">
<input type="hidden" name="pg" value="rmk">
<input type="hidden" name="ac" value="apv">
<table cellspacing="1" style=" font-family:Arial; font-size:14px " width="500">
<tr>
  <th bgcolor="#999999" style="color:#EEEEEE " colspan="2"><?= $APPROVEREMARK ?></th>
</tr>
<tr bgcolor="#CCCCCC">
<?
  //------ status part -----------------
?>
  <td bgcolor="#999999" style="color:#EEEEEE "><?= $STATUSREMARK ?></td>
  <td>&nbsp;
      <select name="selStatus" onChange="this.form.submit()">
<?
  $arrStatus = array("PENDING","APPROVED","REJECT","ALL");
  $i=0;
  while($i<4){
    if($i==$status){
	  $selected = "SELECTED";
	}else{
	  $selected = "";
	}
    echo "<option value='$i' $selected>" . $arrStatus[$i] . "</option>";
	$i++;
  }
?>      
      </select><?= $msgnew ?>
  </td>
</tr>
<?
  //------ event part -------------------------
?>
<tr>
  <td bgcolor="#999999" style="color:#EEEEEE "><?= $EVENT ?></td>
  <td bgcolor="#CCCCCC">&nbsp;
    <select name="selEvent" onChange="this.form.submit()">
	  <option value="0">SEMUA</option>
<?
  $i=1;
  foreach($arrEvent as $id=>$tevent){
    if($i==$event){
	  $selected="SELECTED";
	}else{
	  $selected="";
	}
  
    echo "<option value='$id' $selected>$tevent</option>";
	$i++;
  }
?>
    </select>
  </td>
</tr>
<?
  //------ submit part -------------------------
?>
<tr bgcolor="#999999">
  <td align="center" colspan="2">
    <input type="submit" value="<?= $DISPLAY ?>">
  </td>
</tr>
</table>
</form>
<hr>

<?
//--- display pending request -----------
?>
<?
  if( $event==0 ){
    $strEvent = "";
  }else{
    $strEvent = " AND eventId=$event";
  }
  if( $status==3 ){
    $strStatus = "";
  }else{
    $strStatus = " AND status=$status";
  }
  
?>
<?
  $q1 = "SELECT * FROM xoops_pc_remarkrecord WHERE id>0 $strEvent $strStatus";
  $r1 = mysql_query($q1);
  $n1 = mysql_num_rows($r1);
  $n2 = 10;
  if($selStatus!=""){
    $selStatus=$_GET["selStatus"];
  }else{
    $selStatus=0;
  }
  if($selEvent!=""){
    $selEvent=$_GET["selEvent"];
  }else{
    $selEvent=0;
  }
  
  
  $idx=$_GET["idx"];
  $query = "SELECT * FROM xoops_pc_remarkrecord WHERE id>0 $strEvent $strStatus ORDER BY remarkDate DESC LIMIT ".($idx*$n2).", $n2";
  $result = mysql_query($query);
  $num = mysql_num_rows($result);
?>
<table style="font-size:11px " width="640" border="1">
  <tr bgcolor="#999999" style="color:#EEEEEE ">
    <th colspan="6">
	<?
	  $div = ceil($n1/$n2);
      for($i=0;$i<$div;$i++){
	    $url = "main.php?pg=rmk&ac=apv&selStatus=$selStatus&selEvent=$selEvent&idx=$i";
	    echo "<a href='$url'>[" . ($i+1) . "]</a> ";
	  }
	?>
	</th>
  </tr>
  <tr bgcolor="#999999" style="color:#EEEEEE ">
    <th width="80"><?= $NAME ?></th>
	<th width="80"><?= $DATE ?></th>
	<th width="60"><?= $EVENT ?></th>
	<th width="190"><?= $REMARK ?></th>
	<th width="70"><?= $STATUS ?></th>
	<th width="30"></th>
  </tr>
<?
  $i=0;
  while($i<$num){
    $tid = mysql_result($result,$i,"id");
    $tteaid = mysql_result($result,$i,"staffId");
	$rDate = mysql_result($result,$i,"remarkDate");
	$rDatetil = mysql_result($result,$i,"remarkDatetil");
    $tevent = mysql_result($result,$i,"eventId");
    $tnotice = mysql_result($result,$i,"notice");
	$tstatus = mysql_result($result,$i,"status");
?>
  <form action="main.php" method="get">
  <input type="hidden" name="pg" value="rmk">
  <input type="hidden" name="ac" value="apv2">
  <input type="hidden" name="hid" value="<?= $tid ?>">
  <tr>
    <td><?= $arrTea[$tteaid] ?></td>
	<td align="center"><?= $rDate ?></td>
	<td><?= $arrEvent[$tevent] ?></td>
	<td><?= $tnotice ?></td>
	<td align="center"><?= $arrStatus[$tstatus] ?></td>
	<td><input type="submit" value="..." style=" width:30"></td>
  </tr>
  </form>
<?
    $i++;
  }
?>
</table>
</center>