<style>
    @media print{
        .hide {
            display:none;
        }
    }
</style>

<script>
    function printme(){
	    window.print();
    }
</script>
<form method="post" action="">
<select class="hide" name="section">
    <option value="">--Select Section--</option>
    <?php $section = $db->getRows("select * from section order by name");
        foreach($section as $sec){?>
        <option value="<?php echo $sec["name"]; ?>"><?php echo $sec["name"]; ?></option>
        <?php } ?>
</select>
<button type="submit" class="hide">Search</button>
<button onclick="printme()" class="hide">Print</button>
</form>

<?php
    $id = $_GET['id'];
    $class = $_GET['class'];

    $wheresection = "";
    if(isset($_POST["section"]) && trim($_POST['section'])!=''){
        $wheresection = " section='$_POST[section]' and ";
    } else {
        if($_GET['section']!=""){
            $wheresection = " section='$_GET[section]' and ";
        }
    }

	$paper = $db->getRow("SELECT * FROM omr_paper WHERE session='".$_SESSION["admin"]["session"]."' and id='$id' ");

    $subomr = $db->getVal("select sub_omr from subject where id='$paper[subject]' ");

    if(count($paper) > 0){

    $allquestions = $db->getRows("select * from omr_question where paper='$id' ");

    $allstudent = $db->getRows("select * from student where class='$class' and $wheresection session='".$_SESSION['admin']['session']."' and status=1 ");
    foreach($allstudent as $stu){    
?>
<div class="mydiv">
    <div style="background:black;width:20px;height:20px;float:left;"></div>
    <div style="background:black;width:20px;height:20px;float:right;"></div>
    <!--<br><br>-->
    <!--<div class="tab-content">-->

    <!--    <div style="width:100%;">-->

    <!--        <div style="width:100%;float:left;">-->
    <!--            <table cellspacing="0" style="width:100%;color:#d11d53;text-align:center;border-color:#d11d53" border="1">-->
    <!--                <tr>-->
    <!--                    <td style="background:pink;color:black;font-weight:600">Class</td>-->
    <!--                    <td style="background:pink;color:black;font-weight:600">Student's Name</td>-->
    <!--                    <td style="background:pink;color:black;font-weight:600">Subject</td>-->
    <!--                    <td style="background:pink;color:black;font-weight:600;width:100px;">Roll No.</td>-->
    <!--                </tr>-->
    <!--                <tr>-->
                        <!--<td style="height:25px;font-weight:600;"><?php echo $stu['omr']; ?></td>-->
                        <!--<td style="height:25px;font-weight:600;"><?php echo $stu['name']; ?></td>-->
                        <!--<td style="height:25px;font-weight:600;"><?php echo $subomr;?></td>-->
                        <!--<td style="height:25px;font-weight:600;"><?php echo $stu['fincome']; ?></td>-->
                        <td style="height:25px;font-weight:600;"><?php //echo $stu['omr']; ?></td>
                        <td style="height:25px;font-weight:600;"><?php //echo $stu['name']; ?></td>
                        <td style="height:25px;font-weight:600;"><?php //echo $subomr;?></td>
                        <td style="height:25px;font-weight:600;"><?php //echo $stu['fincome']; ?></td>
    <!--                </tr>-->
    <!--            </table>-->
    <!--        </div>-->
    
    <!--    </div>-->
    
    <!--</div>-->
    <div style="width:950px;color:transparent">.</div>
    
    <div style="width:100%;float:left;margin-top:20px;">
        <?php
        $max = count($allquestions);
            if(count($allquestions)>0 ){
                ?>
                <table cellspacing="0" style="color:#d11d53;text-align:center;display:inline-block;float:left;margin-top:0px;width:5%;margin-left:20px;">
                    <?php
                        for($i=1;$i<41;$i++){
                            if($i<=$max){   ?>
                            <tr>
                                <td style="width:20px;font-weight:bold;padding:5px;border:solid 1px;padding-top:6px;"><?php echo $i; ?></td>
                            </tr>
                            <?php 
                            }   }
                    ?>
                </table>

                <table cellspacing="0" style="color:#d11d53;text-align:center;display:inline-block;float:left;margin-top:0px;width:40%;border:solid 1px;margin-left:10px;">
                    <?php
                        for($i=1;$i<41;$i++){
                            if($i<=$max){   ?>
                            <tr>
                                <?php foreach( range('A', 'D') as $ele) {
                                        echo "<td style='font-weight:bold;text-align:center;padding:5px;width:90px;padding-left:37px;padding-top:6px;'><p style='border:solid 1px;width:18px;height:18px;border-radius:50%;'>$ele</p></td>";
                                    }
                                ?>
                            </tr>
                            <?php 
                            }   }
                    ?>
                </table>
                <?php if($max > 40) { ?>
                    <table cellspacing="0" style="color:#d11d53;text-align:center;display:inline-block;float:left;margin-top:0px;width:5%;margin-left:20px;">
                        <?php
                            for($i=41;$i<81;$i++){
                                if($i<=$max){   ?>
                                <tr>
                                    <td style="width:20px;font-weight:bold;padding:5px;border:solid 1px;padding-top:6px;"><?php echo $i; ?></td>
                                </tr>
                                <?php 
                                }   }
                        ?>
                    </table>
    
                    <table cellspacing="0" style="color:#d11d53;text-align:center;display:inline-block;float:left;margin-top:0px;width:40%;border:solid 1px;margin-left:10px;">
                        <?php
                            for($i=41;$i<81;$i++){
                                if($i<=$max){   ?>
                                <tr>
                                    <?php foreach( range('A', 'D') as $ele) {
                                            echo "<td style='font-weight:bold;text-align:center;padding:5px;width:90px;padding-left:37px;padding-top:6px;'><p style='border:solid 1px;width:18px;height:18px;border-radius:50%;'>$ele</p></td>";
                                        }
                                    ?>
                                </tr>
                                <?php 
                                }   }
                        ?>
                    </table>
                <?php }
                }
    
        ?>
      </div>
    
    <div style="background:black;width:20px;height:20px;float:left;bottom:-5px;position:relative;"></div>
    <div style="background:black;width:20px;height:20px;bottom:-5px;position:relative;float:right;"></div>

</div>
<style>
    @media print {
        .mydiv {page-break-after: always;}
    }
</style>

<?php } 
    }   ?>

    

