<style>
.black_overlay{
	display: none;
	position: absolute;
	top: 0%;
	left: 0%;
	width: 100%;
	height: 100%;
	background-color: black;
	z-index:1001;
	-moz-opacity: 0.8;
	opacity:.80;
	filter: alpha(opacity=80);
}

.white_content {
background-color: white;
    border: 2px solid orange;
    display: none;
    height: 75%;
    left: 16%;
    overflow: auto;
    padding: 16px;
    position: absolute;
    top: 8%;
    width: 67%;
    z-index: 1002;
}
</style>
<script type="text/javascript">
function detail(id_monev){
			$.ajax({ url: "view/detailmonev.php?id_monev="+id_monev, 
		    type: "GET",
			success: function(msg){
					$("#detailformmonev").html(msg); 
				} 
	}); 
}
function Openfile(id_monev){
			$.ajax({ url: "modules/openPDF.php?id_monev="+id_monev, 
		    type: "GET",
			success: function(msg){
					$("#detailformmonev").html(msg); 
				} 
	}); 
}

</script>
<?php
session_start();
include "config/conn.php";
if($_POST['btncari']=="Search") {
	$tglf=$_POST['tglf'];
	$tgls=$_POST['tgls'];
} else { 
	$tglf= date('Y-m-d');
	$tgls = date('Y-m-d',strtotime('-1 day',strtotime($tglf))) ;
}
$sql="SELECT * FROM m_lokasi INNER JOIN t_monev ON t_monev.id_lokasi=m_lokasi.id_lokasi WHERE 1=1 AND m_lokasi.id_bbws=".$_SESSION['id_bbws']."";
$query=mysql_query($sql);

if($_POST['simpan']=="Simpan"){
		$id_monev=strip_tags($_POST['id_monev']);
		$peserta_monev=strip_tags($_POST['peserta_monev']);
		$tgl_monev=$_POST['tgl_monev'];
		$ibbws=trim($_POST['ibbws']);
		$id_lokasi=strip_tags($_POST['id_lokasi']);
		$gpa=strip_tags($_POST['gpa']);
		$note_gpa=strip_tags($_POST['note_gpa']);
		$sensor=strip_tags($_POST['sensor']);
		$note_sensor=strip_tags($_POST['note_sensor']);
		$solarcell=strip_tags($_POST['solarcell']);
		$note_solarcell=strip_tags($_POST['note_solarcell']);
		$solarcharger=strip_tags($_POST['solarcharger']);
		$note_solarcharger=strip_tags($_POST['note_solarcharger']);
		$baterai=strip_tags($_POST['baterai']);
		$note_baterai=strip_tags($_POST['note_baterai']);
		$lainlain=strip_tags($_POST['lainlain']);
		$note_lainlain=strip_tags($_POST['note_lainlain']);
		$tgl_tindakan=strip_tags($_POST['tgl_tindakan']);
		$tindakan=strip_tags($_POST['tindakan']);
		$hasil_tindakan=strip_tags($_POST['hasil_tindakan']);
		$keterangan=strip_tags($_POST['keterangan']);
		$status=strip_tags($_POST['status']);
		$tindakan_sensor=strip_tags($_POST['tindakan_sensor']);
		$tindakan_solarcell=strip_tags($_POST['tindakan_solarcell']);
		$tindakan_solarcharger=strip_tags($_POST['tindakan_solarcharger']);
		$tindakan_baterai=strip_tags($_POST['tindakan_baterai']);
		$fileNameMonev = "monev_".$_FILES['filemonev']['name'];
		$fileNamePerbaikan = "perbaikan_".$_FILES['fileperbaikan']['name'];

		if ($id_monev=="") {
		   	// INSERT m_lokasi
			$sqlinsertmmonev="INSERT INTO t_monev values('','','$ibbws','$id_lokasi','$tgl_monev','$peserta_monev','$gpa','$note_gpa','$sensor','$note_sensor','$solarcell','$note_solarcell','$solarcharger','$note_solarcharger','$baterai','$note_baterai','$lainlain','$note_lainlain','$tindakan','$note_tindakan','','','',now(),'Open','','','','','$fileNameMonev','')";
		    $query=mysql_query($sqlinsertmmonev);
			if($query){
				move_uploaded_file($_FILES['filemonev']['tmp_name'], "file/monev/".$_FILES['filemonev']['name']);
				echo "<script>alert('Input hasil monev berhasil disimpan!');history.go(-1);</script>";
			}
		} else {
		$sql="UPDATE t_monev SET gpa='$gpa', sensor='$sensor',solarcell='$solarcell',solarcharger='$solarcharger',baterai='$baterai',lainlain='$lainlain',tindakan='$tindakan',hasil_tindakan='$hasil_tindakan',keterangan='$keterangan',tgl_tindakan='$tgl_tindakan',status='$status',tindakan_sensor='$tindakan_sensor',tindakan_solarcell='$tindakan_solarcell',tindakan_solarcharger='$tindakan_solarcharger',tindakan_baterai='$tindakan_baterai',file_perbaikan='$fileNamePerbaikan'
		WHERE id_monev='$id_monev'";			
		$query=mysql_query($sql);
			if($query){
				move_uploaded_file($_FILES['fileperbaikan']['tmp_name'], "file/perbaikan/".$_FILES['fileperbaikan']['name']);
				echo"<script>alert('Update data monev berhasil !');history.go(-1);</script>";
			}
		}
}
?>

<div id="light" class="white_content"><div id="detailformmonev"></div></div>
        <div id="fade" class="black_overlay"></div>
        
		<article class="module width_4_quarter">
		<header>
		<h3 class="tabs_involved" style="background-image:url(images/icons/stats_lines.png); background-repeat:no-repeat; padding-left:20px; margin-left:5px;">LIST DATA MONITORING DAN EVALUASI POS TELEMETRY</h3>
		<form action="" method="post">
        <ul class="tabs">
        	<li><!--Periode : <input type="text" id="tgls" name="tgls" value="<?php echo date('Y-m-d',strtotime($tgls));?>" size="10" /> s/d <input type="text" id="tglf" name="tglf" value="<?php echo date('Y-m-d',strtotime($tglf));?>" size="10" /-->
            	<input type="button" id="btnd" name="btnd" value="Download Xls" />&nbsp;<input type="button" id="btntambah" name="btntambah" value="Tambah" onclick="tambah()" />	
            </li>
        </ul>
        </form>
		</header>
		<div class="tab_container">
        <div id="formmonev">
        		<table class="tablesorter" cellspacing="0" border="1">
                                   <thead>
                                        <tr>
                                            <th rowspan="2">#</th>
                                            <th rowspan="2">Nama Lokasi</th>
                                            <th rowspan="2">Jenis</th>
                                            <th rowspan="2">Tgl Monev</th>
                                            <th colspan="7" align="center">STATUS PERANGKAT <br />
<img src='images/icon_offline3.png'/> : Rusak&nbsp;&nbsp; <img src='images/icon_online3.png'/> : Baik</th>
                                            <th rowspan="2">Status</th>
                                            <th rowspan="2">Action</th>
                                        </tr>
                                        <tr>
                                            <th>GPA</th>
                                            <th>Sensor</th>
                                            <th>Solarcell</th>
                                            <th>Solarcharger</th>
                                            <th>Baterai</th>
                                            <th>Kartu</th>
                                            <th>lainya</th>
                                        </tr>
                                    </thead>
									<?php
                                    $i=0;
                                    while($row=mysql_fetch_array($query)){
                                    $i++;
									if($row['gpa']=="Baik") { $icogpa="<img src='images/icon_online3.png' />";  }
										else { $icogpa="<img src='images/icon_offline3.png'/>"; }
									if($row['sensor']=="Baik") { $icosensor="<img src='images/icon_online3.png' />";  }
										else { $icosensor="<img src='images/icon_offline3.png'/>"; }
									if($row['solarcell']=="Baik") { $icosolarcell="<img src='images/icon_online3.png' />";  }
										else { $icosolarcell="<img src='images/icon_offline3.png'/>"; }
									if($row['solarcharger']=="Baik") { $icosolarcharger="<img src='images/icon_online3.png' />";  }
										else { $icosolarcharger="<img src='images/icon_offline3.png'/>"; }
									if($row['baterai']=="Baik") { $icobaterai="<img src='images/icon_online3.png' />";  }
										else { $icobaterai="<img src='images/icon_offline3.png'/>"; }
									
									if($row['status']=="Open") { 
										$bgsts="style='background-image:url(images/icdanger.png); background-repeat:no-repeat; padding-left:20px;'";
									} else if($row['status']=="Progress") { 
										$bgsts="style='background-image:url(images/icwarning.png); background-repeat:no-repeat; padding-left:20px;'";
									} else if($row['status']=="Close") { 
										$bgsts="style='background-image:url(images/icsukses.png); background-repeat:no-repeat; padding-left:20px;'";
									}
                                    ?>
                                    <tr>
                                    	<td><?php echo $i; ?></td>
                                    	<td><?php echo $row['nama_lokasi'];?></td>
                                    	<td><?php echo $row['id_tipe'];?></td>
                                    	<td><?php echo date('d/m/Y',strtotime($row['tgl_monev']));?></td>
                                    	<td align="center"><?php echo $icogpa;?></td>
                                    	<td align="center"><?php echo $icosensor;?></td>
                                    	<td align="center"><?php echo $icosolarcell;?></td>
                                    	<td align="center"><?php echo $icosolarcharger;?></td>
                                    	<td align="center"><?php echo $icobaterai;?></td>
                                    	<td align="center"><?php echo $row['kartu'];?></td>
                                    	<td align="center"><?php echo $row['lainlain'];?></td>
                                    	<td <?php echo $bgsts;?>><?php echo $row['status'];?></td>
                                    	<td>
                                        <a href = "javascript:void(0)" onclick = "document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block';detail(<?php echo $row['id_monev'];?>)">
                                        <img src="images/icons/page_white_edit.png"/></a>
                                        <!--a href = "javascript:void(0)" onclick = "document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block';detail(<?php echo $row['id_monev'];?>)">
                                        <img src="images/icons/print.png"/></a-->&nbsp;
                                        <a href="javascript:void(0);" onclick="javascipt:window.open('file/monev/a.pdf');" class="popup">
                                        <img src="images/icons/icon_pdf.png"/></a>
                                        
                                        </td>
                                    </tr>
                                    <?php }?>
                                </table>
			</div>
		</div><!-- end of .tab_container -->
		</article><!-- end of content manager article -->        
<script src="js/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="js/manmonev.js"></script>
