<?php
session_start();
include "../../inc/config.php";
$token = get_token();
$url = $db->get_service_url('rest');
session_check();
switch ($_GET["act"]) {
  case "input_to_kurikulum":
      $data_req_akt = [
        'act' => 'GetDetailMataKuliah',
          'token' => $token,
          'filter' => "id_matkul='".$_POST['id_matkul']."'",
          'order' => "",
          'limit' => "",
          'offset' => ""

      ];
      $check_akt_exist_json = json_decode($db->run($data_req_akt,$url));
      $matkul = $check_akt_exist_json->data[0];
    $data = array(
    "id_kurikulum" => $_POST['id_kurikulum'],
    "id_matkul" => $_POST['id_matkul'],
    "semester" => $_POST['semester'],
    'sks_mata_kuliah' => $matkul->sks_mata_kuliah,
    'sks_tatap_muka' => $matkul->sks_tatap_muka,
    'sks_praktek' => $matkul->sks_praktek,
    'sks_praktek_lapangan' => $matkul->sks_praktek_lapangan,
    'sks_simulasi' => $matkul->sks_simulasi,
  );
  
    if(isset($_POST["apakah_wajib"])=="on") {
      $data["apakah_wajib"] = '1';
    } else {
      $data["apakah_wajib"] = '0';
    }

     $temp_up_array = [
      'act' => 'InsertMatkulKurikulum',
        'token' => $token,
        'record' => $data
    ];

    $temp_up = json_decode($db->run($temp_up_array,$url));
    if ($temp_up->error_desc=="") {
      $array_reponse['status'] = 'good';
    } else {
      $array_reponse['status'] = 'band';
      $array_reponse['error_desc'] = $temp_up->error_desc;
    }
 echo json_encode($array_reponse);
  break;
  case "up_pembelajaran":
  
  
  $data = array(
    "id_matkul" => $_POST['id_matkul'],
    "pertemuan" => $_POST['pertemuan'],
    "materi_indonesia" => $_POST['materi_indonesia'],
    "materi_inggris" => $_POST['materi_inggris'],
  );
  
     $temp_up_array = [
      'act' => 'UpdateRencanaPembelajaran',
      'key' => array('id_rencana_ajar' => $_POST['id']),
        'token' => $token,
        'record' => $data
    ];

    $temp_up = json_decode($db->run($temp_up_array,$url));
    if ($temp_up->error_desc=="") {
      $array_reponse['status'] = 'good';
    } else {
      $array_reponse['status'] = 'band';
      $array_reponse['error_desc'] = $temp_up->error_desc;
    }
 echo json_encode($array_reponse);
    break;
  case "delete":
    
    
    
    $db->delete("mat_kurikulum","id",$_GET["id"]);
    break;
  case "up_matakuliah":
  $data = array(
        'id_matkul' => $_POST['id_matkul'],
        'kode_mata_kuliah' => $_POST['kode_mata_kuliah'],
        'nama_mata_kuliah' => $_POST['nama_mata_kuliah'],
        'id_prodi' => $_POST['id_prodi'],
        'id_jenis_mata_kuliah' => $_POST['id_jenis_mata_kuliah'],
        'id_kelompok_mata_kuliah' => $_POST['id_kelompok_mata_kuliah'],
        //'sks_mata_kuliah' => $_POST['sks_mata_kuliah'],
        'sks_tatap_muka' => $_POST['sks_tatap_muka'],
        'sks_praktek' => $_POST['sks_praktek'],
        'sks_praktek_lapangan' => $_POST['sks_praktek_lapangan'],
        'sks_simulasi' => $_POST['sks_simulasi'],
        'metode_kuliah' => $_POST['metode_kuliah'],
        'tanggal_mulai_efektif' => $_POST['tanggal_mulai_efektif'],
        'tanggal_akhir_efektif' => $_POST['tanggal_selesai_efektif']
    );



         $temp_up_array = [
      'act' => 'UpdateMataKuliah',
      'key' => array('id_matkul' => $_POST['id_matkul']),
        'token' => $token,
        'record' => $data
    ];

    $temp_up = json_decode($db->run($temp_up_array,$url));


    if ($temp_up->error_desc=="") {
      $array_reponse['status'] = 'good';
    } else {
      $array_reponse['status'] = 'band';
      $array_reponse['error_desc'] = $temp_up->error_desc;
    }
    echo json_encode($array_reponse);
    break;
  default:
    # code...
    break;
}

?>