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

$today_date=time();
$today_date=date("Y-m-d",$today_date);

$startDate = new DateTime('2023-04-01');
$endDate = new DateTime($today_date);
$diff = $endDate->diff($startDate);
$numberOfWeeks = floor($diff->days / 7);


include_once 'database.php';

$database = new Database();

$db = $database->getConnection();
$user_name=$_POST['email_id'];
//$user_name="Renukarani1994@gmail.com";
$total_live_calls="select * from zoom_meeting where user_name='".$user_name."'";
$total_live_calls_res = $db->query($total_live_calls);

$total_live_calls_no=0;
while($row2 = $total_live_calls_res->fetch_object())
{
    $firstTime=strtotime($row2->start_time);
    $lastTime=strtotime($row2->end_time);
    $timeDiff=$lastTime-$firstTime;
    $timeDiff=$timeDiff/60;
    if($timeDiff>=20)
    {
    $total_live_calls_no++;
    }
}


//$onboarding_query="select * from zoom_meeting";
$onboarding_query="select * from zoom_meeting where user_name='".$user_name."' AND week(created_at)=week(now())";


$result = $db->query($onboarding_query);


$monday=false;
$tuesday=false;
$wednesday=false;
$thrusday=false;
$friday=false;
$saturday=false;
$sunday=false;
$total_call_ts_week=0;
$days=[];

$weekly_attendence;
while($row1 = $result->fetch_object())
{
    $firstTime=strtotime($row1->start_time);
    $lastTime=strtotime($row1->end_time);
    $timeDiff=$lastTime-$firstTime;
    $timeDiff=$timeDiff/60;
    if($row1->days=='Monday' && $timeDiff>=20)
    {
    $total_call_ts_week++;
            $monday=true;
            $days[]=$row1->days;
       
    }
    if($row1->days=='Tuesday' && $timeDiff>=20)
    {
        $total_call_ts_week++;
   
            $tuesday=true;
            $days[]=$row1->days;
    
    }
    if($row1->days=='Wednesday' && $timeDiff>=20)
    {
        $total_call_ts_week++;
            $wednesday=true;
            $days[]=$row1->days;
  
    }
    if($row1->days=='Thrusday' && $timeDiff>=20)
    {

        $total_call_ts_week++;
            $thrusday=true;
            $days[]=$row1->days;
   
    }
    if($row1->days=='Friday' && $timeDiff>=20)
    {
        $total_call_ts_week++;
            $friday=true;
            $days[]=$row1->days;
           
    
    }
    if($row1->days=='Saturday' && $timeDiff>=20)
    {
        $total_call_ts_week++;
            $saturday=true;
            $days[]=$row1->days;
   
    }
    if($row1->days=='Sunday' && $timeDiff>=20)
    {
        $total_call_ts_week++;
            $sunday=true;
            $days[]=$row1->days;
      
    }


}

$avg_per_week=$total_live_calls_no/$numberOfWeeks;
$weekly_attendence=['days'=>$days,'total_call_ts_week'=>$total_call_ts_week,'avg_per_week'=>$avg_per_week,'total_live_calls_no'=>$total_live_calls_no];

$abc=json_encode($weekly_attendence);
print_r($abc);




?>

