<?php
include("../../db.php");
//header("Access-Control-Allow-Origin: * ");
header('Content-Type: application/json');

    $class = $_REQUEST['class'];
    $uid = $_REQUEST['uid'];
	$array = array();
	$status = 0;
	
	$attemptpaper = 0;
	$correct = 0;
    $wrong = 0;
    $skipped = 0;
    
    $subjectArray = array();

	$allSubject = $db->getRows("select * from subject_new where class='$class' and type='subject'  ");
    if(count($allSubject) > 0){
        $status = 1;

    	foreach($allSubject as $subject){
                array_push($subjectArray,["id"=>"$subject[id]","subject"=>"$subject[subject]", "image"=>"uploads/subjectimage/$subject[subject_image]" ]);
    	}

    }

    $attempt_paper = $db->getRows("select * from assignment_attempt_paper where uid='$uid' ");
    if(count($attempt_paper) > 0){
        $attemptpaper = count($attemptpaper);
        foreach($attempt_paper as $paper){
            $correct += $paper['correct'];
            $wrong += $paper['wrong'];
            $skipped += $paper['skipped'];
        }
    }

    $array['status'] = $status;
    $array['total_attempt'] = count($attempt_paper);
    $array['correct'] = $correct;
    $array['wrong'] = $wrong;
    $array['skipped'] = $skipped;
    $array['data'] = $subjectArray;

    echo json_encode($array);

	?>