<?php require_once('../auth/auth.php'); ?>
<?php
$get_acid=$_GET['acid'];
if(isset($_GET['acid'])){
   $stidquery= mysqli_query($conn,"SELECT `brid`,`ac_name`,`ac_number`,`balance` FROM accounts WHERE acid='$get_acid' LIMIT 1 ") or die (mysqli_error($conn));
  $rows= mysqli_fetch_assoc($stidquery);
   $ac_name  = $rows['ac_name'];
   $ac_number= $rows['ac_number'];
   $getbrid  = $rows['brid'];
   $balance= $rows['balance'];
}


 $branch_name=mysqli_fetch_assoc(mysqli_query($conn,"SELECT branch_name FROM branch WHERE  coid='$coid' AND brid='$getbrid' LIMIT 1 "))['branch_name'];
?>
<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">Singel SMS </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>Number <b class="text-danger"> *</b></label>
                <input type="number" name="send_number"  value="<?php echo @$ac_number ?>" 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>Select Business Mode</label>
                <select name="stid" id="stid_select"  class="form-control select2" style="width: 100%;" >
                  <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>SMS Body<b class="text-danger"> *</b></label>
                              						      <textarea name="sms_body"  id="smsshow" class="form-control form-control-sm inputselect" rows="2" > প্রিয় স্যার / ম্যাডাম, <?php echo $branch_name;?> এ আপনার <?php echo $balance;?> টাকা বাকি পড়েছে।  অনুগ্রহ করে যত শীঘ্রই সম্ভব পরিশোধ করুন। 
                              						      ইতি- মালিকপক্ষ   </textarea>

              </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 if (@$_GET['stid']) {echo 'update ';}else{echo 'Sent Sms';}?></button>
        <button type="reset" class="btn btn-secondary btn-xs">Reset</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>

