<?php 
    require_once "user_class.php";
    session_start();

    require_once "kep_metod.php";
    require_once "baratok_Json.php";
    require_once "user_Json.php";
    require_once "uzenet_Json.php";
    require_once "jatekstat_Json.php";
    
    function user_torol($id,$Json,$kep_Json,$barat_Json){
        foreach(pkepek($kep_Json,$id,false) as $i ){
            if($kep_Json[kep_index_keres($i,$kep_Json)]->cimke!="alap_profil"){
                kep_torol($i,$kep_Json);
            }
        }

        $barat_inex=barat_index_keres($id);
        foreach($barat_Json[$barat_inex]-> baratokT as $i){
            for($j=0;$j<count($barat_Json[barat_index_keres($i)]-> baratokT);$j++){
                if($barat_Json[barat_index_keres($i)]-> baratokT[$j]==$id){
                    $barat_Json[barat_index_keres($i)]-> baratokT[$j]=-1;
                }
            }
        }
        $barat_Json[$barat_inex]=null;
        
        ertekelo_jatekos_torol($id);
        /*if($_SESSION['rang']==true){
            
            file_put_contents("../Json/hiba.Json",json_encode( $barat_Json,JSON_PRETTY_PRINT));
            
            die();
        }*/
        
        while(report_index_keres($id)!=-1){
            $GLOBALS['uzenet_json']->report[report_index_keres($id)]=null;
        }
        while(pchat_index_keres($id)!=-1){
            $GLOBALS['uzenet_json']->pchat[pchat_index_keres($id)]=null;
        }
        
        rmdir("../media/users/jatekosok/".$id."/");
        file_put_contents("../Json/uzenet.Json",json_encode( $GLOBALS['uzenet_json'],JSON_PRETTY_PRINT));
        file_put_contents("../Json/barat_list.Json",json_encode( $barat_Json,JSON_PRETTY_PRINT));
        $Json[user_index_keres($id,false,$Json)]=null;
        file_put_contents("../Json/user.Json",json_encode( $Json,JSON_PRETTY_PRINT));
        
     }
    
    if(isset($_POST['user_id']) ){
        user_torol($_POST['user_id'],$GLOBALS['user_json'],$kep_json,$GLOBALS['barat_json']);
        echo "a profil törölve! frisicsd az oldalt";
    }

  
    session_unset();
    session_destroy();
  
?>