<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']."";
$sql="SELECT
b.id_temuan,
b.creator,
b.sumber,
b.isi_temuan,
b.lat,
b.lot,
b.id_user,
b.priority,
b.tanggal_temuan,
b.lastUpdate,
b.status_temuan,
a.area_id,
Count(c.nama_gambar) AS jmlGambar
FROM
mas_user AS a
INNER JOIN t_temuan AS b ON a.user_id = b.id_user
INNER JOIN t_gambar AS c ON b.id_temuan = c.`foreign`
WHERE
1 = 1
 ";
$sql.="AND a.area_id =".$_SESSION['id_bbws']."";
$sql.=" GROUP BY
b.id_temuan,
b.creator,
b.sumber,
b.isi_temuan,
b.lat,
b.lot,
b.id_user,
b.priority,
b.tanggal_temuan,
b.lastUpdate,
b.status_temuan,
a.area_id";
$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/eye.png); background-repeat:no-repeat; padding-left:20px; margin-left:5px;">LIST TEMUAN LAPANGAN</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>#</th>
                                            <th>Nama Temuan</th>
                                            <th>Keterangan</th>
                                            <th>Pengirim Temuan</th>
                                            <th>Tgl Temuan</th>
                                            <th>Gambar</th>
                                            <th>Status</th>
                                            <th>Action</th>
                                        </tr>
                                    </thead>
									<?php
                                    $i=0;
                                    while($row=mysql_fetch_array($query)){
                                    $i++;
                                    ?>
                                    <tr>
                                    	<td><?php echo $i; ?></td>
                                    	<td><?php echo $row['sumber'];?></td>
                                    	<td><?php echo $row['isi_temuan'];?></td>
                                    	<td><?php echo $row['creator'];?></td>
                                    	<td><?php echo date('d/m/Y',strtotime($row['tanggal_temuan']));?></td>
                                    	<td><?php echo $row['jmlGambar'];?> Gambar</td>
                                    	<td><?php echo $row['status'];?> Gambar</td>
                                    	<td align="center">
                                        <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;</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/temuanlapangan.js"></script>
