<!DOCTYPE html>
<html>
<head>
	<title>sms</title>
	<meta charset="utf-8">
  
  
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>


<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">


<script type="text/javascript" src="https://unpkg.com/xlsx@0.15.1/dist/xlsx.full.min.js"></script>
  
  <script src="https://cdn.jsdelivr.net/npm/table-to-json@1.0.0/lib/jquery.tabletojson.min.js" integrity="sha256-H8xrCe0tZFi/C2CgxkmiGksqVaxhW0PFcUKZJZo1yNU=" crossorigin="anonymous"></script>
  

  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
 
<!-- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">         -->
  <link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">  
  <!-- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script> -->



<style>

.topnav {
  overflow: hidden;
  background-color: #333;
}

.topnav a {
  float: left;
  color: #f2f2f2;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  font-size: 17px;
}

.topnav a:hover {
  background-color: #ddd;
  color: black;
}

.topnav a.active {
  background-color: #4CAF50;
  color: white;
}

#sms-table th {
  font-size: 16px;
  background: purple;
  color: white;
  position: sticky;
  top: 0; /* Don't forget this, required for the stickiness */
  box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.4);
}
.container3{
  margin-top: 20px;
  background: #fafaf7;
  /* height: 130px; */
  padding: 14px 16px;
}

.container1{
  margin-top: 20px;
  background: #ebebeb;
  /* height: 130px; */
  padding: 14px 16px;
}
.btn{
  width:100%;
  margin-top:20px;
}



textarea#smstxt_area {
	width:100%;
	box-sizing:border-box;
	/* direction:rtl; */
	display:block;
	max-width:100%;
	line-height:1.5;
	padding:15px 15px 30px;
	border-radius:3px;
	border:1px solid #F7E98D;
	font:13px Tahoma, cursive;
	transition:box-shadow 0.5s ease;
	box-shadow:0 4px 6px rgba(0,0,0,0.1);
	font-smoothing:subpixel-antialiased;
	/* background:linear-gradient(#F9EFAF, #F7E98D);
	background:-o-linear-gradient(#F9EFAF, #F7E98D);
	background:-ms-linear-gradient(#F9EFAF, #F7E98D);
	background:-moz-linear-gradient(#F9EFAF, #F7E98D);
	background:-webkit-linear-gradient(#F9EFAF, #F7E98D); */
}

#tbselectdata1 th {
  background: purple;
  color: white;
  position: sticky;
  top: 0; /* Don't forget this, required for the stickiness */
  box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.4);
}
td { 
		font-size: 12px;
            font-weight: normal; 
            height: 1vw; 
        } 
</style>




</head>
  <body style="background-color: #ebebeb">
  <div class="topnav">
  
  <a  href="https://easyaccount-bpatcsc.easytechsolution.org/welcome.php">Home</a>
  <!-- <a  href="http://localhost/easyaccount-gchsc/welcome.php">Home</a> -->
  <a class="active" href="sms.php">Send SMS</a>
  </div>


<div class="container-fluid" style="margin-top: 10px; background-color: #859bed;">

                <h2 class="text-center"> SMS Panel </h2>
                <!-- http://api.greenweb.com.bd/g_api.php?token=d28c64966d30bb80787a063d678a85bc&balance&expiry&rate&tokensms&totalsms -->
                      <a class="btn btn-info" href="http://api.greenweb.com.bd/g_api.php?token=d28c64966d30bb80787a063d678a85bc&balance&expiry&rate&tokensms&totalsms" role="button">Check Balance</a>
               
                      <!-- <a class="btn btn-info" href="http://api.greenweb.com.bd/g_api.php?token=d28c64966d30bb80787a063d678a85bc&balance&expiry&rate&tokensms&totalsms"role="button">Check Balance</a> -->

               


                      <!-- #c0edd9 -->
    
    <div class="row">

              <div id="classname-container" class="col-md-4" style="margin-top:20px; margin-bottom:20px; background-color:#ffffff ; padding: 0px 50px;">
              
                  
                    <form id="formSubmit">
                      <!-- <div class="form-group">
                        <input type="text" class="form-control" name="name" id="name" placeholder="Student Name"> 
                      </div> -->


                      
                                            
<p  align="center">
<h5>Select Class</h5>
  <div class="btn-group" role="group" style="width:100%;" aria-label="Basic radio toggle button group">
  <input type="radio" class="btn-check" name="btnradio" value="1" id="addclass" autocomplete="off" > 
  <label class="btn btn-outline-primary" for="addclass">General SMS</label>

  <input type="radio" class="btn-check" name="btnradio" value="2" id="add_absent" autocomplete="off">
  <label class="btn btn-outline-danger" for="add_absent">Absent SMS</label>

  <input type="radio" class="btn-check" name="btnradio" value="3" id="addaccessclass" autocomplete="off">
  <label class="btn btn-outline-primary" for="addaccessclass">Access SMS</label>

  <!-- <input type="radio" class="btn-check" name="btnradio" value="4" id="edit_fees_item" autocomplete="off" >
  <label class="btn btn-outline-danger" for="edit_fees_item">Edit Fees Item</label>

  <input type="radio" class="btn-check" name="btnradio" value="5" id="edit_class_list" autocomplete="off">
  <label class="btn btn-outline-danger" for="edit_class_list">Edit Class</label> -->

  <!-- <input type="radio" class="btn-check" name="btnradio" value="6" id="btnradio3" autocomplete="off">
  <label class="btn btn-outline-primary" for="btnradio3">Radio 6</label> -->

</div>

                      <!-- <button type="submit" id="addclass" class="btn btn-success" style="width:100%;">Add Student</button>
                      <button type="submit" id="addaccessclass" class="btn btn-primary" style="width:100%;">Add Access</button>

                      <button type="submit" id="addabsent" class="btn btn-danger" style="width:45%;">Add Absent</button></br> -->
                       </p>
                       <p  align="left">
                                           
                       <!-- <button type="submit" id="addaccessclass" class="btn btn-primary" style="width:100%;">Add Access</button> -->
                       <button type="submit" id="addemail" class="btn btn-primary" style="width:45%;">Add Email</button></br>
                       </p>
                      
                      
                      
                        <label class="check-label" style="color:red;">
                          <input type="checkbox" id="all-check"  class="check-all" value="all" >  SELECT ALL
                        </label>
                      

                      <div id="totalclass" >


                      <!-- <div class="form-check">
                        <label class="form-check-label" style="color:blue;">
                          <input type="checkbox" id="class-name" class="form-check-input" value="102"> TEACHER SCHOOL
                        </label>
                      </div>
                      
                      <div class="form-check">
                        <label class="form-check-label"style="color:blue;">
                          <input type="checkbox" id="class-name" class="form-check-input" value="101"> TEACHER COLLEGE
                        </label>
                      </div>
                  
                      <div class="form-check">
                        <label class="form-check-label"style="color:blue;">
                          <input type="checkbox" id="class-name" class="form-check-input" value="103"> STAFF
                        </label>
                      </div> -->


                      </div>
                    </form>
                </div>




      <div class="col-md-5" style="margin-top:20px; margin-bottom:20px; background-color:  #faf2c8; ">
       

        <form id="formshowdata">
          <div id="showsmsData">
            <table id="sms-table" class="table table-striped table-responsive"   border="0" cellspacing="0" 
              cellpadding="5px" style="height: 500px; overflow: auto; font-size: 14px; width: 100%;  margin: 0 auto;">
              <thead>

                    <tr>
                          <th width="5%"><input type="checkbox" id="allCheck" class="checkbox_sms" value="" ></th>
                          <th style="text-align:center;" width="10%">ID</th>
                            <th style="text-align:center;" width="45%" >Name</th>
                            <th style="text-align:center;" width="15%">Class</th>
                            <th id="th-mobile" style="text-align:center;" width="20%">Mobile</th>
                            <th style="text-align:center" width="5%">S/L</th>
                    </tr>
                <tbody></tbody>
              </thead>    

            </table>
          </div>
                
        </form>
                  <div style="float:right;">
                      
                      <button type="button" class="btn btn-outline-danger" id="download_xls">XL Download</button>
                  </div> 
        
        <center>
        <div id="smsreprt" style="font-size: 12px; margin-top:40px;"></div>
                      <div id="error-message"></div>
                      <div id="success-message"></div> 

    </center>
      </div> 




      <div class="col-md-3" style="margin-top:20px; margin-bottom:20px; background-color:  #facdf8; ">
              

<div class="row">
<form id="smsform" method="post" enctype="multipart/form-data">
              <div class="admitbtn" style="width:100%; margin-top:0px; background: #fafaf7; border: 2px outset red; height:100%; padding: 14px 16px;"> 
              
                      <!-- <p  align="left"> -->
                      <div id="email-id">
                      <label for="emailtxt">Subject:</label><br>
                      
                      <input type="text" id="emailsubject" name="emailsubject" placeholder="Write Subject.." style="height:35px; width:260px;"><br><br>
                      <!-- <label>Attachment: <input type="file" id="attachment" name="attachment" /></label>  -->

                      <input id="attachment" type="file"  name="image" multiple/>
                      
                      
                            <div id="preview"><img id="img_view" src="filled.png" /></div></br>

                            <div id="uploadimage"><input id="uploadfile" class="btn btn-success" type="submit" value="Upload"></div>
                     
                      
                      <div id="err"></div>
                      
                        </div>

      <div style="width:100%;">                  
                        Template:
  <input type="radio" class="buttoncheck" name="tempsms"  value="absent">Absent
  <input type="radio" class="buttoncheck" name="tempsms" value="link">Link
  <input type="radio" class="buttoncheck" name="tempsms" value="mistake">Mistake
  <input type="radio" class="buttoncheck" name="tempsms" value="examabs">Exam Abs  

  <br>
                        <!-- <label for="smstxt">SMS:</label><br> -->
                          <textarea id="smstxt"  name="smstxt" oninput="smsCount()" placeholder="Write SMS.." style="height:130px; width:100%;"></textarea>
                          <span id="demo" >0</span> Characters
                      <!---<button type="submit" class="btn btn-primary" name="checkbal" onclick="return balanceConfirm();"/ >Check Balance</button>-->
                     
                      <button type="submit" id="sndemail" class="btn btn-success" name="sendsms" style="margin-left:50px;" >Send Email</button>
                      <button type="submit" id="sndaccesscode" class="btn btn-primary" name="sendaccesscode" style="margin-left:0px;" >Send Access</button>
                      <button type="submit" id="sndsms" class="btn btn-success" name="sendsms" style="margin-left:0px;" >Send SMS</button>
                       <!-- </p> -->
                      
</div>
                      <!-- <div class="txtchar" id="demo"></div> -->
              
                      </form>
              </div>
              
              </div>         
              
              
              
              <div class="row" >
                <div class="container3" style="width:100%; margin-top:20px; background: #fafaf7; border: 2px outset red; height:100%;">
                <p><a href="assets/xl_sms_sample.xlsx">Download Sample Excel file</a></p>
                
                <form id="formupload_xlsx" method="post" enctype="multipart/form-data">

                <div class="custom-file mb-3" >
            
                  <input style="width:100%;" type="file" class="custom-file-input" id="xlfile" name="excel">
                  <label style="width:100%;" class="custom-file-label" for="xlfile">Choose xlsx file</label>
                  
                 
                </div>
                <input type="submit" id="uploadxl" class="btn btn-primary" name="submit" value="Upload">
                </form>
              </div>
              </div>
              


              
              <div class="row" >
              
              <div class="container1" style="width:100%; margin-top:40px; background: #fafaf7; border: 2px outset red; height:100%;">
              
              <p><a href="assets/xl_sms_sample.xlsx">Download Sample Dyanamic Excel</a></p>
                
              <form id="dynamicsms_xlsx" method="post" enctype="multipart/form-data">
                <div class="custom-file mb-3"  >
                <input style="width:100%;" type="file" class="custom-file-input" id="dynamicxlfile" name="dynamicexcel">
                  <label style="width:100%;" class="custom-file-label" for="dynamicxlfile">Choose xlsx file</label>
                   </div>
                  <input type="submit" id="uploaddynamicxl" class="btn btn-success" name="submit" value="Send dynamic sms">
                </form>
                
              </div>
              
              </div>
              


              <div class="row" >

              <div class="panel panel-default" style="width:100%; margin-top:40px; background: #fafaf7; border: 2px outset red; height:100%;">
<div class="panel-heading">
<h4 class="panel-title" align="center" style="margin-top:10px;">Result SMS</h4>
     <!-- <h3 class="panel-title">Enter Data</h3> -->
    </div>
    <div class="panel-body">
<form id="upload_form" name="upload_form" action="#" method="POST" enctype="multipart/form-data">







                  <div class="form-group" style="margin-top:0px;">
                    <!-- <label>Select Exam</label>              	 -->
                    <select tabindex="1" id="exam_name" name="exam_name" class="form-control" onChange="resetAll();" required>
                    <option value="">--Select Exam--</option>
                    <?php
                    include 'config-result.php';
                    $sql = "SELECT exam_code,exam_name FROM examination_name Order by exam_code ASC";
                        $query = mysqli_query($link, $sql);
                    $numRows = mysqli_num_rows($query);
                    if ($numRows > 0 ) {
                    while($row = mysqli_fetch_assoc($query)){
                        echo '<option value='.$row['exam_code'].'>'.$row['exam_name'].'</option>';
                    }
                    }
                    ?> 
                    </select>
                    </div>
                    <div class="form-group" >
                    <!-- <label>Select Exam Year</label>              	 -->
                    <select tabindex="2" id="exam_year" name="exam_year" class="form-control"  required>
                    <option value="">--Select Exam Year--</option>
                   
                    </select>
                    </div>
                    <div class="form-group" >
                    <!-- <label>Select Class</label>              	 -->
                    <select tabindex="3" id="class_name" name="class_name" class="form-control" onChange="fetchGroup();" required>
                    <option value="">--Select Class--</option>
                    <?php
                    include 'config-result.php';
                    $sql = "SELECT class_id,st_class FROM class_name Order by class_id ASC";
                        $query = mysqli_query($link, $sql);
                    $numRows = mysqli_num_rows($query);
                    if ($numRows > 0 ) {
                    while($row = mysqli_fetch_assoc($query)){
                        echo '<option value='.$row['class_id'].'>'.$row['st_class'].'</option>';
                    }
                    }
                    ?> 
                    </select>
                    </div>

                    <div class="form-group" >
                    <!-- <label>Select Group</label>              	 -->
                    <select tabindex="4" id="group_name" name="group_name" class="form-control"  required>
                    <option value="">--Select Group--</option>
                   
                    </select>
                    </div>


                  
                  <div class="form-group" >
                    <!-- <label>Select Option</label>              	 -->
                    <select tabindex="8" id="opt_name" name="opt_name" class="form-control"  required>
                    <option value="">--Select Option--</option>
                    <option value="All">All</option>
                    <option value="Pass">Pass</option>
                    <option value="Fail">Fail</option>
                    <option value="Whld">Whld</option>
                    </select>
                    </div>

                  <div class="form-group" >
                   <button type="button" style="margin-top:0px;" name="add_result_student" id="add_result_student" class="btn btn-primary">Add Student</button>
                   <!-- <span id="pls_wait" class="text-danger"></span> -->
                 </div>

                 <div class="form-group" >
                   <button type="button" style="margin-top:0px;" name="add_result" id="add_result" class="btn btn-primary">Add Result</button>
                   <!-- <span id="pls_wait" class="text-danger"></span> -->
                 </div>

                 <div class="form-group" >
                   <button type="button" style="margin-top:0px;" name="send_result_sms" id="send_result_sms" class="btn btn-success">Send Result</button>
                   <!-- <span id="pls_wait" class="text-danger"></span> -->
                 </div>


                 </form>
  </div>
</div>

</div>





<div class="row" >
              
              <div class="container1" style="width:100%; margin-top:40px; background: #fafaf7; border: 2px outset red; height:100%;">
              
              <p><a href="assets/id_xl_sms_sample.xlsx">Download Sample ID Excel</a></p>
                
              <form id="student_id_xlsx" method="post" enctype="multipart/form-data">
                <div class="custom-file mb-3"  >
                <input style="width:100%;" type="file" class="custom-file-input" id="idxlfile" name="idexcel">
                  <label style="width:100%;" class="custom-file-label" for="idxlfile">Choose xlsx file</label>
                   </div>
                  <input type="submit" id="student_id_xls" class="btn btn-success" name="submit" value="Add Id sms">
                </form>
                
              </div>
              
              </div>









              <div class="row" >

              <div class="panel panel-default" style="width:100%; margin-top:40px; background: #fafaf7; border: 2px outset red; height:100%;">
<div class="panel-heading">
<h4 class="panel-title" align="center" style="margin-top:10px;">Fees SMS</h4>
     <!-- <h3 class="panel-title">Enter Data</h3> -->
    </div>
    <div class="panel-body">
<form id="upload_form" name="upload_form" action="#" method="POST" enctype="multipart/form-data">

<div class="form-group" >
<div class="table-responsive" id="table-data" style="height: 300px; width : 100%; overflow: auto;">
                <!-- <div class="table-responsive" style="height: 200px; width : 115%; overflow: auto;" >  -->
                <!-- <div class="table-responsive" style="height: 200px; width : 115%; overflow: auto;"> -->
                    <table class="table table-striped" id="tbselectdata1" style="width : 100%;">
                        <thead  id="thd1">
                     
                            <tr>
                            <th ><input type="checkbox" class="checkedAll" id="checkbox_items"></th>
                            <th width="15%">S/L</th>
                            <th >Items</th>
                             <th >id</th>
                            
                            </tr>
                        </thead>
                        <tbody id="tbdy1" ></tbody>
                    </table>
    <!-- </div> -->
                    
  </div>      
  </div>    

  <div class="form-group" >
<!-- <div class="form-inline" style="border: ;"> -->
<label id="lb_to_month"  style="padding:0px 0px 0px 10px;">To Month</label>
  <div id="div_to_month" class="input-group  col-sm-12" style="border: ;" >
  
    <select class="form-control" id="month_to" name="month_t">
     
    </select>
   
    <select class="form-control" id="year_to" name="year_to">
     
    </select>
  </div>
  </div>
  <div class="form-group" >
  <div id="div_st_class" class="input-group  col-sm-12" style="border: ;" >
  
  <select class="form-select" multiple aria-label="multiple select example" id="st_class" name="st_class">
   
  </select>
   
  </div>
  </div>

  <div class="form-group" >     
  <textarea id="datetxt"  name="datetxt" class="form-control"  placeholder="Write Fees Collection From Date to Date.." style="height:70px; width:100%;"></textarea>
  </div>
                    
                    
                    
                  <div class="form-group" >
                   <button type="button" style="margin-top:0px;" name="add_fees" id="add_fees" class="btn btn-primary">Add Fees</button>
                   <!-- <span id="pls_wait" class="text-danger"></span> -->
                 </div>

                 <div class="form-group" >
                   <button type="button" style="margin-top:0px;" name="send_fees_sms" id="send_fees_sms" class="btn btn-success">Send Fees</button>
                   <!-- <span id="pls_wait" class="text-danger"></span> -->
                 </div>


                 </form>
  </div>
</div>

</div>







                      

      </div> 




    </div>

   
    



</div>



<!---jQuery ajax Insert multiple checkbox value --->
<script type="text/javascript">
  $(document).ready(function(){



    $("#sndsms").show();
    $("#sndaccesscode").hide();
    $("#sndemail").hide();
    $("#email-id").hide();
   

/// class open from database
    function loadClass(){
       		$.ajax({
  			url : "load-totalclass.php",
  			type : "POST",
  			data: {},
  			success : function(result){
  				//alert(data);
  					//$("#class-box").html(data);
  			//$("#totalclass").append(result);
  			$("#totalclass").html(result);
         			}
  		});
  	}

    loadClass();








    $(document).on('click', '#sms-table td.st_absent', function(){
//$('#tbselectdata2 td').click(function(){
  //alert('yes');
    //$(this).attr("contenteditable");
    $(this).attr('contentEditable', true);
     $(this).closest('tr').find("td:eq(0)").attr('contentEditable', false);
     //$(this).closest('tr td.checkboxsms').prop('checked', true);
     
     //$(this).closest('tr td#checkAll').prop('checked', true);
     $(this).closest('tr').find('td .checkboxsms').prop('checked', true);
    // $(this).closest('tr').find("td.col1").attr('contentEditable', false);
    // $(this).closest('tr').find("td.col2").attr('contentEditable', false);
    // $(this).closest('tr').find("td.col3").attr('contentEditable', false);
    $(this).focus();
    //.closest('tr').find("td:eq(2)")
});









/// show data class wise for sms

$(document).on('click', '#addclass', function(){
//$('#addclass').click(function(e) {

    //$("#formSubmit").on("submit",function(e){
         // e.preventDefault();
          //var name = $("#name").val();
          var studentgroup = prompt("Please enter Group;A for All, S for Science, H for Humanities, B for BS", "A");
          var classname = [];
          
          $(".form-check-input").each(function(){
              if ($(this).is(":checked")) {
                classname.push($(this).val()
                
                );
              }
          });
/* var class_name="";
classname.forEach(function(item) {
  class_name=class_name + "'" +item+ "',"
    // do something with `item`
});

classname=class_name.slice(0,-1); */
          //console.log(classname);
          //console.log(classname_full);
           //alert(classname[0]);
 //classname = classname.toString(); // toString function convert array to string
 //console.log(classname);
 //alert(classname);
          
          if (classname !=="" && classname.length > 0) {
            
            $("#sndsms").show();
        $("#sndaccesscode").hide();
        $("#sndemail").hide();
        $("#email-id").hide();
        $('#th-mobile').html('Mobile');
            $.ajax({
              url : "load-student-smsdata.php",
              type: "POST",
              cache: false,
              data : {classname:classname,studentgroup:studentgroup},
             
              success:function(result){
                //alert(result);

                //console.log(result);
                 $("#sms-table tbody").html(result);
                 $("#smsreprt").html("");
                
              }
            });
          }else{
            alert("Pls Select Class!");
          }
      });
   


      $('#add_absent').click(function() {

//$("#formSubmit").on("submit",function(e){
      //e.preventDefault();
      //var name = $("#name").val();
      var studentgroup = prompt("Please enter Group;A for All, S for Science, H for Humanities, B for BS", "A");
      var classname = [];
      $(".form-check-input").each(function(){
          if ($(this).is(":checked")) {
            classname.push($(this).val());
          }
      });
       //alert(classname[0]);
//classname = classname.toString(); // toString function convert array to string
      //alert(classname);
      
      if (classname !=="" && classname.length > 0) {
        
        $("#sndsms").show();
    $("#sndaccesscode").hide();
    $("#sndemail").hide();
    $("#email-id").hide();
    $('#th-mobile').html('Mobile');
        $.ajax({
          url : "load-student-smsdata.php",
          type: "POST",
          cache: false,
          data : {classname:classname,studentgroup:studentgroup},
         
          success:function(result){
            //alert(result);
            $("#sms-table tbody").html(result);
            $("#smsreprt").html("");
            
          }
        });
      }else{
        alert("Pls Select Class!");
      }
  });




/// show email data class wise for email

$('#addemail').click(function(e) {

//$("#formSubmit").on("submit",function(e){
      e.preventDefault();
      //var name = $("#name").val();
      var classname = [];
      $(".form-check-input").each(function(){
          if ($(this).is(":checked")) {
            classname.push($(this).val());
          }
      });
//alert(classname[0]);
classname = classname.toString(); // toString function convert array to string
      //alert(classname);
      
      if (classname !=="" && classname.length > 0) {

        $("#sndsms").hide();
        $("#sndaccesscode").hide();
        $("#sndemail").show();
        $("#email-id").show();
        $('#th-mobile').html('Email');
        $.ajax({
          url : "load-student-emaildata.php",
          type: "POST",
          cache: false,
          data : {classname:classname},
         
          success:function(result){
            //alert(result);
            $("#sms-table tbody").html(result);
            $("#attachment").val('');
            //$("#preview").val('');
            $("#err").html('');
            $("#img_view").attr("src","filled.png");
            $("#smsreprt").html("");
          }
        });
      }else{
        alert("Pls Select Class!");
      }
  });












/// add access classs student

      $('#addaccessclass').click(function() {

    //$("#formSubmit").on("submit",function(e){
     // e.preventDefault();


      var studentgroup = prompt("Please enter Group;A for All, S for Science, H for Humanities, B for BS", "A");
          

          //var name = $("#name").val();
          var classname = [];
          $(".form-check-input").each(function(){
              if ($(this).is(":checked")) {
                classname.push($(this).val());
              }
          });
 //alert(classname[0]);
 //classname = classname.toString(); // toString function convert array to string
          //alert(classname);
          
          if (classname !=="" && classname.length > 0) {

            $("#sndsms").hide();
        $("#sndaccesscode").show();
        $("#sndemail").hide();
        $("#email-id").hide();
        $('#th-mobile').html('Mobile');
            $.ajax({
              url : "load-studentdata-access.php",
              type: "POST",
              cache: false,
              data : {classname:classname,studentgroup:studentgroup},
             
              success:function(result){
                //alert(result);
                $("#sms-table tbody").html(result);
                $("#smsreprt").html("");

              }
            });
          }else{
            alert("Pls Select Class!");
          }
      });





/// show absent data class wise for sms

$('#addabsent').click(function(e) {

//$("#formSubmit").on("submit",function(e){
      e.preventDefault();
      //var name = $("#name").val();
      var classname = [];
      $(".form-check-input").each(function(){
          if ($(this).is(":checked")) {
            classname.push($(this).val());
          }
      });
//alert(classname[0]);
classname = classname.toString(); // toString function convert array to string
      //alert(classname);
      
      if (classname !=="" && classname.length > 0) {
        $("#sndsms").show();
        $("#sndaccesscode").hide();
        $("#sndemail").hide();
        $("#email-id").hide();
        $('#th-mobile').html('Mobile');
        $.ajax({
          url : "load-absent-smsdata.php",
          type: "POST",
          cache: false,
          data : {classname:classname},
         
          success:function(result){
            //alert(result);
            $("#sms-table tbody").html(result);
            $("#smsreprt").html("");

          }
        });
      }else{
        alert("Pls Select Class!");
      }
  });









/// show data class wise for sms

$(document).on('click', '#add_result_student', function(){
//$('#addclass').click(function(e) {

    //$("#formSubmit").on("submit",function(e){
         // e.preventDefault();
          //var name = $("#name").val();

          var examName= $("#exam_name").val();
  var className= $("#class_name").val();
  var groupName= $("#group_name").val();
    var examYear= $("#exam_year").val();
var optionName=$("#opt_name").val();
if (examName=="" || className=="" || groupName=="" || examYear=="" || optionName==""){
alert('Pls Select All Filed!')
return false;
}

           
            $("#sndsms").show();
        $("#sndaccesscode").hide();
        $("#sndemail").hide();
        $("#email-id").hide();
        $('#th-mobile').html('Mobile');
            $.ajax({
              url : "load-result-smsdata.php",
              type: "POST",
              cache: false,
              data : {examName : examName, className : className, groupName : groupName,examYear:examYear,optionName:optionName},
             
              success:function(result){
                //alert(result);

                //console.log(result);
                 $("#sms-table tbody").html(result);
                 $("#smsreprt").html("");
                
              }
            });
          
      });
   






/// show data class wise for sms

$(document).on('click', '#add_result', function(){
//$('#addclass').click(function(e) {

    //$("#formSubmit").on("submit",function(e){
         // e.preventDefault();
          //var name = $("#name").val();

          var examName= $("#exam_name").val();
          var exam_name= $('#exam_name option:selected').text();
  var className= $("#class_name").val();
  var groupName= $("#group_name").val();
    var examYear= $("#exam_year").val();
var optionName=$("#opt_name").val();
if (examName=="" || className=="" || groupName=="" || examYear=="" || optionName==""){
alert('Pls Select All Filed!')
return false;
}

           
            $("#sndsms").show();
        $("#sndaccesscode").hide();
        $("#sndemail").hide();
        $("#email-id").hide();
        $('#th-mobile').html('Mobile');
            $.ajax({
              url : "load-result-sms.php",
              type: "POST",
              cache: false,
              data : {examName : examName, className : className, groupName : groupName,examYear:examYear,optionName:optionName,exam_name:exam_name},
             
              success:function(result){
                //alert(result);

                //console.log(result);
                
                 $("#sms-table tbody").html(result);
                 $("#smsreprt").html("");
                 //console.log($("#checkAll").data('txtsms'));
              }
            });
          
      });
   


/// send result sms
      $(document).on('click', '#send_result_sms', function(){

        var txt_sms=[];
  $('#sms-table .checkboxsms:checked').each(function(){
    txt_sms.push($(this).data('txtsms'));
    });

    var st_mobile=[];
  $('#sms-table .checkboxsms:checked').each(function(){
    st_mobile.push($(this).data('st_mobile'));
    });
    if (txt_sms.length==0 || st_mobile.length==0){
alert('Pls Check Some ID!')
return false;
}
    //console.log(txt_sms);
    //console.log(st_mobile);

        $.ajax({
             url : "send_result_sms.php",
             type: "POST",
             cache: false,
             data : {st_mobile : st_mobile, txt_sms : txt_sms},
            
             success:function(result){
               //alert(result);
               $("#smsreprt").html(result);
               $(".checkboxsms").prop("checked", false);

             }
           });

      });

      










                  // Insert New Records from excel

                  
    $('#formupload_xlsx').on("submit", function(e){  
    //$("#uploadxl").on("click",function(e){
      e.preventDefault();
            var fname = $('input[name="excel"]').val();
      
      if(fname == "" ){
      alert("Pls select xlsx file!");
      }else{
        //alert(fname);
        $.ajax({
          url: "load_xltohtmltable.php",
                   method:"POST",  
                     data:new FormData(this),  
                     contentType:false,          // The content type used when sending data to the server.  
                     cache:false,                // To unable request pages to be cached  
                     processData:false,
          success : function(result){
           // $("#sms-table tbody").html(result);
            //$("#success-message").html(result).slideDown();
            if(result !== "0"){
              //loadTable();
              //$("#addForm").trigger("reset");
                $("#sms-table tbody").html(result);
              $("#success-message").html("Total Rows Inserted Successfully.").slideDown();
              $("#error-message").slideUp();
            }else{
              $("#error-message").html("Can't Save Record.").slideDown();
              $("#success-message").slideUp();
            }

          }
        });
      }

    });






    /// from only id send sms
    $('#student_id_xlsx').on("submit", function(e){  
    //$("#uploadxl").on("click",function(e){
      e.preventDefault();
            var fname = $('input[name="idexcel"]').val();
      
      if(fname == "" ){
      alert("Pls select xlsx file!");
      }else{
        //alert(fname);
        $.ajax({
          url: "load_xltohtmltable_from_id.php",
                   method:"POST",  
                     data:new FormData(this),  
                     contentType:false,          // The content type used when sending data to the server.  
                     cache:false,                // To unable request pages to be cached  
                     processData:false,
          success : function(result){
           // $("#sms-table tbody").html(result);
            //$("#success-message").html(result).slideDown();
            if(result !== "0"){
              //loadTable();
              //$("#addForm").trigger("reset");
                $("#sms-table tbody").html(result);
              $("#success-message").html("Total Rows Inserted Successfully.").slideDown();
              $("#error-message").slideUp();
            }else{
              $("#error-message").html("Can't Save Record.").slideDown();
              $("#success-message").slideUp();
            }

          }
        });
      }

    });













    // load inserted data
    function loadTable(){
       	$.ajax({
  			url : "load-insertedxlsx-data.php",
  			type : "POST",
  			data: {},
  			success : function(result){
  				//alert(data);
  					//$("#class-box").html(data);
            $("#sms-table tbody").html(result);
  			//$("#class-name").append(data);
         			}
  		});
  	}






// send sms 

$('#sndsms').click(function(e) {
  e.preventDefault();
 //var selectedcheckbox =$('input[name="selected_id"]').val();
 //var selectedcheckbox =$('#checkAll').val();
 
var smstext =$('#smstxt').val();

if ($('#add_absent').prop("checked")){
var data_update='1';
}else{
  var data_update='0';

}

/* var selectedcheckbox = [];
          $(".checkboxsms").each(function(){
              if ($(this).is(":checked")) {
                selectedcheckbox.push($(this).val());
              }
          });

 */
          var selectedcheckbox=[];
          $('.checkboxsms:checked').each(function(){
            selectedcheckbox.push($(this).closest('tr').find("td:eq(4)").text());
          }); 


          var st_id=[];
          $('.checkboxsms:checked').each(function(){
            st_id.push($(this).closest('tr').find("td:eq(1)").text());
          });  

 //alert(selectedcheckbox[0]);
 //var mobile_number = JSON.stringify(selectedcheckbox);
 var student_id = JSON.stringify(st_id);
 var cell_number = JSON.stringify(selectedcheckbox);
 selectedcheckbox = selectedcheckbox.toString(); // toString function convert array to string
 
 //console.log(st_id);
 //alert(selectedcheckbox);
//alert(smstext);
if (st_id.length<1){
  alert("Pls select student!");
  return false;
}

$.ajax({
              url : "send-sms.php",
              type: "POST",
              cache: false,
              data : {selectedcheckbox : selectedcheckbox, smstext : smstext,student_id:student_id,data_update:data_update,cell_number:cell_number},
             
              success:function(result){
                //alert(result);
                //console.log(result);
                //$("#smsreprt").html(result);
                var mobile_textarea='<textarea id="smstxt_area"  name="smstxt_area"  placeholder="" style="height:100%; width:100%;"></textarea>';
                $("#smsreprt").html(mobile_textarea);
                $('#smstxt_area').val(result);
                $("#smstxt_area").trigger("input");

                $(".checkboxsms").prop("checked", false);

              }
            });


});


//// texarea auto resize
$(document).on('input', '#smstxt_area', function () {
        $(this).outerHeight(38).outerHeight(this.scrollHeight); // 38 or '1em' -min-height
    }); 





// // send mail

$('#sndemail').click(function(e) {
  e.preventDefault();
//var selectedcheckbox =$('input[name="selected_id"]').val();
//var selectedcheckbox =$('#checkAll').val();

var smstext =$('#smstxt').val();
var mailsubject=$('#emailsubject').val();
var attachment =$('#attachment').val();
//var attachment = $('input[name="attachment"]').val();
var selectedcheckbox = [];
         $(".checkboxsms").each(function(){
             if ($(this).is(":checked")) {
               selectedcheckbox.push($(this).val());
             }
         });
//alert(selectedcheckbox[0]);
selectedcheckbox = selectedcheckbox.toString(); // toString function convert array to string


//alert(selectedcheckbox);
//alert(attachment);
$.ajax({
             url : "email.php",
             type: "POST",
             cache: false,
             data : {selectedcheckbox : selectedcheckbox, smstext : smstext, mailsubject : mailsubject, attachment : attachment},
            
             success:function(result){
               //alert(result);
               $("#preview").html(result);
               $("#attachment").val('');
              
             }
           });


});



////upload file for email

 $("#smsform").on('submit',(function(e) {
  e.preventDefault();
  //alert("Yes");
  $.ajax({
         url: "ajaxupload.php",
   type: "POST",
   data:  new FormData(this),
   contentType: false,
         cache: false,
   processData:false,
   beforeSend : function()
   {
    //$("#preview").fadeOut();
    $("#err").fadeOut();
   },
   success: function(data)
      {
    if(data=='invalid')
    {
     // invalid file format.
     $("#err").html("Invalid File !").fadeIn();
    }
    else
    {
     // view uploaded file.
     $("#preview").html(data).fadeIn();
     
     //$("#smsform")[0].reset(); 
    }
      },
     error: function(e) 
      {
    $("#err").html(e).fadeIn();
      }          
    });
 }));



// check radio button template sms
 $(function() {
        $('.buttoncheck').click(function () {
            var var_name = $("input[name='tempsms']:checked").val();
            var absentsms="";
            var today = new Date();
            var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
            if (var_name=="link"){
              absentsms="সম্মানিত সহকর্মী,\n\
আপনার আজকের জুম ক্লাশ লিঙ্ক সঠিকভাবে আপলোড হয়েছে কিনা তা পুনরায় যাচাইয়ের জন্য অনুরোধ করা হলো।\n\
bpatcsc\n"
+date;
              //alert(absentsms);
              $('#smstxt').val(absentsms);
            } else if(var_name=="mistake"){
              absentsms="সম্মানিত সহকর্মী,\n\
আপনার আজকের জুম ক্লাশ লিঙ্ক ভুল আছে। সঠিকটি আপলোড করুন। \n\
bpatcsc\n"
+date;
//alert(absentsms);
$('#smstxt').val(absentsms);

            }else if(var_name=="absent"){
              absentsms="আজ " + date +" তারিখ আপনার সন্তান অনুপস্থিত।\n\অনুঃ ফি ৩০ টাকা।\n\
bpatcsc";
//alert(absentsms);
$('#smstxt').val(absentsms);

            }else if(var_name=="examabs"){
             absentsms="আজকের  " + date +" পরীক্ষায় আপনার সন্তান অনুপস্থিত। বিষয়টি গুরুত্বপূর্ণ। আগামী পরীক্ষায় অংশগ্রহণ করতে আপনার সহযোগিতা কামনা করছি।\n\অধ্যক্ষ\n\
bpatcsc";
//alert(absentsms);
$('#smstxt').val(absentsms);

            }
            //$('#smstxt').val(var_name);
            
        });
    });





// send access code sms 

$('#sndaccesscode').click(function(e) {
  e.preventDefault();
//var selectedcheckbox =$('input[name="selected_id"]').val();
//var selectedcheckbox =$('#checkAll').val();

var smstext =$('#smstxt').val();


var selectedcheckbox = [];
         $(".checkboxsms").each(function(){
             if ($(this).is(":checked")) {
               selectedcheckbox.push($(this).val());
             }
         });
//alert(selectedcheckbox[0]);
selectedcheckbox = selectedcheckbox.toString(); // toString function convert array to string


 //alert(selectedcheckbox);
//alert(smstext);
$.ajax({
             url : "send_accesscode.php",
             type: "POST",
             cache: false,
             data : {selectedcheckbox : selectedcheckbox, smstext : smstext},
            
             success:function(result){
               //alert(result);
               $("#smsreprt").html(result);

             }
           });


});









// send dynamic sms 
$('#dynamicsms_xlsx').on("submit", function(e){  
//$('#dynamicsms').click(function(e){  
    //$("#uploadxl").on("click",function(e){
      e.preventDefault();
//alert('yes');
var fname = $('input[name="dynamicexcel"]').val();
      
      if(fname == "" ){
      alert("Pls select xlsx file!");
      }else{
$.ajax({
             url : "send-dynamicsms.php",
             type: "POST",
             data:new FormData(this),  
                     contentType:false,          // The content type used when sending data to the server.  
                     cache:false,                // To unable request pages to be cached  
                     processData:false,
          success : function(result){
               $("#smsreprt").html(result);

             }
           });

      }
});








/// All check class
$('.check-all').click(function() {

var _this = this;
$('#totalclass').find('.form-check-input').each(function() {
 
  if ($(_this).is(':checked')) {
    $(this).prop('checked', true);
  } else {
    $(this).prop('checked', false);
  }
});
});


/// multriple check student
      $('.checkbox_sms').click(function() {

var _this = this;
$('#showsmsData').find('.checkboxsms').each(function() {
 
  if ($(_this).is(':checked')) {
    $(this).prop('checked', true);
  } else {
    $(this).prop('checked', false);
  }
});
});




 // Add the following code if you want the name of the file appear on select
 $(".custom-file-input").on("change", function() {
                    var excel = $(this).val().split("\\").pop();
                    $(this).siblings(".custom-file-label").addClass("selected").html(excel);
                  });





  });




/// count sms character
function smsCount() {
  var x = document.getElementById("smstxt").value;
  document.getElementById("demo").innerHTML = x.length ;
}


function sentConfirm(){
    var result = confirm("Do you really want to Send SMS?");
    if(result){
        return true;
    }else{
        return false;
    }
}

function hidebutton(){
  $("#addabsent").hide();
  //$("#addaccessclass").hide();
  $("#addemail").hide();
}
hidebutton();




function resetAll() {
  
  $("#class_name").val("");
  $("#group_name").val("");
  $("#exam_year").val("");
  // $("#subject_name").val("");
  // //$("#subject_part").val("");
  // $("#marks_option").val("");
}





function fetchYear(){
var thisyear = new Date().getFullYear(); 
var htm='';
htm+='<option value='+(thisyear-1)+'>'+(thisyear-1)+'</option>';
htm+='<option value='+thisyear+'>'+thisyear+'</option>';
htm+='<option value='+(thisyear+1)+'>'+(thisyear+1)+'</option>';

$('#exam_year').append(htm);
}
fetchYear();



          function fetchGroup(){
 
 var className = $("#class_name").val();
 $('#group_name').html('');
 $('#group_name').html('<option>--Select Group--</option>');
 $.ajax({
   type:'post',
   url: 'group_name.php',
   data : {className : className},
   success : function(data){
     //alert (data);
      $('#group_name').html(data);
      //resetSome1();
      
   }

 })
}



$(document).on('click', '.checkbox_items', function(){

/// multriple check student
//$('.checkbox_items').click(function() {

var _this = this;
$('#table-data').find('.chk_box').each(function() {
 
  if ($(_this).is(':checked')) {
    $(this).prop('checked', true);
  } else {
    $(this).prop('checked', false);
  }
});
});



var flldall='';
 function fees_item_show(){
        //alert('yes');
     /*    $('#tbselectdata2 #tbdy2').html('');
        $('#div_main').hide();  
        $('#div_to_month').hide();
     $('#lb_to_month').hide();
        $('#div_st_group').hide();
        $('#view_student').hide();
        $('#send_item').hide(); */
 //alert("data");  
 $('#tbdy1').html('');
        $.ajax({
            url:"https://easyaccount-bpatcsc.easytechsolution.org/pre_defined_fees_list_fetch.php",
            method:"POST",
            dataType:"json",
            success:function(data){
                //console.log(data);
                //console.log(Object.keys(data[0]).length);
               
                flldall=data;
                //console.log(Object.keys(fldall[0])[37]);
              //alert(data);


                            var thd_htm='';

                            thd_htm='<tr><th ><input type="checkbox"  class="checkbox_items"></th>'
                            +'<th width="15%">S/L</th><th >Items</th><th >id</th></tr>';


                            $('#thd1').html(thd_htm);




                var html = '';

          

                for(var count = 0; count < data.length; count++)
                {
                    html += '<tr>';
                    var dtta='';
                    var jsnth=Object.keys(data[0]).length;
                    var srtlnth=jsnth/2;
                    
                    for(var k = srtlnth; k < jsnth; k++){
            var fld=Object.keys(data[0])[k];
            
            
            var dta='data-'+fld;
            var dtss= data[count][k-srtlnth];
            dtta+=dta+'="'+dtss+ '" ';
            
          }
          
                    html += '<td><input type="checkbox" id="'+data[count][0]+'" '+dtta+'class="chk_box"  /></td>';
                    html += '<td class="st_delete">'+data[count][0]+'</td>';
                    
                    for(var i = 1; i < Object.keys(data[0]).length/2; i++){
                  var cls='cls'+i;
                       var dttt=dtta + ' data-edit_id="'+cls+'" ';
                      html += '<td  class="'+cls+'"><a '+dttt+' style="color:blue"; href="#" id="edit_fees">'+data[count][i]+'</a></td>';
                      
                   
                       

                    }
                    html += '</tr>';                    
                    // html += '<td  ><button type="button" name="delete_btn" id="'+data[count][0]+'" class="btn btn-xs btn-danger btn_delete"><span class="glyphicon glyphicon-remove"></span></button></td></tr>';

                }
                 
                //$('#sms-table tbody').html(html);
                //console.log(html);
                $('#tbdy1').html(html);
                //$('#tbselectdata1 #048').closest('tr').find("td:eq(2)").text('PREVIOUS DUE');
                 $('#tbselectdata1 tr td:nth-child(4),#tbselectdata1 tr th:nth-child(4)').hide();
                // $('#tbselectdata2 tr td:nth-child(4),#tbselectdata2 tr th:nth-child(4)').hide();
            
    /* $("#month_to").prop("disabled",false);
    $("#year_to").prop("disabled",false);
    $("#st_class").prop("disabled",false); */
            }
        });
  


    };
  

    fees_item_show();



    var cts=0;
    $(document).on('click', '#edit_fees', function(event){
      event.preventDefault();
//alert('yes');
cts++;
var html = '';
          var dtta='';
          var jsnth=Object.keys(flldall[0]).length;
            var srtlnth=jsnth/2;
            //console.log(flldall[0]);
          for(var k = srtlnth; k < jsnth; k++){
            var fld=Object.keys(flldall[0])[k];
            var dta='data-'+fld;
            //var fldd="'"+fld+"'";
            //console.log(flldall[0]);

            var dtss= $(this).data(fld);
            //console.log(dtss);
            dtta+=dta+'="'+dtss+ '" ';
            //dtta+=dta+'='+$(this).data("'+fld+'") ';
            
          }

          var incr=1;
              var incrlast=1;
              var id_numm='s_l';


          
          
          html = '<td><input type="checkbox" id="'+$(this).data(id_numm)+'" '+dtta+'class="chk_box"  /></td>';
          var ncf=0;
        
          for(var j = srtlnth; j < jsnth; j++){
              var fld=Object.keys(flldall[0])[j];
              ncf++;
              if (j>=srtlnth+incr && j<=jsnth-incrlast){

                  var sl_data='cls'+(ncf-1)+cts;
                html += '<td style="background-color:#fffaeb"  class="'+sl_data+'">'+$(this).data(fld)+'</td>';   
                  
              }else{
                html += '<td >'+$(this).data(fld)+'</td>';   

              }

                     
                   
            }
            //html += '<td><button type="button" name="delete_btn" id="'+$(this).attr('id')+'" class="btn btn-xs btn-danger btn_delete"><span class="glyphicon glyphicon-remove"></span></button></td></tr>';

            $(this).closest('tr').html(html);
            
            //$('#tbselectdata1 tr td:nth-child(5),#tbselectdata1 tr th:nth-child(5)').hide();
            
            
            var sl_clas=$(this).data('edit_id')+cts;
            var sl_class='.'+sl_clas;
            
            //console.log(sl_class);
            //alert($(this).attr('class'));
            var sl_c=$(this).data(id_numm);
            var sl_id='#'+sl_c;
            //console.log(sl_c);
            $(sl_id).prop('checked', true);
            //$(sl_class).click();
            //$(sl_class).focus();
            $('#tbselectdata1 tr td:nth-child(4),#tbselectdata1 tr th:nth-child(4)').hide();
    });


   // add fees for sms
   
    $(document).on('click', '#add_fees', function(event){
      event.preventDefault();

      var fld_item=[];
      var item_name=[];
      //var st_class= $('#st_class option:selected').text();
var st_class=$('#st_class').val();
var toMonth=$('#month_to').val();
var toYear=$('#year_to').val();
var datetxt=$('#datetxt').val();
//console.log(st_class)

$('#tbselectdata1 .chk_box:checked').each(function(){
  item_name.push($(this).data('items'));
});  
$('#tbselectdata1 .chk_box:checked').each(function(){
  fld_item.push($(this).data('payments_list'));
}); 

//console.log(item_name);
//console.log(fld_item);

if (st_class.length=='0' || toMonth==''|| toYear==''|| item_name.length=='0'||st_class[0]==''|| fld_item.length=='0'|| datetxt.length=='0'){
alert('Pls Fill All!');
return;
}

$.ajax({
   url: "create-sms-fees.php",
   type: "POST",
   data : {st_class:st_class,toMonth:toMonth ,toYear:toYear,item_name:item_name,fld_item:fld_item,datetxt:datetxt},
   success: function(data) {
    //console.log(data);
    $("#sms-table tbody").html(data);
    
   }
  });




    });
    





/// send fees sms
$(document).on('click', '#send_fees_sms', function(){

var txt_sms=[];
$('#sms-table .checkboxsms:checked').each(function(){
txt_sms.push($(this).data('txtsms'));
});

var st_mobile=[];
$('#sms-table .checkboxsms:checked').each(function(){
st_mobile.push($(this).closest('tr').find('td.st_absent').text());
});


if (txt_sms.length==0 || st_mobile.length==0){
alert('Pls Check Some ID!')
return false;
}
//console.log(txt_sms);
//console.log(st_mobile);

$.ajax({
     url : "send_result_sms.php",
     type: "POST",
     cache: false,
     data : {st_mobile : st_mobile, txt_sms : txt_sms},
    
     success:function(result){
       //alert(result);
       $("#smsreprt").html(result);
       $(".checkboxsms").prop("checked", false);
     }
   });

});











//------month name----------------------
var html_month='';
const theMonths = ["January", "February", "March", "April", "May",
  "June", "July", "August", "September", "October", "November", "December"];
for (var z=0; z<12; z++) {
  //document.write(theMonths[z]);
  var month_name=theMonths[z].toUpperCase();
  html_month +='<option value="'+month_name+'">'+month_name+'</option>';
}


//$('#month_from').html('<option value="">Month</option>'+html_month);
$('#month_to').html('<option value="">Month</option>'+html_month);
//----------------------------------



//----------year----------------------
const d = new Date();
let year = d.getFullYear();
var html_year='';
for (var z=0; z<5; z++) {
  var year_name=year+z-3;
  html_year +='<option value="'+year_name+'">'+year_name+'</option>';
}

//$('#year_from').html('<option value="">Year</option>'+html_year);
$('#year_to').html('<option value="">Year</option>'+html_year);
//-----------------------------



let class_id=[];

function fetch_class_id(){
    
        $.ajax({
            url:"https://easyaccount-bpatcsc.easytechsolution.org/class_list_fetch.php",
            method:"POST",
            dataType:"json",
            success:function(data){
              class_id=data;
              /* console.log(class_id.length);
              console.log(class_id);
              console.log((class_id[0][1]).length);
              console.log(class_id[10][1]);
              console.log(Object.keys(data[0]).length); */

              var class_html='';
              class_html='<option value="" selected>--Select Class--</option>'
for(var m=0;m<class_id.length;m++){

    
class_html+='<option value="'+class_id[m][1] +'">'+class_id[m][1] + '</option >'

  

}

$('#st_class').html(class_html);
//console.log(class_html);

            }
        });
}
fetch_class_id();










$(document).ready(function() {
   var $chkboxes = $('#sms-table');
var $range = '#sms-table tbody';
var $first = false;
var $indexWrapp = 'tr';
var lastChecked = null;
var $checkboxes = 'input[type="checkbox"]';

$chkboxes.on('click',$checkboxes,function(e) {

    if ($first===false) {

        lastChecked = $(this).closest($indexWrapp).index();
        lastCheckedInput = $(this).prop('checked');
        $first=true;
        return;
    }

    if (e.shiftKey) {

        var start = lastChecked;
        var end =  $(this).closest($indexWrapp).index();

       $( $range+' '+$indexWrapp).each(function() {
          $currIndex=$(this).index();
          if( $currIndex>=start && $currIndex<=end ){
              $(this).find($checkboxes).prop('checked', lastCheckedInput);
          }

       })
    }

     lastCheckedInput = $(this).prop('checked');
     lastChecked = $(this).closest($indexWrapp).index();
});

});








$(document).on('click', '#download_xls', function(){
 //alert('yes');


 //$('#table-main .chk_box:not(:checked)').closest('tr').remove();

 var table = $('#sms-table').tableToJSON({
//ignoreColumns: removeCol //column 1,3,5,7 remove  

ignoreColumns: [0] //column 1,3,5,7 remove 


 });

//console.log(table);

var ws = XLSX.utils.json_to_sheet(table);

/* add to workbook */
var wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, "student_list");

/* generate an XLSX file */
XLSX.writeFile(wb, "student_list.xlsx");


});



</script>




  </body>
</html>