

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



<style>
#dynamic_ajax_table_length ,.dt-buttons ,#dynamic_ajax_table_filter{
    //float: left;
}
.custom-design-modal{
max-width:70%;
}
.dt-buttons{
    height: 34px;
}
</style>
   <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; ?>"  active_mn="<?= $rows->root;?>"  active_mnt="<?= $rows->menu_type;?>">
    <?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_icon="fa fa-pencil" btn_text="Edit" btn_click_function="call_edit_modal" btn_class="btn btn-success btn-sm btn-dtbl" col_width="30" >
     <?php endif; ?> 
     <?php if($info == "1" && $z==2): ?>
        <input type="hidden" class="additional_btns" btn_icon="fa fa-trash-o " btn_text="Remove" btn_click_function="call_remove_modal" btn_class="btn btn-danger btn-sm btn-dtbl" col_width="40"  >
     <?php endif; ?> 
     <?php if($info == "1" && $z==3): ?>
          <input type="hidden" class="additional_btns" btn_icon="fa fa-print" btn_text="Print" btn_click_function="call_print_function2" btn_class="btn btn-info btn-sm btn-dtbl" col_width="40"  >
     <?php endif; ?>
  <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
<?php endif; ?>


<div class="page-header">
<div class="row align-items-center">
<div class="col">
<h3 class="page-title"><?= $rows->menu_name;?></h3>
</div>
<div class="col-auto float-end ms-auto">
<a href="#" class="btn add-btn" data-bs-toggle="modal" data-bs-target="#add_employee"><i class="fa fa-plus"></i> Add User</a>

</div>
</div>
</div>


<div class="row filter-row">




</div>

<div class="row">
<div class="col-md-12">
<div class="table-responsive" id="table_result">
    
</div>
</div>
</div>
<input type="hidden" id="hidden_status" value="0">
<input type="hidden" id="row_id" value="0">




<div id="add_employee" class="modal custom-modal fade add_main_modal" role="dialog">
<div class="modal-dialog modal-dialog-centered modal-lg custom-design-modal" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><?= $rows->menu_name;?></h5>
<button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label class="col-form-label"> Name<span class="text-danger">*</span></label>
<input class="form-control focusable" autocomplete="off" type="text" id="name">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label class="col-form-label">User Name</label>
<input class="form-control focusable" autocomplete="off" type="text" id="uname">

</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label class="col-form-label">Phone</label>

<input class="form-control focusable" autocomplete="off"  id="phone1">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label class="col-form-label">Password</label>
<input class="form-control focusable" autocomplete="off"  id="password">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label class="col-form-label">Email</label>
<input class="form-control focusable " type="text" id="email"> 
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label class="col-form-label">Address</label>
<input class="form-control focusable " type="text" id="address"> 
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label class="col-form-label">User Group</label>
  <select class="select  form-control " name="tags[]" multiple="multiple"
                id="select2Multiple" >
                <?php $__currentLoopData = $ug; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i=>$s): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
              
                  <option value="<?php echo e($s->ug_id); ?>"><?php echo e($s->ug_name); ?></option>
                  <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
          </select>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label class="col-form-label">&nbsp;</label>
<div class="checkbox">
<label>
<input type="checkbox" name="rs_menu" value="1"> Reset Menu
</label>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label class="col-form-label">Branch</label>
    <?php $__currentLoopData = $br; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i=>$s): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
         

                            <div class="checkbox">
<label>
<input type="checkbox" name="branch_id" value="<?php echo e($s->CID); ?>"> <?php echo e($s->BranchName); ?>

</label>
</div>
                  <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</div>
</div>


<div class="submit-section">

<button type="button" id="add_btn" class="btn btn-info btn-lg" onclick="submit_form();">Save</button>
<button type="button" id="edit_btn" class="btn btn-success btn-lg" onclick="submit_form();">Edit</button>
<button type="button" class="btn btn-danger btn-lg">Reset</button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php $__env->stopSection(); ?>




<?php $__env->startSection('page-script'); ?>
<script src="<?php echo e(asset('project-js\vega-front-scripts.js')); ?>"></script>
<script type="text/javascript">

  
   $(document).ready(function() {
            // Select2 Multiple
            /*$('#select2Multiple').select2({
                placeholder: "Select",
                allowClear: false
            });
*/
           $('#select2Multiple').on("select2:unselecting", function(e){

           
      var unselected_value = e.params.args.data.id;
         $('.ug_id'+unselected_value).remove();
    }).trigger('change');

        });
set_mn();

fetch_view_table();



//http://192.168.18.128/prl_api/ij/prl_branch_edit.php

function call_edit_modal(row_id) {
$('#add_btn').hide();
$('#edit_btn').show();

    $('#row_id').val(row_id);
    $('#hidden_status').val(1);
    $.ajax({
          url: "/edit_user",
          type: "POST",
          data:{
             '_token': "<?php echo e(csrf_token()); ?>",
              row_id:row_id
          },
          error: function(response) {
          },
          success:function(response){
             $('.add_main_modal').modal('show');
            if(response.ug_id!=null){
           ug_id= response.ug_id.split(',');
           $('#select2Multiple').val(ug_id).trigger('change');
         }else{
            $('#select2Multiple').val('').trigger('change');
         }

           $('#name').val(response.name);
              $('#uname').val(response.uname);
              $('#email').val(response.email);
              $('#password').val(response.password);
              $('#phone1').val(response.phone);
              $('#address').val(response.address);
              $
              $('input[name="branch_id"]:checked').val(response.branch_id);
          }
         });
}

  function Save_form() {
 ug_id = $("#select2Multiple").val(); 
           $.ajax({
          url: "/op_user",
          type: "POST",
          data:{
             '_token': "<?php echo e(csrf_token()); ?>",
              hidden_status:$.trim($('#hidden_status').val()),
              row_id:$.trim($('#row_id').val()),
              name:$.trim($('#name').val()),
              uname:$.trim($('#uname').val()),
              password:$.trim($('#password').val()),
              email:$.trim($('#email').val()),
              phone:$.trim($('#phone').val()),
              address:$.trim($('#address').val()),
              ug_id:ug_id.join(),
              rs_menu:$.trim($('input[name="rs_menu"]:checked').val()),
              branch_id:$.trim($('input[name="branch_id"]:checked').val())
          },
          success:function(response){
            
            console.log(response);
            if (response) {
              alert(response['msg']);
            
               $('.add_main_modal').modal('hide');
               fetch_view_table();
            }else{

            }
          },
          error: function(response) {
          }
         });
  }

  $( ".add_main_modal" ).on('hidden.bs.modal', function(){ $('#add_btn').show();
$('#edit_btn').hide();
 $('#hidden_status').val(0);
 $('.add_main_modal .form-control').val('');
});



  function submit_form() {
    status=0;
    if ($.trim($('#name').val())=='') {
      alert('Enter Name ');
      $('#name').focus();
       status=1;
      return;
    }
    if ($.trim($('#uname').val())=='') {
      alert('Enter User Name ');
      $('#uname').focus();
       status=1;
      return;
    }
    if ($.trim($('#password').val())=='') {
      alert('Enter Password ');
      $('#password').focus();
       status=1;
      return;
    }
    if ($.trim($('#select2Multiple').val())=='') {
      alert('Enter User Group ');
      $('#select2Multiple').focus();
       status=1;
      return;
    }
     if ($('input[name="branch_id"]:checked').length=='0') {
      alert('Select Company ');
       status=1;
      return;
    }
    if(status==0) Save_form();
  }

</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.admin', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\xampp\htdocs\payroll\resources\views/aview/user.blade.php ENDPATH**/ ?>