<?php $__env->startSection('content_header'); ?>
    <h1>Tapal Routing</h1>
<?php $__env->stopSection(); ?>

<script src="//code.jquery.com/jquery.js"></script>

<?php $__env->startSection('content'); ?>
 <?php echo notifyCss(); ?>
 <?php echo notifyJs(); ?>   
     <?php if($errors->any()): ?>
         <div class="alert alert-danger">
             <ul>
                 <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <li><?php echo e($error); ?></li>
                 <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </ul>
        </div>
     <?php endif; ?>
    <?php if(session('status')): ?>
        <div class="alert alert-success">
             <?php echo e(session('status')); ?>

        </div>
    <?php endif; ?>
<?php echo $__env->make('notify::messages', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
    <div class="row">
            <!--row starts-->
     <div class="col-md-12">
        <div class="panel panel-primary">
           <div class="panel-heading">
                <h3 class="panel-title">
                            <?php echo e(request()->session()->get('session_tname')); ?>Route Configuration
                        </h3>
           </div>

                <div class="panel-body">
                    <div class="container">
                     <form class="form-horizontal"  action="<?php echo e(url('tapalroute')); ?>" method="post" >
                         <?php echo e(csrf_field()); ?>

                        <div class="form-group">
                            <label for="tapalsubject"><?php echo e(request()->session()->get('session_tname')); ?> Subject </label>
                              <select class="form-control" name="tapalsubject" id="subject">
                                  <option value="0"placeholder="">Select Subject</option> 
                                    <?php $__currentLoopData = $sub; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $subj): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($subj->id); ?>"placeholder=""><?php echo e($subj->subject); ?></option> 
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>  
                                    </select>
                               
                        </div>
                        <div class="form-group">
                              <label for="username">User Name:</label>
                                <input class="form-control" id="username"value="<?php echo e($name); ?>"type="text"name="username">
                              </div>
                                    
                          <div class="form-group">
                              <label for="username">Route Name:</label>
                                <input class="form-control" id="routename" type="text"name="routename">
                              </div>

                         
                              <div id="optiondiv">
                                <div class="col-md-12">
                                 <div class="form-group" >
                                    <div class="col-sm-4"><b>LEVEL</b></div>
                                    <div class="col-sm-4"><b>OFFICE</b></div>
                                    <div class="col-sm-4"> <b> SEAT</b></div>
                                     <button type="button" class="btn btn-primary btn-xs pull-right" id="addmore">Add More</button>
                                 </div>
                                </div>
                             <div class="col-md-12">
                               <div class="form-group" >
                                  <input type="hidden" name="optioncount" id="optioncount" value="1">
                                  <div class="col-sm-4">
                                     <input type="text" name="level1" id="level1" class="form-control" placeholder="Enter the level" >
                                  </div>
                                 <?php print("<script>var officeidarray=[]; var officenamearray=[];</script>"); ?> 
                                    <?php $i=0; ?>
                                   <?php $__currentLoopData = $offz; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $off): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                                    <?php 
                                   

                                    print("<script>officeidarray.push($off->id); officenamearray.push('$off->office_name');</script>");
                                    
                                   $i++; ?>

                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                 <div class="col-sm-4">
                                     <select class="form-control" name="office1" id="office1" onchange="fetchseats(1)" >
                                        <option value="">Select an Office</option>
                                        <?php $__currentLoopData = $offz; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $off): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                                       <option value="<?php echo e($off->id); ?>"><?php echo e($off->office_name); ?></option>
                                       <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                       
                                     </select>
                                </div>
                                <div class="col-sm-4">
                                    <select class="form-control" name="seat1" id="seat1">
                                       <option value=""placeholder="seat"></option>
                                   </select>
                                </div>
                              </div>
                                </div>
                            </div>
                                <button type="submit" class="btn btn-primary mb-2">Submit</button>
                          </form>
                       </div>             
            </div>
         </div>
     </div>
     </div>
            <!--md-12 ends-->
      <!--Table view for Tapal/File Forwarding Routes-->
<table class="table table-bordered" id="routetable">
        <thead>
            <tr>
                <th>Id</th>
                <th>Subject Name</th>
                <th>Route Name</th>
                <th>Updated At</th>
                <th>Actions</th>
            </tr>
        </thead>
    </table>

<script>
$(function() {

    $('#routetable').DataTable({
        processing: true,
        serverSide: true,
        ajax: '<?php echo url('routetabledata'); ?>',
        columns: [
            { data: 'id', name: 'id' },
            { data: 'subject', name: 'subject' },
            { data: 'routename', name: 'routename' },
            { data: 'updated_at', name: 'updated_at' },
            { data: 'action', name: 'action' }
        ],
        /*
        initComplete: function () {
            this.api().columns([1,2,3]).every( function () {
                var column = this;
                var select = $('<select><option value="">Select</option></select>')
                    .appendTo( $(column.header()))
                    .on( 'change', function () {
                        var val = $.fn.dataTable.util.escapeRegex(
                            $(this).val()
                        );

                        column
                            .search( val ? val : '', true, false )
                            .draw();
                    } );

                column.data().unique().sort().each( function ( d, j ) 
                {
                    select.append( '<option value="'+d+'">'+d+'</option>' )
                } );
            } );
        } */     
    });
});

</script>




<script type="text/javascript">
function fetchseats(cnt)
{

  var officeid=$("#office"+cnt).val();
        $.get("<?php echo e(url('getseat')); ?>",
        { option: officeid },
        function(data) {
            
            $('#seat'+cnt).empty();
            $('#seat'+cnt).append("<option value='0'>Select a seat</option>");
            $.each(data, function(key, element) {
             // alert(key);
                $('#seat'+cnt).append("<option value='" + key +"'>" + element + "</option>");
            });
        });
    
}

  $('#addmore').click(function(){
      var optioncount=$('#optioncount').val();
      optioncount++;
      var fieldHTML='<div class="col-sm-12"><div class="form-group" ><div class="col-sm-4"><input type="text" name="level'+optioncount+'" id="level'+optioncount+'" class="form-control" placeholder="enter the level" ></div><div class="col-sm-4"><select name="office'+optioncount+'" id="office'+optioncount+'" class="form-control" placeholder="office" onchange="fetchseats('+optioncount+')"><option value="">Select an Office</option>';
      for(i=0;i<officeidarray.length;i++)
      {
        fieldHTML=fieldHTML+'<option value='+officeidarray[i]+'>'+officenamearray[i]+'</option>';
      }
      fieldHTML=fieldHTML+'</select></div> <div class="col-sm-4"><select name="seat'+optioncount+'" id="seat'+optioncount+'" class="form-control" placeholder="seat" ></div> </div></div>';
      $('#optiondiv').append(fieldHTML);
      $('#optioncount').val(optioncount);
    }); 






</script>

<?php $__env->stopSection(); ?>




















































                 
<?php echo $__env->make('adminlte::page', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>