<?php

include '../../config/conn.php';
if ($_GET['aksi'] == '') {
?>

<!-- page content -->
<div class="col" role="main">
    <div class="">
        <div class="clearfix"></div>

        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                    <div class="x_title" style="text-transform: capitalize;">

                        <h2 style="color: crimson;">KONFIRMSI UBAH STATUS AKTIF SERENTAK <small></small></h2>

                        <div class="clearfix"></div>

                    </div>

                    <div class="x_content">
                        <form action="?module=confirm-data-ubah&aksi=ubah" method="POST">
                            <div class="col-md-3">

                            <label for="nama">Ubah Ke :</label>    
                            <input style=" color:black;" type="hidden" class="form-control" id="saldo" name="ubahdatastatus" value="<?php echo $_POST['ubahdatastatus']; ?>">
                                <select disabled id="heard" class="form-control" required name="">
                                    <?php
                                    $query2  = "SELECT * FROM status_aktif ORDER BY id";
                                    $tampil2 = mysqli_query($conn, $query2);
                                    while ($w = mysqli_fetch_array($tampil2)) {
                                      if ($_POST['ubahdatastatus'] == $w['id']) {
                                        echo "<option value=\"$w[id]\" selected>$w[nama]</option>";
                                      } else {
                                        echo "<option value=\"$w[id]\">$w[nama]</option>";
                                      }
                                    }
                                    
                                    ?>
                                  </select>
                                
                                <button onclick="submit()" class='open_modal btn  btn-danger btn-xl'>Konfirmasi</button>
                            </div>



                            <table id="" class="table table-bordered">


                                <thead>
                                    <tr style="color: black;">
                                        <!--<th>Tanggal</th>-->
                                        <!--<th>id transaksi</th> -->
                                        <th width="15px">NO.</th>
                                        <th>Id Santri</th>
                                        <th>Nama Santri</th>
                                        <th>jenkel</th>

                                        <th>Tanggal masuk</th>

                                    </tr>
                                </thead>


                                <tbody>
                                    <input type="hidden" name="selector[]" id="" value="<?php echo  $_POST['selector']; ?>">
                                    <?php
                                    $no = 0;
                                    $id = $_POST['selector'];
                                    $N = count($id);
                                    for ($i = 0; $i < $N; $i++) {

                                        // echo $idtran . "<br>";
                                        $idd = $id[$i];


                                        $query = mysqli_query($conn, "SELECT * FROM santri WHERE id_santri='$idd'");
                                        $row = mysqli_fetch_array($query);

                                        $no++;
                                    ?>



                                        <tr style="background: <?php if ($no % 2 == 1) { ?>
                          #ececec;
                          <?php } else { ?>
                            white;
                            <?php } ?>">

                                            <td style=" color:black"><?php echo $no; ?></td>

                                            <td style=" color:black">

                                                <?php echo $row['id_santri']; ?></td>
                                            <input type="hidden" name="selector[]" value="<?php echo  $row['id_santri']; ?>">
                                            <td style=" color:black"><?php echo $row['nama']; ?></td>
                                            <td style=" color:black"><?php if ($row['jenkel'] == 'l') {
                                                                            echo "Laki-laki";
                                                                        } else {
                                                                            echo "Perempuan";
                                                                        } ?></td>

                                            <td style=" color:black"><?php echo $row['tanggal_masuk'];  ?></td>

                                            <?php
                                            $count++

                                            ?>

                                        </tr>

                                    <?php
                                    } ?>





                                </tbody>
                        </form>
                        </table>
                    </div>

                </div>
            </div>

        </div>
    </div>
</div>

<?php
}elseif ($_GET['aksi'] == 'ubah') {

    $id = $_POST['selector'];
    $N = count($id);
    echo $N;
    for ($i = 0; $i < $N; $i++) {
        $idtran = id_transaksi() + $i;
        // echo $idtran . "<br>";
        $idd = $id[$i];
        echo $id[$i] . "<br>";
        $save = mysqli_query($conn, "UPDATE santri SET 
                                    status_aktif ='$_POST[ubahdatastatus]'
                                    WHERE id_santri = '$idd'");
                                    

    }

    if (!$save) {
        echo "gagal";
        echo "<script>nSimpan('?module=santri');</script>";
    } else {

        echo "<script>ySimpan('?module=santri');</script>";
        echo "sukses";
    }
}