<?php require_once('../auth/auth.php'); ?>
<?php
if(isset($_GET['stid'])){
   $stid= $_GET['stid'];
   $stidquery= mysqli_query($conn,"SELECT `head`,`body` FROM sms_tamp WHERE stid='$stid' LIMIT 1 ") or die (mysqli_error($conn));
  $rows= mysqli_fetch_assoc($stidquery);
   $head=$rows['head'];
   $body=$rows['body'];
}
?>
<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"><?php echo language(269); ?> </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="singel_sms_form" action="#" method="post" autocomplete="off">
        <?php if(isset($_GET['stid'])){  ?>
        <input type="hidden" name="newtamp" id="newtamp" value="<?php echo @$stid ;?>"/>
        <?php }else{?>
        <input type="hidden" name="newtamp" id="newtamp" value="0"/>
        <?php } ?>
        <div class="card-body">
         <div class="col-md-12">
           <div class="row">
            <div class="col-md-6">
              <div class="form-group">
                <label> <?php echo language(111); ?> <b class="text-danger"> *</b></label>
                <input type="number" name="send_number"  value="<?php echo @$GSMNumber ?>" class="form-control form-control-sm inputselect"  style="text-align:center;" required="true">
              </div>
            </div>

             <div class="col-md-6">
              <div class="form-group">
                <label><?php echo language(273); ?></label>
                <select name="stid" id="stid_select"  class="form-control">
                  <option value=""></option>
                  <?php
                  $accat1= mysqli_query($conn,"SELECT stid,body FROM sms_tamp  WHERE coid='$coid'  ") or die (mysqli_error($conn));
                  while($acat1= mysqli_fetch_assoc($accat1)){   
                  echo '<option value='.$acat1["stid"].'>    '.$acat1["body"].'    </option>';
                  }  
                  ?>
                </select>
              </div>
            </div>

            <div class="col-md-12">
              <div class="form-group">
                <label> <?php echo language(274); ?><b class="text-danger"> *</b></label>
                <input type="text" name="sms_body" id="smsshow" value="<?php echo @$SMSText ?>" class="form-control form-control-sm inputselect" style="text-align:center;" required="true">
              </div>
            </div>

<script>// Event handler for text input
$('#smsshow').on('input', function() {
  // Getiing option based on input value and setting it as selected
  $('#stid_select option:contains(' + this.value + ')').eq(0).prop('selected', true);
});

// Event handler for select
$('#stid_select').change(function() {
  // Updating text input based on selected value
  $('#smsshow').val($('option:selected', this).text());
});</script>


          </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(132);?></button>
      </div>
    </center>
  </form>


</div>
</div>






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

<script>
 $(document).ready(function() {
$("select").select2();
   $('#singel_sms_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("../sms/sms_send_db.php",$(this).serialize(),function(data){
      $('#singel_sms_form')[0].reset();
      $('#save').prop('disabled', false);
      $.post('../sms/single_sms.php?running='+1,{},function(res){
       $('#sms_sview').html(res);
       toastr.success(Showing, '<?php echo "Data Load Succefully " ?>');
     }); 
    });
   });

    $('.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();
        }
      });
    });

  });
</script>

