    <?php if($this->session->flashdata('menu_permission_added_success')): ?>
	<?php echo '<p class="alert alert-sucess">'.$this->session->flashdata('menu_permission_added_success').'</p>'; ?>
	<?php endif; ?>

	<?php if($this->session->flashdata('menu_permission_added_failed')): ?>
	<?php echo '<p class="alert alert-danger">'.$this->session->flashdata('menu_permission_added_failed').'</p>'; ?>
	<?php endif; ?>

    <?php if($this->session->flashdata('page_added_success')): ?>
	<?php echo '<p class="alert alert-sucess">'.$this->session->flashdata('page_added_success').'</p>'; ?>
	<?php endif; ?>

	<?php if($this->session->flashdata('page_added_failed')): ?>
	<?php echo '<p class="alert alert-danger">'.$this->session->flashdata('page_added_failed').'</p>'; ?>
	<?php endif; ?>

    <?php if($this->session->flashdata('mtr_menu_added_success')): ?>
	<?php echo '<p class="alert alert-sucess">'.$this->session->flashdata('mtr_menu_added_success').'</p>'; ?>
	<?php endif; ?>

	<?php if($this->session->flashdata('mtr_menu_added_failed')): ?>
	<?php echo '<p class="alert alert-danger">'.$this->session->flashdata('mtr_menu_added_failed').'</p>'; ?>
	<?php endif; ?>

<div class="row">
        <div class="col-12">
          <h1>Menu Permission</h1>
          <hr> 
          <p>
          <!--content starts-->




                                <div class="w3-row">
                                        <!--div class="w3-quarter"--><button data-toggle="collapse" data-parent="#accordion" href="#add_menu_permission"  class="collapsed btn btn-success"><i class="fa fa-plus"></i>ADD Menu Permission</button><!--/div-->
                                    
                                        <!--div class="w3-threequarter"-->
                                                                <div id="add_menu_permission" class="panel-collapse collapse" style="height: 0px;">
                                                                <br>
                                                                        <div class="w3-mobile w3-border panel-body"><center>
                                                                       
                                                                        <?php echo form_open('menu_permission/add_menu_permission'); ?>
                                                                        <div class="w3-row"> 
                                                                                <table class="table table-striped table-hover" style="width:100%;">
                                                                                        <tr>
                                                                                        <th colspan="2" align="center"><label><h2>Add New Menu & Permission</h2></label></th>
                                                                                        </tr>

                                                                                        <tr>
                                                                                        <th>Menu Name:</th>
                                                                                        <td>
                                                                                                <?php echo form_input(['name'=>'menu_name','class'=>'form-control','placeholder'=>'Enter Menu Name','id'=>'menu_name']); ?>    
                                                                                        </td>
                                                                                        </tr>

                                                                                        <tr>
                                                                                        <th>Page Link/Path:</th>
                                                                                        <td>
                                                                                                <select name='file_path'  class="form-control" id='file_path' required aria-required='true'>
                                                                                                        <option selected disabled hidden style='display: none' value=''>Select Page</option>
                                                                                                        <option  value="#">#</option>
                                                                                                        <?php foreach($pages as $page): ?>
                                                                                                                <option  value="<?php echo $page['page_link']; ?>"><?php echo $page['page_name']; ?></option>
                                                                                                        <?php endforeach; ?>
                                                                                                </select>
                                                                                        </td>
                                                                                        </tr>
        
                                                                                        <tr>
                                                                                        <th>Under-Menu:</th>
                                                                                        <td>
                                                                                                <select name='under_menu_id'  class="form-control" id='under_menu_id' required aria-required='true'>
                                                                                                        <option selected disabled hidden style='display: none' value=''>Select Under-Menu</option>
                                                                                                        <option  value="0">#</option>
                                                                                                        <?php foreach($menus as $menu): ?>
                                                                                                            <?php if($menu['under_menu_id']=='0'): ?>
                                                                                                                <option  value="<?php echo $menu['id']; ?>"><?php echo $menu['menu_name']; ?></option>
                                                                                                            <?php endif; ?>
                                                                                                        <?php endforeach; ?>
                                                                                                </select>
                                                                                        </td>
                                                                                        </tr>

                                                                                        <tr>
                                                                                        <th>Menu Order:</th>
                                                                                        <td>
                                                                                                <?php echo form_input(['name'=>'menu_order','class'=>'form-control','placeholder'=>'Enter Menu Order','id'=>'menu_order']); ?>    
                                                                                        </td>
                                                                                        </tr>

                                                                                        <tr>
                                                                                        <th>Permission To:</th>
                                                                                        <td>
                                                                                                            <table class="w3-table stripped">
                                                                                                                
                                                                                                                    <?php $m=0; foreach($user_types as $user_type): $m++; ?>
                                                                                                                    <tr class="w3-row">
                                                                                                                        <td class="w3-pull-left" align="left">
                                                                                                                            <?php echo form_checkbox(['name'=>'user_type_id'.'['.$m.']','class'=>'form-control','value'=>$user_type['id'],'checked'=>'','id'=>'user_type_id'.'['.$m.']']); ?>
                                                                                                                        </td>
                                                                                                                        <td class="w3-pull-right" align="right">
                                                                                                                            <?php echo $user_type['description']; ?>
                                                                                                                        </td>
                                                                                                                        <td class="w3-pull-left" align="left">
                                                                                                                            <select name='active_status[<?php echo $m; ?>]'  class="form-control" id='active_status[<?php echo $m; ?>]' required aria-required='true'>
                                                                                                                                    <option selected disabled hidden style='display: none' value='0'>Select Status</option>
                                                                                                                                    <option  value="1">ACTIVE</option>
                                                                                                                                    <option  selected="selected" value="0">IN-ACTIVE</option>                                                                                                                                    
                                                                                                                            </select>
                                                                                                                        </td>
                                                                                                                    </tr>
                                                                                                                    <?php endforeach; ?> 
                                                                                                            </table>                 
                                                                                        </td>
                                                                                        </tr>


                                                                                        <tr>
                                                                                        <td>
                                                                                                <button class="btn btn-info" type="submit">Submit</button>
                                                                                        </td>
                                                                                        <td>
                                                                                                <button class="btn btn-info" type="reset">Reset</button>
                                                                                        </td>
                                                                                        </tr>

                                                                                </table>
                                                                        </div>
                                                                        <?php echo form_close(); ?>              
                                                                        </center></div> 
                                                                        <br>        
                                                                </div>
                                        <!--/div--> 


                                        <!--div class="w3-quarter"--><button data-toggle="collapse" data-parent="#accordion" href="#add_page_function"  class="collapsed btn btn-success"><i class="fa fa-plus"></i>ADD Page/Function</button><!--/div-->
                                      
                                        <!--div class="w3-threequarter"-->
                                                                <div id="add_page_function" class="panel-collapse collapse" style="height: 0px;">
                                                                <br>
                                                                        <div class="w3-mobile w3-border panel-body"><center>
                                                                        
                                                                        <?php echo form_open('menu_permission/add_page_function'); ?>
                                                                        <div class="w3-row"> 
                                                                                <table class="table table-striped table-hover" style="width:100%;">
                                                                                        <tr>
                                                                                        <th colspan="2" align="center"><label><h2>Add New Page/Function</h2></label></th>
                                                                                        </tr>

                                                                                        <tr>
                                                                                        <th>Page Name:</th>
                                                                                        <td>
                                                                                                <?php echo form_input(['name'=>'page_name','class'=>'form-control','placeholder'=>'Enter Page Name','id'=>'page_name']); ?>    
                                                                                        </td>
                                                                                        </tr>

                                                                                        <tr>
                                                                                        <th>Page Link:</th>
                                                                                        <td>
                                                                                                <?php echo form_input(['name'=>'page_link','class'=>'form-control','placeholder'=>'Enter Page Link','id'=>'page_link']); ?>
                                                                                        </td>
                                                                                        </tr>
        
                                                                                
                                                                                        <tr>
                                                                                        <th>Page Description:</th>
                                                                                        <td>
                                                                                                <?php echo form_textarea(['name'=>'page_desc','class'=>'form-control','placeholder'=>'Enter Page Description(If Any)','id'=>'page_desc']); ?>    
                                                                                        </td>
                                                                                        </tr>

                                                                                        <tr>
                                                                                        <td>
                                                                                                <button class="btn btn-info" type="submit">Submit</button>
                                                                                        </td>
                                                                                        <td>
                                                                                                <button class="btn btn-info" type="reset">Reset</button>
                                                                                        </td>
                                                                                        </tr>

                                                                                </table>
                                                                        </div>
                                                                        <?php echo form_close(); ?>              
                                                                        </center></div>   
                                                                        <br>      
                                                                </div>
                                        <!--/div--> 



                                </div>      






                                        
                        <div class="w3-container">
                                    <br>  
                                <div class="w3-row">

                                        <div class="col-md-10">
                                                <?php if($menus): ?>
                                                        <table  class="table table-striped table-bordered table-hover">
                                                        <thead>
                                                                <tr>
                                                                <th>#</th>
                                                                <th>Menu Name</th>
                                                                <th>File  Path</th>
                                                                <th>Under Menu</th>
                                                                <th>Menu Order</th>
                                                                <th>Action</th>
                                                                </tr>
                                                        </thead>

                                                        <?php $i=0; foreach($menus as $post):  $i++;?>
                                                                <!--onclick model-->
                                                                <div id="<?php echo $i; ?>" class="w3-modal">
                                                                        <div class="w3-modal-content w3-card-4">
                                                                        <div class="w3-container">
                                                                                <div class="card-header"><h3>Update Menu:</h3>Menu ID-<?php echo $post['id']; ?></div>
                                                                                <span onclick="document.getElementById('<?php echo $i; ?>').style.display='none'" class="w3-button w3-display-topright" style="color:red;font-size:30px;font-weight:strong;">&times;</span>
                                                                                <div class="w3-card card-body">
                                                                                        <?php if(validation_errors()):$error=validation_errors();echo "<script>alert(".$error.");</script>";endif; ?>
                                                                                        <?php echo form_open('dashboard/update_menu'); ?>
                                                                                        <?php echo form_input(['name'=>'id','id'=>'id','hidden'=>'hidden','value'=>$post['id']]); ?>
                                                                                        <div class="form-group">
                                                                                        <label>Menu Name:</label>
                                                                                        <?php echo form_input(['name'=>'menu_name','id'=>'menu_name','placeholder'=>'Enter Menu Name','class'=>'form-control','value'=>$post['menu_name']]); ?>
                                                                                        </div>
                                                                                        <div class="form-group">
                                                                                        <label>Page Link/Path:</label>
                                                                                                <select name='file_path'  class="form-control" id='file_path' required aria-required='true'>
                                                                                                        <option selected disabled hidden style='display: none' value=''>Select Page</option>
                                                                                                        <?php foreach($pages as $page): ?>
                                                                                                            <?php if($page['page_link']==$post['file_path']): ?>
                                                                                                                <option  selected="selected" value="<?php echo $page['page_link']; ?>"><?php echo $page['page_name']; ?></option>
                                                                                                            <?php else: ?>
                                                                                                                <option  value="<?php echo $page['page_link']; ?>"><?php echo $page['page_name']; ?></option>
                                                                                                            <?php endif; ?>
                                                                                                        <?php endforeach; ?>
                                                                                                </select>
                                                                                        </div>
                                                                                        <div class="form-group">
                                                                                        <label>Under Menu:</label>
                                                                                                <select name='under_menu_id'  class="form-control" id='under_menu_id' required aria-required='true'>
                                                                                                        <option selected disabled hidden style='display: none' value=''>Select Under-Menu</option>
                                                                                                        <?php foreach($menus as $menu): ?>
                                                                                                            <?php if($menu['under_menu_id']=='0'): ?>
                                                                                                                <?php if($menu['id']==$post['id']):  ?>
                                                                                                                    <option selected="selected" value="<?php echo $menu['id']; ?>"><?php echo $menu['menu_name']; ?></option>
                                                                                                                <?php else: ?>
                                                                                                                    <option value="<?php echo $menu['id']; ?>"><?php echo $menu['menu_name']; ?></option>
                                                                                                                <?php endif; ?>
                                                                                                            <?php endif; ?>
                                                                                                        <?php endforeach; ?>
                                                                                                </select>
                                                                                        </div>
                                                                                        <div class="form-group">
                                                                                        <label>Menu Order</label>
                                                                                        <?php echo form_input(['name'=>'menu_name','id'=>'menu_order','placeholder'=>'Enter Menu Order','class'=>'form-control','value'=>$post['menu_order']]); ?>
                                                                                        </div>
                                                                                        <div class="form-group">
                                                                                        <label>Permission to</label>
                                                                                        
                                                                                            <?php foreach($user_types as $user_type): ?>
                                                                                                
                                                                                                    <?php foreach($menu_permissions as $menu_permission): ?>
                                                                                                        <?php if(($menu_permission['user_type_id']==$user_type['id'])&&($menu_permission['menu_id']==$post['id'])): ?>
                                                                                                            <?php echo form_checkbox(['name'=>'user_type_id','class'=>'form-control','value'=>$user_type['id'],'id'=>'user_type_id']); ?>
                                                                                                            <?php echo $user_type['description']; ?>
                                                                                                        <?php break;else: ?>
                                                                                                            <?php echo form_checkbox(['name'=>'user_type_id','class'=>'form-control','value'=>$user_type['id'],'id'=>'user_type_id']); ?>
                                                                                                            <?php echo $user_type['description']; ?>
                                                                                                        <?php break;endif; ?>
                                                                                                    <?php endforeach; ?>
                                                                                                                       
                                                                                            <?php endforeach; ?>
                                                                                        
                                                                                        </div>
                                                                                        <button class="btn btn-primary btn-block" type="submit">Update Now</button>
                                                                                        <?php echo form_close(); ?>
                                                                                </div>
                                                                        </div>
                                                                        </div>
                                                                </div>
                                                                <script>
                                                                        // Get the modal
                                                                        var modal = document.getElementById('<?php echo $i; ?>');

                                                                        // When the user clicks anywhere outside of the modal, close it
                                                                        window.onclick = function(event) {
                                                                        if (event.target == modal) {
                                                                                modal.style.display = "none";
                                                                                }
                                                                        }
                                                                </script>

                                                        <tbody>
                                                                <tr>
                                                                        <td><?php echo $i; ?></td>
                                                                        <td><?php echo $post['menu_name']; ?></td>
                                                                        <td><?php echo $post['file_path']; ?></td>
                                                                        <td><?php foreach($menus as $menu): if($menu['id']==$post['under_menu_id']): echo $menu['menu_name']; endif;endforeach; ?></td>
                                                                        <td><?php echo $post['menu_order']; ?></td>               
                                                                        <td>
                                                                        <div class="btn-group">
                                                                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                                                        Select Action
                                                                        <span class="caret"></span>
                                                                        </button>
                                                                        <ul class="dropdown-menu" >
                                                                                <li><a  onclick = "return confirm('Remove Menu-ID: <?php echo $post['id']; ?> ?')" href="<?php echo base_url('dashboard/delete_menu/').$post['id']; ?>" class="w3-button" style="width:100%;text-align:left;padding:0px;">Remove</a></li>
                                                                                <li><a href="#" onclick="document.getElementById('<?php echo $i; ?>').style.display='block'" class="w3-button" style="width:100%;text-align:left;left;padding:0px;">Update</a></li>
                                                                        </ul>
                                                                        </div>
                                                                        </td>
                                                                </tr>
                                                        </tbody>
                                                        <?php endforeach; ?>
                                                        </table>
                                                        <?php else: ?>
                                                        <?php echo "<div class='row'><p><pre><center><h2>No Menu added yet.</h2></center></pre></p></div>"; ?>
                                                        <?php endif; ?>
                                        </div>


                                </div>

                               
                        </div>











          <!--content ends-->
          </p>          
        </div>
      </div>