<?php

require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/group/business/AppGroup.class.php';

class ViewTemplateAccess extends HtmlResponse {

   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/group/template');
      $this->SetTemplateFile('view_template_access.html');
   }
   
   function ProcessRequest() {
		@$msg = Messenger::Instance()->Receive(__FILE__);
		@$return['Pesan'] = $msg[0][1];
		@$return['Data'] = $msg[0][0];

		$idDec = Dispatcher::Instance()->Decrypt($_REQUEST['grp']);
		if ($idDec == '')
         $idDec = Dispatcher::Instance()->Decrypt($return['Data']['0']['grp']);
			
      	$groupObj = new AppGroup();
      	$menuGroup = $groupObj->GetAllPrivilege($idDec);      
      	$return['menuGroup'] = $menuGroup;

      	$dataGroup = $groupObj->GetDataGroupById($idDec);
      	$dataUnitKerja = $groupObj->GetComboUnitKerja();
		
		#action
      	$actionTemp = $groupObj->GetAllAksiByGroupId($idDec);
      	foreach($actionTemp as $values){
	      	$key = $values['MenuId'];
	      	$actionGroup[$key][] = $values;
	  	}

      	$return['actionGroup'] = $actionGroup;
		$return['decDataId'] = $idDec;
		$return['dataGroup'] = $dataGroup;
		return $return;
	}

   function ParseTemplate($data = NULL) {
	  
   	  $dataGroup = $data['dataGroup'];
      #print_r($data['dataGroup']);
      @$menu = explode('|',$dataGroup[0]['menu_name']);
      $menuGroup = $data['menuGroup'];

      $len = sizeOf($menuGroup);
      $mlen = sizeOf($menu);
      for ($i=0;$i<$len;$i++) {
         if ($menuGroup[$i]['menu_parent_id']==0) {
            $parent=$menuGroup[$i]['menu_name'];
            $this->mrTemplate->addVar('menu', 'MENU_PARENT', 'YES');
            $this->mrTemplate->addVar('menu', 'PARENT_MENU', $parent);
            $this->mrTemplate->parseTemplate('menu', 'a'); 
            for ($j=$i;$j<$len;$j++) { 
               if ($menuGroup[$j]['menu_parent_id']==$menuGroup[$i]['menu_id']) {
                  $idmenu=$menuGroup[$j]['menu_id'];
                  $menu_name=$menuGroup[$j]['menu_name'];
                  $htmlField = '';
                  if($data['actionGroup'][$idmenu]){
		               foreach($data['actionGroup'][$idmenu] as $val){
		               	if ($val['AksiLabel'] <> ''){
			               	$label='';
			               	if($val['LabelAksi'] <> '') $label = '('.ucwords(str_replace('_',' ',$val['LabelAksi'])).')';
			               	if ($val['Checked'] == 1)
			               		$htmlField .= '<li><input type="checkbox" class="checkact childCheckbox" name="aksi[]" value="'.$val['ModuleId'].'" checked>'.$val['AksiLabel'].' '.$label.'</li>';
			               	else
			               		$htmlField .= '<li><input type="checkbox" class="checkact childCheckbox" name="aksi[]" value="'.$val['ModuleId'].'" >'.$val['AksiLabel'].' '.$label.'</li>';
		               	}
		               }             
                  }
                  for ($k=0;$k<$mlen;$k++) { 
                     #if ($menuGroup[$j]['menu_name']==$menu[$k]) {
                     if (!empty($menuGroup[$j]['MenuName'])) {
                         $this->mrTemplate->addVar('menu', 'CHECK', 'checked'); 
                         break;
                     } else $this->mrTemplate->addVar('menu', 'CHECK', '');
                  } 
                  $this->mrTemplate->addVar('menu', 'MENU_PARENT', 'NO');
                  $this->mrTemplate->addVar('menu', 'ACTIONLIST',$htmlField);
                  $this->mrTemplate->addVar('menu', 'IDMENU', $idmenu);  
                  $this->mrTemplate->addVar('menu', 'MENU', $menu_name);       
                  $this->mrTemplate->parseTemplate('menu', 'a');
               } 
            } 
        }
     }
     
   }
}
?>
