<?php
include("../../db.php");

header('Content-Type: application/json');

    $paper = $_REQUEST['pid'];

    $subjectiveArray = array();
    $subpaperArray = array();

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

            $tq = count($allquestions);
            $marks = $subjective['per_que_marks']*$tq;
            $time = $subjective['duration'];
            $level = $subjective['level'];
            $description = $subjective['paper_description'];

            if(count($allquestions) > 0){
                $status = 1;

            	foreach($allquestions as $question){
            	    $options = json_decode($question[options], true);
            	    $m_options = json_decode($question[m_options], true);
            	    
                    $allimages = $db->getRows("SELECT * from assignment_question_files where question_id='$question[id]' ");
                    $imageArray = array();
                    $optionimage = array();

                    foreach($allimages as $image){
                        if($image[image_type]=="question_image"){
                            array_push($imageArray, ["image"=>"http://$_SERVER[HTTP_HOST]/uploads/questionimages/$image[name]"]);
                        }
                        else {
                            array_push($optionimage, ["image"=>"http://$_SERVER[HTTP_HOST]/uploads/questionimages/$image[name]", "optno"=>"$image[option_no]"]);
                        }
                    }

                  array_push($subpaperArray,["id"=>"$question[id]","question"=>"$question[question]","q_image"=>$imageArray,"options"=>$options, "opt_image"=>$optionimage, "m_options"=>$m_options, "answer"=>"$question[answer]", "hint"=>"$question[hint]", "solution"=>"$question[solution]", "qtype"=>$question[qtype], "quemark"=>$question[quemark] ]);
            	}

            }

    echo json_encode($subpaperArray);
?>