Percolating granular superconductor in a magnetic field