<?php
/**
 * SiaSetting
 * SiaSetting class
 * 
 * @package sia_setting 
 * @author Maya Alipin 
 * @copyright Copyright (c) 2006 GamaTechno
 * @version 1.0 
 * @date 2006-02-27
 * @revision 
 *
 */

class SiaSetting extends DatabaseConnected {

   var $mDataProceed;
   var $mUserId;
   var $mUserRole;
   var $mUserProdiId;
   var $mSemesterProdiId;
   var $mSemesterId;
   
   var $mIsError;
   var $mErrorMessage;
   
   /**
    * SiaSetting::SiaSetting
    * constructor for SiaSetting class
    * 
    * @param configObject object configuration
    * @param dataProceed array data needed for procees (sent by client)
    */
   function SiaSetting(&$configObject, $dataProceed) {
      DatabaseConnected::DatabaseConnected($configObject,"module/sia_setting/business/sia_setting.sql.php");
      $this->mDataProceed = $dataProceed;
      if ($this->Connect()) {
         $this->mIsError = false;
      }else{
         $this->SetError('');
      }
   }
   
   /**
    * SiaSetting::GetSiaSetting
    * get data sia setting (information about semester aktif form database)
    * use : set mDataProceed[0] = UserRole 
    *       set mDataProceed[1] = UserProdiId
    *
    * @param
    * @return array data semester 
    */
   function GetSiaSetting() {
      $sempId = $this->GetSemesterProdiIdAktif();
      if ($sempId === false){
         $this->mIsError = true;
         $this->mErrorMessage= "GetSiaSetting gagal karena ".$this->GetProperty("DbErrorMessage");
         return false;
      }else{
         $this->mDataProceed = array($sempId);
         $dataInfo = $this->GetSemesterInformation();
         if ($dataInfo === false){
            $this->SetError('GetSiaSetting gagal karena ');
            return false;
         }else{
            return $dataInfo;
         }
      }
      
   }
   
   /**
    * SiaSetting::GetSemesterProdiIdAktif
    * get active semester prodi id 
    * use : set mDataProceed[0] = UserRole 
    *       set mDataProceed[1] = UserProdiId
    *
    * @param
    * @return array data semester 
    */
   function GetSemesterProdiIdAktif() {
      $this->mUserRole = $this->mDataProceed[0];
      $this->mUserProdiId = $this->mDataProceed[1];
      
      $param = array();
      $sqlQuery ="get_semester_aktif_dosen";
      $param = array($this->mUserProdiId);
      if ($this->mUserRole == 1)  {
         $sqlQuery ="get_semester_aktif_mahasiswa";
         $param = array($this->mUserProdiId);
      }
      $dataInfo = $this->GetDataAsOne($this->mSqlQueries[$sqlQuery], $param);
      if (false === $dataInfo){
         $this->SetError("GetSemesterProdiIdAktif gagal karena ");
         return false;
      }else{
         return $dataInfo;
      }
   }
   
   /**
    * SiaSetting::GetSemesterInformation
    * get semester information from database
    * use : set mDataProceed[0] = SemesterProdiId 
    *
    * @param
    * @return array semester information
    */
   function GetSemesterInformation() {
      $this->mSemesterProdiId = $this->mDataProceed[0];
      
      $param = array($this->mSemesterProdiId);
      $dataInfo = $this->GetAllDataAsArray($this->mSqlQueries['get_semester_information'], $param);
      if (false === $dataInfo){
         $this->SetError("GetSemesterInformation gagal karena ");
         return false;
      }else{
         return $dataInfo;
      }
   }
   
   /**
    * SiaSetting::GetTranslatedSemesterProdiIdIntoSemesterId
    * translate semester prodi id into semester id
    * use : set mDataProceed[0] = SemesterProdiId 
    *           mDataProceed[1] = UserProdiId 
    *
    * @param
    * @return integer semester id
    */
   function GetTranslatedSemesterProdiIdIntoSemesterId() {
      $this->mSemesterProdiId = $this->mDataProceed[0];
      $this->mUserProdiId = $this->mDataProceed[1];
      
      $param = array($this->mSemesterProdiId, $this->mUserProdiId);
      $dataInfo = $this->GetDataAsOne($this->mSqlQueries['get_translated_semester_prodi_id_into_semester_id'], $param);
      if (false === $dataInfo){
         $this->SetError("GetTranslatedSemesterProdiIdIntoSemesterId gagal karena ");
         return false;
      }else{
         return $dataInfo;
      }
   }
   
   /**
    * SiaSetting::GetAllPassedSemesterMahasiswa
    * get all semester passed by mahasiswa
    * use : set mDataProceed[0] = UserId 
    *
    * @param
    * @return array data semester 
    */
   function GetAllPassedSemesterMahasiswa() {
      $this->mUserId = $this->mDataProceed[0];
      
      $param = array($this->mUserId);
      if ($this->ExecuteSetParameterQuery($this->mSqlQueries['set_niu_and_prodi_by_niu'],$param)) {
         $dataInfo = $this->GetAllDataAsArray($this->mSqlQueries['get_all_passed_semester_mahasiswa'], $param);
         $this->ExecuteSetParameterQuery($this->mSqlQueries['set_niu_and_prodi_by_niu'],array(NULL));
         if (false === $dataInfo){
            $this->SetError("GetAllPassedSemesterMahasiswa gagal karena ");
            return false;
         }else{
            return $dataInfo;
         }
      } else {
         
         return false;
      }
      
   }
   
   /**
     * SiaSetting::GetBobotKeteranganNilai
     * Get Bobot Keterangan Nilai
     * 
     * @param
     * @return array data keterangan nilai
     */
   function GetBobotKeteranganNilai() {
      $ketNilai = $this->GetAllDataAsArray($this->mSqlQueries['get_all_keterangan_nilai_for_transkrip_nilai'], array($this->mDataProceed[0]));
      if (false === $ketNilai){
         $this->SetError("GetBobotKeteranganNilai gagal karena ");
         return false;
      }else{
         return $ketNilai;
      }
   }
   
   /**
     * SiaSetting::DoCekIsMahasiswaHasRegistrationForSemester
     * Cek Is Mahasiswa Has Registration For Semester
     *
     * @param
     * @return integer registrasi mahasiswa
     *
     */
   function DoCekIsMahasiswaHasRegistrationForSemester()
   {
      $this->mUserId = $this->mDataProceed[0];
      $this->mSemesterId = $this->mDataProceed[1];
      
      $param = array($this->mUserId, $this->mSemesterId);
      $cekRegistrasi = $this->GetDataAsOne($this->mSqlQueries['get_status_registrasi'], $param);
      if (false === $cekRegistrasi) {
         $this->SetError("DoCekIsMahasiswaHasRegistrationForSemester gagal karena ");
         return false;
      }
      else {
         return $cekRegistrasi;
      }
   }
   
   function SetError($strErrorMsg) {
      echo $this->GetProperty("DbErrorMessage");
      $this->mIsError = true;
      if ($this->mErrorMessage == "") {
         $this->mErrorMessage = $strErrorMsg . $this->GetProperty("DbErrorMessage");
      } else {
         $this->mErrorMessage = $this->GetProperty("ErrorMessage") . " \n".$strErrorMsg . $this->GetProperty("DbErrorMessage");
      }
   }
   
   /**
    * SiaSetting::GetAllSupportedSemesterDosen
    * get all semester supported by mahasiswa
    * use : set mDataProceed[0] = UserId 
    *
    * @param
    * @return array data semester 
    */
   function GetAllSupportedSemesterDosen() {
      $this->mUserId = $this->mDataProceed[0];
      
      $param = array($this->mUserId);
      $dataSemester = $this->GetAllDataAsArray($this->mSqlQueries['get_all_supported_semester_dosen'], $param);
      if (false === $dataSemester){
         $this->SetError("GetAllSupportedSemesterDosen gagal karena ");
         return false;
      }else{
         return $dataSemester;
      }
   }
   
   /**
    * SiaSetting::GetAllPilihanNilai
    * get all pilihan nilai
    * use : set mDataProceed[0] = 0|1 integer with empty value
    * @param
    * @return array data nilai
    */
   function GetAllPilihanNilai () {
      $withEmptyValue = $this->mDataProceed[0];
      $kodeProdi = $this->mDataProceed[1];      
      
      $dataPilihanNilai = $this->GetAllDataAsArray($this->mSqlQueries['get_all_pilihan_nilai'], array($kodeProdi));      
      
      if (false === $dataPilihanNilai){
         $thisSetError("GetAllPilihanNilai gagal karena ");
         return false;
      }else{
         if ($withEmptyValue  == 1){
            $dataPilihanNilai[sizeof($dataPilihanNilai)] = array("nilai"=>NULL, "kodekelompoknilai"=>NULL, "bobot"=>NULL, "bobotmin"=>NULL, 
                                                                                 "bobotmax"=>NULL, "bobotkelompok"=>NULL, "bobotkelompokmin"=>NULL,
                                                                                 "bobotkelompokmax"=>NULL, "labelindonesia"=>NULL, "labelasing"=>NULL, );
         }
         return $dataPilihanNilai;
      }
   }
   
   /**
    * SiaSetting::GetNamaSemesterForSemesterId
    * get all pilihan nilai
    * use set mDataProceed[0] = integer semester id
    * 
    * @param
    * @return array data nilai
    */
   function GetNamaSemesterForSemesterId() {
      $this->mSemesterId = $this->mDataProceed[0];
      $this->mUserProdiId = $this->mDataProceed[1];
      
      $param = array($this->mSemesterId);
      $dataSemester = $this->GetAllDataAsArray($this->mSqlQueries['get_nama_semester_for_semester_id'], $param);
      if (false === $dataSemester){
         $this->SetError("GetNamaSemesterForSemesterId gagal karena ");
         return false;
      }else{
         return $dataSemester;
      }
   }
   
    /**
    * SiaSetting::GetNamaSemesterForSemesterProdiId
    * get all pilihan nilai
    * use set mDataProceed[0] = integer semester prodi id
    *             mDataProceed[1] = integer user prodi id
    * 
    * @param
    * @return array data nilai
    */
   function GetNamaSemesterForSemesterProdiId() {
      $this->mDebugMode = true;
      $semesterId = $this->GetTranslatedSemesterProdiIdIntoSemesterId();
      $param = array($semesterId);
      $dataSemester = $this->GetAllDataAsArray($this->mSqlQueries['get_nama_semester_for_semester_id'], $param);
      if (false === $dataSemester){
         $this->SetError("GetNamaSemesterForSemesterProdiId gagal karena ");
         return false;
      }else{
         return $dataSemester;
      }
   }
   
   function GetSemesterProdiIdForSemesterId() {
      $this->mSemesterId = $this->mDataProceed[0];
      $this->mUserProdiId = $this->mDataProceed[1];
      
      $param = array($this->mSemesterId,$this->mUserProdiId);
      $dataSemester = $this->GetDataAsOne($this->mSqlQueries['get_semester_prodi_id_for_semester_id'], $param);
      if (false === $dataSemester){
         $this->SetError("GetSemesterProdiIdForSemesterId gagal karena ");
         return false;
      }else{
         return $dataSemester;
      }
   }

   function getDataMhs(){
      $dataProceed = $this->GetProperty("DataProceed");
      $mhsNiu = $dataProceed[0];

      $result = $this->GetAllDataAsArray($this->mSqlQueries['getDataMhs'],array($mhsNiu));
      return $result[0];
   }

   function getDataPejabatTtd(){
      $dataProceed = $this->GetProperty("DataProceed");
      $namaDokumen = $dataProceed[0];
      $tipeSah = $dataProceed[1];

      return $this->GetAllDataAsArray($this->mSqlQueries['getDataPejabatTtd'],array($namaDokumen,$tipeSah));
   }

   function getDataPejabatTtdWithProdi(){
      $dataProceed = $this->GetProperty("DataProceed");
      $namaDokumen = $dataProceed[0];
      $tipeSah = $dataProceed[1];
      $prodiKode = $dataProceed[2];

      return $this->GetAllDataAsArray($this->mSqlQueries['getDataPejabatTtdWithProdi'],array($namaDokumen,$tipeSah,$prodiKode));
   }

   /**
    * SiaSetting::DestroyObject
    * deconstructor for SiaSetting class
    * 
    */
   function DestroyObject() {
      $this->Disconnect();
   }
}
?>
