<?php
$modelClass =& get_instance();
$modelClass->load->model('default/defaults');

function print_child($data,$parent_id,$title,$link,$userid){
	$modelClass =& get_instance();
	$menu_pesan = '';
	if($parent_id==262){
		$menu_pesan = ' id="menu_pesan" ';
	}
	if(count($data)>0){
		echo '<li class="has-sub">';
			echo '<a '.$menu_pesan.' href="'.$link.'">'.$title.'</a>';
			echo "<ul>";
			foreach ($data as $child) {
				$link = '';
				if($child['parent_id']==$parent_id){
					if(empty($child['link'])){
						$link = '#';
					}else{
						$link = base_url().$child['link'];
						if(!empty($child['params'])){
							$tmp = explode('=', $child['params']);
							if(count($tmp)>0){
								$link .= '/type/'.base64_encode($modelClass->encrypt->encode($tmp[1])).'/'.base64_encode($modelClass->encrypt->encode($child['params']));
							}
						}
					}
					print_child($data,$child['id'],$child['title'],$link,$userid);
				}
			}
			echo "</ul>";
		echo "</li>";
	}else{
		echo '<li>';
			echo '<a href="'.$link.'"><span>'.$title.'</span></a>';
		echo "</li>";
	}
}
$userid = '';
if($this->session->userdata('userid')){
	$userid = $this->session->userdata('userid');
}

if(!empty($userid)){
	$query = $this->nativesession->get('menus');
}else{
	$query ='';
}

if(empty($query)){
	$query = $modelClass->defaults->getParentMenu($userid);
	$this->nativesession->set('menus', $query->result_array());
	$query = $this->nativesession->get('menus');
}
if($query!=false){
	$about=$modelClass->defaults->getMenuAbout();
	echo '<div id="cssmenu">';
		echo "<ul class='nav navbar-nav'>";
	foreach ($query as $row) {
		
		$parent_id = $row['id'];
		if($row['parent_id']==''){
			if($row['link']==''){
				$link = '#';
			}else{
				$link = base_url().$row['link'];
				if(!empty($row['params'])){
					$tmp = explode('=', $row['params']);
					if(count($tmp)>0){
						$link .= '/type/'.base64_encode($modelClass->encrypt->encode($tmp[1]));
					}
				}
			}
			if($row['title']=='Delegasi'){
				print_child($query,$parent_id,"Delegasi<div class='notif_delegasi hidden'></div>",$link,$userid);	
			}else if($row['title']=='e-Court'){
				print_child($query,$parent_id,"e-Court<div class='notif_efiling hidden'></div>",$link,$userid);	
			}else{
				print_child($query,$parent_id,$row['title'],$link,$userid);	
			}
			
		}
	}
		echo "</ul>";
	echo '<div class="about">';
	echo '	<i class="fa fa-question-circle-o  animated infinite swing"> </i> Help';
	echo '		<div class="sub_about">';
				if($about!=false){
					echo "<ul>";
					foreach ($about->result() as $row) {
						echo '<li onclick="jalankan(\''.$row->link.'\')"><a>'.$row->title.'</a></li>';
					}
					echo "</ul>";
				}		
	echo '</div>';
	echo '</div>';
	echo '</div>';
}
?>
<script type="text/javascript">
$(function() {
	$('.sub_about').hide();
	$('.about').hover(	
       function () {
          $('.sub_about').show();
       }, 
		
       function () {
          $('.sub_about').hide();
       }
    );
});
	
 $('.sub_about').click(function(event) {
 	$('.sub_about').toggle();
 });
  function jalankan(link){
  	if (link=='tentang_sipp') {
  		popup_form('<?php echo base_url("help")."/";?>'+link,"_parent")
  	}else{
  		window.open('<?php echo base_url("help")."/";?>'+link,"_parent")
  	}
  	$('.sub_about').fadeOut();
  }

</script>

