<!DOCTYPE html>
<html lang="en">
<head>
	<?php $this->load->view("includes/header");?>
</head>

<body>
	<?php $this->load->view("includes/menu");?>
	
	<section class="content">
		<?php $this->load->view("includes/nav");?>
		
		<div class="wraper container-fluid xs_container-fluid">
<!--			<div class="page-title"> -->
<!--				<h3 class="title">Panels</h3> -->
<!--			</div>-->
			
			<div class="row">
				<div class="col-md-12">
					<?php $this->load->view("includes/success_msg");?>
					
					<div class="panel panel-default xs_panel" style="padding-left: 10px; padding-right: 10px;">
						<div class="panel-heading">
							<h3 class="panel-title">
								<i class="fa fa-key fa-fw"></i>
								Access
							</h3> 
						</div>
						<div class="panel-body">
							<div class="tabs-vertical-env">
								<?php $parent_id_array = array();?>
								<ul class="nav tabs-vertical" id="myTab">
	<!--								<li><a href="#tab_0" data-toggle="tab">Main</a></li>-->
									<?php foreach($menu as $m):?>
										<?php if ($m->PARENT_ID == 0 && $m->EVERYONE_ACCESS == 0):?>
											<li>
												<a href="<?php echo '#tab_'.$m->PKKEY ;?>" data-toggle="tab">
													<?php echo $m->NAME ;?>
												</a>
											</li>
											<?php array_push($parent_id_array,$m->PKKEY);?>
										<?php endif;?>
									<?php endforeach;?>
								</ul>
								
								<div class="tab-content" style="width: 100%; padding: 0 0 0 30px;">
									<!--<div class="tab-pane" id="tab_0">
										<table class="table table-hover">
											<thead>
												<tr>
													<th>Menu</th>
													<th style="width: 1%; text-align: center;">Action</th>
												</tr>
											</thead>
											<?php foreach($menu as $sm):?>
												<?php if($sm->PARENT_ID == 0):?>
													<tr>
														<td><b><?php echo $sm->NAME;?></b></td>
														<td style="white-space: nowrap;">
															<div class="btn-group">
																<a href="<?php echo base_url($this->router->fetch_class()."/toggle_up/".$sm->PKKEY);?>" class="btn btn-default" style="float: none; margin: -2px;" title="Move Up"><i class="menu-icon fa fa-arrow-up"></i></a>
																<a href="<?php echo base_url($this->router->fetch_class()."/toggle_down/".$sm->PKKEY);?>" class="btn btn-default" style="float: none; margin: -2px;" title="Move Down"><i class="menu-icon fa fa-arrow-down"></i></a>
															</div>
														</td>
													</tr>
												<?php endif;?>
											<?php endforeach;?>
										</table>
									</div>
									-->
									<?php for($x=0; $x<count($parent_id_array); $x++):?>
										<div class="tab-pane" id="tab_<?php echo $parent_id_array[$x];?>">
											<table class="table table-hover">
												<thead>
													<tr>
														<th>Menu</th>
														<th style="width: 1%; text-align: center;">Action</th>
													</tr>
												</thead>
												
												<!---->
												<?php foreach($menu as $pm):?>
													<?php if($pm->PKKEY == $parent_id_array[$x]):?>
													<?php if((($pm->URL != NULL && $pm->URL != "") || ($pm->EXE == "1")) && ! $pm->EVERYONE_ACCESS):?>
															<tr>
																<td><?php echo $pm->NAME;	//Child URL?></td>
																<td>
																	<div class="btn-group">
																		<a href="#edit_modal" data-toggle="modal" onClick="edit_load_data('<?php echo $pm->PKKEY;?>');" class="btn btn-default" title="Configuration"><i class="menu-icon fa fa-cog"></i></a>
																	</div>
																</td>
															</tr>
														<?php endif;?>
														
														<?php break;?>
														
													<?php endif;?>
												<?php endforeach;?>
												<!---->
												<?php foreach($menu as $sm):?>
													<?php if($sm->PARENT_ID == $parent_id_array[$x]):?>
														<tr>
															<td><?php echo $sm->NAME;	//Child URL?></td>
															<td style="white-space: nowrap;">
																<div class="btn-group">
																	<a href="#edit_modal" data-toggle="modal" onClick="edit_load_data('<?php echo $sm->PKKEY;?>');" class="btn btn-default" style="float: none; margin: -2px;" title="Configuration"><i class="menu-icon fa fa-cog"></i></a>
	<!--																<a href="<?php echo base_url($this->router->fetch_class()."/toggle_up/".$sm->PKKEY);?>" class="btn btn-default" style="float: none; margin: -2px;" title="Move Up"><i class="menu-icon fa fa-arrow-up"></i></a>-->
	<!--																<a href="<?php echo base_url($this->router->fetch_class()."/toggle_down/".$sm->PKKEY);?>" class="btn btn-default" style="float: none; margin: -2px;" title="Move Down"><i class="menu-icon fa fa-arrow-down"></i></a>-->
																</div>
															</td>
														</tr>
														
														<?php foreach($menu as $method)://Method URL?>
															<?php if($method->PARENT_ID == $sm->PKKEY):?>
																<tr>
																	<td><i class="menu-icon fa fa-arrow-right"></i> <?php echo $method->NAME;?></td>
																	<td>
																		<div class="btn-group">
																			<a href="#edit_modal" data-toggle="modal" onClick="edit_load_data('<?php echo $method->PKKEY;?>');" class="btn btn-default" style="float: none; margin: -2px;" title="Configuration"><i class="menu-icon fa fa-cog"></i></a>
	<!--																		<a href="<?php echo base_url($this->router->fetch_class()."/toggle_up/".$method->PKKEY);?>" class="btn btn-default" style="float: none; margin: -2px;" title="Move Up"><i class="menu-icon fa fa-arrow-up"></i></a>-->
	<!--																		<a href="<?php echo base_url($this->router->fetch_class()."/toggle_down/".$method->PKKEY);?>" class="btn btn-default" style="float: none; margin: -2px;" title="Move Down"><i class="menu-icon fa fa-arrow-down"></i></a>-->
																		</div>
																	</td>
																</tr>
															<?php endif;?>
														<?php endforeach;?>
														
													<?php endif;?>
												<?php endforeach;?>
											</table>
										</div>
									<?php endfor;?>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		
		<!-- edit_modal -->
		<div id="edit_modal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
			<div class="modal-dialog" style="width: 500px;">
				<div class="modal-content">
					<form onSubmit="disable_btn('.btn_submit');" action="<?php echo base_url($this->router->fetch_class()."/update")?>" class="form-horizontal" method="POST">
						<div id="edit_ajax_container">
							
						</div>
					</form>
				</div>
			</div>
		</div>
		<!--  -->
		
		<?php $this->load->view("includes/footer");?>
	</section>
	
	<script>
		$(document).ready(function(){
			<?php
				$get = $this->input->get();
		
				if($get['id'] != ""){
					echo "$('#myTab a[href=\"#tab_" . $get['id'] . "\"]').tab('show');";
				}
				else{
					echo "$('#myTab a:first').tab('show');";
				}
			?>
		});

		function edit_load_data(id){
			disable_btn("#edit_btn_submit");
			
			//Loader---
			$("#edit_ajax_container").html("<?php echo $this->text_ajax_loader;?>");
			//---------
			
			var title = id == 0? "New":"Edit";
			$("#edit_h4_title").html(title);
			
			$.ajax({
				type: "POST",
				url: "<?php echo base_url($this->router->fetch_class());?>/edit",
				data: "PKKEY=" + id,
				success: function(result, status, xhr){
					$("#edit_ajax_container").html(result);
					enable_btn("#edit_btn_submit");
				},
				error: function(xhr,status,error){
					$("#edit_ajax_container").html("<?php echo $this->text_ajax_fail;?>");
				},
				complete: function(xhr,status){
				},
			});
		}
	</script>
</body>
</html>
