<div  class="panel panel-primary" id="main_supp">
  <div class="panel-heading clearfix"style="font-size:1.2em;">
  <div class="row" style="padding:4px;">
      <div class="col-xs-4 col-md-3"style="float:right;">
        <label class="control-label"style="float:right;font-size: 16px">بحث و تعديل بيانات شركات التأمين</label>
      </div>
      <div class="col-xs-4 col-md-2"style="float:left;  color: #000 ;">
      <input type="text" id="nn" name="nn" class="form-control" name="nn" placeholder="ابحث بالرقم">
      </div>
      <div class="col-xs-12 col-md-3"style="float:left;  color: #000 ;">
          <input type="text" class="form-control" id="tt" name="tt" placeholder="ابحث بالاسم">
          </div>
      <input type="hidden" id="vwv" name="vwv" style="width:20; color:#000 ;">
      <div class="col-xs-3 col-md-3"style="float:left;  color: #000 ;">
    <a href="a/ins_Update.php"target="_blank" id="v5" hidden><button type="button" class="btn btn-success"> تحديث </button></a>
    </div>
    </div>
    </div>
  <div class="panel-body"  style="background-color:#00324d;color:#cce5ff;">
    <?php
 include "../actions/dbPDO.php";
 $output = '';
 $sql =$db->prepare("SELECT insurance_id, ins_name, crash_man, crash_jawal, crash_jawal2, fax
                     from insurance order by insurance_id desc");
 $sql->execute();
 $output .= '
      <div class="table-responsive">
           <table class="table table-bordered table-hover">
                <tr>
                     <th width="10%">حركة</th>
                     <th width="20%">اسم الشركة</th>
                     <th width="20%">مسئول الحوادث</th>
                     <th width="15%">جوال1</th>
                     <th width="15%">جوال2</th>
                     <th width="15%">فاكس الشركة</th>
                    </tr>';
 if($sql->rowCount()>0)
 {
    while($row = $sql->fetch())
      {
           $output .= '
                <tr>
                     <td>
                     <a href="a/ins_update.php?id=' . $row['insurance_id'] . '"target="_blank"><button type="button" class="btn btn-success ">تحديث</button></a>
                     </td>
                     <td>' . $row['ins_name'] . '</td>
                     <td>' . $row['crash_man'] . '</td>
                     <td>' . $row['crash_jawal'] . '</td>
                     <td>' . $row['crash_jawal2'] . '</td>
                     <td>' . $row['fax'] . '</td>
                  </tr>
           ';
      }

 }
 else
 {
      $output .= '<tr>
                          <td colspan="6">لا يوجد سجلات ...</td>
                     </tr>';
 }
 $output .= '</table>


      </div>';
 echo $output;
 ?>
</div>
</div>
<!-- panel body style -->
<?php
$output = array();
    $sql2 =$db->prepare("SELECT insurance_id , ins_name from insurance
              union(select insurance_id, ins_owner from insurance)
              union(select insurance_id, boss from insurance)
              union(select insurance_id, repman from insurance)
              union(select insurance_id, crash_man from insurance)
              union(select insurance_id, address from insurance)
              union(select insurance_id, comm from insurance)");
  $sql2->execute();
  if($sql2->rowCount()>0)
  {
      $i=0;
         while($row = $sql2->fetch())
         {$output[$i] = array( "value" => $row["ins_name"], "data" => $row["insurance_id"]);      $i++ ;}
    }
    else { $output[0]= 'لا يوجد شركة بهذا الاسم';}
    // search by any number phone fax id licenes
    $number_out = array();
      $sql3 =$db->prepare ("SELECT insurance_id , boss_jawal from insurance
                  union(select insurance_id, repjawal from insurance)
                  union(select insurance_id, repjawal2 from insurance)
                  union(select insurance_id, crash_jawal from insurance)
                  union(select insurance_id, crash_jawal2 from insurance)
                  union(select insurance_id, fax from insurance)
                  union(select insurance_id, phone from insurance)");
        $sql3->execute();
     if($sql3->rowCount()>0)
        {
          $d=0;
             while($row = $sql3->fetch())
             {$number_out[$d] = array( "value" => $row["boss_jawal"], "data" => $row["insurance_id"]);      $d++ ;}
        }
        else { $number_out[0]= 'هذا الرقم غير موجود بالشركات';}
?>
<script>
$(document).ready(function(){
  var arr=  JSON.parse('<?php echo json_encode($output) ; ?>');

  $('#tt').autocomplete({
	 lookup: arr,
   maxHeight : 200,
   onSelect: function(suggestion) {$('#v5').attr("href", "a/ins_update.php?id="+(suggestion.data)).show();},
  //  onHint: function (hint) {$('#supp_name_x').val(hint);},$.cookie('ddy',tt);
    onInvalidateSelection: function() {$('#supp_val').html('You selected: none');}
  })
    var numm=  JSON.parse('<?php echo json_encode($number_out) ; ?>');
$('#nn').autocomplete({
 lookup: numm,
 maxHeight : 200,
 onSelect: function(suggestion) {$('#v5').attr("href", "a/ins_update.php?id="+(suggestion.data)).show();},
//  onHint: function (hint) {$('#supp_name_x').val(hint);},
//  onInvalidateSelection: function() {$('#supp_val').html('You selected: none');}
})
})

</script>
