<?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">
  
<?php


$rxx=mysql_query("Select * from perusahaan where id_perusahaan='".$_SESSION['id_perusahaan']."'");
      $sss=mysql_fetch_array($rxx);
      $id_perusahaan=$sss['id_perusahaan'];
?>
  <div class="page-header">
      <h2>Join 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-"> Join Tender</i></li>
            </ol>
  </div>



<?php

if(isset($_POST['validasi']))
{
  $rs=mysql_query("Update evaluasi SET validasi='1' Where id_paket='".$_POST['id_paket']."' and id_perusahaan='$id_perusahaan'");
  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 divalidasi</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['hapus']))
{
  $rgg=mysql_query("Delete from peserta Where id_paket='".$_POST['id_paket']."' and id_perusahaan='".$_SESSION['id_perusahaan']."'");
  $rgq=mysql_query("Delete from evaluasi Where id_paket='".$_POST['id_paket']."' and id_perusahaan='".$_SESSION['id_perusahaan']."'");
  $rgw=mysql_query("Delete from kualifikasi Where id_paket='".$_POST['id_paket']."' and id_perusahaan='".$_SESSION['id_perusahaan']."'");
  $rge=mysql_query("Delete from administrasi Where id_paket='".$_POST['id_paket']."' and id_perusahaan='".$_SESSION['id_perusahaan']."'");
  $rgr=mysql_query("Delete from teknis Where id_paket='".$_POST['id_paket']."' and id_perusahaan='".$_SESSION['id_perusahaan']."'");
  $rgt=mysql_query("Delete from harga Where id_paket='".$_POST['id_paket']."' and id_perusahaan='".$_SESSION['id_perusahaan']."'");
  $rgtt=mysql_query("Delete from pemenang Where id_paket='".$_POST['id_paket']."' and id_perusahaan='".$_SESSION['id_perusahaan']."'");
   $rgts=mysql_query("Delete from file_upload Where id_paket='".$_POST['id_paket']."' and id_perusahaan='".$_SESSION['id_perusahaan']."'");


      if($rgg and $rgq and $rgw and $rge and $rgr and $rgt and $rgtt and $rgts)
      {
         ?>
        <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
      }else{
        ?>
        <div class="row">
        <div class="col-xs-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['simpan']))
{
  
  $rl=mysql_query("Select * from peserta where id_paket='".$_POST['id_paket']."' and id_perusahaan='$id_perusahaan'");
  $mm=mysql_fetch_array($rl);
  if(!$mm){
  
  $rti=mysql_query("Insert into file_upload (`id_paket`,`id_perusahaan`) values ('".$_POST['id_paket']."','$id_perusahaan')");
  $rip=mysql_query("Select * from file_upload where id_paket='".$_POST['id_paket']."' and id_perusahaan='$id_perusahaan'");
  $tt=mysql_fetch_array($rip);
  $id_file_upload=$tt['id_file_upload'];

  $rs=mysql_query("Insert into peserta (`id_paket`,`id_perusahaan`) values ('".$_POST['id_paket']."','$id_perusahaan')");
  $rw=mysql_query("Insert into administrasi (`id_paket`,`id_perusahaan`,`id_file_upload`) values ('".$_POST['id_paket']."','$id_perusahaan','$id_file_upload')");
  $rq=mysql_query("Insert into kualifikasi (`id_paket`,`id_perusahaan`,`id_file_upload`) values ('".$_POST['id_paket']."','$id_perusahaan','$id_file_upload')");
  $rr=mysql_query("Insert into teknis (`id_paket`,`id_perusahaan`,`id_file_upload`) values ('".$_POST['id_paket']."','$id_perusahaan','$id_file_upload')");
  $rt=mysql_query("Insert into harga (`id_paket`,`id_perusahaan`,`id_file_upload`) values ('".$_POST['id_paket']."','$id_perusahaan','$id_file_upload')");
 
  $ru=mysql_query("Select * from administrasi where id_paket='".$_POST['id_paket']."' and id_perusahaan='$id_perusahaan'");
  $ss=mysql_fetch_array($ru);
  $id_administrasi=$ss['id_administrasi'];

  $ri=mysql_query("Select * from kualifikasi where id_paket='".$_POST['id_paket']."' and id_perusahaan='$id_perusahaan'");
  $sq=mysql_fetch_array($ri);
  $id_kualifikasi=$sq['id_kualifikasi'];

  $ro=mysql_query("Select * from teknis where id_paket='".$_POST['id_paket']."' and id_perusahaan='$id_perusahaan'");
  $sw=mysql_fetch_array($ro);
  $id_teknis=$sw['id_teknis'];

  $rp=mysql_query("Select * from harga where id_paket='".$_POST['id_paket']."' and id_perusahaan='$id_perusahaan'");
  $se=mysql_fetch_array($rp);
  $id_harga=$se['id_harga'];

  $ruz=mysql_query("Select * from paket where id_paket='".$_POST['id_paket']."'");
  $ssz=mysql_fetch_array($ruz);
  $nama_paket=$ssz['nama_paket'];
  $nama_proyek=$ssz['nama_proyek'];
  $hps=$ssz['hps'];
  $kecamatan=$ssz['kecamatan'];

  $rup=mysql_query("Select * from perusahaan where id_perusahaan='$id_perusahaan'");
  $ssr=mysql_fetch_array($rup);
  $nama_perusahaan=$ssr['nama'];
  
  $tidak_lulus="tidak lulus";
  $ra=mysql_query("Insert into evaluasi (`id_paket`,`id_perusahaan`,`id_administrasi`,`id_kualifikasi`,`id_teknis`,`id_harga`) values ('".$_POST['id_paket']."','$id_perusahaan','$id_administrasi','$id_kualifikasi','$id_teknis','$id_harga')");
  $rz=mysql_query("Insert into pemenang (`id_paket`,`id_perusahaan`,`nama_perusahaan`,`nama_paket`,`nama_proyek`,`hps`,`kecamatan`,`status`) values ('".$_POST['id_paket']."','$id_perusahaan','$nama_perusahaan','$nama_paket','$nama_proyek','$hps','$kecamatan','$tidak_lulus')");
 
  if($rs and $rw and $rq and $rr and $rt and $ra and $rz and $rti)
  {
    ?>
      <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> Berhasil join tender</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
  }

  }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>Anda sudah mengikuti tender</center>
          
          </div></div></div>
    <?php
  }

  
}

      

?>

<table id="tabel" class="table table-bordered display" cellspacing="0" width="100%">
    <thead>
    <tr class="success">
      <th width="5%">No</th>
          <th width="40%">Nama Paket</th>
            <th width="20%"><center>Status Data</center></th>

            <th width="15%"><center>Validasi</center></th>
            <th width="20%"><center>Aksi</center></th>
         
    </tr>
    </thead>

    <tbody>
    <?php
      $nomor=0;
    
      $rw=mysql_query("Select * from perusahaan 
      JOIN evaluasi on perusahaan.id_perusahaan=evaluasi.id_perusahaan
      JOIN paket on evaluasi.id_paket=paket.id_paket
      JOIN kualifikasi on evaluasi.id_kualifikasi=kualifikasi.id_kualifikasi
      JOIN administrasi on evaluasi.id_administrasi=administrasi.id_administrasi
      JOIN teknis on evaluasi.id_teknis=teknis.id_teknis
      JOIN harga on evaluasi.id_harga=harga.id_harga
      where evaluasi.id_perusahaan='$id_perusahaan' ");
      while($st=mysql_fetch_array($rw))
      {$nomor++;
        $hps=format_rupiah($st['hps']);
        $raw=mysql_query("Select * from file_upload where id_perusahaan='".$st['id_perusahaan']."'");
           $s=mysql_fetch_array($raw);
      ?>
      <tr>
        <td align="center"><?php echo $nomor; ?></td>
        <td><?php echo $st['nama_paket']; ?></td>
        <?php 
        if(empty($s['skk1'] and $s['skk2'] and $s['skk3'] and $s['skk4'] and $s['skk5'] and $s['ska1'] and $s['ska2'] and $s['ska3'] and $s['ska4'] and $s['ska5'] and $s['skt1'] and $s['skt2'] and $s['skt3'] and $s['skt4'] and $s['skt5'] and $s['skh1'] and $st['harga_penawaran'] )){
          ?>
          <td align="center"><p class="label label-danger">Belum Lengkap<p></td>
          <?php
        }else{
          ?>
          <td align="center"><p class="label label-success">Lengkap</p></td>
          <?php
        }

         ?>
          <?php 
        if($st['validasi']=='0'){
          ?>
          <td align="center"><p class="label label-danger">Belum validasi<p></td>
          <?php
        }else{
          ?>
          <td align="center"><p class="label label-success">Validasi</p></td>
          <?php
        }

         ?>
        
        
        <?php
        if($st['validasi']=='0'){
          ?>
          <td align="center">
           <div class="btn-group" role="group">
    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
      Aksi
      <span class="caret"></span>
    </button>
    <ul class="dropdown-menu">
      
          <li>
       <a href="?cat=perusahaan&page=upload_data&id_paket=<?php echo $st['id_paket'];?>"  ><i class="fa fa-edit" > Isi Data  </i></a>
        </li>
           <li>
       <a href="#"  data-toggle="modal" data-target="#modal_validasi<?php echo $st['id_paket'];?>"><i class="fa fa-check" > Validasi Data  </i></a>
        </li>
        <li class="divider"></li>
      <li>
      <a href="#" data-toggle="modal" data-target="#modal_join<?php echo $st['id_paket'];?>"><i class="fa fa-times" > Batal Join  </i></a>
         </li>

    </ul>

  </div>
         
        </td>
          <?php
        }else{
          ?>
           <td align="center">
      
        <a type="button" href="?cat=perusahaan&page=lihat_data&id_paket=<?php echo $st['id_paket'];?>" class="btn btn-default tooltipsku" data-placement="top" title="Lihat Data"  ><i class="fa fa-eye" >   </i></a>
        </td>
          
          <?php
        }
        ?>
       
   
     
    </tr>
    <?php
     
   }
    ?>
    </tbody>
</table>
</div>
</div>
</div>

<?php
$rw=mysql_query("Select * from paket");
while($s=mysql_fetch_array($rw)){
?>
<div id="modal_join<?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" 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 Membatalkan Tender <strong style="color:red"> <?php echo $s['nama_paket'];?></strong>?</center>
        </div></div>
   </div>

      <input type="hidden" class="form-control" name="id_paket" value="<?php echo $s['id_paket'];  ?>" required > 
      
            </div>
 
 <div class="modal-footer">
        <button type="submit" name="hapus" class="btn btn-primary">OK</button>
      </div>
            </form>
        </div>
    </div>
</div>
<?php
}
?>




<?php
$rw=mysql_query("Select * from paket");
while($s=mysql_fetch_array($rw)){
?>
<div id="modal_validasi<?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" enctype="multipart/form-data">
<div class="form-group">
    <div class="col-md-offset-1 col-md-10">
        <div class="alert alert-info  alert-dismissable">
        <button type="button" class="close" data-dismiss="alert"></button>
        <center>Ingat! Validasi data mengakibatkan Anda tidak bisa mengisi data dan tidak bisa membatalkan Join Tender</center>
        </div></div>
   </div>
<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 Memvalidasi Data?</center>
        </div></div>
   </div>

      <input type="hidden" class="form-control" name="id_paket" value="<?php echo $s['id_paket'];  ?>" required > 
      
            </div>
 
 <div class="modal-footer">
        <button type="submit" name="validasi" class="btn btn-primary">VALIDASI</button>
      </div>
            </form>
        </div>
    </div>
</div>
<?php
}
?>



