<?php 
  include "../../db.php";
  date_default_timezone_set('Asia/Kolkata');
  $currentCoreDate = date("Y-m-d");
  session_start();

if (isset($_POST['start'])) {
    
    $start= mysqli_real_escape_string($con,$_POST['start']);
     $AndWhere ='';

    if (!empty($_POST['First1FilterValue']) && !empty($_POST['First2FilterValue']) ) {
        $AndWhere .= "AND st_lastRemarkDate BETWEEN '$_POST[First1FilterValue]' AND '$_POST[First2FilterValue]'";
    }

    if (!empty($_POST['First1FilterValue']) && empty($_POST['First2FilterValue']) ) {
        $AndWhere .= "AND st_lastRemarkDate BETWEEN '$_POST[First1FilterValue]' AND '$currentCoreDate'";
    }

    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 .= "";
    }

    if (!empty($_POST['ThirdFilterValue'])) {
        $AndWhere .= "AND st_name='$_POST[ThirdFilterValue]'";
    }

    if (!empty($_POST['aFilterValue'])) {
        $AndWhere .= "AND st_ph='$_POST[aFilterValue]'";
    }

    if (!empty($_POST['bFilterValue'])) {
        $AndWhere .= "AND st_status='$_POST[bFilterValue]'";
    }

    if (!empty($_POST['cFilterValue'])) {
        $AndWhere .= "AND st_category='$_POST[cFilterValue]'";
    }
   


    $sql = "SELECT * FROM student_details WHERE `st_admin` ='".$_POST['uadmin']."' AND ( st_name != '' && st_name IS NOT NULL ) AND ( st_by='' || st_by IS NULL ) AND `flag_status` ='A' $AndWhere ORDER BY uploadDT ASC LIMIT $start,25";


    $res = mysqli_query($con,$sql);
    if ($total_rows=mysqli_num_rows($res)>0) {
        $s_output="";
          $c = $start+25;
        while ($rows=mysqli_fetch_assoc($res)) {

          ?>
<li class='clearfix' style='float: none;'>
    <div class="single-dis-admin mb-2">
        <span id="status-msg-<?= $rows['st_no']; ?>" class="text-center"></span>
        <div class="row">
            <div class="col-md-9">
                <i class="fa fa-user-circle" aria-hidden="true" style="color:orange;font-size:16px;"></i>
                <b style="font-size:16px;"><?= $rows['st_name']; ?></b>
                <br>
                <b><i class="fa fa-upload" aria-hidden="true"></i> </b> <?= $rows['uploadDT']; ?>
            </div>
            <div class="col-md-3">
                <button type="button" class="lead_Accept_from_Global_Data btn btn-primary btn-sm"
                    id="<?= $rows['st_no']; ?>">Click to Accept</button>
            </div>
            <div class="col-md-12 mt-2">
                <div class='about-display mb-2'>
                    <label for=''>About :</label>
                    <?= implode(', ', array_filter([
                    $rows['st_about'], $rows['st_about2'], $rows['st_about3'],
                    $rows['st_about4'], $rows['st_about5'], $rows['st_about6'],
                    $rows['st_about7'], $rows['st_about8']
                    ]))?>
                </div>
            </div>
        </div>
    </div>

</li>
<?php 
$c++;
        }
        echo $s_output;
    }

}
?>

<script>
$(document).ready(function() {

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

        var sid = $(this).attr('id');
        $.ajax({
            url: "action-Ajax.php",
            method: "POST",
            data: {
                action: 'leadAcceptfromGlobalData',
                sid: sid
            },
            cache: false,
            success: function(result) {
                $("#status-msg-" + sid).html(result);
            }
        });

    });


    $('.remarkDetails').on('click', function() {
        var remark_for = $(this).attr('id');
        var title = $(this).data('title');
        //console.log(remark_for);
        $('#modalName').text(title);

        $('.modal-css').css({
            'color': 'black'
        });
        $('.modal-name').css({
            'text-align': 'center',
            'color': 'black',
            'font-size': '20px'
        });
        $.ajax({
            url: 'action-Ajax.php',
            type: 'post',
            data: {
                action: 'remark',
                remark_for: remark_for
            },
            success: function(result) {
                $('#remarkShow').html(result);
            }
        });
    });


    $('.adminRemarkDetails').on('click', function() {
        var remark_for = $(this).attr('id');
        var title = $(this).data('title');
        //console.log(remark_for);
        $('#modalName').text(title);

        $('.modal-css').css({
            'color': 'black'
        });
        $('.modal-name').css({
            'text-align': 'center',
            'color': 'black',
            'font-size': '20px'
        });
        $.ajax({
            url: 'action-Ajax.php',
            type: 'post',
            data: {
                action: 'adminRemark',
                remark_for: remark_for
            },
            success: function(result) {
                $('#remarkShow').html(result);
            }
        });
    });
});
</script>