// kataloogi rekursiivne kustutamine
    function clr_dir($dir) {
/*
        if (file_exists("$dir/index.htm")) {
            rename("$dir/index.htm","$dir/kvfailid_index.html");
            copy("/root/hoiatus.tmpl","$dir/index.html");
        }
        else if(file_exists("$dir/index.html")) {
            rename("$dir/index.html","$dir/kvfailid_index.html");
            copy("/root/hoiatus.tmpl","$dir/index.html");
        }
        else { */
            if(@ ! $opendir = opendir($dir)) {
                return false;
            }
            while(false !== ($readdir = readdir($opendir))) {
                if($readdir !== '..' && $readdir !== '.') {
                    $readdir = trim($readdir);
                    if(is_file($dir.'/'.$readdir)) {
                        if(@ ! unlink($dir.'/'.$readdir)) {
                            return false;
                        }
                    }
                    elseif(is_dir($dir.'/'.$readdir)) {
                        // Calls itself to clear subdirectories
                        if(! clr_dir($dir.'/'.$readdir)) {
                            return false;
                        }
                    }
                }
            }
            closedir($opendir);
            if(@ ! rmdir($dir)) {
                return false;
            }
/*      } */
        return true;
    }