<?php
include "asset/fungsi/fungsi_indotgl.php";
include "asset/fungsi/fungsi_rupiah.php";
?>
<div class="col-md-9">
<div class="panel panel-default">
<div class="panel-body">

	<div class="page-header">
			<h2>Paket Tender</h2>
			<ol class="breadcrumb">

				<li><a href="dashboard.php"><i class="fa fa-home"> Home</i></a></li>
				<li class="active"><i class="fa fa-tasks"> Paket Tender </i></li>
            </ol>
	</div>
	
<?php

if(isset($_POST['delete'])){
	$rs=mysql_query("Delete from paket Where id_paket='".$_POST['id_paket']."'");
			if($rs)
			{
				 ?>
				<div class="row">
				<div class="col-xs-offset-2 col-md-8">
				<div class="alert alert-success  alert-dismissable">
				<button type="button" class="close" data-dismiss="alert">x</button>
				<center>Data Berhasil dihapus</center>
				</div></div></div>
	 
				<?php
			}
}

if(isset($_POST['tambah']))
{
   if (!empty($_FILES['file']['name'])) 
  {
    $file = $_FILES['file']['name'];
    move_uploaded_file($_FILES['file']['tmp_name'], "asset/img/file/".$_FILES['file']['name']);
  
  }
	$rs=mysql_query("Insert into paket (`nama_paket`,`nama_proyek`,`hps`,`kecamatan`,`file`) values ('".$_POST['nama_paket']."','".$_POST['nama_proyek']."','".$_POST['hps']."','".$_POST['kecamatan']."','$file')");
	if($rs)
	{
		?>
      <div class="row">
          <div class="col-md-offset-2 col-md-8">
          <div class="alert alert-success  alert-dismissable">
          <button type="button" class="close" data-dismiss="alert">x</button>
            <center>Data Berhasil ditambahkan</center>
          
          </div></div></div>
    <?php
	}else
	{
		?>
      <div class="row">
          <div class="col-md-offset-2 col-md-8">
          <div class="alert alert-danger  alert-dismissable">
          <button type="button" class="close" data-dismiss="alert">x</button>
            <center>Terjadi kesalahan</center>
          
          </div></div></div>
    <?php
	}
  
}

if(isset($_POST['edit']))
{
  if (!empty($_FILES['file']['name'])) 
  {
    $file = $_FILES['file']['name'];
    move_uploaded_file($_FILES['file']['tmp_name'], "asset/img/file/".$_FILES['file']['name']);
      $rs=mysql_query("Update paket SET nama_paket='".$_POST['nama_paket']."', nama_proyek='".$_POST['nama_proyek']."', hps='".$_POST['hps']."', kecamatan='".$_POST['kecamatan']."', file='$file' Where id_paket='".$_POST['id_paket']."'");
  }else{
      $rs=mysql_query("Update paket SET nama_paket='".$_POST['nama_paket']."', nama_proyek='".$_POST['nama_proyek']."', hps='".$_POST['hps']."', kecamatan='".$_POST['kecamatan']."' Where id_paket='".$_POST['id_paket']."'");
  }
if($rs)
	{
		?>
    <div class="row">
          <div class="col-md-offset-2 col-md-8">
          <div class="alert alert-success  alert-dismissable">
          <button type="button" class="close" data-dismiss="alert">x</button>
            <center>Data Berhasil diperbaharui</center>
          
          </div></div></div>
    <?php
	}else
	{
		?>
      <div class="row">
          <div class="col-md-offset-2 col-md-8">
          <div class="alert alert-danger  alert-dismissable">
          <button type="button" class="close" data-dismiss="alert">x</button>
            <center>Terjadi kesalahan</center>
          
          </div></div></div>
    <?php
	}
  
}

			

?>
<button class="btn btn-primary tooltipsku" type="button" data-placement="top" title="Tambah Paket" data-toggle="modal" data-target="#modal_tambah"><i class="fa fa-plus"></i></button>
  <p></p>

<table id="tabel" class="table table-bordered display" cellspacing="0" width="100%">
		<thead>
		<tr class="success">
			<th width="5%">No</th>
        	<th width="20%">Nama Paket</th>
            <th width="20%">Nama Proyek</th>
            <th width="15%">HPS</th>
            <th width="15%">Keterangan</th>

            <th width="10%">File Pendukung</th>
            <th width="10%">Status</th>
            <th width="15%"><center>Aksi</center></th>
         
		</tr>
		</thead>

		<tbody>
		<?php
  		$nomor=0;
  		$rw=mysql_query("Select * from paket order by id_paket DESC");
  		while($s=mysql_fetch_array($rw))
  		{$nomor++;
        $rwq=mysql_query("Select * from pemenang where id_paket='".$s['id_paket']."'");
      $sq=mysql_fetch_array($rwq);
        $hps=format_rupiah($s['hps']);
  		?>
   		<tr>
    		<td align="center"><?php echo $nomor; ?></td>
    		<td><?php echo $s['nama_paket']; ?></td>
    		<td><?php echo $s['nama_proyek']; ?></td>
    		<td><?php echo"Rp. ";echo $hps; ?></td>
    		<td><?php echo $s['kecamatan']; ?></td>
        <td>
          <center>
           <?php
        if ($s['file'] != NULL) 
        {
          ?>
          <a class="btn btn-default tooltipsku" target="_blank"  href="asset/img/file/<?php echo $s['file']; ?>" data-placement="top" title="Lihat"><i class="fa fa-eye"></i></a>
        
          <?php
        }else{
          echo"<span class='label label-danger'>Tidak ada file</span>";
        }
        ?>
      </center>
        </td>

        <td>
          <center>
        <?php
        if($sq['keterangan']==0){
          echo"<span class='label label-info'>Ongoing</span>";
        }else{

          echo"<span class='label label-danger'>Expired</span>";
        }
        ?>
        </center>
      </td>
    		<td >
    	<center>
       
        <button href="#" class="btn btn-default tooltipsku" data-placement="top" title="Edit" data-toggle="modal" data-target="#modal_edit<?php echo $s['id_paket'];?>"><i class="fa fa-edit" >   </i></button>
    		
    		<button href="#"  class="btn btn-danger tooltipsku" data-placement="top" title="Hapus" data-toggle="modal" data-target="#modal_delete<?php echo $s['id_paket'];?>"><i class="fa fa-trash" >   </i></Button>
    	</center>
    		</td>
		</tr>
		<?php
 		 }
 		?>
		</tbody>
</table>
</div></div></div>

<?php
$rw=mysql_query("Select * from paket");
while($s=mysql_fetch_array($rw)){
  $hps=($s['hps']);
?>
<div id="modal_edit<?php echo $s['id_paket'];?>" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Ubah Paket</h4>
            </div>
            <div class="modal-body">
<form class="form-horizontal" method="post" action="dashboard.php?cat=web&page=paket" role="form" enctype="multipart/form-data">
    <input type="hidden" class="form-control" id="id_paket<?php echo $s['id_paket'];?>" name="id_paket" value="<?php echo $s['id_paket'];  ?>" required > 
<div class="form-group">
    <center>  <label for="nama_paket" class="col-sm-4 control-label" >Nama Paket</label></center>
      <div class="col-md-8">
         <input type="text" class="form-control" id="nama_paket<?php echo $s['id_paket'];?>" name="nama_paket" value="<?php echo $s['nama_paket'];  ?>" required > 
      </div>
   </div>
   <div class="form-group">
    <center>  <label for="nama_proyek" class="col-sm-4 control-label" >Nama Proyek</label></center>
      <div class="col-md-8">
         <input type="text" class="form-control" id="nama_proyek<?php echo $s['id_paket'];?>" name="nama_proyek" value="<?php echo $s['nama_proyek'];  ?>" required > 
      </div>
   </div>
   
    <div class="form-group">
    <center>  <label for="hps" class="col-sm-4 control-label">HPS </label></center>
      <div class="col-md-8">
       <div class="input-group">
      <div class="input-group-addon">Rp.</div>
         <input rows="3" class="form-control" name="hps" value="<?php echo $hps;  ?>" required > 
      <div class="input-group-addon">.00</div>
    </div>
      </div>
   </div>
   <div class="form-group">
    <center>  <label for="kecamatan" class="col-sm-4 control-label">Keterangan </label></center>
      <div class="col-md-8">
         <input type="text" class="form-control" id="kecamatan<?php echo $s['id_paket'];?>" name="kecamatan" value="<?php echo $s['kecamatan'];  ?>" required > 
      </div>
   </div>
   <div class="form-group">
    <center>  <label for="kecamatan" class="col-sm-4 control-label">File Pendukung </label></center>
      <div class="col-md-8">
        <?php
        if ($s['file'] != NULL) 
        {
          ?>
         <a class="btn btn-default tooltipsku" target="_blank"  href="asset/img/file/<?php echo $s['file']; ?>" data-placement="top" title="Lihat"><i class="fa fa-eye"></i></a>
        <?php
        }
        ?>
        
         <input type="file" class="form-control"  name="file" value="<?php echo $s['file'];  ?>" > 
      </div>
   </div>

      
            </div>
 
 <div class="modal-footer">
        <button type="submit" name="edit" class="btn btn-primary">Update</button>
      </div>
            </form>
        </div>
    </div>
</div>
<?php
}
?>

<?php
$rw=mysql_query("Select * from paket");
while($s=mysql_fetch_array($rw)){
?>
<div id="modal_delete<?php echo $s['id_paket'];?>" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Konfirmasi </h4>
            </div>
            <div class="modal-body">
		

<form class="form-horizontal" role="form" method="post" action="dashboard.php?cat=web&page=paket" enctype="multipart/form-data">
<div class="form-group">
    <div class="col-md-offset-1 col-md-10">
				<div class="alert alert-danger  alert-dismissable">
				<button type="button" class="close" data-dismiss="alert"></button>
				<center>Apakah Anda Yakin akan Menghapus <strong style="color:red"> <?php echo $s['nama_paket'];?></strong>?</center>
				</div></div>
   </div>

            </div>
              <input type="hidden" class="form-control" id="id_paket<?php echo $s['id_paket'];?>" name="id_paket" value="<?php echo $s['id_paket'];  ?>" required > 

  <div class="modal-footer">
        <button type="submit" name="delete" class="btn btn-danger">Hapus</button>
      </div>
            </form>
        </div>
    </div>
</div>
<?php
}
?>

<div id="modal_tambah" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Tambah Paket</h4>
            </div>
            <div class="modal-body">

<form class="form-horizontal" id="paket" action="dashboard.php?cat=web&page=paket" method="post" role="form" enctype="multipart/form-data">
  
<div class="form-group">
    <label for="nama_paket" class="col-sm-4 control-label" >Nama Paket</label>
      <div class="col-md-8">
         <input type="text" class="form-control" id="nama_paket" name="nama_paket" placeholder="Nama Paket"   required > 
      </div>
   </div>
   <div class="form-group">
     <label for="nama_proyek" class="col-sm-4 control-label" >Nama Proyek</label>
      <div class="col-md-8">
      
         <input type="text" class="form-control" id="nama_proyek" name="nama_proyek" placeholder="Nama Proyek"  required > 
      </div>
   </div>
   
    <div class="form-group">
   <label for="hps" class="col-sm-4 control-label">Harga Perkiraan Sendiri </label>
      <div class="col-md-8">
       <div class="input-group">
      <div class="input-group-addon">Rp.</div>
         <input rows="3" class="form-control" id="hps" name="hps" placeholder="50000000" required >
     <div class="input-group-addon">.00</div>
    </div>
      </div>
   </div>
   <div class="form-group">
   <label for="kecamatan" class="col-sm-4 control-label">Keterangan </label>
      <div class="col-md-8">
         <input type="text" class="form-control" id="kecamatan" name="kecamatan" placeholder="Keterangan" required > 
      </div>
   </div>
   <div class="form-group">
   <label for="kecamatan" class="col-sm-4 control-label">File Pendukung </label>
      <div class="col-md-8">
         <input type="file" class="form-control" id="kecamatan" name="file" > 
      </div>
   </div>
  
            </div>
 <div class="modal-footer">
        <button type="submit" name="tambah" class="btn btn-primary">Tambah</button>
      </div>
            </form>
        </div>
    </div>
</div>
</div>
</div>
