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

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



switch ($_GET["act"]) {
  case "matkur":
  $id_matkur = explode('_',$_POST["id"]);
    $temp_del_dosen = [
      'act' => 'DeleteMatkulKurikulum',
        'token' => $token,
        'key' => array('id_kurikulum' => $id_matkur[1],'id_matkul' => $id_matkur[0])
    ];

    $temp_del = json_decode($db->run($temp_del_dosen,$url));
    if ($temp_del->error_desc!="") {
       dump($temp_del);
    } else {
      echo "good";
    }
  break;
  case "pembelajaran":
  $id_rencana_ajar = $_POST["id"];
    $temp_del_dosen = [
      'act' => 'DeleteRencanaPembelajaran',
        'token' => $token,
        'key' => array('id_rencana_ajar' => $id_rencana_ajar)
    ];

    $temp_del = json_decode($db->run($temp_del_dosen,$url));
    if ($temp_del->error_desc!="") {
       dump($temp_del);
    } else {
      echo "good";
    }
  break;
  case "evaluasi":
  $id_rencana_evaluasi = $_POST["id"];
    $temp_del_dosen = [
      'act' => 'DeleteRencanaEvaluasi',
        'token' => $token,
        'key' => array('id_rencana_evaluasi' => $id_rencana_evaluasi)
    ];

    $temp_del = json_decode($db->run($temp_del_dosen,$url));
    if ($temp_del->error_desc!="") {
       dump($temp_del);
    } else {
      echo "good";
    }
   

  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_kls) {
 //hapus dosen ajar
              $temp_data_kelas = [
                'act' => 'GetDosenPengajarKelasKuliah',
                  'token' => $token,
                  'filter' => "id_kelas_kuliah='$id_kls'",
                  'order' => '',
                  'limit' => '',
                  'offset' => ''
              ];

        $temp_rec = json_decode($db->run($temp_data_kelas,$url));
        if ($temp_rec->data) {
          foreach ($temp_rec->data as $key) {
                $temp_del_dosen = [
                'act' => 'DeleteDosenPengajarKelasKuliah',
                  'token' => $token,
                  'key' => array('id_aktivitas_mengajar' => $key->id_aktivitas_mengajar)
              ];

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

  //hapus GetKRSMahasiswa
              $temp_data_kelas = [
                'act' => 'GetKRSMahasiswa',
                  'token' => $token,
                  'filter' => "id_kelas='$id_kls'",
                  'order' => '',
                  'limit' => '',
                  'offset' => ''
              ];

        $temp_rec = json_decode($db->run($temp_data_kelas,$url));
        if ($temp_rec->data) {
          foreach ($temp_rec->data as $key) {
                $temp_del_dosen = [
                'act' => 'DeletePesertaKelasKuliah',
                  'token' => $token,
                  'key' => array(
                    'id_kelas_kuliah' => $key->id_kelas,
                    'id_registrasi_mahasiswa' => $key->id_registrasi_mahasiswa)
              ];

                  $temp_del = json_decode($db->run($temp_del_dosen,$url));
                  dump($temp_del);
          }
        }
  //hapus kelas 
    $temp_data_kelas = [
      'act' => 'DeleteKelasKuliah',
        'token' => $token,
        'key' => array('id_kelas_kuliah' => $id_kls)
    ];

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

    }
    break;

}