<style>
/* The Modal (background) */
.modal {
  display: none; /* Hidden by default */
  position: fixed; /* Stay in place */
  z-index: 1; /* Sit on top */
  left: 0;
  top: 0;
  width: 100%; /* Full width */
  height: 100%; /* Full height */
  overflow: auto; /* Enable scroll if needed */
  background-color: rgb(0,0,0); /* Fallback color */
  background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
  -webkit-animation-name: fadeIn; /* Fade in the background */
  -webkit-animation-duration: 0.4s;
  animation-name: fadeIn;
  animation-duration: 0.4s
}

/* Modal Content */
.modal-content {
  position: fixed;
  /*bottom: 0;*/
  background-color: #fefefe;
  margin-left:18%;
  margin-top:50px;
  width: 900px;
  height:550px;
  padding:0px;
  -webkit-animation-name: slideIn;
  -webkit-animation-duration: 0.4s;
  animation-name: slideIn;
  animation-duration: 0.4s
}

/* The Close Button */
.close {
  color: white;
  float: right;
  font-size: 38px;
  font-weight: 900;
  margin-right:-50px;
}

.close:hover,
.close:focus {
  color: #000;
  text-decoration: none;
  cursor: pointer;
}

.modal-header {
  padding: 2px 16px;
  background-color: #5cb85c;
  color: white;
}

.modal-body {padding: 2px 16px;}

.modal-footer {
  padding: 2px 16px;
  background-color: #5cb85c;
  color: white;
}

/* Add Animation */
@-webkit-keyframes slideIn {
  from {bottom: -300px; opacity: 0} 
  to {bottom: 0; opacity: 1}
}

@keyframes slideIn {
  from {bottom: -300px; opacity: 0}
  to {bottom: 0; opacity: 1}
}

@-webkit-keyframes fadeIn {
  from {opacity: 0} 
  to {opacity: 1}
}

@keyframes fadeIn {
  from {opacity: 0} 
  to {opacity: 1}
}

    @media print {
        #myPrntbtn {
            display :  none;
        }
    }

    .nav-link{
        background:red;
        color:white;
    }

</style>

<script>
    function printme(){
	    window.print();
    }
</script>


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

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

    $subject = $db->getVal("select subject from subject_new where id='$paper[parent_subject]' ");
    $subsubject = $db->getVal("select subject from subject_new where id='$paper[sub_subject]' ");
    $chapter = $db->getVal("select subject from subject_new where id='$paper[chapter]' ");

    if(count($paper) > 0){ 

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

?>

<div class="tab-content">

<button onclick="printme()" id="myPrntbtn">Print</button>

    <div style="width:100%;text-align:center;">

        <img src="<?php echo $LinksDetails['logo']; ?>" style="width:200px;float:left;height:80px;"/>

        <h1><?php
            echo $LinksDetails['site_name']; ?>
        </h1>
        <label><?php
                echo $LinksDetails['contact_content']; ?>
        </label>

    </div>
<hr>
<table class="table" border="1" cellspacing="0" cellpadding="5" style="width:100%;">
    <tr>
        <th>Class</th>
        <td><?php echo $paper['class']; ?></td>
        <th>Subject</th>
        <td><?php echo $subject; ?></td>
    </tr>
    <tr>
        <th>Sub-subject</th>
        <td><?php echo $subsubject; ?></td>
        <th>Chapter</th>
        <td><?php echo $chapter; ?></td>
    </tr>
    <tr>
        <th>Per Question Marks</th>
        <td><?php echo $paper['per_que_marks']; ?></td>
        <th>Level Name</th>
        <td><?php echo $paper['level']; ?></td>
    </tr>
    <tr>
        <th>Paper Description</th>
        <td><?php echo $paper['paper_description']; ?></td>
        <th>Status</th>
        <td><?php echo $paper['paper_status']; ?></td>
    </tr>
    <tr>
        <th>Live Date</th>
        <td><?php echo $paper['livedate']; ?></td>
        <th>Live Time</th>
        <td><?php echo $paper['livetime']; ?></td>
    </tr>
    <tr>
        <th>Paper Time</th>
        <td><?php echo $paper['duration']; ?></td>
        <th>Total Questions</th>
        <td><?php echo count($allquestions); ?></td>
    </tr>
    <tr>
        <th>Paper Type</th>
        <td><?php if($paper['paper_type'] == '1'){
                        echo "Objective";
                    }
                    if($paper['paper_type'] == '2'){
                        echo "Subjective";
                    }
                    if($paper['paper_type'] == '3'){
                        echo "NCERT";
                    }?>
        </td>
        <th>Session</th>
        <td><?php echo $paper['session']; ?></td>
    </tr>
</table>

  <div class="tab-pane fade in active">

    <?php
            if(count($allquestions)>0 ){
            $i = 0;
            foreach($allquestions as $question){ $i++;
             $qtype = $question['qtype'];
             $questatus = '';

                $att_question = $db->getRow("select * from assignment_attempt_question where pid='$id' and uid='$uid' and qid='$question[id]' ");
                ?>
                    <table class="" style="margin:20px 0px;border:solid 1px #e5e5e5;float:left;background:#fff0f7;width:100%;">
                        <tr>
                            <td style="width:100px;font-weight:bold;padding:5px;">Question.<?php echo $i; ?></td>
                            <td><?php echo $question['question']; ?></td>
                        </tr>

                        <?php
                            $allimages = $db->getRows("select * from assignment_question_files where paper_id='$id' and question_id='$question[id]' ");
                            $correctans = json_decode($question['answer'],true);
                        ?>
                        <tr>
                            <td></td>
                            <td>
                                <?php foreach($allimages as $image){
                                    if($image['image_type'] == "question_image"){ ?>
                                        <img src='../uploads/questionimages/<?php echo $image[name]; ?>' onclick="showmodal('../uploads/questionimages/<?php echo $image[name]; ?>')" style='width:200px;height:150px;margin:5px;' />
                                <?php
                                    }
                                } ?>
                            </td>
                        </tr>
                        
                        <?php if($qtype == 7 || $qtype == 8) {?>
                        <tr>
                            <td style="width:100px;font-weight:bold;padding:5px;">Solution</td>
                            <td><?php echo $question['solution']; ?></td>
                        </tr>                        
                        <?php } else { ?>
                        <tr>
                            <td>Options :</td>
                            <td>
                                <?php 
                                    if($qtype == 1 || $qtype == 2 || $qtype == 3 || $qtype == 4){
                                     $options= json_decode($question[options], true);
                                        $j = 0;
                                        foreach($options as $opt){ $j++;
                                            echo "<li style='display:block;'>$j. $opt[answer]</li>";
                                            foreach($allimages as $image){ 
                                                if($image['image_type'] == "option_image" && $image['option_no'] == $j){ ?>
                                                    <img src='../uploads/questionimages/<?php echo $image[name]; ?>' onclick="showmodal('../uploads/questionimages/<?php echo $image[name]; ?>')" style='width:200px;height:150px;margin:5px;' />
                                                    <?php
                                                }
                                            }
                                        }
                                    }
                                    else {
                                        $options= json_decode($question[options], true);
                                        $m_options = json_decode($question[m_options], true);
                                		$marray = array();
                                    		foreach ($m_options as $key ) {
                                    			$marray[] = $key[answer];
                                    		}
                                        $j = 0;$k=0;
                                        echo "<table class='table' style='width:100%;'><tr style='font-weight:bold;'><td>Column A</td><td>Column B</td>";
                                        foreach($options as $opt){ $j++;
                                            echo "<tr><td>$j. $opt[answer]</td><td>$j. $marray[$k]</td></tr>";
                                            $k++;
                                        }
                                        echo "</table>";
                                    }
                                ?>                                
                            </td>
                        </tr>
                        <tr>
                            <td style="width:140px;font-weight:bold;padding:5px;">Correct Answer:</td>
                            <td>
                                <?php 
                                    if($qtype == 6){
                                    foreach($correctans as $cans){
                                        echo json_encode($cans);
                                    }
                                } else{
                                    foreach($correctans as $cans){
                                        echo "$cans, ";
                                    }
                                }
                                ?>
                            </td>
                        </tr>
                        <?php } ?>
                    </table>
                <?php
            }
        }

    ?>

<!-- The Modal -->
<div id="myModal" class="modal">

  <!-- Modal content -->
  <div class="modal-content">

    <div class="modal-header">
      <span class="close">&times;</span>
    </div>
    <br>
    <div class="modal-body">
        <div id="modalimg"></div>
    </div>

  </div>

</div>



  </div>

</div>

<?php
    }
?>
 
 
 <script>
function showmodal(img){
    document.getElementById('modalimg').innerHTML = "<img src='"+img+"' style='width:100%; height:92%'>";
      modal.style.display = "block";
} 
// Get the modal
var modal = document.getElementById("myModal");

// Get the button that opens the modal
var btn = document.getElementById("myBtn");

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks the button, open the modal 
// btn.onclick = function() {
//   modal.style.display = "block";
// }


// When the user clicks on <span> (x), close the modal
span.onclick = function() {
  modal.style.display = "none";
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
  if (event.target == modal) {
    modal.style.display = "none";
  }
}
</script>