<script>
  function del(iden,action){
    var dataString = "id="+iden+"&action="+action;
    var status = $("#status").val();
    var identity = $('#loading')+iden;
    var confirms = confirm("Clicking this will delete this department to totally, are you sure you want to continue?");
    if (confirms == true) {
    $.ajax({
        type: "POST",
        url: "control.php",
        cache : false,
        data : dataString,
        beforeSend : function(){
            $('#del'+iden).hide();
            $('#loading'+iden).show();
        },
        success : function(response){
            $('#loading'+iden).hide();
            document.getElementById('inputHere').innerHTML = response;
            $('#myModal').modal('show');
            window.location.reload(1);
        }
    });
}
}

 function add(iden,action){
    var dataString = "id="+iden+"&action="+action;
    var status = $("#status").val();
    var identity = $('#addloading')+iden;
    var confirms = confirm("Clicking this will add this department back, are you sure you want to continue?");
    if (confirms == true) {
    $.ajax({
        type: "POST",
        url: "control.php",
        cache : false,
        data : dataString,
        beforeSend : function(){
            $('#add'+iden).hide();
            $('#addloading'+iden).show();
        },
        success : function(response){
            $('#addloading'+iden).hide();
            document.getElementById('inputHere').innerHTML = response;
            $('#myModal').modal('show');
            window.location.reload(1);
        }
    });
}
}
</script>

                  <div class="x_content">
                      <table id="datatable-responsive" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
                            <thead>
                             <tr>
                                <th>S/N</th>
                                <th>Name</th>
                                <th>Faculty</th>
                                <th>Action</th>
                              </tr>
                            </thead>
                            <tbody>
                        <?php
                         $select = $conn->query("SELECT * FROM darchive ORDER BY name ASC");
                            $fetch = $select->fetchAll(PDO::FETCH_OBJ);
                            $count = $select->rowCount();
                            $serial = 1;
                            if ($count > 0) {
                              foreach ($fetch as $value) {
                                $iden = $value->id;
                                $name = $value->name;
                                $under = $value->under;
                            ?>
                              <tr>
                                <td><?php echo $serial; ?></td>
                                <td><?php echo $name; ?></td>
                                <td>
                                  <?php
                                  $select2 = $conn->query("SELECT * FROM faculty WHERE id = $under ORDER BY name ASC");
                                  $fetch2 = $select2->fetchAll(PDO::FETCH_OBJ);
                                  $count2 = $select2->rowCount();
                                   $select3 = $conn->query("SELECT * FROM farchive WHERE id = $under ORDER BY name ASC");
                                  $fetch3 = $select3->fetchAll(PDO::FETCH_OBJ);
                                  $count3 = $select3->rowCount();
                                  if ($count2 > 0) {
                                    foreach ($fetch2 as $value2) {
                                      $name2 = $value2->name;
                                      echo "$name2";
                                       }
                                  }elseif ($count3 > 0) {
                                    
                                    echo "Archived";
                                  }else{
                                    echo "Deleted";
                                  }
                                  ?>
                                </td>
                                <td>
                                  <button class="btn btn-default btn-xs" title="Add Back" id="add<?php echo $iden?>" onclick= "add('<?php echo $iden ?>', 'addadepartment')"><i class="fa fa-plus"></i></button><span id="addloading<?php echo $iden ?>" style="display:none"><img src="../img/loading.gif"></span>

                                <button class="btn btn-default btn-xs" title="Archive" id="del<?php echo $iden?>" onclick= "del('<?php echo $iden ?>', 'deladepartment')"><i class="fa fa-trash"></i></button><span id="loading<?php echo $iden ?>" style="display:none"><img src="../img/loading.gif"></span>
                                </td>
                               </tr>
                              
                            <?php
                            $serial++;
                              }
                            }
                        ?>
                            </tbody>
                          </table>
                            </div>


<div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog modal-sm">
      <div class="modal-content">
        <div class="modal-body text-center">
        <div id="inputHere">

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