<?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']);

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

    $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_2 AS a2 JOIN attendance AS a ON a2.attendance_ref = a.ref WHERE a2.stu_id = '$id' $AndWhere ORDER BY a2.a_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']);

            if ($rows['stu_attendance'] == 'A') {

                $attn = "style='background: #ff4d4d;'";

            } else {

                $attn = "style='background:#00b33c;'";

            }

            $s_output .= 

                "

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

                    <div class='card mb-3' $attn>

                        <div class='card-header text-center' style='color:#fff;'>

                         

                          $showFullDate &nbsp;&nbsp; $showTime

                         

                        </div>

                        <div class='card-body text-center'  style='color:#fff;'>

                            <b>$showCS[showSubject] </b> 



                        </div>

                    </div>

                </div>

                ";

          $c++;

        }



        mysqli_close($con);



        echo $s_output;

    }



}

?>

        <script>

        $(document).ready(function(){



            $('.viewDetails').on('click', function () {

                var n_ref = $(this).data('ref');

                var title = $(this).data('title');

                console.log(n_ref);

                $('#modalName').text(title);



                $('.modal-css').css({

                    'color' : 'black'

                });

                $('.modal-name').css({

                    'text-align' : 'center',

                    'color' : 'black',

                    'font-size' : '20px'

                });

                var note = $(this).data('note_script');

                $('#modalData').html(note);



                 $.ajax({

                    url:'noteImgDisplay-Ajax.php',

                    type:'post',

                    data:{

                      n_ref:n_ref

                    },

                    success:function(result){

                      $('#imageShow').html(result);

                    }

                });



                

                

            });

        });

    </script>