<?php
include "../../inc/config.php";

$token = get_token();
$url = $db->get_service_url('rest');


switch ($_GET["act"]) {
  case 'delete_all':
  if ($_POST['jurusan']!='all') {
       $id_sms = "p.id_sms='".$_POST['jurusan']."' and ";
  } else {
    $id_sms = "";
  }

   
  $filter_semester = "$id_sms p.id_smt='".$_POST['sem']."'";
  $all_kelas = $proxy->GetRecordset($token,'kelas_kuliah',$filter_semester,'','','');
  if ($all_kelas['result']) {
            foreach($all_kelas['result'] as $id) {
        $id_kls = $id['id_kls'];
        //hapus dosen ajar
  $filter_dosen = "p.id_kls='".$id_kls."'";
    $temp_dosen = $proxy->GetRecordset($token,'ajar_dosen',$filter_dosen,'','','');
    foreach ($temp_dosen['result'] as $reg) {
      $hapus_ajar[] = array(
      'id_ajar' => $reg['id_ajar'],
      );
       
     }

     $temp_res = $proxy->DeleteRecordset($token, 'ajar_dosen', json_encode($hapus_ajar));

     $hapus_ajar = array();

      }
  }


    break;
  case "delete":
  $id_mengajar = $_GET["id"];
                 $temp_del_dosen = [
                'act' => 'DeleteDosenPengajarKelasKuliah',
                  'token' => $token,
                  'key' => array('id_aktivitas_mengajar' => $id_mengajar)
              ];

                  $temp_del = json_decode($db->run($temp_del_dosen,$url));
                  dump($temp_del);
  break;

  case 'del_massal':
     $data_ids = $_REQUEST['data_ids'];
    $data_id_array = explode(",", $data_ids);
    if(!empty($data_id_array)) {

      foreach($data_id_array as $id_mengajar) {

                 $temp_del_dosen = [
                'act' => 'DeleteDosenPengajarKelasKuliah',
                  'token' => $token,
                  'key' => array('id_aktivitas_mengajar' => $id_mengajar)
              ];

                  $temp_del = json_decode($db->run($temp_del_dosen,$url));
                   dump($temp_del_dosen);
                  dump($temp_del);

      }

    }
    break;

}