<?php
   require_once $cfg->mValue['docroot'] . "module/sia_setting/business/sia_setting.class.php";
   class Kurikulum extends SiaSetting {

      function Kurikulum(&$configObject, $dataProceed) {
         SiaSetting::SiaSetting($configObject, $dataProceed);
         $this->AppendSqlQueries("module/kurikulum/business/kurikulum.sql.php");
      }
/*
      function GetDataKurikulumAdd(){
		   $data = $this->GetAllDataAsArray($this->mSqlQueries['get_kurikulum_add'], array());
         return $data;
      }

      function GetDataKurikulumUpdate(){
		   return $this->GetAllDataAsArray($this->mSqlQueries['get_kurikulum_update'], array());
      }

      function GetDataKurikulumDelete(){

      }

      function UpdateStatSyncKurikulum(){
         $dataProceed = $this->GetProperty("DataProceed");
         $id = $dataProceed[0];
         $kurNama = $dataProceed[1];
//return $dataProceed;
         $update = $this->ExecuteUpdateQuery($this->mSqlQueries['do_update_stat_sync_kur'], array($id,$kurNama));
         if (false === $update) {
            $this->SetError("UpdateStatSyncKurikulum gagal");
            return false;
         }
         else {
            return true;
         }
      }


      function IsMahasiswaRegistered(){
         $dataProceed = $this->GetProperty("DataProceed");
         $this->SetProperty("UserId", $dataProceed[0]);
         $param = array($this->GetProperty("UserId"));
         $isMhsRegistered = $this->GetAllDataAsArray($this->mSqlQueries['is_mahasiswa_registered'], $param);
         if (!empty($isMhsRegistered)) {
            return true;
         }
         else {
            return false;
         }
      }

      function GetYudiciumRequisite(){
	     $dataProceed = $this->GetProperty("DataProceed");
         $this->SetProperty("UserId", $dataProceed[0]);
		 $param = array($this->GetProperty("UserId"));
		 $arrKurId = $this->GetAllDataAsArray($this->mSqlQueries['get_mhs_kurikulum_id'], $param);
		 $arrSyarat = $this->GetAllDataAsArray($this->mSqlQueries['get_yudicium_requisite'], array($arrKurId[0][kur_id]));
         if (false === $arrSyarat) {
            $this->SetError("GetYudiciumRequisite gagal karena ");
            return false;
         }
         else {
            return $arrSyarat;
         }
      }

      function DoYudiciumRegistration(){
         $dataProceed = $this->GetProperty("DataProceed");
         $this->SetProperty("UserId", $dataProceed[0]);
         $this->SetProperty("SemesterId", $dataProceed[1]);
         $param = array($this->GetProperty("UserId"),$this->GetProperty("SemesterId"));
         //$this->mDbConnection->debug = true;
         //echo $this->GetDataAsOne($this->mSqlQueries['get_new_yudicium_id'], array());
         $this->StartTransaction();
         //$yudiciumId = $this->GetDataAsOne($this->mSqlQueries['get_new_yudicium_id'], array());
         $addYudiciumRegistration = $this->ExecuteInsertQuery($this->mSqlQueries['do_insert_yudicium'], $param);
         //$param1 = array($yudiciumId);
         $addYudiciumRegistrationDetail = $this->ExecuteInsertQuery($this->mSqlQueries['do_insert_yudicium_detail'], array());
         $this->CompleteTransaction($addYudiciumRegistration && $addYudiciumRegistrationDetail);
         if (false === $addYudiciumRegistrationDetail) {
            $this->SetError("AddYudiciumRegistration gagal karena ");
            return false;
         }
         else {
            return true;
         }
      }
*/
      function GetDataKurikulumForAdd(){
         $data = $this->GetAllDataAsArray($this->mSqlQueries['GetDataKurikulumForAdd'], array());
         return $data;
      }

      function updateKurikulumIdRecFeeder(){
         $dataList = $this->GetProperty("DataProceed");
         //echo '<pre>'; print_r($dataList); exit;
         $this->StartTransaction();
         $prosesUpdate = TRUE;

         for ($i=0; $i < count($dataList); $i++) {
            //prep data kurTahun
            $kurTahun = substr($dataList[$i]['id_smt_berlaku'], 0, -1);

            $p = array(
               $dataList[$i]['id_kurikulum_sp'],
               $dataList[$i]['nm_kurikulum_sp'],
               $kurTahun,
               $dataList[$i]['id_sms']
            );
            $proses = $this->ExecuteUpdateQuery($this->mSqlQueries['updateKurikulumIdRecFeeder'], $p);
            if($proses == FALSE) $prosesUpdate = FALSE;
         }

         $prosesUpdate = TRUE;
         $this->CompleteTransaction($prosesUpdate);

         return $prosesUpdate;
      }

      function insertFeederKurikulum(){
         $dataList = $this->GetProperty("DataProceed");
         $this->StartTransaction();
         $prosesInsert = TRUE;

         for ($i=0; $i < count($dataList); $i++) {
            //get gt_id kurikulum yaitu di tabel s_kurikulum (kurId)
            $kurTahun = substr($dataList[$i]['id_smt_berlaku'], 0, -1);
            $p = array(
               $dataList[$i]['nm_kurikulum_sp'],
               $kurTahun,
               $dataList[$i]['id_sms']
            );
            $dataKurId = $this->GetAllDataAsArray($this->mSqlQueries['getKurIdValue'], $p);
            $dataList[$i]['gt_id'] = $dataKurId[0]['kurId'];

            $p = array(
               $dataList[$i]['id_kurikulum_sp'],
               $dataList[$i]['nm_kurikulum_sp'],
               $dataList[$i]['jml_sem_normal'],
               $dataList[$i]['jml_sks_lulus'],
               $dataList[$i]['jml_sks_wajib'],
               $dataList[$i]['jml_sks_pilihan'],
               $dataList[$i]['id_sms'],
               $dataList[$i]['id_jenj_didik'],
               $dataList[$i]['id_smt_berlaku'],
               $dataList[$i]['gt_id'],
               $dataList[$i]['nm_kurikulum_sp'], //update
               $dataList[$i]['jml_sem_normal'],
               $dataList[$i]['jml_sks_lulus'],
               $dataList[$i]['jml_sks_wajib'],
               $dataList[$i]['jml_sks_pilihan'],
               $dataList[$i]['id_sms'],
               $dataList[$i]['id_jenj_didik'],
               $dataList[$i]['id_smt_berlaku'],
               $dataList[$i]['gt_id']
            );
            $proses = $this->ExecuteInsertQuery($this->mSqlQueries['insertFeederKurikulum'], $p);
            if($proses == FALSE) $prosesInsert = FALSE;
         }

         $this->CompleteTransaction($prosesInsert);
         return $prosesInsert;
      }

   }
?>