<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/user/business/AppUser.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/user/business/AppGroup.class.php';

//set Label for module
require_once GTFWConfiguration::GetValue( 'application', 'docroot') .
'module/label/response/Label.proc.class.php';

class ViewProfile extends HtmlResponse {

   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').
         'module/user/template');
      $this->SetTemplateFile('view_profile.html');
   }
   
   function ProcessRequest() {
      $userObj = new AppUser();
      $groupObj = new AppGroup();
      
      $result = $userObj->GetDataUserByUsername($_SESSION['username']);
      $idDec = $result['user_id'];
      $dataUser = $userObj->GetDataUserById($idDec);

      $dataGroup = $groupObj->GetDataGroupById($dataUser[0]['group_id']);
      $return['dataUser'] = $dataUser;
      $return['dataGroup'] = $dataGroup;

      return $return;
   }

   function TemplateLabeling(){
      $ObjLabel = new GetModuleLabel();
      $arrLabel = $ObjLabel->GetLabel();
      
      //patTemplate name yang memiliki label2 dinamic
      $arrContent=array("content");
      
      for($i=0;$i<count($arrContent);$i++){
         for($j=0;$j<count($arrLabel);$j++){
            $this->mrTemplate->AddVar($arrContent[$i],$arrLabel[$j]['labelCode'],$arrLabel[$j]['labelName']);
         }
      }
   }
   
	function ParseTemplate($data = NULL)
   {
      //set Label
      $this->TemplateLabeling();
      
      $dataUser = $data['dataUser'];
      $dataGroup = $data['dataGroup'];
      $instUser = $data['instUser'];
      $this->mrTemplate->AddVar('content', 'PENGGUNA', $dataUser[0]['real_name']);
      $this->mrTemplate->AddVar('content', 'NO_PEGAWAI', $dataUser[0]['no_pegawai']);
      $this->mrTemplate->AddVar('content', 'URL_UPDATE_PASSWORD', Dispatcher::Instance()->GetUrl('user', 'updatePassword', 'view', 'html'));
      $this->mrTemplate->AddVar('content', 'PROFILE_URL_EDIT', Dispatcher::Instance()->GetUrl('user', 'inputProfile', 'view', 'html'));
      $this->mrTemplate->AddVar('content', 'USERNAME', $dataUser[0]['user_name']);
      $this->mrTemplate->AddVar('content', 'DESKRIPSI', $dataUser['0']['description']);
      
      if ($dataUser[0]['is_active'] == 'Yes') {
         $dataUser[0]['status'] = 'aktif';
      } else {
         $dataUser[0]['status'] = 'tidak aktif';
      }
      $this->mrTemplate->AddVar('content', 'STATUS', $dataUser[0]['status']);
      $this->mrTemplate->AddVar('content', 'NAMA_GROUP', $dataUser[0]['group_name']);
     
      $menuId = explode('|', $dataGroup[0]['menu_id']);                    
      $menuName = explode('|', $dataGroup[0]['menu_name']);
      $parentMenu = explode('|', $dataGroup[0]['parent_menu']);
      $mlen=sizeof($menuId);
      $s=0;
      for ($m=0;$m<$mlen;$m++) {    
         if ($parentMenu[$m]==0) {
         $menuBaru[$s]='<b>'.$menuName[$m].'</b><br>';
         for ($mm=0;$mm<$mlen;$mm++) {
           if ($menuId[$m]==$parentMenu[$mm]) $menuBaru[$s]=$menuBaru[$s].'&nbsp;&nbsp;'.$menuName[$mm].'<br>';
         }
         $s++;
         }
      }

      for ($k=0;$k<$s;$k++) {
         $this->mrTemplate->AddVar('list_hak_akses', 'HAK_AKSES', $menuBaru[$k]);
         $this->mrTemplate->parseTemplate('list_hak_akses', 'a');
      }      
            

      if (isset ($_REQUEST['err'])) {
         $error=Dispatcher::Instance()->Decrypt($_REQUEST['err']);
         $classWarning = "notebox-done";
         if ($error=='gagal') {
            $pesan='Penggantian password gagal';
            $classWarning = "notebox-warning";
         } else if ($error=='berhasil') {
           $pesan='Penggantian password berhasil';
         } else if ($error=='up_gagal') {
            $pesan='Ubah Profile gagal';
            $classWarning = "notebox-warning";
         } else if ($error=='up_berhasil') {
            $pesan='Ubah Profile berhasil';
         }
         $this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
         $this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $pesan);
         $this->mrTemplate->AddVar('warning_box', 'CLASS_PESAN', $classWarning);
      } 
   }
}
?>
