<?php require_once('../auth/auth.php'); ?>
<?php
   if(isset($_GET['getbrid'])){
      $getbrid= $_GET['getbrid'];
      $Getuser_query= mysqli_query($conn,"SELECT `brid`,`sms_api_key`, `sms_senderid`,sms_status  FROM branch
      WHERE  coid='$coid' AND brid='$getbrid' LIMIT 1 ") or die (mysqli_error($conn));
      $rowuid= mysqli_fetch_assoc($Getuser_query);
      $get_brid=$rowuid['brid'];
   }
?>
<section class="content">
   <div class="container-fluid">
      <div class="row">
         <div class="col-md-2"> </div>
         <div class="col-md-8">
            <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"><?php echo language(272); ?></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>

        <?php if (@$_GET['getbrid']) { ?>
               <form id="api_form" action="#" method="post" autocomplete="off">
                  <?php if(isset($_GET['getbrid'])){  ?>
                  <input type="hidden" name="new_api" id="new_api" value="<?php echo @$getbrid ;?>"/>
                  <?php } ?>
                  <div class="card-body">
                     <div class="col-md-12">
                        <div class="row">
                           <div class="col-md-12">
                              <div class="form-group">
                                 <label><?php echo language(276); ?> <b class="text-danger"> *</b></label>
                                 <input type="text" name="sms_api_key"  value="<?php echo @$rowuid['sms_api_key'];?>" class="form-control form-control-sm inputselect">
                              </div>
                           </div>
                           <div class="col-md-6">
                              <div class="form-group">
                                 <label><?php echo language(277); ?> <b class="text-danger"> *</b></label>
                                 <input type="text" name="sms_senderid"  value="<?php echo @$rowuid['sms_senderid']; ?>" class="form-control form-control-sm inputselect" >
                              </div>
                           </div>
                           
                           <div class="col-md-6">
                               <div class="form-group">
                                   <label><?php echo language(90);?>  </label>
                                 <select  name="sms_status" class="form-control select2" style="width: 100%;" required="true">
                                 	<option value="<?php echo $rowuid['sms_status']; ?>">
                                 	    <?php if ($rowuid['sms_status']==0) {
                                               echo  $currentMode= "Deactive";
                                                  }else if ($rowuid['sms_status']==1) {
                                                echo	$currentMode= "Active";
                                                 } ?> </option>
                                 	<option value="1">  <?php echo language(278);?>  </option>
                                 	<option value="0"> <?php echo language(279);?> </option>
                               
                                 </select>
                            </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"> <?php echo language(25);?></button>
                  </div>
                  </center>
               </form>
            <?php } ?>
               <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 class="table table-sm table-head-fixed text-nowrap table-hover table-bordered " style="overflow-x:auto;">
                     <thead>
                        <tr class="sticky-top">
                           <th class="text-center" style="width:5%;"><?php echo language(15);?></th>
                           <th class="text-center"><?php echo language(276); ?></th>
                           <th class="text-center"><?php echo language(277); ?></th>
                           <th class="text-center"><?php echo language(90);?> </th>


                           
                        </tr>
                     </thead>
                     <tbody class="actived">
                        <?php
                        $api_query= mysqli_query($conn,"SELECT `brid`,`sms_api_key`, `sms_senderid`,`sms_status` FROM branch WHERE  coid='$coid' ") or die (mysqli_error($conn));
                        $i=0;
                        while ($rowus= mysqli_fetch_array ($api_query) ){
                        $branchid  =$rowus['brid'];                  
                        ?>
             
                         <tr class="btn-outline-dark tr-hover delete_op<?php echo $rowar['ptid'];?>"  onclick="pagecall('../sms/sms_tamp_setting.php?getbrid='+'<?php echo $rowus['brid'];?>','#sms_view')">
    
                           <td class="text-center"><?php echo ++$i ?></td>
                           <td class="text-center"><?php echo $rowus['sms_api_key'];?></td>
                           <td class="text-center"><?php echo $rowus['sms_senderid'];?></td>   
                           <td class="text-center"><?php 
                              if ($rowus['sms_status']==1) {
                                echo  $status = 'Active';
                                } else {
                                 echo  $status = 'Deactive';
                                }
                             ?>
                             </td>

                           
                        </tr>
                        <?php } ?>
                     </tbody>
                  </table>
               </div>
            </div>
         </div>
         <div class="col-md-2"> </div>
      </div>
   </div>
</section>
<script>
$("select").select2();
$(document).ready(function() {
$('#api_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("../company_setup/branch_db.php",$(this).serialize(),function(data){
$('#api_form')[0].reset();
$('#save').prop('disabled', false);
$.post('../sms/sms_tamp_setting.php?running='+1,{},function(res){
$('#sms_view').html(res);
toastr.success(Showing, '<?php echo "Data Load Succefully " ?>');
});
});
});

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