<?php

include '../admin/config.php';
$conn = new mysqli($HostName, $HostUser, $HostPass, $DatabaseName);


////////////////////
// جلب سجل المستخدم
////////////////////

	    $email = $_POST["email"];
	    $pass = $_POST["pass"];
		$catagory = $_POST["catagory"];
	
	$query = "SELECT log FROM USERS WHERE email='$email' ";
        $result = mysqli_query($conn,$query);
           if($row = mysqli_fetch_array($result)) {
		      $log = $row['log'] ;
             }else{
				 return ;
			 }
	
       $conn->close();

/////////////
// جلب الأسئلة
/////////////

switch ($catagory) {
   case "0":
    $catagory = "amma" ;
    break;
   case "1":
     $catagory = "din" ;
    break;
   case "2":
     $catagory = "tarikh" ;
    break;
   case "3":
     $catagory = "awasim" ;
    break;
   case "4":
     $catagory = "taqafa" ;
    break;
   case "5":
     $catagory = "sport" ;
    break;
   case "6":
     $catagory = "ilm" ;
    break;
   case "7":
     $catagory = "english" ;
    break;
   case "8":
     $catagory = "alghaz" ;
    break;
	
  default:
     $catagory = "all" ;
}


$conn = new mysqli($HostName, $HostUser, $HostPass, $DatabaseName);	
$heroes = array(); 

$sql = "SELECT id, domain, type, question, a_1, a_2, a_3, a_4, answer FROM QUESTION ORDER BY RAND() " ; // جلب الاسئلة عشوائيا
$result = $conn->query($sql);

$x = 1 ;
    while($row = $result->fetch_assoc()) {
         
		   $domain = $row['domain'] ;

           if ( $domain == $catagory OR $domain == "all"){
	     	    $temp["id"] = $row["id"] ;
	            $temp["type"] = $row["type"] ;
                $temp["question"] = $row["question"] ;
                $temp["a_1"] = $row["a_1"] ;
                $temp["a_2"] = $row["a_2"] ;
                $temp["a_3"] = $row["a_3"] ;
                $temp["a_4"] = $row["a_4"] ;
                $temp["answer"] = $row["answer"] ;
		      array_push($heroes, $temp);  
             $x++ ;			  
		   }

      if ($x > 25 ) { // عدد الأسئلة التي ستعرض على التطبيق
        	echo json_encode($heroes);
			$conn->close();
	        return ;
          }
		   
    }
	
$conn->close();
  
if( sizeof($heroes) == 0 ) {
	// echo sizeof($heroes);// حجم قاعدة البيانات
}

echo json_encode($heroes);

?>
