<?php
/*
Author : Nikolius
Email : n1colius.lau@gmail.com
Date : 27-Jul-2015 03:47 PM
*/
require_once $cfg->mValue['docroot'] . "module/sia_setting/business/sia_setting.class.php";
class Apps_home extends SiaSetting {
   function Apps_home(&$configObject, $dataProceed) {
      SiaSetting::SiaSetting($configObject, $dataProceed);
      $this->AppendSqlQueries("module/apps_home/business/apps_home.sql.php");
   }

   function getStatusSinkronAwal(){
      $status = $this->GetAllDataAsArray($this->mSqlQueries['getStatusSinkronAwal'], array());
      return $status[0]['statusNya'];
   }

   function setStatusSyncAwalDone(){
      $prosesUpdate = $this->ExecuteUpdateQuery($this->mSqlQueries['setStatusSyncAwalDone'], array());
      return $prosesUpdate;
   }

   function getDataSettingSemester(){
      $data = $this->GetAllDataAsArray($this->mSqlQueries['getDataSettingSemester'], array());
      return $data[0];
   }
   
   function setSemPelaporan(){
      $dataParam = $this->GetProperty("DataProceed");
      $semid = $dataParam[0];
      $semidLabel = $dataParam[1];
      return $this->ExecuteUpdateQuery($this->mSqlQueries['setSemPelaporan'], array($semid,$semidLabel));
   }
   
   function getModulDikti(){
      $data = $this->GetAllDataAsArray($this->mSqlQueries['getModulDikti'], array());
      return $data;
   }

   function setModul(){
      $dataParam = $this->GetProperty("DataProceed");
	  $status = explode(",",$dataParam[0]);
	  $this->StartTransaction();
	  foreach($status as $key => $value)
	  {
		  $id=$key+1;
		  $data=$this->ExecuteUpdateQuery($this->mSqlQueries['setModul'], array($value,$id));
		  if($data==FALSE)
		  {
			  return FALSE;
		  }
	  }
	  $this->CompleteTransaction($data);
      return $data;
   }

   function getDataListPemetaanProdiTotalRow(){
      $result = $this->GetAllDataAsArray($this->mSqlQueries['getDataListPemetaanProdiTotalRow'], array());
      return $result[0]['BANYAK'];
   }

   function getDataListPemetaanProdi(){
      $dataParam = $this->GetProperty("DataProceed");
      $p = array(
         $dataParam['pagePosition'],
         $dataParam['limitPerPage']
      );
      return $this->GetAllDataAsArray($this->mSqlQueries['getDataListPemetaanProdi'], $p);
   }

   function getIdSP(){
      $_data = $this->GetAllDataAsArray($this->mSqlQueries['getIdSP'], array());
      $data = empty($_data) ? 0 : $_data[0]['id_sp'];
      return $data;
   }

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

   function savePemetaanProdiDiktiKode(){
      $dataParam = $this->GetProperty("DataProceed");

      //cek dl apakah sudah dipakai id yg dipilih ini
      $p = array(
         $dataParam['prodiKode'],
         $dataParam['id_baru']
      );
      $dataCek = $this->GetAllDataAsArray($this->mSqlQueries['cekUpdatePemetaanProdi'], $p);
      if($dataCek[0]['BANYAK'] != '0'){
         return 'updateErr';
      }

      $id_sp = $this->getIdSP();
      $is_exist = $this->GetAllDataAsArray($this->mSqlQueries['cekPemetaanProdi'], array($dataParam['id_baru'], $id_sp));
      $addProdiIsNotExist = true;
      if ($is_exist[0]['BANYAK'] == 0 && !empty($dataParam['prodiData'])){
         $addProdiIsNotExist = $this->ExecuteUpdateQuery($this->mSqlQueries['addFeederDataSMS'], array_values($dataParam['prodiData']));
      }
      // jika prodi gagal ditambahkan ke fata feeder
      if ($addProdiIsNotExist == false){
         return 'updateErr';
      }

      $p = array(
         $dataParam['id_baru'],
         $dataParam['prodiKode']
      );
      $result = $this->ExecuteUpdateQuery($this->mSqlQueries['savePemetaanProdiDiktiKode'], $p);
      if($result == true){
         return 'updateOke';
      }else{
         return 'updateErr';
      }
   }

   function resetPemetaanProdi(){
      $dataParam = $this->GetProperty("DataProceed");

      $p = array(
         $dataParam['prodiKode']
      );
      $result = $this->ExecuteUpdateQuery($this->mSqlQueries['resetPemetaanProdi'], $p);
      if($result == true){
         return 'resetOke';
      }else{
         return 'resetErr';
      }
   }

   function getDataListKodePTTotalRow(){
      $result = $this->GetAllDataAsArray($this->mSqlQueries['getDataListKodePTTotalRow'], array());
      return $result[0]['BANYAK'];
   }

   function getDataListKodePT(){
      $dataParam = $this->GetProperty("DataProceed");
      $p = array(
         $dataParam['pagePosition'],
         $dataParam['limitPerPage']
      );
      return $this->GetAllDataAsArray($this->mSqlQueries['getDataListKodePT'], $p);
   }

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

   function saveKodePT(){
      $dataParam = $this->GetProperty("DataProceed");
      $p = array(
         $dataParam['ptDiktiKodeNew'],
         $dataParam['ptDiktiKodeOld']
      );

      $qcek = $this->GetAllDataAsArray($this->mSqlQueries['getKodePT'], array($dataParam['ptDiktiKodeNew']));
      $cek = $qcek;
      if (empty($cek)){
         $addPT = $this->ExecuteInsertQuery($this->mSqlQueries['addKodePT'], array($dataParam['ptDiktiKodeNew']));
         if (!$addPT){
            return false;
         }
      }
      $result = $this->ExecuteUpdateQuery($this->mSqlQueries['updateKodePT'], $p);
      if($result == true){
         return true;
      }else{
         return false;
      }
   }

   function resetKodePT(){
      $dataParam = $this->GetProperty("DataProceed");
      $p = array(
         $dataParam[0]
      );
      $result = $this->ExecuteUpdateQuery($this->mSqlQueries['resetKodePT'], $p);
      if($result == true){
         return true;
      }else{
         return false;
      }
   }

}
?>