

<?php $__env->startSection('pageTitle', 'Vega Soft'); ?>
<?php $__env->startSection('page-content'); ?>

<style type="text/css">
 .form-check .form-check-label input[type="checkbox"]:disabled + .input-helper::before {
  background-color: #797d83;
  border: #797d83;
}


</style>

<div id="form-div">
<div class="page-header form-header" >
  <h3 class="page-title text-white"><?= $rows->menu_name;?> </h3>
    <nav aria-label="breadcrumb">
      <ol class="breadcrumb">
      
        <!-- <li class="breadcrumb-item text-success  icon-md " aria-current="page"><i class="icon-list slide1"></i> </li> -->
      </ol>
    </nav>
    

    <input type="hidden" id="table_settings_field" branch_id="" branch_name=""  column_heading="<?= $rows->column_heading;?>" column_width="<?= $rows->column_width;?>" column_alighn="<?= $rows->column_alighn;?>"  column_conversion="<?= $rows->column_conversion;?>" settings_row_id="<?= $id;?>" sp_date_picker="<?= $rows->sp_date_picker;?>"  header_from_date="<?=date('d-m-Y', strtotime('-7 days')); ?>"   header_till_date="<?=date('d-m-Y'); ?>"  sp_sort="<?= $rows->menu_id; ?>"   >
    <?php if($rows->sedp != ""): ?>
  <?php $__currentLoopData = explode(',', $rows->sedp); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $z=>$info): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> 
     <?php if($info == "1" && $z==1): ?>
       <input type="hidden" class="additional_btns" btn_text="Edit" btn_click_function="call_edit_modal" btn_class="btn btn-success btn-sm" col_width="30" >
     <?php endif; ?> 
     <?php if($info == "1" && $z==2): ?>
        <input type="hidden" class="additional_btns" btn_text="Remove" btn_click_function="call_remove_modal" btn_class="btn btn-danger btn-sm" col_width="40"  >
     <?php endif; ?> 
     <?php if($info == "1" && $z==3): ?>
          <input type="hidden" class="additional_btns" btn_text="View" btn_click_function="call_print_function2" btn_class="btn btn-info btn-sm" col_width="40"  >
     <?php endif; ?>
  <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
<?php endif; ?>
</div>
<div class="card">
    <div class="card-body">
    	<form class="forms-sample" autocomplete="off">
<div class="row">
  <div class="col-md-4">
    <div class="form-group row">
      <label class="col-sm-3 form-label">Name</label>
      <div class="col-sm-9">
        <select   class="js-example-basic-single form-control " id="uid" onchange="get_user_menus();">
            <option value="0">Select User</option>
          <?php $__currentLoopData = $user; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ug): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

  <option value="<?php echo e($ug->id); ?>"><?php echo e($ug->name); ?></option>
  <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</select>
      </div>
    </div>
    
  </div>

  <div class="col-md-8">
    <h4 class="card-title text-primary">Menus</h4>
    
    <!-- <div class="col-md-12" id="menu_all">
    
    </div> -->
   <div class="container" >
     <ul id="accordion" class="accordion">
     <!-- 
  <li>
    <div class="link"><i class="fa fa-laptop"></i>
User
      <i class="fa fa-chevron-down"></i></div>
    <ul class="submenu">
      <li>
         <div class="col-sm-6  ">
        <div class="form-check form-check-info  form-check-inline">
          <label class="form-check-label">
            <input type="checkbox" class="form-check-input" name="" > Save <i class="input-helper"></i>
          <i class="input-helper"></i></label>
        </div> 
        </div> 
        <div class="col-sm-6 row ">
        <div class="form-check form-check-success  form-check-inline">
          <label class="form-check-label">
            <input type="checkbox" class="form-check-input" name="" > Save <i class="input-helper"></i>
          <i class="input-helper"></i></label>
        </div>
        <div class="form-check form-check-success  form-check-inline">
          <label class="form-check-label">
            <input type="checkbox" class="form-check-input" name="" > Edit <i class="input-helper"></i>
          <i class="input-helper"></i></label>
        </div>
        <div class="form-check form-check-success  form-check-inline">
          <label class="form-check-label">
            <input type="checkbox" class="form-check-input" name="" > Delete <i class="input-helper"></i>
          <i class="input-helper"></i></label>
        </div>
        <div class="form-check form-check-success  form-check-inline">
          <label class="form-check-label">
            <input type="checkbox" class="form-check-input" name="" > Print <i class="input-helper"></i>
          <i class="input-helper"></i></label>
        </div>
      </div>
      </li>
      <li><a href="#">HP Envy</a></li>
      <li><a href="#">Macbook Air</a></li>
    </ul>
  </li>
  <li>
    <div class="link"><i class="fa fa-tv"></i>Smart TV<i class="fa fa-chevron-down"></i></div>
    <ul class="submenu">
      <li><a href="#">Sony Bravia</a></li>
      <li><a href="#">Samsung</a></li>
      <li><a href="#">MI</a></li>
    </ul>   
  </li>
  <li>
    <div class="link"><i class="fa fa-mobile"></i>Mobiles<i class="fa fa-chevron-down"></i></div>
    <ul class="submenu">
      <li><a href="#">Samsung S9</a></li>
      <li><a href="#">Apple X</a></li>
      <li><a href="#">Honor Play</a></li>
    </ul>
  </li>
  <li>
    <div class="link"><i class="fa fa-globe"></i>Search Engines<i class="fa fa-chevron-down"></i></div>
    <ul class="submenu">
      <li><a href="#">Google</a></li>
      <li><a href="#">Bing</a></li>
      <li><a href="#">Yahoo</a></li>
    </ul>
  </li>
 --></ul>
   </div>
  </div>
</div>


                      <div class="template-demo">
                        
                     <button type="button" class="btn btn-success btn-icon-text save_btn btn-sm"  onclick="submit_form();">
                            <i class="icon-doc btn-icon-prepend"></i> Submit </button>
                      <button type="button" class="btn btn-danger btn-icon-text reset_btn btn-sm"  >
                            <i class="icon-reload btn-icon-prepend"></i> Reset </button>
                            <input type="hidden" id="row_id" value="0">
                            <input type="hidden" id="hidden_status" value="0">
                          </div>
                    </form>
    </div>
</div>
</div>

<div id="table-div">
<div class="page-header form-header" >
  <h3 class="page-title text-white">  Tables </h3>
    <nav aria-label="breadcrumb">
      <ol class="breadcrumb">
      
        <li class="breadcrumb-item text-success  icon-md " aria-current="page"><i class="icon-plus slide2"></i> </li>
      </ol>
    </nav>
</div>

  

<div class="card">
  


    <div class="col-lg-12 col-sm-12 col-md-12" id="table_result">
                                            
                                            </div>


    
    
</div>
</div>







<script type="text/javascript">


//tree();
options = [];
 $(document).ready(function() {
 
   
  $(".js-example-basic-single").select2(
    {
      placeholder: {
        id: '', // the value of the option
        text: 'None Selected'
      },
      allowClear: false,
    
    });
  // Select2 Multiple
          

        });







function submit_form() {
    status=0;
    // if ($.trim($('#ug_name').val())=='') {
    //   alert('Enter USer Group ');
    //    status=1;
    //   return;
    // }
    //  if ($('input[type="checkbox"]:checked').length=='0') {
    //   alert('Assign Atleast One Menu To User Group ');
    //    status=1;
    //   return;
    // }
    if(status==0) Save_form();
  }
  function Save_form() {
    marr=[];
     $('.act_m_menu').each(function(){
      menu_id=$(this).attr('menu_id');
       arr={
        'menu_id':menu_id,
        'sedp':''
      }
       marr.push(arr);
     });
     $('.act_menu').each(function(){
      menu_id=$(this).attr('menu_id');
      sedp=[0,0,0,0];
     if($('input[name="mn'+menu_id+'"]').prop('checked')){ //alert(sedp[0]);
      if ($('input[name="cs'+menu_id+'"]').prop('checked')) {
        sedp[0]=1;
      } 
      if ($('input[name="ce'+menu_id+'"]').prop('checked')) {
        sedp[1]=1;
      }
      if ($('input[name="cd'+menu_id+'"]').prop('checked')) {
        sedp[2]=1;
      }
      if ($('input[name="cp'+menu_id+'"]').prop('checked')) {
        sedp[3]=1;
      }
      arr={
        'menu_id':menu_id,
        'sedp':sedp.join(',')
      }
       marr.push(arr);
     }


     });
    // console.log(marr);
         $.ajax({
          url: "/op_set_menu",
          type: "POST",
          data:{
             '_token': "<?php echo e(csrf_token()); ?>",
              hidden_status:$.trim($('#hidden_status').val()),
              uid:$.trim($('#uid').val()),
              marr:marr
          },
          error: function(response) {
          },
          success:function(response){
             console.log(response);
            if (response) {
              alert(response['msg']);
            
               $('.add_main_modal').modal('hide');
               fetch_view_table();
            }else{

            }
          }
         });
  }
var tree1=0;
  function get_user_menus() {
      uid = $("#uid").val(); 
      if(uid!=''){
          $.ajax({
          url: "/get_user_menus",
          type: "POST",
          data:{
             '_token': "<?php echo e(csrf_token()); ?>",
              uid:uid
          },
          error: function(response) {
          },
          success:function(response){
            var data = JSON.parse(response);
            // alert(data.length);
             $('input[type="checkbox').prop('checked',false);
          if(data.length>0) {

                $(data).each(function(i,val){
                  nme='mn'+val['menu_id'];
                  $('input[name="'+nme+'"]').prop('checked',true);
                  sedp=val['sedp'].split(',');
                  cls=['s','e','d','p'];
                   for (var j = 0; j <4; j++) {

                      nme='c'+cls[j]+val['menu_id'];
                    if(sedp[j]==1 && $('input[name="'+nme+'"]').prop('disabled')==false){ 
                       $('input[name="'+nme+'"]').prop('checked',true);
                    }else{
                        $('input[name="'+nme+'"]').prop('checked',false);
                    }
                   }
                });
            }
          }
         });
      }
  }

  var tree1=0;
  get_all_menus();

  function get_all_menus() { 

           $.ajax({
          url: "/get_all_menus",
          type: "POST",
          data:{
             '_token': "<?php echo e(csrf_token()); ?>"
          },
          error: function(response) {
          },
          success:function(response){
          
          var data = JSON.parse(response);
         k=0;
         len=data.length;
         res='';
          if(data.length>0){
          $(data).each(function(i,val){
            menu=['Save','Edit','Delete','Print'];
            cls=['s','e','d','p'];
           
if(val['menu_type']!=3){




  if(val['menu_type']==0){
  if(i>0){
                 res+='</ul>';
                res+='</li>';
               
              }
              
            res+='<li class="act_m_menu " menu_id="'+val['menu_id']+'"><div class="link"><i class="fa fa-laptop" ></i>'+val['menu_name']+'      <i class="fa fa-chevron-down"></i></div> <ul class="submenu1">';
k++;
            }
            if(val['menu_type']==1){
res+='<li class="row act_menu"  menu_id="'+val['menu_id']+'">';
res+='<div class="col-sm-5  ">';
res+='<div class="form-check form-check-info  form-check-inline">';
res+='<label class="form-check-label">';
res+='<input type="checkbox" class="form-check-input"  name="mn'+val['menu_id']+'"  value="'+val['menu_id']+'"> '+val['menu_name']+' <i class="input-helper"></i>          <i class="input-helper"></i><i class="input-helper"></i></label>';
res+='</div> ';
res+='</div> ';
res+='<div class="col-sm-7 row ">';
arr=val['sedp'].split(',');
for (var j = 0; j <4; j++) {
//  alert(arr[j]);
chk='disabled="" ';
if(arr[j]=='0'){
chk='';
}else if(arr[j]=='1'){
chk='checked=""';
}
res+='<div class="form-check form-check-primary  form-check-inline">';
res+='<label class="form-check-label">';
res+='<input type="checkbox" class="form-check-input c'+cls[j]+val['menu_id']+'"  name="c'+cls[j]+val['menu_id']+'" '+chk+'> '+menu[j]+' <i class="input-helper"></i></label>';
res+='</div>';
};
res+='</div></li>';
}


if(len==(i+1)){
                 res+='</ul>';
                res+='</li>';
               
              
            }




     
}

else

{


  res+='</ul><li><div class="link"><i class="fa fa-laptop"></i>'+val['menu_name']+'      <i class="fa fa-chevron-down"></i></div> <ul class="submenu1">';
         res+='<li class="row act_menu"  menu_id="'+val['menu_id']+'">';
          res+='<div class="col-sm-5  ">';
         res+='<div class="form-check form-check-info  form-check-inline">';
           res+='<label class="form-check-label">';
              res+='<input type="checkbox" class="form-check-input" name="mn'+val['menu_id']+'"  value="'+val['menu_id']+'"> '+val['menu_name']+' <i class="input-helper"></i>          <i class="input-helper"></i><i class="input-helper"></i></label>';
         res+='</div> ';
         res+='</div> ';
         res+='<div class="col-sm-7  row">';
              arr=val['sedp'].split(',');
          for (var j = 0; j <4; j++) {
    //  alert(arr[j]);
        chk='disabled="" ';
        if(arr[j]=='0'){
          chk='';
        }else if(arr[j]=='1'){
          chk='checked=""';
        }
        res+='<div class="form-check form-check-primary  form-check-inline">';
          res+='<label class="form-check-label">';
            res+='<input type="checkbox" class="form-check-input c'+cls[j]+val['menu_id']+'"  name="c'+cls[j]+val['menu_id']+'" '+chk+'> '+menu[j]+' <i class="input-helper"></i></label>';
        res+='</div>';
       };
       res+='</div>';
      res+='</li></ul>';



         
           




       
            }


            i++;
            });
          res+='</ul>'; //alert(res);
          $('#accordion').html(res);
          tree();
         }
         
          }
         });
           
  }

</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.admin', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/trafiqer/public_html/petro/resources/views/aview/set_menu.blade.php ENDPATH**/ ?>