<?php
$this->load->view('vwHeader');
?>
      <div id="page-wrapper">
        <div class="row">
          <div class="col-lg-12">
            <h1>Monitoring <small> Backup Subdist (ownCloud)</small></h1>
            <ol class="breadcrumb">
              <li><a href="dashboard"><i class="icon-dashboard"></i> Backup Subdist</a></li>
              <li class="active"><i class="icon-file-alt"></i> Backup Subdist</li>             
              <div style="clear: both;"></div>
            </ol>
          </div>
        </div><!-- /.row -->
            <div class="table-responsive">
			<div class="form-signin">
			 <form class="form-signin panel" method="post" action="<?php echo base_url(); ?>dashboard">
			 	<label>Tahun&nbsp;&nbsp;&nbsp;&nbsp;:</label>
				<?php $now=date("Y"); ?>
				<select class="form-filter"  name='tahun' id='tahun'>
				<option value=0>--Semua Tahun--</option>
                <?php  for ($a=$now;$a>=2012;$a--) { 
					if($_POST['tahun'] == $a) $selected='selected=true'; else $selected= '';

				?>
                      <option <?php echo $selected; ?> value=<?php echo $a; ?>><?php echo $a; ?></option>";
                 <?php  } ?>
               </select><br />
				<label>Period&nbsp;&nbsp;&nbsp;:</label>
				<select class="form-filter" name="startperiod" id="startperiod">
				<option value=0>--Pilih Periode--</option>
				<?php 
				  for ($i=1;$i<=12;$i++) {
				   if($startperiod == $i) $selected='selected=true'; else $selected= '';

				?>
					<option <?php echo $selected; ?> value=<?php echo $i; ?>><?php echo str_pad($i, 2, '0', STR_PAD_LEFT); ?></option>
				<?php } ?>	
				</select>				
				 <label>to</label>
				<select class="form-filter" name="endperiod" id="endperiod">
				<option value=0>--Pilih Periode--</option>
				<?php 
				  for ($i=1;$i<=12;$i++) {
				   		if($endperiod == $i) $selected='selected=true'; else $selected= '';
				?>
					<option <?php echo $selected; ?> value=<?php echo $i; ?>><?php echo str_pad($i, 2, '0', STR_PAD_LEFT); ?></option>
				<?php } ?>	
				</select><br />				
				<label>Subdist :</label>
				<select class="form-filter" name="subdist" id="subdist">
				<option value='0'>--Semua Subdist--</option>
				<?php 
				 foreach($subdist as $row) {
				 
				 if($kd_subdist == $row->kd_subdist) $selected='selected=true'; else $selected= '';
				?>
					<option <?php echo $selected; ?> value='<?php echo $row->kd_subdist; ?>'><?php echo $row->kd_subdist; ?> - <?php echo $row->subdist_name; ?> </option>
				<?php } ?>	
				</select><br /><br />
				 <button type="submit" class="btn btn-primary" type="submit"><i class="fa fa-search"></i> Search</button>
				 <a class="btn btn-outline btn-default" href="<?php echo base_url(); ?>index.php/dashboard/export"><i class="icon-ok-circle"></i> Export XLS</a>
		
			  </form>	 
			</div>
			<ol class="breadcrumb">L = Lokal | C = Complete | O = OwnCloud | D = Delete</ol>

			<div style="width:100%; overflow: auto;">
              <table class="table table-hover tablesorter" >
                <thead>
                  <tr>
                    <th class="header" style="margin:0; white-space:nowrap;">Subdist </th>
					<th class="header" style="margin:0; white-space:nowrap;">Nama </th>
                    <th class="header" style="margin:0; white-space:nowrap;">Year</th>
					 <?php                                                                                         
	    for ($i=$startweek;$i<=$endweek;$i++){                                                                  
	      echo ("<th class=header style='margin:0; white-space:nowrap;'>Week ".str_pad($i, 2, '0', STR_PAD_LEFT) ." </th>");                  
	    }                                                                                           
	  ?>
	    <th class="header" style="margin:0; white-space:nowrap;">Week <?php echo $startweek; ?>-<?php echo $endweek; ?>(% by Subdist)</th>
                  </tr>
                </thead>
                <tbody>
				  <?php
				  
				  $percentage = 0;
				  if ($startweek > 0) {  
				  foreach($query->result_array() as $row){
				  
				  ?>                                            
     <tr>                                                                                        
         <td ><?php echo $row['subdist_id'];?></td>                                               
         <td style="margin:0; white-space:nowrap;"><?php echo $row['subdist_name'];?></td> 
		 <td><?php echo $row['year']=='' ? '-' : $row['year']; ?></td> 
		                                                     
		<?php              
		             $ii=0;
					$week=$endweek-$startweek;


	   for ($i=$startweek;$i<=$endweek;$i++){                                                                   
	   $number = str_pad($i, 2, '0', STR_PAD_LEFT); ?>  
       <td style="width:0.3px">                       
	           
	   <?php if ($row['wk_'.$number] == 'Y') {   ?>
	           <img src="<?php echo asset_url();?>images/right.png" width="15" height="15"> 
       <?php } else if ($row['wk_'.$number] == 'O' || $row['wk_'.$number] == '') { ?>
	           <img src="<?php echo asset_url();?>images/wrong.png" width="15" height="15">      
	   <?php  }  
	   
	        if ($row['loc_'.$number] == 'L')  
			   echo ('<b>L</b>');
			else if ($row['loc_'.$number] == 'O')  
			   echo ('<b>O</b>');
			else
			   echo ('<b></b>');
			   
		?>
			   <b><?php echo $row['st_'.$number]=='' ? '-' : $row['st_'.$number] ; ?></b>                                                  
	   
	    </td>
	    <?php
		//print_r($number);
	    } 		
		$prct=0;
		 for ($i=$startweek;$i<=$endweek;$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/($week+1))*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){
		  //for ($i=$startweek;$i<=$endweek;$i++){ 
		    //  $number = str_pad($i, 2, '0', STR_PAD_LEFT);       
		    
		 //}
		 //
		 $row["jml"]=='0' ? $count_subdist : $row["jml"];
		 
		 ?>                                            
	     <td><p align="center"><B><?php echo round_up(($row["jml"]/$count_subdist)*100,1); ?>%</B></p></td>
                                                                            
         <?php 
		   //}   
		 }  ?>                                                                                 
         </tr> 
		 	  
            </tbody>
              </table>
			  </div>
            </div>
			
        <?php 
		
		echo $links; ?>
		

        
        
      </div><!-- /#page-wrapper -->

<table>
</table>

<?php
$this->load->view('vwFooter');
?>
