<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/js/swal/sweetalert.css');?>">
<script src="<?php echo base_url('assets/js/swal/sweetalert.js');?>"></script>
<link rel="stylesheet" href="<?php echo base_url('assets/peta/leaflet.css');?>" />
<script src="<?php echo base_url('assets/peta/leaflet-src.js');?>"></script>
<script language="JavaScript" type="text/JavaScript">
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
</script>
</script>
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            Peta Absen
            <small>Version <?php echo $versiapp;?></small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li class="active">Peta Absen</li>
        </ol>
    </section>
    <!-- Main content -->
    <section class="content">
      <div class="row">
      <div class="col-md-12 ">
      <?php

      $jenis=$this->input->get('jenis');
      $dd=$this->input->get('dd');
      $mm=$this->input->get('mm');
      $yy=$this->input->get('yy');
      if (!$dd) $dd=date('d');
      if (!$mm) $mm=date('m');
      if (!$yy) $yy=date('Y');
      $harike3=substr(hari($dd,$mm,$yy),0,3);
      ?>
      <center>
      <table><tr><td>TANGGAL</td><td>:</td><td>
        <select  name="mm" onChange="MM_jumpMenu('parent',this,0)">
          <?php if (!$dd=='') { ?>
            <option><?php echo $dd;?></option>
          <?php } else {?>
          <?php }
            for ($i=1;$i<=31;$i++) {
                  echo "<option value='?yy=$yy&mm=$mm&dd=$i'>$i</option>";
             } ?>

        </select>
        <select  name="mm" onChange="MM_jumpMenu('parent',this,0)">
          <?php if (!$mm=='') { ?>
            <option><?php echo bulan($mm);?></option>
          <?php } else {?>
          <?php }
            for ($i=1;$i<=12;$i++) {
                  echo "<option value='?yy=$yy&mm=$i&dd=$dd'>".bulan($i)."</option>";
             } ?>

        </select>
        <select  name="yy" onChange="MM_jumpMenu('parent',this,0)">
          <?php if (!$yy=='') { ?>
            <option><?php echo $yy;?></option>
          <?php }
            for ($i=date("Y");$i>date('Y')-10;$i-=1){
                  echo "<option value='?yy=$i&mm=$mm&dd=$dd'>$i</option>";
             } ?>

        </select>
        </td>
        </tr>
        <tr><td>HARI</td><td>:</td><td><b><?php echo hari($dd,$mm,$yy);?></b></td></tr>
        <tr><td>TAMPILKAN</td><td> :</td><td>
          <select name="jenis" onChange="MM_jumpMenu('parent',this,0)">
          <?php if (!$jenis=='') {
              $jurusan1=$this->db->query("SELECT * FROM web_kelas WHERE kode='".$jenis."' ORDER BY urut ASC");
              foreach ($jurusan1->result() as $row1) {
              $nama1=$row1->nama;
              }
            ?>

            <option><?php echo $nama1;?></option>
          <?php } else {?>
          <option selected>ALL</option>
          <?php }
          echo "<option value='?yy=$yy&mm=$mm&dd=$dd&jenis='>ALL</option>";
          $jurusan=$this->db->query("SELECT * FROM web_kelas ORDER BY urut ASC");
                  foreach ($jurusan->result() as $row) {
                  $kode=$row->kode;
                  $nama=$row->nama;
                  echo "<option value='?yy=$yy&mm=$mm&dd=$dd&jenis=$kode'>$nama</option>";
          ?>
          <?php } ?>

          </select>
          </td></tr>
        </table>
      </div>
    </div>
        <div class="row">
			<div class="col-md-12 font">
        <div id="map" style="width:100%; height:400px;"></div>
        <script type='text/javascript'>
        var mymap = L.map('map').setView([<?php echo $koordinat;?>], 13);
        L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
            maxZoom: 18,
            attribution: '',
            id: 'mapbox.streets'
        }).addTo(mymap);

        var markers = [
          <?php
          $skrg="$yy-$mm-$dd";
          if ($jenis =="ALL") {
            $carikelas="SELECT * FROM web_kelas ORDER BY urut ASC";
          }elseif($jenis ==""){
            $carikelas="SELECT * FROM web_kelas ORDER BY urut ASC";
          } else {
            $carikelas="SELECT * FROM web_kelas WHERE kode='".$jenis."' ORDER BY urut ASC";
          }
          $kelas = $this->db->query($carikelas);
          foreach ($kelas->result() as $rs) {
            $namakelas=$rs->nama;
            $kodekelas=$rs->kode;
            $jurusan1=$this->db->query("SELECT * FROM web_siswa WHERE KD_JENIS_KETENAGAAN='$kodekelas'");
            foreach ($jurusan1->result() as $row1) {
             $namapeg=$row1->NM_PEGAWAI;
             $kodeabsen=$row1->absen;
              $jurusan=$this->db->query("SELECT nip,lat_x,lat_y FROM web_absen where status='1' AND nip='$kodeabsen' and tgl='$skrg' and lat_x <>''");
              foreach ($jurusan->result() as $row) {
                $kode=$row->nip;
                $latx=$row->lat_x;
                $laty=$row->lat_y;
                echo '{pos: ['.$latx.','.$laty.'], popup: "'.$namapeg.'"},';
                  }
				$jurusan=$this->db->query("SELECT nip,lat_x,lat_y FROM web_absen where status='7' AND nip='$kodeabsen' and tgl='$skrg' and lat_x <>''");
              foreach ($jurusan->result() as $row) {
                $kode=$row->nip;
                $latx=$row->lat_x;
                $laty=$row->lat_y;
                echo '{pos: ['.$latx.','.$laty.'], popup: "'.$namapeg.'"},';
                  }
              }
            }
          ?>

          ];
        markers.forEach(function (obj) {
            var m = L.marker(obj.pos).addTo(mymap),
                p = new L.Popup({ autoClose: false, closeOnClick: false })
                        .setContent(obj.popup)
                        .setLatLng(obj.pos);
            m.bindPopup(p).openPopup();
        });

        </script>

			</div>
		</div>

    </section><!-- /.content -->
