Fix getGlobalBlocks() to retrieve only global areas used by the collection

Rewritten DB query fixes the outputAutoHeaderItems() issue for global areas. With this fix, only global blocks used on the page are retrieved, and so only the necessary JS and CSS resources are auto-loaded.

I'm no SQL guru, so I can't say how this solution ranks performance- or compatibility-wise, but it does work.