<?php header("Access-Control-Allow-Origin: *");
  header("Access-Control-Allow-Headers: *");  

  // Allow headers (important for fetch / axios)
  header("Access-Control-Allow-Headers: Content-Type, Authorization");

  include '../db/connectMe.php';   
  include '../function/function.php';  

  // (C) GENERATE JWT TOKEN
  require "../vendor/autoload.php";
  use Firebase\JWT\JWT;



  // (C) GET JWT FROM AUTH HEADER

  //if( AuthorizeMe(@substr(getallheaders()["Authorization"], 7)) ){

    $jwt = substr(getallheaders()["Authorization"], 7);

    //Decoding data
    $decodeToken = (json_decode(base64_decode(str_replace('_', '/', str_replace('-','+',explode('.', $jwt)[1]))))->data);

    if(!isset($decodeToken)){

      //http_response_code(401);

      exit(json_encode(array("error" => "unauthorised") ));

    }


    //payment
    $payment = (float) calculatePaidAmount(1)->amount;


    //students
    $students = (float) countStudents(1)->qty;

    //courses
    $courses = (float) countCourses(1)->qty;
    

    $report  = array(
      'payment' => $payment,
      'students' => $students,

      'courses' => $courses,

    );



    exit(json_encode($report));





  







