<?php include("parent/callMe.php"); ?>
<?php  include("sessioncheck.php"); ?>
<?php

 
   $m->where("branch_id", $_SESSION['branch']);
   $sms_service = $m->get("edu_branch_config");

   $branch=$_SESSION['branch'];
   $date=date('Y-m-d');

 $sql = "SELECT * FROM  eduportal_attendance_detail  WHERE branch_id='$branch' and status='1' and message_status='0' and date='$date' and (attendance='LA' or attendance='A' or attendance='SL' or attendance='L' )";
 // print_r($sql);


 $WorkAssignListings = $m->query($sql);
 

     ?>


<!DOCTYPE html>
<html lang="en">
  <head>
   
    <title>Send Attendance Messages | EduPortal</title>
    <?php include('RootMe/css_links.php');?>
   

<style>
/* The container */
.btn_style {
    display: block;
    position: relative;
    padding-left: 35px;
    margin-bottom: 12px;
    cursor: pointer;
    font-size: 12px;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Hide the browser's default radio button */
.btn_style input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
}

/* Create a custom radio button */
.checkmark {
    position: absolute;
    top: 0;
    left: 0;
    height: 20px;
    width: 20px;
    background-color: #eee;
    border-radius: 50%;
}

/* On mouse-over, add a grey background color */
.btn_style:hover input ~ .checkmark {
    background-color: #ccc;
}

/* When the radio button is checked, add a blue background */
.btn_style input:checked ~ .checkmark {
    background-color: #2196F3;
}

/* Create the indicator (the dot/circle - hidden when not checked) */
.checkmark:after {
    content: "";
    position: absolute;
    display: none;
}

/* Show the indicator (dot/circle) when checked */
.btn_style input:checked ~ .checkmark:after {
    display: block;
}

/* Style the indicator (dot/circle) */
.btn_style .checkmark:after {
  top: 6px;
  left: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: white;
}
</style>

  </head>
  
<script type="text/javascript">

function show_message(){
  
  $("#msg").slideDown('slow').delay(4000).slideUp('slow');
}

</script>

  <body class="nav-md">
    <div class="container body">
      <div class="main_container">
        <div class="col-md-3 left_col">
     
            <?php include('RootMe/sidebar.php');?>

              <?php include('RootMe/header.php');?>
     
        <!-- page content -->
          <div class="right_col" role="main">
          <div class="" style="background-color: white">

        <a href="<?php echo $_SESSION['dashboard'];?>">Dashboard </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp; 
    
         <a href="mark_attendanceReport_list.php">Attendance Reports </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp; 
              
          Send Attendance SMS Report

          <br><br>


           
  <section class="add_sub_agent" id="table_sub_agent">
  <div class="container">

 <div class="" style="margin-top:10px;">
      
        <div class="panel panel-default">
          <div class="panel-heading"><?php echo count($WorkAssignListings);?> Students Records <span style="float:right;margin-top: -7px;">

          <input type="hidden" value="<?php echo session_id().session_id().session_id().session_id().session_id(); ?>" name="session" />




          </span><div class="clearfix"></div> </div>
         


        </div>
     
      <div class="clearfix"></div>
    </div>
    <br>

     
<div style="overflow-x:auto;">

<form class="form-style-7" action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post" onSubmit='return disableButton()'  enctype="multipart/form-data">


  
      <input type="hidden" name="action" value="SendAttendanceSMS"  />
      <input type="hidden" name="class_id" value="<?php echo $_REQUEST['class_id'];?>" />
      <input type="hidden" name="section_id"  value="<?php echo $_REQUEST['section'];?>" >
      <input type="hidden" name="limit"  value="<?php echo $brid[0]['sms_limit']; ?>" >

      
      <div class="col-md-9">

          
           <div id="check_std_msg" style="display:none;" class="alert alert-warning alert-dismissible">
                    <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
                     <strong>Warning !</strong> Please select class to save attendance !!!
            </div>
    
          <?php  if(isset($_SESSION['error_msg'])){?>

           <div id="error"  class="alert alert-warning alert-dismissible">
                    <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
                     <strong>Warning !</strong> You have already saved the attendance of this class !!!
            </div>

         <?php  unset($_SESSION['error_msg']); }?>

        </div>


        <div class="col-md-3" style="margin-bottom:1%;">

         <?php 

         $branch=$_SESSION['branch'];
           $monthId=date("m");
           $sessionID=date("Y");

            $qr="SELECT SUM(add_sms) as TaditionalSms FROM eduportal_branches_SMScredit_limit WHERE month_id='$monthId'  and branch_id='$branch' AND session_id=".$sessionID;

            $AdSMS = $m->query($qr);

         $total_sms_monthly_used=getCurrentMonthFeeSms($m)+getCurrentMonthResultSms($m)+getCurrentMonthOtherSms($m)+getCurrentMonthAttendanceSms($m)+0;
         $sms_credit=$brid[0]['monthly_credit']+$AdSMS[0]['TaditionalSms']-$total_sms_monthly_used;
         
          if(count($WorkAssignListings)>0 && $sms_service[0]['sms_service']==0) {
            ?>
            
              <input type="submit" name="save_attendance" <?php if($sms_credit <= 0) { echo "disabled";}?> onClick=" return confirmation()" id="btn" class="pull-right btn btn-primary"  value="Send SMS to Parents"  />

         <?php 
            
          } else { ?>    
              
            <span  onclick="alert('This input is disabled')">
              <input type="submit" disabled name="save_attendance" class="pull-right btn btn-primary"  value="Send SMS to Parents"  />                 
              </span>
            <?php } ?>

        </div>



    <table id="listofstudents" data-page-length='200' class="table table-striped table-bordered" style="width:100%">
          
          <thead>
            <tr>
                <th width="2%">S.No</th>
                <th width="12%">Student Name</th>
                <th width="10%"> Father Name </th>
                <th width="10%"> Cell No </th>
                <th width="8%">Roll#</th>
                <th width="10%" style="text-align:center;"> Class </th>
                <th width="7%" style="text-align:center;"> Date </th>
              <th width="5%">Attendance</th>
              <th width="5%">SMS</th>

              <th width="8%">

            <label class="container1">
              <input  type="checkbox" id="checkAll" /><span style="margin-top: -13px;" class="checkmark"></span>
            </label>
            
             </th>

            </tr>
        </thead>
        <tbody>


   
     
     <?php /*$WorkAssignList = $m->query("select * from edu_student_details where status='0' order by student_id desc");*/
      $count=1;
      foreach($WorkAssignListings as $WorkAssignListVal)
      { 

        $m->where("class_id", $WorkAssignListVal['class_id']);
        $class=$m->get("edu_class_config");

        $m->where("section_id", $WorkAssignListVal['section_id']);
        $section=$m->get("edu_adm_section_detail");

        $m->where("student_id", $WorkAssignListVal['student_id']);
        $student=$m->get("edu_student_details");
        
      ?>

        <tr>
                
                  <td style="text-align:center;">

                     <?php echo $count; $count++;?>

                   </td>


                  <td >

                     
                     <?php echo $student[0]['first_name'];?>

                   </td>

                  <td> 

                  <input type="hidden" name="numbers<?php echo $student[0]['student_id']; ?>" value="<?php echo $student[0]['cell_no'];?>" />
                  <input type="hidden" name="attend<?php echo $student[0]['student_id']; ?>" value="<?php echo $WorkAssignListVal['attendance'];?>" />
                  <input type="hidden" name="names<?php echo $student[0]['student_id']; ?>" value="<?php echo $student[0]['first_name'];?>" />
                  <input type="hidden" name="std<?php echo $student[0]['student_id']; ?>" value="<?php echo $student[0]['student_id'];?>" />
                  
                   <?php echo $student[0]['last_name'];?> </td>
                  <td>  <?php echo $student[0]['cell_no'];?> </td>

                  <td> <?php echo $student[0]['candidate_roll_no'];?> </td>
                  <td style="text-align:center;"> <?php echo $class[0]['Class_Name'];?> - <?php echo $section[0]['section_name'];?> </td>
                  
                  <td style="text-align:center;"> <?php echo date("d-M-Y",strtotime($WorkAssignListVal['date']));?> </td>

                  <td style="color:white;text-align:center;background-color:<?php if($WorkAssignListVal['attendance']=="L"){echo "#F2DEE0";} if($WorkAssignListVal['attendance']=="A"){echo "#E26867";} if($WorkAssignListVal['attendance']=="LA"){echo "#FFA07A";} if($WorkAssignListVal['attendance']=="SL"){echo "#878A70";}?>;" >

                  <?php echo $WorkAssignListVal['attendance'];?>
        
        



                <script>
                function confirmation() {
                    var txt;
                    var r = confirm("Are you sure you want to send sms ?");
                    if (r == true) {
                        delete_student(id);
                        
                    } else {
                        return false;
                    }
                    
                }

                function disableButton() {
                    let btn = document.getElementById('btn');
                    btn.disabled=true;                   
                    return true;
                }
                </script>



                  </td>

                  <td> <?php if($WorkAssignListVal['message_status']==0){echo "Not sent";}else {echo "Sent"; } ?> </td>

                  <td>
                   <label class="container1">
                   <input type="checkbox" name="checkboxes[]" checked  value="<?php echo $WorkAssignListVal['student_id']; ?>"  class="cb-element" /><span class="checkmark"></span>
                  </label>
                  </td>

              </tr>





              <?php
      } ?>



           
            
           
        </tbody>
        
    </table>

</form>
</div>

    <br><br>


  </div>
  <div class="clearfix"></div>
</section>
    

           
          </div>
        </div>

            </div>
          </div>
        </div>
        <!-- /page content -->
  

 <script src="js/ajax_functions.js"></script>
 <?php include('RootMe/js_linksscript.php');?>
    <!-- Links for Datatable-->

<script src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
    <script>
        $(document).ready(function() {
		    $('#listofstudents').DataTable({
		      "pageLength": 100
		    });
		    } 
		  );

     $("#checkAll").change(function () {

            $("input:checkbox").prop('checked', $(this).prop("checked"));
        });        

    </script>
  
  </body>
</html>
