<?php 

  include_once "../db.php";

  include_once "includes/function.php";

  date_default_timezone_set('Asia/Kolkata');

  $currentDate = date('Y-m-d');



  session_start();



if (isset($_POST['start'])) {

    

    $start= mysqli_real_escape_string($con,$_POST['start']);

    $cid= mysqli_real_escape_string($con,$_POST['cid']);

    $AndWhere ='';



    if (!empty($_POST['First1FilterValue']) && !empty($_POST['First2FilterValue']) ) {



        $AndWhere .= "AND class_date2 BETWEEN '$_POST[First1FilterValue]' AND '$_POST[First2FilterValue]'";

       



    }

    if (!empty($_POST['First1FilterValue']) && empty($_POST['First2FilterValue']) ) {



        $AndWhere .= "AND class_date2 BETWEEN '$_POST[First1FilterValue]' AND '$currentDate'";

       



    }

    if (empty($_POST['First1FilterValue']) && !empty($_POST['First2FilterValue']) ) {



        echo "<div style='text-align:center;font-size:20px;color:red;padding:15px;background:#f2f2f2;'>You Have To Enter Starting Date First.</div><br>";

        die();

       



    }



    if ( !empty($_POST['SecondFilterValue']) ) {



         $AndWhere .= "AND stu_class='$_POST[SecondFilterValue]' ";



    }



    if (!empty($_POST['ThirdFilterValue'])) {





        $AndWhere .= "AND class_period='$_POST[ThirdFilterValue]'";

    }



    $sql = "SELECT * FROM attendance WHERE teacher_id = '$_SESSION[uid]' AND stu_class='$cid'  $AndWhere ORDER BY id DESC LIMIT $start,12";



    $res = mysqli_query($con,$sql);

    if ($total_rows=mysqli_num_rows($res)>0) {

        $s_output='';

        $c = $start+1;

        while ($rows = mysqli_fetch_assoc($res)) {

            $showCS = showClassSubjectFromSid($con,$rows['class_period']);

            $showFullDate = showFullDate($rows['class_date']);

            $showTime= showTime($rows['class_time']);



            $s_output .= 

                "

                <a href='student-attendance.php?ref=$rows[ref]'>

                 <div class='col-md-3 ggtt'>

                    <div class='card mb-3'>

                        <div class='card-header text-center'>

                         

                          $showFullDate &nbsp; $showTime

                         

                        </div>

                        <div class='card-body text-center'>

                          

                            

                            <i class='fa fa-book'></i> $showCS[showSubject]

                    

                        </div>

                    </div>

                 </div>

                </a>

                ";

          $c++;

        }



        mysqli_close($con);



        echo $s_output;

    }



}

?>

