Phase transition in granulated superconductors