<?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'],
      );
      
     }

  //hapus krs
  $filter_nilai = "p.id_kls='".$id_kls."'";
    $temp_sms = $proxy->GetRecordset($token,'nilai',$filter_nilai,'','','');
    foreach ($temp_sms['result'] as $reg) {
      $hapus[] = array(
      'id_kls' => $reg['id_kls'],
      'id_reg_pd'=>$reg['id_reg_pd']
      );
    //print_r($hapus);
   
   // print_r($temp_result);
    
    }
  //hapus kelas 
   $hapus_kelas[] = array(
      'id_kls' => $id_kls,
      );
    //print_r($hapus);
  

      }
    $temp_res = $proxy->DeleteRecordset($token, 'ajar_dosen', json_encode($hapus_ajar));
    $temp_result = $proxy->DeleteRecordset($token, 'nilai', json_encode($hapus));
    $temp_result = $proxy->DeleteRecordset($token, 'kelas_kuliah', json_encode($hapus));

 }

    break;
  case "delete":
  $id_kls = $_GET["id"];
  $data_id_array = explode("$", $id_kls);
  $hapus = array(
  'id_kelas_kuliah' => $data_id_array[0],
  'id_registrasi_mahasiswa'=>$data_id_array[1],
  );

  $param = array(
    'act' => 'DeletePesertaKelasKuliah',
    'token' => get_token(),
    'key' => $hapus
  );

  $delete_peserta = service_request($param);
  dump($delete_peserta);

  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) {
    
      $ids = explode("$", $id_kls);
      
          $hapus = array(
          'id_kelas_kuliah' => $ids[0],
          'id_registrasi_mahasiswa'=>$ids[1],
          );

          $param = array(
            'act' => 'DeletePesertaKelasKuliah',
            'token' => get_token(),
            'key' => $hapus
          );
          dump($hapus);
            dump($param);


          $delete_peserta = service_request($param);
          dump($delete_peserta);
    }
  }
    break;

}