<?php 
  include "../db.php";
  session_start();
    $class_sql = "SELECT sclass FROM users WHERE uref = '$_SESSION[uref]'";
    $class_result = mysqli_query($con, $class_sql);
    $class_row = mysqli_fetch_assoc($class_result);
    $userClass = $class_row["sclass"];

    $class_sql = mysqli_query($con, "SELECT * FROM class WHERE sclass = '$userClass'");
    if($class_row = mysqli_fetch_assoc($class_sql)){
        $class_sl = $class_row["sid"];
    }

if (isset($_POST['start'])) {
    $start= mysqli_real_escape_string($con,$_POST['start']);
    $sid= mysqli_real_escape_string($con,$_POST['sid']);
    $AndWhere ='';
    if ( !empty($_POST['FirstFilterValue']) ) {
        $AndWhere .= "AND n_title='$_POST[FirstFilterValue]' ";
    }

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

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

    $sql = "SELECT * FROM notes WHERE n_class = '$class_sl' AND n_subject = '$sid' $AndWhere  ORDER BY n_id DESC LIMIT $start,10";

    $res = mysqli_query($con,$sql);
    if ($total_rows=mysqli_num_rows($res)>0) {
        $s_output='';
        $c = $start+1;
        while ($rows=mysqli_fetch_assoc($res)) {
        $uploadedImage = $rows["notes"];

        $up_sql = "SELECT uname, uref FROM users WHERE uref = '$rows[uploadedby]' ";
        $up_run = mysqli_query($con, $up_sql);
        $up_rows = mysqli_fetch_assoc($up_run);
?>
<li class='clearfix' style='float: none;'>
    <div class='row'>
        <div class='col-md-9 col-xs-12 second-item'>
            <a data-toggle='modal' class='viewDetails' data-target='#modalNotes' data-ref='<?php echo $rows['n_ref'];?>'
                style="cursor: pointer;" data-title='<?php echo $rows["n_title"];?>'
                data-note_script='<?php echo $rows["note_script"];?>'>
                <i class='fa fa-pencil-square-o' aria-hidden='true' style='color:#000;font-size:17px;'></i> <b
                    style='color:black;font-size:15px;'><?php echo $rows["n_title"];?></b>
            </a>
            <br>
            <b style='color:black;'><i class='fa fa-user'></i> </b> <?php echo $up_rows['uname'];?>
            &nbsp;&nbsp;
            <i class='fa fa-clock-o text-primary'></i> <?php echo $rows["n_date"];?>
        </div>
        <div class='col-md-3 col-xs-12 second-item'>
            <a href="view-notes-attachment.php?n_id=<?php echo $rows["n_id"];?>" class="btn btn-primary">View Notes</a>
            <a href="practice-set.php?n_id=<?php echo $rows["n_id"];?>" class="btn btn-primary">Practice Test</a>
        </div>
    </div>
</li>
<?php
          $c++;
        }
        mysqli_close($con);
    }
}
?>

<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>