<?php 

    include "Admin/config/setup.php" ;
    session_start();
    if(isset($_POST['selectPlayer'])){
        $player = $_POST['selectPlayer'];
        $amount = $_POST['paid_entry'];
        if(array_search($player,$_SESSION['pid'][$player])){
            unset($_SESSION['pid'][$player]);
            array_pop($_SESSION['price']);
            $total = array_sum($_SESSION['price']);
            $data = array(
                "player"  => $player,
                "amount"  => '',
                "total" => $total
            );
            echo json_encode($data);
        }else{
            // $_SESSION['pid'];
            $_SESSION['pid'][$player] = array('pid' => $player,'amt' => $amount);
            if(empty($_SESSION['price'])){
                $_SESSION['price'] = array();
            }
            array_push($_SESSION['price'],$amount);
            $total = array_sum($_SESSION['price']);
            $data = array(
                "player"  => $player,
                "amount"  => $amount,
                "total" => $total
            );
            echo json_encode($data);
        }
    }
    // print_r($_SESSION['pid']);
?>
