<!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://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
  <script src="https://code.jquery.com/jquery-3.1.0.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);
}
.container{
  margin-top: 20px;
  background: #fafaf7;
  height: 130px;
}

.container1{
  margin-top: 20px;
  background: #ebebeb;
  height: 130px;
}
</style>




</head>
  <body style="background-color: #ebebeb">
  <div class="topnav">
  
  <a  href="zoom_link.php">Upload Zoom Link</a>
    <a href="access_code.php">Upload Access Code</a>
  <a href="student_list.php">Upload Student List</a>
  <a href="class_routine.php">Upload Class Routine</a>
  <a class="active" href="sms.php">Send SMS</a>
  <a href="adminlogout.php">Logout</a>
  <a href="#about">About</a>
</div>


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

                <h2 class="text-center"> SMS Panel</h2>
               
                      <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>
               
                
               


    
    
    <div class="row">
                  
              <div id="classname-container" class="col-md-3" style="margin-top:20px; margin-bottom:20px; background-color: #c0edd9;">
                  
                  
                    <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>
                      <button type="submit" id="addclass" class="btn btn-success" style="width:45%;">Add Student</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:45%;">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-6" 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: 13px; width: 100%;  margin: 0 auto;">'
              <thead>

                    <tr>
                          <th width="35px"><input type="checkbox" id="allCheck" class="checkbox_sms" value="" ></th>
                          <th style="text-align:center" width="45px">ID</th>
                            <th style="text-align:center" width="260px" >Name</th>
                            <th style="text-align:center" width="80px">Class</th>
                            <th id="th-mobile" style="text-align:center" width="100px">Mobile</th>
                            <th style="text-align:center" width="30px">S/L</th>
                    </tr>
                <tbody></tbody>
              </thead>    

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




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



              <div class="admitbtn"> 
              <form id="smsform" method="post" enctype="multipart/form-data">
                      <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>

                        
                        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  

  <br>
                        <label for="smstxt">SMS:</label><br>
                          <textarea id="smstxt" name="smstxt" oninput="smsCount()" placeholder="Write SMS.." style="height:130px; width:260px;"></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:50px;" >Send Access</button>
                      <button type="submit" id="sndsms" class="btn btn-success" name="sendsms" style="margin-left:45px;" >Send SMS</button>
                       </p>

                      <!-- <div class="txtchar" id="demo"></div> -->
              </form>
              
              </div>

              
              
              
              
              <div class="container">
                <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>
                  <input type="submit" id="uploadxl" class="btn btn-primary" name="submit" value="Upload">
                 
                </div>
                </form>
              </div>


              <div class="container1">
                <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:90%;" type="file" class="custom-file-input" id="dynamicxlfile" name="dynamicexcel">
                  <label style="width:90%;" class="custom-file-label" for="dynamicxlfile">Choose xlsx file</label>
                  <input type="submit" id="uploaddynamicxl" class="btn btn-success" name="submit" value="Send dynamic sms">
                  
                </div>
                </form>
              </div>






                      <div id="smsreprt" style="font-size: 12px;"></div>
                      <div id="error-message"></div>
                      <div id="success-message"></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();


/// show data class wise for sms

$('#addclass').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-student-smsdata.php",
              type: "POST",
              cache: false,
              data : {classname:classname},
             
              success:function(result){
                //alert(result);
                $("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);
            $("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(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").show();
        $("#sndemail").hide();
        $("#email-id").hide();
        $('#th-mobile').html('Mobile');
            $.ajax({
              url : "load-studentdata-access.php",
              type: "POST",
              cache: false,
              data : {classname:classname},
             
              success:function(result){
                //alert(result);
                $("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);
            $("tbody").html(result);
            $("#smsreprt").html("");

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






                  // 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){
           // $("tbody").html(result);
            //$("#success-message").html(result).slideDown();
            if(result !== "0"){
              //loadTable();
              //$("#addForm").trigger("reset");
                $("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);
            $("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();


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-sms.php",
              type: "POST",
              cache: false,
              data : {selectedcheckbox : selectedcheckbox, smstext : smstext},
             
              success:function(result){
                //alert(result);
                $("#smsreprt").html(result);

              }
            });


});



// // 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="Sommanito Ovivabok,\n\
Aj " + date +" tarikh Apnar Sontan Onupusthit. Bisoiti Udbegjonok.\n\Agami Class-e Tar Upsthiti Nishchit Korte Onurodh Kora Holo.\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;
    }
}

</script>




  </body>
</html>