<?php
$nama_file = date('Y-m-d')."_data_monitoring_backup_owncloud.xls";    
header("Pragma: public");   
header("Expires: 0");   
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");     
header("Content-Type: application/force-download");     
header("Content-Type: application/octet-stream");   
header("Content-Type: application/download");   
header("Content-Disposition: attachment;filename=".$nama_file."");  
header("Content-Transfer-Encoding: binary ");

?>
<table>
<tr>
<td></td>
<td align="center">Data Monitoring Backup</td>
</tr>
<tr>
<td></td>
<td>
  <table cellpadding="8" style="border-collapse:collapse;" border="1">
      <tr>
        <td style="margin:0; white-space:nowrap;">Subdist</td>
        <td style="margin:0; white-space:nowrap;"> Nama </td>
        <td style="margin:0; white-space:nowrap;">Year</td>
         <?php                                                                                         
	    for ($i=$startweek;$i<=$endweek;$i++)                                        
	      echo ("<td colspan=3 style='margin:0; white-space:nowrap;' >Week ".str_pad($i, 2, '0', STR_PAD_LEFT) ." </td>");     
	    ?>      
		    <td style="margin:0; white-space:nowrap;">Week 1-<?php echo $curr_week; ?>(% by Subdist)</td>                  
      </tr>
	   <?php 
				if ($startweek > 0) {  
				  foreach($data_backup->result_array() as $row){?>                                            
     <tr>                                                                                        
         <td ><?php echo $row['kd_subdist'];?></td>                                               
         <td style="margin:0; white-space:nowrap;"><?php echo $row['subdist_name'];?></td> 
		 <td><?php echo $row['year'];?></td> 
		                                                     
		<?php              
		                                                                       
	   for ($i=$startweek;$i<=$endweek;$i++){                                                                   
	   $number = str_pad($i, 2, '0', STR_PAD_LEFT);                                                 
	   if ($row['wk_'.$number] == 'Y') {                                                            
	        if ($row['loc_'.$number] == 'L') { ?>                                                   
	           <td><img style="padding-top:0.5px" src="<?php echo asset_url();?>images/right.png" width="10" height="10"></td>
		       <td>L</td>
			   <td><?php echo $row['st_'.$number]=='' ? '-' : $row['st_'.$number] ; ?></td>                                                                              
	   <?php  } else if ($row['loc_'.$number] == 'O') { ?>                                          
	           <td><img src="<?php echo asset_url();?>images/wrong.png" width="10" height="10"></td>
		       <td>O</td>
			   <td><?php echo $row['st_'.$number]=='' ? '-' : $row['st_'.$number] ; ?></td>                                                                              
	   <?php  }                                                                                     
	      }else { ?>                                                                                
	           <td><img  src="<?php echo asset_url();?>images/wrong.png" width="10" height="10"></td>
		       <td> - </td>                                                                            
		      <td><?php echo $row['st_'.$number]=='' ? '-' : $row['st_'.$number] ; ?></td>                                                                                        
		  <?php }
	    } 		
		$prct   = 0;
		for ($i=1;$i<=$curr_week;$i++){
		 $number = str_pad($i, 2, '0', STR_PAD_LEFT);       
			if ($row['wk_'.$number] == 'Y') {   
				 $prct = $prct+ 1;
				 }
		 }  
 	  ?>       
	  		<td><b><?php echo round_up(($prct/$curr_week)*100,1); ?>%</b></td>                                
           </tr> 
     <?php 
	   }

	 }?>  
                                          
     <tr>                                                                                        
         <td colspan="3"><p align="right"><b>(%) by week :</b></p></td>                                               
         <?php  foreach($count_data->result_array() as $row){ 
		 
		  $row["jml"]=='0' ? $count_subdist : $row["jml"];
		  ?>
	     <td colspan="3"><p align="center"><B><?php echo round_up(($row["jml"]/$count_subdist)*100,1); ?>%</B></p></td>
                                                                           
         <?php }  ?>                                                                                 
         </tr> 
		 	  
            </tbody>
              </table>
</td>
</tr>
</table>