<?
  include "../../mainfile.php";
  include "include/CEVENT.php";
  include "include/CARRAY.php";
  include "../admsys/include/CSYSTEM.php";
?>
<?
  $mysys = new CSYSTEM;

  $pg = $_POST["pg"];
  $ac = $_POST["ac"];
  $pyr = $_POST["pyr"];

  $arrEvent = getEventList();
?>
<?
  $qrmkevt = "SELECT month( remarkdate ) , count( id ) , eventid
                FROM `xoops_pc_remarkrecord` 
                WHERE year( remarkdate ) = '". $pyr ."' 
                GROUP BY month( remarkdate ) , eventid";
  $rrmkevt = mysql_query($qrmkevt);
  $nrmkevt = mysql_num_rows($rrmkevt);
  $i=0;
  while($i<$nrmkevt){
  
    $tmth = mysql_result($rrmkevt,$i,"month( remarkdate )");
	$tevt = mysql_result($rrmkevt,$i,"eventid");
	$tcount = mysql_result($rrmkevt,$i,"count( id )");
  
    $arrRmkevt[$tmth][$tevt] = $tcount;
  
    $i++;
  }
?>
<?
  $qprecord = "SELECT month( punchdate ) , count( punch_id ) FROM `xoops_pc_punchrecord` GROUP BY month( punchdate ) ";
  $rprecord = mysql_query($qprecord);
  $nprecord = mysql_num_rows($rprecord);
  $i=0;
  while($i<$nprecord){
  
    $tmth = mysql_result($rprecord,$i,"month( punchdate )");
    $tcount = mysql_result($rprecord,$i,"count( punch_id )");
  
    $tjum[$tmth] = $tcount;
  
    $i++;
  }
?>
<center>
<table border="0" style="font-family:Arial; font-size:14px">
<tr align="center"><td> <?= $mysys->schName ?><br />
LAPORAN RUMUSAN KEHADIRAN PADA TAHUN <?= $pyr ?> 
</td></tr></table>
<br />

<table border="1" style="font-family:Arial; font-size:14px">
<tr align="center">
  <td width="150px">BULAN</td>
  <?
  foreach($arrMth as $tmthid=>$tmth){
    echo "<td width='50px'>".substr($tmth,0,3)."</td>";
  }
  ?>
</tr>
<?
  foreach($arrEvent as $tevtid=>$tevt){
  echo "<tr align='center'>";
  echo "<td>".$tevt["event"]."</td>";

    foreach($arrMth as $tmthid=>$tmth){
	  if(!isset($arrRmkevt[$tmthid][$tevtid])){
	    $arrRmkevt[$tmthid][$tevtid]=0;
		$tpctg = "";
	  }else{
		$tpctg = "<font size='1'>".round((($arrRmkevt[$tmthid][$tevtid]/$tjum[$tmthid])*100),2) . "%</font>";
	  }
	//print_r($tevt);
//	  echo "<td>".$tevt[$tmthid][$tevtid]."</td>";
	  echo "<td>" . $arrRmkevt[$tmthid][$tevtid] . "<br>" . $tpctg . "</td>";
	}

  echo "</tr>";
  }
?>
<tr>
  <td>JUMLAH HADIR</td>
  <?
  foreach($arrMth as $tmthid=>$tmth){
    if( $tjum[$tmthid]=="" ){
	  $tjum[$tmthid] = 0;
	}
    echo "<td align='center' width='50px'>".$tjum[$tmthid]."</td>";
  }
  ?>
</tr>
</table>
</center>