<?php require_once('../auth/auth.php');require_once('../auth/function.php');  ?>
<section class="content">
  <div class="container-fluid">
    <div class="row">
       <div class="col-md-12">
         <div class="card card-primary card-outline direct-chat direct-chat-primary shadow-none" style="border-left:1px solid #969c9d;border-right:1px solid #969c9d;border-bottom:1px solid #969c9d;">
           <div class="card-header" style="padding: 5px 8px;">
               <h3 class="card-title">New Complain  Add</h3>

            <div class="card-tools"> <button type="button" class="btn btn-tool" data-card-widget="remove"> <i class="fas fa-times"></i>  </button> </div>
        </div>
        <form id="complain_form" action="#" method="post" autocomplete="off">
            <input type="hidden" name="newcom" required="true">
         <div class="card-body">
            <div class="col-md-12">
               <div class="row">
                  <div class="col-md-3">
                     <div class="form-group">
                        <label>Select Main Menubar   </label>
                        <select name="navber" id="navber"  class="form-control select2" style="width: 100%;" required="true">
                           <option value="N/A" >Select Menubar</option>
                             <?php 
                           $language_query= mysqli_query($conn,"SELECT * FROM language WHERE  lang_type=1 ") or die (mysqli_error($conn));
                           while($lagr= mysqli_fetch_assoc($language_query)){
                             echo '<option value='.$lagr["english"].'>'.$lagr["english"].')</option>';
                          }?>  
                        </select>
                     </div>
                  </div>

                    <div class="col-md-3">
                     <div class="form-group">
                        <label>Select Sub Menubar   </label>
                        <select name="sub_navber" id="sub_navber"  class="form-control select2" style="width: 100%;" required="true">
                           <option value="N/A" >Select Sub Menubar</option>
                             <?php 
                           $language_query= mysqli_query($conn,"SELECT * FROM language WHERE  lang_type=1 ") or die (mysqli_error($conn));
                           while($lagr= mysqli_fetch_assoc($language_query)){
                             echo '<option value='.$lagr["english"].'>'.$lagr["english"].')</option>';
                          }?>  
                        </select>
                     </div>
                  </div>
                  <div class="col-md-4">
                     <div class="form-group">
                        <label> Problem  Type   </label>
                        <select  id="problem_type" name="problem_type"  class="form-control select2" style="width: 100%;" required="true">
                           <option value="Long Time Load">Long Time Load</option>
                           <option value="Update Failed ">Update Failed</option>
                           <option value="Print Button Not working">Print Button Not working </option>
                           <option value="Accounting Balance Not Actual">Accounting Balance Not Actual </option>
                           <option value="Apps Problem">Apps Problem</option>
                        </select>
                     </div>
                  </div>
                  <div class="col-md-2">
                     <div class="form-group">
                       <label>Problem Start Date  </label>
                      <input type="text" name="p_start_date" class="form-control form-control-sm" onmouseover="stdate(this)"  style="text-align:center;" required="true" value="<?php echo $date;?>">
                    </div>
                  </div>
                  <div class="col-md-12">
                     <div class="form-group">
                        <label>Problem Genaeral Note </label>
                        <textarea name="p_note" class="form-control form-control-sm inputselect" rows="2" placeholder="Enter ...Your Complain "></textarea>
                     </div>
                  </div>
                  <div class="col-md-4">
                     <div class="form-group">
                        <label>Problem  Type   </label>
                        <select id="type" name="type"  class="form-control select2" style="width: 100%;" required="true">
                           <option value="High">High </option>
                           <option value="Low">Low</option>
                           <option value="Normal">Normal</option>
                        </select>
                     </div>
                  </div>
                  <div class="col-md-4">
                     <div class="form-group">
                      <center><label> Date </label></center>
                      <input type="text" name="date" class="form-control form-control-sm" onmouseover="lcdate(this)" style="text-align:center;" readonly="true" required="true" value="<?php echo $date;?>">
                     </div>
                  </div>
                  <div class="col-md-1"> </div>
                  <div class="col-md-3">
                     <div class="form-group" style="margin-top:19px;">
                        <div class="custom-control custom-checkbox">
                           <input name="sendsms" class="custom-control-input" type="checkbox" id="customCheckbox2" value="yes">
                           <label for="customCheckbox2" class="custom-control-label">Send via SMS</label>
                        </div>
                     </div>
                  </div>
               </div>   
            </div>
         </div>
         <center>
            <div class="card-footer" style="padding: 8px 5px;">
               <button type="submit" id="save" class="btn btn-success btn-xs">Info Save</button>
               <button type="reset" class="btn btn-secondary btn-xs">Reset</button>
            </div>
         </center>
      </form>

     <div class="card-body p-1">
         <tr>
            <th rowspan="3"  class="text-center" >
              <input type="text" id="search" class="form-control form-control-sm search"  placeholder="searching" required="true" style="border-radius: ;border:1px solid primary;width:100%; text-align:center; padding:; ">
            </th>
         </tr>
<table id="trbl_table" class="ttable searchtable" cellpadding="0" cellspacing="0">
   <thead>
      <tr class="sticky-top">
        <th class="text-center" style="width:3%;">S/l</th>
        <th style="width:10%;">Company </th>
        <th style="width:8%;">Main Menubar </th>
        <th class="text-center" style="width:9%;">Sub Menubar </th>
        <th class="text-center" style="width:15%;">Problem Type   </th>
        <th class="text-center" style="width:7%;">P Start Date  </th>
        <th class="text-center" style="width:13%;">Problem Genaeral Note  </th>
        <th class="text-center" style="width:8%;">Type </th>
        <th class="text-center" style="width:10%;">Date</th>
        <th class="text-center" style="width:7%;">Status</th>
        <th class="text-center" style="width:15%;">userid</th>
      </tr>
   </thead>
      <tbody id="colview">
      <?php
         $complain_query= mysqli_query($conn,"SELECT * FROM complain WHERE cid AND coid='$coid'  ") or die (mysql_error());
           $i=0;
           while ($rowc= mysqli_fetch_array ($complain_query) ){
            $companyid= $rowc['coid'];
            $uidid= $rowc['userid'];
            $company_name=mysqli_fetch_assoc(mysqli_query($conn,"SELECT co_name FROM company WHERE   coid='$companyid'  LIMIT 1 "))['co_name'];  
             $employee_name=mysqli_fetch_assoc(mysqli_query($conn,"SELECT em_acname FROM em_employee WHERE   em_id='$uidid'  LIMIT 1 "))['em_acname'];  
        ?>
         <tr>
            <td  style="font-size: 11.5px;text-align: center;"><?php echo ++$i ?></td>
            <td  style="font-size: 11.5px"><?php echo $company_name; ?>  </td>
            <td  style="font-size: 11.5px"><?php echo $rowc['navber'] ?>  </td>
            <td  style="font-size: 11.5px"><?php echo $rowc['sub_navber']?></td>
            <td  style="font-size: 11.5px"><?php echo $rowc['problem_type']?></td>
            <td  style="font-size: 11.5px"><?php echo $rowc['p_start_date']?></td>
            <td  style="font-size: 11.5px"><?php echo $rowc['p_note']?></td>
            <td  style="font-size: 11.5px"><?php echo $rowc['type']?></td>
            <td  style="font-size: 11.5px"><?php echo $rowc['date']?></td>
            <td  style="font-size: 11.5px"><?php echo $rowc['status']?></td>
            <td  style="font-size: 11.5px"><?php echo $employee_name ?></td>
         </tr>
         <?php } ?>
      </tbody>
   </table>
</div>
   </div>
</div>
</div>
</div>

</section>
<script>
   $(document).ready(function(){
     $("#navber,#sub_navber,#problem_type,#type").select2();
  });  
</script>
<script>
   $(document).ready(function() {
    $('#complain_form').on('submit', function(e){
     $('#save').prop('disabled', true);
     $('#save').html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> '+'Loading...');
     e.preventDefault();  
     $.post("../support_desk/complain_db.php",$(this).serialize(),function(data){
        $('#complain_form')[0].reset();
        $('#save').prop('disabled', false);
        $('#save').html('Company Save');
           $.post('../support_desk/complain_center.php?running='+1,{},function(res){
              $('#complainview').html(res);
           }); 
           toastr.success(Showing, '<?php echo "New Complain Add Successful" ?>');
    
    });
  });

 });  
</script>


<script>
 $(document).ready(function(){
    $('.search').on('keyup',function(){
      var searchTerm = $(this).val().toLowerCase();
      $('.searchtable tr').each(function(){
        var lineStr = $(this).text().toLowerCase();
        if(lineStr.indexOf(searchTerm) === -1){
          $(this).hide();
      }else{
          $(this).show();
      }
  });
  });

    $('th').each(function (col) {
      $(this).hover(
        function () {
          $(this).addClass('focus');
      },
      function () {
          $(this).removeClass('focus');
      }
      );
      $(this).click(function () {
        if ($(this).is('.asc')) {
          $(this).removeClass('asc');
          $(this).addClass('desc selected');
          sortOrder = -1;
      } else {
          $(this).addClass('asc selected');
          $(this).removeClass('desc');
          sortOrder = 1;
      }
      $(this).siblings().removeClass('asc selected');
      $(this).siblings().removeClass('desc selected');
      var arrData = $('table').find('tbody >tr:has(td)').get();
      arrData.sort(function (a, b) {
          var val1 = $(a).children('td').eq(col).text().toUpperCase();
          var val2 = $(b).children('td').eq(col).text().toUpperCase();
          if ($.isNumeric(val1) && $.isNumeric(val2))
            return sortOrder == 1 ? val1 - val2 : val2 - val1;
        else
            return (val1 < val2) ? -sortOrder : (val1 > val2) ? sortOrder : 0;
    });
      $.each(arrData, function (index, row) {
          $('tbody').append(row);
      });
  });
  });
});
</script>